|
@@ -1,101 +1,17 @@
|
|
|
#include "model.h"
|
|
#include "model.h"
|
|
|
-#include <stdio.h>
|
|
|
|
|
-#include <iostream>
|
|
|
|
|
-#include <fstream>
|
|
|
|
|
-#include <sstream>
|
|
|
|
|
#include "vector3.h"
|
|
#include "vector3.h"
|
|
|
-#include "matrix.h"
|
|
|
|
|
#include <limits>
|
|
#include <limits>
|
|
|
|
|
|
|
|
Model::Model(std::string path){
|
|
Model::Model(std::string path){
|
|
|
- buildMesh(path);
|
|
|
|
|
|
|
+ OBJ::buildMeshFromFile(mMesh, path);
|
|
|
buildBoundaryBox();
|
|
buildBoundaryBox();
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Mesh * Model::getMesh(){
|
|
Mesh * Model::getMesh(){
|
|
|
return &mMesh;
|
|
return &mMesh;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void Model::describeMesh(){
|
|
|
|
|
- int meshSize = mMesh.numVertices;
|
|
|
|
|
- for(int i = 0; i < meshSize; ++i){
|
|
|
|
|
- Vector3 vertex = mMesh.vertices[i];
|
|
|
|
|
- printf("Vertex %2.1d: %f, %f, %f \n",i,vertex.x, vertex.y, vertex.z);
|
|
|
|
|
- }
|
|
|
|
|
- printf("Meshsize is: %d \n", meshSize);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-void Model::buildMesh(std::string path){
|
|
|
|
|
- printf("Loading models...\n");
|
|
|
|
|
-
|
|
|
|
|
- //Open file containing vertex data
|
|
|
|
|
- std::ifstream file;
|
|
|
|
|
- file.open(path.c_str());
|
|
|
|
|
-
|
|
|
|
|
- //Get vertices into mesh
|
|
|
|
|
- loadVertices(file);
|
|
|
|
|
-
|
|
|
|
|
- //Get faces
|
|
|
|
|
- loadFaces(file);
|
|
|
|
|
-
|
|
|
|
|
- //Get normals
|
|
|
|
|
- loadNormals(file);
|
|
|
|
|
-
|
|
|
|
|
- //Close file after reading
|
|
|
|
|
- file.close();
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-void Model::loadFaces(std::ifstream &file){
|
|
|
|
|
- std::string line, f, x ,y ,z;
|
|
|
|
|
- while(!file.eof()){
|
|
|
|
|
-
|
|
|
|
|
- std::getline(file,line);
|
|
|
|
|
- std::istringstream iss(line);
|
|
|
|
|
- iss >> f;
|
|
|
|
|
- if(f == "f"){
|
|
|
|
|
- iss >> x >> y >> z;
|
|
|
|
|
- Vector3 face(std::stof(x)-1,std::stof(y)-1,std::stof(z)-1);
|
|
|
|
|
- mMesh.faces.push_back(face);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- mMesh.numFaces = mMesh.faces.size();
|
|
|
|
|
- file.clear();
|
|
|
|
|
- file.seekg(0, file.beg);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-void Model::loadVertices(std::ifstream &file){
|
|
|
|
|
- std::string line, v, x ,y ,z;
|
|
|
|
|
- while(!file.eof()){
|
|
|
|
|
- std::getline(file,line);
|
|
|
|
|
- std::istringstream iss(line);
|
|
|
|
|
- iss >> v;
|
|
|
|
|
- if(v == "v"){
|
|
|
|
|
- iss >> x >> y >> z;
|
|
|
|
|
- Vector3 vertex(std::stof(x),std::stof(y),std::stof(z));
|
|
|
|
|
- mMesh.vertices.push_back(vertex);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- mMesh.numVertices = mMesh.vertices.size();
|
|
|
|
|
- file.clear();
|
|
|
|
|
- file.seekg(0, file.beg);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-void Model::loadNormals(std::ifstream &file){
|
|
|
|
|
- std::string line, v, x ,y ,z;
|
|
|
|
|
- while(!file.eof()){
|
|
|
|
|
- std::getline(file,line);
|
|
|
|
|
- std::istringstream iss(line);
|
|
|
|
|
- iss >> v;
|
|
|
|
|
- if(v == "vn"){
|
|
|
|
|
- iss >> x >> y >> z;
|
|
|
|
|
- Vector3 normal(std::stof(x),std::stof(y),std::stof(z));
|
|
|
|
|
- mMesh.normals.push_back(normal);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- file.clear();
|
|
|
|
|
- file.seekg(0, file.beg);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
void Model::initPosition(TransformParameters initVals){
|
|
void Model::initPosition(TransformParameters initVals){
|
|
|
Matrix4 modelMatrix = Matrix4::transformMatrix(initVals);
|
|
Matrix4 modelMatrix = Matrix4::transformMatrix(initVals);
|
|
|
int size = mMesh.numVertices;
|
|
int size = mMesh.numVertices;
|