[Bf-blender-cvs] [acae8f430db] temp-geometry-nodes-fields-prototype: simplify switching between value and attribute in modifier

Jacques Lucke noreply at git.blender.org
Tue Aug 10 17:00:31 CEST 2021


Commit: acae8f430db1379fc0e6c5fe5e9fd6629884e68a
Author: Jacques Lucke
Date:   Tue Aug 10 16:55:41 2021 +0200
Branches: temp-geometry-nodes-fields-prototype
https://developer.blender.org/rBacae8f430db1379fc0e6c5fe5e9fd6629884e68a

simplify switching between value and attribute in modifier

===================================================================

M	source/blender/editors/object/object_intern.h
M	source/blender/editors/object/object_modifier.c
M	source/blender/editors/object/object_ops.c
M	source/blender/modifiers/intern/MOD_nodes.cc

===================================================================

diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h
index 6299fdcc7f7..7cb7286362b 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -191,6 +191,7 @@ void OBJECT_OT_skin_radii_equalize(struct wmOperatorType *ot);
 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_modifier_value_or_attribute_toggle(struct wmOperatorType *ot);
 
 /* object_gpencil_modifiers.c */
 void OBJECT_OT_gpencil_modifier_add(struct wmOperatorType *ot);
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index e9142742d15..6b728a1e66e 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -3242,3 +3242,55 @@ void OBJECT_OT_surfacedeform_bind(wmOperatorType *ot)
 }
 
 /** \} */
+
+/* ------------------------------------------------------------------- */
+/** \name Toggle Value or Attribute Operator
+ * \{ */
+
+static int geometry_nodes_modifier_value_or_attribute_toggle_exec(bContext *C, wmOperator *op)
+{
+  Object *ob = ED_object_active_context(C);
+
+  char modifier_name[MAX_NAME];
+  RNA_string_get(op->ptr, "modifier_name", modifier_name);
+
+  NodesModifierData *nmd = (NodesModifierData *)BKE_modifiers_findby_name(ob, modifier_name);
+
+  if (nmd == NULL) {
+    return OPERATOR_CANCELLED;
+  }
+
+  char prop_path[MAX_NAME];
+  RNA_string_get(op->ptr, "prop_path", prop_path);
+
+  PointerRNA mod_ptr;
+  RNA_pointer_create(&ob->id, &RNA_Modifier, nmd, &mod_ptr);
+
+  const int old_value = RNA_int_get(&mod_ptr, prop_path);
+  const int new_value = !old_value;
+  RNA_int_set(&mod_ptr, prop_path, new_value);
+
+  DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
+  WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+  return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_geometry_nodes_modifier_value_or_attribute_toggle(wmOperatorType *ot)
+{
+  /* identifiers */
+  ot->name = "Toggle Geometry Nodes Modifier Value or Attribute Toggle";
+  ot->description = "Toggle between attribute and value";
+  ot->idname = "OBJECT_OT_geometry_nodes_modifier_value_or_attribute_toggle";
+
+  /* api callbacks */
+  ot->exec = geometry_nodes_modifier_value_or_attribute_toggle_exec;
+
+  /* flags */
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
+
+  RNA_def_string(ot->srna, "prop_path", NULL, 0, "Prop Path", "Prop path");
+  RNA_def_string(
+      ot->srna, "modifier_name", NULL, MAX_NAME, "Modifier", "Name of the modifier to edit");
+}
+
+/** \} */
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index a438c760d3b..81a03d769af 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -145,6 +145,7 @@ void ED_operatortypes_object(void)
   WM_operatortype_append(OBJECT_OT_skin_loose_mark_clear);
   WM_operatortype_append(OBJECT_OT_skin_radii_equalize);
   WM_operatortype_append(OBJECT_OT_skin_armature_create);
+  WM_operatortype_append(OBJECT_OT_geometry_nodes_modifier_value_or_attribute_toggle);
 
   /* grease pencil modifiers */
   WM_operatortype_append(OBJECT_OT_gpencil_modifier_add);
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index 3598057b7b0..57295f5e132 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -87,6 +87,8 @@
 #include "NOD_geometry_nodes_eval_log.hh"
 #include "NOD_node_tree_multi_function.hh"
 
+#include "WM_types.h"
+
 using blender::destruct_ptr;
 using blender::float3;
 using blender::FunctionRef;
@@ -1110,6 +1112,7 @@ static void modifyGeometrySet(ModifierData *md,
  * the node socket identifier for the property names, since they are unique, but also having
  * the correct label displayed in the UI. */
 static void draw_property_for_socket(uiLayout *layout,
+                                     NodesModifierData *nmd,
                                      PointerRNA *bmain_ptr,
                                      PointerRNA *md_ptr,
                                      const IDProperty *modifier_props,
@@ -1185,15 +1188,25 @@ static void draw_property_for_socket(uiLayout *layout,
     case SOCK_RGBA:
     case SOCK_INT:
     case SOCK_BOOLEAN: {
-      uiLayout *col = uiLayoutColumn(layout, false);
+      uiLayout *row = uiLayoutRow(layout, true);
       const int use_attribute = RNA_int_get(md_ptr, rna_path_use_attribute) != 0;
       if (use_attribute) {
-        uiItemR(col, md_ptr, rna_path_attribute, 0, socket.name, ICON_NONE);
+        uiItemR(row, md_ptr, rna_path_attribute, 0, socket.name, ICON_NONE);
       }
       else {
-        uiItemR(col, md_ptr, rna_path, 0, socket.name, ICON_NONE);
+        uiItemR(row, md_ptr, rna_path, 0, socket.name, ICON_NONE);
       }
-      uiItemR(col, md_ptr, rna_path_use_attribute, 0, "Use Attribute", ICON_NONE);
+      PointerRNA props;
+      uiItemFullO(row,
+                  "object.geometry_nodes_modifier_value_or_attribute_toggle",
+                  "",
+                  ICON_SPREADSHEET,
+                  nullptr,
+                  WM_OP_INVOKE_DEFAULT,
+                  0,
+                  &props);
+      RNA_string_set(&props, "modifier_name", nmd->modifier.name);
+      RNA_string_set(&props, "prop_path", rna_path_use_attribute);
       break;
     }
     default: {
@@ -1230,7 +1243,7 @@ static void panel_draw(const bContext *C, Panel *panel)
     RNA_main_pointer_create(bmain, &bmain_ptr);
 
     LISTBASE_FOREACH (bNodeSocket *, socket, &nmd->node_group->inputs) {
-      draw_property_for_socket(layout, &bmain_ptr, ptr, nmd->settings.properties, *socket);
+      draw_property_for_socket(layout, nmd, &bmain_ptr, ptr, nmd->settings.properties, *socket);
     }
   }



More information about the Bf-blender-cvs mailing list