Blender V4.5
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").supported_type(GeometryComponent::Type::Mesh);
20 b.add_input<decl::Float>("Density").default_value(1.0f).min(0.01f).max(FLT_MAX);
21 b.add_input<decl::Float>("Voxel Size")
22 .default_value(0.3f)
23 .min(0.01f)
24 .max(FLT_MAX)
25 .subtype(PROP_DISTANCE);
26 b.add_input<decl::Float>("Gradient Width")
27 .default_value(0.2f)
28 .min(0.0001f)
29 .max(FLT_MAX)
30 .subtype(PROP_DISTANCE)
31 .description("Width of the gradient inside of the mesh");
32 b.add_output<decl::Float>("Density Grid").structure_type(StructureType::Grid);
33}
34
36{
37#ifdef WITH_OPENVDB
38 const GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh");
39 const Mesh *mesh = geometry_set.get_mesh();
40 if (!mesh || mesh->faces_num == 0) {
41 params.set_default_remaining_outputs();
42 return;
43 }
44 bke::VolumeGrid<float> grid = geometry::mesh_to_density_grid(
45 mesh->vert_positions(),
46 mesh->corner_verts(),
47 mesh->corner_tris(),
48 params.extract_input<float>("Voxel Size"),
49 params.extract_input<float>("Gradient Width"),
50 params.extract_input<float>("Density"));
51 params.set_output("Density Grid", std::move(grid));
52#else
54#endif
55}
56
57static void node_register()
58{
59 static blender::bke::bNodeType ntype;
60
61 geo_node_type_base(&ntype, "GeometryNodeMeshToDensityGrid", GEO_NODE_MESH_TO_DENSITY_GRID);
62 ntype.ui_name = "Mesh to Density Grid";
63 ntype.ui_description = "Create a filled volume grid from a mesh";
64 ntype.enum_name_legacy = "MESH_TO_DENSITY_GRID";
66 ntype.declare = node_declare;
70}
72
73} // namespace blender::nodes::node_geo_mesh_to_density_grid_cc
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1215
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:447
#define GEO_NODE_MESH_TO_DENSITY_GRID
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_DISTANCE
Definition RNA_types.hh:244
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
void search_link_ops_for_volume_grid_node(GatherLinkSearchOpParams &params)
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:226
std::string ui_description
Definition BKE_node.hh:232
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:347
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:371
NodeDeclareFunction declare
Definition BKE_node.hh:355
max
Definition text_draw.cc:251