[Bf-blender-cvs] [526373b8970] master: Cleanup - Point Instance: Use own DNA struct

Dalai Felinto noreply at git.blender.org
Fri Jan 22 11:48:22 CET 2021


Commit: 526373b89705b0401f41d31e7176498531f3f986
Author: Dalai Felinto
Date:   Fri Jan 22 10:49:20 2021 +0100
Branches: master
https://developer.blender.org/rB526373b89705b0401f41d31e7176498531f3f986

Cleanup - Point Instance: Use own DNA struct

We will need to expand this node soon to add weight/count for different
elements inside the collection. For that it is better to have the node
to use its own DNA.

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

M	source/blender/blenkernel/BKE_blender_version.h
M	source/blender/blenloader/intern/versioning_290.c
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/geometry/nodes/node_geo_point_instance.cc

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

diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
index e64cb1b0452..8854949fa11 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -39,7 +39,7 @@ extern "C" {
 
 /* Blender file format version. */
 #define BLENDER_FILE_VERSION BLENDER_VERSION
-#define BLENDER_FILE_SUBVERSION 2
+#define BLENDER_FILE_SUBVERSION 3
 
 /* Minimum Blender version that supports reading file written with the current
  * version. Older Blender versions will test this and show a warning if the file
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index 627eecddeaa..555b2453c62 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -1611,6 +1611,24 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
     }
   }
 
+  if (!MAIN_VERSION_ATLEAST(bmain, 293, 3)) {
+    FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
+      if (ntree->type != NTREE_GEOMETRY) {
+        continue;
+      }
+      LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+        if (node->type == GEO_NODE_POINT_INSTANCE && node->storage == NULL) {
+          NodeGeometryPointInstance *data = (NodeGeometryPointInstance *)MEM_callocN(
+              sizeof(NodeGeometryPointInstance), __func__);
+          data->instance_type = node->custom1;
+          data->flag = (node->custom2 ? 0 : GEO_NODE_POINT_INSTANCE_WHOLE_COLLECTION);
+          node->storage = data;
+        }
+      }
+    }
+    FOREACH_NODETREE_END;
+  }
+
   /**
    * Versioning code until next subversion bump goes here.
    *
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 7d18ff3ed58..4dba856b87b 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1174,6 +1174,15 @@ typedef struct NodeGeometryObjectInfo {
   char _pad[7];
 } NodeGeometryObjectInfo;
 
+typedef struct NodeGeometryPointInstance {
+  /* GeometryNodePointInstanceType. */
+  uint8_t instance_type;
+  /* GeometryNodePointInstanceFlag. */
+  uint8_t flag;
+
+  char _pad[6];
+} NodeGeometryPointInstance;
+
 /* script node mode */
 #define NODE_SCRIPT_INTERNAL 0
 #define NODE_SCRIPT_EXTERNAL 1
@@ -1586,6 +1595,10 @@ typedef enum GeometryNodePointInstanceType {
   GEO_NODE_POINT_INSTANCE_TYPE_COLLECTION = 1,
 } GeometryNodePointInstanceType;
 
+typedef enum GeometryNodePointInstanceFlag {
+  GEO_NODE_POINT_INSTANCE_WHOLE_COLLECTION = (1 << 0),
+} GeometryNodePointInstanceFlag;
+
 typedef enum GeometryNodeAttributeInputMode {
   GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE = 0,
   GEO_NODE_ATTRIBUTE_INPUT_FLOAT = 1,
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 1a83dcf674c..355b1360ab0 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -8648,16 +8648,17 @@ static void def_geo_point_instance(StructRNA *srna)
   };
 
   PropertyRNA *prop;
+  RNA_def_struct_sdna_from(srna, "NodeGeometryPointInstance", "storage");
 
   prop = RNA_def_property(srna, "instance_type", PROP_ENUM, PROP_NONE);
-  RNA_def_property_enum_sdna(prop, NULL, "custom1");
+  RNA_def_property_enum_sdna(prop, NULL, "instance_type");
   RNA_def_property_enum_items(prop, instance_type_items);
   RNA_def_property_enum_default(prop, GEO_NODE_POINT_INSTANCE_TYPE_OBJECT);
   RNA_def_property_ui_text(prop, "Instance Type", "");
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
 
   prop = RNA_def_property(srna, "use_whole_collection", PROP_BOOLEAN, PROP_NONE);
