22 const bNode *node =
b.node_or_null();
24 .supported_type({GeometryComponent::Type::Mesh,
25 GeometryComponent::Type::PointCloud,
26 GeometryComponent::Type::Curve,
27 GeometryComponent::Type::Instance,
28 GeometryComponent::Type::GreasePencil})
29 .description(
"Geometry to sample a value on");
30 if (node !=
nullptr) {
32 b.add_input(data_type,
"Value").hide_value().field_on_all();
36 .
description(
"Which element to retrieve a value from on the geometry")
37 .structure_type(StructureType::Dynamic);
39 if (node !=
nullptr) {
41 b.add_output(data_type,
"Value").dependent_field({2});
56 data->domain = int8_t(AttrDomain::Point);
71 bNode &node =
params.add_node(
"GeometryNodeSampleIndex");
72 node_storage(node).data_type = *type;
73 params.update_and_connect_available_socket(node,
"Value");
95 GeometryComponent::Type::Mesh,
96 GeometryComponent::Type::PointCloud,
97 GeometryComponent::Type::Curve,
98 GeometryComponent::Type::Instance,
99 GeometryComponent::Type::GreasePencil};
102 return geometry.get_component(src_type);
119 dst[
i] = src[std::clamp(index, 0, last_index)];
135 mf::Signature signature_;
137 std::optional<bke::GeometryFieldContext> geometry_context_;
138 std::unique_ptr<FieldEvaluator> evaluator_;
139 const GVArray *src_data_ =
nullptr;
146 : src_geometry_(std::move(
geometry)),
147 src_field_(std::move(src_field)),
151 src_geometry_.ensure_owns_direct_data();
153 mf::SignatureBuilder builder{
"Sample Index", signature_};
154 builder.single_input<
int>(
"Index");
155 builder.single_output(
"Value", src_field_.cpp_type());
156 this->set_signature(&signature_);
158 this->evaluate_field();
164 if (component ==
nullptr) {
169 evaluator_ = std::make_unique<FieldEvaluator>(*geometry_context_, domain_num);
170 evaluator_->add(src_field_);
171 evaluator_->evaluate();
172 src_data_ = &evaluator_->get_evaluated(0);
180 const CPPType &type = dst.type();
181 if (src_data_ ==
nullptr) {
188 using T =
decltype(dummy);
203 const bool use_clamp = bool(storage.clamp);
209 if (index_value_variant.is_single()) {
212 params.set_default_remaining_outputs();
218 int index = index_value_variant.extract<
int>();
220 index = std::clamp(index, 0, domain_size - 1);
222 if (index >= 0 && index < domain_size) {
226 evaluator.
add(value_field);
230 data.get_to_uninitialized(index, buffer);
232 cpp_type.destruct(buffer);
241 std::string error_message;
243 std::make_shared<SampleIndexFunction>(
244 std::move(
geometry), std::move(value_field), domain, use_clamp),
245 {&index_value_variant},
250 params.set_default_remaining_outputs();
255 params.set_output(
"Value", std::move(output_value));
263 ntype.
ui_name =
"Sample Index";
264 ntype.
ui_description =
"Retrieve values from specific geometry elements";
#define NODE_STORAGE_FUNCS(StorageT)
#define NODE_CLASS_GEOMETRY
#define GEO_NODE_SAMPLE_INDEX
#define BUFFER_FOR_CPP_TYPE_VALUE(type, variable_name)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
BMesh const char void * data
void value_initialize_indices(void *ptr, const IndexMask &mask) const
constexpr int64_t last(const int64_t n=0) const
IndexRange index_range() const
int attribute_domain_size(AttrDomain domain) const
int add(GField field, GVArray *varray_ptr)
const GVArray & get_evaluated(const int field_index) const
const CPPType & cpp_type() const
Vector< SocketDeclaration * > inputs
SampleIndexFunction(GeometrySet geometry, GField src_field, const AttrDomain domain, const bool clamp)
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
constexpr T clamp(T, U, U) RET
void * MEM_callocN(size_t len, const char *str)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
void convert_to_static_type(const CPPType &cpp_type, const Func &func)
void copy_with_checked_indices(const GVArray &src, const VArray< int > &indices, const IndexMask &mask, GMutableSpan dst)
void node_register_type(bNodeType &ntype)
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
std::optional< eCustomDataType > socket_type_to_custom_data_type(eNodeSocketDatatype type)
GField make_constant_field(const CPPType &type, const void *value)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static const GeometryComponent * find_source_component(const GeometrySet &geometry, const AttrDomain domain)
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
static void node_register()
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
void copy_with_clamped_indices(const VArray< T > &src, const VArray< int > &indices, const IndexMask &mask, MutableSpan< T > dst)
static bool component_is_available(const GeometrySet &geometry, const GeometryComponent::Type type, const AttrDomain domain)
static void node_init(bNodeTree *, bNode *node)
void search_link_ops_for_declarations(GatherLinkSearchOpParams ¶ms, Span< SocketDeclaration * > declarations)
bool execute_multi_function_on_value_variant(const MultiFunction &fn, const std::shared_ptr< MultiFunction > &owned_fn, const Span< SocketValueVariant * > input_values, const Span< SocketValueVariant * > output_values, GeoNodesUserData *user_data, std::string &r_error_message)
void devirtualize_varray2(const VArray< T1 > &varray1, const VArray< T2 > &varray2, const Func &func, bool enable=true)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_free_standard_storage(bNode *node)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
std::string ui_description
void(* initfunc)(bNodeTree *ntree, bNode *node)
NodeGeometryExecFunction geometry_node_execute
const char * enum_name_legacy
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)