Changeset 2764 for GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp
- Timestamp:
- 06/17/08 03:47:02 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp
r2763 r2764 18 18 SceneEntity *BinaryLoader::LoadSceneEntity(ifstream &str) 19 19 { 20 Geometry *geom = LoadGeometry(str); 21 Material *mat = LoadMaterial(str); 22 Matrix4x4 *trafo = NULL;//IdentityMatrix(); 20 // shape 21 int shapeId; 22 str.read(reinterpret_cast<char *>(&shapeId), sizeof(int)); 23 24 Geometry *geom = mGeometryTable[shapeId]; 25 Material *mat = mMaterialTable[shapeId]; 26 27 28 bool hasTrafo; 29 str.read(reinterpret_cast<char *>(&hasTrafo), sizeof(bool)); 30 31 Matrix4x4 *trafo; 32 33 if (!hasTrafo) 34 { 35 trafo = NULL; 36 } 37 else 38 { 39 trafo = new Matrix4x4(); 40 //*trafo = IdentityMatrix(); 41 str.read(reinterpret_cast<char *>(trafo->x), sizeof(Matrix4x4)); 42 //str.read(reinterpret_cast<char *>(trafo), sizeof(Matrix4x4)); 43 //cout << "m:\n" << *trafo<<endl; 44 } 23 45 24 46 SceneEntity *sceneGeom = new SceneEntity(geom, mat, trafo); … … 37 59 // texture 38 60 int texnameSize; 39 int id; 40 41 str.read(reinterpret_cast<char *>(&id), sizeof(int)); 61 62 //str.read(reinterpret_cast<char *>(&id), sizeof(int)); 42 63 str.read(reinterpret_cast<char *>(&texnameSize), sizeof(int)); 43 64 … … 48 69 Texture *tex = new Texture(texname); 49 70 50 mTextureTable[id] = tex; 51 } 71 mTextureTable[i] = tex; 72 } 73 74 cout << "loaded " << mTextureTable.size() << " textures" << endl; 75 } 76 77 78 void BinaryLoader::LoadShapes(ifstream &str) 79 { 80 int numShapes; 81 str.read(reinterpret_cast<char *>(&numShapes), sizeof(int)); 82 83 for (int i = 0; i < numShapes; ++ i) 84 { 85 Geometry *geom = LoadGeometry(str); 86 Material *mat = LoadMaterial(str); 87 88 mGeometryTable[i] = geom; 89 mMaterialTable[i] = mat; 90 } 91 92 cout << "loaded " << mGeometryTable.size() << " shapes" << endl; 52 93 } 53 94 … … 61 102 // texture 62 103 int texId; 63 64 104 str.read(reinterpret_cast<char *>(&texId), sizeof(int)); 65 //cout << "texid: " << texId << endl;66 105 67 106 if (texId >= 0) 68 {69 107 mat->SetTexture(mTextureTable[texId]); 70 }108 71 109 72 110 // material … … 99 137 100 138 return app;*/ 101 102 139 return mat; 103 140 } … … 156 193 157 194 158 bool BinaryLoader::Load(const std::string &filename, SceneEntityContainer &geometry) 195 void BinaryLoader::LoadSceneEntities(ifstream &str, SceneEntityContainer &entities) 196 { 197 int entityCount; 198 str.read(reinterpret_cast<char *>(&entityCount), sizeof(int)); 199 200 entities.resize(entityCount); 201 202 for (int i = 0; i < entityCount; ++ i) 203 { 204 SceneEntity *ent = LoadSceneEntity(str); 205 ent->id = i; 206 entities[i] = ent; 207 } 208 209 cout << "loaded " << entityCount << " scene entities" << endl; 210 } 211 212 213 bool BinaryLoader::Load(const std::string &filename, SceneEntityContainer &entities) 159 214 { 160 215 //clear_textures(); // clear the texture table … … 166 221 return false; 167 222 223 cout << "loading textures" << endl; 224 168 225 // load the texture table 169 226 LoadTextures(istr); 170 227 171 // #shapes 172 int shapeCount; 173 istr.read(reinterpret_cast<char *>(&shapeCount), sizeof(int)); 174 175 geometry.resize(shapeCount); 176 177 for (size_t i = 0; i < geometry.size(); ++ i) 178 geometry[i] = NULL; 179 180 181 int progress = 0; 182 183 for (int i = 0; i < shapeCount; ++ i) 184 { 185 //int id;istr.read(reinterpret_cast<char *>(&id), sizeof(int)); 186 SceneEntity *ent = LoadSceneEntity(istr); 187 ent->id = i; 188 189 geometry[i] = ent; 190 191 int p = (i + 1) * 100 / shapeCount; 192 193 if (p >= progress) 194 { 195 cout << "% loaded: " << p << endl; 196 progress += 10; 197 } 198 } 199 200 for (size_t i = 0; i < geometry.size(); ++ i) 201 { 202 if (!geometry[i]) 203 Debug << "error: index " << i << " missing" << endl; 204 } 205 228 cout << "loading shapes (geometry + materials)" << endl; 229 230 // load the shapees 231 LoadShapes(istr); 232 233 cout << "loading scene entites" << endl; 234 LoadSceneEntities(istr, entities); 235 206 236 cout << "bin loading finished" << endl; 207 237
Note: See TracChangeset
for help on using the changeset viewer.