Attributes: Integrate implicit sharing with the attribute API #107059
|
@ -660,10 +660,16 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
|
|||
MutableAttributeAccessor attributes = mesh_final->attributes_for_write();
|
||||
const AttributeReader positions = attributes.lookup<float3>("position");
|
||||
if (positions) {
|
||||
attributes.add<float3>(
|
||||
"rest_position",
|
||||
ATTR_DOMAIN_POINT,
|
||||
AttributeInitShared(positions.varray.common_info().data, *positions.sharing_info));
|
||||
if (positions.sharing_info && positions.varray.is_span()) {
|
||||
attributes.add<float3>("rest_position",
|
||||
ATTR_DOMAIN_POINT,
|
||||
AttributeInitShared(positions.varray.get_internal_span().data(),
|
||||
|
||||
*positions.sharing_info));
|
||||
}
|
||||
else {
|
||||
attributes.add<float3>(
|
||||
"rest_position", ATTR_DOMAIN_POINT, AttributeInitVArray(positions.varray));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -168,7 +168,8 @@ static void add_instances_from_component(
|
|||
}
|
||||
|
||||
const eCustomDataType type = bke::cpp_type_to_custom_data_type(src.varray.type());
|
||||
if (src.varray.size() == dst_component.instances_num() && src.sharing_info) {
|
||||
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);
|
||||
|
|
|
@ -72,7 +72,8 @@ static void convert_instances_to_points(GeometrySet &geometry_set,
|
|||
const eCustomDataType type = item.value.data_type;
|
||||
|
||||
const GAttributeReader src = src_attributes.lookup(id);
|
||||
if (selection.size() == instances.instances_num() && src.sharing_info) {
|
||||
if (selection.size() == instances.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_POINT, type, init);
|
||||
|
|
|
@ -579,8 +579,15 @@ static void interpolate_curve_attributes(bke::CurvesGeometry &child_curves,
|
|||
}
|
||||
|
||||
const GAttributeReader src = point_attributes.lookup(id);
|
||||
const bke::AttributeInitShared init(src.varray.get_internal_span().data(), *src.sharing_info);
|
||||
children_attributes.add(id, ATTR_DOMAIN_CURVE, meta_data.data_type, init);
|
||||
if (src.sharing_info && src.varray.is_span()) {
|
||||
const bke::AttributeInitShared init(src.varray.get_internal_span().data(),
|
||||
*src.sharing_info);
|
||||
children_attributes.add(id, ATTR_DOMAIN_CURVE, meta_data.data_type, init);
|
||||
}
|
||||
else {
|
||||
children_attributes.add(
|
||||
id, ATTR_DOMAIN_CURVE, meta_data.data_type, bke::AttributeInitVArray(src.varray));
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ static void geometry_set_mesh_to_points(GeometrySet &geometry_set,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (share_arrays && src.domain == domain && src.sharing_info) {
|
||||
if (share_arrays && src.domain == domain && src.sharing_info && src.varray.is_span()) {
|
||||
const bke::AttributeInitShared init(src.varray.get_internal_span().data(),
|
||||
*src.sharing_info);
|
||||
dst_attributes.add(attribute_id, ATTR_DOMAIN_POINT, data_type, init);
|
||||
|
|
|
@ -67,7 +67,7 @@ static void geometry_set_points_to_vertices(
|
|||
const AttributeIDRef id = entry.key;
|
||||
const eCustomDataType data_type = entry.value.data_type;
|
||||
const GAttributeReader src = src_attributes.lookup(id);
|
||||
if (selection.size() == points->totpoint && src.sharing_info) {
|
||||
if (selection.size() == points->totpoint && 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_POINT, data_type, init);
|
||||
|
|
Loading…
Reference in New Issue
I think you make too many implicit assumptions here:
Both assumptions generally have to be checked for.
I thought it was reasonable to assume that
sharing_info != nullptr
impliesvarray.is_span()
, but I can also check the latter explicitly too. I guess this will get nicer when attributes don't always have to be stored as contiguous arrays.I should definitely check for
sharing_info
here though. I did it elsewhere and forgot here.