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