1/*
2---------------------------------------------------------------------------
3Open Asset Import Library (assimp)
4---------------------------------------------------------------------------
5
6Copyright (c) 2006-2017, assimp team
7
8
9All rights reserved.
10
11Redistribution and use of this software in source and binary forms,
12with or without modification, are permitted provided that the following
13conditions are met:
14
15* Redistributions of source code must retain the above
16 copyright notice, this list of conditions and the
17 following disclaimer.
18
19* Redistributions in binary form must reproduce the above
20 copyright notice, this list of conditions and the
21 following disclaimer in the documentation and/or other
22 materials provided with the distribution.
23
24* Neither the name of the assimp team, nor the names of its
25 contributors may be used to endorse or promote products
26 derived from this software without specific prior
27 written permission of the assimp team.
28
29THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40---------------------------------------------------------------------------
41*/
42
43/** @file AssbinLoader.cpp
44 * @brief Implementation of the .assbin importer class
45 *
46 * see assbin_chunks.h
47 */
48
49#ifndef ASSIMP_BUILD_NO_ASSBIN_IMPORTER
50
51// internal headers
52#include "AssbinLoader.h"
53#include "assbin_chunks.h"
54#include "MemoryIOWrapper.h"
55#include <assimp/mesh.h>
56#include <assimp/anim.h>
57#include <assimp/scene.h>
58#include <assimp/importerdesc.h>
59
60#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
61# include <zlib.h>
62#else
63# include <contrib/zlib/zlib.h>
64#endif
65
66using namespace Assimp;
67
68static const aiImporterDesc desc = {
69 ".assbin Importer",
70 "Gargaj / Conspiracy",
71 "",
72 "",
73 aiImporterFlags_SupportBinaryFlavour | aiImporterFlags_SupportCompressedFlavour,
74 0,
75 0,
76 0,
77 0,
78 "assbin"
79};
80
81const aiImporterDesc* AssbinImporter::GetInfo() const
82{
83 return &desc;
84}
85
86bool AssbinImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool /*checkSig*/ ) const
87{
88 IOStream * in = pIOHandler->Open(pFile);
89 if (!in)
90 return false;
91
92 char s[32];
93 in->Read( s, sizeof(char), 32 );
94
95 pIOHandler->Close(in);
96
97 return strncmp( s, "ASSIMP.binary-dump.", 19 ) == 0;
98}
99
100template <typename T>
101T Read(IOStream * stream)
102{
103 T t;
104 stream->Read( &t, sizeof(T), 1 );
105 return t;
106}
107
108template <>
109aiVector3D Read<aiVector3D>(IOStream * stream)
110{
111 aiVector3D v;
112 v.x = Read<float>(stream);
113 v.y = Read<float>(stream);
114 v.z = Read<float>(stream);
115 return v;
116}
117
118template <>
119aiColor4D Read<aiColor4D>(IOStream * stream)
120{
121 aiColor4D c;
122 c.r = Read<float>(stream);
123 c.g = Read<float>(stream);
124 c.b = Read<float>(stream);
125 c.a = Read<float>(stream);
126 return c;
127}
128
129template <>
130aiQuaternion Read<aiQuaternion>(IOStream * stream)
131{
132 aiQuaternion v;
133 v.w = Read<float>(stream);
134 v.x = Read<float>(stream);
135 v.y = Read<float>(stream);
136 v.z = Read<float>(stream);
137 return v;
138}
139
140template <>
141aiString Read<aiString>(IOStream * stream)
142{
143 aiString s;
144 stream->Read(&s.length,4,1);
145 stream->Read(s.data,s.length,1);
146 s.data[s.length] = 0;
147 return s;
148}
149
150template <>
151aiVertexWeight Read<aiVertexWeight>(IOStream * stream)
152{
153 aiVertexWeight w;
154 w.mVertexId = Read<unsigned int>(stream);
155 w.mWeight = Read<float>(stream);
156 return w;
157}
158
159template <>
160aiMatrix4x4 Read<aiMatrix4x4>(IOStream * stream)
161{
162 aiMatrix4x4 m;
163 for (unsigned int i = 0; i < 4;++i) {
164 for (unsigned int i2 = 0; i2 < 4;++i2) {
165 m[i][i2] = Read<float>(stream);
166 }
167 }
168 return m;
169}
170
171template <>
172aiVectorKey Read<aiVectorKey>(IOStream * stream)
173{
174 aiVectorKey v;
175 v.mTime = Read<double>(stream);
176 v.mValue = Read<aiVector3D>(stream);
177 return v;
178}
179
180template <>
181aiQuatKey Read<aiQuatKey>(IOStream * stream)
182{
183 aiQuatKey v;
184 v.mTime = Read<double>(stream);
185 v.mValue = Read<aiQuaternion>(stream);
186 return v;
187}
188
189template <typename T>
190void ReadArray(IOStream * stream, T * out, unsigned int size)
191{
192 for (unsigned int i=0; i<size; i++) out[i] = Read<T>(stream);
193}
194
195template <typename T> void ReadBounds( IOStream * stream, T* /*p*/, unsigned int n )
196{
197 // not sure what to do here, the data isn't really useful.
198 stream->Seek( sizeof(T) * n, aiOrigin_CUR );
199}
200
201void AssbinImporter::ReadBinaryNode( IOStream * stream, aiNode** node, aiNode* parent ) {
202 uint32_t chunkID = Read<uint32_t>(stream);
203 (void)(chunkID);
204 ai_assert(chunkID == ASSBIN_CHUNK_AINODE);
205 /*uint32_t size =*/ Read<uint32_t>(stream);
206
207 *node = new aiNode();
208
209 (*node)->mName = Read<aiString>(stream);
210 (*node)->mTransformation = Read<aiMatrix4x4>(stream);
211 (*node)->mNumChildren = Read<unsigned int>(stream);
212 (*node)->mNumMeshes = Read<unsigned int>(stream);
213 unsigned int nb_metadata = Read<unsigned int>(stream);
214
215 if(parent) {
216 (*node)->mParent = parent;
217 }
218
219 if ((*node)->mNumMeshes) {
220 (*node)->mMeshes = new unsigned int[(*node)->mNumMeshes];
221 for (unsigned int i = 0; i < (*node)->mNumMeshes; ++i) {
222 (*node)->mMeshes[i] = Read<unsigned int>(stream);
223 }
224 }
225
226 if ((*node)->mNumChildren) {
227 (*node)->mChildren = new aiNode*[(*node)->mNumChildren];
228 for (unsigned int i = 0; i < (*node)->mNumChildren; ++i) {
229 ReadBinaryNode( stream, &(*node)->mChildren[i], *node );
230 }
231 }
232
233 if ( nb_metadata > 0 ) {
234 (*node)->mMetaData = aiMetadata::Alloc(nb_metadata);
235 for (unsigned int i = 0; i < nb_metadata; ++i) {
236 (*node)->mMetaData->mKeys[i] = Read<aiString>(stream);
237 (*node)->mMetaData->mValues[i].mType = (aiMetadataType) Read<uint16_t>(stream);
238 void* data( nullptr );
239
240 switch ((*node)->mMetaData->mValues[i].mType) {
241 case AI_BOOL:
242 data = new bool(Read<bool>(stream));
243 break;
244 case AI_INT32:
245 data = new int32_t(Read<int32_t>(stream));
246 break;
247 case AI_UINT64:
248 data = new uint64_t(Read<uint64_t>(stream));
249 break;
250 case AI_FLOAT:
251 data = new float(Read<float>(stream));
252 break;
253 case AI_DOUBLE:
254 data = new double(Read<double>(stream));
255 break;
256 case AI_AISTRING:
257 data = new aiString(Read<aiString>(stream));
258 break;
259 case AI_AIVECTOR3D:
260 data = new aiVector3D(Read<aiVector3D>(stream));
261 break;
262#ifndef SWIG
263 case FORCE_32BIT:
264#endif // SWIG
265 default:
266 break;
267 }
268
269 (*node)->mMetaData->mValues[i].mData = data;
270 }
271 }
272}
273
274// -----------------------------------------------------------------------------------
275void AssbinImporter::ReadBinaryBone( IOStream * stream, aiBone* b )
276{
277 uint32_t chunkID = Read<uint32_t>(stream);
278 (void)(chunkID);
279 ai_assert(chunkID == ASSBIN_CHUNK_AIBONE);
280 /*uint32_t size =*/ Read<uint32_t>(stream);
281
282 b->mName = Read<aiString>(stream);
283 b->mNumWeights = Read<unsigned int>(stream);
284 b->mOffsetMatrix = Read<aiMatrix4x4>(stream);
285
286 // for the moment we write dumb min/max values for the bones, too.
287 // maybe I'll add a better, hash-like solution later
288 if (shortened)
289 {
290 ReadBounds(stream,b->mWeights,b->mNumWeights);
291 } // else write as usual
292 else
293 {
294 b->mWeights = new aiVertexWeight[b->mNumWeights];
295 ReadArray<aiVertexWeight>(stream,b->mWeights,b->mNumWeights);
296 }
297}
298
299
300void AssbinImporter::ReadBinaryMesh( IOStream * stream, aiMesh* mesh )
301{
302 uint32_t chunkID = Read<uint32_t>(stream);
303 (void)(chunkID);
304 ai_assert(chunkID == ASSBIN_CHUNK_AIMESH);
305 /*uint32_t size =*/ Read<uint32_t>(stream);
306
307 mesh->mPrimitiveTypes = Read<unsigned int>(stream);
308 mesh->mNumVertices = Read<unsigned int>(stream);
309 mesh->mNumFaces = Read<unsigned int>(stream);
310 mesh->mNumBones = Read<unsigned int>(stream);
311 mesh->mMaterialIndex = Read<unsigned int>(stream);
312
313 // first of all, write bits for all existent vertex components
314 unsigned int c = Read<unsigned int>(stream);
315
316 if (c & ASSBIN_MESH_HAS_POSITIONS)
317 {
318 if (shortened) {
319 ReadBounds(stream,mesh->mVertices,mesh->mNumVertices);
320 } // else write as usual
321 else
322 {
323 mesh->mVertices = new aiVector3D[mesh->mNumVertices];
324 ReadArray<aiVector3D>(stream,mesh->mVertices,mesh->mNumVertices);
325 }
326 }
327 if (c & ASSBIN_MESH_HAS_NORMALS)
328 {
329 if (shortened) {
330 ReadBounds(stream,mesh->mNormals,mesh->mNumVertices);
331 } // else write as usual
332 else
333 {
334 mesh->mNormals = new aiVector3D[mesh->mNumVertices];
335 ReadArray<aiVector3D>(stream,mesh->mNormals,mesh->mNumVertices);
336 }
337 }
338 if (c & ASSBIN_MESH_HAS_TANGENTS_AND_BITANGENTS)
339 {
340 if (shortened) {
341 ReadBounds(stream,mesh->mTangents,mesh->mNumVertices);
342 ReadBounds(stream,mesh->mBitangents,mesh->mNumVertices);
343 } // else write as usual
344 else
345 {
346 mesh->mTangents = new aiVector3D[mesh->mNumVertices];
347 ReadArray<aiVector3D>(stream,mesh->mTangents,mesh->mNumVertices);
348 mesh->mBitangents = new aiVector3D[mesh->mNumVertices];
349 ReadArray<aiVector3D>(stream,mesh->mBitangents,mesh->mNumVertices);
350 }
351 }
352 for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_COLOR_SETS;++n)
353 {
354 if (!(c & ASSBIN_MESH_HAS_COLOR(n)))
355 break;
356
357 if (shortened)
358 {
359 ReadBounds(stream,mesh->mColors[n],mesh->mNumVertices);
360 } // else write as usual
361 else
362 {
363 mesh->mColors[n] = new aiColor4D[mesh->mNumVertices];
364 ReadArray<aiColor4D>(stream,mesh->mColors[n],mesh->mNumVertices);
365 }
366 }
367 for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_TEXTURECOORDS;++n)
368 {
369 if (!(c & ASSBIN_MESH_HAS_TEXCOORD(n)))
370 break;
371
372 // write number of UV components
373 mesh->mNumUVComponents[n] = Read<unsigned int>(stream);
374
375 if (shortened) {
376 ReadBounds(stream,mesh->mTextureCoords[n],mesh->mNumVertices);
377 } // else write as usual
378 else
379 {
380 mesh->mTextureCoords[n] = new aiVector3D[mesh->mNumVertices];
381 ReadArray<aiVector3D>(stream,mesh->mTextureCoords[n],mesh->mNumVertices);
382 }
383 }
384
385 // write faces. There are no floating-point calculations involved
386 // in these, so we can write a simple hash over the face data
387 // to the dump file. We generate a single 32 Bit hash for 512 faces
388 // using Assimp's standard hashing function.
389 if (shortened) {
390 Read<unsigned int>(stream);
391 }
392 else // else write as usual
393 {
394 // if there are less than 2^16 vertices, we can simply use 16 bit integers ...
395 mesh->mFaces = new aiFace[mesh->mNumFaces];
396 for (unsigned int i = 0; i < mesh->mNumFaces;++i) {
397 aiFace& f = mesh->mFaces[i];
398
399 static_assert(AI_MAX_FACE_INDICES <= 0xffff, "AI_MAX_FACE_INDICES <= 0xffff");
400 f.mNumIndices = Read<uint16_t>(stream);
401 f.mIndices = new unsigned int[f.mNumIndices];
402
403 for (unsigned int a = 0; a < f.mNumIndices;++a) {
404 if (mesh->mNumVertices < (1u<<16))
405 {
406 f.mIndices[a] = Read<uint16_t>(stream);
407 }
408 else
409 {
410 f.mIndices[a] = Read<unsigned int>(stream);
411 }
412 }
413 }
414 }
415
416 // write bones
417 if (mesh->mNumBones) {
418 mesh->mBones = new C_STRUCT aiBone*[mesh->mNumBones];
419 for (unsigned int a = 0; a < mesh->mNumBones;++a) {
420 mesh->mBones[a] = new aiBone();
421 ReadBinaryBone(stream,mesh->mBones[a]);
422 }
423 }
424}
425
426void AssbinImporter::ReadBinaryMaterialProperty(IOStream * stream, aiMaterialProperty* prop)
427{
428 uint32_t chunkID = Read<uint32_t>(stream);
429 (void)(chunkID);
430 ai_assert(chunkID == ASSBIN_CHUNK_AIMATERIALPROPERTY);
431 /*uint32_t size =*/ Read<uint32_t>(stream);
432
433 prop->mKey = Read<aiString>(stream);
434 prop->mSemantic = Read<unsigned int>(stream);
435 prop->mIndex = Read<unsigned int>(stream);
436
437 prop->mDataLength = Read<unsigned int>(stream);
438 prop->mType = (aiPropertyTypeInfo)Read<unsigned int>(stream);
439 prop->mData = new char [ prop->mDataLength ];
440 stream->Read(prop->mData,1,prop->mDataLength);
441}
442
443// -----------------------------------------------------------------------------------
444void AssbinImporter::ReadBinaryMaterial(IOStream * stream, aiMaterial* mat)
445{
446 uint32_t chunkID = Read<uint32_t>(stream);
447 (void)(chunkID);
448 ai_assert(chunkID == ASSBIN_CHUNK_AIMATERIAL);
449 /*uint32_t size =*/ Read<uint32_t>(stream);
450
451 mat->mNumAllocated = mat->mNumProperties = Read<unsigned int>(stream);
452 if (mat->mNumProperties)
453 {
454 if (mat->mProperties)
455 {
456 delete[] mat->mProperties;
457 }
458 mat->mProperties = new aiMaterialProperty*[mat->mNumProperties];
459 for (unsigned int i = 0; i < mat->mNumProperties;++i) {
460 mat->mProperties[i] = new aiMaterialProperty();
461 ReadBinaryMaterialProperty( stream, mat->mProperties[i]);
462 }
463 }
464}
465
466// -----------------------------------------------------------------------------------
467void AssbinImporter::ReadBinaryNodeAnim(IOStream * stream, aiNodeAnim* nd)
468{
469 uint32_t chunkID = Read<uint32_t>(stream);
470 (void)(chunkID);
471 ai_assert(chunkID == ASSBIN_CHUNK_AINODEANIM);
472 /*uint32_t size =*/ Read<uint32_t>(stream);
473
474 nd->mNodeName = Read<aiString>(stream);
475 nd->mNumPositionKeys = Read<unsigned int>(stream);
476 nd->mNumRotationKeys = Read<unsigned int>(stream);
477 nd->mNumScalingKeys = Read<unsigned int>(stream);
478 nd->mPreState = (aiAnimBehaviour)Read<unsigned int>(stream);
479 nd->mPostState = (aiAnimBehaviour)Read<unsigned int>(stream);
480
481 if (nd->mNumPositionKeys) {
482 if (shortened) {
483 ReadBounds(stream,nd->mPositionKeys,nd->mNumPositionKeys);
484
485 } // else write as usual
486 else {
487 nd->mPositionKeys = new aiVectorKey[nd->mNumPositionKeys];
488 ReadArray<aiVectorKey>(stream,nd->mPositionKeys,nd->mNumPositionKeys);
489 }
490 }
491 if (nd->mNumRotationKeys) {
492 if (shortened) {
493 ReadBounds(stream,nd->mRotationKeys,nd->mNumRotationKeys);
494
495 } // else write as usual
496 else
497 {
498 nd->mRotationKeys = new aiQuatKey[nd->mNumRotationKeys];
499 ReadArray<aiQuatKey>(stream,nd->mRotationKeys,nd->mNumRotationKeys);
500 }
501 }
502 if (nd->mNumScalingKeys) {
503 if (shortened) {
504 ReadBounds(stream,nd->mScalingKeys,nd->mNumScalingKeys);
505
506 } // else write as usual
507 else
508 {
509 nd->mScalingKeys = new aiVectorKey[nd->mNumScalingKeys];
510 ReadArray<aiVectorKey>(stream,nd->mScalingKeys,nd->mNumScalingKeys);
511 }
512 }
513}
514
515
516// -----------------------------------------------------------------------------------
517void AssbinImporter::ReadBinaryAnim( IOStream * stream, aiAnimation* anim )
518{
519 uint32_t chunkID = Read<uint32_t>(stream);
520 (void)(chunkID);
521 ai_assert(chunkID == ASSBIN_CHUNK_AIANIMATION);
522 /*uint32_t size =*/ Read<uint32_t>(stream);
523
524 anim->mName = Read<aiString> (stream);
525 anim->mDuration = Read<double> (stream);
526 anim->mTicksPerSecond = Read<double> (stream);
527 anim->mNumChannels = Read<unsigned int>(stream);
528
529 if (anim->mNumChannels)
530 {
531 anim->mChannels = new aiNodeAnim*[ anim->mNumChannels ];
532 for (unsigned int a = 0; a < anim->mNumChannels;++a) {
533 anim->mChannels[a] = new aiNodeAnim();
534 ReadBinaryNodeAnim(stream,anim->mChannels[a]);
535 }
536 }
537}
538
539void AssbinImporter::ReadBinaryTexture(IOStream * stream, aiTexture* tex)
540{
541 uint32_t chunkID = Read<uint32_t>(stream);
542 (void)(chunkID);
543 ai_assert(chunkID == ASSBIN_CHUNK_AITEXTURE);
544 /*uint32_t size =*/ Read<uint32_t>(stream);
545
546 tex->mWidth = Read<unsigned int>(stream);
547 tex->mHeight = Read<unsigned int>(stream);
548 stream->Read( tex->achFormatHint, sizeof(char), 4 );
549
550 if(!shortened) {
551 if (!tex->mHeight) {
552 tex->pcData = new aiTexel[ tex->mWidth ];
553 stream->Read(tex->pcData,1,tex->mWidth);
554 }
555 else {
556 tex->pcData = new aiTexel[ tex->mWidth*tex->mHeight ];
557 stream->Read(tex->pcData,1,tex->mWidth*tex->mHeight*4);
558 }
559 }
560
561}
562
563// -----------------------------------------------------------------------------------
564void AssbinImporter::ReadBinaryLight( IOStream * stream, aiLight* l )
565{
566 uint32_t chunkID = Read<uint32_t>(stream);
567 (void)(chunkID);
568 ai_assert(chunkID == ASSBIN_CHUNK_AILIGHT);
569 /*uint32_t size =*/ Read<uint32_t>(stream);
570
571 l->mName = Read<aiString>(stream);
572 l->mType = (aiLightSourceType)Read<unsigned int>(stream);
573
574 if (l->mType != aiLightSource_DIRECTIONAL) {
575 l->mAttenuationConstant = Read<float>(stream);
576 l->mAttenuationLinear = Read<float>(stream);
577 l->mAttenuationQuadratic = Read<float>(stream);
578 }
579
580 l->mColorDiffuse = Read<aiColor3D>(stream);
581 l->mColorSpecular = Read<aiColor3D>(stream);
582 l->mColorAmbient = Read<aiColor3D>(stream);
583
584 if (l->mType == aiLightSource_SPOT) {
585 l->mAngleInnerCone = Read<float>(stream);
586 l->mAngleOuterCone = Read<float>(stream);
587 }
588
589}
590
591// -----------------------------------------------------------------------------------
592void AssbinImporter::ReadBinaryCamera( IOStream * stream, aiCamera* cam )
593{
594 uint32_t chunkID = Read<uint32_t>(stream);
595 (void)(chunkID);
596 ai_assert(chunkID == ASSBIN_CHUNK_AICAMERA);
597 /*uint32_t size =*/ Read<uint32_t>(stream);
598
599 cam->mName = Read<aiString>(stream);
600 cam->mPosition = Read<aiVector3D>(stream);
601 cam->mLookAt = Read<aiVector3D>(stream);
602 cam->mUp = Read<aiVector3D>(stream);
603 cam->mHorizontalFOV = Read<float>(stream);
604 cam->mClipPlaneNear = Read<float>(stream);
605 cam->mClipPlaneFar = Read<float>(stream);
606 cam->mAspect = Read<float>(stream);
607}
608
609void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene )
610{
611 uint32_t chunkID = Read<uint32_t>(stream);
612 (void)(chunkID);
613 ai_assert(chunkID == ASSBIN_CHUNK_AISCENE);
614 /*uint32_t size =*/ Read<uint32_t>(stream);
615
616 scene->mFlags = Read<unsigned int>(stream);
617 scene->mNumMeshes = Read<unsigned int>(stream);
618 scene->mNumMaterials = Read<unsigned int>(stream);
619 scene->mNumAnimations = Read<unsigned int>(stream);
620 scene->mNumTextures = Read<unsigned int>(stream);
621 scene->mNumLights = Read<unsigned int>(stream);
622 scene->mNumCameras = Read<unsigned int>(stream);
623
624 // Read node graph
625 scene->mRootNode = new aiNode[1];
626 ReadBinaryNode( stream, &scene->mRootNode, (aiNode*)NULL );
627
628 // Read all meshes
629 if (scene->mNumMeshes)
630 {
631 scene->mMeshes = new aiMesh*[scene->mNumMeshes];
632 for (unsigned int i = 0; i < scene->mNumMeshes;++i) {
633 scene->mMeshes[i] = new aiMesh();
634 ReadBinaryMesh( stream,scene->mMeshes[i]);
635 }
636 }
637
638 // Read materials
639 if (scene->mNumMaterials)
640 {
641 scene->mMaterials = new aiMaterial*[scene->mNumMaterials];
642 for (unsigned int i = 0; i< scene->mNumMaterials; ++i) {
643 scene->mMaterials[i] = new aiMaterial();
644 ReadBinaryMaterial(stream,scene->mMaterials[i]);
645 }
646 }
647
648 // Read all animations
649 if (scene->mNumAnimations)
650 {
651 scene->mAnimations = new aiAnimation*[scene->mNumAnimations];
652 for (unsigned int i = 0; i < scene->mNumAnimations;++i) {
653 scene->mAnimations[i] = new aiAnimation();
654 ReadBinaryAnim(stream,scene->mAnimations[i]);
655 }
656 }
657
658 // Read all textures
659 if (scene->mNumTextures)
660 {
661 scene->mTextures = new aiTexture*[scene->mNumTextures];
662 for (unsigned int i = 0; i < scene->mNumTextures;++i) {
663 scene->mTextures[i] = new aiTexture();
664 ReadBinaryTexture(stream,scene->mTextures[i]);
665 }
666 }
667
668 // Read lights
669 if (scene->mNumLights)
670 {
671 scene->mLights = new aiLight*[scene->mNumLights];
672 for (unsigned int i = 0; i < scene->mNumLights;++i) {
673 scene->mLights[i] = new aiLight();
674 ReadBinaryLight(stream,scene->mLights[i]);
675 }
676 }
677
678 // Read cameras
679 if (scene->mNumCameras)
680 {
681 scene->mCameras = new aiCamera*[scene->mNumCameras];
682 for (unsigned int i = 0; i < scene->mNumCameras;++i) {
683 scene->mCameras[i] = new aiCamera();
684 ReadBinaryCamera(stream,scene->mCameras[i]);
685 }
686 }
687
688}
689
690void AssbinImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler )
691{
692 IOStream * stream = pIOHandler->Open(pFile,"rb");
693 if (!stream)
694 return;
695
696 stream->Seek( 44, aiOrigin_CUR ); // signature
697
698 /*unsigned int versionMajor =*/ Read<unsigned int>(stream);
699 /*unsigned int versionMinor =*/ Read<unsigned int>(stream);
700 /*unsigned int versionRevision =*/ Read<unsigned int>(stream);
701 /*unsigned int compileFlags =*/ Read<unsigned int>(stream);
702
703 shortened = Read<uint16_t>(stream) > 0;
704 compressed = Read<uint16_t>(stream) > 0;
705
706 if (shortened)
707 throw DeadlyImportError( "Shortened binaries are not supported!" );
708
709 stream->Seek( 256, aiOrigin_CUR ); // original filename
710 stream->Seek( 128, aiOrigin_CUR ); // options
711 stream->Seek( 64, aiOrigin_CUR ); // padding
712
713 if (compressed)
714 {
715 uLongf uncompressedSize = Read<uint32_t>(stream);
716 uLongf compressedSize = static_cast<uLongf>(stream->FileSize() - stream->Tell());
717
718 unsigned char * compressedData = new unsigned char[ compressedSize ];
719 stream->Read( compressedData, 1, compressedSize );
720
721 unsigned char * uncompressedData = new unsigned char[ uncompressedSize ];
722
723 uncompress( uncompressedData, &uncompressedSize, compressedData, compressedSize );
724
725 MemoryIOStream io( uncompressedData, uncompressedSize );
726
727 ReadBinaryScene(&io,pScene);
728
729 delete[] uncompressedData;
730 delete[] compressedData;
731 }
732 else
733 {
734 ReadBinaryScene(stream,pScene);
735 }
736
737 pIOHandler->Close(stream);
738}
739
740#endif // !! ASSIMP_BUILD_NO_ASSBIN_IMPORTER
741