Blender V4.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 "BKE_mesh.hh"
6#include "BKE_volume_grid.hh"
7
9
10#include "node_geometry_util.hh"
11
13
15
17{
18 b.add_input<decl::Geometry>("Mesh").supported_type(GeometryComponent::Type::Mesh);
19 b.add_input<decl::Float>("Density").default_value(1.0f).min(0.01f).max(FLT_MAX);
20 b.add_input<decl::Float>("Voxel Size")
21 .default_value(0.3f)
22 .min(0.01f)
23 .max(FLT_MAX)
25 b.add_input<decl::Float>("Gradient Width")
26 .default_value(0.2f)
27 .min(0.0001f)
28 .max(FLT_MAX)
30 .description("Width of the gradient inside of the mesh");
31 b.add_output<decl::Float>("Density Grid");
32}
33
35{
36#ifdef WITH_OPENVDB
37 const GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh");
38 const Mesh *mesh = geometry_set.get_mesh();
39 if (!mesh || mesh->faces_num == 0) {
40 params.set_default_remaining_outputs();
41 return;
42 }
43 bke::VolumeGrid<float> grid = geometry::mesh_to_density_grid(
44 mesh->vert_positions(),
45 mesh->corner_verts(),
46 mesh->corner_tris(),
47 params.extract_input<float>("Voxel Size"),
48 params.extract_input<float>("Gradient Width"),
49 params.extract_input<float>("Density"));
50 params.set_output("Density Grid", std::move(grid));
51#else
53#endif
54}
55
56static void node_register()
57{
58 static blender::bke::bNodeType ntype;
59
61 &ntype, GEO_NODE_MESH_TO_DENSITY_GRID, "Mesh to Density Grid", NODE_CLASS_GEOMETRY);
62 ntype.declare = node_declare;
66}
68
69} // namespace blender::nodes::node_geo_mesh_to_density_grid_cc
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_DISTANCE
Definition RNA_types.hh:159
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
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, int type, const char *name, short nclass)
#define FLT_MAX
Definition stdcycles.h:14
const Mesh * get_mesh() const
Defines a node type.
Definition BKE_node.hh:218
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:363
NodeDeclareFunction declare
Definition BKE_node.hh:347