Blender  V3.3
node_geo_material_replace.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 
5 #include "UI_interface.h"
6 #include "UI_resources.h"
7 
8 #include "DNA_mesh_types.h"
9 #include "DNA_meshdata_types.h"
10 
11 #include "BKE_material.h"
12 
14 
16 {
17  b.add_input<decl::Geometry>(N_("Geometry")).supported_type(GEO_COMPONENT_TYPE_MESH);
18  b.add_input<decl::Material>(N_("Old"));
19  b.add_input<decl::Material>(N_("New"));
20  b.add_output<decl::Geometry>(N_("Geometry"));
21 }
22 
24 {
25  Material *old_material = params.extract_input<Material *>("Old");
26  Material *new_material = params.extract_input<Material *>("New");
27 
28  GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
29 
30  geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
31  if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
32  for (const int i : IndexRange(mesh->totcol)) {
33  if (mesh->mat[i] == old_material) {
34  mesh->mat[i] = new_material;
35  }
36  }
37  }
38  });
39 
40  params.set_output("Geometry", std::move(geometry_set));
41 }
42 
43 } // namespace blender::nodes::node_geo_material_replace_cc
44 
46 {
48 
49  static bNodeType ntype;
50 
54  nodeRegisterType(&ntype);
55 }
@ GEO_COMPONENT_TYPE_MESH
General operations, lookup, etc. for materials.
#define GEO_NODE_REPLACE_MATERIAL
Definition: BKE_node.h:1404
#define NODE_CLASS_GEOMETRY
Definition: BKE_node.h:359
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_geo_material_replace()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
void modify_geometry_sets(ForeachSubGeometryCallback callback)
struct Material ** mat
short totcol
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)