Add macro defs to shader regen
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / mesh-definition.cpp
index 6c4c104..7875012 100644 (file)
@@ -15,8 +15,8 @@
  *
  */
 
-// INTERNAL INCLUDES
-#include "dali-scene3d/public-api/loader/mesh-definition.h"
+// CLASS HEADER
+#include <dali-scene3d/public-api/loader/mesh-definition.h>
 
 // EXTERNAL INCLUDES
 #include <dali/devel-api/adaptor-framework/file-stream.h>
 #include <dali/public-api/math/compile-time-math.h>
 #include <cstring>
 #include <fstream>
+#include <functional>
 #include <type_traits>
 
-namespace Dali
-{
-namespace Scene3D
-{
-namespace Loader
+namespace Dali::Scene3D::Loader
 {
 namespace
 {
+template<bool use32BitIndices>
 class IndexProvider
 {
 public:
+  using IndexType = typename std::conditional_t<use32BitIndices, uint32_t, uint16_t>;
   IndexProvider(const uint16_t* indices)
   : mData(reinterpret_cast<uintptr_t>(indices)),
     mFunc(indices ? IncrementPointer : Increment)
   {
   }
 
-  uint16_t operator()()
+  IndexType operator()()
   {
     return mFunc(mData);
   }
 
 private:
-  static uint16_t Increment(uintptr_t& data)
+  static IndexType Increment(uintptr_t& data)
   {
-    return static_cast<uint16_t>(data++);
+    // mData was 'zero' at construct time. Just simply return counter start with 0.
+    return static_cast<IndexType>(data++);
   }
 
-  static uint16_t IncrementPointer(uintptr_t& data)
+  static IndexType IncrementPointer(uintptr_t& data)
   {
-    auto iPtr   = reinterpret_cast<const uint16_t*>(data);
+    auto iPtr   = reinterpret_cast<const IndexType*>(data);
     auto result = *iPtr;
     data        = reinterpret_cast<uintptr_t>(++iPtr);
     return result;
   }
 
   uintptr_t mData;
-  uint16_t (*mFunc)(uintptr_t&);
+  IndexType (*mFunc)(uintptr_t&);
 };
 
-const std::string QUAD("quad");
+const char* QUAD("quad");
 
 ///@brief Reads a blob from the given stream @a source into @a target, which must have
 /// at least @a descriptor.length bytes.
@@ -91,11 +91,11 @@ bool ReadBlob(const MeshDefinition::Blob& descriptor, std::istream& source, uint
       uint32_t       readSize  = 0;
       uint32_t       totalSize = (descriptor.mLength / descriptor.mElementSizeHint) * descriptor.mStride;
       while(readSize < totalSize &&
-            source.read(reinterpret_cast<char*>(target), descriptor.mElementSizeHint) &&
-            source.seekg(diff, std::istream::cur))
+            source.read(reinterpret_cast<char*>(target), descriptor.mElementSizeHint))
       {
         readSize += descriptor.mStride;
         target += descriptor.mElementSizeHint;
+        source.seekg(diff, std::istream::cur);
       }
       return readSize == totalSize;
     }
@@ -114,7 +114,7 @@ void ReadValues(const std::vector<uint8_t>& valuesBuffer, const std::vector<uint
   }
 }
 
-bool ReadAccessor(const MeshDefinition::Accessor& accessor, std::istream& source, uint8_t* target)
+bool ReadAccessor(const MeshDefinition::Accessor& accessor, std::istream& source, uint8_t* target, std::vector<uint32_t>* sparseIndices)
 {
   bool success = false;
 
@@ -153,33 +153,65 @@ bool ReadAccessor(const MeshDefinition::Accessor& accessor, std::istream& source
       return false;
     }
 
+    // If non-null sparse indices vector, prepare it for output
+    if(sparseIndices)
+    {
+      sparseIndices->resize(accessor.mSparse->mCount);
+    }
+
     switch(indices.mElementSizeHint)
     {
       case 1u:
       {
         ReadValues<uint8_t>(valuesBuffer, indicesBuffer, target, accessor.mSparse->mCount, values.mElementSizeHint);
+        if(sparseIndices)
+        {
+          // convert 8-bit indices into 32-bit
+          std::transform(indicesBuffer.begin(), indicesBuffer.end(), sparseIndices->begin(), [](const uint8_t& value) { return uint32_t(value); });
+        }
         break;
       }
       case 2u:
       {
         ReadValues<uint16_t>(valuesBuffer, indicesBuffer, target, accessor.mSparse->mCount, values.mElementSizeHint);
+        if(sparseIndices)
+        {
+          // convert 16-bit indices into 32-bit
+          std::transform(reinterpret_cast<uint16_t*>(indicesBuffer.data()),
+                         reinterpret_cast<uint16_t*>(indicesBuffer.data()) + accessor.mSparse->mCount,
+                         sparseIndices->begin(),
+                         [](const uint16_t& value) {
+                           return uint32_t(value);
+                         });
+        }
         break;
       }
       case 4u:
       {
         ReadValues<uint32_t>(valuesBuffer, indicesBuffer, target, accessor.mSparse->mCount, values.mElementSizeHint);
+        if(sparseIndices)
+        {
+          std::copy(indicesBuffer.begin(), indicesBuffer.end(), reinterpret_cast<uint8_t*>(sparseIndices->data()));
+        }
         break;
       }
       default:
+      {
         DALI_ASSERT_DEBUG(!"Unsupported type for an index");
+      }
     }
   }
 
   return success;
 }
 
+bool ReadAccessor(const MeshDefinition::Accessor& accessor, std::istream& source, uint8_t* target)
+{
+  return ReadAccessor(accessor, source, target, nullptr);
+}
+
 template<typename T>
-void ReadJointAccessor(MeshDefinition::RawData& raw, const MeshDefinition::Accessor& accessor, std::istream& source, const std::string& meshPath)
+void ReadJointAccessor(MeshDefinition::RawData& raw, const MeshDefinition::Accessor& accessor, std::istream& source, const std::string& meshPath, const std::string& name)
 {
   constexpr auto sizeofBlobUnit = sizeof(T) * 4;
 
@@ -209,16 +241,93 @@ void ReadJointAccessor(MeshDefinition::RawData& raw, const MeshDefinition::Acces
       ++floats;
     }
   }
-  raw.mAttribs.push_back({"aJoints", Property::VECTOR4, static_cast<uint32_t>(outBufferSize / sizeof(Vector4)), std::move(buffer)});
+  raw.mAttribs.push_back({name, Property::VECTOR4, static_cast<uint32_t>(outBufferSize / sizeof(Vector4)), std::move(buffer)});
+}
+
+void ReadTypedJointAccessor(MeshDefinition::RawData& raw, uint32_t flags, MeshDefinition::Accessor& accessor, std::iostream& stream, std::string& path, const std::string& name)
+{
+  if(MaskMatch(flags, MeshDefinition::U16_JOINT_IDS))
+  {
+    ReadJointAccessor<uint16_t>(raw, accessor, stream, path, name);
+  }
+  else if(MaskMatch(flags, MeshDefinition::U8_JOINT_IDS))
+  {
+    ReadJointAccessor<uint8_t>(raw, accessor, stream, path, name);
+  }
+  else
+  {
+    ReadJointAccessor<float>(raw, accessor, stream, path, name);
+  }
 }
 
