Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/attribute_access.cc
| Show First 20 Lines • Show All 386 Lines • ▼ Show 20 Lines | switch (type) { | ||||
| 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<Color4f>(); | return &CPPType::get<Color4f>(); | ||||
| case CD_PROP_BOOL: | |||||
| return &CPPType::get<bool>(); | |||||
| 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::fn::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>()) { | ||||
| return CD_PROP_FLOAT3; | return CD_PROP_FLOAT3; | ||||
| } | } | ||||
| if (type.is<int>()) { | if (type.is<int>()) { | ||||
| return CD_PROP_INT32; | return CD_PROP_INT32; | ||||
| } | } | ||||
| if (type.is<Color4f>()) { | if (type.is<Color4f>()) { | ||||
| return CD_PROP_COLOR; | return CD_PROP_COLOR; | ||||
| } | } | ||||
| if (type.is<bool>()) { | |||||
| return CD_PROP_BOOL; | |||||
| } | |||||
| return static_cast<CustomDataType>(-1); | return static_cast<CustomDataType>(-1); | ||||
| } | } | ||||
| } // namespace blender::bke | } // namespace blender::bke | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Utilities for Accessing Attributes | /** \name Utilities for Accessing Attributes | ||||
| * \{ */ | * \{ */ | ||||
| Show All 18 Lines | if (layer.name != nullptr && layer.name == attribute_name) { | ||||
| return std::make_unique<ArrayReadAttribute<float3>>( | return std::make_unique<ArrayReadAttribute<float3>>( | ||||
| domain, Span(static_cast<float3 *>(layer.data), size)); | domain, Span(static_cast<float3 *>(layer.data), size)); | ||||
| case CD_PROP_INT32: | case CD_PROP_INT32: | ||||
| return std::make_unique<ArrayReadAttribute<int>>( | return std::make_unique<ArrayReadAttribute<int>>( | ||||
| domain, Span(static_cast<int *>(layer.data), size)); | domain, Span(static_cast<int *>(layer.data), size)); | ||||
| case CD_PROP_COLOR: | case CD_PROP_COLOR: | ||||
| return std::make_unique<ArrayReadAttribute<Color4f>>( | return std::make_unique<ArrayReadAttribute<Color4f>>( | ||||
| domain, Span(static_cast<Color4f *>(layer.data), size)); | domain, Span(static_cast<Color4f *>(layer.data), size)); | ||||
| case CD_PROP_BOOL: | |||||
| return std::make_unique<ArrayReadAttribute<bool>>( | |||||
| domain, Span(static_cast<bool *>(layer.data), size)); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| static WriteAttributePtr write_attribute_from_custom_data( | static WriteAttributePtr write_attribute_from_custom_data( | ||||
| CustomData &custom_data, | CustomData &custom_data, | ||||
| Show All 25 Lines | if (layer.name != nullptr && layer.name == attribute_name) { | ||||
| return std::make_unique<ArrayWriteAttribute<float3>>( | return std::make_unique<ArrayWriteAttribute<float3>>( | ||||
| domain, MutableSpan(static_cast<float3 *>(layer.data), size)); | domain, MutableSpan(static_cast<float3 *>(layer.data), size)); | ||||
| case CD_PROP_INT32: | case CD_PROP_INT32: | ||||
| return std::make_unique<ArrayWriteAttribute<int>>( | return std::make_unique<ArrayWriteAttribute<int>>( | ||||
| domain, MutableSpan(static_cast<int *>(layer.data), size)); | domain, MutableSpan(static_cast<int *>(layer.data), size)); | ||||
| case CD_PROP_COLOR: | case CD_PROP_COLOR: | ||||
| return std::make_unique<ArrayWriteAttribute<Color4f>>( | return std::make_unique<ArrayWriteAttribute<Color4f>>( | ||||
| domain, MutableSpan(static_cast<Color4f *>(layer.data), size)); | domain, MutableSpan(static_cast<Color4f *>(layer.data), size)); | ||||
| case CD_PROP_BOOL: | |||||
| return std::make_unique<ArrayWriteAttribute<bool>>( | |||||
| domain, MutableSpan(static_cast<bool *>(layer.data), size)); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| /* Returns true when the layer was found and is deleted. */ | /* Returns true when the layer was found and is deleted. */ | ||||
| static bool delete_named_custom_data_layer(CustomData &custom_data, | static bool delete_named_custom_data_layer(CustomData &custom_data, | ||||
| ▲ Show 20 Lines • Show All 245 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| return domain == ATTR_DOMAIN_POINT; | return domain == ATTR_DOMAIN_POINT; | ||||
| } | } | ||||
| bool PointCloudComponent::attribute_domain_with_type_supported( | bool PointCloudComponent::attribute_domain_with_type_supported( | ||||
| const AttributeDomain domain, const CustomDataType data_type) const | const AttributeDomain domain, const CustomDataType data_type) const | ||||
| { | { | ||||
| return domain == ATTR_DOMAIN_POINT && ELEM(data_type, | return domain == ATTR_DOMAIN_POINT && ELEM(data_type, | ||||
| CD_PROP_BOOL, | |||||
| CD_PROP_FLOAT, | CD_PROP_FLOAT, | ||||
| CD_PROP_FLOAT2, | CD_PROP_FLOAT2, | ||||
| CD_PROP_FLOAT3, | CD_PROP_FLOAT3, | ||||
| CD_PROP_INT32, | CD_PROP_INT32, | ||||
| CD_PROP_COLOR); | CD_PROP_COLOR); | ||||
| } | } | ||||
| int PointCloudComponent::attribute_domain_size(const AttributeDomain domain) const | int PointCloudComponent::attribute_domain_size(const AttributeDomain domain) const | ||||
| ▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| bool MeshComponent::attribute_domain_with_type_supported(const AttributeDomain domain, | bool MeshComponent::attribute_domain_with_type_supported(const AttributeDomain domain, | ||||
| const CustomDataType data_type) const | const CustomDataType data_type) const | ||||
| { | { | ||||
| if (!this->attribute_domain_supported(domain)) { | if (!this->attribute_domain_supported(domain)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return ELEM( | return ELEM(data_type, | ||||
| data_type, CD_PROP_FLOAT, CD_PROP_FLOAT2, CD_PROP_FLOAT3, CD_PROP_INT32, CD_PROP_COLOR); | CD_PROP_BOOL, | ||||
| CD_PROP_FLOAT, | |||||
| CD_PROP_FLOAT2, | |||||
| CD_PROP_FLOAT3, | |||||
| CD_PROP_INT32, | |||||
| CD_PROP_COLOR); | |||||
| } | } | ||||
| int MeshComponent::attribute_domain_size(const AttributeDomain domain) const | int MeshComponent::attribute_domain_size(const AttributeDomain domain) const | ||||
| { | { | ||||
| BLI_assert(this->attribute_domain_supported(domain)); | BLI_assert(this->attribute_domain_supported(domain)); | ||||
| if (mesh_ == nullptr) { | if (mesh_ == nullptr) { | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 236 Lines • Show Last 20 Lines | |||||