Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/object')
-rw-r--r--source/blender/editors/object/object_add.cc41
-rw-r--r--source/blender/editors/object/object_relations.c10
2 files changed, 39 insertions, 12 deletions
diff --git a/source/blender/editors/object/object_add.cc b/source/blender/editors/object/object_add.cc
index e712b6e9d32..c350b955e14 100644
--- a/source/blender/editors/object/object_add.cc
+++ b/source/blender/editors/object/object_add.cc
@@ -24,6 +24,7 @@
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meta_types.h"
+#include "DNA_modifier_types.h"
#include "DNA_object_fluidsim_types.h"
#include "DNA_object_force_types.h"
#include "DNA_object_types.h"
@@ -72,6 +73,7 @@
#include "BKE_mesh.h"
#include "BKE_mesh_runtime.h"
#include "BKE_nla.h"
+#include "BKE_node.h"
#include "BKE_object.h"
#include "BKE_particle.h"
#include "BKE_pointcloud.h"
@@ -114,6 +116,10 @@
#include "object_intern.h"
+using blender::float3;
+using blender::float4x4;
+using blender::Vector;
+
/* -------------------------------------------------------------------- */
/** \name Local Enum Declarations
* \{ */
@@ -2070,29 +2076,42 @@ void OBJECT_OT_curves_random_add(wmOperatorType *ot)
static int object_curves_empty_hair_add_exec(bContext *C, wmOperator *op)
{
+ Scene *scene = CTX_data_scene(C);
+
ushort local_view_bits;
- float loc[3], rot[3];
+ blender::float3 loc, rot;
if (!ED_object_add_generic_get_opts(
C, op, 'Z', loc, rot, nullptr, nullptr, &local_view_bits, nullptr)) {
return OPERATOR_CANCELLED;
}
Object *surface_ob = CTX_data_active_object(C);
+ BLI_assert(surface_ob != nullptr);
- Object *object = ED_object_add_type(C, OB_CURVES, nullptr, loc, rot, false, local_view_bits);
+ Object *curves_ob = ED_object_add_type(C, OB_CURVES, nullptr, loc, rot, false, local_view_bits);
- if (surface_ob != nullptr && surface_ob->type == OB_MESH) {
- Curves *curves_id = static_cast<Curves *>(object->data);
- curves_id->surface = surface_ob;
- id_us_plus(&surface_ob->id);
+ /* Set surface object. */
+ Curves *curves_id = static_cast<Curves *>(curves_ob->data);
+ curves_id->surface = surface_ob;
- Mesh *surface_mesh = static_cast<Mesh *>(surface_ob->data);
- const char *uv_name = CustomData_get_active_layer_name(&surface_mesh->ldata, CD_MLOOPUV);
- if (uv_name != nullptr) {
- curves_id->surface_uv_map = BLI_strdup(uv_name);
- }
+ /* Parent to surface object. */
+ ED_object_parent_set(
+ op->reports, C, scene, curves_ob, surface_ob, PAR_OBJECT, false, true, nullptr);
+
+ /* Decide which UV map to use for attachment. */
+ Mesh *surface_mesh = static_cast<Mesh *>(surface_ob->data);
+ const char *uv_name = CustomData_get_active_layer_name(&surface_mesh->ldata, CD_MLOOPUV);
+ if (uv_name != nullptr) {
+ curves_id->surface_uv_map = BLI_strdup(uv_name);
}
+ /* Add deformation modifier. */
+ blender::ed::curves::ensure_surface_deformation_node_exists(*C, *curves_ob);
+
+ /* Make sure the surface object has a rest position attribute which is necessary for
+ * deformations. */
+ surface_ob->modifier_flag |= OB_MODIFIER_FLAG_ADD_REST_POSITION;
+
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index b58b0dac79b..01042824aac 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -951,7 +951,7 @@ static int parent_set_invoke_menu(bContext *C, wmOperatorType *ot)
1);
struct {
- bool mesh, gpencil;
+ bool mesh, gpencil, curves;
} has_children_of_type = {0};
CTX_DATA_BEGIN (C, Object *, child, selected_editable_objects) {
@@ -964,6 +964,9 @@ static int parent_set_invoke_menu(bContext *C, wmOperatorType *ot)
if (child->type == OB_GPENCIL) {
has_children_of_type.gpencil = true;
}
+ if (child->type == OB_CURVES) {
+ has_children_of_type.curves = true;
+ }
}
CTX_DATA_END;
@@ -987,6 +990,11 @@ static int parent_set_invoke_menu(bContext *C, wmOperatorType *ot)
else if (parent->type == OB_LATTICE) {
uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_LATTICE);
}
+ else if (parent->type == OB_MESH) {
+ if (has_children_of_type.curves) {
+ uiItemO(layout, "Object (Attach Curves to Surface)", ICON_NONE, "CURVES_OT_surface_set");
+ }
+ }
/* vertex parenting */
if (OB_TYPE_SUPPORT_PARVERT(parent->type)) {