34 "Splits the elements of the input geometry into groups which can be sampled "
36 b.add_input<
decl::Vector>(
"Sample Position",
"Source Position")
38 b.add_input<
decl::Int>(
"Sample Group ID").hide_value().supports_field();
39 b.add_output<
decl::Vector>(
"Position").dependent_field({2, 3}).reference_pass_all();
40 b.add_output<
decl::Float>(
"Distance").dependent_field({2, 3}).reference_pass_all();
42 .dependent_field({2, 3})
44 "Whether the sampling was successful. It can fail when the sampled group is empty");
56 node->storage = node_storage;
75 : target_(std::move(target)), type_(type)
80 builder.single_input<
float3>(
"Source Position");
81 builder.single_input<
int>(
"Sample ID");
82 builder.single_output<
float3>(
"Position", mf::ParamFlag::SupportsUnusedOutput);
83 builder.single_output<
float>(
"Distance", mf::ParamFlag::SupportsUnusedOutput);
84 builder.single_output<
bool>(
"Is Valid", mf::ParamFlag::SupportsUnusedOutput);
101 for (BVHTrees &trees : bvh_trees_) {
102 if (trees.mesh_bvh.tree) {
105 if (trees.pointcloud_bvh.tree) {
116 field_evaluator.add(group_id_field);
117 field_evaluator.evaluate();
118 const VArray<int> group_ids = field_evaluator.get_evaluated<
int>(0);
122 const int groups_num = group_masks.
size();
125 bvh_trees_.
resize(groups_num);
130 for (
const int group_i :
range) {
131 const IndexMask &group_mask = group_masks[group_i];
140 [&](
const int group_i) {
return group_masks[group_i].
size(); }, pointcloud.
totpoint));
147 const int domain_size = mesh.attributes().domain_size(domain);
150 field_evaluator.
add(group_id_field);
151 field_evaluator.evaluate();
152 const VArray<int> group_ids = field_evaluator.get_evaluated<
int>(0);
156 const int groups_num = group_masks.
size();
159 bvh_trees_.
resize(groups_num);
164 for (
const int group_i :
range) {
165 const IndexMask &group_mask = group_masks[group_i];
187 [&](
const int group_i) {
return group_masks[group_i].
size(); }, domain_size));
207 0,
"Source Position");
208 const VArray<int> &sample_ids =
params.readonly_single_input<
int>(1,
"Sample ID");
216 mask.foreach_index([&](
const int i) {
217 const float3 sample_position = sample_positions[i];
218 const int sample_id = sample_ids[i];
219 const int group_index = group_indices_.
index_of_try(sample_id);
220 if (group_index == -1) {
221 if (!positions.is_empty()) {
222 positions[i] =
float3(0, 0, 0);
224 if (!is_valid_span.is_empty()) {
225 is_valid_span[i] =
false;
227 if (!distances.is_empty()) {
232 const BVHTrees &trees = bvh_trees_[group_index];
238 if (trees.mesh_bvh.
tree !=
nullptr) {
245 if (trees.pointcloud_bvh.
tree !=
nullptr) {
253 if (!positions.is_empty()) {
254 positions[i] = nearest.co;
256 if (!is_valid_span.is_empty()) {
257 is_valid_span[i] =
true;
259 if (!distances.is_empty()) {
260 distances[i] = std::sqrt(nearest.dist_sq);
271 if (!target.has_mesh() && !target.has_pointcloud()) {
272 params.set_default_remaining_outputs();
281 auto proximity_fn = std::make_unique<ProximityFunction>(
284 std::move(proximity_fn), {std::move(position_field), std::move(sample_id_field)});
298 "Calculate the proximity to the target's points (faster than the other modes)"},
303 "Calculate the proximity to the target's edges"},
308 "Calculate the proximity to the target's faces"},
309 {0,
nullptr, 0,
nullptr,
nullptr},
315 "Element of the target geometry to calculate the distance from",
316 target_element_items,
void free_bvhtree_from_mesh(BVHTreeFromMesh *data)
void BKE_bvhtree_from_pointcloud_get(const PointCloud &pointcloud, const blender::IndexMask &points_mask, BVHTreeFromPointCloud &r_data)
void free_bvhtree_from_pointcloud(BVHTreeFromPointCloud *data)
void BKE_bvhtree_from_mesh_verts_init(const Mesh &mesh, const blender::IndexMask &verts_mask, BVHTreeFromMesh &r_data)
void BKE_bvhtree_from_mesh_edges_init(const Mesh &mesh, const blender::IndexMask &edges_mask, BVHTreeFromMesh &r_data)
void BKE_bvhtree_from_mesh_tris_init(const Mesh &mesh, const blender::IndexMask &faces_mask, BVHTreeFromMesh &r_data)
#define NODE_STORAGE_FUNCS(StorageT)
#define NODE_CLASS_GEOMETRY
#define BLI_assert_unreachable()
int BLI_bvhtree_find_nearest(const BVHTree *tree, const float co[3], BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata)
GeometryNodeProximityTargetType
@ GEO_NODE_PROX_TARGET_EDGES
@ GEO_NODE_PROX_TARGET_POINTS
@ GEO_NODE_PROX_TARGET_FACES
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
int64_t index_of_try(const Key &key) const
void resize(const int64_t new_size)
int add(GField field, GVArray *varray_ptr)
static std::shared_ptr< FieldOperation > Create(std::shared_ptr< const mf::MultiFunction > function, Vector< GField > inputs={})
const Signature & signature() const
void set_signature(const Signature *signature)
static Vector< IndexMask, 4 > from_group_ids(const VArray< int > &group_ids, IndexMaskMemory &memory, VectorSet< int > &r_index_by_group_id)
void init_for_pointcloud(const PointCloud &pointcloud, const Field< int > &group_id_field)
bke::AttrDomain get_domain_on_mesh() const
ProximityFunction(GeometrySet target, GeometryNodeProximityTargetType type, const Field< int > &group_id_field)
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
void init_for_mesh(const Mesh &mesh, const Field< int > &group_id_field)
local_group_size(16, 16) .push_constant(Type b
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
void node_register_type(bNodeType *ntype)
static void node_geo_exec(GeoNodeExecParams params)
static void node_register()
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_rna(StructRNA *srna)
static void geo_proximity_init(bNodeTree *, bNode *node)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
auto individual_task_sizes(Fn &&fn, const std::optional< int64_t > full_size=std::nullopt)
VecBase< float, 3 > float3
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
BVHTree_NearestPointCallback nearest_callback
BVHTree_NearestPointCallback nearest_callback
bool has_pointcloud() const
void ensure_owns_direct_data()
const PointCloud * get_pointcloud() const
const Mesh * get_mesh() const
void(* initfunc)(bNodeTree *ntree, bNode *node)
NodeGeometryExecFunction geometry_node_execute
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
NodeDeclareFunction declare