X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-scene3d%2Finternal%2Floader%2Fgltf2-asset.cpp;h=bbc092ea0f0dd33fad32ff9e412bb82553798bbe;hb=HEAD;hp=82970454f919cd67de3bc3aaa5a00f99729e3cf1;hpb=f2ee13ccda8c768fddc68f5208b7dcfa54c07242;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-scene3d/internal/loader/gltf2-asset.cpp b/dali-scene3d/internal/loader/gltf2-asset.cpp index 8297045..bbc092e 100644 --- a/dali-scene3d/internal/loader/gltf2-asset.cpp +++ b/dali-scene3d/internal/loader/gltf2-asset.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Samsung Electronics Co., Ltd. +* Copyright (c) 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ * limitations under the License. * */ -#include "dali-scene3d/internal/loader/gltf2-asset.h" + +// EXTERNAL INCLUDES +#include #include #include -#include "dali/public-api/math/matrix.h" -#define ENUM_STRING_MAPPING(t, x) \ - { \ -#x, t::x \ - } +// INTERNAL INCLUDES +#include using namespace Dali; @@ -40,133 +39,151 @@ constexpr uint32_t ACCESSOR_TYPE_ELEMENT_COUNT[]{ 16, static_cast(-1)}; -const std::map ACCESSOR_TYPES{ - ENUM_STRING_MAPPING(AccessorType, SCALAR), - ENUM_STRING_MAPPING(AccessorType, VEC2), - ENUM_STRING_MAPPING(AccessorType, VEC3), - ENUM_STRING_MAPPING(AccessorType, VEC4), - ENUM_STRING_MAPPING(AccessorType, MAT2), - ENUM_STRING_MAPPING(AccessorType, MAT3), - ENUM_STRING_MAPPING(AccessorType, MAT4), -}; - -const std::map ALPHA_MODE_TYPES{ - ENUM_STRING_MAPPING(AlphaMode::Type, OPAQUE), - ENUM_STRING_MAPPING(AlphaMode::Type, MASK), - ENUM_STRING_MAPPING(AlphaMode::Type, BLEND), -}; - -const std::map ATTRIBUTE_TYPES{ - ENUM_STRING_MAPPING(Attribute::Type, POSITION), - ENUM_STRING_MAPPING(Attribute::Type, NORMAL), - ENUM_STRING_MAPPING(Attribute::Type, TANGENT), - ENUM_STRING_MAPPING(Attribute::Type, TEXCOORD_0), - ENUM_STRING_MAPPING(Attribute::Type, TEXCOORD_1), - ENUM_STRING_MAPPING(Attribute::Type, COLOR_0), - ENUM_STRING_MAPPING(Attribute::Type, JOINTS_0), - ENUM_STRING_MAPPING(Attribute::Type, WEIGHTS_0), -}; - -const std::map ANIMATION_SAMPLER_INTERPOLATION{ - ENUM_STRING_MAPPING(Animation::Sampler::Interpolation::Type, STEP), - ENUM_STRING_MAPPING(Animation::Sampler::Interpolation::Type, LINEAR), - ENUM_STRING_MAPPING(Animation::Sampler::Interpolation::Type, CUBICSPLINE), -}; - -const std::map ANIMATION_CHANNEL_TARGET_PATH_TYPES{ - ENUM_STRING_MAPPING(Animation::Channel::Target::Type, TRANSLATION), - ENUM_STRING_MAPPING(Animation::Channel::Target::Type, ROTATION), - ENUM_STRING_MAPPING(Animation::Channel::Target::Type, SCALE), - ENUM_STRING_MAPPING(Animation::Channel::Target::Type, WEIGHTS), -}; +const std::map& GetAccessorTypes() +{ + static const std::map ACCESSOR_TYPES{ + ENUM_STRING_MAPPING(AccessorType, SCALAR), + ENUM_STRING_MAPPING(AccessorType, VEC2), + ENUM_STRING_MAPPING(AccessorType, VEC3), + ENUM_STRING_MAPPING(AccessorType, VEC4), + ENUM_STRING_MAPPING(AccessorType, MAT2), + ENUM_STRING_MAPPING(AccessorType, MAT3), + ENUM_STRING_MAPPING(AccessorType, MAT4), + }; + return ACCESSOR_TYPES; +} -} // namespace +const std::map& GetAlphaModeTypes() +{ + static const std::map ALPHA_MODE_TYPES{ + ENUM_STRING_MAPPING(AlphaMode::Type, OPAQUE), + ENUM_STRING_MAPPING(AlphaMode::Type, MASK), + ENUM_STRING_MAPPING(AlphaMode::Type, BLEND), + }; + return ALPHA_MODE_TYPES; +} -bool Component::IsUnsigned(Type t) +const std::map& GetAnimationSamplerInterpolation() { - return t == UNSIGNED_BYTE || t == UNSIGNED_SHORT || t == UNSIGNED_INT; + static const std::map ANIMATION_SAMPLER_INTERPOLATION{ + ENUM_STRING_MAPPING(Animation::Sampler::Interpolation::Type, STEP), + ENUM_STRING_MAPPING(Animation::Sampler::Interpolation::Type, LINEAR), + ENUM_STRING_MAPPING(Animation::Sampler::Interpolation::Type, CUBICSPLINE), + }; + return ANIMATION_SAMPLER_INTERPOLATION; } -uint32_t Component::Size(Type t) +const std::map& GetAnimationChannelTargetPathTypes() { - switch(t) - { - case BYTE: - case UNSIGNED_BYTE: - return 1; - case SHORT: - case UNSIGNED_SHORT: - return 2; - case UNSIGNED_INT: - case FLOAT: - return 4; - default: - return -1; - } + static const std::map ANIMATION_CHANNEL_TARGET_PATH_TYPES{ + ENUM_STRING_MAPPING(Animation::Channel::Target::Type, TRANSLATION), + ENUM_STRING_MAPPING(Animation::Channel::Target::Type, ROTATION), + ENUM_STRING_MAPPING(Animation::Channel::Target::Type, SCALE), + ENUM_STRING_MAPPING(Animation::Channel::Target::Type, WEIGHTS), + }; + return ANIMATION_CHANNEL_TARGET_PATH_TYPES; } -uint32_t AccessorType::ElementCount(Type t) +} // namespace + +ENUM_TYPE_FROM_STRING(AccessorType, GetAccessorTypes()) +ENUM_TYPE_FROM_STRING(AlphaMode, GetAlphaModeTypes()) +ENUM_TYPE_FROM_STRING(Animation::Sampler::Interpolation, GetAnimationSamplerInterpolation()) +ENUM_TYPE_FROM_STRING(Animation::Channel::Target, GetAnimationChannelTargetPathTypes()) + +const std::map& GetTargetTypes() { - return ACCESSOR_TYPE_ELEMENT_COUNT[t]; + static const std::map TARGET_TYPES{ + ENUM_STRING_MAPPING(Attribute::Type, POSITION), + ENUM_STRING_MAPPING(Attribute::Type, TANGENT), + ENUM_STRING_MAPPING(Attribute::Type, NORMAL), + }; + return TARGET_TYPES; } -AccessorType::Type AccessorType::FromString(const char* s, size_t len) +const std::map& GetAttributeSetTypes() { - auto iFind = ACCESSOR_TYPES.find(std::string_view(s, len)); - if(iFind != ACCESSOR_TYPES.end()) - { - return iFind->second; - } - return AccessorType::INVALID; + static const std::map ATTRIBUTE_SET_TYPES{ + {Attribute::Type::TEXCOORD_N, "TEXCOORD_%u"}, + {Attribute::Type::COLOR_N, "COLOR_%u"}, + {Attribute::Type::JOINTS_N, "JOINTS_%u"}, + {Attribute::Type::WEIGHTS_N, "WEIGHTS_%u"}, + }; + return ATTRIBUTE_SET_TYPES; } -AlphaMode::Type AlphaMode::FromString(const char* s, size_t len) +uint32_t Attribute::HashFromString(const char* token, size_t length) { - auto iFind = ALPHA_MODE_TYPES.find(std::string_view(s, len)); - if(iFind != ALPHA_MODE_TYPES.end()) + auto& table1 = GetTargetTypes(); + auto& table2 = GetAttributeSetTypes(); + + std::string target(token, length); + std::transform(target.begin(), target.end(), target.begin(), ::toupper); + + auto iFind = table1.find(std::string_view(target.c_str(), length)); + if(iFind != table1.end()) { - return iFind->second; + return Attribute::ToHash(iFind->second, false, 0); } - return AlphaMode::INVALID; + + uint32_t hash = Attribute::ToHash(Attribute::INVALID, false, 0); + for(const auto& [key, match] : table2) + { + int setIndex; + if(sscanf(target.c_str(), match, &setIndex) > 0) + { + hash = Attribute::ToHash(key, true, setIndex); + break; + } + } + return hash; } -Attribute::Type Attribute::FromString(const char* s, size_t len) +Attribute::Type Attribute::TargetFromString(const char* token, size_t length) { - auto iFind = ATTRIBUTE_TYPES.find(std::string_view(s, len)); - if(iFind != ATTRIBUTE_TYPES.end()) + std::string target(token, length); + std::transform(target.begin(), target.end(), target.begin(), ::toupper); + + auto iFind = GetTargetTypes().find(std::string_view(target.c_str(), length)); + if(iFind != GetTargetTypes().end()) { return iFind->second; } return Attribute::INVALID; } -Animation::Sampler::Interpolation::Type Animation::Sampler::Interpolation::FromString(const char* s, size_t len) +bool Component::IsUnsigned(Type t) +{ + return t == UNSIGNED_BYTE || t == UNSIGNED_SHORT || t == UNSIGNED_INT; +} + +uint32_t Component::Size(Type t) { - auto iFind = ANIMATION_SAMPLER_INTERPOLATION.find(std::string_view(s, len)); - if(iFind != ANIMATION_SAMPLER_INTERPOLATION.end()) + switch(t) { - return iFind->second; + case BYTE: + case UNSIGNED_BYTE: + return 1; + case SHORT: + case UNSIGNED_SHORT: + return 2; + case UNSIGNED_INT: + case FLOAT: + return 4; + default: + return -1; } - return Animation::Sampler::Interpolation::Type::INVALID; } -uint32_t ComponentTypedBufferViewClient::GetBytesPerComponent() const +uint32_t AccessorType::ElementCount(Type t) { - return Component::Size(mComponentType); + return ACCESSOR_TYPE_ELEMENT_COUNT[t]; } -Animation::Channel::Target::Type Animation::Channel::Target::FromString(const char* s, size_t len) +uint32_t ComponentTypedBufferViewClient::GetBytesPerComponent() const { - std::string target(s, len); - std::transform(target.begin(), target.end(), target.begin(), ::toupper); - - auto iFind = ANIMATION_CHANNEL_TARGET_PATH_TYPES.find(std::string_view(target.c_str(), len)); - if(iFind != ANIMATION_CHANNEL_TARGET_PATH_TYPES.end()) - { - return iFind->second; - } - return Animation::Channel::Target::INVALID; -}; + return Component::Size(mComponentType); +} void Node::SetMatrix(const Matrix& m) {