return ALPHA_MODE_TYPES;
}
-const std::map<std::string_view, Attribute::Type>& GetAttributeTypes()
-{
- static const std::map<std::string_view, Attribute::Type> 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),
- };
- return ATTRIBUTE_TYPES;
-}
-
const std::map<std::string_view, Animation::Sampler::Interpolation::Type>& GetAnimationSamplerInterpolation()
{
static const std::map<std::string_view, Animation::Sampler::Interpolation::Type> ANIMATION_SAMPLER_INTERPOLATION{
ENUM_TYPE_FROM_STRING(AccessorType, GetAccessorTypes())
ENUM_TYPE_FROM_STRING(AlphaMode, GetAlphaModeTypes())
-ENUM_TYPE_FROM_STRING(Attribute, GetAttributeTypes())
ENUM_TYPE_FROM_STRING(Animation::Sampler::Interpolation, GetAnimationSamplerInterpolation())
ENUM_TYPE_FROM_STRING(Animation::Channel::Target, GetAnimationChannelTargetPathTypes())
+const std::map<std::string_view, Attribute::Type>& GetTargetTypes()
+{
+ static const std::map<std::string_view, Attribute::Type> TARGET_TYPES{
+ ENUM_STRING_MAPPING(Attribute::Type, POSITION),
+ ENUM_STRING_MAPPING(Attribute::Type, TANGENT),
+ ENUM_STRING_MAPPING(Attribute::Type, NORMAL),
+ };
+ return TARGET_TYPES;
+}
+
+const std::map<Attribute::Type, const char*>& GetAttributeSetTypes()
+{
+ static const std::map<Attribute::Type, const char*> 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;
+}
+
+uint32_t Attribute::HashFromString(const char* token, size_t length)
+{
+ 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 Attribute::ToHash(iFind->second, false, 0);
+ }
+
+ 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::TargetFromString(const char* token, size_t length)
+{
+ 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;
+}
+
bool Component::IsUnsigned(Type t)
{
return t == UNSIGNED_BYTE || t == UNSIGNED_SHORT || t == UNSIGNED_INT;