AssbinLoader.cpp 19 KB

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