6# include <openvdb/openvdb.h>
7# include <openvdb/tools/LevelSetUtil.h>
8# include <openvdb/tools/ParticlesToLevelSet.h>
29static void gather_point_data_from_component(
Field<float> radius_field,
42 r_positions.
resize(r_positions.
size() + domain_num);
43 positions.materialize(r_positions.
as_mutable_span().take_back(domain_num));
51static float compute_voxel_size_from_amount(
const float voxel_amount,
55 if (positions.is_empty()) {
59 if (voxel_amount <= 1) {
67 const float extended_diagonal = diagonal + 2.0f * radius;
68 const float voxel_size = extended_diagonal / voxel_amount;
88 if (r_geometry_set.
has(type)) {
89 gather_point_data_from_component(
90 radius_field, *r_geometry_set.
get_component(type), positions, radii);
94 if (positions.is_empty()) {
98 float voxel_size = 0.0f;
100 voxel_size =
params.get_input<
float>(
"Voxel Size");
103 const float voxel_amount =
params.get_input<
float>(
"Voxel Amount");
104 const float max_radius = *std::max_element(radii.begin(), radii.end());
105 voxel_size = compute_voxel_size_from_amount(voxel_amount, positions, max_radius);
111 const double determinant = std::pow(
double(voxel_size), 3.0);
118 const float density =
params.get_input<
float>(
"Density");
119 blender::geometry::fog_volume_grid_add_from_points(
120 volume,
"density", positions, radii, voxel_size, density);
133 b.add_input<
decl::Float>(
"Density").default_value(1.0f).min(0.0f);
134 auto &voxel_size =
b.add_input<
decl::Float>(
"Voxel Size")
138 .make_available([](
bNode &node) {
139 node_storage(node).resolution_mode =
142 auto &voxel_amount =
b.add_input<
decl::Float>(
"Voxel Amount")
143 .default_value(64.0f)
146 node_storage(node).resolution_mode =
156 const bNode *node =
b.node_or_null();
157 if (node !=
nullptr) {
160 voxel_amount.available(data.resolution_mode ==
176 node->storage =
data;
185 initialize_volume_component_from_points(
params, storage, geometry_set);
187 params.set_output(
"Volume", std::move(geometry_set));
200 "Specify the approximate number of voxels along the diagonal"},
205 "Specify the voxel side length"},
206 {0,
nullptr, 0,
nullptr,
nullptr},
212 "How the voxel size is specified",
213 resolution_mode_items,
224 "NodeGeometryPointsToVolume",
void * BKE_id_new_nomain(short type, const char *name)
#define NODE_STORAGE_FUNCS(StorageT)
#define NODE_CLASS_GEOMETRY
bool BKE_volume_grid_determinant_valid(double determinant)
#define BLI_assert_msg(a, msg)
#define BLT_I18NCONTEXT_ID_ID
@ GEO_NODE_POINTS_TO_VOLUME_RESOLUTION_MODE_AMOUNT
@ GEO_NODE_POINTS_TO_VOLUME_RESOLUTION_MODE_SIZE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
void uiLayoutSetPropDecorate(uiLayout *layout, bool is_sep)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
btScalar determinant() const
Return the determinant of the matrix.
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
int attribute_domain_size(AttrDomain domain) const
virtual std::optional< AttributeAccessor > attributes() const
virtual bool is_empty() const
int add_with_destination(GField field, GVMutableArray dst)
void make_available(bNode &node) const
local_group_size(16, 16) .push_constant(Type b
void node_type_size(bNodeType *ntype, int width, int minwidth, int maxwidth)
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
void node_register_type(bNodeType *ntype)
std::optional< Bounds< T > > min_max(const std::optional< Bounds< T > > &a, const T &b)
T distance(const T &a, const T &b)
static void node_geo_exec(GeoNodeExecParams params)
static void node_register()
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_declare(NodeDeclarationBuilder &b)
static void node_init(bNodeTree *, bNode *node)
static void node_rna(StructRNA *srna)
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)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
void replace_volume(Volume *volume, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
bool has(const GeometryComponent::Type component_type) const
void keep_only_during_modify(Span< GeometryComponent::Type > component_types)
const GeometryComponent * get_component(GeometryComponent::Type component_type) const
void modify_geometry_sets(ForeachSubGeometryCallback callback)
void(* initfunc)(bNodeTree *ntree, bNode *node)
NodeGeometryExecFunction geometry_node_execute
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
NodeDeclareFunction declare