unsigned int WavefrontObj::loadObj(const char *fname, bool textured) // load a wavefront obj returns number of triangles that were loaded. Data is persists until the class is destructed. { unsigned int ret = 0; delete []mVertices; mVertices = 0; delete []mIndices; mIndices = 0; mVertexCount = 0; mTriCount = 0; BuildMesh bm; OBJ obj; obj.LoadMesh(fname, &bm, textured); if (bm.GetNumVertices()) { mVertexCount = bm.GetNumVertices()/3; mVertices = new float[mVertexCount*3]; memcpy(mVertices, bm.GetVertices(), sizeof(float)*mVertexCount*3); if (textured) { mTexCoords = new float[mVertexCount * 2]; memcpy(mTexCoords, bm.GetTexCoords(), sizeof(float) * mVertexCount * 2); } mTriCount = bm.GetNumIndices()/3; mIndices = new int[mTriCount*3]; memcpy(mIndices, bm.GetIndices(), sizeof(int)*mTriCount*3); ret = mTriCount; } return ret; }
NxU32 WavefrontObj::loadObj(const char *fname, bool textured) // load a wavefront obj returns number of triangles that were loaded. Data is persists until the class is destructed. { NxU32 ret = 0; delete mVertices; mVertices = 0; delete mIndices; mIndices = 0; mVertexCount = 0; mTriCount = 0; BuildMesh bm; OBJ obj; obj.LoadMesh(fname,&bm, textured); const FloatVector &vlist = bm.GetVertices(); const IntVector &indices = bm.GetIndices(); if ( vlist.size() ) { mVertexCount = (NxI32)vlist.size()/3; mVertices = new NxF32[mVertexCount*3]; memcpy( mVertices, &vlist[0], sizeof(NxF32)*mVertexCount*3 ); if (textured) { mTexCoords = new NxF32[mVertexCount * 2]; const FloatVector& tList = bm.GetTexCoords(); memcpy( mTexCoords, &tList[0], sizeof(NxF32) * mVertexCount * 2); } mTriCount = (NxI32)indices.size()/3; mIndices = new NxU32[mTriCount*3*sizeof(NxU32)]; memcpy(mIndices, &indices[0], sizeof(NxU32)*mTriCount*3); ret = mTriCount; } return ret; }
unsigned int WavefrontObj::loadObj(const char *fname) // load a wavefront obj returns number of triangles that were loaded. Data is persists until the class is destructed. { unsigned int ret = 0; delete [] mVertices; mVertices = 0; delete [] mIndices; mIndices = 0; mVertexCount = 0; mTriCount = 0; BuildMesh bm; OBJ obj; obj.LoadMesh(fname,&bm); const FloatVector &vlist = bm.GetVertices(); const IntVector &indices = bm.GetIndices(); if ( vlist.size() ) { mVertexCount = vlist.size()/3; mVertices = new float[mVertexCount*3]; memcpy( mVertices, &vlist[0], sizeof(float)*mVertexCount*3 ); mTriCount = indices.size()/3; mIndices = new int[mTriCount*3*sizeof(int)]; memcpy(mIndices, &indices[0], sizeof(int)*mTriCount*3); ret = mTriCount; } return ret; }