[Bf-blender-cvs] [108fc6c8ac2] builtin-simulation-nodes: add data type property to Particle Attribute node

Jacques Lucke noreply at git.blender.org
Mon Mar 16 13:59:14 CET 2020


Commit: 108fc6c8ac2aad072831471c1e2ca9620f7bc588
Author: Jacques Lucke
Date:   Mon Mar 16 13:28:20 2020 +0100
Branches: builtin-simulation-nodes
https://developer.blender.org/rB108fc6c8ac2aad072831471c1e2ca9620f7bc588

add data type property to Particle Attribute node

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

M	source/blender/editors/space_node/drawnode.c
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/NOD_static_types.h
M	source/blender/nodes/simulation/nodes/node_sim_particle_attribute.cc

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

diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index f657a04b28f..373701b6603 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3132,12 +3132,22 @@ static void node_simulation_buts_particle_time_step_event(uiLayout *layout,
   uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
 }
 
+static void node_simulation_buts_particle_attribute(uiLayout *layout,
+                                                    bContext *UNUSED(C),
+                                                    PointerRNA *ptr)
+{
+  uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
+}
+
 static void node_simulation_set_butfunc(bNodeType *ntype)
 {
   switch (ntype->type) {
     case SIM_NODE_PARTICLE_TIME_STEP_EVENT:
       ntype->draw_buttons = node_simulation_buts_particle_time_step_event;
       break;
+    case SIM_NODE_PARTICLE_ATTRIBUTE:
+      ntype->draw_buttons = node_simulation_buts_particle_attribute;
+      break;
   }
 }
 
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 4296fee9ab3..48a5c46e560 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -91,6 +91,18 @@ static const EnumPropertyItem node_socket_type_items[] = {
     {0, NULL, 0, NULL, NULL},
 };
 
+static const EnumPropertyItem node_socket_particle_attribute_types[] = {
+    {SOCK_FLOAT, "FLOAT", 0, "Float", ""},
+    {SOCK_INT, "INT", 0, "Int", ""},
+    {SOCK_BOOLEAN, "BOOLEAN", 0, "Boolean", ""},
+    {SOCK_VECTOR, "VECTOR", 0, "Vector", ""},
+    {SOCK_RGBA, "RGBA", 0, "Color", ""},
+    {SOCK_OBJECT, "OBJECT", 0, "Object", ""},
+    {SOCK_IMAGE, "IMAGE", 0, "Image", ""},
+    {SOCK_SURFACE_HOOK, "SURFACE_HOOK", 0, "Surface Hook", ""},
+    {0, NULL, 0, NULL, NULL},
+};
+
 static const EnumPropertyItem node_quality_items[] = {
     {NTREE_QUALITY_HIGH, "HIGH", 0, "High", "High quality"},
     {NTREE_QUALITY_MEDIUM, "MEDIUM", 0, "Medium", "Medium quality"},
@@ -3664,6 +3676,15 @@ static void rna_ShaderNode_socket_update(Main *bmain, Scene *scene, PointerRNA *
   rna_Node_update(bmain, scene, ptr);
 }
 
+static void rna_SimulationNode_socket_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+  bNodeTree *ntree = (bNodeTree *)ptr->owner_id;
+  bNode *node = (bNode *)ptr->data;
+
+  nodeUpdate(ntree, node);
+  rna_Node_update(bmain, scene, ptr);
+}
+
 static void rna_CompositorNodeScale_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
   bNodeTree *ntree = (bNodeTree *)ptr->owner_id;
