[Bf-blender-cvs] [5a9a16334c5] master: Geometry Nodes: support for geometry instancing

Jacques Lucke noreply at git.blender.org
Mon Sep 6 18:37:37 CEST 2021


Commit: 5a9a16334c573c4566dc9b2a314cf0d0ccdcb54f
Author: Jacques Lucke
Date:   Mon Sep 6 18:22:24 2021 +0200
Branches: master
https://developer.blender.org/rB5a9a16334c573c4566dc9b2a314cf0d0ccdcb54f

Geometry Nodes: support for geometry instancing

Previously, the Point Instance node in geometry nodes could only instance
existing objects or collections. The reason was that large parts of Blender
worked under the assumption that objects are the main unit of instancing.
Now we also want to instance geometry within an object, so a slightly larger
refactor was necessary.

This should not affect files that do not use the new kind of instances.

The main change is a redefinition of what "instanced data" is. Now, an
instances is a cow-object + object-data (the geometry). This can be nicely
seen in `struct DupliObject`. This allows the same object to generate
multiple geometries of different types which can be instanced individually.

A nice side effect of this refactor is that having multiple geometry components
is not a special case in the depsgraph object iterator anymore, because those
components are integrated with the `DupliObject` system.

Unfortunately, different systems that work with instances in Blender (e.g.
render engines and exporters) often work under the assumption that objects are
the main unit of instancing. So those have to be updated as well to be able to
handle the new instances. This patch updates Cycles, EEVEE and other viewport
engines. Exporters have not been updated yet. Some minimal (not master-ready)
changes to update the obj and alembic exporters can be found in P2336 and P2335.
Different file formats may want to handle these new instances in different ways.

For users, the only thing that changed is that the Point Instance node now
has a geometry mode.

This also fixes T88454.

Differential Revision: https://developer.blender.org/D11841

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

