Cleanup: encapsulate check for whether attribute is built-in
This commit is contained in:
@@ -802,4 +802,6 @@ class GreasePencilComponent : public GeometryComponent {
|
||||
std::optional<MutableAttributeAccessor> attributes_for_write() final;
|
||||
};
|
||||
|
||||
bool attribute_is_builtin_on_component_type(const GeometryComponent::Type type, StringRef name);
|
||||
|
||||
} // namespace blender::bke
|
||||
|
||||
@@ -653,6 +653,42 @@ void GeometrySet::propagate_attributes_from_layer_to_instances(
|
||||
});
|
||||
}
|
||||
|
||||
bool attribute_is_builtin_on_component_type(const GeometryComponent::Type type,
|
||||
const StringRef name)
|
||||
{
|
||||
switch (type) {
|
||||
case GeometryComponent::Type::Mesh: {
|
||||
static auto component = GeometryComponent::create(type);
|
||||
return component->attributes()->is_builtin(name);
|
||||
}
|
||||
case GeometryComponent::Type::PointCloud: {
|
||||
static auto component = GeometryComponent::create(type);
|
||||
return component->attributes()->is_builtin(name);
|
||||
}
|
||||
case GeometryComponent::Type::Instance: {
|
||||
static auto component = GeometryComponent::create(type);
|
||||
return component->attributes()->is_builtin(name);
|
||||
}
|
||||
case GeometryComponent::Type::Curve: {
|
||||
static auto component = GeometryComponent::create(type);
|
||||
return component->attributes()->is_builtin(name);
|
||||
}
|
||||
case GeometryComponent::Type::GreasePencil: {
|
||||
static auto grease_pencil_component = GeometryComponent::create(
|
||||
GeometryComponent::Type::GreasePencil);
|
||||
static auto curves_component = GeometryComponent::create(GeometryComponent::Type::Curve);
|
||||
return grease_pencil_component->attributes()->is_builtin(name) ||
|
||||
curves_component->attributes()->is_builtin(name);
|
||||
}
|
||||
case GeometryComponent::Type::Volume:
|
||||
case GeometryComponent::Type::Edit: {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
BLI_assert_unreachable();
|
||||
return false;
|
||||
}
|
||||
|
||||
void GeometrySet::gather_attributes_for_propagation(
|
||||
const Span<GeometryComponent::Type> component_types,
|
||||
const GeometryComponent::Type dst_component_type,
|
||||
@@ -660,9 +696,6 @@ void GeometrySet::gather_attributes_for_propagation(
|
||||
const AttributeFilter &attribute_filter,
|
||||
Map<StringRef, AttributeKind> &r_attributes) const
|
||||
{
|
||||
/* Only needed right now to check if an attribute is built-in on this component type.
|
||||
* TODO: Get rid of the dummy component. */
|
||||
const GeometryComponentPtr dummy_component = GeometryComponent::create(dst_component_type);
|
||||
this->attribute_foreach(
|
||||
component_types,
|
||||
include_instances,
|
||||
@@ -670,7 +703,7 @@ void GeometrySet::gather_attributes_for_propagation(
|
||||
const AttributeMetaData &meta_data,
|
||||
const GeometryComponent &component) {
|
||||
if (component.attributes()->is_builtin(attribute_id)) {
|
||||
if (!dummy_component->attributes()->is_builtin(attribute_id)) {
|
||||
if (!attribute_is_builtin_on_component_type(dst_component_type, attribute_id)) {
|
||||
/* Don't propagate built-in attributes that are not built-in on the destination
|
||||
* component. */
|
||||
return;
|
||||
|
||||
@@ -859,53 +859,50 @@ static void gather_attributes_for_propagation(
|
||||
const bke::AttributeFilter &attribute_filter,
|
||||
Map<StringRef, AttributeKind> &r_attributes)
|
||||
{
|
||||
/* Only needed right now to check if an attribute is built-in on this component type.
|
||||
* TODO: Get rid of the dummy component. */
|
||||
const bke::GeometryComponentPtr dummy_component = bke::GeometryComponent::create(
|
||||
dst_component_type);
|
||||
attribute_foreach(geometry_set,
|
||||
component_types,
|
||||
0,
|
||||
VariedDepthOptions::MAX_DEPTH,
|
||||
instance_depth,
|
||||
selection,
|
||||
[&](const StringRef attribute_id,
|
||||
const AttributeMetaData &meta_data,
|
||||
const bke::GeometryComponent &component) {
|
||||
if (component.attributes()->is_builtin(attribute_id)) {
|
||||
if (!dummy_component->attributes()->is_builtin(attribute_id)) {
|
||||
/* Don't propagate built-in attributes that are not built-in on the
|
||||
* destination component. */
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (meta_data.data_type == CD_PROP_STRING) {
|
||||
/* Propagating string attributes is not supported yet. */
|
||||
return;
|
||||
}
|
||||
if (attribute_filter.allow_skip(attribute_id)) {
|
||||
return;
|
||||
}
|
||||
attribute_foreach(
|
||||
geometry_set,
|
||||
component_types,
|
||||
0,
|
||||
VariedDepthOptions::MAX_DEPTH,
|
||||
instance_depth,
|
||||
selection,
|
||||
[&](const StringRef attribute_id,
|
||||
const AttributeMetaData &meta_data,
|
||||
const bke::GeometryComponent &component) {
|
||||
if (component.attributes()->is_builtin(attribute_id)) {
|
||||
if (!bke::attribute_is_builtin_on_component_type(dst_component_type, attribute_id)) {
|
||||
/* Don't propagate built-in attributes that are not built-in on the
|
||||
* destination component. */
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (meta_data.data_type == CD_PROP_STRING) {
|
||||
/* Propagating string attributes is not supported yet. */
|
||||
return;
|
||||
}
|
||||
if (attribute_filter.allow_skip(attribute_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
AttrDomain domain = meta_data.domain;
|
||||
if (dst_component_type != bke::GeometryComponent::Type::Instance &&
|
||||
domain == AttrDomain::Instance)
|
||||
{
|
||||
domain = AttrDomain::Point;
|
||||
}
|
||||
AttrDomain domain = meta_data.domain;
|
||||
if (dst_component_type != bke::GeometryComponent::Type::Instance &&
|
||||
domain == AttrDomain::Instance)
|
||||
{
|
||||
domain = AttrDomain::Point;
|
||||
}
|
||||
|
||||
auto add_info = [&](AttributeKind *attribute_kind) {
|
||||
attribute_kind->domain = domain;
|
||||
attribute_kind->data_type = meta_data.data_type;
|
||||
};
|
||||
auto modify_info = [&](AttributeKind *attribute_kind) {
|
||||
attribute_kind->domain = bke::attribute_domain_highest_priority(
|
||||
{attribute_kind->domain, domain});
|
||||
attribute_kind->data_type = bke::attribute_data_type_highest_complexity(
|
||||
{attribute_kind->data_type, meta_data.data_type});
|
||||
};
|
||||
r_attributes.add_or_modify(attribute_id, add_info, modify_info);
|
||||
});
|
||||
auto add_info = [&](AttributeKind *attribute_kind) {
|
||||
attribute_kind->domain = domain;
|
||||
attribute_kind->data_type = meta_data.data_type;
|
||||
};
|
||||
auto modify_info = [&](AttributeKind *attribute_kind) {
|
||||
attribute_kind->domain = bke::attribute_domain_highest_priority(
|
||||
{attribute_kind->domain, domain});
|
||||
attribute_kind->data_type = bke::attribute_data_type_highest_complexity(
|
||||
{attribute_kind->data_type, meta_data.data_type});
|
||||
};
|
||||
r_attributes.add_or_modify(attribute_id, add_info, modify_info);
|
||||
});
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
Reference in New Issue
Block a user