[Bf-blender-cvs] [c09988941dc] temp-geometry-nodes-volume: initial volume component

Jacques Lucke noreply at git.blender.org
Mon Jan 18 16:36:46 CET 2021


Commit: c09988941dc8584e035fb6d416f64dd84bfd1544
Author: Jacques Lucke
Date:   Mon Jan 18 15:03:45 2021 +0100
Branches: temp-geometry-nodes-volume
https://developer.blender.org/rBc09988941dc8584e035fb6d416f64dd84bfd1544

initial volume component

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

M	source/blender/blenkernel/BKE_geometry_set.hh
M	source/blender/blenkernel/intern/geometry_set.cc

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

diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index 391bd243edf..ee7ed72b996 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -36,6 +36,7 @@ struct Collection;
 struct Mesh;
 struct Object;
 struct PointCloud;
+struct Volume;
 
 /* Each geometry component has a specific type. The type determines what kind of data the component
  * stores. Functions modifying a geometry will usually just modify a subset of the component types.
@@ -44,6 +45,7 @@ enum class GeometryComponentType {
   Mesh = 0,
   PointCloud = 1,
   Instances = 2,
+  Volume = 3,
 };
 
 enum class GeometryOwnershipType {
@@ -462,3 +464,25 @@ class InstancesComponent : public GeometryComponent {
 
   static constexpr inline GeometryComponentType static_type = GeometryComponentType::Instances;
 };
+
+/** A geometry component that stores volume grids. */
+class VolumeComponent : public GeometryComponent {
+ private:
+  Volume *volume_ = nullptr;
+  GeometryOwnershipType ownership_ = GeometryOwnershipType::Owned;
+
+ public:
+  VolumeComponent();
+  ~VolumeComponent();
+  GeometryComponent *copy() const override;
+
+  void clear();
+  bool has_volume() const;
+  void replace(Volume *volume, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
+  Volume *release();
+
+  const Volume *get_for_read() const;
+  Volume *get_for_write();
+
+  static constexpr inline GeometryComponentType static_type = GeometryComponentType::Volume;
+};
diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc
index 5d2b82dcc5f..e95ca3157c6 100644
--- a/source/blender/blenkernel/intern/geometry_set.cc
+++ b/source/blender/blenkernel/intern/geometry_set.cc
@@ -19,6 +19,7 @@
 #include "BKE_mesh.h"
 #include "BKE_mesh_wrapper.h"
 #include "BKE_pointcloud.h"
+#include "BKE_volume.h"
 
 #include "DNA_object_types.h"
 
@@ -51,6 +52,8 @@ GeometryComponent *GeometryComponent::create(GeometryComponentType component_typ
       return new PointCloudComponent();
     case GeometryComponentType::Instances:
       return new InstancesComponent();
+    case GeometryComponentType::Volume:
+      return new VolumeComponent();
   }
   BLI_assert(false);
   return nullptr;
@@ -556,6 +559,78 @@ bool InstancesComponent::is_empty() const
 
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name Volume Component
+ * \{ */
+
+VolumeComponent::VolumeComponent() : GeometryComponent(GeometryComponentType::Volume)
+{
+}
+
+VolumeComponent::~VolumeComponent()
+{
+  this->clear();
+}
+
+GeometryComponent *VolumeComponent::copy() const
+{
+  VolumeComponent *new_component = new VolumeComponent();
+  if (volume_ != nullptr) {
+    new_component->volume_ = BKE_volume_copy_for_eval(volume_, false);
+    new_component->ownership_ = GeometryOwnershipType::Owned;
+  }
+  return new_component;
+}
+
+void VolumeComponent::clear()
+{
+  BLI_assert(this->is_mutable());
+  if (volume_ != nullptr) {
+    if (ownership_ == GeometryOwnershipType::Owned) {
+      BKE_id_free(nullptr, volume_);
+    }
+    volume_ = nullptr;
+  }
+}
+
+bool VolumeComponent::has_volume() const
+{
+  return volume_ != nullptr;
+}
+
+void VolumeComponent::replace(Volume *volume, GeometryOwnershipType ownership)
+{
+  BLI_assert(this->is_mutable());
+  this->clear();
+  volume_ = volume;
+  ownership_ = ownership;
+}
+
+Volume *VolumeComponent::release()
+{
+  BLI_assert(this->is_mutable());
+  Volume *volume = volume_;
+  volume_ = nullptr;
+  return volume;
+}
+
+const Volume *VolumeComponent::get_for_read() const
+{
+  return volume_;
+}
+
+Volume *VolumeComponent::get_for_write()
+{
+  BLI_assert(this->is_mutable());
+  if (ownership_ == GeometryOwnershipType::ReadOnly) {
+    volume_ = BKE_volume_copy_for_eval(volume_, false);
+    ownership_ = GeometryOwnershipType::Owned;
+  }
+  return volume_;
+}
+
+/** \} */
+
 /* -------------------------------------------------------------------- */
 /** \name C API
  * \{ */



More information about the Bf-blender-cvs mailing list