M	intern/cycles/blender/blender_curves.cpp
M	intern/cycles/blender/blender_geometry.cpp
M	intern/cycles/blender/blender_light.cpp
M	intern/cycles/blender/blender_mesh.cpp
M	intern/cycles/blender/blender_object.cpp
M	intern/cycles/blender/blender_sync.h
M	intern/cycles/blender/blender_util.h
M	intern/cycles/blender/blender_volume.cpp
M	source/blender/blenkernel/BKE_duplilist.h
M	source/blender/blenkernel/BKE_geometry_set.h
M	source/blender/blenkernel/BKE_geometry_set.hh
M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/geometry_component_instances.cc
M	source/blender/blenkernel/intern/geometry_set.cc
M	source/blender/blenkernel/intern/geometry_set_instances.cc
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/object_dupli.cc
M	source/blender/blenlib/BLI_user_counter.hh
M	source/blender/depsgraph/DEG_depsgraph_query.h
M	source/blender/depsgraph/intern/depsgraph_query_iter.cc
M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/intern/draw_manager.h
M	source/blender/editors/object/object_add.c
M	source/blender/editors/space_spreadsheet/spreadsheet_cell_value.hh
M	source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc
M	source/blender/editors/space_spreadsheet/spreadsheet_layout.cc
M	source/blender/editors/transform/transform_snap_object.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/intern/cycles/blender/blender_curves.cpp b/intern/cycles/blender/blender_curves.cpp
index 85d886fd850..6fe5ea41fff 100644
--- a/intern/cycles/blender/blender_curves.cpp
+++ b/intern/cycles/blender/blender_curves.cpp
@@ -526,8 +526,13 @@ bool BlenderSync::object_has_particle_hair(BL::Object b_ob)
 
 /* Old particle hair. */
 void BlenderSync::sync_particle_hair(
-    Hair *hair, BL::Mesh &b_mesh, BL::Object &b_ob, bool motion, int motion_step)
+    Hair *hair, BL::Mesh &b_mesh, BObjectInfo &b_ob_info, bool motion, int motion_step)
 {
+  if (!b_ob_info.is_real_object_data()) {
+    return;
+  }
+  BL::Object b_ob = b_ob_info.real_object;
+
   /* obtain general settings */
   if (b_ob.mode() == b_ob.mode_PARTICLE_EDIT || b_ob.mode() == b_ob.mode_EDIT) {
     return;
@@ -788,10 +793,10 @@ static void export_hair_curves_motion(Hair *hair, BL::Hair b_hair, int motion_st
 }
 
 /* Hair object. */
-void BlenderSync::sync_hair(Hair *hair, BL::Object &b_ob, bool motion, int motion_step)
+void BlenderSync::sync_hair(Hair *hair, BObjectInfo &b_ob_info, bool motion, int motion_step)
 {
   /* Convert Blender hair to Cycles curves. */
-  BL::Hair b_hair(b_ob.data());
+  BL::Hair b_hair(b_ob_info.object_data);
   if (motion) {
     export_hair_curves_motion(hair, b_hair, motion_step);
   }
@@ -800,16 +805,16 @@ void BlenderSync::sync_hair(Hair *hair, BL::Object &b_ob, bool motion, int motio
   }
 }
 #else
-void BlenderSync::sync_hair(Hair *hair, BL::Object &b_ob, bool motion, int motion_step)
+void BlenderSync::sync_hair(Hair *hair, BObjectInfo &b_ob_info, bool motion, int motion_step)
 {
   (void)hair;
-  (void)b_ob;
+  (void)b_ob_info;
   (void)motion;
   (void)motion_step;
 }
 #endif
 
-void BlenderSync::sync_hair(BL::Depsgraph b_depsgraph, BL::Object b_ob, Hair *hair)
+void BlenderSync::sync_hair(BL::Depsgraph b_depsgraph, BObjectInfo &b_ob_info, Hair *hair)
 {
   /* make a copy of the shaders as the caller in the main thread still need them for syncing the
    * attributes */
@@ -819,19 +824,19 @@ void BlenderSync::sync_hair(BL::Depsgraph b_depsgraph, BL::Object b_ob, Hair *ha
   new_hair.set_used_shaders(used_shaders);
 
   if (view_layer.use_hair) {
-    if (b_ob.type() == BL::Object::type_HAIR) {
+    if (b_ob_info.object_data.is_a(&RNA_Hair)) {
       /* Hair object. */
-      sync_hair(&new_hair, b_ob, false);
+      sync_hair(&new_hair, b_ob_info, false);
     }
     else {
       /* Particle hair. */
       bool need_undeformed = new_hair.need_attribute(scene, ATTR_STD_GENERATED);
       BL::Mesh b_mesh = object_to_mesh(
-          b_data, b_ob, b_depsgraph, need_undeformed, Mesh::SUBDIVISION_NONE);
+          b_data, b_ob_info, b_depsgraph, need_undeformed, Mesh::SUBDIVISION_NONE);
 
       if (b_mesh) {
-        sync_particle_hair(&new_hair, b_mesh, b_ob, false);
-        free_object_to_mesh(b_data, b_ob, b_mesh);
+        sync_particle_hair(&new_hair, b_mesh, b_ob_info, false);
+        free_object_to_mesh(b_data, b_ob_info, b_mesh);
       }
     }
   }
@@ -859,7 +864,7 @@ void BlenderSync::sync_hair(BL::Depsgraph b_depsgraph, BL::Object b_ob, Hair *ha
 }
 
 void BlenderSync::sync_hair_motion(BL::Depsgraph b_depsgraph,
-                                   BL::Object b_ob,
+                                   BObjectInfo &b_ob_info,
                                    Hair *hair,
                                    int motion_step)
 {
@@ -869,18 +874,19 @@ void BlenderSync::sync_hair_motion(BL::Depsgraph b_depsgraph,
   }
 
   /* Export deformed coordinates. */
-  if (ccl::BKE_object_is_deform_modified(b_ob, b_scene, preview)) {
-    if (b_ob.type() == BL::Object::type_HAIR) {
+  if (ccl::BKE_object_is_deform_modified(b_ob_info, b_scene, preview)) {
+    if (b_ob_info.object_data.is_a(&RNA_Hair)) {
       /* Hair object. */
-      sync_hair(hair, b_ob, true, motion_step);
+      sync_hair(hair, b_ob_info, true, motion_step);
       return;
     }
     else {
       /* Particle hair. */
-      BL::Mesh b_mesh = object_to_mesh(b_data, b_ob, b_depsgraph, false, Mesh::SUBDIVISION_NONE);
+      BL::Mesh b_mesh = object_to_mesh(
+          b_data, b_ob_info, b_depsgraph, false, Mesh::SUBDIVISION_NONE);
       if (b_mesh) {
-        sync_particle_hair(hair, b_mesh, b_ob, true, motion_step);
-        free_object_to_mesh(b_data, b_ob, b_mesh);
+        sync_particle_hair(hair, b_mesh, b_ob_info, true, motion_step);
+        free_object_to_mesh(b_data, b_ob_info, b_mesh);
         return;
       }
     }
diff --git a/intern/cycles/blender/blender_geometry.cpp b/intern/cycles/blender/blender_geometry.cpp
index a009018f357..acc089a286c 100644
--- a/intern/cycles/blender/blender_geometry.cpp
+++ b/intern/cycles/blender/blender_geometry.cpp
@@ -29,13 +29,15 @@
 
 CCL_NAMESPACE_BEGIN
 
-static Geometry::Type determine_geom_type(BL::Object &b_ob, bool use_particle_hair)
+static Geometry::Type determine_geom_type(BObjectInfo &b_ob_info, bool use_particle_hair)
 {
-  if (b_ob.type() == BL::Object::type_HAIR || use_particle_hair) {
+  if (b_ob_info.object_data.is_a(&RNA_Hair) || use_particle_hair) {
     return Geometry::HAIR;
   }
 
-  if (b_ob.type() == BL::Object::type_VOLUME || object_fluid_gas_domain_find(b_ob)) {
+  if (b_ob_info.object_data.is_a(&RNA_Volume) ||
+      (b_ob_info.object_data == b_ob_info.real_object.data() &&
+       object_fluid_gas_domain_find(b_ob_info.real_object))) {
     return Geometry::VOLUME;
   }
 
@@ -71,20 +73,17 @@ array<Node *> BlenderSync::find_used_shaders(BL::Object &b_ob)
 }
 
 Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph,
-                                     BL::Object &b_ob,
-                                     BL::Object &b_ob_instance,
+                                     BObjectInfo &b_ob_info,
                                      bool object_updated,
                                      bool use_particle_hair,
                                      TaskPool *task_pool)
 {
   /* Test if we can instance or if the object is modified. */
-  BL::ID b_ob_data = b_ob.data();
-  BL::ID b_key_id = (BKE_object_is_modified(b_ob)) ? b_ob_instance : b_ob_data;
-  Geometry::Type geom_type = determine_geom_type(b_ob, use_particle_hair);
-  GeometryKey key(b_key_id.ptr.data, geom_type);
+  Geometry::Type geom_type = determine_geom_type(b_ob_info, use_particle_hair);
+  GeometryKey key(b_ob_info.object_data, geom_type);
 
   /* Find shader indices. */
-  array<Node *> used_shaders = find_used_shaders(b_ob);
+  array<Node *> used_shaders = find_used_shaders(b_ob_info.iter_object);
 
   /* Ensure we only sync instanced geometry once. */
   Geometry *geom = geometry_map.find(key);
@@ -111,7 +110,7 @@ Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph,
   }
   else {
     /* Test if we need to update existing geometry. */
-    sync = geometry_map.update(geom, b_key_id);
+    sync = geometry_map.update(geom, b_ob_info.object_data);
   }
 
   if (!sync) {
@@ -144,7 +143,7 @@ Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph,
 
   geometry_synced.insert(geom);
 
-  geom->name = ustring(b_ob_data.name().c_str());
+  geom->name = ustring(b_ob_info.object_data.name().c_str());
 
   /* Store the shaders immediately for the object attribute code. */
   geom->set_used_shaders(used_shaders);
@@ -153,19 +152,19 @@ Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph,
     if (progress.get_cancel())
       return;
 
-    progress.set_sync_status("Synchronizing object", b_ob.name());
+    progress.set_sync_status("Synchronizing object", b_ob_info.real_object.name());
 
     if (geom_type == Geometry::HAIR) {
       Hair *hair = static_cast<Hair *>(geom);
-      sync_hair(b_depsgraph, b_ob, hair);
+      sync_hair(b_depsgraph, b_ob_info, hair);
     }
     else if (geom_type == Geometry::VOLUME) {
       Volume *volume = static_cast<Volume *>(geom);
-      sync_volume(b_ob, volume);
+      sync_volume(b_ob_info, volume);
     }
     else {
       Mesh *mesh = static_cast<Mesh *>(geom);
-      sync_mesh(b_depsgraph, b_ob, mesh);
+      sync_mesh(b_depsgraph, b_ob_info, mesh);
     }
   };
 
@@ -181,7 +180,7 @@ Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph,
 }
 
 void BlenderSync::sync_geometry_motion(BL::Depsgraph &b_depsgraph,
-                                       BL::Object &b_ob,
+                                       BObjectInfo &b_ob_info,
                                        Object *object,
                                        float motion_time,
                                        bool use_particle_hair,
@@ -210,16 +209,17 @@ void BlenderSync::sync_geometry_motion(BL::Depsgraph &b_depsgraph,
     if (progress.get_cancel())
       return;
 
-    if (b_ob.type() == BL::Object::type_HAIR || use_particle_hair) {
+    if (b_ob_info.object_data.is_a(&RNA_Hair) || use_particle_hair) {
       Hair *hair = static_cast<Hair *>(geom);
-      sync_hair_motion(b_depsgraph, b_ob, hair, motion_step);
+      sync_hair_motion(b_depsgraph, b_ob_info, hair, motion_step);
     }
-    else if (b_ob.type() == BL::Object::type_VOLUME || object_fluid_gas_domain_find(b_ob)) {
+    else if (b_ob_info.object_data.is_a(&RNA_Volume) ||
+             object_fluid_gas_domain_find(b_ob_info.real_object)) {
       /* No volume motion blur support yet. */
     }
     else {
       Mesh *mesh = static_cast<Mesh *>(geom);
-      sync_mesh_motion(b_depsgraph, b_ob, mesh, motion_step);
+      sync_mesh_motion(b_depsgraph, b_ob_info, mesh, motion_step);
     }
   };
 
diff --git a/intern/cycles/blender/blender_light.cpp b/intern/cycles/blender/blender_light.cpp
index 50cd9e3db5c..542028f4b2f 100644
--- a/intern/cycles/blender/blender_light.cpp
+++ b/intern/cycles/blender/blender_light.cpp
@@ -27,15 +27,14 @@ CCL_NAMESPACE_BEGIN
 
 void BlenderSync::sync_light(BL::Object &b_parent,
                              int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
-                             BL::Object &b_ob,
-                             BL::Object &b_ob_instance,
+                             BObjectInfo &b_ob_info,
                              int random_id,
                              Transform &tfm,
                              bool *use_portal)
 {
   /* test if we need to sync */
- 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list