void Animation::Mesh::InitMesh(unsigned int meshIndex, const aiMesh* aiMesh, std::vector<VertexInfo>& vertices, std::vector<unsigned int>& indices) { const aiVector3D zero3D(0.0f, 0.0f, 0.0f); // Populate the vertex attribute vectors for (unsigned int i = 0; i < aiMesh->mNumVertices; i++) { VertexInfo vertex; const aiVector3D* pos = &(aiMesh->mVertices[i]); const aiVector3D* normal = &(aiMesh->mNormals[i]); const aiVector3D* texCoord = aiMesh->HasTextureCoords(0) ? &(aiMesh->mTextureCoords[0][i]) : &zero3D; vertex.position = glm::vec3(pos->x, pos->y, pos->z); vertex.normal = glm::vec3(normal->x, normal->y, normal->z); vertex.texCoords = glm::vec2(texCoord->x, texCoord->y); vertices.push_back(vertex); } printf("Mesh #%d has %d bones.\n", meshIndex, aiMesh->mNumBones); LoadBones(meshIndex, aiMesh, vertices); // Populate the index buffer for (unsigned int i = 0; i < aiMesh->mNumFaces; i++) { const aiFace& Face = aiMesh->mFaces[i]; assert(Face.mNumIndices == 3); indices.push_back(Face.mIndices[0]); indices.push_back(Face.mIndices[1]); indices.push_back(Face.mIndices[2]); } }
void Mesh::InitMesh(uint MeshIndex, const aiMesh* paiMesh, vector<Vector3f>& Positions, vector<Vector3f>& Normals, vector<Vector2f>& TexCoords, vector<VertexBoneData>& Bones, vector<uint>& Indices) { const aiVector3D Zero3D(0.0f, 0.0f, 0.0f); // Populate the vertex attribute vectors for (uint i = 0 ; i < paiMesh->mNumVertices ; i++) { const aiVector3D* pPos = &(paiMesh->mVertices[i]); const aiVector3D* pNormal = &(paiMesh->mNormals[i]); const aiVector3D* pTexCoord = paiMesh->HasTextureCoords(0) ? &(paiMesh->mTextureCoords[0][i]) : &Zero3D; Positions.push_back(Vector3f(pPos->x, pPos->y, pPos->z)); Normals.push_back(Vector3f(pNormal->x, pNormal->y, pNormal->z)); TexCoords.push_back(Vector2f(pTexCoord->x, pTexCoord->y)); } LoadBones(MeshIndex, paiMesh, Bones); // Populate the index buffer for (uint i = 0 ; i < paiMesh->mNumFaces ; i++) { const aiFace& Face = paiMesh->mFaces[i]; assert(Face.mNumIndices == 3); Indices.push_back(Face.mIndices[0]); Indices.push_back(Face.mIndices[1]); Indices.push_back(Face.mIndices[2]); } }
bool Mesh::InitMesh(unsigned int Index, const aiMesh* paiMesh, std::vector<float>& pos, std::vector<float>& nrm, std::vector<float>& tex, std::vector<VtxBoneInfo>& bones, std::vector<unsigned int>& idx) { const aiVector3D zero3D(0.0f, 0.0f, 0.0f); for(unsigned int i=0; i< paiMesh->mNumVertices; i++) { const aiVector3D* pPos = &(paiMesh->mVertices[i]); const aiVector3D* pNor = &(paiMesh->mNormals[i]); const aiVector3D* pTex = paiMesh->HasTextureCoords(0)? &(paiMesh->mTextureCoords[0][i]): &zero3D; pos.push_back(pPos->x); pos.push_back(pPos->y); pos.push_back(pPos->z); nrm.push_back(pNor->x); nrm.push_back(pNor->y); nrm.push_back(pNor->z); tex.push_back(pTex->x); tex.push_back(pTex->y); } if (paiMesh->HasBones()) LoadBones(Index, paiMesh, bones); else printf("Mesh does not contain bones\n"); /* printf("Vertices (size=%u)\n", vtx.size()); for(unsigned int i=0; i<vtx.size(); i++) printf("%6.4f %6.4f %6.4f\n", vtx[i].px, vtx[i].py, vtx[i].pz); */ for(unsigned int i=0; i<paiMesh->mNumFaces; i++) { aiFace& f = paiMesh->mFaces[i]; assert(f.mNumIndices ==3); idx.push_back(f.mIndices[0]); idx.push_back(f.mIndices[1]); idx.push_back(f.mIndices[2]); } return true; }