Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ProcessMesh Function
- -----------------------------
- ModelMaintenance ModelObject::ProcessMesh(aiMesh* Mesh, const aiScene* Scene) {
- // data to fill
- std::vector<Vertex> vertices;
- std::vector<unsigned int> indices;
- std::vector<Texture> textures;
- //std::string Name = Mesh->mName.C_Str();
- // walk through each of the mesh's vertices
- for(unsigned int i = 0; i < Mesh->mNumVertices; i++)
- {
- Vertex vertex;
- SetVertexBoneDataToDefault(vertex);
- vertex.Position = UniversalHelpers::GetGLMvec(Mesh->mVertices[i]);
- vertex.Normal = UniversalHelpers::GetGLMvec(Mesh->mNormals[i]);
- glm::vec3 vector; // we declare a placeholder vector since assimp uses its own vector class that doesn't directly convert to glm's vec3 class so we transfer the data to this placeholder glm::vec3 first.
- // positions
- vector.x = Mesh->mVertices[i].x;
- vector.y = Mesh->mVertices[i].y;
- vector.z = Mesh->mVertices[i].z;
- vertex.Position = vector;
- // normals
- if (Mesh->HasNormals())
- {
- vector.x = Mesh->mNormals[i].x;
- vector.y = Mesh->mNormals[i].y;
- vector.z = Mesh->mNormals[i].z;
- vertex.Normal = vector;
- }
- // texture coordinates
- if(Mesh->mTextureCoords[0]) // does the mesh contain texture coordinates?
- {
- glm::vec2 vec;
- // a vertex can contain up to 8 different texture coordinates. We thus make the assumption that we won't
- // use models where a vertex can have multiple texture coordinates so we always take the first set (0).
- vec.x = Mesh->mTextureCoords[0][i].x;
- vec.y = Mesh->mTextureCoords[0][i].y;
- vertex.TexCoords = vec;
- // tangent
- //vector.x = Mesh->mTangents[i].x;
- //vector.y = Mesh->mTangents[i].y;
- //vector.z = Mesh->mTangents[i].z;
- //vertex.Tangent = vector;
- //// bitangent
- //vector.x = Mesh->mBitangents[i].x;
- //vector.y = Mesh->mBitangents[i].y;
- //vector.z = Mesh->mBitangents[i].z;
- //vertex.Bitangents = vector;
- }
- else {
- vertex.TexCoords = glm::vec2(0.0f, 0.0f);
- }
- vertices.push_back(vertex);
- }
- ExtractBoneWeightForVertices(vertices, Mesh, Scene);
- // now wak through each of the mesh's faces (a face is a mesh its triangle) and retrieve the corresponding vertex indices.
- for(unsigned int i = 0; i < Mesh->mNumFaces; i++)
- {
- aiFace face = Mesh->mFaces[i];
- //if(Name == "Plane.004") {
- if (face.mNumIndices == 3) {
- indices.push_back(face.mIndices[0]);
- indices.push_back(face.mIndices[1]);
- indices.push_back(face.mIndices[2]);
- //for all the indices in each face, add each indice
- } else {
- indices.push_back(i);
- }
- //}
- // retrieve all indices of the face and store them in the indices vector
- }
- // process materials
- aiMaterial* material = Scene->mMaterials[Mesh->mMaterialIndex];
- // we assume a convention for sampler names in the shaders. Each diffuse texture should be named
- // as 'texture_diffuseN' where N is a sequential number ranging from 1 to MAX_SAMPLER_NUMBER.
- // Same applies to other texture as the following list summarizes:
- // diffuse: texture_diffuseN
- // specular: texture_specularN
- // normal: texture_normal
- // 1. diffuse maps
- std::vector<Texture> diffuseMaps = loadMaterialTextures(material, aiTextureType_DIFFUSE, "texture_diffuse");
- textures.insert(textures.end(), diffuseMaps.begin(), diffuseMaps.end());
- // 2. specular maps
- std::vector<Texture> specularMaps = loadMaterialTextures(material, aiTextureType_SPECULAR, "texture_specular");
- textures.insert(textures.end(), specularMaps.begin(), specularMaps.end());
- // 3. normal maps
- std::vector<Texture> normalMaps = loadMaterialTextures(material, aiTextureType_HEIGHT, "texture_normal");
- textures.insert(textures.end(), normalMaps.begin(), normalMaps.end());
- // 4. height maps
- std::vector<Texture> heightMaps = loadMaterialTextures(material, aiTextureType_AMBIENT, "texture_height");
- textures.insert(textures.end(), heightMaps.begin(), heightMaps.end());
- // return a mesh object created from the extracted mesh data
- return ModelMaintenance(vertices, textures, indices);
- }
- worlds update method
- -----------------------------------
- void World::Update() {
- player.Update(Programs);
- DrawObjects();
- for(int i = 0; i < 100; i++) { //Blender model faces for my orientation goes from bootom left, bottom right, top right, bottom left, top right, top left
- std::cout << "Vertex " << i << "(" << entityManager.Enviroment.Meshes[0].Verts[entityManager.Enviroment.Meshes[0].Indicies[i]].Position.x << "," << entityManager.Enviroment.Meshes[0].Verts[entityManager.Enviroment.Meshes[0].Indicies[i]].Position.y << ", " << entityManager.Enviroment.Meshes[0].Verts[entityManager.Enviroment.Meshes[0].Indicies[i]].Position.z << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment