Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_modifier.cc
| Show All 32 Lines | |||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BKE_DerivedMesh.h" | #include "BKE_DerivedMesh.h" | ||||
| #include "BKE_animsys.h" | #include "BKE_animsys.h" | ||||
| #include "BKE_armature.h" | #include "BKE_armature.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_curves.h" | #include "BKE_curves.h" | ||||
| #include "BKE_curves.hh" | |||||
| #include "BKE_displist.h" | #include "BKE_displist.h" | ||||
| #include "BKE_editmesh.h" | #include "BKE_editmesh.h" | ||||
| #include "BKE_effect.h" | #include "BKE_effect.h" | ||||
| #include "BKE_geometry_set.hh" | #include "BKE_geometry_set.hh" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_gpencil_modifier.h" | #include "BKE_gpencil_modifier.h" | ||||
| #include "BKE_key.h" | #include "BKE_key.h" | ||||
| #include "BKE_lattice.h" | #include "BKE_lattice.h" | ||||
| ▲ Show 20 Lines • Show All 647 Lines • ▼ Show 20 Lines | if (ob->type == OB_MESH) { | ||||
| } | } | ||||
| KeyBlock *kb = BKE_keyblock_add(key, md_eval->name); | KeyBlock *kb = BKE_keyblock_add(key, md_eval->name); | ||||
| BKE_mesh_nomain_to_meshkey(mesh_applied, me, kb); | BKE_mesh_nomain_to_meshkey(mesh_applied, me, kb); | ||||
| BKE_id_free(nullptr, mesh_applied); | BKE_id_free(nullptr, mesh_applied); | ||||
| } | } | ||||
| else { | else { | ||||
| /* TODO: implement for curves, point clouds and volumes. */ | |||||
| 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 false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| static bool modifier_apply_obdata( | static bool modifier_apply_obdata( | ||||
| ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md_eval) | ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md_eval) | ||||
| ▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | else if (ob->type == OB_LATTICE) { | ||||
| float(*vertexCos)[3] = BKE_lattice_vert_coords_alloc(lattice, &verts_num); | float(*vertexCos)[3] = BKE_lattice_vert_coords_alloc(lattice, &verts_num); | ||||
| mti->deformVerts(md_eval, &mectx, nullptr, vertexCos, verts_num); | mti->deformVerts(md_eval, &mectx, nullptr, vertexCos, verts_num); | ||||
| BKE_lattice_vert_coords_apply(lattice, vertexCos); | BKE_lattice_vert_coords_apply(lattice, 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 if (ob->type == OB_CURVES) { | |||||
| Curves &curves = *static_cast<Curves *>(ob->data); | |||||
| if (mti->modifyGeometrySet == nullptr) { | |||||
| BLI_assert_unreachable(); | |||||
| return false; | |||||
| } | |||||
| /* Create a temporary geometry set and component. */ | |||||
| GeometrySet geometry_set; | |||||
| geometry_set.get_component_for_write<CurveComponent>().replace( | |||||
| &curves, GeometryOwnershipType::Editable); | |||||
| ModifierEvalContext mectx = {depsgraph, ob, (ModifierApplyFlag)0}; | |||||
| mti->modifyGeometrySet(md_eval, &mectx, &geometry_set); | |||||
| if (!geometry_set.has_curves()) { | |||||
| BKE_report(reports, RPT_ERROR, "Evaluated geometry from modifier does not contain curves"); | |||||
| return false; | |||||
| } | |||||
| CurveComponent &component = geometry_set.get_component_for_write<CurveComponent>(); | |||||
| Curves &curves_eval = *geometry_set.get_curves_for_write(); | |||||
| /* Anonymous attributes shouldn't be available on the applied geometry. */ | |||||
| component.attributes_remove_anonymous(); | |||||
| /* If the modifier's output is a different curves data-block, copy the relevant information to | |||||
| * the original. */ | |||||
| if (&curves_eval != &curves) { | |||||
| blender::bke::CurvesGeometry::wrap(curves.geometry) = std::move( | |||||
| blender::bke::CurvesGeometry::wrap(curves_eval.geometry)); | |||||
| Main *bmain = DEG_get_bmain(depsgraph); | |||||
| BKE_object_material_from_eval_data(bmain, ob, &curves_eval.id); | |||||
| } | |||||
| } | |||||
| else { | else { | ||||
| /* TODO: implement for curves, point clouds and volumes. */ | /* TODO: implement for point clouds and volumes. */ | ||||
| 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 false; | return false; | ||||
| } | } | ||||
| /* 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) { | ||||
| LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { | LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { | ||||
| if (psys->part->type != PART_HAIR) { | if (psys->part->type != PART_HAIR) { | ||||
| ▲ Show 20 Lines • Show All 2,535 Lines • Show Last 20 Lines | |||||