[Bf-blender-cvs] [b844caca6d0] geometry-nodes: Geometry Nodes: Add pointcloud support to geometry class

Hans Goudey noreply at git.blender.org
Tue Oct 27 05:00:40 CET 2020


Commit: b844caca6d074d5fbaf2a2e87b26cf39be8ecbd6
Author: Hans Goudey
Date:   Mon Oct 26 22:41:57 2020 -0500
Branches: geometry-nodes
https://developer.blender.org/rBb844caca6d074d5fbaf2a2e87b26cf39be8ecbd6

Geometry Nodes: Add pointcloud support to geometry class

This adds another set of the same mesh functions but for pointclouds.
There are probably better ways to generalize this functionality, but that
may have to be rethought in the future anyway if we want to store
multiple of each type. And anyway it's handy to have a specific set of
"pointcloud" functions available in the node implementations.

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

M	source/blender/blenkernel/BKE_geometry.hh
M	source/blender/blenkernel/intern/geometry.cc

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

diff --git a/source/blender/blenkernel/BKE_geometry.hh b/source/blender/blenkernel/BKE_geometry.hh
index a90a1f433f2..1ad34a8a3fb 100644
--- a/source/blender/blenkernel/BKE_geometry.hh
+++ b/source/blender/blenkernel/BKE_geometry.hh
@@ -26,6 +26,7 @@
 #include "BLI_hash.hh"
 
 struct Mesh;
+struct PointCloud;
 
 namespace blender::bke {
 
@@ -43,11 +44,14 @@ class Geometry {
    * above 1, the geometry is immutable. */
   std::atomic<int> users_ = 1;
 
-  /* Only contains a mesh for now. */
   Mesh *mesh_ = nullptr;
   /* Determines if the mesh is freed when the geometry does not want to reference it anymore. */
   bool mesh_owned_ = false;
 
+  PointCloud *pointcloud_ = nullptr;
+  /* True if the pointcloud is freed with the geometry. */
+  bool pointcloud_owned_ = false;
+
  public:
   Geometry() = default;
   Geometry(const Geometry &other);
@@ -69,6 +73,14 @@ class Geometry {
   Mesh *mesh_get_for_read();
   Mesh *mesh_get_for_write();
   Mesh *mesh_release();
+
+  bool pointcloud_available() const;
+  void pointcloud_set_and_keep_ownership(PointCloud *pointcloud);
+  void pointcloud_set_and_transfer_ownership(PointCloud *pointcloud);
+  void pointcloud_reset();
+  PointCloud *pointcloud_get_for_read();
+  PointCloud *pointcloud_get_for_write();
+  PointCloud *pointcloud_release();
 };
 
 /**
diff --git a/source/blender/blenkernel/intern/geometry.cc b/source/blender/blenkernel/intern/geometry.cc
index 58ec71108da..2282b544b78 100644
--- a/source/blender/blenkernel/intern/geometry.cc
+++ b/source/blender/blenkernel/intern/geometry.cc
@@ -17,6 +17,7 @@
 #include "BKE_geometry.hh"
 #include "BKE_lib_id.h"
 #include "BKE_mesh.h"
+#include "BKE_pointcloud.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -30,11 +31,17 @@ Geometry::Geometry(const Geometry &other)
     /* Own the new mesh, regardless of whether the original mesh was owned. */
     mesh_owned_ = true;
   }
+  if (other.pointcloud_ != nullptr) {
+    pointcloud_ = BKE_pointcloud_copy_for_eval(other.pointcloud_, false);
+    /* Own the new pointcloud, regardless of whether the original mesh was owned. */
+    pointcloud_owned_ = true;
+  }
 }
 
 Geometry::~Geometry()
 {
   this->mesh_reset();
+  this->pointcloud_reset();
 }
 
 void Geometry::user_add()
@@ -64,6 +71,10 @@ bool Geometry::mesh_available() const
 {
   return mesh_ != nullptr;
 }
+bool Geometry::pointcloud_available() const
+{
+  return pointcloud_ != nullptr;
+}
 
 /**
  * Replace the mesh in the geometry. The caller remains the owner of the given mesh and is
@@ -76,6 +87,13 @@ void Geometry::mesh_set_and_keep_ownership(Mesh *mesh)
   mesh_ = mesh;
   mesh_owned_ = false;
 }
+void Geometry::pointcloud_set_and_keep_ownership(PointCloud *pointcloud)
+{
+  BLI_assert(this->is_mutable());
+  this->pointcloud_reset();
+  pointcloud_ = pointcloud;
+  pointcloud_owned_ = false;
+}
 
 /**
  * Replace the mesh in the geometry. The geometry becomes responsible for freeing the mesh.
@@ -87,6 +105,13 @@ void Geometry::mesh_set_and_transfer_ownership(Mesh *mesh)
   mesh_ = mesh;
   mesh_owned_ = true;
 }
+void Geometry::pointcloud_set_and_transfer_ownership(PointCloud *pointcloud)
+{
+  BLI_assert(this->is_mutable());
+  this->pointcloud_reset();
+  pointcloud_ = pointcloud;
+  pointcloud_owned_ = true;
+}
 
 /**
  * Clear any mesh data the geometry might have.
@@ -101,6 +126,16 @@ void Geometry::mesh_reset()
     mesh_ = nullptr;
   }
 }
+void Geometry::pointcloud_reset()
+{
+  BLI_assert(this->is_mutable());
+  if (pointcloud_ != nullptr) {
+    if (pointcloud_owned_) {
+      BKE_id_free(nullptr, pointcloud_);
+    }
+    pointcloud_ = nullptr;
+  }
+}
 
 /**
  * Get the mesh from the geometry. This mesh should only be read and not modified. This can be used
@@ -111,6 +146,10 @@ Mesh *Geometry::mesh_get_for_read()
 {
   return mesh_;
 }
+PointCloud *Geometry::pointcloud_get_for_read()
+{
+  return pointcloud_;
+}
 
 /**
  * Get the mesh from the geometry. The caller is allowed to modify the mesh. This method can only
@@ -122,6 +161,11 @@ Mesh *Geometry::mesh_get_for_write()
   BLI_assert(this->is_mutable());
   return mesh_;
 }
+PointCloud *Geometry::pointcloud_get_for_write()
+{
+  BLI_assert(this->is_mutable());
+  return pointcloud_;
+}
 
 /**
  * Return the mesh in the geometry and remove it. This only works on mutable geometries.
@@ -134,6 +178,13 @@ Mesh *Geometry::mesh_release()
   mesh_ = nullptr;
   return mesh;
 }
+PointCloud *Geometry::pointcloud_release()
+{
+  BLI_assert(this->is_mutable());
+  PointCloud *pointcloud = pointcloud_;
+  pointcloud_ = nullptr;
+  return pointcloud;
+}
 
 /**
  * Changes the given pointer so that it points to a mutable geometry. This might do nothing, create



More information about the Bf-blender-cvs mailing list