AssbinLoader.cpp 21 KB

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