Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_add.cc
| Show First 20 Lines • Show All 2,756 Lines • ▼ Show 20 Lines | #endif | ||||
| "Grease Pencil from Curve or Mesh objects"}, | "Grease Pencil from Curve or Mesh objects"}, | ||||
| #ifdef WITH_POINT_CLOUD | #ifdef WITH_POINT_CLOUD | ||||
| {OB_POINTCLOUD, | {OB_POINTCLOUD, | ||||
| "POINTCLOUD", | "POINTCLOUD", | ||||
| ICON_OUTLINER_OB_POINTCLOUD, | ICON_OUTLINER_OB_POINTCLOUD, | ||||
| "Point Cloud", | "Point Cloud", | ||||
| "Point Cloud from Mesh objects"}, | "Point Cloud from Mesh objects"}, | ||||
| #endif | #endif | ||||
| {OB_CURVES, "CURVES", ICON_OUTLINER_OB_CURVES, "Curves", "Curves from evaluated curve data"}, | |||||
HooglyBoogly: Maybe "Curves from evaluated curve data" would make the way it works a bit clearer? | |||||
| {0, nullptr, 0, nullptr, nullptr}, | {0, nullptr, 0, nullptr, nullptr}, | ||||
| }; | }; | ||||
| static const EnumPropertyItem *convert_target_items_fn(bContext *UNUSED(C), | |||||
| PointerRNA *UNUSED(ptr), | |||||
| PropertyRNA *UNUSED(prop), | |||||
| bool *r_free) | |||||
| { | |||||
| EnumPropertyItem *items = nullptr; | |||||
| int items_num = 0; | |||||
| for (const EnumPropertyItem *item = convert_target_items; item->identifier != nullptr; item++) { | |||||
| if (item->value == OB_CURVES) { | |||||
| if (U.experimental.use_new_curves_type) { | |||||
| RNA_enum_item_add(&items, &items_num, item); | |||||
| } | |||||
| } | |||||
| else { | |||||
| RNA_enum_item_add(&items, &items_num, item); | |||||
| } | |||||
| } | |||||
| RNA_enum_item_end(&items, &items_num); | |||||
| *r_free = true; | |||||
| return items; | |||||
| } | |||||
| static void object_data_convert_ensure_curve_cache(Depsgraph *depsgraph, Scene *scene, Object *ob) | static void object_data_convert_ensure_curve_cache(Depsgraph *depsgraph, Scene *scene, Object *ob) | ||||
| { | { | ||||
| if (ob->runtime.curve_cache == nullptr) { | if (ob->runtime.curve_cache == nullptr) { | ||||
| /* Force creation. This is normally not needed but on operator | /* Force creation. This is normally not needed but on operator | ||||
| * redo we might end up with an object which isn't evaluated yet. | * redo we might end up with an object which isn't evaluated yet. | ||||
| * Also happens in case we are working on a copy of the object | * Also happens in case we are working on a copy of the object | ||||
| * (all its caches have been nuked then). | * (all its caches have been nuked then). | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 284 Lines • ▼ Show 20 Lines | else if (ob->type == OB_MESH && target == OB_GPENCIL) { | ||||
| if (actcol >= slot) { | if (actcol >= slot) { | ||||
| actcol--; | actcol--; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ob_gpencil->actcol = actcol; | ob_gpencil->actcol = actcol; | ||||
| } | } | ||||
| else if (target == OB_CURVES) { | |||||
| 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 (geometry.has_curves()) { | |||||
| if (keep_original) { | |||||
| basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, nullptr); | |||||
| newob = basen->object; | |||||
| /* Decrement original curve's usage count. */ | |||||
| Curve *legacy_curve = static_cast<Curve *>(newob->data); | |||||
| id_us_min(&legacy_curve->id); | |||||
| /* Make a copy of the curve. */ | |||||
| newob->data = BKE_id_copy(bmain, &legacy_curve->id); | |||||
| } | |||||
| else { | |||||
| newob = ob; | |||||
| } | |||||
| const CurveComponent &curve_component = *geometry.get_component_for_read<CurveComponent>(); | |||||
| const Curves *curves_eval = curve_component.get_for_read(); | |||||
| Curves *new_curves = static_cast<Curves *>(BKE_id_new(bmain, ID_CV, newob->id.name + 2)); | |||||
| newob->data = new_curves; | |||||
| newob->type = OB_CURVES; | |||||
| blender::bke::CurvesGeometry::wrap( | |||||
| new_curves->geometry) = blender::bke::CurvesGeometry::wrap(curves_eval->geometry); | |||||
| BKE_object_material_from_eval_data(bmain, newob, &curves_eval->id); | |||||
| BKE_object_free_derived_caches(newob); | |||||
| BKE_object_free_modifiers(newob, 0); | |||||
| } | |||||
| else { | |||||
| BKE_reportf( | |||||
Not Done Inline ActionsWhat about Object '%s' has no evaluated curves data? HooglyBoogly: What about `Object '%s' has no evaluated curves data`? | |||||
| op->reports, RPT_WARNING, "Object '%s' has no evaluated curves data", ob->id.name + 2); | |||||
| } | |||||
| } | |||||
| else if (ob->type == OB_MESH && target == OB_POINTCLOUD) { | else if (ob->type == OB_MESH && target == OB_POINTCLOUD) { | ||||
| ob->flag |= OB_DONE; | ob->flag |= OB_DONE; | ||||
| if (keep_original) { | if (keep_original) { | ||||
| basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, nullptr); | basen = duplibase_for_convert(bmain, depsgraph, scene, view_layer, base, nullptr); | ||||
| newob = basen->object; | newob = basen->object; | ||||
| /* Decrement original mesh's usage count. */ | /* Decrement original mesh's usage count. */ | ||||
| ▲ Show 20 Lines • Show All 399 Lines • ▼ Show 20 Lines | void OBJECT_OT_convert(wmOperatorType *ot) | ||||
| ot->ui = object_convert_ui; | ot->ui = object_convert_ui; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* properties */ | /* properties */ | ||||
| ot->prop = RNA_def_enum( | ot->prop = RNA_def_enum( | ||||
| ot->srna, "target", convert_target_items, OB_MESH, "Target", "Type of object to convert to"); | ot->srna, "target", convert_target_items, OB_MESH, "Target", "Type of object to convert to"); | ||||
| RNA_def_enum_funcs(ot->prop, convert_target_items_fn); | |||||
| RNA_def_boolean(ot->srna, | RNA_def_boolean(ot->srna, | ||||
| "keep_original", | "keep_original", | ||||
| false, | false, | ||||
| "Keep Original", | "Keep Original", | ||||
| "Keep original objects instead of replacing them"); | "Keep original objects instead of replacing them"); | ||||
| RNA_def_boolean( | RNA_def_boolean( | ||||
| ot->srna, | ot->srna, | ||||
| ▲ Show 20 Lines • Show All 620 Lines • Show Last 20 Lines | |||||
Maybe "Curves from evaluated curve data" would make the way it works a bit clearer?