27 const bNode *node =
b.node_or_null();
30 if (node !=
nullptr) {
32 b.add_input(data_type,
"Value").hide_value().field_on_all();
38 "Splits the faces of the input mesh into groups which can be sampled individually");
40 b.add_input<
decl::Int>(
"Sample Group ID").hide_value().supports_field();
42 if (node !=
nullptr) {
44 b.add_output(data_type,
"Value").dependent_field({3, 4});
47 .dependent_field({3, 4})
49 "Whether the sampling was successful. It can fail when the sampled group is empty");
72 bNode &node =
params.add_node(
"GeometryNodeSampleNearestSurface");
74 params.update_and_connect_available_socket(node,
"Value");
87 : source_(std::move(geometry))
93 builder.single_input<
float3>(
"Position");
94 builder.single_input<
int>(
"Sample ID");
95 builder.single_output<
int>(
"Triangle Index");
96 builder.single_output<
float3>(
"Sample Position");
97 builder.single_output<
bool>(
"Is Valid", mf::ParamFlag::SupportsUnusedOutput);
107 field_evaluator.
add(group_id_field);
108 field_evaluator.evaluate();
109 const VArray<int> group_ids = field_evaluator.get_evaluated<
int>(0);
114 group_ids, memory, group_indices_);
115 const int groups_num = group_masks.
size();
123 for (
const int group_i :
range) {
124 const IndexMask &group_mask = group_masks[group_i];
130 [&](
const int group_i) {
return group_masks[group_i].
size(); }, mesh.faces_num));
143 const VArray<int> &sample_ids =
params.readonly_single_input<
int>(1,
"Sample ID");
146 3,
"Sample Position");
150 mask.foreach_index([&](
const int i) {
151 const float3 position = positions[i];
152 const int sample_id = sample_ids[i];
153 const int group_index = group_indices_.
index_of_try(sample_id);
154 if (group_index == -1) {
155 triangle_index[i] = -1;
156 sample_position[i] =
float3(0, 0, 0);
157 if (!is_valid_span.is_empty()) {
158 is_valid_span[i] =
false;
168 triangle_index[i] = nearest.index;
169 sample_position[i] = nearest.co;
170 if (!is_valid_span.is_empty()) {
171 is_valid_span[i] =
true;
187 const Mesh *mesh = geometry.get_mesh();
188 if (mesh ==
nullptr) {
189 params.set_default_remaining_outputs();
192 if (mesh->verts_num == 0) {
193 params.set_default_remaining_outputs();
196 if (mesh->faces_num == 0) {
197 params.error_message_add(NodeWarningType::Error,
TIP_(
"The source mesh must have faces"));
198 params.set_default_remaining_outputs();
203 std::make_shared<SampleNearestSurfaceFunction>(geometry,
205 {params.extract_input<Field<float3>>(
"Sample Position"),
206 params.extract_input<Field<int>>(
"Sample Group ID")});
212 std::make_shared<bke::mesh_surface_sample::BaryWeightFromPositionFn>(geometry),
213 {nearest_positions, triangle_indices}));
217 std::make_shared<bke::mesh_surface_sample::BaryWeightSampleFn>(geometry, std::move(field)),
218 {triangle_indices, bary_weights});
void free_bvhtree_from_mesh(BVHTreeFromMesh *data)
void BKE_bvhtree_from_mesh_tris_init(const Mesh &mesh, const blender::IndexMask &faces_mask, BVHTreeFromMesh &r_data)
#define NODE_CLASS_GEOMETRY
int BLI_bvhtree_find_nearest(const BVHTree *tree, const float co[3], BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
void reinitialize(const int64_t new_size)
int64_t index_of_try(const Key &key) const
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)
Vector< SocketDeclaration * > inputs
ExecutionHints get_execution_hints() const override
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
~SampleNearestSurfaceFunction()
SampleNearestSurfaceFunction(GeometrySet geometry, const Field< int > &group_id_field)
local_group_size(16, 16) .push_constant(Type b
void node_type_size_preset(bNodeType *ntype, eNodeSizePreset size)
void node_register_type(bNodeType *ntype)
std::optional< eCustomDataType > socket_type_to_custom_data_type(eNodeSocketDatatype type)
const EnumPropertyItem * attribute_type_type_with_socket_fn(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
static void node_register()
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
static void node_rna(StructRNA *srna)
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_init(bNodeTree *, bNode *node)
void search_link_ops_for_declarations(GatherLinkSearchOpParams ¶ms, Span< SocketDeclaration * > declarations)
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)
const EnumPropertyItem rna_enum_attribute_type_items[]
BVHTree_NearestPointCallback nearest_callback
void ensure_owns_direct_data()
const Mesh * get_mesh() const
void(* initfunc)(bNodeTree *ntree, bNode *node)
NodeGeometryExecFunction geometry_node_execute
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare