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
path: root/source
diff options
context:
space:
mode:
authorAngus Stanton <abstanton>2022-04-18 18:15:30 +0300
committerHans Goudey <h.goudey@me.com>2022-04-18 18:15:30 +0300
commitccd2e89d37fb4887045969c1a50a66ca024c8c11 (patch)
tree7de971316373c59c2ade1599abedc592ea91a6a1 /source
parentef2b8c1c3afac9176da936995231523745e21643 (diff)
Fix T94559: Copying geometry node group does not copy animation data
Reimplement copy geometry node groups in C. The version implemented in Python could also manually copy the animation data, but it's more standard to do this with `BKE_id_copy_ex` and `LIB_ID_COPY_ACTIONS`. Differential Revision: https://developer.blender.org/D14615
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/object/object_intern.h1
-rw-r--r--source/blender/editors/object/object_modifier.c47
-rw-r--r--source/blender/editors/object/object_ops.c1
3 files changed, 49 insertions, 0 deletions
diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h
index eae08e89104..fb61200be9d 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -201,6 +201,7 @@ void OBJECT_OT_skin_armature_create(struct wmOperatorType *ot);
void OBJECT_OT_laplaciandeform_bind(struct wmOperatorType *ot);
void OBJECT_OT_surfacedeform_bind(struct wmOperatorType *ot);
void OBJECT_OT_geometry_nodes_input_attribute_toggle(struct wmOperatorType *ot);
+void OBJECT_OT_geometry_node_tree_copy_assign(struct wmOperatorType *ot);
/* object_gpencil_modifiers.c */
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index 6a230669056..10d1c8e0b34 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -3293,3 +3293,50 @@ void OBJECT_OT_geometry_nodes_input_attribute_toggle(wmOperatorType *ot)
}
/** \} */
+
+/* ------------------------------------------------------------------- */
+/** \name Copy and Assign Geometry Node Group operator
+ * \{ */
+
+static int geometry_node_tree_copy_assign_exec(bContext *C, wmOperator *op)
+{
+ Main *bmain = CTX_data_main(C);
+ Object *ob = ED_object_active_context(C);
+
+ ModifierData *md = BKE_object_active_modifier(ob);
+ if (md->type != eModifierType_Nodes) {
+ return OPERATOR_CANCELLED;
+ }
+
+ NodesModifierData *nmd = (NodesModifierData *)md;
+ bNodeTree *tree = nmd->node_group;
+ if (tree == NULL) {
+ return OPERATOR_CANCELLED;
+ }
+
+ bNodeTree *new_tree = (bNodeTree *)BKE_id_copy_ex(
+ bmain, &tree->id, NULL, LIB_ID_COPY_ACTIONS | LIB_ID_COPY_DEFAULT);
+
+ if (new_tree == NULL) {
+ return OPERATOR_CANCELLED;
+ }
+
+ nmd->node_group = new_tree;
+ id_us_min(&tree->id);
+
+ WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_geometry_node_tree_copy_assign(wmOperatorType *ot)
+{
+ ot->name = "Copy Geometry Node Group";
+ ot->description = "Copy the active geometry node group and assign it to the active modifier";
+ ot->idname = "OBJECT_OT_geometry_node_tree_copy_assign";
+
+ ot->exec = geometry_node_tree_copy_assign_exec;
+
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+/** \} */
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index ad0d6b88123..9b21dabb4bb 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -133,6 +133,7 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_skin_radii_equalize);
WM_operatortype_append(OBJECT_OT_skin_armature_create);
WM_operatortype_append(OBJECT_OT_geometry_nodes_input_attribute_toggle);
+ WM_operatortype_append(OBJECT_OT_geometry_node_tree_copy_assign);
/* grease pencil modifiers */
WM_operatortype_append(OBJECT_OT_gpencil_modifier_add);