Blender V4.3
node_geo_set_shade_smooth.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 "DNA_mesh_types.h"
6
7#include "UI_interface.hh"
8#include "UI_resources.hh"
9
10#include "NOD_rna_define.hh"
11
12#include "RNA_enum_types.hh"
13
14#include "node_geometry_util.hh"
15
17
19{
20 b.add_input<decl::Geometry>("Geometry").supported_type(GeometryComponent::Type::Mesh);
21 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
22 b.add_input<decl::Bool>("Shade Smooth").default_value(true).field_on_all();
23 b.add_output<decl::Geometry>("Geometry").propagate_all();
24}
25
26static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
27{
28 uiItemR(layout, ptr, "domain", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
29}
30
31static void node_init(bNodeTree * /*tree*/, bNode *node)
32{
33 node->custom1 = int16_t(AttrDomain::Face);
34}
35
42 const StringRef name,
43 const Field<bool> &selection,
44 const Field<bool> &sharpness)
45{
46 if (selection.node().depends_on_input() || sharpness.node().depends_on_input()) {
47 return false;
48 }
49 if (!fn::evaluate_constant_field(selection)) {
50 return true;
51 }
52 if (fn::evaluate_constant_field(sharpness)) {
53 return false;
54 }
55 mesh.attributes_for_write().remove(name);
56 return true;
57}
58
59static void set_sharp(Mesh &mesh,
60 const AttrDomain domain,
61 const StringRef name,
62 const Field<bool> &selection,
63 const Field<bool> &sharpness)
64{
65 const int domain_size = mesh.attributes().domain_size(domain);
66 if (domain_size == 0) {
67 return;
68 }
69 if (try_removing_sharp_attribute(mesh, name, selection, sharpness)) {
70 return;
71 }
72 bke::try_capture_field_on_geometry(mesh.attributes_for_write(),
73 bke::MeshFieldContext(mesh, domain),
74 name,
75 domain,
76 selection,
77 sharpness);
78}
79
81{
82 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
83 const AttrDomain domain = AttrDomain(params.node().custom1);
84 const Field<bool> selection = params.extract_input<Field<bool>>("Selection");
85 const Field<bool> smooth_field = params.extract_input<Field<bool>>("Shade Smooth");
86
87 geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
88 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
89 set_sharp(*mesh,
90 domain,
91 domain == AttrDomain::Face ? "sharp_face" : "sharp_edge",
93 fn::invert_boolean_field(smooth_field));
94 }
95 });
96 params.set_output("Geometry", std::move(geometry_set));
97}
98
99static void node_rna(StructRNA *srna)
100{
102 "domain",
103 "Domain",
104 "",
107}
108
109static void node_register()
110{
111 static blender::bke::bNodeType ntype;
112
113 geo_node_type_base(&ntype, GEO_NODE_SET_SHADE_SMOOTH, "Set Shade Smooth", NODE_CLASS_GEOMETRY);
115 ntype.declare = node_declare;
116 ntype.initfunc = node_init;
119
120 node_rna(ntype.rna_ext.srna);
121}
123
124} // namespace blender::nodes::node_geo_set_shade_smooth_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_EXPAND
bool depends_on_input() const
Definition FN_field.hh:556
const FieldNode & node() const
Definition FN_field.hh:137
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
bool try_capture_field_on_geometry(MutableAttributeAccessor attributes, const fn::FieldContext &field_context, const StringRef attribute_id, AttrDomain domain, const fn::Field< bool > &selection, const fn::GField &field)
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
Field< bool > invert_boolean_field(const Field< bool > &field)
Definition field.cc:525
void evaluate_constant_field(const GField &field, void *r_value)
Definition field.cc:498
static void node_declare(NodeDeclarationBuilder &b)
static void set_sharp(Mesh &mesh, const AttrDomain domain, const StringRef name, const Field< bool > &selection, const Field< bool > &sharpness)
static void node_init(bNodeTree *, bNode *node)
static bool try_removing_sharp_attribute(Mesh &mesh, const StringRef name, const Field< bool > &selection, const Field< bool > &sharpness)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_geo_exec(GeoNodeExecParams params)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
GPU_SHADER_INTERFACE_INFO(overlay_edit_curve_handle_iface, "vert").flat(Type pos vertex_in(1, Type::UINT, "data") .vertex_out(overlay_edit_curve_handle_iface) .geometry_layout(PrimitiveIn Frequency::GEOMETRY storage_buf(1, Qualifier::READ, "uint", "data[]", Frequency::GEOMETRY) .push_constant(Type Frequency::GEOMETRY selection[]
const EnumPropertyItem rna_enum_attribute_domain_edge_face_items[]
signed short int16_t
Definition stdint.h:76
StructRNA * srna
Definition RNA_types.hh:780
void modify_geometry_sets(ForeachSubGeometryCallback callback)
Defines a node type.
Definition BKE_node.hh:218
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126