23 b.use_custom_socket_order();
24 b.allow_any_socket_order();
32 .propagate_all_geometry()
33 .align_with_previous()
38 .evaluated_geometry_field();
50 const int domain_size = attributes.
domain_size(domain);
56 if (selection.
size() != domain_size) {
65 new_index =
Span(materials, orig_materials_num).first_index_try(material);
68 if (new_index == -1) {
70 new_index = orig_materials_num;
74 if (selection.
size() == domain_size) {
75 attributes.
remove(
"material_index");
77 max_index_cache.ensure([&](std::optional<int> &
data) {
data = new_index; });
81 "material_index", domain);
84 if (new_index == orig_materials_num) {
85 max_index_cache.ensure([&](std::optional<int> &
data) {
data = new_index; });
98 bool no_faces_warning =
false;
99 bool point_selection_warning =
false;
100 bool volume_selection_warning =
false;
103 if (
Mesh *
mesh = geometry_set.get_mesh_for_write()) {
104 if (
mesh->faces_num == 0) {
105 if (
mesh->verts_num > 0) {
106 no_faces_warning =
true;
118 mesh->runtime->max_material_index);
121 if (
Volume *volume = geometry_set.get_volume_for_write()) {
123 if (selection_field.depends_on_input()) {
124 volume_selection_warning =
true;
127 if (
PointCloud *pointcloud = geometry_set.get_pointcloud_for_write()) {
129 if (selection_field.depends_on_input()) {
130 point_selection_warning =
true;
133 if (
Curves *curves_id = geometry_set.get_curves_for_write()) {
143 curves.runtime->max_material_index_cache);
147 for (
const int layer_index :
grease_pencil->layers().index_range()) {
149 if (drawing ==
nullptr) {
166 curves.runtime->max_material_index_cache);
171 if (no_faces_warning) {
173 TIP_(
"Mesh has no faces for material assignment"));
175 if (volume_selection_warning) {
178 TIP_(
"Volumes only support a single material; selection input cannot be a field"));
180 if (point_selection_warning) {
183 TIP_(
"Point clouds only support a single material; selection input cannot be a field"));
186 params.
set_output(
"Geometry"_ustr, std::move(geometry_set));
194 ntype.
ui_name =
"Set Material";
Low-level operations for curves.
Low-level operations for grease pencil.
General operations, lookup, etc. for materials.
#define NODE_CLASS_GEOMETRY
#define GEO_NODE_SET_MATERIAL
#define NOD_REGISTER_NODE(REGISTER_FUNC)
int domain_size(const AttrDomain domain) const
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
bool remove(const StringRef name)
bke::CurvesGeometry & strokes_for_write()
void set_selection(Field< bool > selection)
IndexMask get_evaluated_selection_as_mask() const
void error_message_add(const NodeWarningType type, StringRef message) const
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
void node_register_type(bNodeType &ntype)
void foreach_real_geometry(bke::GeometrySet &geometry, FunctionRef< void(bke::GeometrySet &geometry_set)> fn)
void masked_fill(MutableSpan< T > data, const T &value, const IndexMask &mask)
static void node_geo_exec(GeoNodeExecParams params)
static void assign_material_to_id_geometry(ID *id, const fn::FieldContext &field_context, const Field< bool > &selection_field, MutableAttributeAccessor &attributes, const AttrDomain domain, Material *material, SharedCache< std::optional< int > > &max_index_cache)
static void node_declare(NodeDeclarationBuilder &b)
static void node_register()
void BKE_id_material_eval_assign(ID *id, int slot, Material *material)
short * BKE_id_material_len_p(ID *id)
Material *** BKE_id_material_array_p(ID *id)
BMesh const char void * data
void BKE_id_material_eval_ensure_default_slot(ID *id)
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
MutableVArraySpan< T > span
std::string ui_description
NodeGeometryExecFunction geometry_node_execute
const char * enum_name_legacy
NodeDeclareFunction declare