From 4d39a0f8eb1103aa58611fff7219f4bf3d70f70f Mon Sep 17 00:00:00 2001 From: Victor-Louis De Gusseme Date: Fri, 5 Feb 2021 08:28:31 -0600 Subject: Geometry Nodes: Add Attribute Proximity Node This node calculates a distance from each point to the closest position on a target geometry, similar to the vertex weight proximity modifier. Mapping the output distance to a different range can be done with an attribute math node after this node. A drop-down changes whether to calculate distances from points, edges, or faces. In points mode, the node also calculates distances from point cloud points. Design task and use cases: T84842 Differential Revision: https://developer.blender.org/D10154 --- source/blender/blenkernel/intern/bvhutils.c | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'source/blender/blenkernel/intern/bvhutils.c') diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index fd5cb33f02d..790fb128c7c 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -27,6 +27,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" +#include "DNA_pointcloud_types.h" #include "BLI_linklist.h" #include "BLI_math.h" @@ -1717,3 +1718,41 @@ void free_bvhtree_from_mesh(struct BVHTreeFromMesh *data) memset(data, 0, sizeof(*data)); } + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Point Cloud BVH Building + * \{ */ + +BVHTree *BKE_bvhtree_from_pointcloud_get(BVHTreeFromPointCloud *data, + const PointCloud *pointcloud, + const int tree_type) +{ + BVHTree *tree = BLI_bvhtree_new(pointcloud->totpoint, 0.0f, tree_type, 6); + if (!tree) { + return NULL; + } + + for (int i = 0; i < pointcloud->totpoint; i++) { + BLI_bvhtree_insert(tree, i, pointcloud->co[i], 1); + } + BLI_assert(BLI_bvhtree_get_len(tree) == pointcloud->totpoint); + BLI_bvhtree_balance(tree); + + data->coords = pointcloud->co; + data->tree = tree; + data->nearest_callback = NULL; + + return tree; +} + +void free_bvhtree_from_pointcloud(BVHTreeFromPointCloud *data) +{ + if (data->tree) { + BLI_bvhtree_free(data->tree); + } + memset(data, 0, sizeof(*data)); +} + +/** \} */ -- cgit v1.2.3