Blender V4.3
node_geo_set_material_index.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
6
8#include "DNA_mesh_types.h"
9
10#include "BKE_curves.hh"
11#include "BKE_grease_pencil.hh"
12
14
16{
17 b.add_input<decl::Geometry>("Geometry")
19 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
20 b.add_input<decl::Int>("Material Index").min(0).field_on_all();
21 b.add_output<decl::Geometry>("Geometry").propagate_all();
22}
23
25 const Field<bool> &selection,
26 const Field<int> &material_index)
27{
28 using namespace blender::bke::greasepencil;
29 for (const int layer_index : grease_pencil.layers().index_range()) {
30 Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
31 if (drawing == nullptr) {
32 continue;
33 }
36 bke::GreasePencilLayerFieldContext(grease_pencil, AttrDomain::Curve, layer_index),
37 "material_index",
38 AttrDomain::Curve,
39 selection,
40 material_index);
41 }
42}
43
45{
46 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
47 const Field<bool> selection = params.extract_input<Field<bool>>("Selection");
48 const Field<int> material_index = params.extract_input<Field<int>>("Material Index");
49
50 geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
51 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
52 bke::try_capture_field_on_geometry(mesh->attributes_for_write(),
53 bke::MeshFieldContext(*mesh, AttrDomain::Face),
54 "material_index",
55 AttrDomain::Face,
56 selection,
57 material_index);
58 }
59 if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
60 set_material_index_in_grease_pencil(*grease_pencil, selection, material_index);
61 }
62 });
63 params.set_output("Geometry", std::move(geometry_set));
64}
65
66static void node_register()
67{
68 static blender::bke::bNodeType ntype;
69
71 &ntype, GEO_NODE_SET_MATERIAL_INDEX, "Set Material Index", NODE_CLASS_GEOMETRY);
73 ntype.declare = node_declare;
75}
77
78} // namespace blender::nodes::node_geo_set_material_index_cc
Low-level operations for curves.
Low-level operations for grease pencil.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
#define NOD_REGISTER_NODE(REGISTER_FUNC)
MutableAttributeAccessor attributes_for_write()
bke::CurvesGeometry & strokes_for_write()
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
static void node_declare(NodeDeclarationBuilder &b)
static void set_material_index_in_grease_pencil(GreasePencil &grease_pencil, const Field< bool > &selection, const Field< int > &material_index)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
#define min(a, b)
Definition sort.c:32
void modify_geometry_sets(ForeachSubGeometryCallback callback)
GreasePencil * get_grease_pencil_for_write()
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