diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc index 8974190d0e3..3ac7f67067e 100644 --- a/source/blender/blenkernel/intern/attribute_access.cc +++ b/source/blender/blenkernel/intern/attribute_access.cc @@ -38,7 +38,9 @@ static CLG_LogRef LOG = {"bke.attribute_access"}; +using blender::Color4f; using blender::float3; +using blender::MutableSpan; using blender::Set; using blender::StringRef; using blender::StringRefNull; @@ -1956,6 +1958,31 @@ void OutputAttributePtr::save() StringRefNull name = attribute->final_name; const blender::fn::CPPType &cpp_type = attribute->cpp_type(); + /* Allow implicit conversions for Color4f to float3, so try this first. */ + if (!attribute->component.attribute_try_create( + name, attribute_->domain(), attribute_->custom_data_type())) { + ReadAttributePtr dst_attribute = attribute->component.attribute_try_get_for_read(name); + if (dst_attribute && dst_attribute->custom_data_type() != attribute_->custom_data_type()) { + /* Only allow Color4f to float3 currently. */ + if ((attribute_->custom_data_type() == CD_PROP_COLOR) && + (dst_attribute->custom_data_type() == CD_PROP_FLOAT3)) { + OutputAttributePtr new_out = attribute->component.attribute_try_get_for_output( + name, attribute_->domain(), dst_attribute->custom_data_type()); + if (new_out) { + MutableSpan span = new_out->get_span().typed(); + for (const int i : span.index_range()) { + Color4f coldata; + attribute_->get(i, coldata); + span[i] = {coldata.r, coldata.g, coldata.b}; + } + new_out.apply_span_and_save(); + attribute_.reset(); + return; + } + } + } + } + /* Delete an existing attribute with the same name if necessary. */ attribute->component.attribute_try_delete(name);