-  RNA_def_property_boolean_negative_sdna(prop, NULL, "custom2", 1);
+  RNA_def_property_boolean_sdna(prop, NULL, "flag", GEO_NODE_POINT_INSTANCE_WHOLE_COLLECTION);
   RNA_def_property_ui_text(prop, "Whole Collection", "Instance entire collection on each point");
   RNA_def_property_update(prop, 0, "rna_Node_socket_update");
 }
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc b/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
index d9e69adb860..54d37661d35 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
@@ -47,8 +47,10 @@ static void geo_node_point_instance_update(bNodeTree *UNUSED(tree), bNode *node)
   bNodeSocket *collection_socket = object_socket->next;
   bNodeSocket *seed_socket = collection_socket->next;
 
-  GeometryNodePointInstanceType type = (GeometryNodePointInstanceType)node->custom1;
-  const bool use_whole_collection = node->custom2 == 0;
+  NodeGeometryPointInstance *node_storage = (NodeGeometryPointInstance *)node->storage;
+  GeometryNodePointInstanceType type = (GeometryNodePointInstanceType)node_storage->instance_type;
+  const bool use_whole_collection = (node_storage->flag &
+                                     GEO_NODE_POINT_INSTANCE_WHOLE_COLLECTION) != 0;
 
   nodeSetSocketAvailability(object_socket, type == GEO_NODE_POINT_INSTANCE_TYPE_OBJECT);
   nodeSetSocketAvailability(collection_socket, type == GEO_NODE_POINT_INSTANCE_TYPE_COLLECTION);
@@ -79,6 +81,8 @@ static void get_instanced_data__collection(
     MutableSpan<std::optional<InstancedData>> r_instances_data)
 {
   const bNode &node = params.node();
+  NodeGeometryPointInstance *node_storage = (NodeGeometryPointInstance *)node.storage;
+
   bke::PersistentCollectionHandle collection_handle =
       params.get_input<bke::PersistentCollectionHandle>("Collection");
   Collection *collection = params.handle_map().lookup(collection_handle);
@@ -86,7 +90,8 @@ static void get_instanced_data__collection(
     return;
   }
 
-  const bool use_whole_collection = node.custom2 == 0;
+  const bool use_whole_collection = (node_storage->flag &
+                                     GEO_NODE_POINT_INSTANCE_WHOLE_COLLECTION) != 0;
   if (use_whole_collection) {
     InstancedData instance;
     instance.type = INSTANCE_DATA_TYPE_COLLECTION;
@@ -128,8 +133,9 @@ static Array<std::optional<InstancedData>> get_instanced_data(const GeoNodeExecP
                                                               const int amount)
 {
   const bNode &node = params.node();
-  const GeometryNodePointInstanceType type = (GeometryNodePointInstanceType)node.custom1;
-
+  NodeGeometryPointInstance *node_storage = (NodeGeometryPointInstance *)node.storage;
+  const GeometryNodePointInstanceType type = (GeometryNodePointInstanceType)
+                                                 node_storage->instance_type;
   Array<std::optional<InstancedData>> instances_data(amount);
 
   switch (type) {
@@ -187,6 +193,16 @@ static void geo_node_point_instance_exec(GeoNodeExecParams params)
 
   params.set_output("Geometry", std::move(geometry_set_out));
 }
+
+static void geo_node_point_instance_init(bNodeTree *UNUSED(tree), bNode *node)
+{
+  NodeGeometryPointInstance *data = (NodeGeometryPointInstance *)MEM_callocN(
+      sizeof(NodeGeometryPointInstance), __func__);
+  data->instance_type = GEO_NODE_POINT_INSTANCE_TYPE_OBJECT;
+  data->flag |= GEO_NODE_POINT_INSTANCE_WHOLE_COLLECTION;
+  node->storage = data;
+}
+
 }  // namespace blender::nodes
 
 void register_node_type_geo_point_instance()
@@ -195,6 +211,9 @@ void register_node_type_geo_point_instance()
 
   geo_node_type_base(&ntype, GEO_NODE_POINT_INSTANCE, "Point Instance", NODE_CLASS_GEOMETRY, 0);
   node_type_socket_templates(&ntype, geo_node_point_instance_in, geo_node_point_instance_out);
+  node_type_init(&ntype, blender::nodes::geo_node_point_instance_init);
+  node_type_storage(
+      &ntype, "NodeGeometryPointInstance", node_free_standard_storage, node_copy_standard_storage);
   node_type_update(&ntype, blender::nodes::geo_node_point_instance_update);
   ntype.geometry_node_execute = blender::nodes::geo_node_point_instance_exec;
   nodeRegisterType(&ntype);



More information about the Bf-blender-cvs mailing list