From 1aeaef2037c71f1312e8cfe93dacae30f870683a Mon Sep 17 00:00:00 2001 From: Gargaj Date: Wed, 6 Aug 2014 15:01:04 +0200 Subject: [PATCH] add lights and cameras --- code/AssbinLoader.cpp | 68 ++++++++++++++++++++++++++++++++++++------- code/AssbinLoader.h | 2 ++ 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/code/AssbinLoader.cpp b/code/AssbinLoader.cpp index c0777a87b..8dbbbae22 100644 --- a/code/AssbinLoader.cpp +++ b/code/AssbinLoader.cpp @@ -425,6 +425,48 @@ void AssbinImporter::ReadBinaryTexture(IOStream * stream, aiTexture* tex) } +// ----------------------------------------------------------------------------------- +void AssbinImporter::ReadBinaryLight( IOStream * stream, aiLight* l ) +{ + ai_assert( Read(stream) == ASSBIN_CHUNK_AILIGHT); + uint32_t size = Read(stream); + + l->mName = Read(stream); + l->mType = (aiLightSourceType)Read(stream); + + if (l->mType != aiLightSource_DIRECTIONAL) { + l->mAttenuationConstant = Read(stream); + l->mAttenuationLinear = Read(stream); + l->mAttenuationQuadratic = Read(stream); + } + + l->mColorDiffuse = Read(stream); + l->mColorSpecular = Read(stream); + l->mColorAmbient = Read(stream); + + if (l->mType == aiLightSource_SPOT) { + l->mAngleInnerCone = Read(stream); + l->mAngleOuterCone = Read(stream); + } + +} + +// ----------------------------------------------------------------------------------- +void AssbinImporter::ReadBinaryCamera( IOStream * stream, aiCamera* cam ) +{ + ai_assert( Read(stream) == ASSBIN_CHUNK_AICAMERA); + uint32_t size = Read(stream); + + cam->mName = Read(stream); + cam->mPosition = Read(stream); + cam->mLookAt = Read(stream); + cam->mUp = Read(stream); + cam->mHorizontalFOV = Read(stream); + cam->mClipPlaneNear = Read(stream); + cam->mClipPlaneFar = Read(stream); + cam->mAspect = Read(stream); +} + void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene ) { ai_assert( Read(stream) == ASSBIN_CHUNK_AISCENE); @@ -482,19 +524,25 @@ void AssbinImporter::ReadBinaryScene( IOStream * stream, aiScene* scene ) } } -/* // Read lights - for (unsigned int i = 0; i < scene->mNumLights;++i) { - const aiLight* l = scene->mLights[i]; - ReadBinaryLight(stream,l); - } + if (scene->mNumLights) + { + scene->mLights = new aiLight*[scene->mNumLights]; + for (unsigned int i = 0; i < scene->mNumLights;++i) { + scene->mLights[i] = new aiLight(); + ReadBinaryLight(stream,scene->mLights[i]); + } + } // Read cameras - for (unsigned int i = 0; i < scene->mNumCameras;++i) { - const aiCamera* cam = scene->mCameras[i]; - ReadBinaryCamera(stream,cam); - } -*/ + if (scene->mNumCameras) + { + scene->mCameras = new aiCamera*[scene->mNumCameras]; + for (unsigned int i = 0; i < scene->mNumCameras;++i) { + scene->mCameras[i] = new aiCamera(); + ReadBinaryCamera(stream,scene->mCameras[i]); + } + } } diff --git a/code/AssbinLoader.h b/code/AssbinLoader.h index a1b2a71d6..f4e6e059a 100644 --- a/code/AssbinLoader.h +++ b/code/AssbinLoader.h @@ -83,6 +83,8 @@ public: void ReadBinaryNodeAnim(IOStream * stream, aiNodeAnim* nd); void ReadBinaryAnim( IOStream * stream, aiAnimation* anim ); void ReadBinaryTexture(IOStream * stream, aiTexture* tex); + void ReadBinaryLight( IOStream * stream, aiLight* l ); + void ReadBinaryCamera( IOStream * stream, aiCamera* cam ); }; } // end of namespace Assimp