[Bf-blender-cvs] [cd11dde40d1] temp-geometry-nodes-volume: Add helper methods for geometry set volume data

Hans Goudey noreply at git.blender.org
Mon Jan 18 20:21:57 CET 2021


Commit: cd11dde40d18c815ea469823b9eea2e77a8f210b
Author: Hans Goudey
Date:   Mon Jan 18 13:21:50 2021 -0600
Branches: temp-geometry-nodes-volume
https://developer.blender.org/rBcd11dde40d18c815ea469823b9eea2e77a8f210b

Add helper methods for geometry set volume data

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

M	source/blender/blenkernel/BKE_geometry_set.hh
M	source/blender/blenkernel/intern/geometry_set.cc
M	source/blender/nodes/geometry/nodes/node_geo_transform.cc

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

diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index ee7ed72b996..a4b3829ea73 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -321,10 +321,13 @@ struct GeometrySet {
   bool has_mesh() const;
   bool has_pointcloud() const;
   bool has_instances() const;
+  bool has_volume() const;
   const Mesh *get_mesh_for_read() const;
   const PointCloud *get_pointcloud_for_read() const;
+  const Volume *get_volume_for_read() const;
   Mesh *get_mesh_for_write();
   PointCloud *get_pointcloud_for_write();
+  Volume *get_volume_for_write();
 
   /* Utility methods for replacement. */
   void replace_mesh(Mesh *mesh, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc
index e95ca3157c6..ab3425b53d9 100644
--- a/source/blender/blenkernel/intern/geometry_set.cc
+++ b/source/blender/blenkernel/intern/geometry_set.cc
@@ -204,6 +204,13 @@ const PointCloud *GeometrySet::get_pointcloud_for_read() const
   return (component == nullptr) ? nullptr : component->get_for_read();
 }
 
+/* Returns a read-only volume or null. */
+const Volume *GeometrySet::get_volume_for_read() const
+{
+  const VolumeComponent *component = this->get_component_for_read<VolumeComponent>();
+  return (component == nullptr) ? nullptr : component->get_for_read();
+}
+
 /* Returns true when the geometry set has a point cloud component that has a point cloud. */
 bool GeometrySet::has_pointcloud() const
 {
@@ -218,6 +225,13 @@ bool GeometrySet::has_instances() const
   return component != nullptr && component->instances_amount() >= 1;
 }
 
+/* Returns true when the geometry set has a volume component that has a volume. */
+bool GeometrySet::has_volume() const
+{
+  const VolumeComponent *component = this->get_component_for_read<VolumeComponent>();
+  return component != nullptr && component->has_volume();
+}
+
 /* Create a new geometry set that only contains the given mesh. */
 GeometrySet GeometrySet::create_with_mesh(Mesh *mesh, GeometryOwnershipType ownership)
 {
@@ -265,6 +279,13 @@ PointCloud *GeometrySet::get_pointcloud_for_write()
   return component.get_for_write();
 }
 
+/* Returns a mutable volume or null. No ownership is transferred. */
+Volume *GeometrySet::get_volume_for_write()
+{
+  VolumeComponent &component = this->get_component_for_write<VolumeComponent>();
+  return component.get_for_write();
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/nodes/geometry/nodes/node_geo_transform.cc b/source/blender/nodes/geometry/nodes/node_geo_transform.cc
index bafd0e0fe84..091ae4b8bb4 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_transform.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_transform.cc
@@ -112,16 +112,11 @@ static void transform_instances(InstancesComponent &instances,
   }
 }
 
-static void transform_volume(VolumeComponent &component,
+static void transform_volume(Volume *volume,
                              const float3 translation,
                              const float3 rotation,
                              const float3 scale)
 {
-  Volume *volume = component.get_for_write();
-  if (volume == nullptr) {
-    return;
-  }
-
   // BKE_volume_load(volume, bmain);
 
   float matrix[4][4];
@@ -163,9 +158,9 @@ static void geo_node_transform_exec(GeoNodeExecParams params)
     transform_instances(instances, translation, rotation, scale);
   }
 
-  if (geometry_set.has<VolumeComponent>()) {
-    VolumeComponent &volume_component = geometry_set.get_component_for_write<VolumeComponent>();
-    transform_volume(volume_component, translation, rotation, scale);
+  if (geometry_set.has_volume()) {
+    Volume *volume = geometry_set.get_volume_for_write();
+    transform_volume(volume, translation, rotation, scale);
   }
 
   params.set_output("Geometry", std::move(geometry_set));



More information about the Bf-blender-cvs mailing list