Commit: a4b99735116b2dbe2c49b6a8f2a5309053b1218d
Author: Antonio Vazquez
Date: Tue Aug 18 20:35:19 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rBa4b99735116b2dbe2c49b6a8f2a5309053b1218d
GPencil: Replace Trace to use Empty images
Instead to use the Image Editor, now it uses the current selected Empty image
===================================================================
M release/scripts/startup/bl_operators/__init__.py
D release/scripts/startup/bl_operators/gpencil_trace_image.py
M release/scripts/startup/bl_ui/space_view3d.py
M source/blender/editors/gpencil/gpencil_trace_ops.c
===================================================================
diff --git a/release/scripts/startup/bl_operators/__init__.py
b/release/scripts/startup/bl_operators/__init__.py
index 94c9c510a05..c927cc184a3 100644
--- a/release/scripts/startup/bl_operators/__init__.py
+++ b/release/scripts/startup/bl_operators/__init__.py
@@ -49,7 +49,6 @@ _modules = [
"vertexpaint_dirt",
"view3d",
"gpencil_mesh_bake",
- "gpencil_trace_image",
"wm",
]
diff --git a/release/scripts/startup/bl_operators/gpencil_trace_image.py
b/release/scripts/startup/bl_operators/gpencil_trace_image.py
deleted file mode 100644
index a8366909381..00000000000
--- a/release/scripts/startup/bl_operators/gpencil_trace_image.py
+++ /dev/null
@@ -1,142 +0,0 @@
-# ##### BEGIN GPL LICENSE BLOCK #####
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# ##### END GPL LICENSE BLOCK #####
-
-# <pep8-80 compliant>
-
-import bpy
-from bpy.types import Operator
-from bpy.props import (
- IntProperty,
- FloatProperty,
- BoolProperty,
- EnumProperty,
-)
-
-gp_object_items = []
-
-
-def my_objlist_callback(scene, context):
- gp_object_items.clear()
- gp_object_items.append(('*NEW', "New Object", ""))
- for o in context.scene.objects:
- if o.type == 'GPENCIL':
- gp_object_items.append((o.name, o.name, ""))
-
- return gp_object_items
-
-
-class GPENCIL_OT_trace(Operator):
- """Extract Grease Pencil strokes from Black and White image"""
- bl_idname = "gpencil.trace"
- bl_label = "Trace Image to Grease Pencil"
- bl_options = {'REGISTER', 'UNDO'}
-
- target: EnumProperty(
- name="Target Object",
- description="Grease Pencil Object",
- items=my_objlist_callback
- )
- frame_target: IntProperty(
- name="Target Frame",
- description="Destination frame for the baked animation",
- min=1, max=300000,
- default=1,
- )
- thickness: IntProperty(
- name="Thickness",
- description="Thickness of the stroke lines",
- min=1, max=100,
- default=10,
- )
- resolution: IntProperty(
- name="Resolution",
- description="Resolution of the generated curves",
- min=1, max=20,
- default=5,
- )
- scale: FloatProperty(
- name="Scale",
- description="Scale of the final output",
- min=0.001,
- max=100.0,
- default=1.0,
- )
- sample: FloatProperty(
- name="Sample Distance",
- description="Determine distance between points",
- soft_min=0.001, soft_max=100.0,
- min=0.001, max=100.0,
- default=0.05,
- precision=3,
- step=1,
- subtype='DISTANCE',
- unit='LENGTH',
- )
- threshold: FloatProperty(
- name="Color Threshold",
- description="Determine what is considered white and what black",
- soft_min=0.0, soft_max=1.0,
- min=0.0, max=1.0,
- default=0.5,
- precision=3,
- step=1,
- )
- turnpolicy: EnumProperty(
- name="Turn Policy",
- description="Determines how to resolve ambiguities during
decomposition of bitmaps into paths",
- items=(
- ("BLACK", "Black", "prefers to connect black (foreground)
components"),
- ("WHITE", "White", "Prefers to connect white (background)
components"),
- ("LEFT", "Left", "Always take a left turn"),
- ("RIGHT", "Right", "Always take a right turn"),
- ("MINORITY", "Minority", "Prefers to connect the color (black or
white) that occurs least frequently"),
- ("MAJORITY", "Majority", "Prefers to connect the color (black or
white) that occurs most frequently"),
- ("RANDOM", "Random", "Choose pseudo-randomly.")
- ),
- default="MINORITY"
- )
-
- @classmethod
- def poll(self, context):
- return context.space_data.type == 'IMAGE_EDITOR'
-
- def execute(self, context):
- try:
- bpy.ops.gpencil.trace_image(
- target=self.target,
- frame_target=self.frame_target,
- thickness=self.thickness,
- resolution=self.resolution,
- scale=self.scale,
- sample=self.sample,
- threshold=self.threshold,
- turnpolicy=self.turnpolicy
- )
- except:
- print("Unable to complete trace")
-
- return {'FINISHED'}
-
- def invoke(self, context, _event):
- wm = context.window_manager
- return wm.invoke_props_dialog(self)
-
-
-classes = (
- GPENCIL_OT_trace,
-)
diff --git a/release/scripts/startup/bl_ui/space_view3d.py
b/release/scripts/startup/bl_ui/space_view3d.py
index c251b4bfcac..02e93048771 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -2286,6 +2286,10 @@ class VIEW3D_MT_object(Menu):
layout.separator()
+ layout.operator("gpencil.trace_image")
+
+ layout.separator()
+
layout.menu("VIEW3D_MT_object_showhide")
layout.separator()
diff --git a/source/blender/editors/gpencil/gpencil_trace_ops.c
b/source/blender/editors/gpencil/gpencil_trace_ops.c
index efecab4c15a..30d9c3dbb35 100644
--- a/source/blender/editors/gpencil/gpencil_trace_ops.c
+++ b/source/blender/editors/gpencil/gpencil_trace_ops.c
@@ -56,6 +56,7 @@
#include "IMB_imbuf_types.h"
#include "ED_gpencil.h"
+#include "ED_object.h"
#include "gpencil_trace.h"
#include "potracelib.h"
@@ -140,13 +141,12 @@ static bool gpencil_trace_image(
/* Trace Image to Grease Pencil. */
static bool gpencil_trace_image_poll(bContext *C)
{
- SpaceLink *sl = CTX_wm_space_data(C);
- if ((sl != NULL) && (sl->spacetype == SPACE_IMAGE)) {
- SpaceImage *sima = CTX_wm_space_image(C);
- return (sima->image != NULL);
+ Object *ob = CTX_data_active_object(C);
+ if ((ob == NULL) || (ob->type != OB_EMPTY) || (ob->data == NULL)) {
+ return false;
}
- return false;
+ return true;
}
static int gpencil_trace_image_exec(bContext *C, wmOperator *op)
@@ -154,39 +154,34 @@ static int gpencil_trace_image_exec(bContext *C,
wmOperator *op)
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
- SpaceImage *sima = CTX_wm_space_image(C);
- Object *ob = NULL;
+ Base *base_active = CTX_data_active_base(C);
+ Object *ob_active = base_active->object;
+ Image *image = (Image *)ob_active->data;
bool ob_created = false;
- if (sima->image->type != IMA_TYPE_IMAGE) {
- BKE_report(op->reports, RPT_ERROR, "Image format not supported");
- return OPERATOR_CANCELLED;
- }
-
- char target[64];
- RNA_string_get(op->ptr, "target", target);
- const int frame_target = RNA_int_get(op->ptr, "frame_target");
-
- /* Create a new grease pencil object in origin. */
- if (ob == NULL) {
- if (STREQ(target, "*NEW")) {
- ushort local_view_bits = (v3d && v3d->localvd) ? v3d->local_view_uuid :
0;
- float loc[3] = {0.0f, 0.0f, 0.0f};
- ob = ED_gpencil_add_object(C, loc, local_view_bits);
- ob_created = true;
- }
- else {
- ob = BLI_findstring(&bmain->objects, target, offsetof(ID, name) + 2);
- }
+ const int frame_target = CFRA;
+ Object *ob_gpencil = (Object *)RNA_pointer_get(op->ptr, "target").data;
+
+ /* Create a new grease pencil object. */
+ if (ob_gpencil == NULL) {
+ ushort local_view_bits = (v3d && v3d->localvd) ? v3d->local_view_uuid : 0;
+ ob_gpencil = ED_gpencil_add_object(C, ob_active->loc, local_view_bits);
+ /* Apply image rotation. */
+ copy_v3_v3(ob_gpencil->rot, ob_active->rot);
+ /* Grease pencil is rotated 90 degrees in X axis by default. */
+ ob_gpencil->rot[0] -= DEG2RADF(90.0f);
+ ob_created = true;
+ /* Apply image Scale. */
+ copy_v3_v3(ob_gpencil->scale, ob_active->scale);
}
- if ((ob == NULL) || (ob->type != OB_GPENCIL)) {
+ if ((ob_gpencil == NULL) || (ob_gpencil->type != OB_GPENCIL)) {
BKE_report(op->reports, RPT_ERROR, "Target grease pencil object not
valid");
return OPERATOR_CANCELLED;
}
/* Create Layer. */
- bGPdata *gpd = (bGPdata *)ob->data;
+ bGPdata *gpd = (bGPdata *)ob_gpencil->data;
bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd);
if (gpl == NULL) {
gpl = BKE_gpencil_layer_addnew(gpd, DATA_("Trace"), true);
@@ -194,7 +189,10 @@ static int gpencil_trace_image_exec(bContext *C,
wmOperator *op)
/* Create frame. */
bGPDframe *gpf = BKE_gpencil_layer_frame_get(gpl, frame_target,
GP_GETFRAME_ADD_NEW);
- gpencil_trace_image(C, op, ob, sima->image, gpf);
+ gpencil_trace_image(C, op, ob_gpencil, image, gpf);
+
+ /* Back to active base. */
+ ED_object_base_activate(C, base_active);
/* notifiers */
if (ob_created) {
@@ -210,8 +208,15 @@ static int gpencil_trace_image_exec(bContext *C,
wmOperator *op)
return OPERATOR_FINISHED;
}
+static bool rna_GPencil_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
+{
+ return ((Object *)value.owner_id)->type == OB_GPENCIL;
+}
+
void GPENCIL_OT_trace_image(wmOperatorType *ot)
{
+ PropertyRNA *prop;
+
static const EnumPropertyItem turnpolicy_type[] = {
{POTRACE_TURNPOLICY_BLACK,
"BLACK",
@@ -244,7 +249,7 @@ void GPENCIL_OT_trace_image(wmOperatorType *ot)
/* identifiers */
ot->name = "Trace Image to Grease Pencil";
ot->idname = "GPENCIL_OT_trace_image";
- ot->description = "Extract Grease Pencil strokes from Black and White image";
+ ot->description = "Extract Grease Pencil strokes from image";
/* callbacks */
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs