18# include <openvdb/tools/Interpolation.h>
33 const bNode *node =
b.node_or_null();
39 b.add_input(data_type,
"Grid").hide_value();
42 b.add_output(data_type,
"Value").dependent_field({1});
47 switch (socket.
type) {
64 if (!
U.experimental.use_new_volume_nodes) {
74 bNode &node =
params.add_node(
"GeometryNodeSampleGrid");
75 node.custom1 = *node_type;
76 params.update_and_connect_available_socket(node,
"Grid");
81 bNode &node =
params.add_node(
"GeometryNodeSampleGrid");
82 params.update_and_connect_available_socket(node,
"Position");
88 bNode &node =
params.add_node(
"GeometryNodeSampleGrid");
89 node.custom1 = *node_type;
90 params.update_and_connect_available_socket(node,
"Value");
110void sample_grid(
const bke::OpenvdbGridType<T> &grid,
116 using GridType = bke::OpenvdbGridType<T>;
117 using GridValueT =
typename GridType::ValueType;
118 using AccessorT =
typename GridType::ConstAccessor;
119 using TraitsT =
typename bke::VolumeGridTraits<T>;
120 AccessorT accessor = grid.getConstAccessor();
122 auto sample_data = [&](
auto sampler) {
123 mask.foreach_index([&](
const int64_t i) {
126 dst[i] = TraitsT::to_blender(value);
132 if constexpr (std::is_same_v<T, bool>) {
135 switch (real_interpolation) {
137 openvdb::tools::GridSampler<AccessorT, openvdb::tools::BoxSampler>
sampler(accessor,
143 openvdb::tools::GridSampler<AccessorT, openvdb::tools::QuadraticSampler>
sampler(
144 accessor, grid.transform());
149 openvdb::tools::GridSampler<AccessorT, openvdb::tools::PointSampler>
sampler(
150 accessor, grid.transform());
180class SampleGridFunction :
public mf::MultiFunction {
181 bke::GVolumeGrid grid_;
183 mf::Signature signature_;
186 SampleGridFunction(bke::GVolumeGrid grid, InterpolationMode interpolation)
187 : grid_(std::move(grid)), interpolation_(interpolation)
191 const std::optional<eNodeSocketDatatype> data_type = bke::grid_type_to_socket_type(
193 const CPPType *cpp_type = bke::socket_type_to_geo_nodes_base_cpp_type(*data_type);
194 mf::SignatureBuilder builder{
"Sample Grid", signature_};
195 builder.single_input<
float3>(
"Position");
196 builder.single_output(
"Value", *cpp_type);
197 this->set_signature(&signature_);
200 void call(
const IndexMask &mask, mf::Params
params, mf::Context )
const override
202 const VArraySpan<float3> positions =
params.readonly_single_input<
float3>(0,
"Position");
203 GMutableSpan dst =
params.uninitialized_single_output(1,
"Value");
205 bke::VolumeTreeAccessToken tree_token;
207 using T = decltype(dummy);
209 grid_.typed<T>().grid(tree_token), interpolation_, positions, mask, dst.typed<T>());
223 bke::GVolumeGrid grid =
params.extract_input<bke::GVolumeGrid>(
"Grid");
225 params.set_default_remaining_outputs();
229 auto fn = std::make_shared<SampleGridFunction>(std::move(grid), interpolation);
235 const GField output_field = conversions.try_convert(
fn::GField(std::move(op)), output_type);
236 params.set_output(
"Value", std::move(output_field));
260 "Node socket data type",
270 {0,
nullptr, 0,
nullptr,
nullptr},
274 "interpolation_mode",
275 "Interpolation Mode",
276 "How to interpolate the values between neighboring voxels",
277 interpolation_mode_items,
#define NODE_CLASS_CONVERTER
@ VOLUME_GRID_VECTOR_FLOAT
#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)
static std::shared_ptr< FieldOperation > Create(std::shared_ptr< const mf::MultiFunction > function, Vector< GField > inputs={})
local_group_size(16, 16) .push_constant(Type local_group_size(16, 16) .push_constant(Type input_tx sampler(1, ImageType::FLOAT_2D, "matte_tx") .image(0
local_group_size(16, 16) .push_constant(Type b
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void convert_to_static_type(const CPPType &cpp_type, const Func &func)
const DataTypeConversions & get_implicit_type_conversions()
const CPPType * socket_type_to_geo_nodes_base_cpp_type(eNodeSocketDatatype type)
void node_register_type(bNodeType *ntype)
static std::optional< eNodeSocketDatatype > node_type_for_socket_type(const bNodeSocket &socket)
static void node_register()
static void node_geo_exec(GeoNodeExecParams params)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static const EnumPropertyItem * data_type_filter_fn(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
static void node_declare(NodeDeclarationBuilder &b)
static void node_rna(StructRNA *srna)
static void node_init(bNodeTree *, bNode *node)
static void node_gather_link_search_ops(GatherLinkSearchOpParams ¶ms)
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, int type, const char *name, short nclass)
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
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