Blender V5.3
node_geo_mesh_to_density_grid.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "DNA_mesh_types.h"
6
7#include "BKE_volume_grid.hh"
8
10
11#include "node_geometry_util.hh"
12
14
16
18{
19 b.add_input<decl::Geometry>("Mesh"_ustr)
20 .supported_type(GeometryComponent::Type::Mesh)
21 .description("Mesh whose inner volume is converted to a density grid");
22 b.add_input<decl::Float>("Density"_ustr).default_value(1.0f).min(0.01f).max(FLT_MAX);
23 b.add_input<decl::Float>("Voxel Size"_ustr)
24 .default_value(0.3f)
25 .min(0.01f)
26 .max(FLT_MAX)
27 .subtype(PROP_DISTANCE);
28 b.add_input<decl::Float>("Gradient Width"_ustr)
29 .default_value(0.2f)
30 .min(0.0001f)
31 .max(FLT_MAX)
32 .subtype(PROP_DISTANCE)
33 .description("Width of the gradient inside of the mesh");
34 b.add_output<decl::Float>("Density Grid"_ustr).structure_type(StructureType::Grid);
35}
36
38{
39#ifdef WITH_OPENVDB
40 const GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh"_ustr);
41 const Mesh *mesh = geometry_set.get_mesh();
42 if (!mesh || mesh->faces_num == 0) {
44 return;
45 }
46 bke::VolumeGrid<float> grid = geometry::mesh_to_density_grid(
47 mesh->vert_positions(),
48 mesh->corner_verts(),
49 mesh->corner_tris(),
50 params.extract_input<float>("Voxel Size"_ustr),
51 params.extract_input<float>("Gradient Width"_ustr),
52 params.extract_input<float>("Density"_ustr));
53 if (!grid) {
55 return;
56 }
57 params.set_output("Density Grid"_ustr, std::move(grid));
58#else
60#endif
61}
62
63static void node_register()
64{
65 static bke::bNodeType ntype;
66
67 geo_node_type_base(&ntype, "GeometryNodeMeshToDensityGrid"_ustr, GEO_NODE_MESH_TO_DENSITY_GRID);
68 ntype.ui_name = "Mesh to Density Grid";
69 ntype.ui_description = "Create a filled volume grid from a mesh";
70 ntype.enum_name_legacy = "MESH_TO_DENSITY_GRID";
72 ntype.declare = node_declare;
76}
78
79} // namespace blender::nodes::node_geo_mesh_to_density_grid_cc
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1353
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define GEO_NODE_MESH_TO_DENSITY_GRID
#define NOD_REGISTER_NODE(REGISTER_FUNC)
btScalar max
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
#define FLT_MAX
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_geo_exec_with_missing_openvdb(GeoNodeExecParams &params)
@ PROP_DISTANCE
Definition RNA_types.hh:313
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
#define min(a, b)
Definition sort.cc:38
const Mesh * get_mesh() const
static constexpr int _160
Definition BKE_node.hh:246
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393