Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_modifier.c
| Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_object_deform.h" | #include "BKE_object_deform.h" | ||||
| #include "BKE_ocean.h" | #include "BKE_ocean.h" | ||||
| #include "BKE_paint.h" | #include "BKE_paint.h" | ||||
| #include "BKE_particle.h" | #include "BKE_particle.h" | ||||
| #include "BKE_softbody.h" | #include "BKE_softbody.h" | ||||
| #include "BKE_editmesh.h" | #include "BKE_editmesh.h" | ||||
| #include "BKE_gpencil.h" | |||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_build.h" | #include "DEG_depsgraph_build.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| #include "RNA_enum_types.h" | #include "RNA_enum_types.h" | ||||
| ▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | static bool object_modifier_remove(Main *bmain, Object *ob, ModifierData *md, | ||||
| } | } | ||||
| DEG_relations_tag_update(bmain); | DEG_relations_tag_update(bmain); | ||||
| BLI_remlink(&ob->modifiers, md); | BLI_remlink(&ob->modifiers, md); | ||||
| modifier_free(md); | modifier_free(md); | ||||
| BKE_object_free_derived_caches(ob); | BKE_object_free_derived_caches(ob); | ||||
| /* if grease pencil, need refresh cache */ | |||||
| if (ob->type == OB_GPENCIL) { | |||||
| BKE_gpencil_batch_cache_dirty(ob->gpd); | |||||
| } | |||||
| return 1; | return 1; | ||||
| } | } | ||||
| bool ED_object_modifier_remove(ReportList *reports, Main *bmain, Object *ob, ModifierData *md) | bool ED_object_modifier_remove(ReportList *reports, Main *bmain, Object *ob, ModifierData *md) | ||||
| { | { | ||||
| bool sort_depsgraph = false; | bool sort_depsgraph = false; | ||||
| bool ok; | bool ok; | ||||
| ▲ Show 20 Lines • Show All 309 Lines • ▼ Show 20 Lines | else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { | ||||
| vertexCos = BKE_curve_nurbs_vertexCos_get(&cu->nurb, &numVerts); | vertexCos = BKE_curve_nurbs_vertexCos_get(&cu->nurb, &numVerts); | ||||
| mti->deformVerts(md, &eval_ctx, ob, NULL, vertexCos, numVerts, 0); | mti->deformVerts(md, &eval_ctx, ob, NULL, vertexCos, numVerts, 0); | ||||
| BK_curve_nurbs_vertexCos_apply(&cu->nurb, vertexCos); | BK_curve_nurbs_vertexCos_apply(&cu->nurb, vertexCos); | ||||
| MEM_freeN(vertexCos); | MEM_freeN(vertexCos); | ||||
| DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | ||||
| } | } | ||||
| else if (ELEM(ob->type, OB_GPENCIL)) { | |||||
| /* some modifier need to have bContext */ | |||||
| if (md->type == eModifierType_GpencilArray) { | |||||
| GpencilArrayModifierData *mmd = (GpencilArrayModifierData *)md; | |||||
| mmd->C = (void *) C; | |||||
| } | |||||
| if (md->type == eModifierType_GpencilLattice) { | |||||
| GpencilLatticeModifierData *mmd = (GpencilLatticeModifierData *)md; | |||||
| mmd->C = (void *)C; | |||||
| } | |||||
| mti->applyModifier(md, &eval_ctx, ob, NULL, 0); | |||||
| if (ob->gpd) { | |||||
| BKE_gpencil_batch_cache_dirty(ob->gpd); | |||||
| } | |||||
| return 1; | |||||
| } | |||||
| else { | else { | ||||
| BKE_report(reports, RPT_ERROR, "Cannot apply modifier for this object type"); | BKE_report(reports, RPT_ERROR, "Cannot apply modifier for this object type"); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* lattice modifier can be applied to particle system too */ | /* lattice modifier can be applied to particle system too */ | ||||
| if (ob->particlesystem.first) { | if (ob->particlesystem.first) { | ||||
| Show All 14 Lines | |||||
| int ED_object_modifier_apply(ReportList *reports, const bContext *C, Scene *scene, Object *ob, ModifierData *md, int mode) | int ED_object_modifier_apply(ReportList *reports, const bContext *C, Scene *scene, Object *ob, ModifierData *md, int mode) | ||||
| { | { | ||||
| int prev_mode; | int prev_mode; | ||||
| if (scene->obedit) { | if (scene->obedit) { | ||||
| BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied in edit mode"); | BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied in edit mode"); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| else if (ob->type == OB_GPENCIL) { | |||||
| if (ob->mode != OB_MODE_OBJECT) { | |||||
| BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied in paint, sculpt or edit mode"); | |||||
| return 0; | |||||
| } | |||||
| if (((ID *)ob->gpd)->us > 1) { | |||||
| BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied to multi-user data"); | |||||
| return 0; | |||||
| } | |||||
| modifier_apply_obdata(reports, C, scene, ob, md); | |||||
| BLI_remlink(&ob->modifiers, md); | |||||
| modifier_free(md); | |||||
| BKE_object_free_derived_caches(ob); | |||||
| return 1; | |||||
| } | |||||
| else if (((ID *) ob->data)->us > 1) { | else if (((ID *) ob->data)->us > 1) { | ||||
| BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied to multi-user data"); | BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied to multi-user data"); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| else if ((ob->mode & OB_MODE_SCULPT) && | else if ((ob->mode & OB_MODE_SCULPT) && | ||||
| (find_multires_modifier_before(scene, md)) && | (find_multires_modifier_before(scene, md)) && | ||||
| (modifier_isSameTopology(md) == false)) | (modifier_isSameTopology(md) == false)) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | static const EnumPropertyItem *modifier_add_itemf( | ||||
| const ModifierTypeInfo *mti; | const ModifierTypeInfo *mti; | ||||
| int totitem = 0, a; | int totitem = 0, a; | ||||
| if (!ob) | if (!ob) | ||||
| return rna_enum_object_modifier_type_items; | return rna_enum_object_modifier_type_items; | ||||
| for (a = 0; rna_enum_object_modifier_type_items[a].identifier; a++) { | for (a = 0; rna_enum_object_modifier_type_items[a].identifier; a++) { | ||||
| md_item = &rna_enum_object_modifier_type_items[a]; | md_item = &rna_enum_object_modifier_type_items[a]; | ||||
| if (md_item->identifier[0]) { | if (md_item->identifier[0]) { | ||||
| mti = modifierType_getInfo(md_item->value); | mti = modifierType_getInfo(md_item->value); | ||||
| if (mti->flags & eModifierTypeFlag_NoUserAdd) | if (mti->flags & eModifierTypeFlag_NoUserAdd) | ||||
| continue; | continue; | ||||
| if (!BKE_object_support_modifier_type_check(ob, md_item->value)) | if (!BKE_object_support_modifier_type_check(ob, md_item->value)) | ||||
| continue; | continue; | ||||
| ▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | static int modifier_remove_exec(bContext *C, wmOperator *op) | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); | WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); | ||||
| /* if cloth/softbody was removed, particle mode could be cleared */ | /* if cloth/softbody was removed, particle mode could be cleared */ | ||||
| if (mode_orig & OB_MODE_PARTICLE_EDIT) | if (mode_orig & OB_MODE_PARTICLE_EDIT) | ||||
| if ((ob->mode & OB_MODE_PARTICLE_EDIT) == 0) | if ((ob->mode & OB_MODE_PARTICLE_EDIT) == 0) | ||||
| if (sl->basact && sl->basact->object == ob) | if (sl->basact && sl->basact->object == ob) | ||||
| WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, NULL); | WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, NULL); | ||||
| /* if grease pencil, need refresh cache */ | |||||
| if (ob->type == OB_GPENCIL) { | |||||
| BKE_gpencil_batch_cache_dirty(ob->gpd); | |||||
| } | |||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| static int modifier_remove_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | static int modifier_remove_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| if (edit_modifier_invoke_properties(C, op)) | if (edit_modifier_invoke_properties(C, op)) | ||||
| return modifier_remove_exec(C, op); | return modifier_remove_exec(C, op); | ||||
| else | else | ||||
| Show All 22 Lines | static int modifier_move_up_exec(bContext *C, wmOperator *op) | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| ModifierData *md = edit_modifier_property_get(op, ob, 0); | ModifierData *md = edit_modifier_property_get(op, ob, 0); | ||||
| if (!md || !ED_object_modifier_move_up(op->reports, ob, md)) | if (!md || !ED_object_modifier_move_up(op->reports, ob, md)) | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); | WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); | ||||
| /* if grease pencil, need refresh cache */ | |||||
| if (ob->type == OB_GPENCIL) { | |||||
| BKE_gpencil_batch_cache_dirty(ob->gpd); | |||||
| } | |||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| static int modifier_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | static int modifier_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| if (edit_modifier_invoke_properties(C, op)) | if (edit_modifier_invoke_properties(C, op)) | ||||
| return modifier_move_up_exec(C, op); | return modifier_move_up_exec(C, op); | ||||
| else | else | ||||
| Show All 22 Lines | static int modifier_move_down_exec(bContext *C, wmOperator *op) | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| ModifierData *md = edit_modifier_property_get(op, ob, 0); | ModifierData *md = edit_modifier_property_get(op, ob, 0); | ||||
| if (!md || !ED_object_modifier_move_down(op->reports, ob, md)) | if (!md || !ED_object_modifier_move_down(op->reports, ob, md)) | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); | WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); | ||||
| /* if grease pencil, need refresh cache */ | |||||
| if (ob->type == OB_GPENCIL) { | |||||
| BKE_gpencil_batch_cache_dirty(ob->gpd); | |||||
| } | |||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| static int modifier_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | static int modifier_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| if (edit_modifier_invoke_properties(C, op)) | if (edit_modifier_invoke_properties(C, op)) | ||||
| return modifier_move_down_exec(C, op); | return modifier_move_down_exec(C, op); | ||||
| else | else | ||||
| ▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | static int modifier_copy_exec(bContext *C, wmOperator *op) | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| ModifierData *md = edit_modifier_property_get(op, ob, 0); | ModifierData *md = edit_modifier_property_get(op, ob, 0); | ||||
| if (!md || !ED_object_modifier_copy(op->reports, ob, md)) | if (!md || !ED_object_modifier_copy(op->reports, ob, md)) | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); | WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); | ||||
| /* if grease pencil, need refresh cache */ | |||||
| if (ob->type == OB_GPENCIL) { | |||||
| BKE_gpencil_batch_cache_dirty(ob->gpd); | |||||
| } | |||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| static int modifier_copy_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | static int modifier_copy_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| if (edit_modifier_invoke_properties(C, op)) | if (edit_modifier_invoke_properties(C, op)) | ||||
| return modifier_copy_exec(C, op); | return modifier_copy_exec(C, op); | ||||
| else | else | ||||
| ▲ Show 20 Lines • Show All 1,255 Lines • Show Last 20 Lines | |||||