[Bf-blender-cvs] [622b7fff151] geometry-nodes: Geometry Nodes: fix computing bounding box of evaluated point cloud
Jacques Lucke
noreply at git.blender.org
Thu Nov 26 12:32:15 CET 2020
Commit: 622b7fff1513af9a5162b3397486769543ffd1a2
Author: Jacques Lucke
Date: Thu Nov 26 12:32:08 2020 +0100
Branches: geometry-nodes
https://developer.blender.org/rB622b7fff1513af9a5162b3397486769543ffd1a2
Geometry Nodes: fix computing bounding box of evaluated point cloud
Currently, the bounding box does not include instances. This is consistent
with other object types.
===================================================================
M source/blender/blenkernel/BKE_geometry_set.hh
M source/blender/blenkernel/BKE_pointcloud.h
M source/blender/blenkernel/intern/geometry_set.cc
M source/blender/blenkernel/intern/pointcloud.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index 284c9ae4c9f..ef3ae3c381c 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -225,6 +225,8 @@ struct GeometrySet {
void add(const GeometryComponent &component);
+ void compute_boundbox_without_instances(blender::float3 *r_min, blender::float3 *r_max) const;
+
friend std::ostream &operator<<(std::ostream &stream, const GeometrySet &geometry_set);
friend bool operator==(const GeometrySet &a, const GeometrySet &b);
uint64_t hash() const;
diff --git a/source/blender/blenkernel/BKE_pointcloud.h b/source/blender/blenkernel/BKE_pointcloud.h
index 5598a9c3645..d2d390dc786 100644
--- a/source/blender/blenkernel/BKE_pointcloud.h
+++ b/source/blender/blenkernel/BKE_pointcloud.h
@@ -41,6 +41,7 @@ void *BKE_pointcloud_add_default(struct Main *bmain, const char *name);
struct PointCloud *BKE_pointcloud_new_nomain(const int totpoint);
struct BoundBox *BKE_pointcloud_boundbox_get(struct Object *ob);
+void BKE_pointcloud_minmax(const struct PointCloud *pointcloud, float r_min[3], float r_max[3]);
void BKE_pointcloud_update_customdata_pointers(struct PointCloud *pointcloud);
bool BKE_pointcloud_customdata_required(struct PointCloud *pointcloud,
diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc
index 4450e5d8f59..28695d769d3 100644
--- a/source/blender/blenkernel/intern/geometry_set.cc
+++ b/source/blender/blenkernel/intern/geometry_set.cc
@@ -17,6 +17,7 @@
#include "BKE_geometry_set.hh"
#include "BKE_lib_id.h"
#include "BKE_mesh.h"
+#include "BKE_mesh_wrapper.h"
#include "BKE_pointcloud.h"
#include "DNA_object_types.h"
@@ -146,6 +147,18 @@ void GeometrySet::add(const GeometryComponent &component)
components_.add_new(component.type(), std::move(component_ptr));
}
+void GeometrySet::compute_boundbox_without_instances(float3 *r_min, float3 *r_max) const
+{
+ const PointCloud *pointcloud = this->get_pointcloud_for_read();
+ if (pointcloud != nullptr) {
+ BKE_pointcloud_minmax(pointcloud, *r_min, *r_max);
+ }
+ const Mesh *mesh = this->get_mesh_for_read();
+ if (mesh != nullptr) {
+ BKE_mesh_wrapper_minmax(mesh, *r_min, *r_max);
+ }
+}
+
std::ostream &operator<<(std::ostream &stream, const GeometrySet &geometry_set)
{
stream << "<GeometrySet at " << &geometry_set << ", " << geometry_set.components_.size()
diff --git a/source/blender/blenkernel/intern/pointcloud.cc b/source/blender/blenkernel/intern/pointcloud.cc
index dbb0a1bd569..5f6685817b9 100644
--- a/source/blender/blenkernel/intern/pointcloud.cc
+++ b/source/blender/blenkernel/intern/pointcloud.cc
@@ -40,6 +40,7 @@
#include "BKE_lib_query.h"
#include "BKE_lib_remap.h"
#include "BKE_main.h"
+#include "BKE_mesh_wrapper.h"
#include "BKE_modifier.h"
#include "BKE_object.h"
#include "BKE_pointcloud.h"
@@ -256,10 +257,23 @@ PointCloud *BKE_pointcloud_new_nomain(const int totpoint)
return pointcloud;
}
+void BKE_pointcloud_minmax(const struct PointCloud *pointcloud, float r_min[3], float r_max[3])
+{
+ float(*pointcloud_co)[3] = pointcloud->co;
+ float *pointcloud_radius = pointcloud->radius;
+ for (int a = 0; a < pointcloud->totpoint; a++) {
+ float *co = pointcloud_co[a];
+ float radius = (pointcloud_radius) ? pointcloud_radius[a] : 0.0f;
+ const float co_min[3] = {co[0] - radius, co[1] - radius, co[2] - radius};
+ const float co_max[3] = {co[0] + radius, co[1] + radius, co[2] + radius};
+ DO_MIN(co_min, r_min);
+ DO_MAX(co_max, r_max);
+ }
+}
+
BoundBox *BKE_pointcloud_boundbox_get(Object *ob)
{
BLI_assert(ob->type == OB_POINTCLOUD);
- PointCloud *pointcloud = static_cast<PointCloud *>(ob->data);
if (ob->runtime.bb != nullptr && (ob->runtime.bb->flag & BOUNDBOX_DIRTY) == 0) {
return ob->runtime.bb;
@@ -267,23 +281,18 @@ BoundBox *BKE_pointcloud_boundbox_get(Object *ob)
if (ob->runtime.bb == nullptr) {
ob->runtime.bb = static_cast<BoundBox *>(MEM_callocN(sizeof(BoundBox), "pointcloud boundbox"));
+ }
- float min[3], max[3];
- INIT_MINMAX(min, max);
-
- float(*pointcloud_co)[3] = pointcloud->co;
- float *pointcloud_radius = pointcloud->radius;
- for (int a = 0; a < pointcloud->totpoint; a++) {
- float *co = pointcloud_co[a];
- float radius = (pointcloud_radius) ? pointcloud_radius[a] : 0.0f;
- const float co_min[3] = {co[0] - radius, co[1] - radius, co[2] - radius};
- const float co_max[3] = {co[0] + radius, co[1] + radius, co[2] + radius};
- DO_MIN(co_min, min);
- DO_MAX(co_max, max);
- }
-
- BKE_boundbox_init_from_minmax(ob->runtime.bb, min, max);
+ blender::float3 min, max;
+ INIT_MINMAX(min, max);
+ if (ob->runtime.geometry_set_eval != nullptr) {
+ ob->runtime.geometry_set_eval->compute_boundbox_without_instances(&min, &max);
+ }
+ else {
+ const PointCloud *pointcloud = static_cast<PointCloud *>(ob->data);
+ BKE_pointcloud_minmax(pointcloud, min, max);
}
+ BKE_boundbox_init_from_minmax(ob->runtime.bb, min, max);
return ob->runtime.bb;
}
More information about the Bf-blender-cvs
mailing list