-void GenerateNormals(MeshDefinition::RawData& raw)
+template<typename T>
+void ReadWeightAccessor(MeshDefinition::RawData& raw, const MeshDefinition::Accessor& accessor, std::istream& source, const std::string& meshPath, const std::string& name)
 {
+  constexpr auto sizeofBlobUnit = sizeof(T) * 4;
+
+  DALI_ASSERT_ALWAYS(((accessor.mBlob.mLength % sizeofBlobUnit == 0) ||
+                      accessor.mBlob.mStride >= sizeofBlobUnit) &&
+                     "weights buffer length not a multiple of element size");
+  const auto inBufferSize  = accessor.mBlob.GetBufferSize();
+  const auto outBufferSize = (sizeof(Vector4) / sizeofBlobUnit) * inBufferSize;
+
+  std::vector<uint8_t> buffer(outBufferSize);
+  auto                 inBuffer = buffer.data() + outBufferSize - inBufferSize;
+  if(!ReadAccessor(accessor, source, inBuffer))
+  {
+    ExceptionFlinger(ASSERT_LOCATION) << "Failed to read weights from '" << meshPath << "'.";
+  }
+
+  if constexpr(sizeofBlobUnit != sizeof(Vector4))
+  {
+    auto       floats = reinterpret_cast<float*>(buffer.data());
+    const auto end    = inBuffer + inBufferSize;
+    while(inBuffer != end)
+    {
+      const auto value = *reinterpret_cast<T*>(inBuffer);
+      // Normalize weight value. value /= 255 for uint8_t weight, and value /= 65535 for uint16_t weight.
+      *floats = static_cast<float>(value) / static_cast<float>((1 << (sizeof(T) * 8)) - 1);
+
+      inBuffer += sizeof(T);
+      ++floats;
+    }
+  }
+  raw.mAttribs.push_back({name, Property::VECTOR4, static_cast<uint32_t>(outBufferSize / sizeof(Vector4)), std::move(buffer)});
+}
+
+void ReadTypedWeightAccessor(MeshDefinition::RawData& raw, uint32_t flags, MeshDefinition::Accessor& accessor, std::iostream& stream, std::string& path, std::string name)
+{
+  if(MaskMatch(flags, MeshDefinition::U16_WEIGHT))
+  {
+    ReadWeightAccessor<uint16_t>(raw, accessor, stream, path, name);
+  }
+  else if(MaskMatch(flags, MeshDefinition::U8_WEIGHT))
+  {
+    ReadWeightAccessor<uint8_t>(raw, accessor, stream, path, name);
+  }
+  else
+  {
+    ReadWeightAccessor<float>(raw, accessor, stream, path, name);
+  }
+}
+
+template<bool use32BitsIndices, typename IndexProviderType = IndexProvider<use32BitsIndices>>
+bool GenerateNormals(MeshDefinition::RawData& raw)
+{
+  using IndexType = typename IndexProviderType::IndexType;
+
+  // mIndicies size must be even if we use 32bit indices.
+  if(DALI_UNLIKELY(use32BitsIndices && !raw.mIndices.empty() && !(raw.mIndices.size() % (sizeof(IndexType) / sizeof(uint16_t)) == 0)))
+  {
+    return false;
+  }
+
   auto& attribs = raw.mAttribs;
   DALI_ASSERT_DEBUG(attribs.size() > 0); // positions
-  IndexProvider getIndex(raw.mIndices.data());
 
-  const uint32_t numIndices = raw.mIndices.empty() ? attribs[0].mNumElements : static_cast<uint32_t>(raw.mIndices.size());
+  IndexProviderType getIndex(raw.mIndices.data());
+
+  const uint32_t numIndices = raw.mIndices.empty() ? attribs[0].mNumElements : static_cast<uint32_t>(raw.mIndices.size() / (sizeof(IndexType) / sizeof(uint16_t)));
 
   auto* positions = reinterpret_cast<const Vector3*>(attribs[0].mData.data());
 
@@ -227,8 +336,8 @@ void GenerateNormals(MeshDefinition::RawData& raw)
 
   for(uint32_t i = 0; i < numIndices; i += 3)
   {
-    uint16_t indices[]{getIndex(), getIndex(), getIndex()};
-    Vector3  pos[]{positions[indices[0]], positions[indices[1]], positions[indices[2]]};
+    IndexType indices[]{getIndex(), getIndex(), getIndex()};
+    Vector3   pos[]{positions[indices[0]], positions[indices[1]], positions[indices[2]]};
 
     Vector3 a = pos[1] - pos[0];
     Vector3 b = pos[2] - pos[0];
@@ -247,14 +356,24 @@ void GenerateNormals(MeshDefinition::RawData& raw)
   }
 
   attribs.push_back({"aNormal", Property::VECTOR3, attribs[0].mNumElements, std::move(buffer)});
+
+  return true;
 }
 
