Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_modifier.c
| Show First 20 Lines • Show All 535 Lines • ▼ Show 20 Lines | for (a = 0; a < totchild; a++) { | ||||
| } | } | ||||
| } | } | ||||
| DEG_relations_tag_update(bmain); | DEG_relations_tag_update(bmain); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| /* Gets mesh for the modifier which corresponds to an evaluated state. */ | |||||
| static Mesh *modifier_apply_create_mesh_for_modifier( | |||||
| Depsgraph *depsgraph, | |||||
| Scene *UNUSED(scene), | |||||
| Object *object, | |||||
| ModifierData *md, | |||||
| bool build_shapekey_layers) | |||||
| { | |||||
| Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); | |||||
| Object *object_eval = DEG_get_evaluated_object(depsgraph, object); | |||||
| ModifierData *md_eval = modifiers_findByName(object_eval, md->name); | |||||
| Mesh *mesh_applied = BKE_mesh_create_derived_for_modifier( | |||||
| depsgraph, scene_eval, object_eval, md_eval, build_shapekey_layers); | |||||
| return mesh_applied; | |||||
| } | |||||
| static int modifier_apply_shape( | static int modifier_apply_shape( | ||||
| Main *bmain, ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md) | Main *bmain, ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md) | ||||
| { | { | ||||
| const ModifierTypeInfo *mti = modifierType_getInfo(md->type); | const ModifierTypeInfo *mti = modifierType_getInfo(md->type); | ||||
| if (mti->isDisabled && mti->isDisabled(scene, md, 0)) { | if (mti->isDisabled && mti->isDisabled(scene, 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 All 16 Lines | if (ob->type == OB_MESH) { | ||||
| Key *key = me->key; | Key *key = me->key; | ||||
| KeyBlock *kb; | KeyBlock *kb; | ||||
| if (!modifier_isSameTopology(md) || mti->type == eModifierTypeType_NonGeometrical) { | if (!modifier_isSameTopology(md) || mti->type == eModifierTypeType_NonGeometrical) { | ||||
| BKE_report(reports, RPT_ERROR, "Only deforming modifiers can be applied to shapes"); | BKE_report(reports, RPT_ERROR, "Only deforming modifiers can be applied to shapes"); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| mesh_applied = BKE_mesh_create_derived_for_modifier(depsgraph, scene, ob, md, 0); | mesh_applied = modifier_apply_create_mesh_for_modifier(depsgraph, scene, ob, md, false); | ||||
| if (!mesh_applied) { | if (!mesh_applied) { | ||||
| BKE_report(reports, RPT_ERROR, "Modifier is disabled or returned error, skipping apply"); | BKE_report(reports, RPT_ERROR, "Modifier is disabled or returned error, skipping apply"); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| if (key == NULL) { | if (key == NULL) { | ||||
| key = me->key = BKE_key_add(bmain, (ID *)me); | key = me->key = BKE_key_add(bmain, (ID *)me); | ||||
| key->type = KEY_RELATIVE; | key->type = KEY_RELATIVE; | ||||
| Show All 40 Lines | if (ob->type == OB_MESH) { | ||||
| if (mmd && mmd->totlvl && mti->type == eModifierTypeType_OnlyDeform) { | if (mmd && mmd->totlvl && mti->type == eModifierTypeType_OnlyDeform) { | ||||
| if (!multiresModifier_reshapeFromDeformModifier(depsgraph, mmd, ob, md)) { | if (!multiresModifier_reshapeFromDeformModifier(depsgraph, mmd, ob, md)) { | ||||
| BKE_report(reports, RPT_ERROR, "Multires modifier returned error, skipping apply"); | BKE_report(reports, RPT_ERROR, "Multires modifier returned error, skipping apply"); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| mesh_applied = BKE_mesh_create_derived_for_modifier(depsgraph, scene, ob, md, 1); | mesh_applied = modifier_apply_create_mesh_for_modifier(depsgraph, scene, ob, md, true); | ||||
| if (!mesh_applied) { | if (!mesh_applied) { | ||||
| BKE_report(reports, RPT_ERROR, "Modifier returned error, skipping apply"); | BKE_report(reports, RPT_ERROR, "Modifier returned error, skipping apply"); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| BKE_mesh_nomain_to_mesh(mesh_applied, me, ob, &CD_MASK_MESH, true); | BKE_mesh_nomain_to_mesh(mesh_applied, me, ob, &CD_MASK_MESH, true); | ||||
| if (md->type == eModifierType_Multires) | if (md->type == eModifierType_Multires) | ||||
| multires_customdata_delete(me); | multires_customdata_delete(me); | ||||
| } | } | ||||
| } | } | ||||
| else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { | else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { | ||||
| Curve *cu; | Object *object_eval = DEG_get_evaluated_object(depsgraph, ob); | ||||
| Curve *curve = ob->data; | |||||
| Curve *curve_eval = (Curve *)object_eval->data; | |||||
| int numVerts; | int numVerts; | ||||
| float (*vertexCos)[3]; | float (*vertexCos)[3]; | ||||
| ModifierEvalContext mectx = {depsgraph, ob, 0}; | ModifierEvalContext mectx = {depsgraph, object_eval, 0}; | ||||
| if (ELEM(mti->type, eModifierTypeType_Constructive, eModifierTypeType_Nonconstructive)) { | if (ELEM(mti->type, eModifierTypeType_Constructive, eModifierTypeType_Nonconstructive)) { | ||||
| BKE_report(reports, RPT_ERROR, "Transform curve to mesh in order to apply constructive modifiers"); | BKE_report(reports, RPT_ERROR, "Transform curve to mesh in order to apply constructive modifiers"); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| cu = ob->data; | |||||
| BKE_report(reports, RPT_INFO, "Applied modifier only changed CV points, not tessellated/bevel vertices"); | BKE_report(reports, RPT_INFO, "Applied modifier only changed CV points, not tessellated/bevel vertices"); | ||||
| vertexCos = BKE_curve_nurbs_vertexCos_get(&cu->nurb, &numVerts); | vertexCos = BKE_curve_nurbs_vertexCos_get(&curve_eval->nurb, &numVerts); | ||||
| mti->deformVerts(md, &mectx, NULL, vertexCos, numVerts); | mti->deformVerts(md, &mectx, NULL, vertexCos, numVerts); | ||||
| BK_curve_nurbs_vertexCos_apply(&cu->nurb, vertexCos); | BK_curve_nurbs_vertexCos_apply(&curve->nurb, vertexCos); | ||||
| MEM_freeN(vertexCos); | MEM_freeN(vertexCos); | ||||
| DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | ||||
| } | } | ||||
| 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; | ||||
| ▲ Show 20 Lines • Show All 1,720 Lines • Show Last 20 Lines | |||||