Fix: Geometry Nodes: Create instance attribute of the right type #110146

Merged
Hans Goudey merged 8 commits from mod_moder/blender:tmp_fix_instances_crash into blender-v4.0-release 2023-10-14 10:54:41 +02:00
1 changed files with 15 additions and 13 deletions

View File

@ -161,25 +161,27 @@ static void add_instances_from_component(
bke::MutableAttributeAccessor dst_attributes = dst_component.attributes_for_write();
for (const auto item : attributes_to_propagate.items()) {
const AttributeIDRef &id = item.key;
const bke::GAttributeReader src = src_attributes.lookup(id, ATTR_DOMAIN_POINT);
const eCustomDataType data_type = item.value.data_type;
const bke::GAttributeReader src = src_attributes.lookup(id, ATTR_DOMAIN_POINT, data_type);
mod_moder marked this conversation as resolved Outdated

I think this achieves the same thing, but more automatically:

    const bke::GAttributeReader src = src_attributes.lookup(
        id, ATTR_DOMAIN_POINT, item.value.data_type);
I think this achieves the same thing, but more automatically: ``` const bke::GAttributeReader src = src_attributes.lookup( id, ATTR_DOMAIN_POINT, item.value.data_type); ```
if (!src) {
/* Domain interpolation can fail if the source domain is empty. */
continue;
}
const eCustomDataType type = bke::cpp_type_to_custom_data_type(src.varray.type());
if (src.varray.size() == dst_component.instances_num() && src.sharing_info &&
src.varray.is_span()) {
const bke::AttributeInitShared init(src.varray.get_internal_span().data(),
*src.sharing_info);
dst_attributes.add(id, ATTR_DOMAIN_INSTANCE, type, init);
}
else {
GSpanAttributeWriter dst = dst_attributes.lookup_or_add_for_write_only_span(
id, ATTR_DOMAIN_INSTANCE, type);
array_utils::gather(src.varray, selection, dst.span.slice(start_len, select_len));
dst.finish();
if (!dst_attributes.contains(id)) {
if (src.varray.size() == dst_component.instances_num() && src.sharing_info &&
src.varray.is_span()) {
const bke::AttributeInitShared init(src.varray.get_internal_span().data(),
*src.sharing_info);
dst_attributes.add(id, ATTR_DOMAIN_INSTANCE, data_type, init);
continue;
}
dst_attributes.add(id, ATTR_DOMAIN_INSTANCE, data_type, bke::AttributeInitConstruct());
}
GSpanAttributeWriter dst = dst_attributes.lookup_for_write_span(id);
array_utils::gather(src.varray, selection, dst.span.slice(start_len, select_len));
dst.finish();
}
}