Opens and reads a 3dsmax file for our rooms. Allocs a room to carry the data Returns the index into the Rooms[] array if successful Return -1 on fail
| 189 | // Returns the index into the Rooms[] array if successful |
| 190 | // Return -1 on fail |
| 191 | int Read3DSMaxFile(char *filename) { |
| 192 | uint16_t id; |
| 193 | int len; |
| 194 | CFILE *fp; |
| 195 | int i; |
| 196 | |
| 197 | fp = (CFILE *)cfopen(filename, "rb"); |
| 198 | if (!fp) { |
| 199 | mprintf(0, "Couldn't open 3dsmax file %s!\n", filename); |
| 200 | return -1; |
| 201 | } |
| 202 | |
| 203 | Nest_level = 0; |
| 204 | |
| 205 | // Alloc space for reading stuff in |
| 206 | Reading_room.faces = (reading_face *)mem_malloc(MAX_READING_ROOM_FACES * sizeof(reading_face)); |
| 207 | Reading_room.verts = (vector *)mem_malloc(MAX_VERTS_PER_ROOM * sizeof(vector)); |
| 208 | |
| 209 | Reading_room.num_faces = 0; |
| 210 | Reading_room.num_verts = 0; |
| 211 | |
| 212 | id = cf_ReadShort(fp); |
| 213 | len = cf_ReadInt(fp); |
| 214 | |
| 215 | Num_materials = 0; |
| 216 | |
| 217 | if (id == ID_3DS_MODIFIED) |
| 218 | Parse3DSMaxChunk(fp, len - 6); |
| 219 | else { |
| 220 | mprintf(0, "This file is not a 3ds max file!\n"); |
| 221 | cfclose(fp); |
| 222 | return -1; |
| 223 | } |
| 224 | cfclose(fp); |
| 225 | |
| 226 | if ((Reading_room.num_verts == 0) || (Reading_room.num_faces == 0)) { |
| 227 | OutrageMessageBox("The imported room has %d verts and %d faces. Aborting import.", Reading_room.num_faces, |
| 228 | Reading_room.num_faces); |
| 229 | return -1; |
| 230 | } |
| 231 | |
| 232 | if (Reading_room.num_verts > MAX_VERTS_PER_ROOM) { |
| 233 | OutrageMessageBox("The imported room has %d verts. The limit is %d. Aborting import.", Reading_room.num_verts, |
| 234 | MAX_VERTS_PER_ROOM); |
| 235 | return -1; |
| 236 | } |
| 237 | |
| 238 | if (Reading_room.num_faces > MAX_READING_ROOM_FACES) { |
| 239 | OutrageMessageBox("The imported room has %d faces. The limit is %d. Aborting import.", Reading_room.num_faces, |
| 240 | MAX_READING_ROOM_FACES); |
| 241 | return -1; |
| 242 | } |
| 243 | |
| 244 | if (Reading_room.num_faces > MAX_FACES_PER_ROOM) { |
| 245 | OutrageMessageBox("The imported room has %d faces. The limit after combining faces is %d.\n\nIf there are too " |
| 246 | "many faces after combining, this room will not be imported.", |
| 247 | Reading_room.num_faces, MAX_FACES_PER_ROOM); |
| 248 | } |
no test coverage detected