----------------------------------------------------- //
| 585 | |
| 586 | // ----------------------------------------------------- // |
| 587 | char *bFile::readStruct(char *head, bChunkInd &dataChunk) |
| 588 | { |
| 589 | bool ignoreEndianFlag = false; |
| 590 | |
| 591 | if (mFlags & FD_ENDIAN_SWAP) |
| 592 | swap(head, dataChunk, ignoreEndianFlag); |
| 593 | |
| 594 | if (!mFileDNA->flagEqual(dataChunk.dna_nr)) |
| 595 | { |
| 596 | // Ouch! need to rebuild the struct |
| 597 | short *oldStruct, *curStruct; |
| 598 | char *oldType, *newType; |
| 599 | int oldLen, curLen, reverseOld; |
| 600 | |
| 601 | oldStruct = mFileDNA->getStruct(dataChunk.dna_nr); |
| 602 | oldType = mFileDNA->getType(oldStruct[0]); |
| 603 | |
| 604 | oldLen = mFileDNA->getLength(oldStruct[0]); |
| 605 | |
| 606 | if ((mFlags & FD_BROKEN_DNA) != 0) |
| 607 | { |
| 608 | if ((strcmp(oldType, "b3QuantizedBvhNodeData") == 0) && oldLen == 20) |
| 609 | { |
| 610 | return 0; |
| 611 | } |
| 612 | if ((strcmp(oldType, "b3ShortIntIndexData") == 0)) |
| 613 | { |
| 614 | int allocLen = 2; |
| 615 | char *dataAlloc = new char[(dataChunk.nr * allocLen) + 1]; |
| 616 | memset(dataAlloc, 0, (dataChunk.nr * allocLen) + 1); |
| 617 | short *dest = (short *)dataAlloc; |
| 618 | const short *src = (short *)head; |
| 619 | for (int i = 0; i < dataChunk.nr; i++) |
| 620 | { |
| 621 | dest[i] = src[i]; |
| 622 | if (mFlags & FD_ENDIAN_SWAP) |
| 623 | { |
| 624 | B3_SWITCH_SHORT(dest[i]); |
| 625 | } |
| 626 | } |
| 627 | addDataBlock(dataAlloc); |
| 628 | return dataAlloc; |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | ///don't try to convert Link block data, just memcpy it. Other data can be converted. |
| 633 | if (strcmp("Link", oldType) != 0) |
| 634 | { |
| 635 | reverseOld = mMemoryDNA->getReverseType(oldType); |
| 636 | |
| 637 | if ((reverseOld != -1)) |
| 638 | { |
| 639 | // make sure it's here |
| 640 | //assert(reverseOld!= -1 && "getReverseType() returned -1, struct required!"); |
| 641 | |
| 642 | // |
| 643 | curStruct = mMemoryDNA->getStruct(reverseOld); |
| 644 | newType = mMemoryDNA->getType(curStruct[0]); |