X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-scene-loader%2Finternal%2Fgltf2-asset.h;h=e074c28d3f517d7c06972c4dad34c938b890d641;hb=f8242e3b1f84d21f607d1a7b911f77bff0fd7bd5;hp=79a72db20da551b8aa7e8d170509ccb645b5c265;hpb=02557f62f8d171115d885c87c138faec2a3cb923;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-scene-loader/internal/gltf2-asset.h b/dali-scene-loader/internal/gltf2-asset.h index 79a72db..e074c28 100644 --- a/dali-scene-loader/internal/gltf2-asset.h +++ b/dali-scene-loader/internal/gltf2-asset.h @@ -1,7 +1,7 @@ #ifndef DALI_SCENE_LOADER_GLTF2_ASSET_H_ #define DALI_SCENE_LOADER_GLTF2_ASSET_H_ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -18,23 +18,22 @@ */ // INTERNAL INCLUDES -#include "dali-scene-loader/public-api/index.h" #include "dali-scene-loader/internal/json-reader.h" +#include "dali-scene-loader/public-api/index.h" // EXTERNAL INCLUDES -#include "dali/public-api/math/vector4.h" -#include "dali/public-api/math/quaternion.h" -#include "dali/public-api/common/vector-wrapper.h" -#include "dali/devel-api/common/map-wrapper.h" #include #include +#include "dali/devel-api/common/map-wrapper.h" +#include "dali/public-api/common/vector-wrapper.h" +#include "dali/public-api/math/quaternion.h" +#include "dali/public-api/math/vector4.h" namespace gltf2 { - using Index = Dali::SceneLoader::Index; -template +template class Ref { public: @@ -42,14 +41,18 @@ public: Ref(std::vector& v, Index i) : mVector(&v), mIndex(i) - {} + { + } /** * @return The index of the object into the vector. * @note It is client code responsibility to ensure that the vector is unambiguous. It should be in * a glTF document, since there's one vector for each type. */ - Index GetIndex() const { return mIndex; } + Index GetIndex() const + { + return mIndex; + } /** * @brief There may be scenarios in which the object, whose vector we're populating, changes, e.g. @@ -60,9 +63,18 @@ public: mVector = &v; } - operator bool() const { return mVector != nullptr; } - T* operator->() const { return &(*mVector)[mIndex]; } - T& operator*() const { return (*mVector)[mIndex]; } + operator bool() const + { + return mVector != nullptr; + } + T* operator->() const + { + return &(*mVector)[mIndex]; + } + T& operator*() const + { + return (*mVector)[mIndex]; + } bool operator==(const Ref& other) const { @@ -76,11 +88,12 @@ public: private: std::vector* mVector = nullptr; - Index mIndex = Dali::SceneLoader::INVALID_INDEX; + Index mIndex = Dali::SceneLoader::INVALID_INDEX; }; struct Asset { + std::string_view mGenerator; std::string_view mVersion; }; @@ -88,16 +101,16 @@ struct Component { enum Type { - BYTE = 5120, - UNSIGNED_BYTE = 5121, - SHORT = 5122, + BYTE = 5120, + UNSIGNED_BYTE = 5121, + SHORT = 5122, UNSIGNED_SHORT = 5123, - UNSIGNED_INT = 5125, - FLOAT = 5126, - INVALID = -1 + UNSIGNED_INT = 5125, + FLOAT = 5126, + INVALID = -1 }; - static bool IsUnsigned(Type t); + static bool IsUnsigned(Type t); static uint32_t Size(Type t); Component() = delete; @@ -161,7 +174,7 @@ struct Attribute struct Buffer { - uint32_t mByteLength; + uint32_t mByteLength; std::string_view mUri; //TODO: extensions //TODO: extras @@ -174,7 +187,7 @@ struct BufferView enum Type { NONE, - ARRAY_BUFFER = 34962, + ARRAY_BUFFER = 34962, ELEMENT_ARRAY_BUFFER = 34963 }; @@ -182,10 +195,10 @@ struct BufferView }; Ref mBuffer; - uint32_t mByteOffset = 0; - uint32_t mByteLength; - uint32_t mByteStride = 0; // if 0 after reading, it needs to be calculated - uint32_t mTarget; + uint32_t mByteOffset = 0; + uint32_t mByteLength; + uint32_t mByteStride = 0; // if 0 after reading, it needs to be calculated + uint32_t mTarget; //TODO: extensions //TODO: extras }; @@ -193,7 +206,7 @@ struct BufferView struct BufferViewClient { Ref mBufferView; - uint32_t mByteOffset = 0; + uint32_t mByteOffset = 0; }; struct ComponentTypedBufferViewClient : BufferViewClient @@ -215,18 +228,18 @@ struct Accessor : ComponentTypedBufferViewClient, Named { struct Sparse { - uint32_t mCount; + uint32_t mCount; ComponentTypedBufferViewClient mIndices; - BufferViewClient mValues; + BufferViewClient mValues; //TODO: extensions //TODO: extras }; - uint32_t mCount; - bool mNormalized = false; - AccessorType::Type mType = AccessorType::INVALID; - std::vector mMin; - std::vector mMax; + uint32_t mCount; + bool mNormalized = false; + AccessorType::Type mType = AccessorType::INVALID; + std::vector mMin; + std::vector mMax; std::unique_ptr mSparse; //TODO: extensions //TODO: extras @@ -247,11 +260,11 @@ struct Accessor : ComponentTypedBufferViewClient, Named } }; -struct Image: Named +struct Image : Named { std::string_view mUri; std::string_view mMimeType; - Ref mBufferView; + Ref mBufferView; //TODO: extensions //TODO: extras }; @@ -260,12 +273,12 @@ struct Filter { enum Type { - NEAREST = 9728, - LINEAR = 9729, + NEAREST = 9728, + LINEAR = 9729, NEAREST_MIPMAP_NEAREST = 9984, - NEAREST_MIPMAP_LINEAR = 9985, - LINEAR_MIPMAP_NEAREST = 9986, - LINEAR_MIPMAP_LINEAR = 9987, + NEAREST_MIPMAP_LINEAR = 9985, + LINEAR_MIPMAP_NEAREST = 9986, + LINEAR_MIPMAP_LINEAR = 9987, }; Filter() = delete; @@ -275,8 +288,8 @@ struct Wrap { enum Type { - REPEAT = 10497, - CLAMP_TO_EDGE = 33071, + REPEAT = 10497, + CLAMP_TO_EDGE = 33071, MIRRORED_REPEAT = 33648, }; @@ -287,23 +300,24 @@ struct Sampler { Filter::Type mMinFilter = Filter::LINEAR; Filter::Type mMagFilter = Filter::LINEAR; - Wrap::Type mWrapS = Wrap::CLAMP_TO_EDGE; - Wrap::Type mWrapT = Wrap::CLAMP_TO_EDGE; + Wrap::Type mWrapS = Wrap::CLAMP_TO_EDGE; + Wrap::Type mWrapT = Wrap::CLAMP_TO_EDGE; //TODO: extensions //TODO: extras }; struct Texture { - Ref mSource; + Ref mSource; Ref mSampler; }; struct TextureInfo { Ref mTexture; - uint32_t mTexCoord = 0; - float mScale = 1.f; + uint32_t mTexCoord = 0; + float mScale = 1.f; + float mStrength = 1.f; operator bool() const { @@ -311,32 +325,32 @@ struct TextureInfo } }; -struct Material: Named +struct Material : Named { - struct Pbr//MetallicRoughness + struct Pbr //MetallicRoughness { Dali::Vector4 mBaseColorFactor = Dali::Vector4::ONE; - TextureInfo mBaseColorTexture; - float mMetallicFactor = 1.f; - float mRoughnessFactor = 1.f; - TextureInfo mMetallicRoughnessTexture; + TextureInfo mBaseColorTexture; + float mMetallicFactor = 1.f; + float mRoughnessFactor = 1.f; + TextureInfo mMetallicRoughnessTexture; //TODO: extensions //TODO: extras }; - Pbr mPbrMetallicRoughness; - TextureInfo mNormalTexture; - TextureInfo mOcclusionTexture; - TextureInfo mEmissiveTexture; - Dali::Vector3 mEmissiveFactor; - AlphaMode::Type mAlphaMode = AlphaMode::OPAQUE; - float mAlphaCutoff = .5f; - bool mDoubleSided = false; + Pbr mPbrMetallicRoughness; + TextureInfo mNormalTexture; + TextureInfo mOcclusionTexture; + TextureInfo mEmissiveTexture; + Dali::Vector3 mEmissiveFactor; + AlphaMode::Type mAlphaMode = AlphaMode::OPAQUE; + float mAlphaCutoff = .5f; + bool mDoubleSided = false; //TODO: extensions //TODO: extras }; -struct Mesh: Named +struct Mesh : Named { struct Primitive { @@ -352,11 +366,11 @@ struct Mesh: Named INVALID }; - std::map> mAttributes; + std::map> mAttributes; std::vector>> mTargets; - Ref mIndices; - Ref mMaterial; - Mode mMode = TRIANGLES; + Ref mIndices; + Ref mMaterial; + Mode mMode = TRIANGLES; //TODO: [morph] targets //TODO: extras @@ -364,7 +378,7 @@ struct Mesh: Named }; std::vector mPrimitives; - std::vector mWeights; + std::vector mWeights; //TODO: extras //TODO: extensions }; @@ -373,14 +387,14 @@ struct Node; struct Skin : Named { - Ref mInverseBindMatrices; - Ref mSkeleton; + Ref mInverseBindMatrices; + Ref mSkeleton; std::vector> mJoints; //TODO: extras //TODO: extensions }; -struct Camera: Named +struct Camera : Named { struct Perspective { @@ -403,21 +417,21 @@ struct Camera: Named }; std::string_view mType; - Perspective mPerspective; - Orthographic mOrthographic; + Perspective mPerspective; + Orthographic mOrthographic; //TODO: extras //TODO: extensions }; -struct Node: Named +struct Node : Named { - Dali::Vector3 mTranslation = Dali::Vector3::ZERO; - Dali::Quaternion mRotation = Dali::Quaternion::IDENTITY; - Dali::Vector3 mScale = Dali::Vector3::ONE; + Dali::Vector3 mTranslation = Dali::Vector3::ZERO; + Dali::Quaternion mRotation = Dali::Quaternion::IDENTITY; + Dali::Vector3 mScale = Dali::Vector3::ONE; - Ref mCamera; + Ref mCamera; std::vector> mChildren; - Ref mMesh; + Ref mMesh; Ref mSkin; //TODO: [morph] weights @@ -443,8 +457,8 @@ struct Animation : Named static Type FromString(const char* s, size_t len); }; - Ref mInput; - Ref mOutput; + Ref mInput; + Ref mOutput; Interpolation::Type mInterpolation; //TODO: extras @@ -467,11 +481,11 @@ struct Animation : Named static Type FromString(const char* s, size_t len); Ref mNode; - Type mPath; + Type mPath; }; Ref mSampler; - Target mTarget; + Target mTarget; //TODO: extras //TODO: extensions }; @@ -480,7 +494,7 @@ struct Animation : Named std::vector mChannels; }; -struct Scene: Named +struct Scene : Named { std::vector> mNodes; }; @@ -489,29 +503,29 @@ struct Document { Asset mAsset; - std::vector mBuffers; + std::vector mBuffers; std::vector mBufferViews; - std::vector mAccessors; + std::vector mAccessors; - std::vector mImages; - std::vector mSamplers; - std::vector mTextures; + std::vector mImages; + std::vector mSamplers; + std::vector mTextures; std::vector mMaterials; std::vector mMeshes; std::vector mSkins; std::vector mCameras; - std::vector mNodes; + std::vector mNodes; std::vector mAnimations; std::vector mScenes; - Ref mScene; + Ref mScene; - Document() = default; + Document() = default; Document(const Document&) = delete; - Document(Document&&) = default; + Document(Document&&) = default; Document& operator=(const Document&) = delete; Document& operator=(Document&&) = default; @@ -521,12 +535,12 @@ struct Document * @brief Provides a json::Property::ReadFn for interpreting unsigned integers * as a Ref into a std::vector data member of a type T. */ -template +template struct RefReader { static T* sObject; - template T::* V> + template T::*V> static Ref Read(const json_value_s& j) { uint32_t index = json::Read::Number(j); @@ -534,13 +548,13 @@ struct RefReader } }; -template +template T* RefReader::sObject = nullptr; /** * @brief Convenience method to set the object for RefReader. */ -template +template void SetRefReaderObject(T& object) { RefReader::sObject = &object; @@ -551,7 +565,7 @@ void SetRefReaderObject(T& object) * @note The enum must: 1, be called Type, nested to T, 2, provide a FromString static method taking a const char* * (string data) and a size_t (string length) and returning T::Type. */ -template // T must have a nested enum called Type and a static Type FromString(const char*) method. +template // T must have a nested enum called Type and a static Type FromString(const char*) method. typename T::Type ReadStringEnum(const json_value_s& j) { auto str = json::Read::StringView(j); @@ -564,12 +578,11 @@ typename T::Type ReadStringEnum(const json_value_s& j) * @note T must provide an AsFloat() member method returning the non-const array of its * float components. */ -template -inline -T ReadDaliVector(const json_value_s& j) +template +inline T ReadDaliVector(const json_value_s& j) { std::vector floats = json::Read::Array>(j); - T result; + T result; std::copy(floats.begin(), std::min(floats.end(), floats.begin() + sizeof(T) / sizeof(float)), result.AsFloat()); return result; } @@ -580,6 +593,6 @@ T ReadDaliVector(const json_value_s& j) */ Dali::Quaternion ReadQuaternion(const json_value_s& j); -} +} // namespace gltf2 #endif //DALI_SCENE_LOADER_GLTF2_ASSET_H_