------------------------------------------------------------------------------------------------ Load file - master function
| 1444 | // ------------------------------------------------------------------------------------------------ |
| 1445 | // Load file - master function |
| 1446 | void LWOImporter::LoadLWO2File() { |
| 1447 | bool skip = false; |
| 1448 | |
| 1449 | LE_NCONST uint8_t *const end = mFileBuffer + fileSize; |
| 1450 | unsigned int iUnnamed = 0; |
| 1451 | |
| 1452 | while (true) { |
| 1453 | if (mFileBuffer + sizeof(IFF::ChunkHeader) > end) break; |
| 1454 | |
| 1455 | IFF::ChunkHeader head = IFF::LoadChunk(mFileBuffer); |
| 1456 | |
| 1457 | int bufOffset = 0; |
| 1458 | if( head.type == AI_IFF_FOURCC_FORM ) { // not chunk, it's a form |
| 1459 | mFileBuffer -= 8; |
| 1460 | head = IFF::LoadForm(mFileBuffer); |
| 1461 | bufOffset = 4; |
| 1462 | } |
| 1463 | |
| 1464 | if (mFileBuffer + head.length > end) { |
| 1465 | throw DeadlyImportError("LWO2: Chunk length points behind the file"); |
| 1466 | } |
| 1467 | uint8_t *const next = mFileBuffer + head.length; |
| 1468 | mFileBuffer += bufOffset; |
| 1469 | if (!head.length) { |
| 1470 | mFileBuffer = next; |
| 1471 | continue; |
| 1472 | } |
| 1473 | |
| 1474 | switch (head.type) { |
| 1475 | // new layer |
| 1476 | case AI_LWO_LAYR: { |
| 1477 | // add a new layer to the list .... |
| 1478 | mLayers->push_back(LWO::Layer()); |
| 1479 | LWO::Layer &layer = mLayers->back(); |
| 1480 | mCurLayer = &layer; |
| 1481 | |
| 1482 | AI_LWO_VALIDATE_CHUNK_LENGTH(head.length, LAYR, 16); |
| 1483 | |
| 1484 | // layer index. |
| 1485 | layer.mIndex = GetU2(); |
| 1486 | |
| 1487 | // Continue loading this layer or ignore it? Check the layer index property |
| 1488 | if (UINT_MAX != configLayerIndex && (configLayerIndex - 1) != layer.mIndex) { |
| 1489 | skip = true; |
| 1490 | } else |
| 1491 | skip = false; |
| 1492 | |
| 1493 | // pivot point |
| 1494 | mFileBuffer += 2; /* unknown */ |
| 1495 | mCurLayer->mPivot.x = GetF4(); |
| 1496 | mCurLayer->mPivot.y = GetF4(); |
| 1497 | mCurLayer->mPivot.z = GetF4(); |
| 1498 | GetS0(layer.mName, head.length - 16); |
| 1499 | |
| 1500 | // if the name is empty, generate a default name |
| 1501 | if (layer.mName.empty()) { |
| 1502 | char buffer[128]; // should be sufficiently large |
| 1503 | ::ai_snprintf(buffer, 128, "Layer_%i", iUnnamed++); |
nothing calls this directly
no test coverage detected