src/GLTFLoader.cpp
// This function is identical to the one above, except that it loads the meshes of nodes that don't refer to skins
// In other words, it loads static meshes
This function is identical to the one above, except that it loads the meshes of nodes that don't refer to skins
In other words, it loads static meshes
This function is identical to the one above except that it loads the meshes of nodes that don ' t refer to skins In other words it loads static meshes
std::vector<AnimatedMesh> LoadStaticMeshes(cgltf_data* data)
{
   std::vector<AnimatedMesh> staticMeshes;
   unsigned int numNodes = static_cast<unsigned int>(data->nodes_count);
   for (unsigned int nodeIndex = 0; nodeIndex < numNodes; ++nodeIndex)
   {
      cgltf_node* currNode = &data->nodes[nodeIndex];
      if (currNode->mesh == nullptr)
      {
         continue;
      }
      unsigned int numPrimitives = static_cast<unsigned int>(currNode->mesh->primitives_count);
      for (unsigned int primitiveIndex = 0; primitiveIndex < numPrimitives; ++primitiveIndex)
      {
         cgltf_primitive* currPrimitive = &currNode->mesh->primitives[primitiveIndex];
         staticMeshes.push_back(AnimatedMesh());
         AnimatedMesh& currMesh = staticMeshes[staticMeshes.size() - 1];
         unsigned int numAttributes = static_cast<unsigned int>(currPrimitive->attributes_count);
         for (unsigned int attributeIndex = 0; attributeIndex < numAttributes; ++attributeIndex)
         {
            cgltf_attribute* attribute = &currPrimitive->attributes[attributeIndex];
            GLTFHelpers::StoreValuesOfAttributeInStaticMesh(*attribute, currMesh);
         }
         if (currPrimitive->indices != nullptr)
         {
            unsigned int indexCount = static_cast<unsigned int>(currPrimitive->indices->count);
            std::vector<unsigned int>& indices = currMesh.GetIndices();
            indices.resize(indexCount);
            for (unsigned int i = 0; i < indexCount; ++i)
            {
               indices[i] = static_cast<unsigned int>(cgltf_accessor_read_index(currPrimitive->indices, i));
            }
         }
         currMesh.LoadBuffers();
      }
   }
   return staticMeshes;
}
std :: vector < AnimatedMesh > LoadStaticMeshes ( cgltf_data * data ) { std :: vector < AnimatedMesh > staticMeshes ; unsigned int numNodes = static_cast < unsigned int > ( data -> nodes_count ) ; for ( unsigned int nodeIndex = 0 ; nodeIndex < numNodes ; ++ nodeIndex ) { cgltf_node * currNode = & data -> nodes [ nodeIndex ] ; if ( currNode -> mesh == nullptr ) { continue ; } unsigned int numPrimitives = static_cast < unsigned int > ( currNode -> mesh -> primitives_count ) ; for ( unsigned int primitiveIndex = 0 ; primitiveIndex < numPrimitives ; ++ primitiveIndex ) { cgltf_primitive * currPrimitive = & currNode -> mesh -> primitives [ primitiveIndex ] ; staticMeshes . push_back ( AnimatedMesh ( ) ) ; AnimatedMesh & currMesh = staticMeshes [ staticMeshes . size ( ) - 1 ] ; unsigned int numAttributes = static_cast < unsigned int > ( currPrimitive -> attributes_count ) ; for ( unsigned int attributeIndex = 0 ; attributeIndex < numAttributes ; ++ attributeIndex ) { cgltf_attribute * attribute = & currPrimitive -> attributes [ attributeIndex ] ; GLTFHelpers :: StoreValuesOfAttributeInStaticMesh ( * attribute , currMesh ) ; } if ( currPrimitive -> indices != nullptr ) { unsigned int indexCount = static_cast < unsigned int > ( currPrimitive -> indices -> count ) ; std :: vector < unsigned int > & indices = currMesh . GetIndices ( ) ; indices . resize ( indexCount ) ; for ( unsigned int i = 0 ; i < indexCount ; ++ i ) { indices [ i ] = static_cast < unsigned int > ( cgltf_accessor_read_index ( currPrimitive -> indices , i ) ) ; } } currMesh . LoadBuffers ( ) ; } } return staticMeshes ; }
This function is identical to the one above, except that it loads the meshes of nodes that don't refer to skins
In other words, it loads static meshes
This function is identical to the one above except that it loads the meshes of nodes that don ' t refer to skins In other words it loads static meshes
// Loop over the array of nodes of the glTF file // This function only loads static meshes, so the node must contain a mesh for us to process it // Loop over the array of mesh primitives of the current node // Get the current mesh primitive // Create an AnimatedMesh for the current mesh primitive // Loop over the attributes of the current mesh primitive // Get the current attribute // Read the values of the current attribute and store them in the current mesh // If the current mesh primitive has a set of indices, store them too // Get the vector that will store the indices of the current mesh // Loop over the indices of the current mesh primitive // TODO: Perhaps we shouldn't do this here. The user should choose when this is done // Once we are done loading the current mesh, we load its VBOs with the data that we read