Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_modifier.c
| Show All 32 Lines | |||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "DNA_anim_types.h" | #include "DNA_anim_types.h" | ||||
| #include "DNA_armature_types.h" | #include "DNA_armature_types.h" | ||||
| #include "DNA_curve_types.h" | #include "DNA_curve_types.h" | ||||
| #include "DNA_key_types.h" | #include "DNA_key_types.h" | ||||
| #include "DNA_gpencil_types.h" | |||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "DNA_object_force_types.h" | #include "DNA_object_force_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "BLI_bitmap.h" | #include "BLI_bitmap.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| Show All 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 "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.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 85 Lines • ▼ Show 20 Lines | else if (type == eModifierType_Multires) { | ||||
| } | } | ||||
| } | } | ||||
| else if (type == eModifierType_Skin) { | else if (type == eModifierType_Skin) { | ||||
| /* ensure skin-node customdata exists */ | /* ensure skin-node customdata exists */ | ||||
| BKE_mesh_ensure_skin_customdata(ob->data); | BKE_mesh_ensure_skin_customdata(ob->data); | ||||
| } | } | ||||
| } | } | ||||
| if (ob->type == OB_GPENCIL) { | |||||
| bGPdata *gpd = ob->data; | |||||
| DEG_id_tag_update(&gpd->id, OB_RECALC_OB | OB_RECALC_DATA); | |||||
| } | |||||
| DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | ||||
| DEG_relations_tag_update(bmain); | DEG_relations_tag_update(bmain); | ||||
| return new_md; | return new_md; | ||||
| } | } | ||||
| /* Return true if the object has a modifier of type 'type' other than | /* Return true if the object has a modifier of type 'type' other than | ||||
| * the modifier pointed to be 'exclude', otherwise returns false. */ | * the modifier pointed to be 'exclude', otherwise returns false. */ | ||||
| ▲ Show 20 Lines • Show All 393 Lines • ▼ Show 20 Lines | static int modifier_apply_shape(ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md) | ||||
| } | } | ||||
| 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; | ||||
| } | } | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| static int modifier_apply_obdata(ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md) | static int modifier_apply_obdata(ReportList *reports, Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md) | ||||
| { | { | ||||
| const ModifierTypeInfo *mti = modifierType_getInfo(md->type); | const ModifierTypeInfo *mti = modifierType_getInfo(md->type); | ||||
| md->scene = scene; | md->scene = scene; | ||||
| if (mti->isDisabled && mti->isDisabled(md, 0)) { | if (mti->isDisabled && mti->isDisabled(md, 0)) { | ||||
| BKE_report(reports, RPT_ERROR, "Modifier is disabled, skipping apply"); | BKE_report(reports, RPT_ERROR, "Modifier is disabled, skipping apply"); | ||||
| return 0; | return 0; | ||||
| ▲ Show 20 Lines • Show All 49 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); | ||||
| modifier_deformVerts_DM_deprecated(md, &mectx, NULL, vertexCos, numVerts); | modifier_deformVerts_DM_deprecated(md, &mectx, NULL, vertexCos, numVerts); | ||||
| 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 (ob->type == OB_GPENCIL) { | |||||
| if (ELEM(NULL, ob, ob->data)) { | |||||
| return 0; | |||||
| } | |||||
| else if (mti->gp_bakeModifier == NULL) { | |||||
| BKE_report(reports, RPT_ERROR, "Not implemented"); | |||||
| return 0; | |||||
| } | |||||
| mti->gp_bakeModifier(bmain, depsgraph, md, ob); | |||||
| DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | |||||
| } | |||||
| 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) { | ||||
| ParticleSystem *psys = ob->particlesystem.first; | ParticleSystem *psys = ob->particlesystem.first; | ||||
| for (; psys; psys = psys->next) { | for (; psys; psys = psys->next) { | ||||
| if (psys->part->type != PART_HAIR) | if (psys->part->type != PART_HAIR) | ||||
| continue; | continue; | ||||
| psys_apply_hair_lattice(depsgraph, scene, ob, psys); | psys_apply_hair_lattice(depsgraph, scene, ob, psys); | ||||
| } | } | ||||
| } | } | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| int ED_object_modifier_apply( | int ED_object_modifier_apply( | ||||
| ReportList *reports, Depsgraph *depsgraph, | ReportList *reports, Main *bmain, Depsgraph *depsgraph, | ||||
| Scene *scene, Object *ob, ModifierData *md, int mode) | Scene *scene, Object *ob, ModifierData *md, int mode) | ||||
| { | { | ||||
| int prev_mode; | int prev_mode; | ||||
| if (BKE_object_is_in_editmode(ob)) { | if (BKE_object_is_in_editmode(ob)) { | ||||
| 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->data)->us > 1) { | |||||
| BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied to multi-user data"); | |||||
| return 0; | |||||
| } | |||||
| } | |||||
| 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 All 10 Lines | int ED_object_modifier_apply( | ||||
| if (mode == MODIFIER_APPLY_SHAPE) { | if (mode == MODIFIER_APPLY_SHAPE) { | ||||
| if (!modifier_apply_shape(reports, depsgraph, scene, ob, md)) { | if (!modifier_apply_shape(reports, depsgraph, scene, ob, md)) { | ||||
| md->mode = prev_mode; | md->mode = prev_mode; | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (!modifier_apply_obdata(reports, depsgraph, scene, ob, md)) { | if (!modifier_apply_obdata(reports, bmain, depsgraph, scene, ob, md)) { | ||||
| md->mode = prev_mode; | md->mode = prev_mode; | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||
| BLI_remlink(&ob->modifiers, md); | BLI_remlink(&ob->modifiers, md); | ||||
| modifier_free(md); | modifier_free(md); | ||||
| Show All 40 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 235 Lines • ▼ Show 20 Lines | void OBJECT_OT_modifier_move_down(wmOperatorType *ot) | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | ||||
| edit_modifier_properties(ot); | edit_modifier_properties(ot); | ||||
| } | } | ||||
| /************************ apply modifier operator *********************/ | /************************ apply modifier operator *********************/ | ||||
| static int modifier_apply_exec(bContext *C, wmOperator *op) | static int modifier_apply_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | |||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | Depsgraph *depsgraph = CTX_data_depsgraph(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| 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); | ||||
| int apply_as = RNA_enum_get(op->ptr, "apply_as"); | int apply_as = RNA_enum_get(op->ptr, "apply_as"); | ||||
| if (!md || !ED_object_modifier_apply(op->reports, depsgraph, scene, ob, md, apply_as)) { | if (!md || !ED_object_modifier_apply(op->reports, bmain, depsgraph, scene, ob, md, apply_as)) { | ||||
| 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); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,395 Lines • Show Last 20 Lines | |||||