@@ -8009,6 +8030,20 @@ static void def_sim_particle_time_step_event(StructRNA *srna)
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
+static void def_sim_particle_attribute(StructRNA *srna)
+{
+  PropertyRNA *prop;
+
+  prop = RNA_def_property(srna, "data_type", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "custom1");
+  RNA_def_property_enum_items(prop, node_socket_particle_attribute_types);
+  RNA_def_property_ui_text(
+      prop,
+      "Data Type",
+      "Expected type of the attribute. A default value is returned if the type is not correct");
+  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_SimulationNode_socket_update");
+}
+
 /* -------------------------------------------------------------------------- */
 
 static void rna_def_shader_node(BlenderRNA *brna)
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index b9a8d1000ee..d0515df84f8 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -269,7 +269,7 @@ DefNode(SimulationNode, SIM_NODE_PARTICLE_MESH_EMITTER,  0,              "PARTIC
 DefNode(SimulationNode, SIM_NODE_PARTICLE_MESH_COLLISION_EVENT, 0,       "PARTICLE_MESH_COLLISION_EVENT", ParticleMeshCollisionEvent, "Particle Mesh Collision Event", "")
 DefNode(SimulationNode, SIM_NODE_EMIT_PARTICLES, 0,                      "EMIT_PARTICLES",      EmitParticles,      "Emit Particles",       "")
 DefNode(SimulationNode, SIM_NODE_SIMULATION_TIME, 0,                     "SIMULATION_TIME",     SimulationTime,     "Simulation Time",      "")
-DefNode(SimulationNode, SIM_NODE_PARTICLE_ATTRIBUTE, 0,                  "PARTICLE_ATTRIBUTE",  ParticleAttribute,  "Particle Attribute",   "")
+DefNode(SimulationNode, SIM_NODE_PARTICLE_ATTRIBUTE, def_sim_particle_attribute, "PARTICLE_ATTRIBUTE",  ParticleAttribute,  "Particle Attribute",   "")
 
 DefNode(FunctionNode, FN_NODE_COMBINE_XYZ, 0, "COMBINE_XYZ", CombineXYZ, "Combine XYZ", "")
 DefNode(FunctionNode, FN_NODE_SEPARATE_XYZ, 0, "SEPARATE_XYZ", SeparateXYZ, "Separate XYZ", "")
diff --git a/source/blender/nodes/simulation/nodes/node_sim_particle_attribute.cc b/source/blender/nodes/simulation/nodes/node_sim_particle_attribute.cc
index f828ac100bd..623f6e71d39 100644
--- a/source/blender/nodes/simulation/nodes/node_sim_particle_attribute.cc
+++ b/source/blender/nodes/simulation/nodes/node_sim_particle_attribute.cc
@@ -1,4 +1,5 @@
 #include "node_sim_util.h"
+#include "BLI_listbase.h"
 
 static bNodeSocketTemplate sim_node_particle_attribute_in[] = {
     {SOCK_STRING, N_("Name")},
@@ -6,10 +7,24 @@ static bNodeSocketTemplate sim_node_particle_attribute_in[] = {
 };
 
 static bNodeSocketTemplate sim_node_particle_attribute_out[] = {
-    {SOCK_FLOAT, N_("Value")},
+    {SOCK_FLOAT, N_("Float")},
+    {SOCK_INT, N_("Int")},
+    {SOCK_BOOLEAN, N_("Boolean")},
+    {SOCK_VECTOR, N_("Vector")},
+    {SOCK_RGBA, N_("Color")},
+    {SOCK_OBJECT, N_("Object")},
+    {SOCK_IMAGE, N_("Image")},
+    {SOCK_SURFACE_HOOK, N_("Surface Hook")},
     {-1, ""},
 };
 
+static void sim_node_particle_attribute_update(bNodeTree *UNUSED(ntree), bNode *node)
+{
+  LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
+    nodeSetSocketAvailability(sock, sock->type == node->custom1);
+  }
+}
+
 void register_node_type_sim_particle_attribute()
 {
   static bNodeType ntype;
@@ -17,5 +32,6 @@ void register_node_type_sim_particle_attribute()
   sim_node_type_base(&ntype, SIM_NODE_PARTICLE_ATTRIBUTE, "Particle Attribute", 0, 0);
   node_type_socket_templates(
       &ntype, sim_node_particle_attribute_in, sim_node_particle_attribute_out);
+  node_type_update(&ntype, sim_node_particle_attribute_update);
   nodeRegisterType(&ntype);
 }



More information about the Bf-blender-cvs mailing list