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) {
68 bNode &node =
params.add_node(
"GeometryNodeSampleGridIndex");
70 params.update_and_connect_available_socket(node,
"Grid");
73 if (
params.node_tree().typeinfo->validate_link(other_type,
SOCK_INT)) {
75 bNode &node =
params.add_node(
"GeometryNodeSampleGridIndex");
76 params.update_and_connect_available_socket(node,
"X");
79 bNode &node =
params.add_node(
"GeometryNodeSampleGridIndex");
80 params.update_and_connect_available_socket(node,
"Y");
83 bNode &node =
params.add_node(
"GeometryNodeSampleGridIndex");
84 params.update_and_connect_available_socket(node,
"Z");
90 bNode &node =
params.add_node(
"GeometryNodeSampleGridIndex");
92 params.update_and_connect_available_socket(node,
"Value");
110void sample_grid(
const bke::OpenvdbGridType<T> &grid,
117 using GridType = bke::OpenvdbGridType<T>;
118 using GridValueT =
typename GridType::ValueType;
119 using AccessorT =
typename GridType::ConstAccessor;
120 using TraitsT =
typename bke::VolumeGridTraits<T>;
121 AccessorT accessor = grid.getConstAccessor();
124 GridValueT value = accessor.getValue(openvdb::Coord(
x[
i],
y[
i],
z[
i]));
125 dst[
i] = TraitsT::to_blender(value);
129template<
typename Fn>
void convert_to_static_type(
const VolumeGridType type,
const Fn &fn)
152class SampleGridIndexFunction :
public mf::MultiFunction {
153 bke::GVolumeGrid grid_;
154 mf::Signature signature_;
157 SampleGridIndexFunction(bke::GVolumeGrid grid) : grid_(std::move(grid))
161 const std::optional<eNodeSocketDatatype> data_type = bke::grid_type_to_socket_type(
163 const CPPType *cpp_type = bke::socket_type_to_geo_nodes_base_cpp_type(*data_type);
164 mf::SignatureBuilder builder{
"Sample Grid Index", signature_};
165 builder.single_input<
int>(
"X");
166 builder.single_input<
int>(
"Y");
167 builder.single_input<
int>(
"Z");
168 builder.single_output(
"Value", *cpp_type);
169 this->set_signature(&signature_);
172 void call(
const IndexMask &
mask, mf::Params
params, mf::Context )
const final
174 const VArraySpan<int>
x =
params.readonly_single_input<
int>(0,
"X");
175 const VArraySpan<int>
y =
params.readonly_single_input<
int>(1,
"Y");
176 const VArraySpan<int>
z =
params.readonly_single_input<
int>(2,
"Z");
177 GMutableSpan dst =
params.uninitialized_single_output(3,
"Value");
179 bke::VolumeTreeAccessToken tree_token;
181 using T = decltype(dummy);
182 sample_grid<T>(grid_.typed<T>().grid(tree_token), x, y, z, mask, dst.typed<T>());
195 bke::GVolumeGrid grid =
params.extract_input<bke::GVolumeGrid>(
"Grid");
197 params.set_default_remaining_outputs();
201 auto fn = std::make_shared<SampleGridIndexFunction>(std::move(grid));
209 const GField output_field = conversions.try_convert(
fn::GField(std::move(op)), output_type);
210 params.set_output(
"Value", std::move(output_field));
234 "Node socket data type",
246 ntype.
ui_name =
"Sample Grid Index";
247 ntype.
ui_description =
"Retrieve volume grid values at specific voxels";
#define NODE_CLASS_CONVERTER
#define GEO_NODE_SAMPLE_GRID_INDEX
@ VOLUME_GRID_VECTOR_FLOAT
#define USER_EXPERIMENTAL_TEST(userdef, member)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
static std::shared_ptr< FieldOperation > Create(std::shared_ptr< const mf::MultiFunction > function, Vector< GField > inputs={})
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
void convert_to_static_type(const CPPType &cpp_type, const Func &func)
const DataTypeConversions & get_implicit_type_conversions()
void node_register_type(bNodeType &ntype)
const CPPType * socket_type_to_geo_nodes_base_cpp_type(eNodeSocketDatatype type)
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 const EnumPropertyItem * data_type_filter_fn(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
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)
void node_geo_exec_with_missing_openvdb(GeoNodeExecParams ¶ms)
const EnumPropertyItem * enum_items_filter(const EnumPropertyItem *original_item_array, FunctionRef< bool(const EnumPropertyItem &item)> fn)
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)