-template<bool useVec3, bool hasUvs, typename T = std::conditional_t<useVec3, Vector3, Vector4>, typename = std::enable_if_t<(std::is_same<T, Vector3>::value || std::is_same<T, Vector4>::value)>>
+template<bool use32BitsIndices, bool useVec3, bool hasUvs, typename T = std::conditional_t<useVec3, Vector3, Vector4>, typename = std::enable_if_t<(std::is_same<T, Vector3>::value || std::is_same<T, Vector4>::value)>, typename IndexProviderType = IndexProvider<use32BitsIndices>>
 bool GenerateTangents(MeshDefinition::RawData& raw)
 {
+  using IndexType = typename IndexProviderType::IndexType;
+
+  // mIndicies size must be even if we use 32bit indices.
+  if(DALI_UNLIKELY(use32BitsIndices && !raw.mIndices.empty() && !(raw.mIndices.size() % (sizeof(IndexType) / sizeof(uint16_t)) == 0)))
+  {
+    return false;
+  }
+
   auto& attribs = raw.mAttribs;
   // Required positions, normals, uvs (if we have). If not, skip generation
-  if(attribs.size() < (2 + static_cast<size_t>(hasUvs)))
+  if(DALI_UNLIKELY(attribs.size() < (2 + static_cast<size_t>(hasUvs))))
   {
     return false;
   }
@@ -264,17 +383,18 @@ bool GenerateTangents(MeshDefinition::RawData& raw)
 
   if constexpr(hasUvs)
   {
-    IndexProvider  getIndex(raw.mIndices.data());
-    const uint32_t numIndices = raw.mIndices.empty() ? attribs[0].mNumElements : static_cast<uint32_t>(raw.mIndices.size());
+    IndexProviderType getIndex(raw.mIndices.data());
+
+    const uint32_t numIndices = raw.mIndices.empty() ? attribs[0].mNumElements : static_cast<uint32_t>(raw.mIndices.size() / (sizeof(IndexType) / sizeof(uint16_t)));
 
     auto* positions = reinterpret_cast<const Vector3*>(attribs[0].mData.data());
     auto* uvs       = reinterpret_cast<const Vector2*>(attribs[2].mData.data());
 
     for(uint32_t i = 0; i < numIndices; i += 3)
     {
-      uint16_t indices[]{getIndex(), getIndex(), getIndex()};
-      Vector3  pos[]{positions[indices[0]], positions[indices[1]], positions[indices[2]]};
-      Vector2  uv[]{uvs[indices[0]], uvs[indices[1]], uvs[indices[2]]};
+      IndexType indices[]{getIndex(), getIndex(), getIndex()};
+      Vector3   pos[]{positions[indices[0]], positions[indices[1]], positions[indices[2]]};
+      Vector2   uv[]{uvs[indices[0]], uvs[indices[1]], uvs[indices[2]]};
 
       float x0 = pos[1].x - pos[0].x;
       float y0 = pos[1].y - pos[0].y;
@@ -359,58 +479,221 @@ void CalculateTextureSize(uint32_t totalTextureSize, uint32_t& textureWidth, uin
   textureHeight = 1u << powHeight;
 }
 
-void CalculateGltf2BlendShapes(uint8_t* geometryBuffer, const std::vector<MeshDefinition::BlendShape>& blendShapes, uint32_t numberOfVertices, float& blendShapeUnnormalizeFactor, BufferDefinition::Vector& buffers)
+template<typename T>
+float GetNormalizedScale()
+{
+  return 1.0f / (std::numeric_limits<T>::max());
+}
+
+template<typename T>
+void DequantizeData(std::vector<uint8_t>& buffer, float* dequantizedValues, uint32_t numValues, bool normalized)
+{
+  // see https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
+
+  T* values = reinterpret_cast<T*>(buffer.data());
+
+  for(uint32_t i = 0; i < numValues; ++i)
+  {
+    *dequantizedValues = normalized ? std::max((*values) * GetNormalizedScale<T>(), -1.0f) : *values;
+
+    values++;
+    dequantizedValues++;
+  }
+}
+
+void GetDequantizedData(std::vector<uint8_t>& buffer, uint32_t numComponents, uint32_t count, uint32_t flags, bool normalized)
+{
+  bool dequantized = false;
+
+  std::vector<uint8_t> dequantizedBuffer(count * numComponents * sizeof(float));
+  float*               dequantizedValues = reinterpret_cast<float*>(dequantizedBuffer.data());
+
+  if(MaskMatch(flags, MeshDefinition::Flags::S8_POSITION) || MaskMatch(flags, MeshDefinition::Flags::S8_NORMAL) || MaskMatch(flags, MeshDefinition::Flags::S8_TANGENT) || MaskMatch(flags, MeshDefinition::Flags::S8_TEXCOORD))
+  {
+    DequantizeData<int8_t>(buffer, dequantizedValues, numComponents * count, normalized);
+    dequantized = true;
+  }
+  else if(MaskMatch(flags, MeshDefinition::Flags::U8_POSITION) || MaskMatch(flags, MeshDefinition::Flags::U8_TEXCOORD))
+  {
+    DequantizeData<uint8_t>(buffer, dequantizedValues, numComponents * count, normalized);
+    dequantized = true;
+  }
+  else if(MaskMatch(flags, MeshDefinition::Flags::S16_POSITION) || MaskMatch(flags, MeshDefinition::Flags::S16_NORMAL) || MaskMatch(flags, MeshDefinition::Flags::S16_TANGENT) || MaskMatch(flags, MeshDefinition::Flags::S16_TEXCOORD))
+  {
+    DequantizeData<int16_t>(buffer, dequantizedValues, numComponents * count, normalized);
+    dequantized = true;
+  }
+  else if(MaskMatch(flags, MeshDefinition::Flags::U16_POSITION) || MaskMatch(flags, MeshDefinition::Flags::U16_TEXCOORD))
+  {
+    DequantizeData<uint16_t>(buffer, dequantizedValues, numComponents * count, normalized);
+    dequantized = true;
+  }
+
+  if(dequantized)
+  {
+    buffer = std::move(dequantizedBuffer);
+  }
+}
+
+void GetDequantizedMinMax(std::vector<float>& min, std::vector<float>& max, uint32_t flags)
+{
+  float scale = 1.0f;
+
+  if(MaskMatch(flags, MeshDefinition::Flags::S8_POSITION) || MaskMatch(flags, MeshDefinition::Flags::S8_NORMAL) || MaskMatch(flags, MeshDefinition::Flags::S8_TANGENT) || MaskMatch(flags, MeshDefinition::Flags::S8_TEXCOORD))
+  {
+    scale = GetNormalizedScale<int8_t>();
+  }
+  else if(MaskMatch(flags, MeshDefinition::Flags::U8_POSITION) || MaskMatch(flags, MeshDefinition::Flags::U8_TEXCOORD))
+  {
+    scale = GetNormalizedScale<uint8_t>();
+  }
+  else if(MaskMatch(flags, MeshDefinition::Flags::S16_POSITION) || MaskMatch(flags, MeshDefinition::Flags::S16_NORMAL) || MaskMatch(flags, MeshDefinition::Flags::S16_TANGENT) || MaskMatch(flags, MeshDefinition::Flags::S16_TEXCOORD))
+  {
+    scale = GetNormalizedScale<int16_t>();
+  }
+  else if(MaskMatch(flags, MeshDefinition::Flags::U16_POSITION) || MaskMatch(flags, MeshDefinition::Flags::U16_TEXCOORD))
+  {
+    scale = GetNormalizedScale<uint16_t>();
+  }
+
+  if(scale != 1.0f)
+  {
+    for(float& value : min)
+    {
+      value = std::max(value * scale, -1.0f);
+    }
+
+    for(float& value : max)
+    {
+      value = std::min(value * scale, 1.0f);
+    }
+  }
+}
+
+void CalculateGltf2BlendShapes(uint8_t* geometryBuffer, std::vector<MeshDefinition::BlendShape>& blendShapes, uint32_t numberOfVertices, float& blendShapeUnnormalizeFactor, BufferDefinition::Vector& buffers)
 {
   uint32_t geometryBufferIndex = 0u;
-  float    maxDistance         = 0.f;
+  float    maxDistanceSquared  = 0.f;
   Vector3* geometryBufferV3    = reinterpret_cast<Vector3*>(geometryBuffer);
-  for(const auto& blendShape : blendShapes)
+  for(auto& blendShape : blendShapes)
   {
     if(blendShape.deltas.IsDefined())
     {
-      DALI_ASSERT_ALWAYS(((blendShape.deltas.mBlob.mLength % sizeof(Vector3) == 0u) ||
-                          blendShape.deltas.mBlob.mStride >= sizeof(Vector3)) &&
-                         "Blend Shape position buffer length not a multiple of element size");
+      const auto bufferSize = blendShape.deltas.mBlob.GetBufferSize();
+      uint32_t   numVector3;
 
-      const auto           bufferSize = blendShape.deltas.mBlob.GetBufferSize();
-      std::vector<uint8_t> buffer(bufferSize);
-      if(ReadAccessor(blendShape.deltas, buffers[blendShape.deltas.mBufferIdx].GetBufferStream(), buffer.data()))
+      if(MaskMatch(blendShape.mFlags, MeshDefinition::S8_POSITION))
       {
-        blendShape.deltas.mBlob.ApplyMinMax(static_cast<uint32_t>(bufferSize / sizeof(Vector3)), reinterpret_cast<float*>(buffer.data()));
+        DALI_ASSERT_ALWAYS(((blendShape.deltas.mBlob.mLength % (sizeof(uint8_t) * 3) == 0) ||
+                            blendShape.deltas.mBlob.mStride >= (sizeof(uint8_t) * 3)) &&
+                           "Blend Shape position buffer length not a multiple of element size");
+        numVector3 = static_cast<uint32_t>(bufferSize / (sizeof(uint8_t) * 3));
+      }
+      else if(MaskMatch(blendShape.mFlags, MeshDefinition::S16_POSITION))
+      {
+        DALI_ASSERT_ALWAYS(((blendShape.deltas.mBlob.mLength % (sizeof(uint16_t) * 3) == 0) ||
+                            blendShape.deltas.mBlob.mStride >= (sizeof(uint16_t) * 3)) &&
+                           "Blend Shape position buffer length not a multiple of element size");
+        numVector3 = static_cast<uint32_t>(bufferSize / (sizeof(uint16_t) * 3));
+      }
+      else
+      {
+        DALI_ASSERT_ALWAYS(((blendShape.deltas.mBlob.mLength % sizeof(Vector3) == 0) ||
+                            blendShape.deltas.mBlob.mStride >= sizeof(Vector3)) &&
+                           "Blend Shape position buffer length not a multiple of element size");
+        numVector3 = static_cast<uint32_t>(bufferSize / sizeof(Vector3));
+      }
+
+      std::vector<uint8_t>  buffer(bufferSize);
+      std::vector<uint32_t> sparseIndices{};
+
+      if(ReadAccessor(blendShape.deltas, buffers[blendShape.deltas.mBufferIdx].GetBufferStream(), buffer.data(), &sparseIndices))
+      {
+        GetDequantizedData(buffer, 3u, numVector3, blendShape.mFlags & MeshDefinition::POSITIONS_MASK, blendShape.deltas.mNormalized);
+
+        if(blendShape.deltas.mNormalized)
+        {
+          GetDequantizedMinMax(blendShape.deltas.mBlob.mMin, blendShape.deltas.mBlob.mMax, blendShape.mFlags & MeshDefinition::POSITIONS_MASK);
+        }
+
+        blendShape.deltas.mBlob.ApplyMinMax(numVector3, reinterpret_cast<float*>(buffer.data()), &sparseIndices);
+
         // Calculate the difference with the original mesh.
         // Find the max distance to normalize the deltas.
-        const Vector3* const deltasBuffer = reinterpret_cast<const Vector3* const>(buffer.data());
+        const auto* const deltasBuffer = reinterpret_cast<const Vector3* const>(buffer.data());
 
-        for(uint32_t index = 0u; index < numberOfVertices; ++index)
-        {
-          Vector3& delta = geometryBufferV3[geometryBufferIndex++];
-          delta          = deltasBuffer[index];
+        auto ProcessVertex = [&geometryBufferV3, &deltasBuffer, &maxDistanceSquared](uint32_t geometryBufferIndex, uint32_t deltaIndex) {
+          Vector3& delta = geometryBufferV3[geometryBufferIndex] = deltasBuffer[deltaIndex];
+          delta                                                  = deltasBuffer[deltaIndex];
+          return std::max(maxDistanceSquared, delta.LengthSquared());
+        };
 
-          maxDistance = std::max(maxDistance, delta.LengthSquared());
+        if(sparseIndices.empty())
+        {
+          for(uint32_t index = 0u; index < numberOfVertices; ++index)
+          {
+            maxDistanceSquared = ProcessVertex(geometryBufferIndex++, index);
+          }
+        }
+        else
+        {
+          // initialize blendshape texture
+          // TODO: there may be a case when sparse accessor uses a base buffer view for initial values.
+          std::fill(geometryBufferV3 + geometryBufferIndex, geometryBufferV3 + geometryBufferIndex + numberOfVertices, Vector3::ZERO);
+          for(auto index : sparseIndices)
+          {
+            maxDistanceSquared = ProcessVertex(geometryBufferIndex + index, index);
+          }
+          geometryBufferIndex += numberOfVertices;
         }
       }
     }
 
     if(blendShape.normals.IsDefined())
     {
-      DALI_ASSERT_ALWAYS(((blendShape.normals.mBlob.mLength % sizeof(Vector3) == 0u) ||
-                          blendShape.normals.mBlob.mStride >= sizeof(Vector3)) &&
-                         "Blend Shape normals buffer length not a multiple of element size");
+      const auto bufferSize = blendShape.normals.mBlob.GetBufferSize();
+      uint32_t   numVector3;
 
-      const auto           bufferSize = blendShape.normals.mBlob.GetBufferSize();
-      std::vector<uint8_t> buffer(bufferSize);
-      if(ReadAccessor(blendShape.normals, buffers[blendShape.normals.mBufferIdx].GetBufferStream(), buffer.data()))
+      if(MaskMatch(blendShape.mFlags, MeshDefinition::S8_NORMAL))
       {
-        blendShape.normals.mBlob.ApplyMinMax(static_cast<uint32_t>(bufferSize / sizeof(Vector3)), reinterpret_cast<float*>(buffer.data()));
+        DALI_ASSERT_ALWAYS(((blendShape.normals.mBlob.mLength % (sizeof(int8_t) * 3) == 0) ||
+                            blendShape.normals.mBlob.mStride >= (sizeof(int8_t) * 3)) &&
+                           "Blend Shape normals buffer length not a multiple of element size");
+        numVector3 = static_cast<uint32_t>(bufferSize / (sizeof(int8_t) * 3));
+      }
+      else if(MaskMatch(blendShape.mFlags, MeshDefinition::S16_NORMAL))
+      {
+        DALI_ASSERT_ALWAYS(((blendShape.normals.mBlob.mLength % (sizeof(int16_t) * 3) == 0) ||
+                            blendShape.normals.mBlob.mStride >= (sizeof(int16_t) * 3)) &&
+                           "Blend Shape normals buffer length not a multiple of element size");
+        numVector3 = static_cast<uint32_t>(bufferSize / (sizeof(int16_t) * 3));
+      }
+      else
+      {
+        DALI_ASSERT_ALWAYS(((blendShape.normals.mBlob.mLength % sizeof(Vector3) == 0) ||
+                            blendShape.normals.mBlob.mStride >= sizeof(Vector3)) &&
+                           "Blend Shape normals buffer length not a multiple of element size");
+        numVector3 = static_cast<uint32_t>(bufferSize / sizeof(Vector3));
+      }
 
-        // Calculate the difference with the original mesh, and translate to make all values positive.
-        const Vector3* const deltasBuffer = reinterpret_cast<const Vector3* const>(buffer.data());
+      std::vector<uint8_t>  buffer(bufferSize);
+      std::vector<uint32_t> sparseIndices;
+
+      if(ReadAccessor(blendShape.normals, buffers[blendShape.normals.mBufferIdx].GetBufferStream(), buffer.data(), &sparseIndices))
+      {
+        GetDequantizedData(buffer, 3u, numVector3, blendShape.mFlags & MeshDefinition::NORMALS_MASK, blendShape.normals.mNormalized);
 
-        for(uint32_t index = 0u; index < numberOfVertices; ++index)
+        if(blendShape.normals.mNormalized)
         {
-          Vector3& delta = geometryBufferV3[geometryBufferIndex++];
-          delta          = deltasBuffer[index];
+          GetDequantizedMinMax(blendShape.normals.mBlob.mMin, blendShape.normals.mBlob.mMax, blendShape.mFlags & MeshDefinition::NORMALS_MASK);
+        }
+
+        blendShape.normals.mBlob.ApplyMinMax(numVector3, reinterpret_cast<float*>(buffer.data()), &sparseIndices);
 
+        // Calculate the difference with the original mesh, and translate to make all values positive.
+        const Vector3* const deltasBuffer  = reinterpret_cast<const Vector3* const>(buffer.data());
+        auto                 ProcessVertex = [&geometryBufferV3, &deltasBuffer, &maxDistanceSquared](uint32_t geometryBufferIndex, uint32_t deltaIndex) {
+          Vector3& delta = geometryBufferV3[geometryBufferIndex] = deltasBuffer[deltaIndex];
           delta.x *= 0.5f;
           delta.y *= 0.5f;
           delta.z *= 0.5f;
@@ -418,30 +701,73 @@ void CalculateGltf2BlendShapes(uint8_t* geometryBuffer, const std::vector<MeshDe
           delta.x += 0.5f;
           delta.y += 0.5f;
           delta.z += 0.5f;
+        };
+
+        if(sparseIndices.empty())
+        {
+          for(uint32_t index = 0u; index < numberOfVertices; ++index)
+          {
+            ProcessVertex(geometryBufferIndex++, index);
+          }
+        }
+        else
+        {
+          std::fill(geometryBufferV3 + geometryBufferIndex, geometryBufferV3 + geometryBufferIndex + numberOfVertices, Vector3(0.5, 0.5, 0.5));
+          for(auto index : sparseIndices)
+          {
+            ProcessVertex(geometryBufferIndex + index, index);
+          }
+          geometryBufferIndex += numberOfVertices;
         }
       }
     }
 
     if(blendShape.tangents.IsDefined())
     {
-      DALI_ASSERT_ALWAYS(((blendShape.tangents.mBlob.mLength % sizeof(Vector3) == 0u) ||
-                          blendShape.tangents.mBlob.mStride >= sizeof(Vector3)) &&
-                         "Blend Shape tangents buffer length not a multiple of element size");
+      const auto bufferSize = blendShape.tangents.mBlob.GetBufferSize();
 
-      const auto           bufferSize = blendShape.tangents.mBlob.GetBufferSize();
-      std::vector<uint8_t> buffer(bufferSize);
-      if(ReadAccessor(blendShape.tangents, buffers[blendShape.tangents.mBufferIdx].GetBufferStream(), buffer.data()))
+      uint32_t numVector3;
+
+      if(MaskMatch(blendShape.mFlags, MeshDefinition::S8_TANGENT))
+      {
+        DALI_ASSERT_ALWAYS(((blendShape.tangents.mBlob.mLength % (sizeof(int8_t) * 3) == 0) ||
+                            blendShape.tangents.mBlob.mStride >= (sizeof(int8_t) * 3)) &&
+                           "Blend Shape tangents buffer length not a multiple of element size");
+        numVector3 = static_cast<uint32_t>(bufferSize / (sizeof(int8_t) * 3));
+      }
+      else if(MaskMatch(blendShape.mFlags, MeshDefinition::S16_TANGENT))
       {
-        blendShape.tangents.mBlob.ApplyMinMax(static_cast<uint32_t>(bufferSize / sizeof(Vector3)), reinterpret_cast<float*>(buffer.data()));
+        DALI_ASSERT_ALWAYS(((blendShape.tangents.mBlob.mLength % (sizeof(int16_t) * 3) == 0) ||
+                            blendShape.tangents.mBlob.mStride >= (sizeof(int16_t) * 3)) &&
+                           "Blend Shape tangents buffer length not a multiple of element size");
+        numVector3 = static_cast<uint32_t>(bufferSize / (sizeof(int16_t) * 3));
+      }
+      else
+      {
+        DALI_ASSERT_ALWAYS(((blendShape.tangents.mBlob.mLength % sizeof(Vector3) == 0) ||
+                            blendShape.tangents.mBlob.mStride >= sizeof(Vector3)) &&
+                           "Blend Shape tangents buffer length not a multiple of element size");
+        numVector3 = static_cast<uint32_t>(bufferSize / sizeof(Vector3));
+      }
 
-        // Calculate the difference with the original mesh, and translate to make all values positive.
-        const Vector3* const deltasBuffer = reinterpret_cast<const Vector3* const>(buffer.data());
+      std::vector<uint8_t>  buffer(bufferSize);
+      std::vector<uint32_t> sparseIndices;
+
+      if(ReadAccessor(blendShape.tangents, buffers[blendShape.tangents.mBufferIdx].GetBufferStream(), buffer.data(), &sparseIndices))
+      {
+        GetDequantizedData(buffer, 3u, numVector3, blendShape.mFlags & MeshDefinition::TANGENTS_MASK, blendShape.tangents.mNormalized);
 
-        for(uint32_t index = 0u; index < numberOfVertices; ++index)
+        if(blendShape.tangents.mNormalized)
         {
-          Vector3& delta = geometryBufferV3[geometryBufferIndex++];
-          delta          = deltasBuffer[index];
+          GetDequantizedMinMax(blendShape.tangents.mBlob.mMin, blendShape.tangents.mBlob.mMax, blendShape.mFlags & MeshDefinition::TANGENTS_MASK);
+        }
+
+        blendShape.tangents.mBlob.ApplyMinMax(numVector3, reinterpret_cast<float*>(buffer.data()), &sparseIndices);
 
+        // Calculate the difference with the original mesh, and translate to make all values positive.
+        const Vector3* const deltasBuffer  = reinterpret_cast<const Vector3* const>(buffer.data());
+        auto                 ProcessVertex = [&geometryBufferV3, &deltasBuffer, &maxDistanceSquared](uint32_t geometryBufferIndex, uint32_t deltaIndex) {
+          Vector3& delta = geometryBufferV3[geometryBufferIndex] = deltasBuffer[deltaIndex];
           delta.x *= 0.5f;
           delta.y *= 0.5f;
           delta.z *= 0.5f;
@@ -449,12 +775,37 @@ void CalculateGltf2BlendShapes(uint8_t* geometryBuffer, const std::vector<MeshDe
           delta.x += 0.5f;
           delta.y += 0.5f;
           delta.z += 0.5f;
+        };
+
+        if(sparseIndices.empty())
+        {
+          for(uint32_t index = 0u; index < numberOfVertices; ++index)
+          {
+            ProcessVertex(geometryBufferIndex++, index);
+          }
+        }
+        else
+        {
+          std::fill(geometryBufferV3 + geometryBufferIndex, geometryBufferV3 + geometryBufferIndex + numberOfVertices, Vector3(0.5, 0.5, 0.5));
+          for(auto index : sparseIndices)
+          {
+            ProcessVertex(geometryBufferIndex + index, index);
+          }
+          geometryBufferIndex += numberOfVertices;
         }
       }
     }
   }
 
   geometryBufferIndex = 0u;
+
+  const float maxDistance = sqrtf(maxDistanceSquared);
+
+  const float normalizeFactor = (maxDistanceSquared < Math::MACHINE_EPSILON_100) ? 1.f : (0.5f / maxDistance);
+
+  // Calculate and store the unnormalize factor.
+  blendShapeUnnormalizeFactor = maxDistance * 2.0f;
+
   for(const auto& blendShape : blendShapes)
   {
     // Normalize all the deltas and translate to a possitive value.
@@ -462,8 +813,6 @@ void CalculateGltf2BlendShapes(uint8_t* geometryBuffer, const std::vector<MeshDe
     // whose values that are less than zero are clamped.
     if(blendShape.deltas.IsDefined())
     {
-      const float normalizeFactor = (fabsf(maxDistance) < Math::MACHINE_EPSILON_1000) ? 1.f : (0.5f / sqrtf(maxDistance));
-
       for(uint32_t index = 0u; index < numberOfVertices; ++index)
       {
         Vector3& delta = geometryBufferV3[geometryBufferIndex++];
@@ -471,9 +820,6 @@ void CalculateGltf2BlendShapes(uint8_t* geometryBuffer, const std::vector<MeshDe
         delta.y        = Clamp(((delta.y * normalizeFactor) + 0.5f), 0.f, 1.f);
         delta.z        = Clamp(((delta.z * normalizeFactor) + 0.5f), 0.f, 1.f);
       }
-
-      // Calculate and store the unnormalize factor.
-      blendShapeUnnormalizeFactor = 1.f / normalizeFactor;
     }
 
     if(blendShape.normals.IsDefined())
@@ -513,19 +859,23 @@ MeshDefinition::SparseBlob::SparseBlob(Blob&& indices, Blob&& values, uint32_t c
 
 MeshDefinition::Accessor::Accessor(const MeshDefinition::Blob&       blob,
                                    const MeshDefinition::SparseBlob& sparse,
-                                   Index                             bufferIndex)
+                                   Index                             bufferIndex,
+                                   bool                              normalized)
 : mBlob{blob},
   mSparse{(sparse.mIndices.IsDefined() && sparse.mValues.IsDefined()) ? new SparseBlob{sparse} : nullptr},
-  mBufferIdx(bufferIndex)
+  mBufferIdx(bufferIndex),
+  mNormalized(normalized)
 {
 }
 
 MeshDefinition::Accessor::Accessor(MeshDefinition::Blob&&       blob,
                                    MeshDefinition::SparseBlob&& sparse,
-                                   Index                        bufferIndex)
+                                   Index                        bufferIndex,
+                                   bool                         normalized)
 : mBlob{std::move(blob)},
   mSparse{(sparse.mIndices.IsDefined() && sparse.mValues.IsDefined()) ? new SparseBlob{std::move(sparse)} : nullptr},
-  mBufferIdx(bufferIndex)
+  mBufferIdx(bufferIndex),
+  mNormalized(normalized)
 {
 }
 
@@ -544,7 +894,7 @@ void MeshDefinition::Blob::ComputeMinMax(std::vector<float>& min, std::vector<fl
   }
 }
 
-void MeshDefinition::Blob::ApplyMinMax(const std::vector<float>& min, const std::vector<float>& max, uint32_t count, float* values)
+void MeshDefinition::Blob::ApplyMinMax(const std::vector<float>& min, const std::vector<float>& max, uint32_t count, float* values, std::vector<uint32_t>* sparseIndices)
 {
   DALI_ASSERT_DEBUG(max.size() == min.size() || max.size() * min.size() == 0);
   const auto numComponents = std::max(min.size(), max.size());
@@ -593,9 +943,9 @@ void MeshDefinition::Blob::ComputeMinMax(uint32_t numComponents, uint32_t count,
   ComputeMinMax(mMin, mMax, numComponents, count, values);
 }
 
-void MeshDefinition::Blob::ApplyMinMax(uint32_t count, float* values) const
+void MeshDefinition::Blob::ApplyMinMax(uint32_t count, float* values, std::vector<uint32_t>* sparseIndices) const
 {
-  ApplyMinMax(mMin, mMax, count, values);
+  ApplyMinMax(mMin, mMax, count, values, sparseIndices);
 }
 
 void MeshDefinition::RawData::Attrib::AttachBuffer(Geometry& g) const
@@ -615,7 +965,11 @@ bool MeshDefinition::IsQuad() const
 
 bool MeshDefinition::IsSkinned() const
 {
-  return mJoints0.IsDefined() && mWeights0.IsDefined();
+  return !mJoints.empty() && !mWeights.empty();
+}
+uint32_t MeshDefinition::GetNumberOfJointSets() const
+{
+  return static_cast<uint32_t>(mJoints.size());
 }
 
 bool MeshDefinition::HasBlendShapes() const
@@ -670,18 +1024,6 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector&
       {
         ExceptionFlinger(ASSERT_LOCATION) << "Failed to read indices from '" << path << "'.";
       }
-
-      auto u16s = raw.mIndices.data();
-      auto u32s = reinterpret_cast<uint32_t*>(raw.mIndices.data());
-      auto end  = u32s + indexCount;
-      while(u32s != end)
-      {
-        *u16s = static_cast<uint16_t>(*u32s);
-        ++u16s;
-        ++u32s;
-      }
-
-      raw.mIndices.resize(indexCount);
     }
     else if(MaskMatch(mFlags, U8_INDICES))
     {
@@ -689,7 +1031,7 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector&
                           mIndices.mBlob.mStride >= sizeof(uint8_t)) &&
                          "Index buffer length not a multiple of element size");
       const auto indexCount = mIndices.mBlob.GetBufferSize() / sizeof(uint8_t);
-      raw.mIndices.resize(indexCount); // NOTE: we need space for uint32_ts initially.
+      raw.mIndices.resize(indexCount); // NOTE: we need space for uint16_ts initially.
 
       std::string path;
       auto        u8s    = reinterpret_cast<uint8_t*>(raw.mIndices.data()) + indexCount;
@@ -724,13 +1066,38 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector&
     }
   }
 
+  uint32_t numberOfVertices = 0u;
+
   std::vector<Vector3> positions;
   if(mPositions.IsDefined())
   {
-    DALI_ASSERT_ALWAYS(((mPositions.mBlob.mLength % sizeof(Vector3) == 0) ||
-                        mPositions.mBlob.mStride >= sizeof(Vector3)) &&
-                       "Position buffer length not a multiple of element size");
-    const auto           bufferSize = mPositions.mBlob.GetBufferSize();
+    const auto bufferSize = mPositions.mBlob.GetBufferSize();
+    uint32_t   numVector3;
+
+    if(MaskMatch(mFlags, S8_POSITION) || MaskMatch(mFlags, U8_POSITION))
+    {
+      DALI_ASSERT_ALWAYS(((mPositions.mBlob.mLength % (sizeof(uint8_t) * 3) == 0) ||
+                          mPositions.mBlob.mStride >= (sizeof(uint8_t) * 3)) &&
+                         "Position buffer length not a multiple of element size");
+      numVector3 = static_cast<uint32_t>(bufferSize / (sizeof(uint8_t) * 3));
+    }
+    else if(MaskMatch(mFlags, S16_POSITION) || MaskMatch(mFlags, U16_POSITION))
+    {
+      DALI_ASSERT_ALWAYS(((mPositions.mBlob.mLength % (sizeof(uint16_t) * 3) == 0) ||
+                          mPositions.mBlob.mStride >= (sizeof(uint16_t) * 3)) &&
+                         "Position buffer length not a multiple of element size");
+      numVector3 = static_cast<uint32_t>(bufferSize / (sizeof(uint16_t) * 3));
+    }
+    else
+    {
+      DALI_ASSERT_ALWAYS(((mPositions.mBlob.mLength % sizeof(Vector3) == 0) ||
+                          mPositions.mBlob.mStride >= sizeof(Vector3)) &&
+                         "Position buffer length not a multiple of element size");
+      numVector3 = static_cast<uint32_t>(bufferSize / sizeof(Vector3));
+    }
+
+    numberOfVertices = numVector3;
+
     std::vector<uint8_t> buffer(bufferSize);
 
     std::string path;
@@ -740,7 +1107,13 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector&
       ExceptionFlinger(ASSERT_LOCATION) << "Failed to read positions from '" << path << "'.";
     }
 
-    uint32_t numVector3 = static_cast<uint32_t>(bufferSize / sizeof(Vector3));
+    GetDequantizedData(buffer, 3u, numVector3, mFlags & POSITIONS_MASK, mPositions.mNormalized);
+
+    if(mPositions.mNormalized)
+    {
+      GetDequantizedMinMax(mPositions.mBlob.mMin, mPositions.mBlob.mMax, mFlags & POSITIONS_MASK);
+    }
+
     if(mPositions.mBlob.mMin.size() != 3u || mPositions.mBlob.mMax.size() != 3u)
     {
       mPositions.mBlob.ComputeMinMax(3u, numVector3, reinterpret_cast<float*>(buffer.data()));
@@ -763,10 +1136,31 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector&
   auto       hasNormals  = mNormals.IsDefined();
   if(hasNormals)
   {
-    DALI_ASSERT_ALWAYS(((mNormals.mBlob.mLength % sizeof(Vector3) == 0) ||
-                        mNormals.mBlob.mStride >= sizeof(Vector3)) &&
-                       "Normal buffer length not a multiple of element size");
-    const auto           bufferSize = mNormals.mBlob.GetBufferSize();
+    const auto bufferSize = mNormals.mBlob.GetBufferSize();
+    uint32_t   numVector3;
+
+    if(MaskMatch(mFlags, S8_NORMAL))
+    {
+      DALI_ASSERT_ALWAYS(((mNormals.mBlob.mLength % (sizeof(int8_t) * 3) == 0) ||
+                          mNormals.mBlob.mStride >= (sizeof(int8_t) * 3)) &&
+                         "Normal buffer length not a multiple of element size");
+      numVector3 = static_cast<uint32_t>(bufferSize / (sizeof(int8_t) * 3));
+    }
+    else if(MaskMatch(mFlags, S16_NORMAL))
+    {
+      DALI_ASSERT_ALWAYS(((mNormals.mBlob.mLength % (sizeof(int16_t) * 3) == 0) ||
+                          mNormals.mBlob.mStride >= (sizeof(int16_t) * 3)) &&
+                         "Normal buffer length not a multiple of element size");
+      numVector3 = static_cast<uint32_t>(bufferSize / (sizeof(int16_t) * 3));
+    }
+    else
+    {
+      DALI_ASSERT_ALWAYS(((mNormals.mBlob.mLength % sizeof(Vector3) == 0) ||
+                          mNormals.mBlob.mStride >= sizeof(Vector3)) &&
+                         "Normal buffer length not a multiple of element size");
+      numVector3 = static_cast<uint32_t>(bufferSize / sizeof(Vector3));
+    }
+
     std::vector<uint8_t> buffer(bufferSize);
 
     std::string path;
@@ -776,34 +1170,75 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector&
       ExceptionFlinger(ASSERT_LOCATION) << "Failed to read normals from '" << path << "'.";
     }
 
-    mNormals.mBlob.ApplyMinMax(static_cast<uint32_t>(bufferSize / sizeof(Vector3)), reinterpret_cast<float*>(buffer.data()));
+    GetDequantizedData(buffer, 3u, numVector3, mFlags & NORMALS_MASK, mNormals.mNormalized);
 
-    raw.mAttribs.push_back({"aNormal", Property::VECTOR3, static_cast<uint32_t>(bufferSize / sizeof(Vector3)), std::move(buffer)});
+    if(mNormals.mNormalized)
+    {
+      GetDequantizedMinMax(mNormals.mBlob.mMin, mNormals.mBlob.mMax, mFlags & NORMALS_MASK);
+    }
+
+    mNormals.mBlob.ApplyMinMax(numVector3, reinterpret_cast<float*>(buffer.data()));
+
+    raw.mAttribs.push_back({"aNormal", Property::VECTOR3, numVector3, std::move(buffer)});
   }
   else if(mNormals.mBlob.mLength != 0 && isTriangles)
   {
     DALI_ASSERT_DEBUG(mNormals.mBlob.mLength == mPositions.mBlob.GetBufferSize());
-    GenerateNormals(raw);
-    hasNormals = true;
+    static const std::function<bool(RawData&)> GenerateNormalsFunction[2] =
+      {
+        GenerateNormals<false>,
+        GenerateNormals<true>,
+      };
+    const bool generateSuccessed = GenerateNormalsFunction[MaskMatch(mFlags, U32_INDICES)](raw);
+    if(!generateSuccessed)
+    {
+      DALI_LOG_ERROR("Failed to generate normal\n");
+    }
+    else
+    {
+      hasNormals = true;
+    }
   }
 
-  const auto hasUvs = mTexCoords.IsDefined();
-  if(hasUvs)
+  if(!mTexCoords.empty() && mTexCoords[0].IsDefined())
   {
-    DALI_ASSERT_ALWAYS(((mTexCoords.mBlob.mLength % sizeof(Vector2) == 0) ||
-                        mTexCoords.mBlob.mStride >= sizeof(Vector2)) &&
-                       "Normal buffer length not a multiple of element size");
-    const auto           bufferSize = mTexCoords.mBlob.GetBufferSize();
+    auto& texCoords = mTexCoords[0];
+    const auto bufferSize = texCoords.mBlob.GetBufferSize();
+    uint32_t uvCount;
+
+    if(MaskMatch(mFlags, S8_TEXCOORD) || MaskMatch(mFlags, U8_TEXCOORD))
+    {
+      DALI_ASSERT_ALWAYS(((texCoords.mBlob.mLength % (sizeof(uint8_t) * 2) == 0) ||
+                          texCoords.mBlob.mStride >= (sizeof(uint8_t) * 2)) &&
+                         "TexCoords buffer length not a multiple of element size");
+      uvCount = static_cast<uint32_t>(bufferSize / (sizeof(uint8_t) * 2));
+    }
+    else if(MaskMatch(mFlags, S16_TEXCOORD) || MaskMatch(mFlags, U16_TEXCOORD))
+    {
+      DALI_ASSERT_ALWAYS(((texCoords.mBlob.mLength % (sizeof(uint16_t) * 2) == 0) ||
+                          texCoords.mBlob.mStride >= (sizeof(uint16_t) * 2)) &&
+                         "TexCoords buffer length not a multiple of element size");
+      uvCount = static_cast<uint32_t>(bufferSize / (sizeof(uint16_t) * 2));
+    }
+    else
+    {
+      DALI_ASSERT_ALWAYS(((texCoords.mBlob.mLength % sizeof(Vector2) == 0) ||
+                          texCoords.mBlob.mStride >= sizeof(Vector2)) &&
+                         "TexCoords buffer length not a multiple of element size");
+      uvCount = static_cast<uint32_t>(bufferSize / sizeof(Vector2));
+    }
+
     std::vector<uint8_t> buffer(bufferSize);
 
     std::string path;
-    auto&       stream = GetAvailableData(fileStream, meshPath, buffers[mTexCoords.mBufferIdx], path);
-    if(!ReadAccessor(mTexCoords, stream, buffer.data()))
+    auto&       stream = GetAvailableData(fileStream, meshPath, buffers[texCoords.mBufferIdx], path);
+    if(!ReadAccessor(texCoords, stream, buffer.data()))
     {
       ExceptionFlinger(ASSERT_LOCATION) << "Failed to read uv-s from '" << path << "'.";
     }
 
-    const auto uvCount = bufferSize / sizeof(Vector2);
+    GetDequantizedData(buffer, 2u, uvCount, mFlags & TEXCOORDS_MASK, texCoords.mNormalized);
+
     if(MaskMatch(mFlags, FLIP_UVS_VERTICAL))
     {
       auto uv    = reinterpret_cast<Vector2*>(buffer.data());
@@ -815,18 +1250,46 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector&
       }
     }
 
-    mTexCoords.mBlob.ApplyMinMax(static_cast<uint32_t>(bufferSize / sizeof(Vector2)), reinterpret_cast<float*>(buffer.data()));
+    if(texCoords.mNormalized)
+    {
+      GetDequantizedMinMax(texCoords.mBlob.mMin, texCoords.mBlob.mMax, mFlags & TEXCOORDS_MASK);
+    }
 
+    texCoords.mBlob.ApplyMinMax(static_cast<uint32_t>(uvCount), reinterpret_cast<float*>(buffer.data()));
     raw.mAttribs.push_back({"aTexCoord", Property::VECTOR2, static_cast<uint32_t>(uvCount), std::move(buffer)});
   }
 
   if(mTangents.IsDefined())
   {
-    uint32_t propertySize = static_cast<uint32_t>((mTangentType == Property::VECTOR4) ? sizeof(Vector4) : sizeof(Vector3));
-    DALI_ASSERT_ALWAYS(((mTangents.mBlob.mLength % propertySize == 0) ||
-                        mTangents.mBlob.mStride >= propertySize) &&
-                       "Tangents buffer length not a multiple of element size");
-    const auto           bufferSize = mTangents.mBlob.GetBufferSize();
+    const auto bufferSize = mTangents.mBlob.GetBufferSize();
+
+    uint32_t propertySize   = static_cast<uint32_t>((mTangentType == Property::VECTOR4) ? sizeof(Vector4) : sizeof(Vector3));
+    uint32_t componentCount = static_cast<uint32_t>(propertySize / sizeof(float));
+
+    uint32_t numTangents;
+
+    if(MaskMatch(mFlags, S8_TANGENT))
+    {
+      DALI_ASSERT_ALWAYS(((mTangents.mBlob.mLength % (sizeof(int8_t) * componentCount) == 0) ||
+                          mTangents.mBlob.mStride >= (sizeof(int8_t) * componentCount)) &&
+                         "Tangents buffer length not a multiple of element size");
+      numTangents = static_cast<uint32_t>(bufferSize / (sizeof(int8_t) * componentCount));
+    }
+    else if(MaskMatch(mFlags, S16_TANGENT))
+    {
+      DALI_ASSERT_ALWAYS(((mTangents.mBlob.mLength % (sizeof(int16_t) * componentCount) == 0) ||
+                          mTangents.mBlob.mStride >= (sizeof(int16_t) * componentCount)) &&
+                         "Tangents buffer length not a multiple of element size");
+      numTangents = static_cast<uint32_t>(bufferSize / (sizeof(int16_t) * componentCount));
+    }
+    else
+    {
+      DALI_ASSERT_ALWAYS(((mTangents.mBlob.mLength % propertySize == 0) ||
+                          mTangents.mBlob.mStride >= propertySize) &&
+                         "Tangents buffer length not a multiple of element size");
+      numTangents = static_cast<uint32_t>(bufferSize / propertySize);
+    }
+
     std::vector<uint8_t> buffer(bufferSize);
 
     std::string path;
@@ -835,86 +1298,110 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector&
     {
       ExceptionFlinger(ASSERT_LOCATION) << "Failed to read tangents from '" << path << "'.";
     }
-    mTangents.mBlob.ApplyMinMax(bufferSize / propertySize, reinterpret_cast<float*>(buffer.data()));
 
-    raw.mAttribs.push_back({"aTangent", mTangentType, static_cast<uint32_t>(bufferSize / propertySize), std::move(buffer)});
+    GetDequantizedData(buffer, componentCount, numTangents, mFlags & TANGENTS_MASK, mTangents.mNormalized);
+
+    if(mTangents.mNormalized)
+    {
+      GetDequantizedMinMax(mTangents.mBlob.mMin, mTangents.mBlob.mMax, mFlags & TANGENTS_MASK);
+    }
+
+    mTangents.mBlob.ApplyMinMax(numTangents, reinterpret_cast<float*>(buffer.data()));
+
+    raw.mAttribs.push_back({"aTangent", mTangentType, static_cast<uint32_t>(numTangents), std::move(buffer)});
   }
   else if(mTangents.mBlob.mLength != 0 && hasNormals && isTriangles)
   {
     DALI_ASSERT_DEBUG(mTangents.mBlob.mLength == mNormals.mBlob.GetBufferSize());
-    static const std::function<bool(RawData&)> GenerateTangentsFunction[2][2] =
+    static const std::function<bool(RawData&)> GenerateTangentsFunction[2][2][2] =
       {
         {
-          GenerateTangents<false, false>,
-          GenerateTangents<false, true>,
+          {
+            GenerateTangents<false, false, false>,
+            GenerateTangents<false, false, true>,
+          },
+          {
+            GenerateTangents<false, true, false>,
+            GenerateTangents<false, true, true>,
+          },
         },
         {
-          GenerateTangents<true, false>,
-          GenerateTangents<true, true>,
-        },
-      };
-    const bool generateSuccessed = GenerateTangentsFunction[mTangentType == Property::VECTOR3][hasUvs](raw);
+          {
+            GenerateTangents<true, false, false>,
+            GenerateTangents<true, false, true>,
+          },
+          {
+            GenerateTangents<true, true, false>,
+            GenerateTangents<true, true, true>,
+          },
+        }};
+    const bool hasUvs            = !mTexCoords.empty() && mTexCoords[0].IsDefined();
+    const bool generateSuccessed = GenerateTangentsFunction[MaskMatch(mFlags, U32_INDICES)][mTangentType == Property::VECTOR3][hasUvs](raw);
     if(!generateSuccessed)
     {
       DALI_LOG_ERROR("Failed to generate tangents\n");
     }
   }
 
-  if(mColors.IsDefined())
+  // Only support 1 vertex color
+  if(!mColors.empty() && mColors[0].IsDefined())
   {
-    uint32_t       propertySize = mColors.mBlob.mElementSizeHint;
+    uint32_t       propertySize = mColors[0].mBlob.mElementSizeHint;
     Property::Type propertyType = (propertySize == sizeof(Vector4)) ? Property::VECTOR4 : ((propertySize == sizeof(Vector3)) ? Property::VECTOR3 : Property::NONE);
     if(propertyType != Property::NONE)
     {
-      DALI_ASSERT_ALWAYS(((mColors.mBlob.mLength % propertySize == 0) ||
-                          mColors.mBlob.mStride >= propertySize) &&
+      DALI_ASSERT_ALWAYS(((mColors[0].mBlob.mLength % propertySize == 0) ||
+                          mColors[0].mBlob.mStride >= propertySize) &&
                          "Colors buffer length not a multiple of element size");
-      const auto           bufferSize = mColors.mBlob.GetBufferSize();
+      const auto           bufferSize = mColors[0].mBlob.GetBufferSize();
       std::vector<uint8_t> buffer(bufferSize);
 
       std::string path;
-      auto&       stream = GetAvailableData(fileStream, meshPath, buffers[mColors.mBufferIdx], path);
-      if(!ReadAccessor(mColors, stream, buffer.data()))
+      auto&       stream = GetAvailableData(fileStream, meshPath, buffers[mColors[0].mBufferIdx], path);
+      if(!ReadAccessor(mColors[0], stream, buffer.data()))
       {
         ExceptionFlinger(ASSERT_LOCATION) << "Failed to read colors from '" << path << "'.";
       }
-      mColors.mBlob.ApplyMinMax(bufferSize / propertySize, reinterpret_cast<float*>(buffer.data()));
+      mColors[0].mBlob.ApplyMinMax(bufferSize / propertySize, reinterpret_cast<float*>(buffer.data()));
 
       raw.mAttribs.push_back({"aVertexColor", propertyType, static_cast<uint32_t>(bufferSize / propertySize), std::move(buffer)});
     }
   }
-
-  if(IsSkinned())
+  else
   {
-    std::string pathJoint;
-    auto&       streamJoint = GetAvailableData(fileStream, meshPath, buffers[mJoints0.mBufferIdx], pathJoint);
-    if(MaskMatch(mFlags, U16_JOINT_IDS))
-    {
-      ReadJointAccessor<uint16_t>(raw, mJoints0, streamJoint, pathJoint);
-    }
-    else if(MaskMatch(mFlags, U8_JOINT_IDS))
-    {
-      ReadJointAccessor<uint8_t>(raw, mJoints0, streamJoint, pathJoint);
-    }
-    else
+    std::vector<uint8_t> buffer(raw.mAttribs[0].mNumElements * sizeof(Vector4));
+    auto                 colors = reinterpret_cast<Vector4*>(buffer.data());
+
+    for(uint32_t i = 0; i < raw.mAttribs[0].mNumElements; i++)
     {
-      ReadJointAccessor<float>(raw, mJoints0, streamJoint, pathJoint);
+      colors[i] = Vector4::ONE;
     }
 
-    DALI_ASSERT_ALWAYS(((mWeights0.mBlob.mLength % sizeof(Vector4) == 0) ||
-                        mWeights0.mBlob.mStride >= sizeof(Vector4)) &&
-                       "Weights buffer length not a multiple of element size");
-    const auto           bufferSize = mWeights0.mBlob.GetBufferSize();
-    std::vector<uint8_t> buffer(bufferSize);
+    raw.mAttribs.push_back({"aVertexColor", Property::VECTOR4, raw.mAttribs[0].mNumElements, std::move(buffer)});
+  }
 
-    std::string pathWeight;
-    auto&       streamWeight = GetAvailableData(fileStream, meshPath, buffers[mWeights0.mBufferIdx], pathWeight);
-    if(!ReadAccessor(mWeights0, streamWeight, buffer.data()))
+  if(IsSkinned())
+  {
+    int setIndex = 0;
+    for(auto& accessor : mJoints)
     {
-      ExceptionFlinger(ASSERT_LOCATION) << "Failed to read weights from '" << pathWeight << "'.";
+      std::string        pathJoint;
+      auto&              streamJoint = GetAvailableData(fileStream, meshPath, buffers[accessor.mBufferIdx], pathJoint);
+      std::ostringstream jointName;
+      jointName << "aJoints" << setIndex;
+      ++setIndex;
+      ReadTypedJointAccessor(raw, mFlags, accessor, streamJoint, pathJoint, jointName.str());
+    }
+    setIndex = 0;
+    for(auto& accessor : mWeights)
+    {
+      std::string        pathWeight;
+      auto&              streamWeight = GetAvailableData(fileStream, meshPath, buffers[accessor.mBufferIdx], pathWeight);
+      std::ostringstream weightName;
+      weightName << "aWeights" << setIndex;
+      ++setIndex;
+      ReadTypedWeightAccessor(raw, mFlags, accessor, streamWeight, pathWeight, weightName.str());
     }
-
-    raw.mAttribs.push_back({"aWeights", Property::VECTOR4, static_cast<uint32_t>(bufferSize / sizeof(Vector4)), std::move(buffer)});
   }
 
   // Calculate the Blob for the blend shapes.
@@ -922,22 +1409,31 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector&
   blendShapesBlob.mOffset = std::numeric_limits<unsigned int>::max();
   blendShapesBlob.mLength = 0u;
 
-  for(const auto& blendShape : mBlendShapes)
-  {
-    for(auto i : {&blendShape.deltas, &blendShape.normals, &blendShape.tangents})
+  uint32_t totalTextureSize(0u);
+
+  auto processAccessor = [&](const Accessor& accessor, uint32_t vector3Size) {
+    if(accessor.IsDefined())
     {
-      if(i->IsDefined())
-      {
-        blendShapesBlob.mOffset = std::min(blendShapesBlob.mOffset, i->mBlob.mOffset);
-        blendShapesBlob.mLength += i->mBlob.mLength;
-      }
+      blendShapesBlob.mOffset = std::min(blendShapesBlob.mOffset, accessor.mBlob.mOffset);
+      blendShapesBlob.mLength += accessor.mBlob.mLength;
+
+      totalTextureSize += accessor.mBlob.mLength / vector3Size;
     }
+  };
+
+  for(const auto& blendShape : mBlendShapes)
+  {
+    const auto positionMask = blendShape.mFlags & POSITIONS_MASK;
+    const auto normalMask   = blendShape.mFlags & NORMALS_MASK;
+    const auto tangentMask  = blendShape.mFlags & TANGENTS_MASK;
+
+    processAccessor(blendShape.deltas, MaskMatch(positionMask, S8_POSITION) ? sizeof(uint8_t) * 3 : (MaskMatch(positionMask, S16_POSITION) ? sizeof(uint16_t) * 3 : sizeof(Vector3)));
+    processAccessor(blendShape.normals, MaskMatch(normalMask, S8_NORMAL) ? sizeof(uint8_t) * 3 : (MaskMatch(normalMask, S16_NORMAL) ? sizeof(uint16_t) * 3 : sizeof(Vector3)));
+    processAccessor(blendShape.tangents, MaskMatch(tangentMask, S8_TANGENT) ? sizeof(uint8_t) * 3 : (MaskMatch(tangentMask, S16_TANGENT) ? sizeof(uint16_t) * 3 : sizeof(Vector3)));
   }
 
   if(HasBlendShapes())
   {
-    const uint32_t numberOfVertices = static_cast<uint32_t>(mPositions.mBlob.mLength / sizeof(Vector3));
-
     // Calculate the size of one buffer inside the texture.
     raw.mBlendShapeBufferOffset = numberOfVertices;
 
@@ -947,7 +1443,7 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector&
 
     if(!mBlendShapeHeader.IsDefined())
     {
-      CalculateTextureSize(static_cast<uint32_t>(blendShapesBlob.mLength / sizeof(Vector3)), textureWidth, textureHeight);
+      CalculateTextureSize(totalTextureSize, textureWidth, textureHeight);
       calculateGltf2BlendShapes = true;
     }
     else
@@ -1008,7 +1504,15 @@ MeshGeometry MeshDefinition::Load(RawData&& raw) const
   {
     if(!raw.mIndices.empty())
     {
-      meshGeometry.geometry.SetIndexBuffer(raw.mIndices.data(), raw.mIndices.size());
+      if(MaskMatch(mFlags, U32_INDICES))
+      {
+        // TODO : We can only store indeces as uint16_type. Send Dali::Geometry that we use it as uint32_t actual.
+        meshGeometry.geometry.SetIndexBuffer(reinterpret_cast<const uint32_t*>(raw.mIndices.data()), raw.mIndices.size() / 2);
+      }
+      else
+      {
+        meshGeometry.geometry.SetIndexBuffer(raw.mIndices.data(), raw.mIndices.size());
+      }
     }
 
     for(auto& a : raw.mAttribs)
@@ -1032,6 +1536,14 @@ MeshGeometry MeshDefinition::Load(RawData&& raw) const
   return meshGeometry;
 }
 
-} // namespace Loader
-} // namespace Scene3D
-} // namespace Dali
+void MeshDefinition::RetrieveBlendShapeComponents(bool& hasPositions, bool& hasNormals, bool& hasTangents) const
+{
+  for(const auto& blendShape : mBlendShapes)
+  {
+    hasPositions = hasPositions || blendShape.deltas.IsDefined();
+    hasNormals   = hasNormals || blendShape.normals.IsDefined();
+    hasTangents  = hasTangents || blendShape.tangents.IsDefined();
+  }
+}
+
+} // namespace Dali::Scene3D::Loader