AssbinLoader.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2017, 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. #include <assimp/importerdesc.h>
  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, aiNode* parent )
  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(parent)
  181. {
  182. (*node)->mParent = parent;
  183. }
  184. if ((*node)->mNumMeshes)
  185. {
  186. (*node)->mMeshes = new unsigned int[(*node)->mNumMeshes];
  187. for (unsigned int i = 0; i < (*node)->mNumMeshes; ++i) {
  188. (*node)->mMeshes[i] = Read<unsigned int>(stream);
  189. }
  190. }
  191. if ((*node)->mNumChildren)
  192. {
  193. (*node)->mChildren = new aiNode*[(*node)->mNumChildren];
  194. for (unsigned int i = 0; i < (*node)->mNumChildren; ++i) {
  195. ReadBinaryNode( stream, &(*node)->mChildren[i], *node );
  196. }
  197. }
  198. }
  199. // -----------------------------------------------------------------------------------
  200. void AssbinImporter::ReadBinaryBone( IOStream * stream, aiBone* b )
  201. {
  202. uint32_t chunkID = Read<uint32_t>(stream);
  203. ai_assert(chunkID == ASSBIN_CHUNK_AIBONE);
  204. /*uint32_t size =*/ Read<uint32_t>(stream);
  205. b->mName = Read<aiString>(stream);
  206. b->mNumWeights = Read<unsigned int>(stream);
  207. b->mOffsetMatrix = Read<aiMatrix4x4>(stream);
  208. // for the moment we write dumb min/max values for the bones, too.
  209. // maybe I'll add a better, hash-like solution later
  210. if (shortened)
  211. {
  212. ReadBounds(stream,b->mWeights,b->mNumWeights);
  213. } // else write as usual
  214. else
  215. {
  216. b->mWeights = new aiVertexWeight[b->mNumWeights];
  217. ReadArray<aiVertexWeight>(stream,b->mWeights,b->mNumWeights);
  218. }
  219. }
  220. void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh )
  221. {
  222. uint32_t chunkID = Read<uint32_t>(stream);
  223. ai_assert(chunkID == ASSBIN_CHUNK_AIMESH);
  224. /*uint32_t size =*/ Read<uint32_t>(stream);
  225. mesh->mPrimitiveTypes = Read<unsigned int>(stream);
  226. mesh->mNumVertices = Read<unsigned int>(stream);
  227. mesh->mNumFaces = Read<unsigned int>(stream);
  228. mesh->mNumBones = Read<unsigned int>(stream);
  229. mesh->mMaterialIndex = Read<unsigned int>(stream);
  230. // first of all, write bits for all existent vertex components
  231. unsigned int c = Read<unsigned int>(stream);
  232. if (c & ASSBIN_MESH_HAS_POSITIONS)
  233. {
  234. if (shortened) {
  235. ReadBounds(stream,mesh->mVertices,mesh->mNumVertices);
  236. } // else write as usual
  237. else
  238. {
  239. mesh->mVertices = new aiVector3D[mesh->mNumVertices];
  240. ReadArray<aiVector3D>(stream,mesh->mVertices,mesh->mNumVertices);
  241. }
  242. }
  243. if (c & ASSBIN_MESH_HAS_NORMALS)
  244. {
  245. if (shortened) {
  246. ReadBounds(stream,mesh->mNormals,mesh->mNumVertices);
  247. } // else write as usual
  248. else
  249. {
  250. mesh->mNormals = new aiVector3D[mesh->mNumVertices];
  251. ReadArray<aiVector3D>(stream,mesh->mNormals,mesh->mNumVertices);
  252. }
  253. }
  254. if (c & ASSBIN_MESH_HAS_TANGENTS_AND_BITANGENTS)
  255. {
  256. if (shortened) {
  257. ReadBounds(stream,mesh->mTangents,mesh->mNumVertices);
  258. ReadBounds(stream,mesh->mBitangents,mesh->mNumVertices);
  259. } // else write as usual
  260. else
  261. {
  262. mesh->mTangents = new aiVector3D[mesh->mNumVertices];
  263. ReadArray<aiVector3D>(stream,mesh->mTangents,mesh->mNumVertices);
  264. mesh->mBitangents = new aiVector3D[mesh->mNumVertices];
  265. ReadArray<aiVector3D>(stream,mesh->mBitangents,mesh->mNumVertices);
  266. }
  267. }
  268. for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_COLOR_SETS;++n)
  269. {
  270. if (!(c & ASSBIN_MESH_HAS_COLOR(n)))
  271. break;
  272. if (shortened)
  273. {
  274. ReadBounds(stream,mesh->mColors[n],mesh->mNumVertices);
  275. } // else write as usual
  276. else
  277. {
  278. mesh->mColors[n] = new aiColor4D[mesh->mNumVertices];
  279. ReadArray<aiColor4D>(stream,mesh->mColors[n],mesh->mNumVertices);
  280. }
  281. }
  282. for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_TEXTURECOORDS;++n)
  283. {
  284. if (!(c & ASSBIN_MESH_HAS_TEXCOORD(n)))
  285. break;
  286. // write number of UV components
  287. mesh->mNumUVComponents[n] = Read<unsigned int>(stream);
  288. if (shortened) {
  289. ReadBounds(stream,mesh->mTextureCoords[n],mesh->mNumVertices);
  290. } // else write as usual
  291. else
  292. {
  293. mesh->mTextureCoords[n] = new aiVector3D[mesh->mNumVertices];
  294. ReadArray<aiVector3D>(stream,mesh->mTextureCoords[n],mesh->mNumVertices);
  295. }
  296. }
  297. // write faces. There are no floating-point calculations involved
  298. // in these, so we can write a simple hash over the face data
  299. // to the dump file. We generate a single 32 Bit hash for 512 faces
  300. // using Assimp's standard hashing function.
  301. if (shortened) {
  302. Read<unsigned int>(stream);
  303. }
  304. else // else write as usual
  305. {
  306. // if there are less than 2^16 vertices, we can simply use 16 bit integers ...
  307. mesh->mFaces = new aiFace[mesh->mNumFaces];
  308. for (unsigned int i = 0; i < mesh->mNumFaces;++i) {
  309. aiFace& f = mesh->mFaces[i];
  310. static_assert(AI_MAX_FACE_INDICES <= 0xffff, "AI_MAX_FACE_INDICES <= 0xffff");
  311. f.mNumIndices = Read<uint16_t>(stream);
  312. f.mIndices = new unsigned int[f.mNumIndices];
  313. for (unsigned int a = 0; a < f.mNumIndices;++a) {
  314. if (mesh->mNumVertices < (1u<<16))
  315. {
  316. f.mIndices[a] = Read<uint16_t>(stream);
  317. }
  318. else
  319. {
  320. f.mIndices[a] = Read<unsigned int>(stream);
  321. }
  322. }
  323. }
  324. }
  325. // write bones
  326. if (mesh->mNumBones) {
  327. mesh->mBones = new C_STRUCT aiBone*[mesh->mNumBones];
  328. for (unsigned int a = 0; a < mesh->mNumBones;++a) {
  329. mesh->mBones[a] = new aiBone();
  330. ReadBinaryBone(stream,mesh->mBones[a]);
  331. }
  332. }
  333. }
  334. void AssbinImporter::ReadBinaryMaterialProperty(IOStream * stream, aiMaterialProperty* prop)
  335. {
  336. uint32_t chunkID = Read<uint32_t>(stream);
  337. ai_assert(chunkID == ASSBIN_CHUNK_AIMATERIALPROPERTY);
  338. /*uint32_t size =*/ Read<uint32_t>(stream);
  339. prop->mKey = Read<aiString>(stream);
  340. prop->mSemantic = Read<unsigned int>(stream);
  341. prop->mIndex = Read<unsigned int>(stream);
  342. prop->mDataLength = Read<unsigned int>(stream);
  343. prop->mType = (aiPropertyTypeInfo)Read<unsigned int>(stream);
  344. prop->mData = new char [ prop->mDataLength ];
  345. stream->Read(prop->mData,1,prop->mDataLength);
  346. }
  347. // -----------------------------------------------------------------------------------
  348. void AssbinImporter::ReadBinaryMaterial(IOStream * stream, aiMaterial* mat)
  349. {
  350. uint32_t chunkID = Read<uint32_t>(stream);
  351. ai_assert(chunkID == ASSBIN_CHUNK_AIMATERIAL);
  352. /*uint32_t size =*/ Read<uint32_t>(stream);
  353. mat->mNumAllocated = mat->mNumProperties = Read<unsigned int>(stream);
  354. if (mat->mNumProperties)
  355. {
  356. if (mat->mProperties)
  357. {
  358. delete[] mat->mProperties;
  359. }
  360. mat->mProperties = new aiMaterialProperty*[mat->mNumProperties];
  361. for (unsigned int i = 0; i < mat->mNumProperties;++i) {
  362. mat->mProperties[i] = new aiMaterialProperty();
  363. ReadBinaryMaterialProperty( stream, mat->mProperties[i]);
  364. }
  365. }
  366. }
  367. // -----------------------------------------------------------------------------------
  368. void AssbinImporter::ReadBinaryNodeAnim(IOStream * stream, aiNodeAnim* nd)
  369. {
  370. uint32_t chunkID = Read<uint32_t>(stream);
  371. ai_assert(chunkID == ASSBIN_CHUNK_AINODEANIM);
  372. /*uint32_t size =*/ Read<uint32_t>(stream);
  373. nd->mNodeName = Read<aiString>(stream);
  374. nd->mNumPositionKeys = Read<unsigned int>(stream);
  375. nd->mNumRotationKeys = Read<unsigned int>(stream);
  376. nd->mNumScalingKeys = Read<unsigned int>(stream);
  377. nd->mPreState = (aiAnimBehaviour)Read<unsigned int>(stream);
  378. nd->mPostState = (aiAnimBehaviour)Read<unsigned int>(stream);
  379. if (nd->mNumPositionKeys) {
  380. if (shortened) {
  381. ReadBounds(stream,nd->mPositionKeys,nd->mNumPositionKeys);
  382. } // else write as usual
  383. else {
  384. nd->mPositionKeys = new aiVectorKey[nd->mNumPositionKeys];
  385. ReadArray<aiVectorKey>(stream,nd->mPositionKeys,nd->mNumPositionKeys);
  386. }
  387. }
  388. if (nd->mNumRotationKeys) {
  389. if (shortened) {
  390. ReadBounds(stream,nd->mRotationKeys,nd->mNumRotationKeys);
  391. } // else write as usual
  392. else
  393. {
  394. nd->mRotationKeys = new aiQuatKey[nd->mNumRotationKeys];
  395. ReadArray<aiQuatKey>(stream,nd->mRotationKeys,nd->mNumRotationKeys);
  396. }
  397. }
  398. if (nd->mNumScalingKeys) {
  399. if (shortened) {
  400. ReadBounds(stream,nd->mScalingKeys,nd->mNumScalingKeys);
  401. } // else write as usual
  402. else
  403. {
  404. nd->mScalingKeys = new aiVectorKey[nd->mNumScalingKeys];
  405. ReadArray<aiVectorKey>(stream,nd->mScalingKeys,nd->mNumScalingKeys);
  406. }
  407. }
  408. }
  409. // -----------------------------------------------------------------------------------
  410. void AssbinImporter::ReadBinaryAnim( IOStream * stream, aiAnimation* anim )
  411. {
  412. uint32_t chunkID = Read<uint32_t>(stream);
  413. ai_assert(chunkID == ASSBIN_CHUNK_AIANIMATION);
  414. /*uint32_t size =*/ Read<uint32_t>(stream);
  415. anim->mName = Read<aiString> (stream);
  416. anim->mDuration = Read<double> (stream);
  417. anim->mTicksPerSecond = Read<double> (stream);
  418. anim->mNumChannels = Read<unsigned int>(stream);
  419. if (anim->mNumChannels)
  420. {
  421. anim->mChannels = new aiNodeAnim*[ anim->mNumChannels ];
  422. for (unsigned int a = 0; a < anim->mNumChannels;++a) {
  423. anim->mChannels[a] = new aiNodeAnim();
  424. ReadBinaryNodeAnim(stream,anim->mChannels[a]);
  425. }
  426. }
  427. }
  428. void AssbinImporter::ReadBinaryTexture(IOStream * stream, aiTexture* tex)
  429. {
  430. uint32_t chunkID = Read<uint32_t>(stream);
  431. ai_assert(chunkID == ASSBIN_CHUNK_AITEXTURE);
  432. /*uint32_t size =*/ Read<uint32_t>(stream);
  433. tex->mWidth = Read<unsigned int>(stream);
  434. tex->mHeight = Read<unsigned int>(stream);
  435. stream->Read( tex->achFormatHint, sizeof(char), 4 );
  436. if(!shortened) {
  437. if (!tex->mHeight) {
  438. tex->pcData = new aiTexel[ tex->mWidth ];
  439. stream->Read(tex->pcData,1,tex->mWidth);
  440. }
  441. else {
  442. tex->pcData = new aiTexel[ tex->mWidth*tex->mHeight ];
  443. stream->Read(tex->pcData,1,tex->mWidth*tex->mHeight*4);
  444. }
  445. }
  446. }
  447. // -----------------------------------------------------------------------------------
  448. void AssbinImporter::ReadBinaryLight( IOStream * stream, aiLight* l )
  449. {
  450. uint32_t chunkID = Read<uint32_t>(stream);
  451. ai_assert(chunkID == ASSBIN_CHUNK_AILIGHT);
  452. /*uint32_t size =*/ Read<uint32_t>(stream);
  453. l->mName = Read<aiString>(stream);
  454. l->mType = (aiLightSourceType)Read<unsigned int>(stream);
  455. if (l->mType != aiLightSource_DIRECTIONAL) {
  456. l->mAttenuationConstant = Read<float>(stream);
  457. l->mAttenuationLinear = Read<float>(stream);
  458. l->mAttenuationQuadratic = Read<float>(stream);
  459. }
  460. l->mColorDiffuse = Read<aiColor3D>(stream);
  461. l->mColorSpecular = Read<aiColor3D>(stream);
  462. l->mColorAmbient = Read<aiColor3D>(stream);
  463. if (l->mType == aiLightSource_SPOT) {
  464. l->mAngleInnerCone = Read<float>(stream);
  465. l->mAngleOuterCone = Read<float>(stream);
  466. }
  467. }
  468. // -----------------------------------------------------------------------------------
  469. void AssbinImporter::ReadBinaryCamera( IOStream * stream, aiCamera* cam )
  470. {
  471. uint32_t chunkID = Read<uint32_t>(stream);
  472. ai_assert(chunkID == ASSBIN_CHUNK_AICAMERA);
  473. /*uint32_t size =*/ Read<uint32_t>(stream);
  474. cam->mName = Read<aiString>(stream);
  475. cam->mPosition = Read<aiVector3D>(stream);
  476. cam->mLookAt = Read<aiVector3D>(stream);
  477. cam->mUp = Read<aiVector3D>(stream);
  478. cam->mHorizontalFOV = Read<float>(stream);
  479. cam->mClipPlaneNear = Read<float>(stream);
  480. cam->mClipPlaneFar = Read<float>(stream);
  481. cam->mAspect = Read<float>(stream);
  482. }
  483. void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene )
  484. {
  485. uint32_t chunkID = Read<uint32_t>(stream);
  486. ai_assert(chunkID == ASSBIN_CHUNK_AISCENE);
  487. /*uint32_t size =*/ Read<uint32_t>(stream);
  488. scene->mFlags = Read<unsigned int>(stream);
  489. scene->mNumMeshes = Read<unsigned int>(stream);
  490. scene->mNumMaterials = Read<unsigned int>(stream);
  491. scene->mNumAnimations = Read<unsigned int>(stream);
  492. scene->mNumTextures = Read<unsigned int>(stream);
  493. scene->mNumLights = Read<unsigned int>(stream);
  494. scene->mNumCameras = Read<unsigned int>(stream);
  495. // Read node graph
  496. scene->mRootNode = new aiNode[1];
  497. ReadBinaryNode( stream, &scene->mRootNode, (aiNode*)NULL );
  498. // Read all meshes
  499. if (scene->mNumMeshes)
  500. {
  501. scene->mMeshes = new aiMesh*[scene->mNumMeshes];
  502. for (unsigned int i = 0; i < scene->mNumMeshes;++i) {
  503. scene->mMeshes[i] = new aiMesh();
  504. ReadBinaryMesh( stream,scene->mMeshes[i]);
  505. }
  506. }
  507. // Read materials
  508. if (scene->mNumMaterials)
  509. {
  510. scene->mMaterials = new aiMaterial*[scene->mNumMaterials];
  511. for (unsigned int i = 0; i< scene->mNumMaterials; ++i) {
  512. scene->mMaterials[i] = new aiMaterial();
  513. ReadBinaryMaterial(stream,scene->mMaterials[i]);
  514. }
  515. }
  516. // Read all animations
  517. if (scene->mNumAnimations)
  518. {
  519. scene->mAnimations = new aiAnimation*[scene->mNumAnimations];
  520. for (unsigned int i = 0; i < scene->mNumAnimations;++i) {
  521. scene->mAnimations[i] = new aiAnimation();
  522. ReadBinaryAnim(stream,scene->mAnimations[i]);
  523. }
  524. }
  525. // Read all textures
  526. if (scene->mNumTextures)
  527. {
  528. scene->mTextures = new aiTexture*[scene->mNumTextures];
  529. for (unsigned int i = 0; i < scene->mNumTextures;++i) {
  530. scene->mTextures[i] = new aiTexture();
  531. ReadBinaryTexture(stream,scene->mTextures[i]);
  532. }
  533. }
  534. // Read lights
  535. if (scene->mNumLights)
  536. {
  537. scene->mLights = new aiLight*[scene->mNumLights];
  538. for (unsigned int i = 0; i < scene->mNumLights;++i) {
  539. scene->mLights[i] = new aiLight();
  540. ReadBinaryLight(stream,scene->mLights[i]);
  541. }
  542. }
  543. // Read cameras
  544. if (scene->mNumCameras)
  545. {
  546. scene->mCameras = new aiCamera*[scene->mNumCameras];
  547. for (unsigned int i = 0; i < scene->mNumCameras;++i) {
  548. scene->mCameras[i] = new aiCamera();
  549. ReadBinaryCamera(stream,scene->mCameras[i]);
  550. }
  551. }
  552. }
  553. void AssbinImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler )
  554. {
  555. IOStream * stream = pIOHandler->Open(pFile,"rb");
  556. if (!stream)
  557. return;
  558. stream->Seek( 44, aiOrigin_CUR ); // signature
  559. /*unsigned int versionMajor =*/ Read<unsigned int>(stream);
  560. /*unsigned int versionMinor =*/ Read<unsigned int>(stream);
  561. /*unsigned int versionRevision =*/ Read<unsigned int>(stream);
  562. /*unsigned int compileFlags =*/ Read<unsigned int>(stream);
  563. shortened = Read<uint16_t>(stream) > 0;
  564. compressed = Read<uint16_t>(stream) > 0;
  565. if (shortened)
  566. throw DeadlyImportError( "Shortened binaries are not supported!" );
  567. stream->Seek( 256, aiOrigin_CUR ); // original filename
  568. stream->Seek( 128, aiOrigin_CUR ); // options
  569. stream->Seek( 64, aiOrigin_CUR ); // padding
  570. if (compressed)
  571. {
  572. uLongf uncompressedSize = Read<uint32_t>(stream);
  573. uLongf compressedSize = static_cast<uLongf>(stream->FileSize() - stream->Tell());
  574. unsigned char * compressedData = new unsigned char[ compressedSize ];
  575. stream->Read( compressedData, 1, compressedSize );
  576. unsigned char * uncompressedData = new unsigned char[ uncompressedSize ];
  577. uncompress( uncompressedData, &uncompressedSize, compressedData, compressedSize );
  578. MemoryIOStream io( uncompressedData, uncompressedSize );
  579. ReadBinaryScene(&io,pScene);
  580. delete[] uncompressedData;
  581. delete[] compressedData;
  582. }
  583. else
  584. {
  585. ReadBinaryScene(stream,pScene);
  586. }
  587. pIOHandler->Close(stream);
  588. }
  589. #endif // !! ASSIMP_BUILD_NO_ASSBIN_IMPORTER