------------------------------------------------------------------------------------------------ Constructor. Creates a data structure out of the XFile given in the memory block.
| 80 | // ------------------------------------------------------------------------------------------------ |
| 81 | // Constructor. Creates a data structure out of the XFile given in the memory block. |
| 82 | XFileParser::XFileParser(const std::vector<char> &pBuffer) : |
| 83 | mMajorVersion(0), mMinorVersion(0), mIsBinaryFormat(false), mBinaryNumCount(0), mP(nullptr), mEnd(nullptr), mLineNumber(0), mScene(nullptr) { |
| 84 | // vector to store uncompressed file for INFLATE'd X files |
| 85 | std::vector<char> uncompressed; |
| 86 | |
| 87 | // set up memory pointers |
| 88 | mP = &pBuffer.front(); |
| 89 | mEnd = mP + pBuffer.size() - 1; |
| 90 | |
| 91 | // check header |
| 92 | if (0 != strncmp(mP, "xof ", 4)) { |
| 93 | throw DeadlyImportError("Header mismatch, file is not an XFile."); |
| 94 | } |
| 95 | |
| 96 | // read version. It comes in a four byte format such as "0302" |
| 97 | mMajorVersion = (unsigned int)(mP[4] - 48) * 10 + (unsigned int)(mP[5] - 48); |
| 98 | mMinorVersion = (unsigned int)(mP[6] - 48) * 10 + (unsigned int)(mP[7] - 48); |
| 99 | |
| 100 | bool compressed = false; |
| 101 | |
| 102 | // txt - pure ASCII text format |
| 103 | if (strncmp(mP + 8, "txt ", 4) == 0) |
| 104 | mIsBinaryFormat = false; |
| 105 | |
| 106 | // bin - Binary format |
| 107 | else if (strncmp(mP + 8, "bin ", 4) == 0) |
| 108 | mIsBinaryFormat = true; |
| 109 | |
| 110 | // tzip - Inflate compressed text format |
| 111 | else if (strncmp(mP + 8, "tzip", 4) == 0) { |
| 112 | mIsBinaryFormat = false; |
| 113 | compressed = true; |
| 114 | } |
| 115 | // bzip - Inflate compressed binary format |
| 116 | else if (strncmp(mP + 8, "bzip", 4) == 0) { |
| 117 | mIsBinaryFormat = true; |
| 118 | compressed = true; |
| 119 | } else |
| 120 | ThrowException("Unsupported x-file format '", mP[8], mP[9], mP[10], mP[11], "'"); |
| 121 | |
| 122 | // float size |
| 123 | mBinaryFloatSize = (unsigned int)(mP[12] - 48) * 1000 + (unsigned int)(mP[13] - 48) * 100 + (unsigned int)(mP[14] - 48) * 10 + (unsigned int)(mP[15] - 48); |
| 124 | |
| 125 | if (mBinaryFloatSize != 32 && mBinaryFloatSize != 64) |
| 126 | ThrowException("Unknown float size ", mBinaryFloatSize, " specified in x-file header."); |
| 127 | |
| 128 | // The x format specifies size in bits, but we work in bytes |
| 129 | mBinaryFloatSize /= 8; |
| 130 | |
| 131 | mP += 16; |
| 132 | |
| 133 | // If this is a compressed X file, apply the inflate algorithm to it |
| 134 | if (compressed) { |
| 135 | #ifdef ASSIMP_BUILD_NO_COMPRESSED_X |
| 136 | throw DeadlyImportError("Assimp was built without compressed X support"); |
| 137 | #else |
| 138 | /* /////////////////////////////////////////////////////////////////////// |
| 139 | * COMPRESSED X FILE FORMAT |
nothing calls this directly
no test coverage detected