Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Model {
- public:
- float* vertexArray;
- float* normalArray;
- float* uvArray;
- int numVerts;
- GLuint ModelTexture;
- void Load(string filename, string texture) {
- ModelTexture = LoadTexture(texture);
- Assimp::Importer importer;
- const aiScene* scene = importer.ReadFile(filename, aiProcessPreset_TargetRealtime_Fast);
- aiMesh* mesh = scene->mMeshes[0];
- numVerts = mesh->mNumFaces * 3;
- vertexArray = new float[mesh->mNumFaces * 3 * 3];
- normalArray = new float[mesh->mNumFaces * 3 * 3];
- uvArray = new float[mesh->mNumFaces * 3 * 2];
- for (unsigned int i = 0; i < mesh->mNumFaces; i++)
- {
- const aiFace& face = mesh->mFaces[i];
- for (int j = 0; j < 3; j++)
- {
- aiVector3D uv = mesh->mTextureCoords[0][face.mIndices[j]];
- memcpy(uvArray, &uv, sizeof(float) * 2);
- uvArray += 2;
- aiVector3D normal = mesh->mNormals[face.mIndices[j]];
- memcpy(normalArray, &normal, sizeof(float) * 3);
- normalArray += 3;
- aiVector3D pos = mesh->mVertices[face.mIndices[j]];
- memcpy(vertexArray, &pos, sizeof(float) * 3);
- vertexArray += 3;
- }
- }
- uvArray -= mesh->mNumFaces * 3 * 2;
- normalArray -= mesh->mNumFaces * 3 * 3;
- vertexArray -= mesh->mNumFaces * 3 * 3;
- }
- void Draw() {
- glPushMatrix();
- glBindTexture(GL_TEXTURE_2D, ModelTexture);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_NORMAL_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, vertexArray);
- glNormalPointer(GL_FLOAT, 0, normalArray);
- glTexCoordPointer(2, GL_FLOAT, 0, uvArray);
- glDrawArrays(GL_TRIANGLES, 0, numVerts);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glPopMatrix();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment