Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_add.cc
| Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_action.h" | #include "BKE_action.h" | ||||
| #include "BKE_anim_data.h" | #include "BKE_anim_data.h" | ||||
| #include "BKE_armature.h" | #include "BKE_armature.h" | ||||
| #include "BKE_camera.h" | #include "BKE_camera.h" | ||||
| #include "BKE_collection.h" | #include "BKE_collection.h" | ||||
| #include "BKE_constraint.h" | #include "BKE_constraint.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_curve_to_mesh.hh" | |||||
| #include "BKE_curves.h" | #include "BKE_curves.h" | ||||
| #include "BKE_displist.h" | #include "BKE_displist.h" | ||||
| #include "BKE_duplilist.h" | #include "BKE_duplilist.h" | ||||
| #include "BKE_effect.h" | #include "BKE_effect.h" | ||||
| #include "BKE_geometry_set.h" | #include "BKE_geometry_set.h" | ||||
| #include "BKE_geometry_set.hh" | #include "BKE_geometry_set.hh" | ||||
| #include "BKE_gpencil_curve.h" | #include "BKE_gpencil_curve.h" | ||||
| #include "BKE_gpencil_geom.h" | #include "BKE_gpencil_geom.h" | ||||
| ▲ Show 20 Lines • Show All 2,812 Lines • ▼ Show 20 Lines | if (is_meta_ball) { | ||||
| obn->data = obdata; | obn->data = obdata; | ||||
| } | } | ||||
| return basen; | return basen; | ||||
| } | } | ||||
| static int object_convert_exec(bContext *C, wmOperator *op) | static int object_convert_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| using namespace blender; | |||||
| 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); | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| Base *basen = nullptr, *basact = nullptr; | Base *basen = nullptr, *basact = nullptr; | ||||
| Object *ob1, *obact = CTX_data_active_object(C); | Object *ob1, *obact = CTX_data_active_object(C); | ||||
| const short target = RNA_enum_get(op->ptr, "target"); | const short target = RNA_enum_get(op->ptr, "target"); | ||||
| ▲ Show 20 Lines • Show All 466 Lines • ▼ Show 20 Lines | else if (ob->type == OB_POINTCLOUD && target == OB_MESH) { | ||||
| BKE_pointcloud_to_mesh(bmain, depsgraph, scene, newob); | BKE_pointcloud_to_mesh(bmain, depsgraph, scene, newob); | ||||
| if (newob->type == OB_MESH) { | if (newob->type == OB_MESH) { | ||||
| BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */ | BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */ | ||||
| ED_rigidbody_object_remove(bmain, scene, newob); | ED_rigidbody_object_remove(bmain, scene, newob); | ||||
| } | } | ||||
| } | } | ||||
| else if (ob->type == OB_CURVES && target == OB_MESH) { | |||||
| ob->flag |= OB_DONE; | |||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | |||||
| GeometrySet geometry; | |||||
| if (ob_eval->runtime.geometry_set_eval != nullptr) { | |||||
| geometry = *ob_eval->runtime.geometry_set_eval; | |||||
| } | |||||
| if (keep_original) { | |||||
| basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, nullptr); | |||||
| newob = basen->object; | |||||
| Curves *curves = static_cast<Curves *>(newob->data); | |||||
| id_us_min(&curves->id); | |||||
| newob->data = BKE_id_copy(bmain, &curves->id); | |||||
| } | |||||
| else { | |||||
| newob = ob; | |||||
| } | |||||
| Mesh *new_mesh = static_cast<Mesh *>(BKE_id_new(bmain, ID_ME, newob->id.name + 2)); | |||||
| if (const Mesh *mesh_eval = geometry.get_mesh_for_read()) { | |||||
| BKE_mesh_nomain_to_mesh(BKE_mesh_copy_for_eval(mesh_eval, false), new_mesh, newob); | |||||
| BKE_object_material_from_eval_data(bmain, newob, &mesh_eval->id); | |||||
| new_mesh->attributes_for_write().remove_anonymous(); | |||||
| } | |||||
| else if (const Curves *curves_eval = geometry.get_curves_for_read()) { | |||||
| bke::AnonymousAttributePropagationInfo propagation_info; | |||||
| propagation_info.propagate_all = false; | |||||
| Mesh *mesh = bke::curve_to_wire_mesh(bke::CurvesGeometry::wrap(curves_eval->geometry), | |||||
JacquesLucke: Should probably add some method to `::CurvesGeometry` that does `bke::CurvesGeometry::wrap`. | |||||
Done Inline ActionsYeah, that sounds like a nice improvement. HooglyBoogly: Yeah, that sounds like a nice improvement. | |||||
| propagation_info); | |||||
Done Inline Actionsunnecessary braces JacquesLucke: unnecessary braces | |||||
| BKE_mesh_nomain_to_mesh(mesh, new_mesh, newob); | |||||
| BKE_object_material_from_eval_data(bmain, newob, &curves_eval->id); | |||||
| } | |||||
| else { | |||||
| BKE_reportf(op->reports, | |||||
| RPT_WARNING, | |||||
| "Object '%s' has no evaluated mesh or curves data", | |||||
| ob->id.name + 2); | |||||
| } | |||||
| newob->data = new_mesh; | |||||
| newob->type = OB_MESH; | |||||
| BKE_object_free_derived_caches(newob); | |||||
| BKE_object_free_modifiers(newob, 0); | |||||
| } | |||||
| else { | else { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* Ensure new object has consistent material data with its new obdata. */ | /* Ensure new object has consistent material data with its new obdata. */ | ||||
| if (newob) { | if (newob) { | ||||
| BKE_object_materials_test(bmain, newob, static_cast<ID *>(newob->data)); | BKE_object_materials_test(bmain, newob, static_cast<ID *>(newob->data)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 848 Lines • Show Last 20 Lines | |||||
Should probably add some method to ::CurvesGeometry that does bke::CurvesGeometry::wrap. Would look much more nice.