Updated all header files to new format
[platform/core/uifw/dali-toolkit.git] / dali-scene-loader / internal / gltf2-asset.h
index 79a72db..1ec67e2 100644 (file)
@@ -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) 2021 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.
  */
 
 // 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 <cstdint>
 #include <memory>
+#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 <typename T>
+template<typename T>
 class Ref
 {
 public:
@@ -42,14 +41,18 @@ public:
   Ref(std::vector<T>& 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<T>& other) const
   {
@@ -76,7 +88,7 @@ public:
 
 private:
   std::vector<T>* mVector = nullptr;
-  Index mIndex = Dali::SceneLoader::INVALID_INDEX;
+  Index           mIndex  = Dali::SceneLoader::INVALID_INDEX;
 };
 
 struct Asset
@@ -88,16 +100,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 +173,7 @@ struct Attribute
 
 struct Buffer
 {
-  uint32_t mByteLength;
+  uint32_t         mByteLength;
   std::string_view mUri;
   //TODO: extensions
   //TODO: extras
@@ -174,7 +186,7 @@ struct BufferView
     enum Type
     {
       NONE,
-      ARRAY_BUFFER = 34962,
+      ARRAY_BUFFER         = 34962,
       ELEMENT_ARRAY_BUFFER = 34963
     };
 
@@ -182,10 +194,10 @@ struct BufferView
   };
 
   Ref<Buffer> 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 +205,7 @@ struct BufferView
 struct BufferViewClient
 {
   Ref<BufferView> mBufferView;
-  uint32_t mByteOffset = 0;
+  uint32_t        mByteOffset = 0;
 };
 
 struct ComponentTypedBufferViewClient : BufferViewClient
@@ -215,18 +227,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<float> mMin;
-  std::vector<float> mMax;
+  uint32_t                mCount;
+  bool                    mNormalized = false;
+  AccessorType::Type      mType       = AccessorType::INVALID;
+  std::vector<float>      mMin;
+  std::vector<float>      mMax;
   std::unique_ptr<Sparse> mSparse;
   //TODO: extensions
   //TODO: extras
@@ -247,11 +259,11 @@ struct Accessor : ComponentTypedBufferViewClient, Named
   }
 };
 
-struct Image: Named
+struct Image : Named
 {
   std::string_view mUri;
   std::string_view mMimeType;
-  Ref<BufferView> mBufferView;
+  Ref<BufferView>  mBufferView;
   //TODO: extensions
   //TODO: extras
 };
@@ -260,12 +272,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 +287,8 @@ struct Wrap
 {
   enum Type
   {
-    REPEAT = 10497,
-    CLAMP_TO_EDGE = 33071,
+    REPEAT          = 10497,
+    CLAMP_TO_EDGE   = 33071,
     MIRRORED_REPEAT = 33648,
   };
 
@@ -287,23 +299,23 @@ 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<Image> mSource;
+  Ref<Image>   mSource;
   Ref<Sampler> mSampler;
 };
 
 struct TextureInfo
 {
   Ref<gltf2::Texture> mTexture;
-  uint32_t mTexCoord = 0;
-  float mScale = 1.f;
+  uint32_t            mTexCoord = 0;
+  float               mScale    = 1.f;
 
   operator bool() const
   {
@@ -311,32 +323,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 +364,11 @@ struct Mesh: Named
       INVALID
     };
 
-    std::map<Attribute::Type, Ref<Accessor>> mAttributes;
+    std::map<Attribute::Type, Ref<Accessor>>              mAttributes;
     std::vector<std::map<Attribute::Type, Ref<Accessor>>> mTargets;
-    Ref<Accessor> mIndices;
-    Ref<Material> mMaterial;
-    Mode mMode = TRIANGLES;
+    Ref<Accessor>                                         mIndices;
+    Ref<Material>                                         mMaterial;
+    Mode                                                  mMode = TRIANGLES;
 
     //TODO: [morph] targets
     //TODO: extras
@@ -364,7 +376,7 @@ struct Mesh: Named
   };
 
   std::vector<Primitive> mPrimitives;
-  std::vector<float> mWeights;
+  std::vector<float>     mWeights;
   //TODO: extras
   //TODO: extensions
 };
