Blender  V3.3
node_geo_set_shade_smooth.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "node_geometry_util.hh"
4 
6 
8 {
9  b.add_input<decl::Geometry>(N_("Geometry")).supported_type(GEO_COMPONENT_TYPE_MESH);
10  b.add_input<decl::Bool>(N_("Selection")).default_value(true).hide_value().supports_field();
11  b.add_input<decl::Bool>(N_("Shade Smooth")).supports_field().default_value(true);
12  b.add_output<decl::Geometry>(N_("Geometry"));
13 }
14 
16  const Field<bool> &selection_field,
17  const Field<bool> &shade_field)
18 {
19  const int domain_size = component.attribute_domain_size(ATTR_DOMAIN_FACE);
20  if (domain_size == 0) {
21  return;
22  }
23  MutableAttributeAccessor attributes = *component.attributes_for_write();
24 
26 
27  AttributeWriter<bool> shades = attributes.lookup_or_add_for_write<bool>("shade_smooth",
29 
30  fn::FieldEvaluator evaluator{field_context, domain_size};
31  evaluator.set_selection(selection_field);
32  evaluator.add_with_destination(shade_field, shades.varray);
33  evaluator.evaluate();
34 
35  shades.finish();
36 }
37 
39 {
40  GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
41  Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
42  Field<bool> shade_field = params.extract_input<Field<bool>>("Shade Smooth");
43 
44  geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
45  if (geometry_set.has_mesh()) {
47  geometry_set.get_component_for_write<MeshComponent>(), selection_field, shade_field);
48  }
49  });
50  params.set_output("Geometry", std::move(geometry_set));
51 }
52 
53 } // namespace blender::nodes::node_geo_set_shade_smooth_cc
54 
56 {
58 
59  static bNodeType ntype;
60 
64  nodeRegisterType(&ntype);
65 }
@ ATTR_DOMAIN_FACE
Definition: BKE_attribute.h:29
@ GEO_COMPONENT_TYPE_MESH
#define GEO_NODE_SET_SHADE_SMOOTH
Definition: BKE_node.h:1456
#define NODE_CLASS_GEOMETRY
Definition: BKE_node.h:359
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:108
GAttributeWriter lookup_or_add_for_write(const AttributeIDRef &attribute_id, const eAttrDomain domain, const eCustomDataType data_type, const AttributeInit &initializer=AttributeInitDefault())
void set_selection(Field< bool > selection)
Definition: FN_field.hh:366
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static void node_declare(NodeDeclarationBuilder &b)
static void set_smooth_in_component(GeometryComponent &component, const Field< bool > &selection_field, const Field< bool > &shade_field)
static void node_geo_exec(GeoNodeExecParams params)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_geo_set_shade_smooth()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
GeometryComponent & get_component_for_write(GeometryComponentType component_type)
void modify_geometry_sets(ForeachSubGeometryCallback callback)
bool has_mesh() const
Defines a node type.
Definition: BKE_node.h:226
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:316
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)