Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc47
1 files changed, 39 insertions, 8 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc
index f0f032ed8f4..4f70252ae75 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc
@@ -18,17 +18,15 @@
#include "BKE_subdiv.h"
#include "BKE_subdiv_mesh.h"
+#include "DNA_modifier_types.h"
#include "UI_interface.h"
#include "UI_resources.h"
-
#include "node_geometry_util.hh"
static bNodeSocketTemplate geo_node_subdivision_surface_in[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{SOCK_INT, N_("Level"), 1, 0, 0, 0, 0, 6},
{SOCK_BOOLEAN, N_("Use Creases")},
- {SOCK_BOOLEAN, N_("Boundary Smooth"), true},
- {SOCK_BOOLEAN, N_("Smooth UVs")},
{-1, ""},
};
@@ -37,6 +35,30 @@ static bNodeSocketTemplate geo_node_subdivision_surface_out[] = {
{-1, ""},
};
+static void geo_node_subdivision_surface_layout(uiLayout *layout,
+ bContext *UNUSED(C),
+ PointerRNA *ptr)
+{
+#ifndef WITH_OPENSUBDIV
+ UNUSED_VARS(ptr);
+ uiItemL(layout, IFACE_("Disabled, built without OpenSubdiv"), ICON_ERROR);
+#else
+ uiLayoutSetPropSep(layout, true);
+ uiLayoutSetPropDecorate(layout, false);
+ uiItemR(layout, ptr, "uv_smooth", 0, nullptr, ICON_NONE);
+ uiItemR(layout, ptr, "boundary_smooth", 0, nullptr, ICON_NONE);
+#endif
+}
+
+static void geo_node_subdivision_surface_init(bNodeTree *UNUSED(ntree), bNode *node)
+{
+ NodeGeometrySubdivisionSurface *data = (NodeGeometrySubdivisionSurface *)MEM_callocN(
+ sizeof(NodeGeometrySubdivisionSurface), __func__);
+ data->uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_BOUNDARIES;
+ data->boundary_smooth = SUBSURF_BOUNDARY_SMOOTH_ALL;
+ node->storage = data;
+}
+
namespace blender::nodes {
static void geo_node_subdivision_surface_exec(GeoNodeExecParams params)
{
@@ -53,6 +75,10 @@ static void geo_node_subdivision_surface_exec(GeoNodeExecParams params)
params.error_message_add(NodeWarningType::Error,
TIP_("Disabled, Blender was compiled without OpenSubdiv"));
#else
+ const NodeGeometrySubdivisionSurface &storage =
+ *(const NodeGeometrySubdivisionSurface *)params.node().storage;
+ const int uv_smooth = storage.uv_smooth;
+ const int boundary_smooth = storage.boundary_smooth;
const int subdiv_level = clamp_i(params.extract_input<int>("Level"), 0, 30);
/* Only process subdivision if level is greater than 0. */
@@ -62,8 +88,6 @@ static void geo_node_subdivision_surface_exec(GeoNodeExecParams params)
}
const bool use_crease = params.extract_input<bool>("Use Creases");
- const bool boundary_smooth = params.extract_input<bool>("Boundary Smooth");
- const bool smooth_uvs = params.extract_input<bool>("Smooth UVs");
const Mesh *mesh_in = geometry_set.get_mesh_for_read();
/* Initialize mesh settings. */
@@ -79,9 +103,9 @@ static void geo_node_subdivision_surface_exec(GeoNodeExecParams params)
subdiv_settings.level = subdiv_level;
subdiv_settings.vtx_boundary_interpolation = BKE_subdiv_vtx_boundary_interpolation_from_subsurf(
- !boundary_smooth);
+ boundary_smooth);
subdiv_settings.fvar_linear_interpolation = BKE_subdiv_fvar_interpolation_from_uv_smooth(
- smooth_uvs);
+ uv_smooth);
/* Apply subdivision to mesh. */
Subdiv *subdiv = BKE_subdiv_update_from_mesh(nullptr, &subdiv_settings, mesh_in);
@@ -93,7 +117,7 @@ static void geo_node_subdivision_surface_exec(GeoNodeExecParams params)
}
Mesh *mesh_out = BKE_subdiv_to_mesh(subdiv, &mesh_settings, mesh_in);
- BKE_mesh_calc_normals(mesh_out);
+ BKE_mesh_normals_tag_dirty(mesh_out);
MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
mesh_component.replace(mesh_out);
@@ -117,5 +141,12 @@ void register_node_type_geo_subdivision_surface()
node_type_socket_templates(
&ntype, geo_node_subdivision_surface_in, geo_node_subdivision_surface_out);
ntype.geometry_node_execute = blender::nodes::geo_node_subdivision_surface_exec;
+ ntype.draw_buttons = geo_node_subdivision_surface_layout;
+ node_type_init(&ntype, geo_node_subdivision_surface_init);
+ node_type_size_preset(&ntype, NODE_SIZE_MIDDLE);
+ node_type_storage(&ntype,
+ "NodeGeometrySubdivisionSurface",
+ node_free_standard_storage,
+ node_copy_standard_storage);
nodeRegisterType(&ntype);
}