@@ -373,14 +385,14 @@ struct Node;
 
 struct Skin : Named
 {
-  Ref<Accessor> mInverseBindMatrices;
-  Ref<Node> mSkeleton;
+  Ref<Accessor>          mInverseBindMatrices;
+  Ref<Node>              mSkeleton;
   std::vector<Ref<Node>> mJoints;
   //TODO: extras
   //TODO: extensions
 };
 
-struct Camera: Named
+struct Camera : Named
 {
   struct Perspective
   {
@@ -403,21 +415,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<Camera> mCamera;
+  Ref<Camera>            mCamera;
   std::vector<Ref<Node>> mChildren;
-  Ref<Mesh> mMesh;
+  Ref<Mesh>              mMesh;
 
   Ref<Skin> mSkin;
   //TODO: [morph] weights
@@ -443,8 +455,8 @@ struct Animation : Named
       static Type FromString(const char* s, size_t len);
     };
 
-    Ref<Accessor> mInput;
-    Ref<Accessor> mOutput;
+    Ref<Accessor>       mInput;
+    Ref<Accessor>       mOutput;
     Interpolation::Type mInterpolation;
 
     //TODO: extras
@@ -467,11 +479,11 @@ struct Animation : Named
       static Type FromString(const char* s, size_t len);
 
       Ref<Node> mNode;
-      Type mPath;
+      Type      mPath;
     };
 
     Ref<Sampler> mSampler;
-    Target mTarget;
+    Target       mTarget;
     //TODO: extras
     //TODO: extensions
   };
@@ -480,7 +492,7 @@ struct Animation : Named
   std::vector<Channel> mChannels;
 };
 
-struct Scene: Named
+struct Scene : Named
 {
   std::vector<Ref<Node>> mNodes;
 };
@@ -489,29 +501,29 @@ struct Document
 {
   Asset mAsset;
 
-  std::vector<Buffer> mBuffers;
+  std::vector<Buffer>     mBuffers;
   std::vector<BufferView> mBufferViews;
-  std::vector<Accessor> mAccessors;
+  std::vector<Accessor>   mAccessors;
 
-  std::vector<Image> mImages;
-  std::vector<Sampler> mSamplers;
-  std::vector<Texture> mTextures;
+  std::vector<Image>    mImages;
+  std::vector<Sampler>  mSamplers;
+  std::vector<Texture>  mTextures;
   std::vector<Material> mMaterials;
 
   std::vector<Mesh> mMeshes;
   std::vector<Skin> mSkins;
 
   std::vector<Camera> mCameras;
-  std::vector<Node> mNodes;
+  std::vector<Node>   mNodes;
 
   std::vector<Animation> mAnimations;
 
   std::vector<Scene> mScenes;
-  Ref<Scene> mScene;
+  Ref<Scene>         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 +533,12 @@ struct Document
  * @brief Provides a json::Property<T>::ReadFn for interpreting unsigned integers
  *  as a Ref<U> into a std::vector<U> data member of a type T.
  */
-template <typename T>
+template<typename T>
 struct RefReader
 {
   static T* sObject;
 
-  template <typename U, std::vector<U> T::* V>
+  template<typename U, std::vector<U> T::*V>
   static Ref<U> Read(const json_value_s& j)
   {
     uint32_t index = json::Read::Number<uint32_t>(j);
@@ -534,13 +546,13 @@ struct RefReader
   }
 };
 
-template <typename T>
+template<typename T>
 T* RefReader<T>::sObject = nullptr;
 
 /**
  * @brief Convenience method to set the object for RefReader.
  */
-template <typename T>
+template<typename T>
 void SetRefReaderObject(T& object)
 {
   RefReader<T>::sObject = &object;
@@ -551,7 +563,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 <typename T> // T must have a nested enum called Type and a static Type FromString(const char*) method.
+template<typename T> // 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 +576,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 <typename T>
-inline
-T ReadDaliVector(const json_value_s& j)
+template<typename T>
+inline T ReadDaliVector(const json_value_s& j)
 {
   std::vector<float> floats = json::Read::Array<float, json::Read::Number<float>>(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 +591,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_