Let we allow to seek empty buffer when read blob
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / mesh-definition.cpp
index 3d5f6eb..a485e97 100644 (file)
@@ -90,11 +90,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;
     }
@@ -914,6 +914,18 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector&
       raw.mAttribs.push_back({"aVertexColor", propertyType, static_cast<uint32_t>(bufferSize / propertySize), std::move(buffer)});
     }
   }
+  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++)
+    {
+      colors[i] = Vector4::ONE;
+    }
+
+    raw.mAttribs.push_back({"aVertexColor", Property::VECTOR4, raw.mAttribs[0].mNumElements, std::move(buffer)});
+  }
 
   if(IsSkinned())
   {
@@ -1071,4 +1083,14 @@ MeshGeometry MeshDefinition::Load(RawData&& raw) const
   return meshGeometry;
 }
 
+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