25 const bNode *node =
b.node_or_null();
31 b.add_input(data_type,
"Grid").hide_value().structure_type(StructureType::Grid);
36 b.add_output(data_type,
"Value").dependent_field({1, 2, 3});
41 switch (socket.
type) {
65 bNode &node =
params.add_node(
"GeometryNodeSampleGridIndex");
67 params.update_and_connect_available_socket(node,
"Grid");
70 if (
params.node_tree().typeinfo->validate_link(other_type,
SOCK_INT)) {
72 bNode &node =
params.add_node(
"GeometryNodeSampleGridIndex");
73 params.update_and_connect_available_socket(node,
"X");
76 bNode &node =
params.add_node(
"GeometryNodeSampleGridIndex");
77 params.update_and_connect_available_socket(node,
"Y");
80 bNode &node =
params.add_node(
"GeometryNodeSampleGridIndex");
81 params.update_and_connect_available_socket(node,
"Z");
87 bNode &node =
params.add_node(
"GeometryNodeSampleGridIndex");
89 params.update_and_connect_available_socket(node,
"Value");
102void sample_grid(
const bke::OpenvdbGridType<T> &grid,
109 using GridType = bke::OpenvdbGridType<T>;
110 using GridValueT =
typename GridType::ValueType;
111 using AccessorT =
typename GridType::ConstUnsafeAccessor;
112 using TraitsT =
typename bke::VolumeGridTraits<T>;
115 AccessorT accessor = grid.getConstUnsafeAccessor();
118 GridValueT value = accessor.getValue(openvdb::Coord(
x[
i],
y[
i],
z[
i]));
119 dst[
i] = TraitsT::to_blender(value);
123template<
typename Fn>
void convert_to_static_type(
const VolumeGridType type,
const Fn &fn)
146class SampleGridIndexFunction :
public mf::MultiFunction {
147 bke::GVolumeGrid grid_;
148 mf::Signature signature_;
151 bke::VolumeTreeAccessToken tree_token_;
152 const openvdb::GridBase *grid_base_ =
nullptr;
155 SampleGridIndexFunction(bke::GVolumeGrid grid) : grid_(std::move(grid))
159 const std::optional<eNodeSocketDatatype> data_type = bke::grid_type_to_socket_type(
161 const CPPType *cpp_type = bke::socket_type_to_geo_nodes_base_cpp_type(*data_type);
162 mf::SignatureBuilder builder{
"Sample Grid Index", signature_};
163 builder.single_input<
int>(
"X");
164 builder.single_input<
int>(
"Y");
165 builder.single_input<
int>(
"Z");
166 builder.single_output(
"Value", *cpp_type);
167 this->set_signature(&signature_);
169 grid_base_ = &grid_->grid(tree_token_);
170 grid_type_ = grid_->grid_type();
173 void call(
const IndexMask &
mask, mf::Params
params, mf::Context )
const final
175 const VArraySpan<int>
x =
params.readonly_single_input<
int>(0,
"X");
176 const VArraySpan<int>
y =
params.readonly_single_input<
int>(1,
"Y");
177 const VArraySpan<int>
z =
params.readonly_single_input<
int>(2,
"Z");
178 GMutableSpan dst =
params.uninitialized_single_output(3,
"Value");
181 using T =
decltype(dummy);
182 sample_grid<T>(
static_cast<const bke::OpenvdbGridType<T> &
>(*grid_base_),
197 bke::GVolumeGrid grid =
params.extract_input<bke::GVolumeGrid>(
"Grid");
199 params.set_default_remaining_outputs();
207 std::string error_message;
210 std::make_shared<SampleGridIndexFunction>(std::move(grid)),
216 params.set_default_remaining_outputs();
221 params.set_output(
"Value", std::move(output_value));
237 "Node socket data type",
249 ntype.
ui_name =
"Sample Grid Index";
250 ntype.
ui_description =
"Retrieve volume grid values at specific voxels";
#define NODE_CLASS_GEOMETRY
#define GEO_NODE_SAMPLE_GRID_INDEX
@ VOLUME_GRID_VECTOR_FLOAT
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
StructureType structure_type
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
void convert_to_static_type(const CPPType &cpp_type, const Func &func)
void node_register_type(bNodeType &ntype)
static void node_init(bNodeTree *, bNode *node)
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
static void node_rna(StructRNA *srna)
static void node_gather_link_search_ops(GatherLinkSearchOpParams ¶ms)
static void node_register()
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static std::optional< eNodeSocketDatatype > node_type_for_socket_type(const bNodeSocket &socket)
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)
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)
const EnumPropertyItem * grid_socket_type_items_filter_fn(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
void node_geo_exec_with_missing_openvdb(GeoNodeExecParams ¶ms)
VecBase< float, 3 > float3
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
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)