From: Martin R. <ma...@MP...> - 2004-10-12 11:47:02
|
Hi Andreas, I have put together a version of Load3DS() which uses the new bifstream class. Does this look OK? Cheers, Martin /* Function to load a triangle mesh from a 3DS file based on code of Damiano Vitulli <in...@sp...> */ bool TRIANGLE_MESH::Load3DS (const char *filename) { bifstream file (filename,file_is_lsb); if (!file) return false; while (!file.eof()) { uint2 chunk_id,qty; uint4 chunk_length; file >> chunk_id; file >> chunk_length; cout << "Chunk ID: " << chunk_id << " Length:" << chunk_length << endl; switch (chunk_id) { // TRI_VERTEXL: Vertices list // Chunk Length: 1 x uint2 (number of vertices) // + 3 x float4 (vertex coordinates) x (number of vertices) // + sub chunks case 0x4110: file >> qty; cout << "Vertices list: " << qty << " vertices" << endl; for (int i=0; i<qty; ++i) { float4 x, y, z; file >> x >> y >> z; AddVertex (VECTOR (x, y, z)); } break; // TRI_FACEL1: Polygons (faces) list // Chunk ID: 4120 (hex) // Chunk Length: 1 x uint2 (number of polygons) // + 3 x uint2 (polygon points) x (number of polygons) // + sub chunks case 0x4120: file >> qty; cout << "Faces list: " << qty << " faces" << endl; for (int i=0; i<qty; ++i) { uint2 a, b, c, face_flags; file >> a >> b >> c >> face_flags; AddTriangle (a, b, c); } break; // EDIT_OBJECT: Object block, info for each object case 0x4000: cout << "Object block: skipping name" << endl; { byte c; do { file >> c; } while (c!=0); } break; case 0x4d4d: // main chunk case 0x3d3d: // editor chunk case 0x4100: // triangle mesh chunk cout << " ...superchunk" << endl; break; // skip all other chunks default: cout << " ...skipping" << endl; file.seekg(chunk_length-6,ios::cur); } } return true; } |