AssbinLoader.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2012, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file AssbinLoader.cpp
  35. * @brief Implementation of the .assbin importer class
  36. *
  37. * see assbin_chunks.h
  38. */
  39. #include "AssimpPCH.h"
  40. #ifndef ASSIMP_BUILD_NO_ASSBIN_IMPORTER
  41. // internal headers
  42. #include "AssbinLoader.h"
  43. #include "assbin_chunks.h"
  44. #ifdef ASSIMP_BUILD_NO_OWN_ZLIB
  45. # include <zlib.h>
  46. #else
  47. # include "../contrib/zlib/zlib.h"
  48. #include "MemoryIOWrapper.h"
  49. #endif
  50. using namespace Assimp;
  51. static const aiImporterDesc desc = {
  52. ".assbin Importer",
  53. "Gargaj / Conspiracy",
  54. "",
  55. "",
  56. aiImporterFlags_SupportBinaryFlavour | aiImporterFlags_SupportCompressedFlavour,
  57. 0,
  58. 0,
  59. 0,
  60. 0,
  61. "assbin"
  62. };
  63. const aiImporterDesc* AssbinImporter::GetInfo() const
  64. {
  65. return &desc;
  66. }
  67. bool AssbinImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig ) const
  68. {
  69. IOStream * in = pIOHandler->Open(pFile);
  70. if (!in)
  71. return false;
  72. char s[32];
  73. in->Read( s, sizeof(char), 32 );
  74. pIOHandler->Close(in);
  75. return strncmp( s, "ASSIMP.binary-dump.", 19 ) == 0;
  76. }
  77. template <typename T>
  78. T Read(IOStream * stream)
  79. {
  80. T t;
  81. stream->Read( &t, sizeof(T), 1 );
  82. return t;
  83. }
  84. template <>
  85. aiString Read<aiString>(IOStream * stream)
  86. {
  87. aiString s;
  88. stream->Read(&s.length,4,1);
  89. stream->Read(s.data,s.length,1);
  90. return s;
  91. }
  92. template <>
  93. aiMatrix4x4 Read<aiMatrix4x4>(IOStream * stream)
  94. {
  95. aiMatrix4x4 m;
  96. for (unsigned int i = 0; i < 4;++i) {
  97. for (unsigned int i2 = 0; i2 < 4;++i2) {
  98. m[i][i2] = Read<float>(stream);
  99. }
  100. }
  101. return m;
  102. }
  103. template <typename T> void ReadBounds( IOStream * stream, T* p, unsigned int n )
  104. {
  105. // not sure what to do here, the data isn't really useful.
  106. stream->Seek( sizeof(T) * n, aiOrigin_CUR );
  107. }
  108. void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** node )
  109. {
  110. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AINODE);
  111. uint32_t size = Read<uint32_t>(stream);
  112. *node = new aiNode();
  113. (*node)->mName = Read<aiString>(stream);
  114. (*node)->mTransformation = Read<aiMatrix4x4>(stream);
  115. (*node)->mNumChildren = Read<unsigned int>(stream);
  116. (*node)->mNumMeshes = Read<unsigned int>(stream);
  117. if ((*node)->mNumMeshes)
  118. {
  119. (*node)->mMeshes = new unsigned int[(*node)->mNumMeshes];
  120. for (unsigned int i = 0; i < (*node)->mNumMeshes; ++i) {
  121. (*node)->mMeshes[i] = Read<unsigned int>(stream);
  122. }
  123. }
  124. if ((*node)->mNumChildren)
  125. {
  126. (*node)->mChildren = new aiNode*[(*node)->mNumChildren];
  127. for (unsigned int i = 0; i < (*node)->mNumChildren; ++i) {
  128. ReadBinaryNode( stream, &(*node)->mChildren[i] );
  129. }
  130. }
  131. }
  132. // -----------------------------------------------------------------------------------
  133. void AssbinImporter::ReadBinaryBone( IOStream * stream, aiBone* b )
  134. {
  135. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AIBONE );
  136. uint32_t size = Read<uint32_t>(stream);
  137. b->mName = Read<aiString>(stream);
  138. b->mNumWeights = Read<unsigned int>(stream);
  139. b->mOffsetMatrix = Read<aiMatrix4x4>(stream);
  140. // for the moment we write dumb min/max values for the bones, too.
  141. // maybe I'll add a better, hash-like solution later
  142. if (shortened)
  143. {
  144. ReadBounds(stream,b->mWeights,b->mNumWeights);
  145. } // else write as usual
  146. else
  147. {
  148. b->mWeights = new aiVertexWeight[b->mNumWeights];
  149. stream->Read(b->mWeights,1,b->mNumWeights*sizeof(aiVertexWeight));
  150. }
  151. }
  152. void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh )
  153. {
  154. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AIMESH);
  155. uint32_t size = Read<uint32_t>(stream);
  156. mesh->mPrimitiveTypes = Read<unsigned int>(stream);
  157. mesh->mNumVertices = Read<unsigned int>(stream);
  158. mesh->mNumFaces = Read<unsigned int>(stream);
  159. mesh->mNumBones = Read<unsigned int>(stream);
  160. mesh->mMaterialIndex = Read<unsigned int>(stream);
  161. // first of all, write bits for all existent vertex components
  162. unsigned int c = Read<unsigned int>(stream);
  163. if (c & ASSBIN_MESH_HAS_POSITIONS)
  164. {
  165. if (shortened) {
  166. ReadBounds(stream,mesh->mVertices,mesh->mNumVertices);
  167. } // else write as usual
  168. else
  169. {
  170. mesh->mVertices = new aiVector3D[mesh->mNumVertices];
  171. stream->Read(mesh->mVertices,1,12*mesh->mNumVertices);
  172. }
  173. }
  174. if (c & ASSBIN_MESH_HAS_NORMALS)
  175. {
  176. if (shortened) {
  177. ReadBounds(stream,mesh->mNormals,mesh->mNumVertices);
  178. } // else write as usual
  179. else
  180. {
  181. mesh->mNormals = new aiVector3D[mesh->mNumVertices];
  182. stream->Read(mesh->mNormals,1,12*mesh->mNumVertices);
  183. }
  184. }
  185. if (c & ASSBIN_MESH_HAS_TANGENTS_AND_BITANGENTS)
  186. {
  187. if (shortened) {
  188. ReadBounds(stream,mesh->mTangents,mesh->mNumVertices);
  189. ReadBounds(stream,mesh->mBitangents,mesh->mNumVertices);
  190. } // else write as usual
  191. else
  192. {
  193. mesh->mTangents = new aiVector3D[mesh->mNumVertices];
  194. stream->Read(mesh->mTangents,1,12*mesh->mNumVertices);
  195. mesh->mBitangents = new aiVector3D[mesh->mNumVertices];
  196. stream->Read(mesh->mBitangents,1,12*mesh->mNumVertices);
  197. }
  198. }
  199. for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_COLOR_SETS;++n)
  200. {
  201. if (!(c & ASSBIN_MESH_HAS_COLOR(n)))
  202. break;
  203. if (shortened)
  204. {
  205. ReadBounds(stream,mesh->mColors[n],mesh->mNumVertices);
  206. } // else write as usual
  207. else
  208. {
  209. mesh->mColors[n] = new aiColor4D[mesh->mNumVertices];
  210. stream->Read(mesh->mColors[n],16*mesh->mNumVertices,1);
  211. }
  212. }
  213. for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_TEXTURECOORDS;++n)
  214. {
  215. if (!(c & ASSBIN_MESH_HAS_TEXCOORD(n)))
  216. break;
  217. // write number of UV components
  218. mesh->mNumUVComponents[n] = Read<unsigned int>(stream);
  219. if (shortened) {
  220. ReadBounds(stream,mesh->mTextureCoords[n],mesh->mNumVertices);
  221. } // else write as usual
  222. else
  223. {
  224. mesh->mTextureCoords[n] = new aiVector3D[mesh->mNumVertices];
  225. stream->Read(mesh->mTextureCoords[n],12*mesh->mNumVertices,1);
  226. }
  227. }
  228. // write faces. There are no floating-point calculations involved
  229. // in these, so we can write a simple hash over the face data
  230. // to the dump file. We generate a single 32 Bit hash for 512 faces
  231. // using Assimp's standard hashing function.
  232. if (shortened) {
  233. Read<unsigned int>(stream);
  234. }
  235. else // else write as usual
  236. {
  237. // if there are less than 2^16 vertices, we can simply use 16 bit integers ...
  238. mesh->mFaces = new aiFace[mesh->mNumFaces];
  239. for (unsigned int i = 0; i < mesh->mNumFaces;++i) {
  240. aiFace& f = mesh->mFaces[i];
  241. BOOST_STATIC_ASSERT(AI_MAX_FACE_INDICES <= 0xffff);
  242. f.mNumIndices = Read<uint16_t>(stream);
  243. f.mIndices = new unsigned int[f.mNumIndices];
  244. for (unsigned int a = 0; a < f.mNumIndices;++a) {
  245. if (mesh->mNumVertices < (1u<<16))
  246. {
  247. f.mIndices[a] = Read<uint16_t>(stream);
  248. }
  249. else
  250. {
  251. f.mIndices[a] = Read<unsigned int>(stream);
  252. }
  253. }
  254. }
  255. }
  256. // write bones
  257. if (mesh->mNumBones) {
  258. mesh->mBones = new C_STRUCT aiBone*[mesh->mNumBones];
  259. for (unsigned int a = 0; a < mesh->mNumBones;++a) {
  260. mesh->mBones[a] = new aiBone();
  261. ReadBinaryBone(stream,mesh->mBones[a]);
  262. }
  263. }
  264. }
  265. void AssbinImporter::ReadBinaryMaterialProperty(IOStream * stream, aiMaterialProperty* prop)
  266. {
  267. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AIMATERIALPROPERTY);
  268. uint32_t size = Read<uint32_t>(stream);
  269. prop->mKey = Read<aiString>(stream);
  270. prop->mSemantic = Read<unsigned int>(stream);
  271. prop->mIndex = Read<unsigned int>(stream);
  272. prop->mDataLength = Read<unsigned int>(stream);
  273. prop->mType = (aiPropertyTypeInfo)Read<unsigned int>(stream);
  274. prop->mData = new char [ prop->mDataLength ];
  275. stream->Read(prop->mData,1,prop->mDataLength);
  276. }
  277. // -----------------------------------------------------------------------------------
  278. void AssbinImporter::ReadBinaryMaterial(IOStream * stream, aiMaterial* mat)
  279. {
  280. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AIMATERIAL);
  281. uint32_t size = Read<uint32_t>(stream);
  282. mat->mNumAllocated = mat->mNumProperties = Read<unsigned int>(stream);
  283. if (mat->mNumProperties)
  284. {
  285. if (mat->mProperties)
  286. {
  287. delete[] mat->mProperties;
  288. }
  289. mat->mProperties = new aiMaterialProperty*[mat->mNumProperties];
  290. for (unsigned int i = 0; i < mat->mNumProperties;++i) {
  291. mat->mProperties[i] = new aiMaterialProperty();
  292. ReadBinaryMaterialProperty( stream, mat->mProperties[i]);
  293. }
  294. }
  295. }
  296. // -----------------------------------------------------------------------------------
  297. void AssbinImporter::ReadBinaryNodeAnim(IOStream * stream, aiNodeAnim* nd)
  298. {
  299. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AINODEANIM);
  300. uint32_t size = Read<uint32_t>(stream);
  301. nd->mNodeName = Read<aiString>(stream);
  302. nd->mNumPositionKeys = Read<unsigned int>(stream);
  303. nd->mNumRotationKeys = Read<unsigned int>(stream);
  304. nd->mNumScalingKeys = Read<unsigned int>(stream);
  305. nd->mPreState = (aiAnimBehaviour)Read<unsigned int>(stream);
  306. nd->mPostState = (aiAnimBehaviour)Read<unsigned int>(stream);
  307. if (nd->mNumPositionKeys) {
  308. if (shortened) {
  309. ReadBounds(stream,nd->mPositionKeys,nd->mNumPositionKeys);
  310. } // else write as usual
  311. else {
  312. nd->mPositionKeys = new aiVectorKey[nd->mNumPositionKeys];
  313. stream->Read(nd->mPositionKeys,1,nd->mNumPositionKeys*sizeof(aiVectorKey));
  314. }
  315. }
  316. if (nd->mNumRotationKeys) {
  317. if (shortened) {
  318. ReadBounds(stream,nd->mRotationKeys,nd->mNumRotationKeys);
  319. } // else write as usual
  320. else
  321. {
  322. nd->mRotationKeys = new aiQuatKey[nd->mNumRotationKeys];
  323. stream->Read(nd->mRotationKeys,1,nd->mNumRotationKeys*sizeof(aiQuatKey));
  324. }
  325. }
  326. if (nd->mNumScalingKeys) {
  327. if (shortened) {
  328. ReadBounds(stream,nd->mScalingKeys,nd->mNumScalingKeys);
  329. } // else write as usual
  330. else
  331. {
  332. nd->mScalingKeys = new aiVectorKey[nd->mNumScalingKeys];
  333. stream->Read(nd->mScalingKeys,1,nd->mNumScalingKeys*sizeof(aiVectorKey));
  334. }
  335. }
  336. }
  337. // -----------------------------------------------------------------------------------
  338. void AssbinImporter::ReadBinaryAnim( IOStream * stream, aiAnimation* anim )
  339. {
  340. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AIANIMATION);
  341. uint32_t size = Read<uint32_t>(stream);
  342. anim->mName = Read<aiString> (stream);
  343. anim->mDuration = Read<double> (stream);
  344. anim->mTicksPerSecond = Read<double> (stream);
  345. anim->mNumChannels = Read<unsigned int>(stream);
  346. if (anim->mNumChannels)
  347. {
  348. anim->mChannels = new aiNodeAnim*[ anim->mNumChannels ];
  349. for (unsigned int a = 0; a < anim->mNumChannels;++a) {
  350. anim->mChannels[a] = new aiNodeAnim();
  351. ReadBinaryNodeAnim(stream,anim->mChannels[a]);
  352. }
  353. }
  354. }
  355. void AssbinImporter::ReadBinaryTexture(IOStream * stream, aiTexture* tex)
  356. {
  357. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AITEXTURE);
  358. uint32_t size = Read<uint32_t>(stream);
  359. tex->mWidth = Read<unsigned int>(stream);
  360. tex->mHeight = Read<unsigned int>(stream);
  361. stream->Read( tex->achFormatHint, sizeof(char), 4 );
  362. if(!shortened) {
  363. if (!tex->mHeight) {
  364. tex->pcData = new aiTexel[ tex->mWidth ];
  365. stream->Read(tex->pcData,1,tex->mWidth);
  366. }
  367. else {
  368. tex->pcData = new aiTexel[ tex->mWidth*tex->mHeight ];
  369. stream->Read(tex->pcData,1,tex->mWidth*tex->mHeight*4);
  370. }
  371. }
  372. }
  373. // -----------------------------------------------------------------------------------
  374. void AssbinImporter::ReadBinaryLight( IOStream * stream, aiLight* l )
  375. {
  376. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AILIGHT);
  377. uint32_t size = Read<uint32_t>(stream);
  378. l->mName = Read<aiString>(stream);
  379. l->mType = (aiLightSourceType)Read<unsigned int>(stream);
  380. if (l->mType != aiLightSource_DIRECTIONAL) {
  381. l->mAttenuationConstant = Read<float>(stream);
  382. l->mAttenuationLinear = Read<float>(stream);
  383. l->mAttenuationQuadratic = Read<float>(stream);
  384. }
  385. l->mColorDiffuse = Read<aiColor3D>(stream);
  386. l->mColorSpecular = Read<aiColor3D>(stream);
  387. l->mColorAmbient = Read<aiColor3D>(stream);
  388. if (l->mType == aiLightSource_SPOT) {
  389. l->mAngleInnerCone = Read<float>(stream);
  390. l->mAngleOuterCone = Read<float>(stream);
  391. }
  392. }
  393. // -----------------------------------------------------------------------------------
  394. void AssbinImporter::ReadBinaryCamera( IOStream * stream, aiCamera* cam )
  395. {
  396. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AICAMERA);
  397. uint32_t size = Read<uint32_t>(stream);
  398. cam->mName = Read<aiString>(stream);
  399. cam->mPosition = Read<aiVector3D>(stream);
  400. cam->mLookAt = Read<aiVector3D>(stream);
  401. cam->mUp = Read<aiVector3D>(stream);
  402. cam->mHorizontalFOV = Read<float>(stream);
  403. cam->mClipPlaneNear = Read<float>(stream);
  404. cam->mClipPlaneFar = Read<float>(stream);
  405. cam->mAspect = Read<float>(stream);
  406. }
  407. void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene )
  408. {
  409. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AISCENE);
  410. uint32_t size = Read<uint32_t>(stream);
  411. scene->mFlags = Read<unsigned int>(stream);
  412. scene->mNumMeshes = Read<unsigned int>(stream);
  413. scene->mNumMaterials = Read<unsigned int>(stream);
  414. scene->mNumAnimations = Read<unsigned int>(stream);
  415. scene->mNumTextures = Read<unsigned int>(stream);
  416. scene->mNumLights = Read<unsigned int>(stream);
  417. scene->mNumCameras = Read<unsigned int>(stream);
  418. // Read node graph
  419. scene->mRootNode = new aiNode[1];
  420. ReadBinaryNode( stream, &scene->mRootNode );
  421. // Read all meshes
  422. if (scene->mNumMeshes)
  423. {
  424. scene->mMeshes = new aiMesh*[scene->mNumMeshes];
  425. for (unsigned int i = 0; i < scene->mNumMeshes;++i) {
  426. scene->mMeshes[i] = new aiMesh();
  427. ReadBinaryMesh( stream,scene->mMeshes[i]);
  428. }
  429. }
  430. // Read materials
  431. if (scene->mNumMaterials)
  432. {
  433. scene->mMaterials = new aiMaterial*[scene->mNumMaterials];
  434. for (unsigned int i = 0; i< scene->mNumMaterials; ++i) {
  435. scene->mMaterials[i] = new aiMaterial();
  436. ReadBinaryMaterial(stream,scene->mMaterials[i]);
  437. }
  438. }
  439. // Read all animations
  440. if (scene->mNumAnimations)
  441. {
  442. scene->mAnimations = new aiAnimation*[scene->mNumAnimations];
  443. for (unsigned int i = 0; i < scene->mNumAnimations;++i) {
  444. scene->mAnimations[i] = new aiAnimation();
  445. ReadBinaryAnim(stream,scene->mAnimations[i]);
  446. }
  447. }
  448. // Read all textures
  449. if (scene->mNumTextures)
  450. {
  451. scene->mTextures = new aiTexture*[scene->mNumTextures];
  452. for (unsigned int i = 0; i < scene->mNumTextures;++i) {
  453. scene->mTextures[i] = new aiTexture();
  454. ReadBinaryTexture(stream,scene->mTextures[i]);
  455. }
  456. }
  457. // Read lights
  458. if (scene->mNumLights)
  459. {
  460. scene->mLights = new aiLight*[scene->mNumLights];
  461. for (unsigned int i = 0; i < scene->mNumLights;++i) {
  462. scene->mLights[i] = new aiLight();
  463. ReadBinaryLight(stream,scene->mLights[i]);
  464. }
  465. }
  466. // Read cameras
  467. if (scene->mNumCameras)
  468. {
  469. scene->mCameras = new aiCamera*[scene->mNumCameras];
  470. for (unsigned int i = 0; i < scene->mNumCameras;++i) {
  471. scene->mCameras[i] = new aiCamera();
  472. ReadBinaryCamera(stream,scene->mCameras[i]);
  473. }
  474. }
  475. }
  476. void AssbinImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler )
  477. {
  478. IOStream * stream = pIOHandler->Open(pFile,"rb");
  479. if (!stream)
  480. return;
  481. stream->Seek( 44, aiOrigin_CUR ); // signature
  482. unsigned int versionMajor = Read<unsigned int>(stream);
  483. unsigned int versionMinor = Read<unsigned int>(stream);
  484. unsigned int versionRevision = Read<unsigned int>(stream);
  485. unsigned int compileFlags = Read<unsigned int>(stream);
  486. shortened = Read<uint16_t>(stream) > 0;
  487. compressed = Read<uint16_t>(stream) > 0;
  488. if (shortened)
  489. throw DeadlyImportError( "Shortened binaries are not supported!" );
  490. stream->Seek( 256, aiOrigin_CUR ); // original filename
  491. stream->Seek( 128, aiOrigin_CUR ); // options
  492. stream->Seek( 64, aiOrigin_CUR ); // padding
  493. if (compressed)
  494. {
  495. uLongf uncompressedSize = Read<uint32_t>(stream);
  496. uLongf compressedSize = stream->FileSize() - stream->Tell();
  497. unsigned char * compressedData = new unsigned char[ compressedSize ];
  498. stream->Read( compressedData, 1, compressedSize );
  499. unsigned char * uncompressedData = new unsigned char[ uncompressedSize ];
  500. uncompress( uncompressedData, &uncompressedSize, compressedData, compressedSize );
  501. MemoryIOStream io( uncompressedData, uncompressedSize );
  502. ReadBinaryScene(&io,pScene);
  503. delete[] uncompressedData;
  504. delete[] compressedData;
  505. }
  506. else
  507. {
  508. ReadBinaryScene(stream,pScene);
  509. }
  510. pIOHandler->Close(stream);
  511. }
  512. #endif // !! ASSIMP_BUILD_NO_ASSBIN_IMPORTER