Blender V4.3
node_geo_mesh_subdivide.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_subdiv.hh"
6#include "BKE_subdiv_mesh.hh"
7
8#include "UI_resources.hh"
9
10#include "GEO_randomize.hh"
11
12#include "node_geometry_util.hh"
13
15
17{
18 b.add_input<decl::Geometry>("Mesh").supported_type(GeometryComponent::Type::Mesh);
19 b.add_input<decl::Int>("Level").default_value(1).min(0).max(6);
20 b.add_output<decl::Geometry>("Mesh").propagate_all();
21}
22
23#ifdef WITH_OPENSUBDIV
24static Mesh *simple_subdivide_mesh(const Mesh &mesh, const int level)
25{
26 /* Initialize mesh settings. */
27 bke::subdiv::ToMeshSettings mesh_settings;
28 mesh_settings.resolution = (1 << level) + 1;
29 mesh_settings.use_optimal_display = false;
30
31 /* Initialize subdivision settings. */
32 bke::subdiv::Settings subdiv_settings;
33 subdiv_settings.is_simple = true;
34 subdiv_settings.is_adaptive = false;
35 subdiv_settings.use_creases = false;
36 subdiv_settings.level = 1;
37 subdiv_settings.vtx_boundary_interpolation =
40
41 /* Apply subdivision from mesh. */
42 bke::subdiv::Subdiv *subdiv = bke::subdiv::new_from_mesh(&subdiv_settings, &mesh);
43 if (!subdiv) {
44 return nullptr;
45 }
46
47 Mesh *result = bke::subdiv::subdiv_to_mesh(subdiv, &mesh_settings, &mesh);
48
49 bke::subdiv::free(subdiv);
50
52 return result;
53}
54#endif /* WITH_OPENSUBDIV */
55
57{
58 GeometrySet geometry_set = params.extract_input<GeometrySet>("Mesh");
59#ifdef WITH_OPENSUBDIV
60 /* See CCGSUBSURF_LEVEL_MAX for max limit. */
61 const int level = clamp_i(params.extract_input<int>("Level"), 0, 11);
62 if (level == 0) {
63 params.set_output("Mesh", std::move(geometry_set));
64 return;
65 }
66
67 geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
68 if (const Mesh *mesh = geometry_set.get_mesh()) {
69 geometry_set.replace_mesh(simple_subdivide_mesh(*mesh, level));
70 }
71 });
72#else
73 params.error_message_add(NodeWarningType::Error,
74 TIP_("Disabled, Blender was compiled without OpenSubdiv"));
75#endif
76 params.set_output("Mesh", std::move(geometry_set));
77}
78
79static void node_register()
80{
81 static blender::bke::bNodeType ntype;
82
83 geo_node_type_base(&ntype, GEO_NODE_SUBDIVIDE_MESH, "Subdivide Mesh", NODE_CLASS_GEOMETRY);
84 ntype.declare = node_declare;
87}
89
90} // namespace blender::nodes::node_geo_mesh_subdivide_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
MINLINE int clamp_i(int value, int min, int max)
#define TIP_(msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void free(Subdiv *subdiv)
Definition subdiv.cc:192
Subdiv * new_from_mesh(const Settings *settings, const Mesh *mesh)
Definition subdiv.cc:133
FVarLinearInterpolation fvar_interpolation_from_uv_smooth(int uv_smooth)
Definition subdiv.cc:49
VtxBoundaryInterpolation vtx_boundary_interpolation_from_subsurf(int boundary_smooth)
Definition subdiv.cc:69
Mesh * subdiv_to_mesh(Subdiv *subdiv, const ToMeshSettings *settings, const Mesh *coarse_mesh)
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
void debug_randomize_mesh_order(Mesh *mesh)
Definition randomize.cc:220
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
const Mesh * get_mesh() const
void modify_geometry_sets(ForeachSubGeometryCallback callback)
Defines a node type.
Definition BKE_node.hh:218
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
NodeDeclareFunction declare
Definition BKE_node.hh:347
VtxBoundaryInterpolation vtx_boundary_interpolation
Definition BKE_subdiv.hh:70
FVarLinearInterpolation fvar_linear_interpolation
Definition BKE_subdiv.hh:71