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);
51static float compute_voxel_size_from_amount(
const float voxel_amount,
59 if (voxel_amount <= 1) {
67 const float extended_diagonal = diagonal + 2.0f * radius;
68 const float voxel_size = extended_diagonal / voxel_amount;
85 GeometryComponent::Type::PointCloud,
86 GeometryComponent::Type::Curve})
88 if (r_geometry_set.
has(type)) {
89 gather_point_data_from_component(
90 radius_field, *r_geometry_set.
get_component(type), positions, radii);
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);
117 const float density =
params.get_input<
float>(
"Density");
118 blender::geometry::fog_volume_grid_add_from_points(
119 volume,
"density", positions, radii, voxel_size, density);
133 auto &voxel_size =
b.add_input<
decl::Float>(
"Voxel Size")
137 .make_available([](
bNode &node) {
138 node_storage(node).resolution_mode =
141 auto &voxel_amount =
b.add_input<
decl::Float>(
"Voxel Amount")
144 .make_available([](
bNode &node) {
145 node_storage(node).resolution_mode =
155 const bNode *node =
b.node_or_null();
156 if (node !=
nullptr) {
159 voxel_amount.available(
data.resolution_mode ==
184 initialize_volume_component_from_points(
params, storage, geometry_set);
186 params.set_output(
"Volume", std::move(geometry_set));
199 "Specify the approximate number of voxels along the diagonal"},
204 "Specify the voxel side length"},
205 {0,
nullptr, 0,
nullptr,
nullptr},
211 "How the voxel size is specified",
212 resolution_mode_items,
222 ntype.
ui_name =
"Points to Volume";
223 ntype.
ui_description =
"Generate a fog volume sphere around every point";
void * BKE_id_new_nomain(short type, const char *name)
#define NODE_STORAGE_FUNCS(StorageT)
#define NODE_CLASS_GEOMETRY
#define GEO_NODE_POINTS_TO_VOLUME
bool BKE_volume_voxel_size_valid(const blender::float3 &voxel_size)
#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)
BMesh const char void * data
constexpr bool is_empty() const
void materialize(MutableSpan< T > r_span) const
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)
std::optional< std::string > translation_context
void * MEM_callocN(size_t len, const char *str)
void node_type_size(bNodeType &ntype, int width, int minwidth, int maxwidth)
void node_register_type(bNodeType &ntype)
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
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)
VecBase< float, 3 > float3
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
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)
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)
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)