Fix #114657: Store default color attribute on store if none set yet
When there is no default color attribute yet, when creating a new color attribute with the store named attribute node, set the default. Though we generally try to avoid this more magical behavior, there's little downside in this case, and it's probably what users expect. Don't set the active attribute though, since that's UI data that generally shouldn't be changed procedurally. It's okay if there's no active color attribute. Pull Request: https://projects.blender.org/blender/blender/pulls/117249
This commit is contained in:
@@ -21,6 +21,10 @@ using index_mask::IndexMask;
|
||||
#include "BKE_mesh_types.hh"
|
||||
|
||||
namespace blender::bke {
|
||||
|
||||
enum class AttrDomain : int8_t;
|
||||
class AttributeIDRef;
|
||||
|
||||
namespace mesh {
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Polygon Data Evaluation
|
||||
@@ -334,4 +338,10 @@ void mesh_select_edge_flush(Mesh &mesh);
|
||||
/** Make vertex and edge visibility consistent with faces. */
|
||||
void mesh_select_face_flush(Mesh &mesh);
|
||||
|
||||
/** Set the default name when adding a color attribute if there is no default yet. */
|
||||
void mesh_ensure_default_color_attribute_on_add(Mesh &mesh,
|
||||
const AttributeIDRef &id,
|
||||
AttrDomain domain,
|
||||
eCustomDataType data_type);
|
||||
|
||||
} // namespace blender::bke
|
||||
|
||||
@@ -645,6 +645,25 @@ MutableSpan<MDeformVert> Mesh::deform_verts_for_write()
|
||||
|
||||
namespace blender::bke {
|
||||
|
||||
void mesh_ensure_default_color_attribute_on_add(Mesh &mesh,
|
||||
const AttributeIDRef &id,
|
||||
AttrDomain domain,
|
||||
eCustomDataType data_type)
|
||||
{
|
||||
if (id.is_anonymous()) {
|
||||
return;
|
||||
}
|
||||
if (!(CD_TYPE_AS_MASK(data_type) & CD_MASK_COLOR_ALL) ||
|
||||
!(ATTR_DOMAIN_AS_MASK(domain) & ATTR_DOMAIN_MASK_COLOR))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (mesh.default_color_attribute) {
|
||||
return;
|
||||
}
|
||||
mesh.default_color_attribute = BLI_strdupn(id.name().data(), id.name().size());
|
||||
}
|
||||
|
||||
static void mesh_ensure_cdlayers_primary(Mesh &mesh)
|
||||
{
|
||||
MutableAttributeAccessor attributes = mesh.attributes_for_write();
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "RNA_access.hh"
|
||||
#include "RNA_enum_types.hh"
|
||||
|
||||
#include "BKE_mesh.hh"
|
||||
#include "BKE_type_conversions.hh"
|
||||
|
||||
#include "NOD_rna_define.hh"
|
||||
@@ -134,11 +135,15 @@ static void node_geo_exec(GeoNodeExecParams params)
|
||||
{
|
||||
if (geometry_set.has(type)) {
|
||||
GeometryComponent &component = geometry_set.get_component_for_write(type);
|
||||
if (!bke::try_capture_field_on_geometry(component, name, domain, selection, field)) {
|
||||
if (component.attribute_domain_size(domain) != 0) {
|
||||
failure.store(true);
|
||||
if (bke::try_capture_field_on_geometry(component, name, domain, selection, field)) {
|
||||
if (component.type() == GeometryComponent::Type::Mesh) {
|
||||
Mesh &mesh = *geometry_set.get_mesh_for_write();
|
||||
bke::mesh_ensure_default_color_attribute_on_add(mesh, name, domain, data_type);
|
||||
}
|
||||
}
|
||||
else if (component.attribute_domain_size(domain) != 0) {
|
||||
failure.store(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user