19# include <openvdb/tools/Interpolation.h>
34 const bNode *node =
b.node_or_null();
40 b.add_input(data_type,
"Grid").hide_value().structure_type(StructureType::Grid);
43 b.add_output(data_type,
"Value").dependent_field({1});
48 switch (socket.
type) {
75 bNode &node =
params.add_node(
"GeometryNodeSampleGrid");
77 params.update_and_connect_available_socket(node,
"Grid");
82 bNode &node =
params.add_node(
"GeometryNodeSampleGrid");
83 params.update_and_connect_available_socket(node,
"Position");
89 bNode &node =
params.add_node(
"GeometryNodeSampleGrid");
91 params.update_and_connect_available_socket(node,
"Value");
111void 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();
123 auto sample_data = [&](
auto sampler) {
126 GridValueT value = sampler.wsSample(openvdb::Vec3R(
pos.x,
pos.y,
pos.z));
127 dst[
i] = TraitsT::to_blender(value);
133 if constexpr (std::is_same_v<T, bool>) {
136 switch (real_interpolation) {
138 openvdb::tools::GridSampler<AccessorT, openvdb::tools::BoxSampler> sampler(accessor,
140 sample_data(sampler);
144 openvdb::tools::GridSampler<AccessorT, openvdb::tools::QuadraticSampler> sampler(
145 accessor, grid.transform());
146 sample_data(sampler);
150 openvdb::tools::GridSampler<AccessorT, openvdb::tools::PointSampler> sampler(
151 accessor, grid.transform());
152 sample_data(sampler);
181class SampleGridFunction :
public mf::MultiFunction {
182 bke::GVolumeGrid grid_;
184 mf::Signature signature_;
187 SampleGridFunction(bke::GVolumeGrid grid, InterpolationMode interpolation)
188 : grid_(std::move(grid)), interpolation_(interpolation)
192 const std::optional<eNodeSocketDatatype> data_type = bke::grid_type_to_socket_type(
194 const CPPType *cpp_type = bke::socket_type_to_geo_nodes_base_cpp_type(*data_type);
195 mf::SignatureBuilder builder{
"Sample Grid", signature_};
196 builder.single_input<
float3>(
"Position");
197 builder.single_output(
"Value", *cpp_type);
198 this->set_signature(&signature_);
201 void call(
const IndexMask &
mask, mf::Params
params, mf::Context )
const override
203 const VArraySpan<float3> positions =
params.readonly_single_input<
float3>(0,
"Position");
204 GMutableSpan dst =
params.uninitialized_single_output(1,
"Value");
206 bke::VolumeTreeAccessToken tree_token;
208 using T = decltype(dummy);
210 grid_.typed<T>().grid(tree_token), interpolation_, positions, mask, dst.typed<T>());
224 bke::GVolumeGrid grid =
params.extract_input<bke::GVolumeGrid>(
"Grid");
226 params.set_default_remaining_outputs();
230 auto fn = std::make_shared<SampleGridFunction>(std::move(grid), interpolation);
236 const GField output_field = conversions.try_convert(
fn::GField(std::move(op)), output_type);
237 params.set_output(
"Value", std::move(output_field));
261 "Node socket data type",
271 {0,
nullptr, 0,
nullptr,
nullptr},
275 "interpolation_mode",
276 "Interpolation Mode",
277 "How to interpolate the values between neighboring voxels",
278 interpolation_mode_items,
#define NODE_CLASS_CONVERTER
#define GEO_NODE_SAMPLE_GRID
@ VOLUME_GRID_VECTOR_FLOAT
@ NODE_DEFAULT_INPUT_POSITION_FIELD
#define USER_EXPERIMENTAL_TEST(userdef, member)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
static std::shared_ptr< FieldOperation > Create(std::shared_ptr< const mf::MultiFunction > function, Vector< GField > inputs={})
VecBase< float, 3 > float3
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 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, std::string idname, const std::optional< int16_t > legacy_type)
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
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)