Updated demos to use DALi clang-format
[platform/core/uifw/dali-demo.git] / examples / reflection-demo / gltf-scene.cpp
index 46e39cf..924ead9 100644 (file)
@@ -26,26 +26,22 @@ namespace
 const std::vector<std::string> GLTF_STR_ATTRIBUTE_TYPE = {
   "POSITION",
   "NORMAL",
-  "TEXCOORD_0"
-};
+  "TEXCOORD_0"};
 
 const std::vector<std::pair<std::string, uint32_t>> GLTF_STR_COMPONENT_TYPE = {
-  std::make_pair( "VEC2", 2 ),
-  std::make_pair( "VEC3", 3 ),
-  std::make_pair( "VEC4", 4 ),
-  std::make_pair( "SCALAR", 1 )
-};
+  std::make_pair("VEC2", 2),
+  std::make_pair("VEC3", 3),
+  std::make_pair("VEC4", 4),
+  std::make_pair("SCALAR", 1)};
 
-glTFAttributeType glTFAttributeTypeStrToEnum( const std::string& name )
+glTFAttributeType glTFAttributeTypeStrToEnum(const std::string& name)
 {
-  int index = -1;
-  auto iter = std::find_if( GLTF_STR_ATTRIBUTE_TYPE.begin(), GLTF_STR_ATTRIBUTE_TYPE.end(),
-  [name, &index]( const std::string& val )
-  {
+  int  index = -1;
+  auto iter  = std::find_if(GLTF_STR_ATTRIBUTE_TYPE.begin(), GLTF_STR_ATTRIBUTE_TYPE.end(), [name, &index](const std::string& val) {
     index++;
     return val == name;
   });
-  if( iter == GLTF_STR_ATTRIBUTE_TYPE.end() )
+  if(iter == GLTF_STR_ATTRIBUTE_TYPE.end())
   {
     return glTFAttributeType::UNDEFINED;
   }
@@ -53,14 +49,12 @@ glTFAttributeType glTFAttributeTypeStrToEnum( const std::string& name )
   return static_cast<glTFAttributeType>(index);
 }
 
-uint32_t glTFComponentTypeStrToNum( const std::string& name )
+uint32_t glTFComponentTypeStrToNum(const std::string& name)
 {
-  auto iter = std::find_if( GLTF_STR_COMPONENT_TYPE.begin(), GLTF_STR_COMPONENT_TYPE.end(),
-                            [name]( const std::pair<std::string, uint32_t>& val )
-                            {
-                              return val.first == name;
-                            });
-  if( iter == GLTF_STR_COMPONENT_TYPE.end() )
+  auto iter = std::find_if(GLTF_STR_COMPONENT_TYPE.begin(), GLTF_STR_COMPONENT_TYPE.end(), [name](const std::pair<std::string, uint32_t>& val) {
+    return val.first == name;
+  });
+  if(iter == GLTF_STR_COMPONENT_TYPE.end())
   {
     return 0;
   }
@@ -92,10 +86,9 @@ struct JsonResult<bool>
 };
 
 template<class Expected, class Converted = Expected>
-JsonResult<picojson::value> JsonFindValue( const picojson::object& object, const std::string& name )
+JsonResult<picojson::value> JsonFindValue(const picojson::object& object, const std::string& name)
 {
-  auto iter = find_if(object.begin(), object.end(), [name](decltype(*object.begin())& item)
-  {
+  auto iter = find_if(object.begin(), object.end(), [name](decltype(*object.begin())& item) {
     return item.first == name;
   });
 
@@ -107,11 +100,10 @@ JsonResult<picojson::value> JsonFindValue( const picojson::object& object, const
   return {true, iter->second};
 };
 
-
 template<class Expected, class Converted = Expected>
-JsonResult<Converted> JsonGetValue( const picojson::value& val, const std::string& name, const Converted& onFail )
+JsonResult<Converted> JsonGetValue(const picojson::value& val, const std::string& name, const Converted& onFail)
 {
-  if( val.contains(name) )
+  if(val.contains(name))
   {
     return {true, static_cast<Converted>(val.get(name).get<Expected>())};
   }
@@ -119,9 +111,9 @@ JsonResult<Converted> JsonGetValue( const picojson::value& val, const std::strin
 }
 
 template<class Expected, class Converted = Expected>
-bool JsonGetValueOut( const picojson::value& val, const std::string& name, Converted& writeOut )
+bool JsonGetValueOut(const picojson::value& val, const std::string& name, Converted& writeOut)
 {
-  if( val.contains(name) )
+  if(val.contains(name))
   {
     writeOut = static_cast<Converted>(val.get(name).get<Expected>());
     return true;
@@ -129,27 +121,26 @@ bool JsonGetValueOut( const picojson::value& val, const std::string& name, Conve
   return false;
 }
 
-
 /**
  * Safe json value accessor
  */
 template<class Expected, class Converted = Expected>
-JsonResult<std::vector<Converted>> JsonGetArray( const picojson::value& val, const std::string& name, std::vector<Converted> valueOnFail = {} )
+JsonResult<std::vector<Converted>> JsonGetArray(const picojson::value& val, const std::string& name, std::vector<Converted> valueOnFail = {})
 {
-  if(val.contains(name) )
+  if(val.contains(name))
   {
-    const auto& array = val.get(name).get<picojson::array>();
+    const auto&            array = val.get(name).get<picojson::array>();
     std::vector<Converted> result{};
-    for( const auto& item : array )
+    for(const auto& item : array)
     {
-      result.emplace_back( static_cast<Converted>(item.get<Expected>()) );
+      result.emplace_back(static_cast<Converted>(item.get<Expected>()));
     }
     return {true, result};
   }
   return {false, valueOnFail};
 }
 
-}
+} // namespace
 
 glTF::glTF(const std::string& filename)
 {
@@ -157,17 +148,17 @@ glTF::glTF(const std::string& filename)
   ParseJSON();
 }
 
-void glTF::LoadFromFile( const std::string& filename )
+void glTF::LoadFromFile(const std::string& filename)
 {
-  std::string jsonFile( filename );
+  std::string jsonFile(filename);
   jsonFile += ".gltf";
-  std::string binFile( filename );
+  std::string binFile(filename);
   binFile += ".bin";
 
   // load binary
 
   GLTF_LOG("LoadFromFile: %s", binFile.c_str());
-  mBuffer = LoadFile(binFile);
+  mBuffer    = LoadFile(binFile);
   jsonBuffer = LoadFile(jsonFile);
 
   // Log errors
@@ -177,7 +168,7 @@ void glTF::LoadFromFile( const std::string& filename )
   }
   else
   {
-    GLTF_LOG( "GLTF[BIN]: %s loaded, size = %d", binFile.c_str(), int(mBuffer.size()));
+    GLTF_LOG("GLTF[BIN]: %s loaded, size = %d", binFile.c_str(), int(mBuffer.size()));
   }
   if(jsonBuffer.empty())
   {
@@ -185,7 +176,7 @@ void glTF::LoadFromFile( const std::string& filename )
   }
   else
   {
-    GLTF_LOG( "GLTF: %s loaded, size = %d", binFile.c_str(), int(jsonBuffer.size()));
+    GLTF_LOG("GLTF: %s loaded, size = %d", binFile.c_str(), int(jsonBuffer.size()));
   }
 
   // Abort if errors
@@ -198,18 +189,18 @@ void glTF::LoadFromFile( const std::string& filename )
   auto err = picojson::parse(jsonNode, std::string(reinterpret_cast<char*>(jsonBuffer.data())));
   if(!err.empty())
   {
-    GLTF_LOG( "GLTF: Error parsing %s, error: %s", jsonFile.c_str(), err.c_str());
+    GLTF_LOG("GLTF: Error parsing %s, error: %s", jsonFile.c_str(), err.c_str());
     return;
   }
   else
   {
-    GLTF_LOG( "GLTF: %s loaded, size = %d", jsonFile.c_str(), int(jsonBuffer.size()));
+    GLTF_LOG("GLTF: %s loaded, size = %d", jsonFile.c_str(), int(jsonBuffer.size()));
   }
 }
 
 bool glTF::ParseJSON()
 {
-  if (!jsonNode.is<picojson::object>())
+  if(!jsonNode.is<picojson::object>())
   {
     return false;
   }
@@ -218,212 +209,211 @@ bool glTF::ParseJSON()
   mNodes.emplace_back();
 
   // Sources for textures to be resolved later
-  std::vector<uint32_t> textureSources{};
+  std::vector<uint32_t>     textureSources{};
   std::vector<glTF_Texture> images{};
 
-  for( auto& val : jsonNode.get<picojson::object>() )
+  for(auto& val : jsonNode.get<picojson::object>())
   {
-    GLTF_LOG( "node: %s", val.first.c_str());
+    GLTF_LOG("node: %s", val.first.c_str());
 
     // Parse bufferviews
-    if( val.first == "bufferViews" )
+    if(val.first == "bufferViews")
     {
       auto bufferViews = val.second;
-      for( auto& view : bufferViews.get<picojson::array>() )
+      for(auto& view : bufferViews.get<picojson::array>())
       {
         auto bufferIndex = uint32_t(view.get("buffer").get<double>());
-        auto byteLength = uint32_t(view.get("byteLength").get<double>());
-        auto byteOffset = uint32_t(view.get("byteOffset").get<double>());
+        auto byteLength  = uint32_t(view.get("byteLength").get<double>());
+        auto byteOffset  = uint32_t(view.get("byteOffset").get<double>());
 
         glTF_BufferView bufferView{};
         bufferView.bufferIndex = bufferIndex;
-        bufferView.byteLength = byteLength;
-        bufferView.byteOffset = byteOffset;
+        bufferView.byteLength  = byteLength;
+        bufferView.byteOffset  = byteOffset;
 
-        mBufferViews.emplace_back( bufferView );
+        mBufferViews.emplace_back(bufferView);
       }
     }
 
     // parse accessors
-    else if( val.first == "accessors" )
+    else if(val.first == "accessors")
     {
-      for( const auto& accessor : val.second.get<picojson::array>() )
+      for(const auto& accessor : val.second.get<picojson::array>())
       {
-        auto gltfAccessor = glTF_Accessor{};
-        gltfAccessor.bufferView = uint32_t(accessor.get( "bufferView" ).get<double>());
-        gltfAccessor.componentType = uint32_t(accessor.get( "componentType" ).get<double>());
-        gltfAccessor.count = uint32_t(accessor.get( "count" ).get<double>());
-        gltfAccessor.type = accessor.get( "type" ).get<std::string>();
-        gltfAccessor.componentSize = glTFComponentTypeStrToNum( gltfAccessor.type );
-        mAccessors.emplace_back( gltfAccessor );
+        auto gltfAccessor          = glTF_Accessor{};
+        gltfAccessor.bufferView    = uint32_t(accessor.get("bufferView").get<double>());
+        gltfAccessor.componentType = uint32_t(accessor.get("componentType").get<double>());
+        gltfAccessor.count         = uint32_t(accessor.get("count").get<double>());
+        gltfAccessor.type          = accessor.get("type").get<std::string>();
+        gltfAccessor.componentSize = glTFComponentTypeStrToNum(gltfAccessor.type);
+        mAccessors.emplace_back(gltfAccessor);
       }
     }
 
     // parse meshes
-    else if( val.first == "meshes" )
+    else if(val.first == "meshes")
     {
-      for( const auto& mesh : val.second.get<picojson::array>() )
+      for(const auto& mesh : val.second.get<picojson::array>())
       {
         glTF_Mesh gltfMesh{};
-        gltfMesh.name = mesh.get( "name" ).get<std::string>();
+        gltfMesh.name = mesh.get("name").get<std::string>();
 
         // get primitives (in this implementation assuming single mesh consists of
         // one and only one primitive)
         const auto& primitive = mesh.get("primitives").get<picojson::array>()[0];
-        const auto& attrs = primitive.get("attributes").get<picojson::object>();
-        for( const auto& attr : attrs )
+        const auto& attrs     = primitive.get("attributes").get<picojson::object>();
+        for(const auto& attr : attrs)
         {
-          auto type = glTFAttributeTypeStrToEnum( attr.first );
+          auto type    = glTFAttributeTypeStrToEnum(attr.first);
           auto bvIndex = uint32_t(attr.second.get<double>());
-          gltfMesh.attributes.emplace_back( std::make_pair( type, bvIndex ) );
+          gltfMesh.attributes.emplace_back(std::make_pair(type, bvIndex));
           GLTF_LOG("GLTF: ATTR: type: %d, index: %d", int(type), int(bvIndex));
         }
 
-        gltfMesh.indices = uint32_t(primitive.get("indices").get<double>());
+        gltfMesh.indices  = uint32_t(primitive.get("indices").get<double>());
         gltfMesh.material = uint32_t(primitive.get("material").get<double>());
-        mMeshes.emplace_back( gltfMesh );
+        mMeshes.emplace_back(gltfMesh);
       }
     }
     // parse cameras
-    else if( val.first == "cameras" )
+    else if(val.first == "cameras")
     {
       glTF_Camera tgifCamera{};
-      for( const auto& camera : val.second.get<picojson::array>() )
+      for(const auto& camera : val.second.get<picojson::array>())
       {
-        tgifCamera.name = camera.get( "name" ).to_str();
-        tgifCamera.isPerspective = (camera.get( "type" ).to_str() == "perspective" );
+        tgifCamera.name          = camera.get("name").to_str();
+        tgifCamera.isPerspective = (camera.get("type").to_str() == "perspective");
         if(tgifCamera.isPerspective)
         {
-          const auto& perspective = camera.get( "perspective" );
-          tgifCamera.yfov = static_cast<float>(perspective.get( "yfov" ).get<double>());
-          tgifCamera.zfar = static_cast<float>(perspective.get( "zfar" ).get<double>());
-          tgifCamera.znear = static_cast<float>(perspective.get( "znear" ).get<double>());
+          const auto& perspective = camera.get("perspective");
+          tgifCamera.yfov         = static_cast<float>(perspective.get("yfov").get<double>());
+          tgifCamera.zfar         = static_cast<float>(perspective.get("zfar").get<double>());
+          tgifCamera.znear        = static_cast<float>(perspective.get("znear").get<double>());
         }
 
-        mCameras.emplace_back( tgifCamera );
+        mCameras.emplace_back(tgifCamera);
       }
     }
     // parse nodes
-    else if( val.first == "nodes" )
+    else if(val.first == "nodes")
     {
       auto nodeIndex = 1u;
-      for( const auto& node : val.second.get<picojson::array>() )
+      for(const auto& node : val.second.get<picojson::array>())
       {
         glTF_Node gltfNode{};
-        gltfNode.name = node.get( "name" ).to_str();
-        auto rotation = JsonGetArray<double, float>( node, "rotation", {0.0f, 0.0f, 0.0f, 1.0f} );
-        auto translation = JsonGetArray<double, float>( node, "translation", {0.0f, 0.0f, 0.0f} );
-        auto scale = JsonGetArray<double, float>( node, "scale", {1.0f, 1.0f, 1.0f} );
-        std::copy( rotation.result.begin(), rotation.result.end(), gltfNode.rotationQuaternion );
-        std::copy( translation.result.begin(), translation.result.end(), gltfNode.translation );
-        std::copy( scale.result.begin(), scale.result.end(), gltfNode.scale );
-
-        auto children = JsonGetArray<double, uint32_t>( node, "children" );
+        gltfNode.name    = node.get("name").to_str();
+        auto rotation    = JsonGetArray<double, float>(node, "rotation", {0.0f, 0.0f, 0.0f, 1.0f});
+        auto translation = JsonGetArray<double, float>(node, "translation", {0.0f, 0.0f, 0.0f});
+        auto scale       = JsonGetArray<double, float>(node, "scale", {1.0f, 1.0f, 1.0f});
+        std::copy(rotation.result.begin(), rotation.result.end(), gltfNode.rotationQuaternion);
+        std::copy(translation.result.begin(), translation.result.end(), gltfNode.translation);
+        std::copy(scale.result.begin(), scale.result.end(), gltfNode.scale);
+
+        auto children = JsonGetArray<double, uint32_t>(node, "children");
         if(children.success)
         {
           gltfNode.children = std::move(children.result);
         }
-        gltfNode.index = nodeIndex;
+        gltfNode.index    = nodeIndex;
         gltfNode.cameraId = 0xffffffff;
-        gltfNode.meshId = 0xffffffff;
+        gltfNode.meshId   = 0xffffffff;
 
-        auto cameraId = JsonGetValue<double, uint32_t>( node, "camera", 0xffffffff );
-        if( cameraId.success )
+        auto cameraId = JsonGetValue<double, uint32_t>(node, "camera", 0xffffffff);
+        if(cameraId.success)
         {
           gltfNode.cameraId = cameraId.result;
         }
-        auto meshId = JsonGetValue<double, uint32_t>( node, "mesh",  0xffffffff );
-        if( meshId.success )
+        auto meshId = JsonGetValue<double, uint32_t>(node, "mesh", 0xffffffff);
+        if(meshId.success)
         {
           gltfNode.meshId = meshId.result;
         }
-        mNodes.emplace_back( gltfNode );
+        mNodes.emplace_back(gltfNode);
         ++nodeIndex;
       }
-
     }
     // parse scenes, note: only first scene is being parsed
-    else if( val.first == "scenes" )
+    else if(val.first == "scenes")
     {
-      auto& sceneNode = mNodes[0];
-      const auto& scene = val.second.get<picojson::array>()[0];
-      sceneNode.name = JsonGetValue<std::string>( scene, "name", std::string() );
-      auto result = JsonGetArray<double, uint32_t>( scene, "nodes" );
-      sceneNode.children = result.result;
-      sceneNode.index = 0;
+      auto&       sceneNode = mNodes[0];
+      const auto& scene     = val.second.get<picojson::array>()[0];
+      sceneNode.name        = JsonGetValue<std::string>(scene, "name", std::string());
+      auto result           = JsonGetArray<double, uint32_t>(scene, "nodes");
+      sceneNode.children    = result.result;
+      sceneNode.index       = 0;
     }
-    else if( val.first == "materials" )
+    else if(val.first == "materials")
     {
-      for( const auto& node : val.second.get<picojson::array>() )
+      for(const auto& node : val.second.get<picojson::array>())
       {
         // Get pbr material, base color texture
         glTF_Material material{};
-        material.doubleSided = JsonGetValue<bool>( node, "doubleSided", false ).result;
-        material.name = JsonGetValue<std::string>( node, "name", std::string() ).result;
-        if( node.contains("pbrMetallicRoughness") )
+        material.doubleSided = JsonGetValue<bool>(node, "doubleSided", false).result;
+        material.name        = JsonGetValue<std::string>(node, "name", std::string()).result;
+        if(node.contains("pbrMetallicRoughness"))
         {
           const auto& node0 = node.get("pbrMetallicRoughness");
           if(node0.contains("baseColorTexture"))
           {
-            const auto& node1 = node0.get("baseColorTexture");
-            auto index = uint32_t(node1.get("index").get<double>());
-            auto texCoord = uint32_t(node1.get("texCoord").get<double>());
-            material.pbrMetallicRoughness.enabled = true;
-            material.pbrMetallicRoughness.baseTextureColor.index = index;
+            const auto& node1                                       = node0.get("baseColorTexture");
+            auto        index                                       = uint32_t(node1.get("index").get<double>());
+            auto        texCoord                                    = uint32_t(node1.get("texCoord").get<double>());
+            material.pbrMetallicRoughness.enabled                   = true;
+            material.pbrMetallicRoughness.baseTextureColor.index    = index;
             material.pbrMetallicRoughness.baseTextureColor.texCoord = texCoord;
           }
         }
-        mMaterials.emplace_back( material );
+        mMaterials.emplace_back(material);
       }
     }
-    else if( val.first == "textures" )
+    else if(val.first == "textures")
     {
-      for(const auto& item : val.second.get<picojson::array>() )
+      for(const auto& item : val.second.get<picojson::array>())
       {
-        auto source = JsonGetValue<double, uint32_t>( item, "source", 0xffffffff );
-        textureSources.emplace_back( source.result );
+        auto source = JsonGetValue<double, uint32_t>(item, "source", 0xffffffff);
+        textureSources.emplace_back(source.result);
       }
     }
-    else if( val.first == "images" )
+    else if(val.first == "images")
     {
-      for(const auto& item : val.second.get<picojson::array>() )
+      for(const auto& item : val.second.get<picojson::array>())
       {
         glTF_Texture tex{};
-        JsonGetValueOut<std::string>( item, "name", tex.name );
-        JsonGetValueOut<std::string>( item, "uri", tex.uri );
-        images.emplace_back( tex );
+        JsonGetValueOut<std::string>(item, "name", tex.name);
+        JsonGetValueOut<std::string>(item, "uri", tex.uri);
+        images.emplace_back(tex);
       }
     }
   }
 
   // Resolve cross-referencing
-  for( const auto& source : textureSources )
+  for(const auto& source : textureSources)
   {
-    mTextures.emplace_back( images[source] );
+    mTextures.emplace_back(images[source]);
   }
 
   return true;
 }
 
-glTF_Buffer glTF::LoadFile( const std::string& filename )
+glTF_Buffer glTF::LoadFile(const std::string& filename)
 {
-  Dali::FileStream fileStream( filename.c_str(), Dali::FileStream::READ | Dali::FileStream::BINARY );
-  FILE* fin = fileStream.GetFile();
+  Dali::FileStream           fileStream(filename.c_str(), Dali::FileStream::READ | Dali::FileStream::BINARY);
+  FILE*                      fin = fileStream.GetFile();
   std::vector<unsigned char> buffer;
-  if( fin )
+  if(fin)
   {
-    if( fseek( fin, 0, SEEK_END ) )
+    if(fseek(fin, 0, SEEK_END))
     {
       return {};
     }
     auto size = ftell(fin);
-    if( fseek( fin, 0, SEEK_SET ) )
+    if(fseek(fin, 0, SEEK_SET))
     {
       return {};
     }
     buffer.resize(unsigned(size));
-    auto result = fread( buffer.data(), 1, size_t(size), fin );
-    if( result != size_t(size) )
+    auto result = fread(buffer.data(), 1, size_t(size), fin);
+    if(result != size_t(size))
     {
       GLTF_LOG("LoadFile: Result: %d", int(result));
       // return empty buffer
@@ -441,9 +431,9 @@ glTF_Buffer glTF::LoadFile( const std::string& filename )
 std::vector<const glTF_Mesh*> glTF::GetMeshes() const
 {
   std::vector<const glTF_Mesh*> retval;
-  for( auto& mesh : mMeshes )
+  for(auto& mesh : mMeshes)
   {
-    retval.emplace_back( &mesh );
+    retval.emplace_back(&mesh);
   }
   return retval;
 }
@@ -451,27 +441,27 @@ std::vector<const glTF_Mesh*> glTF::GetMeshes() const
 std::vector<const glTF_Camera*> glTF::GetCameras()
 {
   std::vector<const glTF_Camera*> cameras;
-  for( const auto& cam : mCameras )
+  for(const auto& cam : mCameras)
   {
-    cameras.emplace_back( &cam );
+    cameras.emplace_back(&cam);
   }
   return cameras;
 }
 
-std::vector<unsigned char> glTF::GetMeshAttributeBuffer( const glTF_Mesh& mesh,  const std::vector<glTFAttributeType>& attrTypes )
+std::vector<unsigned char> glTF::GetMeshAttributeBuffer(const glTF_Mesh& mesh, const std::vector<glTFAttributeType>& attrTypes)
 {
   // find buffer views
   struct Data
   {
     uint32_t accessorIndex{0u};
     uint32_t byteStride{0u};
-    char*    srcPtr{ nullptr };
+    char*    srcPtr{nullptr};
   };
   std::vector<Data> data{};
-  for( const auto& attrType : attrTypes )
+  for(const auto& attrType : attrTypes)
   {
-    std::find_if( mesh.attributes.begin(), mesh.attributes.end(), [&data, &attrType]( const std::pair<glTFAttributeType, uint32_t>& item ){
-      if( item.first == attrType )
+    std::find_if(mesh.attributes.begin(), mesh.attributes.end(), [&data, &attrType](const std::pair<glTFAttributeType, uint32_t>& item) {
+      if(item.first == attrType)
       {
         data.emplace_back();
         data.back().accessorIndex = item.second;
@@ -491,32 +481,32 @@ std::vector<unsigned char> glTF::GetMeshAttributeBuffer( const glTF_Mesh& mesh,
   glTF_Buffer retval{};
 
   // data is interleaved
-  if( data.size() > 1 )
+  if(data.size() > 1)
   {
-    auto attributeCount = mAccessors[data[0].accessorIndex].count;// / mAccessors[data[0].accessorIndex].componentSize;
+    auto     attributeCount  = mAccessors[data[0].accessorIndex].count; // / mAccessors[data[0].accessorIndex].componentSize;
     uint32_t attributeStride = 0;
     // now find buffer view stride for particular accessor
-    for( auto& item : data )
+    for(auto& item : data)
     {
       auto& accessor = mAccessors[item.accessorIndex];
 
       // Update byte stride for this buffer view
       auto& bufferView = mBufferViews[accessor.bufferView];
-      item.byteStride = bufferView.byteLength / attributeCount;
+      item.byteStride  = bufferView.byteLength / attributeCount;
       attributeStride += item.byteStride;
       item.srcPtr = reinterpret_cast<char*>(mBuffer.data()) + bufferView.byteOffset;
     }
 
     // now allocate final buffer and interleave data
-    retval.resize( attributeStride * attributeCount );
+    retval.resize(attributeStride * attributeCount);
     auto* dstPtr = retval.data();
-    for( auto i = 0u; i < attributeCount; ++i )
+    for(auto i = 0u; i < attributeCount; ++i)
     {
-      for(auto& item : data )
+      for(auto& item : data)
       {
-        std::copy( item.srcPtr,
-                   item.srcPtr + item.byteStride,
-                   reinterpret_cast<char*>(dstPtr) );
+        std::copy(item.srcPtr,
+                  item.srcPtr + item.byteStride,
+                  reinterpret_cast<char*>(dstPtr));
         dstPtr += item.byteStride;
         item.srcPtr += item.byteStride;
       }
@@ -525,19 +515,17 @@ std::vector<unsigned char> glTF::GetMeshAttributeBuffer( const glTF_Mesh& mesh,
   else // copy data directly as single buffer
   {
     auto& bufferView = mBufferViews[mAccessors[data[0].accessorIndex].bufferView];
-    retval.resize( bufferView.byteLength );
-    std::copy( mBuffer.begin() + bufferView.byteOffset,
-               mBuffer.begin() + bufferView.byteOffset + bufferView.byteLength,
-               retval.begin());
-
+    retval.resize(bufferView.byteLength);
+    std::copy(mBuffer.begin() + bufferView.byteOffset,
+              mBuffer.begin() + bufferView.byteOffset + bufferView.byteLength,
+              retval.begin());
   }
   return retval;
 }
 
-
-const glTF_Mesh* glTF::FindMeshByName( const std::string& name ) const
+const glTF_Mesh* glTF::FindMeshByName(const std::string& name) const
 {
-  for( const auto& mesh : mMeshes )
+  for(const auto& mesh : mMeshes)
   {
     if(mesh.name == name)
       return &mesh;
@@ -545,34 +533,32 @@ const glTF_Mesh* glTF::FindMeshByName( const std::string& name ) const
   return nullptr;
 }
 
-uint32_t glTF::GetMeshAttributeCount( const glTF_Mesh* mesh ) const
+uint32_t glTF::GetMeshAttributeCount(const glTF_Mesh* mesh) const
 {
   const auto& accessor = mAccessors[mesh->attributes[0].second];
-  return accessor.count;// / accessor.componentSize;
+  return accessor.count; // / accessor.componentSize;
 }
 
-std::vector<uint16_t> glTF::GetMeshIndexBuffer( const glTF_Mesh* mesh ) const
+std::vector<uint16_t> glTF::GetMeshIndexBuffer(const glTF_Mesh* mesh) const
 {
   // check GL component type
   const auto& accessor = mAccessors[mesh->indices];
-  if( accessor.componentType == 0x1403 ) // GL_UNSIGNED_SHORT
+  if(accessor.componentType == 0x1403) // GL_UNSIGNED_SHORT
   {
     std::vector<uint16_t> retval{};
-    retval.resize( accessor.count );
+    retval.resize(accessor.count);
     const auto& bufferView = mBufferViews[accessor.bufferView];
-    const auto* srcPtr = reinterpret_cast<const uint16_t*>
-                (reinterpret_cast<const char*>(mBuffer.data()) + bufferView.byteOffset);
-    std::copy( srcPtr, srcPtr + accessor.count, retval.data() );
+    const auto* srcPtr     = reinterpret_cast<const uint16_t*>(reinterpret_cast<const char*>(mBuffer.data()) + bufferView.byteOffset);
+    std::copy(srcPtr, srcPtr + accessor.count, retval.data());
     return retval;
   }
   return {};
 }
 
-const glTF_Node* glTF::FindNodeByName( const std::string& name ) const
+const glTF_Node* glTF::FindNodeByName(const std::string& name) const
 {
-  auto iter = std::find_if( mNodes.begin(), mNodes.end(), [name]( const glTF_Node& node )
-  {
-    return !name.compare( node.name );
+  auto iter = std::find_if(mNodes.begin(), mNodes.end(), [name](const glTF_Node& node) {
+    return !name.compare(node.name);
   });
 
   if(iter == mNodes.end())