Fix #108520: Store Named Attribute node does not propagate values if domain changes

Don't just initialize new values to zero but actually take the existing attribute into account.
Once supported, this can also automatically take defaults for built-in attributes into account
without further changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/131794
This commit is contained in:
Jacques Lucke
2024-12-12 18:11:45 +01:00
parent 4ca3f02601
commit 8e1aec7664

View File

@@ -844,6 +844,7 @@ bool try_capture_fields_on_geometry(MutableAttributeAccessor attributes,
const AttributeValidator validator = attributes.lookup_validator(id);
const fn::GField field = validator.validate_field_if_necessary(fields[input_index]);
const CPPType &type = field.cpp_type();
const eCustomDataType data_type = bke::cpp_type_to_custom_data_type(type);
/* We are writing to an attribute that exists already with the correct domain and type. */
if (const GAttributeReader dst = attributes.lookup(id)) {
@@ -864,7 +865,8 @@ bool try_capture_fields_on_geometry(MutableAttributeAccessor attributes,
* - The field does not depend on that attribute (we can't easily check for that yet). */
void *buffer = MEM_mallocN_aligned(type.size() * domain_size, type.alignment(), __func__);
if (!selection_is_full) {
type.value_initialize_n(buffer, domain_size);
const GAttributeReader old_attribute = attributes.lookup_or_default(id, domain, data_type);
old_attribute.varray.materialize(buffer);
}
GMutableSpan dst(type, buffer, domain_size);