Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_mesh.c
| Show All 33 Lines | |||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| #include "BKE_anim_data.h" | #include "BKE_anim_data.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_gpencil_geom.h" | #include "BKE_gpencil_geom.h" | ||||
| #include "BKE_layer.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 "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| ▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | |||||
| static int gpencil_bake_mesh_animation_exec(bContext *C, wmOperator *op) | static int gpencil_bake_mesh_animation_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| Object *ob_gpencil = NULL; | |||||
| ListBase ob_selected_list = {NULL, NULL}; | ListBase ob_selected_list = {NULL, NULL}; | ||||
| gpencil_bake_ob_list(C, depsgraph, scene, &ob_selected_list); | gpencil_bake_ob_list(C, depsgraph, scene, &ob_selected_list); | ||||
| /* Cannot check this in poll because the active object changes. */ | /* Cannot check this in poll because the active object changes. */ | ||||
| if (ob_selected_list.first == NULL) { | if (ob_selected_list.first == NULL) { | ||||
| BKE_report(op->reports, RPT_INFO, "No valid object selected"); | BKE_report(op->reports, RPT_INFO, "No valid object selected"); | ||||
| gpencil_bake_free_ob_list(&ob_selected_list); | gpencil_bake_free_ob_list(&ob_selected_list); | ||||
| Show All 14 Lines | static int gpencil_bake_mesh_animation_exec(bContext *C, wmOperator *op) | ||||
| const float angle = RNA_float_get(op->ptr, "angle"); | const float angle = RNA_float_get(op->ptr, "angle"); | ||||
| const int thickness = RNA_int_get(op->ptr, "thickness"); | const int thickness = RNA_int_get(op->ptr, "thickness"); | ||||
| const bool use_seams = RNA_boolean_get(op->ptr, "seams"); | const bool use_seams = RNA_boolean_get(op->ptr, "seams"); | ||||
| const bool use_faces = RNA_boolean_get(op->ptr, "faces"); | const bool use_faces = RNA_boolean_get(op->ptr, "faces"); | ||||
| const bool only_selected = RNA_boolean_get(op->ptr, "only_selected"); | const bool only_selected = RNA_boolean_get(op->ptr, "only_selected"); | ||||
| const float offset = RNA_float_get(op->ptr, "offset"); | const float offset = RNA_float_get(op->ptr, "offset"); | ||||
| const int frame_offset = RNA_int_get(op->ptr, "frame_target") - frame_start; | const int frame_offset = RNA_int_get(op->ptr, "frame_target") - frame_start; | ||||
| const int project_type = RNA_enum_get(op->ptr, "project_type"); | const int project_type = RNA_enum_get(op->ptr, "project_type"); | ||||
| ob_gpencil = (Object *)RNA_pointer_get(op->ptr, "target").data; | eGP_TargetObjectMode target = RNA_enum_get(op->ptr, "target"); | ||||
| /* Create a new grease pencil object in origin. */ | /* Create a new grease pencil object in origin or resuse selected. */ | ||||
| Object *ob_gpencil = NULL; | |||||
| bool newob = false; | bool newob = false; | ||||
| if (target == GP_TARGET_OB_SELECTED) { | |||||
| ob_gpencil = BKE_view_layer_first_selected_object_by_type( | |||||
| CTX_data_view_layer(C), v3d, OB_GPENCIL); | |||||
campbellbarton: There aren't any checks for the object data being editable (library data for example). This can… | |||||
| } | |||||
| if (ob_gpencil == NULL) { | if (ob_gpencil == NULL) { | ||||
| ushort local_view_bits = (v3d && v3d->localvd) ? v3d->local_view_uuid : 0; | ushort local_view_bits = (v3d && v3d->localvd) ? v3d->local_view_uuid : 0; | ||||
| const float loc[3] = {0.0f, 0.0f, 0.0f}; | const float loc[3] = {0.0f, 0.0f, 0.0f}; | ||||
| ob_gpencil = ED_gpencil_add_object(C, loc, local_view_bits); | ob_gpencil = ED_gpencil_add_object(C, loc, local_view_bits); | ||||
| newob = true; | newob = true; | ||||
| } | } | ||||
| bGPdata *gpd = (bGPdata *)ob_gpencil->data; | bGPdata *gpd = (bGPdata *)ob_gpencil->data; | ||||
| gpd->draw_mode = (project_type == GP_REPROJECT_KEEP) ? GP_DRAWMODE_3D : GP_DRAWMODE_2D; | gpd->draw_mode = (project_type == GP_REPROJECT_KEEP) ? GP_DRAWMODE_3D : GP_DRAWMODE_2D; | ||||
| /* Set cursor to indicate working. */ | /* Set cursor to indicate working. */ | ||||
| WM_cursor_wait(1); | WM_cursor_wait(1); | ||||
| GP_SpaceConversion gsc = {NULL}; | GP_SpaceConversion gsc = {NULL}; | ||||
| SnapObjectContext *sctx = NULL; | SnapObjectContext *sctx = NULL; | ||||
| if (project_type != GP_REPROJECT_KEEP) { | if (project_type != GP_REPROJECT_KEEP) { | ||||
| /* Init space conversion stuff. */ | /* Init space conversion stuff. */ | ||||
| gpencil_point_conversion_init(C, &gsc); | gpencil_point_conversion_init(C, &gsc); | ||||
| /* Move the grease pencil object to conversion data. */ | |||||
| gsc.ob = ob_gpencil; | |||||
| /* Init snap context for geometry projection. */ | /* Init snap context for geometry projection. */ | ||||
| sctx = ED_transform_snap_object_context_create_view3d(scene, 0, region, CTX_wm_view3d(C)); | sctx = ED_transform_snap_object_context_create_view3d(scene, 0, region, CTX_wm_view3d(C)); | ||||
| /* Tag all existing strokes to avoid reprojections. */ | /* Tag all existing strokes to avoid reprojections. */ | ||||
| LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { | LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { | ||||
| LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { | LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { | ||||
| LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { | LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { | ||||
| gps->flag |= GP_STROKE_TAG; | gps->flag |= GP_STROKE_TAG; | ||||
| ▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | static int gpencil_bake_mesh_animation_invoke(bContext *C, | ||||
| wmOperator *op, | wmOperator *op, | ||||
| const wmEvent *UNUSED(event)) | 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_bake_mesh_animation(wmOperatorType *ot) | void GPENCIL_OT_bake_mesh_animation(wmOperatorType *ot) | ||||
| { | { | ||||
| static const EnumPropertyItem reproject_type[] = { | static const EnumPropertyItem reproject_type[] = { | ||||
| {GP_REPROJECT_KEEP, "KEEP", 0, "No Reproject", ""}, | {GP_REPROJECT_KEEP, "KEEP", 0, "No Reproject", ""}, | ||||
| {GP_REPROJECT_FRONT, "FRONT", 0, "Front", "Reproject the strokes using the X-Z plane"}, | {GP_REPROJECT_FRONT, "FRONT", 0, "Front", "Reproject the strokes using the X-Z plane"}, | ||||
| {GP_REPROJECT_SIDE, "SIDE", 0, "Side", "Reproject the strokes using the Y-Z plane"}, | {GP_REPROJECT_SIDE, "SIDE", 0, "Side", "Reproject the strokes using the Y-Z plane"}, | ||||
| {GP_REPROJECT_TOP, "TOP", 0, "Top", "Reproject the strokes using the X-Y plane"}, | {GP_REPROJECT_TOP, "TOP", 0, "Top", "Reproject the strokes using the X-Y plane"}, | ||||
| {GP_REPROJECT_VIEW, | {GP_REPROJECT_VIEW, | ||||
| "VIEW", | "VIEW", | ||||
| 0, | 0, | ||||
| "View", | "View", | ||||
| "Reproject the strokes to end up on the same plane, as if drawn from the current viewpoint " | "Reproject the strokes to end up on the same plane, as if drawn from the current viewpoint " | ||||
| "using 'Cursor' Stroke Placement"}, | "using 'Cursor' Stroke Placement"}, | ||||
| {GP_REPROJECT_CURSOR, | {GP_REPROJECT_CURSOR, | ||||
| "CURSOR", | "CURSOR", | ||||
| 0, | 0, | ||||
| "Cursor", | "Cursor", | ||||
| "Reproject the strokes using the orientation of 3D cursor"}, | "Reproject the strokes using the orientation of 3D cursor"}, | ||||
| {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}, | |||||
| }; | |||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Bake Mesh Animation to Grease Pencil"; | ot->name = "Bake Mesh Animation to Grease Pencil"; | ||||
| ot->idname = "GPENCIL_OT_bake_mesh_animation"; | ot->idname = "GPENCIL_OT_bake_mesh_animation"; | ||||
| ot->description = "Bake Mesh Animation to Grease Pencil strokes"; | ot->description = "Bake Mesh Animation to Grease Pencil strokes"; | ||||
| /* callbacks */ | /* callbacks */ | ||||
| ot->invoke = gpencil_bake_mesh_animation_invoke; | ot->invoke = gpencil_bake_mesh_animation_invoke; | ||||
| ot->exec = gpencil_bake_mesh_animation_exec; | ot->exec = gpencil_bake_mesh_animation_exec; | ||||
| ot->poll = gpencil_bake_mesh_animation_poll; | ot->poll = gpencil_bake_mesh_animation_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* properties */ | /* properties */ | ||||
| ot->prop = RNA_def_pointer_runtime(ot->srna, | ot->prop = RNA_def_enum(ot->srna, | ||||
| "target", | "target", | ||||
| &RNA_Object, | target_object_modes, | ||||
| GP_TARGET_OB_NEW, | |||||
| "Target Object", | "Target Object", | ||||
| "Target grease pencil object. Leave empty for new object"); | "Target grease pencil"); | ||||
| RNA_def_property_poll_runtime(ot->prop, rna_GPencil_object_poll); | |||||
| RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE); | RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE); | ||||
| prop = RNA_def_int( | prop = RNA_def_int( | ||||
| ot->srna, "frame_start", 1, 1, 100000, "Start Frame", "The start frame", 1, 100000); | ot->srna, "frame_start", 1, 1, 100000, "Start Frame", "The start frame", 1, 100000); | ||||
| prop = RNA_def_int( | prop = RNA_def_int( | ||||
| ot->srna, "frame_end", 250, 1, 100000, "End Frame", "The end frame of animation", 1, 100000); | ot->srna, "frame_end", 250, 1, 100000, "End Frame", "The end frame of animation", 1, 100000); | ||||
| RNA_def_property_update_runtime(prop, gpencil_bake_set_frame_end); | RNA_def_property_update_runtime(prop, gpencil_bake_set_frame_end); | ||||
| Show All 36 Lines | |||||
There aren't any checks for the object data being editable (library data for example). This can be handled in a separate patch though.