Exemplo n.º 1
0
/*void SkeletalAnimationModelLoader::loadscene()//(unsigned int animationId, double time)
{
	createFrame(0, 0);
	//if (m_entity) m_entity->delComponents<MeshRenderer>();
	//else m_entity = std::make_shared<Entity>();
	m_entity = std::make_shared<Entity>();

	for (int k = 0; k < meshes.size(); k++)
	{
		MeshFrame meshFrame = getMeshFrame(meshes[k]);

		std::vector<Vertex> vertices;
		std::vector<unsigned int> indices;

		const aiVector3D aiZeroVector(0.0f, 0.0f, 0.0f);
		for (unsigned int i = 0; i < meshFrame.vertices.size(); i++)
		{
			const aiVector3D* pPos = &(meshFrame.vertices[i]);
			const aiVector3D* pNormal = &(meshes[k].normals[i]);
			const aiVector2D* pTexCoord = &(meshes[k].textureCoords[i]);
			const aiVector3D* pTangent = &(meshFrame.tangents[i]);

			Vertex vert(glm::vec3(pPos->x, pPos->y, pPos->z),
				glm::vec2(pTexCoord->x, pTexCoord->y),
				glm::vec3(pNormal->x, pNormal->y, pNormal->z),
				glm::vec3(pTangent->x, pTangent->y, pTangent->z));

			vertices.push_back(vert);
		}
		for (unsigned int i = 0; i < meshes[k].faces.size(); i++)
		{
			indices.push_back(meshes[k].faces[i].mIndices[0]);
			indices.push_back(meshes[k].faces[i].mIndices[1]);
			indices.push_back(meshes[k].faces[i].mIndices[2]);
		}

		MeshRendererData meshRenderData;
		meshRenderData.mesh = std::make_shared<Mesh>(m_fileName + meshes[k].name, &vertices[0], vertices.size(), &indices[0], indices.size());
		meshRenderData.material = Materials[k];

		MeshLoader::sceneMeshRendererDataCache[m_fileName].push_back(meshRenderData);
		m_entity->addComponent<MeshRenderer>(meshRenderData.mesh, meshRenderData.material);
	}
}//*/
  void SkeletalAnimationModelLoader::loadNewFrame(unsigned int animationId, double time) {
    createFrame(animationId, time);

    for (int k = 0; k < meshes.size(); k++) {
      MeshFrame meshFrame = getMeshFrame(meshes[k]);

      std::vector<Vertex> vertices;
      std::vector<unsigned int> indices;

      const aiVector3D aiZeroVector(0.0f, 0.0f, 0.0f);
      for (unsigned int i = 0; i < meshFrame.vertices.size(); i++) {
        const aiVector3D *pPos = &(meshFrame.vertices[i]);
        const aiVector3D *pNormal = &(meshes[k].normals[i]);
        const aiVector2D *pTexCoord = &(meshes[k].textureCoords[i]);
        const aiVector3D *pTangent = &(meshFrame.tangents[i]);

        Vertex vert(glm::vec3(pPos->x, pPos->y, pPos->z),
                    glm::vec2(pTexCoord->x, pTexCoord->y),
                    glm::vec3(pNormal->x, pNormal->y, pNormal->z),
                    glm::vec3(pTangent->x, pTangent->y, pTangent->z));

        vertices.push_back(vert);
      }
      for (unsigned int i = 0; i < meshes[k].faces.size(); i++) {
        indices.push_back(meshes[k].faces[i].mIndices[0]);
        indices.push_back(meshes[k].faces[i].mIndices[1]);
        indices.push_back(meshes[k].faces[i].mIndices[2]);
      }

      MeshLoader::sceneMeshRendererDataCache[m_fileName][k].mesh->reasign(m_fileName + meshes[k].name, &vertices[0],
                                                                          vertices.size(), &indices[0], indices.size());
    }
  }
Exemplo n.º 2
0
 //Convenient function to draw a frame directly without using createFrame, getMeshFrame, and drawMeshFrame separately. 
 void drawFrame(unsigned int animationId, double time) {
     createFrame(animationId, time);
     for(auto& mesh: this->meshes) {
         MeshFrame meshFrame=getMeshFrame(mesh);
         drawMeshFrame(meshFrame);
     }
 }