Blender V5.3
node_geo_geometry_materials.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_material.hh"
6
7#include "DNA_curves_types.h"
9#include "DNA_mesh_types.h"
10#include "DNA_object_types.h"
12
14
15#include "RNA_enum_types.hh"
16
17#include "UI_interface_icons.hh"
18
19#include "node_geometry_util.hh"
20
22
24{
25 b.add_input<decl::Geometry>("Geometry"_ustr);
26 b.add_input<decl::Menu>("Component Type"_ustr)
28 [](const EnumPropertyItem &item) {
34 })
35 .optional_label();
36 b.add_output<decl::Material>("Materials"_ustr).structure_type(StructureType::List);
37}
38
40{
41 const GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"_ustr);
43 "Component Type"_ustr);
44
45 Material **materials = nullptr;
46 int count = 0;
47
48 switch (component) {
50 if (const Curves *curves = geometry_set.get_curves()) {
51 materials = curves->mat;
52 count = curves->totcol;
53 }
54 break;
55 }
57 if (const GreasePencil *grease_pencil = geometry_set.get_grease_pencil()) {
58 materials = grease_pencil->material_array;
59 count = grease_pencil->material_array_num;
60 }
61 break;
62 }
64 if (const Mesh *mesh = geometry_set.get_mesh()) {
65 materials = mesh->mat;
66 count = mesh->totcol;
67 }
68 break;
69 }
71 if (const PointCloud *point_cloud = geometry_set.get_pointcloud()) {
72 materials = point_cloud->mat;
73 count = point_cloud->totcol;
74 }
75 break;
76 }
77 default:
78 break;
79 }
80
81 if (count == 0 || materials == nullptr) {
83 return;
84 }
85
86 const CPPType &type = CPPType::get<Material *>();
87 GArray<> array(type, count, NoInitialization());
88 type.copy_construct_n(materials, array.data(), count);
89 params.set_output("Materials"_ustr, GList::from_garray(std::move(array)));
90}
91
92static void node_register()
93{
94 static bke::bNodeType ntype;
95
96 geo_node_type_base(&ntype, "GeometryNodeGeometryMaterials"_ustr);
97 ntype.ui_name = "Geometry Materials";
98 ntype.ui_description = "Get a list of the materials used by a geometry component";
101 ntype.declare = node_declare;
103}
105
106} // namespace blender::nodes::node_geo_geometry_materials
General operations, lookup, etc. for materials.
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
Object is a sort of wrapper for general info.
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define ELEM(...)
void copy_construct_n(const void *src, void *dst, int64_t n) const
static const CPPType & get()
static GListPtr from_garray(GArray<> array)
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
const EnumPropertyItem rna_enum_geometry_component_type_items[]
Definition rna_space.cc:51
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
const GreasePencil * get_grease_pencil() const
const Curves * get_curves() const
const PointCloud * get_pointcloud() const
const Mesh * get_mesh() const
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
NodeDeclareFunction declare
Definition BKE_node.hh:393