Blender V5.0
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")
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").default_value(1.0f).min(0.01f).max(FLT_MAX);
23 b.add_input<decl::Float>("Voxel Size")
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")
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").structure_type(StructureType::Grid);
35}
36
38{
39#ifdef WITH_OPENVDB
40 const GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh");
41 const Mesh *mesh = geometry_set.get_mesh();
42 if (!mesh || mesh->faces_num == 0) {
43 params.set_default_remaining_outputs();
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"),
51 params.extract_input<float>("Gradient Width"),
52 params.extract_input<float>("Density"));
53 if (!grid) {
54 params.set_default_remaining_outputs();
55 return;
56 }
57 params.set_output("Density Grid", std::move(grid));
58#else
60#endif
61}
62
63static void node_register()
64{
65 static blender::bke::bNodeType ntype;
66
67 geo_node_type_base(&ntype, "GeometryNodeMeshToDensityGrid", 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;
75}
77
78} // namespace blender::nodes::node_geo_mesh_to_density_grid_cc
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1240
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define GEO_NODE_MESH_TO_DENSITY_GRID
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_DISTANCE
Definition RNA_types.hh:256
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void node_geo_exec_with_missing_openvdb(GeoNodeExecParams &params)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
#define min(a, b)
Definition sort.cc:36
#define FLT_MAX
Definition stdcycles.h:14
const Mesh * get_mesh() const
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362
max
Definition text_draw.cc:251