Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_trace_ops.c
| Show All 32 Lines | |||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| #include "DNA_space_types.h" | #include "DNA_space_types.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_duplilist.h" | #include "BKE_duplilist.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_image.h" | #include "BKE_image.h" | ||||
| #include "BKE_layer.h" | |||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| ▲ Show 20 Lines • Show All 266 Lines • ▼ Show 20 Lines | static int gpencil_trace_image_exec(bContext *C, wmOperator *op) | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| job->scene = scene; | job->scene = scene; | ||||
| job->v3d = CTX_wm_view3d(C); | job->v3d = CTX_wm_view3d(C); | ||||
| job->base_active = CTX_data_active_base(C); | job->base_active = CTX_data_active_base(C); | ||||
| job->ob_active = job->base_active->object; | job->ob_active = job->base_active->object; | ||||
| job->image = (Image *)job->ob_active->data; | job->image = (Image *)job->ob_active->data; | ||||
| job->frame_target = CFRA; | job->frame_target = CFRA; | ||||
| job->ob_gpencil = (Object *)RNA_pointer_get(op->ptr, "target").data; | /* Create a new grease pencil object or resuse selected. */ | ||||
| eGP_TargetObjectMode target = RNA_enum_get(op->ptr, "target"); | |||||
| job->ob_gpencil = (target == GP_TARGET_OB_SELECTED) ? | |||||
| BKE_view_layer_first_selected_object_by_type( | |||||
| CTX_data_view_layer(C), job->v3d, OB_GPENCIL) : | |||||
| NULL; | |||||
| job->was_ob_created = false; | job->was_ob_created = false; | ||||
| job->threshold = RNA_float_get(op->ptr, "threshold"); | job->threshold = RNA_float_get(op->ptr, "threshold"); | ||||
| job->scale = RNA_float_get(op->ptr, "scale"); | job->scale = RNA_float_get(op->ptr, "scale"); | ||||
| job->sample = RNA_float_get(op->ptr, "sample"); | job->sample = RNA_float_get(op->ptr, "sample"); | ||||
| job->resolution = RNA_int_get(op->ptr, "resolution"); | job->resolution = RNA_int_get(op->ptr, "resolution"); | ||||
| job->thickness = RNA_int_get(op->ptr, "thickness"); | job->thickness = RNA_int_get(op->ptr, "thickness"); | ||||
| job->turnpolicy = RNA_enum_get(op->ptr, "turnpolicy"); | job->turnpolicy = RNA_enum_get(op->ptr, "turnpolicy"); | ||||
| Show All 31 Lines | |||||
| static int gpencil_trace_image_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | static int gpencil_trace_image_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| /* Show popup dialog to allow editing. */ | /* Show popup dialog to allow editing. */ | ||||
| /* FIXME: hard-coded dimensions here are just arbitrary. */ | /* FIXME: hard-coded dimensions here are just arbitrary. */ | ||||
| return WM_operator_props_dialog_popup(C, op, 250); | return WM_operator_props_dialog_popup(C, op, 250); | ||||
| } | } | ||||
| 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) | void GPENCIL_OT_trace_image(wmOperatorType *ot) | ||||
| { | { | ||||
| PropertyRNA *prop; | |||||
| static const EnumPropertyItem turnpolicy_type[] = { | static const EnumPropertyItem turnpolicy_type[] = { | ||||
| {POTRACE_TURNPOLICY_BLACK, | {POTRACE_TURNPOLICY_BLACK, | ||||
| "BLACK", | "BLACK", | ||||
| 0, | 0, | ||||
| "Black", | "Black", | ||||
| "Prefers to connect black (foreground) components"}, | "Prefers to connect black (foreground) components"}, | ||||
| {POTRACE_TURNPOLICY_WHITE, | {POTRACE_TURNPOLICY_WHITE, | ||||
| "WHITE", | "WHITE", | ||||
| Show All 19 Lines | void GPENCIL_OT_trace_image(wmOperatorType *ot) | ||||
| }; | }; | ||||
| static const EnumPropertyItem trace_modes[] = { | static const EnumPropertyItem trace_modes[] = { | ||||
| {GPENCIL_TRACE_MODE_SINGLE, "SINGLE", 0, "Single", "Trace the current frame of the image"}, | {GPENCIL_TRACE_MODE_SINGLE, "SINGLE", 0, "Single", "Trace the current frame of the image"}, | ||||
| {GPENCIL_TRACE_MODE_SEQUENCE, "SEQUENCE", 0, "Sequence", "Trace full sequence"}, | {GPENCIL_TRACE_MODE_SEQUENCE, "SEQUENCE", 0, "Sequence", "Trace full sequence"}, | ||||
| {0, NULL, 0, NULL, NULL}, | {0, NULL, 0, NULL, NULL}, | ||||
| }; | }; | ||||
| static const EnumPropertyItem target_object_modes[] = { | |||||
| {GP_TARGET_OB_NEW, "NEW", 0, "New Object", ""}, | |||||
| {GP_TARGET_OB_SELECTED, "SELECTED", 0, "Selected Object", ""}, | |||||
| {0, NULL, 0, NULL, NULL}, | |||||
| }; | |||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Trace Image to Grease Pencil"; | ot->name = "Trace Image to Grease Pencil"; | ||||
| ot->idname = "GPENCIL_OT_trace_image"; | ot->idname = "GPENCIL_OT_trace_image"; | ||||
| ot->description = "Extract Grease Pencil strokes from image"; | ot->description = "Extract Grease Pencil strokes from image"; | ||||
| /* callbacks */ | /* callbacks */ | ||||
| ot->invoke = gpencil_trace_image_invoke; | ot->invoke = gpencil_trace_image_invoke; | ||||
| ot->exec = gpencil_trace_image_exec; | ot->exec = gpencil_trace_image_exec; | ||||
| ot->poll = gpencil_trace_image_poll; | ot->poll = gpencil_trace_image_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* properties */ | /* properties */ | ||||
| prop = RNA_def_pointer_runtime( | ot->prop = RNA_def_enum(ot->srna, | ||||
| ot->srna, | |||||
| "target", | "target", | ||||
| &RNA_Object, | target_object_modes, | ||||
| GP_TARGET_OB_NEW, | |||||
| "Target Object", | "Target Object", | ||||
| "Target grease pencil object name. Leave empty to create a new object"); | "Target grease pencil"); | ||||
| RNA_def_property_poll_runtime(prop, rna_GPencil_object_poll); | RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE); | ||||
| RNA_def_property_flag(prop, PROP_SKIP_SAVE); | |||||
| RNA_def_int(ot->srna, "thickness", 10, 1, 1000, "Thickness", "", 1, 1000); | RNA_def_int(ot->srna, "thickness", 10, 1, 1000, "Thickness", "", 1, 1000); | ||||
| RNA_def_int( | RNA_def_int( | ||||
| ot->srna, "resolution", 5, 1, 20, "Resolution", "Resolution of the generated curves", 1, 20); | ot->srna, "resolution", 5, 1, 20, "Resolution", "Resolution of the generated curves", 1, 20); | ||||
| RNA_def_float(ot->srna, | RNA_def_float(ot->srna, | ||||
| "scale", | "scale", | ||||
| 1.0f, | 1.0f, | ||||
| Show All 37 Lines | |||||