AssbinLoader.cpp 19 KB

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