Blender V4.3
node_geo_material_replace.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
7#include "DNA_mesh_types.h"
8
10
12
14{
15 b.add_input<decl::Geometry>("Geometry")
17 b.add_input<decl::Material>("Old");
18 b.add_input<decl::Material>("New").translation_context(BLT_I18NCONTEXT_ID_MATERIAL);
19 b.add_output<decl::Geometry>("Geometry").propagate_all();
20}
21
23 Material *src_material,
24 Material *dst_material)
25{
26 for (const int i : materials.index_range()) {
27 if (materials[i] == src_material) {
28 materials[i] = dst_material;
29 }
30 }
31}
32
34{
35 Material *old_material = params.extract_input<Material *>("Old");
36 Material *new_material = params.extract_input<Material *>("New");
37
38 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
39
40 geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
41 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
42 replace_materials({mesh->mat, mesh->totcol}, old_material, new_material);
43 }
44 if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
45 replace_materials({grease_pencil->material_array, grease_pencil->material_array_num},
46 old_material,
47 new_material);
48 }
49 });
50
51 params.set_output("Geometry", std::move(geometry_set));
52}
53
54static void node_register()
55{
56 static blender::bke::bNodeType ntype;
57
58 geo_node_type_base(&ntype, GEO_NODE_REPLACE_MATERIAL, "Replace Material", NODE_CLASS_GEOMETRY);
59 ntype.declare = node_declare;
62}
64
65} // namespace blender::nodes::node_geo_material_replace_cc
Low-level operations for grease pencil.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
#define BLT_I18NCONTEXT_ID_MATERIAL
#define NOD_REGISTER_NODE(REGISTER_FUNC)
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_geo_exec(GeoNodeExecParams params)
static void replace_materials(MutableSpan< Material * > materials, Material *src_material, Material *dst_material)
static void node_declare(NodeDeclarationBuilder &b)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
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