gwMd2::gwMd2(const char *filePath){ FILE *fp = fopen(filePath,"r"); assert(fp); header = loadHeader(fp); assert(header); skin = loadSkins(fp); assert(skin); texCoord = loadTexCoords(fp); assert(texCoord); triangle = loadTriangles(fp); assert(triangle); frame = loadFrames(fp); assert(frame); glcmds = loadGlCommands(fp); assert(glcmds); tex = new gwTexture(skin[textureId].name); assert(tex); fclose(fp); }
bool SpriteMeshLoader::loadSpriteMesh( string filename, string meshID ){ //check if meshID already exists! if (renderer->vboList[meshID]){ renderer->vboList.erase(meshID); } // XML File Open cout << "Loading file..." << filename <<endl; TiXmlDocument doc( filename ); if (!doc.LoadFile()) return false; TiXmlHandle hDoc(&doc); TiXmlElement * element; TiXmlHandle hRoot(0); //*********************************************************************** //Skip over first Element //*********************************************************************** element=hDoc.FirstChildElement().Element(); // should always have a valid root but handle gracefully if it doesn't if (!element) return false; // save this for later hRoot=TiXmlHandle(element); //end XML file open; //setup new MeshData MeshData* myMesh=new MeshData; myMesh->bIsSkeletal=false; myMesh->bIsHead=false; myMesh->bVertexColor=true; myMesh->boneCount=0; myMesh->texCoordPerVertexCount=3; myMesh->verticesPerShapeCount=4; myMesh->vertexInterpretation=GL_POINTS; myMesh->drawType=DRAW_VBOMESH; renderer->vboList[meshID]=myMesh; loadVertices(meshID, hRoot.FirstChild("vertices").Element()); loadNormals(meshID, hRoot.FirstChild("normals").Element()); loadTexCoords(meshID, hRoot.FirstChild("texCoords").Element()); loadColors(meshID, hRoot.FirstChild("colors").Element()); loadSecondaryColors(meshID, hRoot.FirstChild("secondaryColors").Element()); loadBoneReferences(meshID, hRoot.FirstChild("boneReferences").Element()); loadVertexWeights(meshID, hRoot.FirstChild("vertexWeights").Element()); cout << "loading bones..." << endl; loadBones(meshID, hRoot.FirstChild("bone").Element()); //fill vertex data for editing if (!renderer->vboList[meshID]->vData.empty()) renderer->vboList[meshID]->vData.clear(); for (int i=0;i<vertexCount;i++){ vertexData myVData; myVData.location=vertices[i]; myVData.normal=normals[i]; myVData.color=colors[i]; myVData.secondaryColor=secondaryColors[i]; myVData.birth=0.0f; myVData.texCoord=texCoords[i]; myVData.vertexWeights=vertexWeights[i]; myVData.boneReferences=boneReference[i]; renderer->vboList[meshID]->vData.push_back(myVData); } cout << "before creating vbos..." << endl; createVBOs(meshID); cout << "after creating vbos..." << endl; //now free our resources: delete(vertices); delete(normals); delete(texCoords); delete(colors); delete(secondaryColors); delete(vertexWeights); delete(boneReference); doc.Clear(); cout << "finished loading SpriteMesh" << endl; return true; }
ObjLoader::ObjLoader(std::string filepath) { std::ifstream file; file.open(filepath.c_str(), std::ios::in); for(std::string line; std::getline(file, line);) { std::stringstream ss(line); std::string identifier; ss >> identifier; if(identifier.compare("#") ==0) { std::cout << "Found comment" << std::endl; } else if(identifier.compare("v") == 0) { std::vector<float> vec3 = loadNumbers(ss); vertices.push_back(Vertex(vec3[0], vec3[1], vec3[2])); } else if(identifier.compare("vn") == 0) { std::vector<float> vec3 = loadNumbers(ss); normals.push_back(triplet<float, float, float>(vec3[0], vec3[1], vec3[2])); } else if(identifier.compare("vt") == 0) { //std::cout << "tex coord found" << std::endl; std::pair<float, float> texCoord = loadTexCoords(ss); texCoords.push_back(texCoord); } else if(identifier.compare("f") == 0) { std::string face; ss >> face; Face newFace; while(!ss.fail()) { std::vector<std::pair<int, bool> > vec3 = loadFace(face); newFace.addVertex(vec3[0].first); if(vec3[1].second) { newFace.addTexCoord(vec3[1].first); } if(vec3[2].second) { newFace.addNormal(vec3[2].first); } ss >> face; } for(int i = 0; i < 3; i ++) { int vertexIdx = newFace.getVertex(i); Vertex vert = vertices[vertexIdx]; triplet<float, float, float> normal = normals[newFace.getNormal(i)]; vert.addNormal(normal.first, normal.second, normal.third); vertices[vertexIdx] = vert; } faces.push_back(newFace); } }