6# include <openvdb/openvdb.h>
7# include <openvdb/tools/Dense.h>
8# include <openvdb/tools/LevelSetUtil.h>
9# include <openvdb/tools/ParticlesToLevelSet.h>
29 b.add_input<
decl::Float>(
"Background").description(
"Value for voxels outside of the cube");
32 .default_value(
float3(-1.0f))
35 .default_value(
float3(1.0f))
54static float map(
const float x,
60 return (
x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
71 : resolution_(resolution), bounds_min_(bounds_min), bounds_max_(bounds_max)
86 if (attribute_field_input ==
nullptr) {
97 int64_t index = x_range.start() * resolution_.y * resolution_.z;
98 for (const int64_t x_i : x_range) {
99 const float x = map(x_i, 0.0f, resolution_.x - 1, bounds_min_.x, bounds_max_.x);
100 for (const int64_t y_i : IndexRange(resolution_.y)) {
101 const float y = map(y_i, 0.0f, resolution_.y - 1, bounds_min_.y, bounds_max_.y);
102 for (const int64_t z_i : IndexRange(resolution_.z)) {
103 const float z = map(z_i, 0.0f, resolution_.z - 1, bounds_min_.z, bounds_max_.z);
104 positions[index] = float3(x, y, z);
120 const int3 resolution =
int3(
params.extract_input<
int>(
"Resolution X"),
121 params.extract_input<
int>(
"Resolution Y"),
122 params.extract_input<
int>(
"Resolution Z"));
124 if (resolution.x < 2 || resolution.y < 2 || resolution.z < 2) {
126 params.set_default_remaining_outputs();
130 if (bounds_min.x == bounds_max.x || bounds_min.y == bounds_max.y || bounds_min.z == bounds_max.z)
133 TIP_(
"Bounding box volume must be greater than 0"));
134 params.set_default_remaining_outputs();
141 TIP_(
"Volume scale is lower than permitted by OpenVDB"));
142 params.set_default_remaining_outputs();
156 const float background =
params.extract_input<
float>(
"Background");
157 openvdb::FloatGrid::Ptr grid = openvdb::FloatGrid::create(background);
158 grid->setGridClass(openvdb::GRID_FOG_VOLUME);
160 openvdb::tools::Dense<float, openvdb::tools::LayoutZYX> dense_grid{
161 openvdb::math::CoordBBox({0, 0, 0}, {resolution.x - 1, resolution.y - 1, resolution.z - 1}),
163 openvdb::tools::copyFromDense(dense_grid, *grid, 0.0f);
165 grid->transform().postScale(openvdb::math::Vec3<double>(scale_fac.x, scale_fac.y, scale_fac.z));
166 grid->transform().postTranslate(
167 openvdb::math::Vec3<float>(bounds_min.x, bounds_min.y, bounds_min.z));
170 BKE_volume_grid_add_vdb(*volume,
"density", std::move(grid));
174 params.set_output(
"Volume", r_geometry_set);
187 "Generate a dense volume with a field that controls the density at each grid voxel based on "
void * BKE_id_new_nomain(short type, const char *name)
#define NODE_CLASS_GEOMETRY
#define GEO_NODE_VOLUME_CUBE
bool BKE_volume_voxel_size_valid(const blender::float3 &voxel_size)
#define BLT_I18NCONTEXT_ID_ID
#define NOD_REGISTER_NODE(REGISTER_FUNC)
MutableSpan< T > as_mutable_span()
static VArray from_container(ContainerT container)
int add_with_destination(GField field, GVMutableArray dst)
Grid3DFieldContext(const int3 resolution, const float3 bounds_min, const float3 bounds_max)
GVArray get_varray_for_input(const FieldInput &field_input, const IndexMask &, ResourceScope &) const override
int64_t points_num() const
VecBase< float, 3 > float3
void node_register_type(bNodeType &ntype)
static void node_declare(NodeDeclarationBuilder &b)
static void node_register()
static void node_geo_exec(GeoNodeExecParams params)
static float map(const float x, const float in_min, const float in_max, const float out_min, const float out_max)
void node_geo_exec_with_missing_openvdb(GeoNodeExecParams ¶ms)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
VecBase< int32_t, 3 > int3
VecBase< double, 3 > double3
VecBase< float, 3 > float3
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void replace_volume(Volume *volume, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
std::string ui_description
NodeGeometryExecFunction geometry_node_execute
const char * enum_name_legacy
NodeDeclareFunction declare