48 uiItemR(layout,
ptr,
"target_geometry_element", 0,
"", ICON_NONE);
58 node->storage = node_storage;
68 const bool bvh_mesh_success,
69 const bool bvh_pointcloud_success,
70 const bool store_distances,
71 const bool store_locations)
81 nearest_from_mesh.
index = -1;
82 nearest_from_pointcloud.
index = -1;
88 if (bvh_mesh_success) {
101 if (bvh_pointcloud_success) {
104 &nearest_from_pointcloud,
106 &tree_data_pointcloud);
109 if (nearest_from_pointcloud.
dist_sq < nearest_from_mesh.
dist_sq) {
110 if (store_distances) {
111 distance_span[i] =
sqrtf(nearest_from_pointcloud.
dist_sq);
113 if (store_locations) {
114 location_span[i] = nearest_from_pointcloud.
co;
118 if (store_distances) {
121 if (store_locations) {
122 location_span[i] = nearest_from_mesh.
co;
130 int target_geometry_element,
134 switch (target_geometry_element) {
148 if (r_tree_data_mesh.
tree ==
nullptr) {
158 if (r_tree_data_pointcloud.
tree ==
nullptr) {
171 const std::string distance_attribute_name =
params.get_input<std::string>(
"Distance");
175 const std::string location_attribute_name =
params.get_input<std::string>(
"Position");
182 if (!position_attribute || (!distance_attribute && !location_attribute)) {
192 bool bvh_mesh_success =
false;
193 bool bvh_pointcloud_success =
false;
204 tree_data_pointcloud);
210 distance_attribute->get_span_for_write_only<
float>() :
213 location_attribute->get_span_for_write_only<
float3>() :
220 tree_data_pointcloud,
222 bvh_pointcloud_success,
226 if (bvh_mesh_success) {
229 if (bvh_pointcloud_success) {
233 if (distance_attribute) {
234 distance_attribute.apply_span_and_save();
236 if (location_attribute) {
237 location_attribute.apply_span_and_save();
261 params.set_output(
"Geometry", geometry_set);
276 "NodeGeometryAttributeProximity",
BVHTree * BKE_bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, struct Mesh *mesh, const BVHCacheType bvh_cache_type, const int tree_type)
void free_bvhtree_from_mesh(struct BVHTreeFromMesh *data)
BVHTree * BKE_bvhtree_from_pointcloud_get(struct BVHTreeFromPointCloud *data, const struct PointCloud *pointcloud, const int tree_type)
void free_bvhtree_from_pointcloud(struct BVHTreeFromPointCloud *data)
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
#define NODE_CLASS_ATTRIBUTE
void nodeRegisterType(struct bNodeType *ntype)
int BLI_bvhtree_find_nearest(BVHTree *tree, const float co[3], BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata)
A kd-tree for nearest neighbor search.
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v3_fl(float r[3], float f)
static uint8 component(Color32 c, uint i)
@ GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_FACES
@ GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_POINTS
@ GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_EDGES
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC Boolean Random Edge Subdivision Point Object Attribute Attribute Attribute Color Attribute Attribute Vector Point Attribute Sample Collection GEO_NODE_ATTRIBUTE_PROXIMITY
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
constexpr IndexRange index_range() const
void *(* MEM_callocN)(size_t len, const char *str)
GeometrySet geometry_set_realize_instances(const GeometrySet &geometry_set)
std::unique_ptr< ReadAttribute > ReadAttributePtr
static void proximity_calc(MutableSpan< float > distance_span, MutableSpan< float3 > location_span, Span< float3 > positions, BVHTreeFromMesh &tree_data_mesh, BVHTreeFromPointCloud &tree_data_pointcloud, const bool bvh_mesh_success, const bool bvh_pointcloud_success, const bool store_distances, const bool store_locations)
static void geo_node_attribute_proximity_exec(GeoNodeExecParams params)
static bool bvh_from_pointcloud(const PointCloud *target_pointcloud, BVHTreeFromPointCloud &r_tree_data_pointcloud)
static void attribute_calc_proximity(GeometryComponent &component, GeometrySet &geometry_set_target, GeoNodeExecParams ¶ms)
static bool bvh_from_mesh(const Mesh *target_mesh, int target_geometry_element, BVHTreeFromMesh &r_tree_data_mesh)
void parallel_for(IndexRange range, int64_t grain_size, const Function &function)
static void geo_attribute_proximity_init(bNodeTree *UNUSED(ntree), bNode *node)
static bNodeSocketTemplate geo_node_attribute_proximity_out[]
void register_node_type_geo_attribute_proximity()
static void geo_node_attribute_proximity_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static bNodeSocketTemplate geo_node_attribute_proximity_in[]
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
void node_free_standard_storage(bNode *node)
BVHTree_NearestPointCallback nearest_callback
BVHTree_NearestPointCallback nearest_callback
const PointCloud * get_pointcloud_for_read() const
GeometryComponent & get_component_for_write(GeometryComponentType component_type)
bool has(const GeometryComponentType component_type) const
const Mesh * get_mesh_for_read() const
bool has_pointcloud() const
uint8_t target_geometry_element
Compact definition of a node socket.
NodeGeometryExecFunction geometry_node_execute
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)