[Bf-blender-cvs] [c90ea7284fe] temp-modifiers-instancing: initial instances component

Jacques Lucke noreply at git.blender.org
Tue Nov 10 16:39:09 CET 2020


Commit: c90ea7284fe0faff171f860233de974beed4f5c1
Author: Jacques Lucke
Date:   Tue Nov 10 13:00:57 2020 +0100
Branches: temp-modifiers-instancing
https://developer.blender.org/rBc90ea7284fe0faff171f860233de974beed4f5c1

initial instances 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 a625158367b..dedbe9c9731 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -23,6 +23,7 @@
 #include <atomic>
 #include <iostream>
 
+#include "BLI_float3.hh"
 #include "BLI_hash.hh"
 #include "BLI_map.hh"
 #include "BLI_user_counter.hh"
@@ -31,6 +32,7 @@
 
 struct Mesh;
 struct PointCloud;
+struct Object;
 
 namespace blender::bke {
 
@@ -43,6 +45,7 @@ using GeometrySetPtr = UserCounter<class GeometrySet>;
 enum class GeometryComponentType {
   Mesh,
   PointCloud,
+  Instances,
 };
 
 }  // namespace blender::bke
@@ -190,6 +193,21 @@ class PointCloudComponent : public GeometryComponent {
   static constexpr inline GeometryComponentType type = GeometryComponentType::PointCloud;
 };
 
+/** A geometry component that stores instances. */
+class InstancesComponent : public GeometryComponent {
+ private:
+  Vector<float3> positions_;
+  Object *instanced_object_ = nullptr;
+
+ public:
+  ~InstancesComponent() = default;
+  GeometryComponent *copy() const override;
+
+  void replace(Vector<float3> positions, Object *instanced_object);
+
+  static constexpr inline GeometryComponentType type = GeometryComponentType::Instances;
+};
+
 inline GeometrySetC *wrap(blender::bke::GeometrySet *geometry_set)
 {
   return reinterpret_cast<GeometrySetC *>(geometry_set);
diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc
index 5e303dd53bd..f096e624d52 100644
--- a/source/blender/blenkernel/intern/geometry_set.cc
+++ b/source/blender/blenkernel/intern/geometry_set.cc
@@ -38,6 +38,8 @@ GeometryComponent *GeometryComponent::create(GeometryComponentType component_typ
       return new MeshComponent();
     case GeometryComponentType::PointCloud:
       return new PointCloudComponent();
+    case GeometryComponentType::Instances:
+      return new InstancesComponent();
   }
   BLI_assert(false);
   return nullptr;
@@ -376,6 +378,26 @@ PointCloud *PointCloudComponent::get_for_write()
 
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name Instances Component
+ * \{ */
+
+GeometryComponent *InstancesComponent::copy() const
+{
+  InstancesComponent *new_component = new InstancesComponent();
+  new_component->positions_ = positions_;
+  new_component->instanced_object_ = instanced_object_;
+  return new_component;
+}
+
+void InstancesComponent::replace(Vector<float3> positions, Object *instanced_object)
+{
+  positions_ = std::move(positions);
+  instanced_object_ = instanced_object;
+}
+
+/** \} */
+
 }  // namespace blender::bke
 
 /* -------------------------------------------------------------------- */



More information about the Bf-blender-cvs mailing list