23 const bNode *node =
b.node_or_null();
29 b.add_input(data_type,
"Grid").hide_value();
34 b.add_output(data_type,
"Value").dependent_field({1, 2, 3});
39 switch (socket.
type) {
56 if (!
U.experimental.use_new_volume_nodes) {
66 bNode &node =
params.add_node(
"GeometryNodeSampleGridIndex");
67 node.custom1 = *node_type;
68 params.update_and_connect_available_socket(node,
"Grid");
71 if (
params.node_tree().typeinfo->validate_link(other_type,
SOCK_INT)) {
73 bNode &node =
params.add_node(
"GeometryNodeSampleGridIndex");
74 params.update_and_connect_available_socket(node,
"X");
77 bNode &node =
params.add_node(
"GeometryNodeSampleGridIndex");
78 params.update_and_connect_available_socket(node,
"Y");
81 bNode &node =
params.add_node(
"GeometryNodeSampleGridIndex");
82 params.update_and_connect_available_socket(node,
"Z");
88 bNode &node =
params.add_node(
"GeometryNodeSampleGridIndex");
89 node.custom1 = *node_type;
90 params.update_and_connect_available_socket(node,
"Value");
108void sample_grid(
const bke::OpenvdbGridType<T> &grid,
115 using GridType = bke::OpenvdbGridType<T>;
116 using GridValueT =
typename GridType::ValueType;
117 using AccessorT =
typename GridType::ConstAccessor;
118 using TraitsT =
typename bke::VolumeGridTraits<T>;
119 AccessorT accessor = grid.getConstAccessor();
121 mask.foreach_index([&](
const int64_t i) {
122 GridValueT value = accessor.getValue(openvdb::Coord(x[i], y[i],
z[i]));
123 dst[i] = TraitsT::to_blender(value);
127template<
typename Fn>
void convert_to_static_type(
const VolumeGridType type,
const Fn &fn)
150class SampleGridIndexFunction :
public mf::MultiFunction {
151 bke::GVolumeGrid grid_;
152 mf::Signature signature_;
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_);
170 void call(
const IndexMask &mask, mf::Params
params, mf::Context )
const final
172 const VArraySpan<int> x =
params.readonly_single_input<
int>(0,
"X");
173 const VArraySpan<int> y =
params.readonly_single_input<
int>(1,
"Y");
174 const VArraySpan<int>
z =
params.readonly_single_input<
int>(2,
"Z");
175 GMutableSpan dst =
params.uninitialized_single_output(3,
"Value");
177 bke::VolumeTreeAccessToken tree_token;
179 using T = decltype(dummy);
180 sample_grid<T>(grid_.typed<T>().grid(tree_token), x, y, z, mask, dst.typed<T>());
193 bke::GVolumeGrid grid =
params.extract_input<bke::GVolumeGrid>(
"Grid");
195 params.set_default_remaining_outputs();
199 auto fn = std::make_shared<SampleGridIndexFunction>(std::move(grid));
207 const GField output_field = conversions.try_convert(
fn::GField(std::move(op)), output_type);
208 params.set_output(
"Value", std::move(output_field));
232 "Node socket data type",
#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)
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={})
local_group_size(16, 16) .push_constant(Type b
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 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, 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