Blender V5.0
node_geo_mesh_to_sdf_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{
17 b.add_input<decl::Geometry>("Mesh")
18 .supported_type(GeometryComponent::Type::Mesh)
19 .description("Mesh whose inner volume is converted to a signed distance field grid");
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::Int>("Band Width")
26 .default_value(3)
27 .min(1)
28 .max(100)
29 .description("Width of the active voxel surface, in voxels");
30 b.add_output<decl::Float>("SDF Grid").structure_type(StructureType::Grid);
31}
32
34{
35#ifdef WITH_OPENVDB
36 const GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh");
37 const Mesh *mesh = geometry_set.get_mesh();
38 if (!mesh || mesh->faces_num == 0) {
39 params.set_default_remaining_outputs();
40 return;
41 }
42 bke::VolumeGrid<float> grid = geometry::mesh_to_sdf_grid(
43 mesh->vert_positions(),
44 mesh->corner_verts(),
45 mesh->corner_tris(),
46 params.extract_input<float>("Voxel Size"),
47 std::max(1, params.extract_input<int>("Band Width")));
48 if (!grid) {
49 params.set_default_remaining_outputs();
50 return;
51 }
52 params.set_output("SDF Grid", std::move(grid));
53#else
55#endif
56}
57
58static void node_register()
59{
60 static blender::bke::bNodeType ntype;
61
62 geo_node_type_base(&ntype, "GeometryNodeMeshToSDFGrid", GEO_NODE_MESH_TO_SDF_GRID);
63 ntype.ui_name = "Mesh to SDF Grid";
64 ntype.ui_description = "Create a signed distance volume grid from a mesh";
65 ntype.enum_name_legacy = "MESH_TO_SDF_GRID";
67 ntype.declare = node_declare;
70}
72
73} // namespace blender::nodes::node_geo_mesh_to_sdf_grid_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define GEO_NODE_MESH_TO_SDF_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
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
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 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