void MeshUtility::AddFaceToMesh(Mesh& mesh, std::size_t p1PositionIndex, std::size_t p2PositionIndex, std::size_t p3PositionIndex, std::size_t p1TextureCoordIndex, std::size_t p2TextureCoordIndex, std::size_t p3TextureCoordIndex) { Mesh::face_t face; face.push_back( MeshVertexIndexer(p1PositionIndex, p1TextureCoordIndex, 0, 0) ); face.push_back( MeshVertexIndexer(p2PositionIndex, p2TextureCoordIndex, 0, 0) ); face.push_back( MeshVertexIndexer(p3PositionIndex, p3TextureCoordIndex, 0, 0) ); mesh.AddFace(face); }
void Model::InitMesh(const aiMesh* mesh) { MeshInfo* meshInfo = new MeshInfo; meshInfo->NumVertices = mesh->mNumVertices; meshInfo->NumIndices = mesh->mNumFaces * 3; Mesh* modelMesh = new Mesh(this, meshInfo); /*READ VERTS INTO MODEL MESH*/ size_t numVerts = mesh->mNumVertices; for(size_t i = 0; i < numVerts; i++) { aiVector3D vertex = mesh->mVertices[i]; aiVector3D tangent = aiVector3D(0.0f); if(mesh->HasTangentsAndBitangents()) { tangent = mesh->mTangents[i]; } aiVector3D normal(0.0f); float u = 0.0f; float v = 0.0f; if(mesh->HasNormals()) { normal = mesh->mNormals[i]; } if(mesh->HasTextureCoords(0)) { aiVector3D uvs = mesh->mTextureCoords[0][i]; u = uvs.x; v = uvs.y; } meshInfo->Vertices.push_back(Vec3(vertex.x, vertex.y, vertex.z)); modelMesh->AddVertex(vertex.x, vertex.y, vertex.z, normal.x, normal.y, normal.z, u, v, tangent.x, tangent.y, tangent.z); } /*READ FACES INTO MODEL MESH*/ size_t numFaces = mesh->mNumFaces; for(size_t i = 0; i < numFaces; i++) { aiFace face = mesh->mFaces[i]; modelMesh->AddFace(face.mIndices[0], face.mIndices[1], face.mIndices[2]); } /*INITIALIZE MESH*/ modelMesh->Init(); /*ADD MODELMESH TO COLLECTION*/ m_meshes.push_back(modelMesh); }