Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/attribute_access.cc
| Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | else if (attribute_id.is_anonymous()) { | ||||
| stream << "<" << BKE_anonymous_attribute_id_debug_name(&anonymous_id) << ">"; | stream << "<" << BKE_anonymous_attribute_id_debug_name(&anonymous_id) << ">"; | ||||
| } | } | ||||
| else { | else { | ||||
| stream << "<none>"; | stream << "<none>"; | ||||
| } | } | ||||
| return stream; | return stream; | ||||
| } | } | ||||
| const blender::fn::CPPType *custom_data_type_to_cpp_type(const CustomDataType type) | const blender::CPPType *custom_data_type_to_cpp_type(const CustomDataType type) | ||||
| { | { | ||||
| switch (type) { | switch (type) { | ||||
| case CD_PROP_FLOAT: | case CD_PROP_FLOAT: | ||||
| return &CPPType::get<float>(); | return &CPPType::get<float>(); | ||||
| case CD_PROP_FLOAT2: | case CD_PROP_FLOAT2: | ||||
| return &CPPType::get<float2>(); | return &CPPType::get<float2>(); | ||||
| case CD_PROP_FLOAT3: | case CD_PROP_FLOAT3: | ||||
| return &CPPType::get<float3>(); | return &CPPType::get<float3>(); | ||||
| case CD_PROP_INT32: | case CD_PROP_INT32: | ||||
| return &CPPType::get<int>(); | return &CPPType::get<int>(); | ||||
| case CD_PROP_COLOR: | case CD_PROP_COLOR: | ||||
| return &CPPType::get<ColorGeometry4f>(); | return &CPPType::get<ColorGeometry4f>(); | ||||
| case CD_PROP_BOOL: | case CD_PROP_BOOL: | ||||
| return &CPPType::get<bool>(); | return &CPPType::get<bool>(); | ||||
| case CD_PROP_INT8: | case CD_PROP_INT8: | ||||
| return &CPPType::get<int8_t>(); | return &CPPType::get<int8_t>(); | ||||
| default: | default: | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| CustomDataType cpp_type_to_custom_data_type(const blender::fn::CPPType &type) | CustomDataType cpp_type_to_custom_data_type(const blender::CPPType &type) | ||||
| { | { | ||||
| if (type.is<float>()) { | if (type.is<float>()) { | ||||
| return CD_PROP_FLOAT; | return CD_PROP_FLOAT; | ||||
| } | } | ||||
| if (type.is<float2>()) { | if (type.is<float2>()) { | ||||
| return CD_PROP_FLOAT2; | return CD_PROP_FLOAT2; | ||||
| } | } | ||||
| if (type.is<float3>()) { | if (type.is<float3>()) { | ||||
| ▲ Show 20 Lines • Show All 1,008 Lines • ▼ Show 20 Lines | this->attribute_foreach( | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| }); | }); | ||||
| return result; | return result; | ||||
| } | } | ||||
| static blender::fn::GVArray try_adapt_data_type(blender::fn::GVArray varray, | static blender::fn::GVArray try_adapt_data_type(blender::fn::GVArray varray, | ||||
| const blender::fn::CPPType &to_type) | const blender::CPPType &to_type) | ||||
| { | { | ||||
| const blender::bke::DataTypeConversions &conversions = | const blender::bke::DataTypeConversions &conversions = | ||||
| blender::bke::get_implicit_type_conversions(); | blender::bke::get_implicit_type_conversions(); | ||||
| return conversions.try_convert(std::move(varray), to_type); | return conversions.try_convert(std::move(varray), to_type); | ||||
| } | } | ||||
| blender::fn::GVArray GeometryComponent::attribute_try_get_for_read( | blender::fn::GVArray GeometryComponent::attribute_try_get_for_read( | ||||
| const AttributeIDRef &attribute_id, | const AttributeIDRef &attribute_id, | ||||
| const AttributeDomain domain, | const AttributeDomain domain, | ||||
| const CustomDataType data_type) const | const CustomDataType data_type) const | ||||
| { | { | ||||
| blender::bke::ReadAttributeLookup attribute = this->attribute_try_get_for_read(attribute_id); | blender::bke::ReadAttributeLookup attribute = this->attribute_try_get_for_read(attribute_id); | ||||
| if (!attribute) { | if (!attribute) { | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| blender::fn::GVArray varray = std::move(attribute.varray); | blender::fn::GVArray varray = std::move(attribute.varray); | ||||
| if (!ELEM(domain, ATTR_DOMAIN_AUTO, attribute.domain)) { | if (!ELEM(domain, ATTR_DOMAIN_AUTO, attribute.domain)) { | ||||
| varray = this->attribute_try_adapt_domain(std::move(varray), attribute.domain, domain); | varray = this->attribute_try_adapt_domain(std::move(varray), attribute.domain, domain); | ||||
| if (!varray) { | if (!varray) { | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| } | } | ||||
| const blender::fn::CPPType *cpp_type = blender::bke::custom_data_type_to_cpp_type(data_type); | const blender::CPPType *cpp_type = blender::bke::custom_data_type_to_cpp_type(data_type); | ||||
| BLI_assert(cpp_type != nullptr); | BLI_assert(cpp_type != nullptr); | ||||
| if (varray.type() != *cpp_type) { | if (varray.type() != *cpp_type) { | ||||
| varray = try_adapt_data_type(std::move(varray), *cpp_type); | varray = try_adapt_data_type(std::move(varray), *cpp_type); | ||||
| if (!varray) { | if (!varray) { | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| } | } | ||||
| Show All 21 Lines | |||||
| blender::bke::ReadAttributeLookup GeometryComponent::attribute_try_get_for_read( | blender::bke::ReadAttributeLookup GeometryComponent::attribute_try_get_for_read( | ||||
| const AttributeIDRef &attribute_id, const CustomDataType data_type) const | const AttributeIDRef &attribute_id, const CustomDataType data_type) const | ||||
| { | { | ||||
| blender::bke::ReadAttributeLookup attribute = this->attribute_try_get_for_read(attribute_id); | blender::bke::ReadAttributeLookup attribute = this->attribute_try_get_for_read(attribute_id); | ||||
| if (!attribute) { | if (!attribute) { | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| const blender::fn::CPPType *type = blender::bke::custom_data_type_to_cpp_type(data_type); | const blender::CPPType *type = blender::bke::custom_data_type_to_cpp_type(data_type); | ||||
| BLI_assert(type != nullptr); | BLI_assert(type != nullptr); | ||||
| if (attribute.varray.type() == *type) { | if (attribute.varray.type() == *type) { | ||||
| return attribute; | return attribute; | ||||
| } | } | ||||
| const blender::bke::DataTypeConversions &conversions = | const blender::bke::DataTypeConversions &conversions = | ||||
| blender::bke::get_implicit_type_conversions(); | blender::bke::get_implicit_type_conversions(); | ||||
| return {conversions.try_convert(std::move(attribute.varray), *type), attribute.domain}; | return {conversions.try_convert(std::move(attribute.varray), *type), attribute.domain}; | ||||
| } | } | ||||
| blender::fn::GVArray GeometryComponent::attribute_get_for_read(const AttributeIDRef &attribute_id, | blender::fn::GVArray GeometryComponent::attribute_get_for_read(const AttributeIDRef &attribute_id, | ||||
| const AttributeDomain domain, | const AttributeDomain domain, | ||||
| const CustomDataType data_type, | const CustomDataType data_type, | ||||
| const void *default_value) const | const void *default_value) const | ||||
| { | { | ||||
| blender::fn::GVArray varray = this->attribute_try_get_for_read(attribute_id, domain, data_type); | blender::fn::GVArray varray = this->attribute_try_get_for_read(attribute_id, domain, data_type); | ||||
| if (varray) { | if (varray) { | ||||
| return varray; | return varray; | ||||
| } | } | ||||
| const blender::fn::CPPType *type = blender::bke::custom_data_type_to_cpp_type(data_type); | const blender::CPPType *type = blender::bke::custom_data_type_to_cpp_type(data_type); | ||||
| if (default_value == nullptr) { | if (default_value == nullptr) { | ||||
| default_value = type->default_value(); | default_value = type->default_value(); | ||||
| } | } | ||||
| const int domain_size = this->attribute_domain_size(domain); | const int domain_size = this->attribute_domain_size(domain); | ||||
| return blender::fn::GVArray::ForSingle(*type, domain_size, default_value); | return blender::fn::GVArray::ForSingle(*type, domain_size, default_value); | ||||
| } | } | ||||
| class GVMutableAttribute_For_OutputAttribute : public blender::fn::GVArrayImpl_For_GSpan { | class GVMutableAttribute_For_OutputAttribute : public blender::fn::GVArrayImpl_For_GSpan { | ||||
| ▲ Show 20 Lines • Show All 324 Lines • Show Last 20 Lines | |||||