AssbinLoader.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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. #include "MemoryIOWrapper.h"
  45. #ifdef ASSIMP_BUILD_NO_OWN_ZLIB
  46. # include <zlib.h>
  47. #else
  48. # include "../contrib/zlib/zlib.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 <>
  104. aiVectorKey Read<aiVectorKey>(IOStream * stream)
  105. {
  106. aiVectorKey v;
  107. v.mTime = Read<double>(stream);
  108. v.mValue = Read<aiVector3D>(stream);
  109. return v;
  110. }
  111. template <>
  112. aiQuatKey Read<aiQuatKey>(IOStream * stream)
  113. {
  114. aiQuatKey v;
  115. v.mTime = Read<double>(stream);
  116. v.mValue = Read<aiQuaternion>(stream);
  117. return v;
  118. }
  119. template <typename T>
  120. void ReadArray(IOStream * stream, T * out, unsigned int size)
  121. {
  122. for (unsigned int i=0; i<size; i++) out[i] = Read<T>(stream);
  123. }
  124. template <typename T> void ReadBounds( IOStream * stream, T* p, unsigned int n )
  125. {
  126. // not sure what to do here, the data isn't really useful.
  127. stream->Seek( sizeof(T) * n, aiOrigin_CUR );
  128. }
  129. void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** node )
  130. {
  131. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AINODE);
  132. uint32_t size = Read<uint32_t>(stream);
  133. *node = new aiNode();
  134. (*node)->mName = Read<aiString>(stream);
  135. (*node)->mTransformation = Read<aiMatrix4x4>(stream);
  136. (*node)->mNumChildren = Read<unsigned int>(stream);
  137. (*node)->mNumMeshes = Read<unsigned int>(stream);
  138. if ((*node)->mNumMeshes)
  139. {
  140. (*node)->mMeshes = new unsigned int[(*node)->mNumMeshes];
  141. for (unsigned int i = 0; i < (*node)->mNumMeshes; ++i) {
  142. (*node)->mMeshes[i] = Read<unsigned int>(stream);
  143. }
  144. }
  145. if ((*node)->mNumChildren)
  146. {
  147. (*node)->mChildren = new aiNode*[(*node)->mNumChildren];
  148. for (unsigned int i = 0; i < (*node)->mNumChildren; ++i) {
  149. ReadBinaryNode( stream, &(*node)->mChildren[i] );
  150. }
  151. }
  152. }
  153. // -----------------------------------------------------------------------------------
  154. void AssbinImporter::ReadBinaryBone( IOStream * stream, aiBone* b )
  155. {
  156. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AIBONE );
  157. uint32_t size = Read<uint32_t>(stream);
  158. b->mName = Read<aiString>(stream);
  159. b->mNumWeights = Read<unsigned int>(stream);
  160. b->mOffsetMatrix = Read<aiMatrix4x4>(stream);
  161. // for the moment we write dumb min/max values for the bones, too.
  162. // maybe I'll add a better, hash-like solution later
  163. if (shortened)
  164. {
  165. ReadBounds(stream,b->mWeights,b->mNumWeights);
  166. } // else write as usual
  167. else
  168. {
  169. b->mWeights = new aiVertexWeight[b->mNumWeights];
  170. ReadArray<aiVertexWeight>(stream,b->mWeights,b->mNumWeights);
  171. }
  172. }
  173. void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh )
  174. {
  175. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AIMESH);
  176. uint32_t size = Read<uint32_t>(stream);
  177. mesh->mPrimitiveTypes = Read<unsigned int>(stream);
  178. mesh->mNumVertices = Read<unsigned int>(stream);
  179. mesh->mNumFaces = Read<unsigned int>(stream);
  180. mesh->mNumBones = Read<unsigned int>(stream);
  181. mesh->mMaterialIndex = Read<unsigned int>(stream);
  182. // first of all, write bits for all existent vertex components
  183. unsigned int c = Read<unsigned int>(stream);
  184. if (c & ASSBIN_MESH_HAS_POSITIONS)
  185. {
  186. if (shortened) {
  187. ReadBounds(stream,mesh->mVertices,mesh->mNumVertices);
  188. } // else write as usual
  189. else
  190. {
  191. mesh->mVertices = new aiVector3D[mesh->mNumVertices];
  192. ReadArray<aiVector3D>(stream,mesh->mVertices,mesh->mNumVertices);
  193. }
  194. }
  195. if (c & ASSBIN_MESH_HAS_NORMALS)
  196. {
  197. if (shortened) {
  198. ReadBounds(stream,mesh->mNormals,mesh->mNumVertices);
  199. } // else write as usual
  200. else
  201. {
  202. mesh->mNormals = new aiVector3D[mesh->mNumVertices];
  203. ReadArray<aiVector3D>(stream,mesh->mNormals,mesh->mNumVertices);
  204. }
  205. }
  206. if (c & ASSBIN_MESH_HAS_TANGENTS_AND_BITANGENTS)
  207. {
  208. if (shortened) {
  209. ReadBounds(stream,mesh->mTangents,mesh->mNumVertices);
  210. ReadBounds(stream,mesh->mBitangents,mesh->mNumVertices);
  211. } // else write as usual
  212. else
  213. {
  214. mesh->mTangents = new aiVector3D[mesh->mNumVertices];
  215. ReadArray<aiVector3D>(stream,mesh->mTangents,mesh->mNumVertices);
  216. mesh->mBitangents = new aiVector3D[mesh->mNumVertices];
  217. ReadArray<aiVector3D>(stream,mesh->mBitangents,mesh->mNumVertices);
  218. }
  219. }
  220. for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_COLOR_SETS;++n)
  221. {
  222. if (!(c & ASSBIN_MESH_HAS_COLOR(n)))
  223. break;
  224. if (shortened)
  225. {
  226. ReadBounds(stream,mesh->mColors[n],mesh->mNumVertices);
  227. } // else write as usual
  228. else
  229. {
  230. mesh->mColors[n] = new aiColor4D[mesh->mNumVertices];
  231. ReadArray<aiColor4D>(stream,mesh->mColors[n],mesh->mNumVertices);
  232. }
  233. }
  234. for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_TEXTURECOORDS;++n)
  235. {
  236. if (!(c & ASSBIN_MESH_HAS_TEXCOORD(n)))
  237. break;
  238. // write number of UV components
  239. mesh->mNumUVComponents[n] = Read<unsigned int>(stream);
  240. if (shortened) {
  241. ReadBounds(stream,mesh->mTextureCoords[n],mesh->mNumVertices);
  242. } // else write as usual
  243. else
  244. {
  245. mesh->mTextureCoords[n] = new aiVector3D[mesh->mNumVertices];
  246. ReadArray<aiVector3D>(stream,mesh->mTextureCoords[n],mesh->mNumVertices);
  247. }
  248. }
  249. // write faces. There are no floating-point calculations involved
  250. // in these, so we can write a simple hash over the face data
  251. // to the dump file. We generate a single 32 Bit hash for 512 faces
  252. // using Assimp's standard hashing function.
  253. if (shortened) {
  254. Read<unsigned int>(stream);
  255. }
  256. else // else write as usual
  257. {
  258. // if there are less than 2^16 vertices, we can simply use 16 bit integers ...
  259. mesh->mFaces = new aiFace[mesh->mNumFaces];
  260. for (unsigned int i = 0; i < mesh->mNumFaces;++i) {
  261. aiFace& f = mesh->mFaces[i];
  262. BOOST_STATIC_ASSERT(AI_MAX_FACE_INDICES <= 0xffff);
  263. f.mNumIndices = Read<uint16_t>(stream);
  264. f.mIndices = new unsigned int[f.mNumIndices];
  265. for (unsigned int a = 0; a < f.mNumIndices;++a) {
  266. if (mesh->mNumVertices < (1u<<16))
  267. {
  268. f.mIndices[a] = Read<uint16_t>(stream);
  269. }
  270. else
  271. {
  272. f.mIndices[a] = Read<unsigned int>(stream);
  273. }
  274. }
  275. }
  276. }
  277. // write bones
  278. if (mesh->mNumBones) {
  279. mesh->mBones = new C_STRUCT aiBone*[mesh->mNumBones];
  280. for (unsigned int a = 0; a < mesh->mNumBones;++a) {
  281. mesh->mBones[a] = new aiBone();
  282. ReadBinaryBone(stream,mesh->mBones[a]);
  283. }
  284. }
  285. }
  286. void AssbinImporter::ReadBinaryMaterialProperty(IOStream * stream, aiMaterialProperty* prop)
  287. {
  288. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AIMATERIALPROPERTY);
  289. uint32_t size = Read<uint32_t>(stream);
  290. prop->mKey = Read<aiString>(stream);
  291. prop->mSemantic = Read<unsigned int>(stream);
  292. prop->mIndex = Read<unsigned int>(stream);
  293. prop->mDataLength = Read<unsigned int>(stream);
  294. prop->mType = (aiPropertyTypeInfo)Read<unsigned int>(stream);
  295. prop->mData = new char [ prop->mDataLength ];
  296. stream->Read(prop->mData,1,prop->mDataLength);
  297. }
  298. // -----------------------------------------------------------------------------------
  299. void AssbinImporter::ReadBinaryMaterial(IOStream * stream, aiMaterial* mat)
  300. {
  301. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AIMATERIAL);
  302. uint32_t size = Read<uint32_t>(stream);
  303. mat->mNumAllocated = mat->mNumProperties = Read<unsigned int>(stream);
  304. if (mat->mNumProperties)
  305. {
  306. if (mat->mProperties)
  307. {
  308. delete[] mat->mProperties;
  309. }
  310. mat->mProperties = new aiMaterialProperty*[mat->mNumProperties];
  311. for (unsigned int i = 0; i < mat->mNumProperties;++i) {
  312. mat->mProperties[i] = new aiMaterialProperty();
  313. ReadBinaryMaterialProperty( stream, mat->mProperties[i]);
  314. }
  315. }
  316. }
  317. // -----------------------------------------------------------------------------------
  318. void AssbinImporter::ReadBinaryNodeAnim(IOStream * stream, aiNodeAnim* nd)
  319. {
  320. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AINODEANIM);
  321. uint32_t size = Read<uint32_t>(stream);
  322. nd->mNodeName = Read<aiString>(stream);
  323. nd->mNumPositionKeys = Read<unsigned int>(stream);
  324. nd->mNumRotationKeys = Read<unsigned int>(stream);
  325. nd->mNumScalingKeys = Read<unsigned int>(stream);
  326. nd->mPreState = (aiAnimBehaviour)Read<unsigned int>(stream);
  327. nd->mPostState = (aiAnimBehaviour)Read<unsigned int>(stream);
  328. if (nd->mNumPositionKeys) {
  329. if (shortened) {
  330. ReadBounds(stream,nd->mPositionKeys,nd->mNumPositionKeys);
  331. } // else write as usual
  332. else {
  333. nd->mPositionKeys = new aiVectorKey[nd->mNumPositionKeys];
  334. ReadArray<aiVectorKey>(stream,nd->mPositionKeys,nd->mNumPositionKeys);
  335. }
  336. }
  337. if (nd->mNumRotationKeys) {
  338. if (shortened) {
  339. ReadBounds(stream,nd->mRotationKeys,nd->mNumRotationKeys);
  340. } // else write as usual
  341. else
  342. {
  343. nd->mRotationKeys = new aiQuatKey[nd->mNumRotationKeys];
  344. ReadArray<aiQuatKey>(stream,nd->mRotationKeys,nd->mNumRotationKeys);
  345. }
  346. }
  347. if (nd->mNumScalingKeys) {
  348. if (shortened) {
  349. ReadBounds(stream,nd->mScalingKeys,nd->mNumScalingKeys);
  350. } // else write as usual
  351. else
  352. {
  353. nd->mScalingKeys = new aiVectorKey[nd->mNumScalingKeys];
  354. ReadArray<aiVectorKey>(stream,nd->mScalingKeys,nd->mNumScalingKeys);
  355. }
  356. }
  357. }
  358. // -----------------------------------------------------------------------------------
  359. void AssbinImporter::ReadBinaryAnim( IOStream * stream, aiAnimation* anim )
  360. {
  361. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AIANIMATION);
  362. uint32_t size = Read<uint32_t>(stream);
  363. anim->mName = Read<aiString> (stream);
  364. anim->mDuration = Read<double> (stream);
  365. anim->mTicksPerSecond = Read<double> (stream);
  366. anim->mNumChannels = Read<unsigned int>(stream);
  367. if (anim->mNumChannels)
  368. {
  369. anim->mChannels = new aiNodeAnim*[ anim->mNumChannels ];
  370. for (unsigned int a = 0; a < anim->mNumChannels;++a) {
  371. anim->mChannels[a] = new aiNodeAnim();
  372. ReadBinaryNodeAnim(stream,anim->mChannels[a]);
  373. }
  374. }
  375. }
  376. void AssbinImporter::ReadBinaryTexture(IOStream * stream, aiTexture* tex)
  377. {
  378. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AITEXTURE);
  379. uint32_t size = Read<uint32_t>(stream);
  380. tex->mWidth = Read<unsigned int>(stream);
  381. tex->mHeight = Read<unsigned int>(stream);
  382. stream->Read( tex->achFormatHint, sizeof(char), 4 );
  383. if(!shortened) {
  384. if (!tex->mHeight) {
  385. tex->pcData = new aiTexel[ tex->mWidth ];
  386. stream->Read(tex->pcData,1,tex->mWidth);
  387. }
  388. else {
  389. tex->pcData = new aiTexel[ tex->mWidth*tex->mHeight ];
  390. stream->Read(tex->pcData,1,tex->mWidth*tex->mHeight*4);
  391. }
  392. }
  393. }
  394. // -----------------------------------------------------------------------------------
  395. void AssbinImporter::ReadBinaryLight( IOStream * stream, aiLight* l )
  396. {
  397. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AILIGHT);
  398. uint32_t size = Read<uint32_t>(stream);
  399. l->mName = Read<aiString>(stream);
  400. l->mType = (aiLightSourceType)Read<unsigned int>(stream);
  401. if (l->mType != aiLightSource_DIRECTIONAL) {
  402. l->mAttenuationConstant = Read<float>(stream);
  403. l->mAttenuationLinear = Read<float>(stream);
  404. l->mAttenuationQuadratic = Read<float>(stream);
  405. }
  406. l->mColorDiffuse = Read<aiColor3D>(stream);
  407. l->mColorSpecular = Read<aiColor3D>(stream);
  408. l->mColorAmbient = Read<aiColor3D>(stream);
  409. if (l->mType == aiLightSource_SPOT) {
  410. l->mAngleInnerCone = Read<float>(stream);
  411. l->mAngleOuterCone = Read<float>(stream);
  412. }
  413. }
  414. // -----------------------------------------------------------------------------------
  415. void AssbinImporter::ReadBinaryCamera( IOStream * stream, aiCamera* cam )
  416. {
  417. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AICAMERA);
  418. uint32_t size = Read<uint32_t>(stream);
  419. cam->mName = Read<aiString>(stream);
  420. cam->mPosition = Read<aiVector3D>(stream);
  421. cam->mLookAt = Read<aiVector3D>(stream);
  422. cam->mUp = Read<aiVector3D>(stream);
  423. cam->mHorizontalFOV = Read<float>(stream);
  424. cam->mClipPlaneNear = Read<float>(stream);
  425. cam->mClipPlaneFar = Read<float>(stream);
  426. cam->mAspect = Read<float>(stream);
  427. }
  428. void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene )
  429. {
  430. ai_assert( Read<uint32_t>(stream) == ASSBIN_CHUNK_AISCENE);
  431. uint32_t size = Read<uint32_t>(stream);
  432. scene->mFlags = Read<unsigned int>(stream);
  433. scene->mNumMeshes = Read<unsigned int>(stream);
  434. scene->mNumMaterials = Read<unsigned int>(stream);
  435. scene->mNumAnimations = Read<unsigned int>(stream);
  436. scene->mNumTextures = Read<unsigned int>(stream);
  437. scene->mNumLights = Read<unsigned int>(stream);
  438. scene->mNumCameras = Read<unsigned int>(stream);
  439. // Read node graph
  440. scene->mRootNode = new aiNode[1];
  441. ReadBinaryNode( stream, &scene->mRootNode );
  442. // Read all meshes
  443. if (scene->mNumMeshes)
  444. {
  445. scene->mMeshes = new aiMesh*[scene->mNumMeshes];
  446. for (unsigned int i = 0; i < scene->mNumMeshes;++i) {
  447. scene->mMeshes[i] = new aiMesh();
  448. ReadBinaryMesh( stream,scene->mMeshes[i]);
  449. }
  450. }
  451. // Read materials
  452. if (scene->mNumMaterials)
  453. {
  454. scene->mMaterials = new aiMaterial*[scene->mNumMaterials];
  455. for (unsigned int i = 0; i< scene->mNumMaterials; ++i) {
  456. scene->mMaterials[i] = new aiMaterial();
  457. ReadBinaryMaterial(stream,scene->mMaterials[i]);
  458. }
  459. }
  460. // Read all animations
  461. if (scene->mNumAnimations)
  462. {
  463. scene->mAnimations = new aiAnimation*[scene->mNumAnimations];
  464. for (unsigned int i = 0; i < scene->mNumAnimations;++i) {
  465. scene->mAnimations[i] = new aiAnimation();
  466. ReadBinaryAnim(stream,scene->mAnimations[i]);
  467. }
  468. }
  469. // Read all textures
  470. if (scene->mNumTextures)
  471. {
  472. scene->mTextures = new aiTexture*[scene->mNumTextures];
  473. for (unsigned int i = 0; i < scene->mNumTextures;++i) {
  474. scene->mTextures[i] = new aiTexture();
  475. ReadBinaryTexture(stream,scene->mTextures[i]);
  476. }
  477. }
  478. // Read lights
  479. if (scene->mNumLights)
  480. {
  481. scene->mLights = new aiLight*[scene->mNumLights];
  482. for (unsigned int i = 0; i < scene->mNumLights;++i) {
  483. scene->mLights[i] = new aiLight();
  484. ReadBinaryLight(stream,scene->mLights[i]);
  485. }
  486. }
  487. // Read cameras
  488. if (scene->mNumCameras)
  489. {
  490. scene->mCameras = new aiCamera*[scene->mNumCameras];
  491. for (unsigned int i = 0; i < scene->mNumCameras;++i) {
  492. scene->mCameras[i] = new aiCamera();
  493. ReadBinaryCamera(stream,scene->mCameras[i]);
  494. }
  495. }
  496. }
  497. void AssbinImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler )
  498. {
  499. IOStream * stream = pIOHandler->Open(pFile,"rb");
  500. if (!stream)
  501. return;
  502. stream->Seek( 44, aiOrigin_CUR ); // signature
  503. unsigned int versionMajor = Read<unsigned int>(stream);
  504. unsigned int versionMinor = Read<unsigned int>(stream);
  505. unsigned int versionRevision = Read<unsigned int>(stream);
  506. unsigned int compileFlags = Read<unsigned int>(stream);
  507. shortened = Read<uint16_t>(stream) > 0;
  508. compressed = Read<uint16_t>(stream) > 0;
  509. if (shortened)
  510. throw DeadlyImportError( "Shortened binaries are not supported!" );
  511. stream->Seek( 256, aiOrigin_CUR ); // original filename
  512. stream->Seek( 128, aiOrigin_CUR ); // options
  513. stream->Seek( 64, aiOrigin_CUR ); // padding
  514. if (compressed)
  515. {
  516. uLongf uncompressedSize = Read<uint32_t>(stream);
  517. uLongf compressedSize = stream->FileSize() - stream->Tell();
  518. unsigned char * compressedData = new unsigned char[ compressedSize ];
  519. stream->Read( compressedData, 1, compressedSize );
  520. unsigned char * uncompressedData = new unsigned char[ uncompressedSize ];
  521. uncompress( uncompressedData, &uncompressedSize, compressedData, compressedSize );
  522. MemoryIOStream io( uncompressedData, uncompressedSize );
  523. ReadBinaryScene(&io,pScene);
  524. delete[] uncompressedData;
  525. delete[] compressedData;
  526. }
  527. else
  528. {
  529. ReadBinaryScene(stream,pScene);
  530. }
  531. pIOHandler->Close(stream);
  532. }
  533. #endif // !! ASSIMP_BUILD_NO_ASSBIN_IMPORTER