Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-10-12 23:28:11 +0300
committerHans Goudey <h.goudey@me.com>2021-10-12 23:28:11 +0300
commit9d03990e32ac36a4b9c6f958e9b1bea7288b0bbc (patch)
treea3739c3d139e4f0ca954b811454ef1cae538da9a /source
parenteb56e8cd788dd9711ec013a5460fdb1d510511c1 (diff)
Fix T92160: Geometry Proximity node can produce invalid values
Check when the node fails to create BVH trees, and fill the result with zero in that case, which is most likely the expected value when the node encounters an error. Warnings will be added with a separate patch.
Diffstat (limited to 'source')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_proximity.cc32
1 files changed, 22 insertions, 10 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_proximity.cc b/source/blender/nodes/geometry/nodes/node_geo_proximity.cc
index 9f357ce2b1c..30d025953af 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_proximity.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_proximity.cc
@@ -50,7 +50,7 @@ static void geo_proximity_init(bNodeTree *UNUSED(ntree), bNode *node)
node->storage = node_storage;
}
-static void calculate_mesh_proximity(const VArray<float3> &positions,
+static bool calculate_mesh_proximity(const VArray<float3> &positions,
const IndexMask mask,
const Mesh &mesh,
const GeometryNodeProximityTargetType type,
@@ -71,7 +71,7 @@ static void calculate_mesh_proximity(const VArray<float3> &positions,
}
if (bvh_data.tree == nullptr) {
- return;
+ return false;
}
threading::parallel_for(mask.index_range(), 512, [&](IndexRange range) {
@@ -97,18 +97,19 @@ static void calculate_mesh_proximity(const VArray<float3> &positions,
});
free_bvhtree_from_mesh(&bvh_data);
+ return true;
}
-static void calculate_pointcloud_proximity(const VArray<float3> &positions,
+static bool calculate_pointcloud_proximity(const VArray<float3> &positions,
const IndexMask mask,
const PointCloud &pointcloud,
- const MutableSpan<float> r_distances,
- const MutableSpan<float3> r_locations)
+ MutableSpan<float> r_distances,
+ MutableSpan<float3> r_locations)
{
BVHTreeFromPointCloud bvh_data;
BKE_bvhtree_from_pointcloud_get(&bvh_data, &pointcloud, 2);
if (bvh_data.tree == nullptr) {
- return;
+ return false;
}
threading::parallel_for(mask.index_range(), 512, [&](IndexRange range) {
@@ -136,6 +137,7 @@ static void calculate_pointcloud_proximity(const VArray<float3> &positions,
});
free_bvhtree_from_pointcloud(&bvh_data);
+ return true;
}
class ProximityFunction : public fn::MultiFunction {
@@ -174,16 +176,23 @@ class ProximityFunction : public fn::MultiFunction {
distances.fill(FLT_MAX);
+ bool success = false;
if (target_.has_mesh()) {
- calculate_mesh_proximity(
+ success |= calculate_mesh_proximity(
src_positions, mask, *target_.get_mesh_for_read(), type_, distances, positions);
}
if (target_.has_pointcloud() && type_ == GEO_NODE_PROX_TARGET_POINTS) {
- calculate_pointcloud_proximity(
+ success |= calculate_pointcloud_proximity(
src_positions, mask, *target_.get_pointcloud_for_read(), distances, positions);
}
+ if (!success) {
+ positions.fill(float3(0));
+ distances.fill(0.0f);
+ return;
+ }
+
if (params.single_output_is_required(2, "Distance")) {
threading::parallel_for(mask.index_range(), 2048, [&](IndexRange range) {
for (const int i : range) {
@@ -199,10 +208,13 @@ static void geo_node_proximity_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set_target = params.extract_input<GeometrySet>("Target");
- if (!geometry_set_target.has_mesh() && !geometry_set_target.has_pointcloud()) {
+ auto return_default = [&]() {
params.set_output("Position", fn::make_constant_field<float3>({0.0f, 0.0f, 0.0f}));
params.set_output("Distance", fn::make_constant_field<float>(0.0f));
- return;
+ };
+
+ if (!geometry_set_target.has_mesh() && !geometry_set_target.has_pointcloud()) {
+ return return_default();
}
const NodeGeometryProximity &storage = *(const NodeGeometryProximity *)params.node().storage;