From fb4eb83e84119ab42bae5ad2ad6c7430868fcc0a Mon Sep 17 00:00:00 2001 From: wise86Android Date: Sun, 17 May 2015 20:54:45 +0200 Subject: [PATCH 1/6] add the ability to export cameras information in a collada file --- code/ColladaExporter.cpp | 64 +++++++++++++++++++++-- code/ColladaExporter.h | 5 ++ test/CMakeLists.txt | 1 + test/models/Collada/cameras.dae | 93 +++++++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 test/models/Collada/cameras.dae diff --git a/code/ColladaExporter.cpp b/code/ColladaExporter.cpp index 078ac0a56..c5d904c07 100644 --- a/code/ColladaExporter.cpp +++ b/code/ColladaExporter.cpp @@ -127,6 +127,7 @@ void ColladaExporter::WriteFile() WriteTextures(); WriteHeader(); + WriteCamerasLibrary(); WriteMaterials(); WriteGeometryLibrary(); @@ -286,6 +287,61 @@ void ColladaExporter::WriteTextures() { } } +// ------------------------------------------------------------------------------------------------ +// Write the embedded textures +void ColladaExporter::WriteCamerasLibrary() { + if(mScene->HasCameras()) { + + mOutput << startstr << "" << endstr; + PushTag(); + + for( size_t a = 0; a < mScene->mNumCameras; ++a) + WriteCamera( a); + + PopTag(); + mOutput << startstr << "" << endstr; + + } +} + +void ColladaExporter::WriteCamera(size_t pIndex){ + + const aiCamera *cam = mScene->mCameras[pIndex]; + const std::string idstrEscaped = XMLEscape(cam->mName.C_Str()); + + mOutput << startstr << "" << endstr; + PushTag(); + mOutput << startstr << "" << endstr; + PushTag(); + mOutput << startstr << "" << endstr; + PushTag(); + //assimp doesn't support the import of orthographic cameras! se we write + //always perspective + mOutput << startstr << "" << endstr; + PushTag(); + mOutput << startstr << ""<< + AI_RAD_TO_DEG(cam->mHorizontalFOV) + <<"" << endstr; + mOutput << startstr << "" + << cam->mAspect + << "" << endstr; + mOutput << startstr << "" + << cam->mClipPlaneNear + << "" << endstr; + mOutput << startstr << "" + << cam->mClipPlaneFar + << "" << endstr; + PopTag(); + mOutput << startstr << "" << endstr; + PopTag(); + mOutput << startstr << "" << endstr; + PopTag(); + mOutput << startstr << "" << endstr; + PopTag(); + mOutput << startstr << "" << endstr; + +} + // ------------------------------------------------------------------------------------------------ // Reads a single surface entry from the given material keys void ColladaExporter::ReadMaterialSurface( Surface& poSurface, const aiMaterial* pSrcMat, aiTextureType pTexture, const char* pKey, size_t pType, size_t pIndex) @@ -847,6 +903,9 @@ void ColladaExporter::WriteNode(aiNode* pNode) mOutput << mat.d1 << " " << mat.d2 << " " << mat.d3 << " " << mat.d4; mOutput << "" << endstr; + if(pNode->mNumMeshes==0){ + mOutput << startstr <<"" << endstr; + }else // instance every geometry for( size_t a = 0; a < pNode->mNumMeshes; ++a ) { @@ -854,9 +913,8 @@ void ColladaExporter::WriteNode(aiNode* pNode) // do not instanciate mesh if empty. I wonder how this could happen if( mesh->mNumFaces == 0 || mesh->mNumVertices == 0 ) continue; - - mOutput << startstr << "mMeshes[a])) << "\">" << endstr; - PushTag(); + mOutput << startstr << "mMeshes[a])) << "\">" << endstr; + PushTag(); mOutput << startstr << "" << endstr; PushTag(); mOutput << startstr << "" << endstr; diff --git a/code/ColladaExporter.h b/code/ColladaExporter.h index 9456508ce..4ded0d13d 100644 --- a/code/ColladaExporter.h +++ b/code/ColladaExporter.h @@ -83,6 +83,11 @@ protected: /// Writes the material setup void WriteMaterials(); + /// Writes the cameras library + void WriteCamerasLibrary(); + + void WriteCamera(size_t pIndex); + /// Writes the geometry library void WriteGeometryLibrary(); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f4b67bad6..9053f66d8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -40,6 +40,7 @@ SET( TEST_SRCS unit/utTriangulate.cpp unit/utVertexTriangleAdjacency.cpp unit/utNoBoostTest.cpp + unit/utColladaExportCamera.cpp ) SOURCE_GROUP( tests FILES ${TEST_SRCS} ) diff --git a/test/models/Collada/cameras.dae b/test/models/Collada/cameras.dae new file mode 100644 index 000000000..d514b0f3d --- /dev/null +++ b/test/models/Collada/cameras.dae @@ -0,0 +1,93 @@ + + + + + Blender User + Blender 2.74.0 commit date:2015-03-31, commit time:13:39, hash:000dfc0 + + 2015-05-17T19:24:51 + 2015-05-17T19:24:51 + + Z_UP + + + + + + + 49.13434 + 1.777778 + 0.1 + 100 + + + + + + 0 + 0 + 0 + + + + + + + + 3 + 1.777778 + 0.1 + 100 + + + + + + 0 + 0 + 0 + + + + + + + + 29.86284 + 1.777778 + 0.1 + 50 + + + + + + 0 + 0 + 0 + + + + + + + + + + 7.54979e-8 0 1 10 0 1 0 0 -1 0 7.54979e-8 0 0 0 0 1 + + + + 7.54979e-8 0 -1 -10 0 1 0 0 1 0 7.54979e-8 0 0 0 0 1 + + + + 3.09086e-8 -1 1.58933e-8 0 -3.09086e-8 1.58933e-8 1 5 -1 -3.09086e-8 -3.09086e-8 0 0 0 0 1 + + + + + + + + From 08499dbd0b722089b3dcfbd95c0ce5882a1b20c2 Mon Sep 17 00:00:00 2001 From: wise86Android Date: Sun, 17 May 2015 21:25:47 +0200 Subject: [PATCH 2/6] add test file --- test/unit/utColladaExportCamera.cpp | 80 +++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 test/unit/utColladaExportCamera.cpp diff --git a/test/unit/utColladaExportCamera.cpp b/test/unit/utColladaExportCamera.cpp new file mode 100644 index 000000000..c647684b6 --- /dev/null +++ b/test/unit/utColladaExportCamera.cpp @@ -0,0 +1,80 @@ +/* + * ColladaCameraExporter.cpp + * + * Created on: May 17, 2015 + * Author: wise + */ + + +#include "UnitTestPCH.h" + +#include +#include +#include +#include + +#ifndef ASSIMP_BUILD_NO_EXPORT + +class ColladaExportCamera : public ::testing::Test { +public: + + virtual void SetUp() + { + ex = new Assimp::Exporter(); + im = new Assimp::Importer(); + + } + + virtual void TearDown() + { + delete ex; + delete im; + } + +protected: + + + Assimp::Exporter* ex; + Assimp::Importer* im; +}; + +// ------------------------------------------------------------------------------------------------ +TEST_F(ColladaExportCamera, testExportCamera) +{ + const char* file = "cameraExp.dae"; + + const aiScene* pTest = im->ReadFile("../test/models/Collada/cameras.dae",0); + ASSERT_TRUE(pTest!=NULL); + ASSERT_TRUE(pTest->HasCameras()); + + + EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada",file)); + + const aiScene* imported = im->ReadFile(file,0); + + ASSERT_TRUE(imported!=NULL); + + EXPECT_TRUE(imported->HasCameras()); + EXPECT_EQ(pTest->mNumCameras,imported->mNumCameras); + + for(size_t i=0; i< pTest->mNumCameras;i++){ + + const aiCamera *orig = pTest->mCameras[i]; + const aiCamera *read = imported->mCameras[i]; + + EXPECT_TRUE(orig->mName==read->mName); + EXPECT_FLOAT_EQ(orig->mHorizontalFOV,read->mHorizontalFOV); + EXPECT_FLOAT_EQ(orig->mClipPlaneNear,read->mClipPlaneNear); + EXPECT_FLOAT_EQ(orig->mClipPlaneFar,read->mClipPlaneFar); + + EXPECT_FLOAT_EQ(orig->mPosition.x,read->mPosition.x); + EXPECT_FLOAT_EQ(orig->mPosition.y,read->mPosition.y); + EXPECT_FLOAT_EQ(orig->mPosition.z,read->mPosition.z); + } + +} + + +#endif + + From 2c194f629a93f6809efd75591f7b6a791277efaa Mon Sep 17 00:00:00 2001 From: wise86Android Date: Tue, 19 May 2015 21:57:51 +0200 Subject: [PATCH 3/6] fix macro for be uesed with expression --- code/ColladaExporter.cpp | 140 ++++++++++- code/ColladaExporter.h | 12 + include/assimp/defs.h | 6 +- test/CMakeLists.txt | 1 + test/models/Collada/lights.dae | 380 +++++++++++++++++++++++++++++ test/unit/utColladaExportLight.cpp | 81 ++++++ 6 files changed, 616 insertions(+), 4 deletions(-) create mode 100644 test/models/Collada/lights.dae create mode 100644 test/unit/utColladaExportLight.cpp diff --git a/code/ColladaExporter.cpp b/code/ColladaExporter.cpp index c5d904c07..ba3530491 100644 --- a/code/ColladaExporter.cpp +++ b/code/ColladaExporter.cpp @@ -51,7 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "XMLTools.h" #include "../include/assimp/IOSystem.hpp" #include "../include/assimp/Exporter.hpp" -#include "../include/assimp/scene.h" +#include "../include/assimp/scene.h" #include "Exceptional.h" @@ -128,6 +128,7 @@ void ColladaExporter::WriteFile() WriteHeader(); WriteCamerasLibrary(); + WriteLightsLibrary(); WriteMaterials(); WriteGeometryLibrary(); @@ -342,6 +343,143 @@ void ColladaExporter::WriteCamera(size_t pIndex){ } + +// ------------------------------------------------------------------------------------------------ +// Write the embedded textures +void ColladaExporter::WriteLightsLibrary() { + if(mScene->HasLights()) { + + mOutput << startstr << "" << endstr; + PushTag(); + + for( size_t a = 0; a < mScene->mNumLights; ++a) + WriteLight( a); + + PopTag(); + mOutput << startstr << "" << endstr; + + } +} + +void ColladaExporter::WriteLight(size_t pIndex){ + + const aiLight *light = mScene->mLights[pIndex]; + const std::string idstrEscaped = XMLEscape(light->mName.C_Str()); + + mOutput << startstr << "" << endstr; + PushTag(); + mOutput << startstr << "" << endstr; + PushTag(); + switch(light->mType){ + case aiLightSource_AMBIENT: + WriteAmbienttLight(light); + break; + case aiLightSource_DIRECTIONAL: + WriteDirectionalLight(light); + break; + case aiLightSource_POINT: + WritePointLight(light); + break; + case aiLightSource_SPOT: + WriteSpotLight(light); + break; + case aiLightSource_UNDEFINED: + case _aiLightSource_Force32Bit: + break; + } + PopTag(); + mOutput << startstr << "" << endstr; + + PopTag(); + mOutput << startstr << "" << endstr; + +} + +void ColladaExporter::WritePointLight(const aiLight *const light){ + const aiColor3D &color= light->mColorDiffuse; + mOutput << startstr << "" << endstr; + PushTag(); + mOutput << startstr << "" + << color.r<<" "<" << endstr; + mOutput << startstr << "" + << light->mAttenuationConstant + <<"" << endstr; + mOutput << startstr << "" + << light->mAttenuationLinear + <<"" << endstr; + mOutput << startstr << "" + << light->mAttenuationQuadratic + <<"" << endstr; + + PopTag(); + mOutput << startstr << "" << endstr; + +} +void ColladaExporter::WriteDirectionalLight(const aiLight *const light){ + const aiColor3D &color= light->mColorDiffuse; + mOutput << startstr << "" << endstr; + PushTag(); + mOutput << startstr << "" + << color.r<<" "<" << endstr; + + PopTag(); + mOutput << startstr << "" << endstr; + +} +void ColladaExporter::WriteSpotLight(const aiLight *const light){ + /* + 1 1 1 + 1 + 0 + 0.001599967 + 45 + 0.15 + + */ + const aiColor3D &color= light->mColorDiffuse; + mOutput << startstr << "" << endstr; + PushTag(); + mOutput << startstr << "" + << color.r<<" "<" << endstr; + mOutput << startstr << "" + << light->mAttenuationConstant + <<"" << endstr; + mOutput << startstr << "" + << light->mAttenuationLinear + <<"" << endstr; + mOutput << startstr << "" + << light->mAttenuationQuadratic + <<"" << endstr; +/* mOutput << startstr << "" + << light-> + <<"" << endstr; + mOutput << startstr << "" + << light->mAttenuationLinear + <<"" << endstr; +*/ + + PopTag(); + mOutput << startstr << "" << endstr; + +} + +void ColladaExporter::WriteAmbienttLight(const aiLight *const light){ + + const aiColor3D &color= light->mColorAmbient; + mOutput << startstr << "" << endstr; + PushTag(); + mOutput << startstr << "" + << color.r<<" "<" << endstr; + + PopTag(); + mOutput << startstr << "" << endstr; +} + // ------------------------------------------------------------------------------------------------ // Reads a single surface entry from the given material keys void ColladaExporter::ReadMaterialSurface( Surface& poSurface, const aiMaterial* pSrcMat, aiTextureType pTexture, const char* pKey, size_t pType, size_t pIndex) diff --git a/code/ColladaExporter.h b/code/ColladaExporter.h index 4ded0d13d..73dc497fa 100644 --- a/code/ColladaExporter.h +++ b/code/ColladaExporter.h @@ -47,6 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../include/assimp/ai_assert.h" #include "../include/assimp/material.h" #include "../include/assimp/mesh.h" +#include "../include/assimp/light.h" #include "../include/assimp/Exporter.hpp" #include #include @@ -86,8 +87,19 @@ protected: /// Writes the cameras library void WriteCamerasLibrary(); + // Write a camera entry void WriteCamera(size_t pIndex); + /// Writes the cameras library + void WriteLightsLibrary(); + + // Write a camera entry + void WriteLight(size_t pIndex); + void WritePointLight(const aiLight *const light); + void WriteDirectionalLight(const aiLight *const light); + void WriteSpotLight(const aiLight *const light); + void WriteAmbienttLight(const aiLight *const light); + /// Writes the geometry library void WriteGeometryLibrary(); diff --git a/include/assimp/defs.h b/include/assimp/defs.h index 6b8ac3416..c21b3cf2b 100644 --- a/include/assimp/defs.h +++ b/include/assimp/defs.h @@ -209,7 +209,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if (defined(__BORLANDC__) || defined (__BCPLUSPLUS__)) #error Currently, Borland is unsupported. Feel free to port Assimp. -// "W8059 Packgröße der Struktur geändert" +// "W8059 Packgr��e der Struktur ge�ndert" #endif ////////////////////////////////////////////////////////////////////////// @@ -257,8 +257,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define AI_MATH_HALF_PI_F (AI_MATH_PI_F * 0.5f) /* Tiny macro to convert from radians to degrees and back */ -#define AI_DEG_TO_RAD(x) (x*0.0174532925f) -#define AI_RAD_TO_DEG(x) (x*57.2957795f) +#define AI_DEG_TO_RAD(x) ((x)*0.0174532925f) +#define AI_RAD_TO_DEG(x) ((x)*57.2957795f) /* Support for big-endian builds */ #if defined(__BYTE_ORDER__) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9053f66d8..287f51698 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -41,6 +41,7 @@ SET( TEST_SRCS unit/utVertexTriangleAdjacency.cpp unit/utNoBoostTest.cpp unit/utColladaExportCamera.cpp + unit/utColladaExportLight.cpp ) SOURCE_GROUP( tests FILES ${TEST_SRCS} ) diff --git a/test/models/Collada/lights.dae b/test/models/Collada/lights.dae new file mode 100644 index 000000000..9e040aac6 --- /dev/null +++ b/test/models/Collada/lights.dae @@ -0,0 +1,380 @@ + + + + + Blender User + Blender 2.74.0 commit date:2015-03-31, commit time:13:39, hash:000dfc0 + + 2015-05-17T21:55:44 + 2015-05-17T21:55:44 + + Z_UP + + + + + + 1 1 1 + 1 + 0 + 0.00111109 + + + + + 0.000999987 + 1 + 0.1 + 0.1 + 1 + 1 + 1 + 2 + 0 + 1 + 1 + 1 + 1 + 1 + 0 + 2880 + 2 + 30.002 + 1.000799 + 0.04999995 + 29.99998 + 1 + 2 + 0 + 0 + 1 + 1 + 1 + 1 + 8192 + 1 + 1 + 0 + 1 + 1 + 1 + 3 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 3 + 0.15 + 75 + 1 + 1 + 0 + 1 + 1 + 0 + + + + + + + 1 1 1 + + + + + 0.000999987 + 0 + 0.1 + 0.1 + 0.1 + 1 + 1 + 2 + 0 + 1 + 1 + 1 + 1 + 1 + 0 + 512 + 2 + 40 + 0.5 + 0.04999995 + 25 + 1 + 2 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 3 + 0 + 0 + 0 + 0 + 2 + 1 + 1 + 1 + 3 + 0.15 + 45 + 1 + 1 + 0 + 1 + 1 + 1 + + + + + + + 1 1 1 + 1 + 0 + 0.001599967 + 45 + 0.15 + + + + + 0.000999987 + 0 + 0.1 + 0.1 + 0.1 + 1 + 1 + 2 + 0 + 1 + 1 + 1 + 1 + 1 + 0 + 512 + 2 + 40 + 0.5 + 0.04999995 + 25 + 1 + 2 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 3 + 0 + 0 + 0 + 0 + 2 + 1 + 1 + 1 + 3 + 0.15 + 45 + 1 + 1 + 0 + 1 + 1 + 2 + + + + + + + 1 1 1 + + + + + 0.000999987 + 0 + 0.1 + 0.1 + 0.1 + 1 + 1 + 2 + 0 + 1 + 1 + 1 + 1 + 1 + 0 + 512 + 2 + 40 + 0.5 + 0.04999995 + 25 + 1 + 2 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 3 + 0 + 0 + 0 + 0 + 2 + 1 + 1 + 1 + 3 + 0.15 + 45 + 1 + 1 + 0 + 1 + 1 + 3 + + + + + + + 1 1 1 + 1 + 0 + 0.001599967 + + + + + 0.000999987 + 0 + 0.1 + 0.1 + 0.1 + 1 + 1 + 2 + 0 + 1 + 1 + 1 + 1 + 1 + 0 + 512 + 2 + 40 + 0.5 + 0.04999995 + 25 + 1 + 2 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 3 + 0 + 0 + 0 + 0 + 2 + 1 + 1 + 1 + 3 + 0.15 + 45 + 1 + 1 + 0 + 1 + 1 + 4 + + + + + + + + + + 1 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 + + + + 1 0 0 7.076701 0 1 0 -5.572294 0 0 1 5.147222 0 0 0 1 + + + + 1 0 0 8.888217 0 1 0 -5.016863 0 0 1 5.336025 0 0 0 1 + + + + 1 0 0 7.326984 0 1 0 -4.602942 0 0 1 5.554852 0 0 0 1 + + + + 1 0 0 8.063721 0 1 0 -4.19857 0 0 1 5.273283 0 0 0 1 + + + + + + + + \ No newline at end of file diff --git a/test/unit/utColladaExportLight.cpp b/test/unit/utColladaExportLight.cpp new file mode 100644 index 000000000..044770be3 --- /dev/null +++ b/test/unit/utColladaExportLight.cpp @@ -0,0 +1,81 @@ +/* + * ColladaCameraExporter.cpp + * + * Created on: May 17, 2015 + * Author: wise + */ + + +#include "UnitTestPCH.h" + +#include +#include +#include +#include + +#ifndef ASSIMP_BUILD_NO_EXPORT + +class ColladaExportLight : public ::testing::Test { +public: + + virtual void SetUp() + { + ex = new Assimp::Exporter(); + im = new Assimp::Importer(); + + } + + virtual void TearDown() + { + delete ex; + delete im; + } + +protected: + + + Assimp::Exporter* ex; + Assimp::Importer* im; +}; + +// ------------------------------------------------------------------------------------------------ +TEST_F(ColladaExportLight, testExportLight) +{ + const char* file = "cameraExp.dae"; + + const aiScene* pTest = im->ReadFile("../test/models/Collada/lights.dae",0); + ASSERT_TRUE(pTest!=NULL); + ASSERT_TRUE(pTest->HasLights()); + + + EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada",file)); + EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada","/home/wise/lightsExp.dae")); + + const aiScene* imported = im->ReadFile(file,0); + + ASSERT_TRUE(imported!=NULL); + + EXPECT_TRUE(imported->HasLights()); + EXPECT_EQ(pTest->mNumLights,imported->mNumLights); +/* + for(size_t i=0; i< pTest->mNumCameras;i++){ + + const aiCamera *orig = pTest->mCameras[i]; + const aiCamera *read = imported->mCameras[i]; + + EXPECT_TRUE(orig->mName==read->mName); + EXPECT_FLOAT_EQ(orig->mHorizontalFOV,read->mHorizontalFOV); + EXPECT_FLOAT_EQ(orig->mClipPlaneNear,read->mClipPlaneNear); + EXPECT_FLOAT_EQ(orig->mClipPlaneFar,read->mClipPlaneFar); + + EXPECT_FLOAT_EQ(orig->mPosition.x,read->mPosition.x); + EXPECT_FLOAT_EQ(orig->mPosition.y,read->mPosition.y); + EXPECT_FLOAT_EQ(orig->mPosition.z,read->mPosition.z); + } +*/ +} + + +#endif + + From b1d085b6a9acc719a0ac044148bb359d66226bd6 Mon Sep 17 00:00:00 2001 From: wise86Android Date: Tue, 19 May 2015 23:08:31 +0200 Subject: [PATCH 4/6] fix the foruma for compute the mAngleOuterCone values --- code/ColladaLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/ColladaLoader.cpp b/code/ColladaLoader.cpp index 735eede18..86c40d9c2 100644 --- a/code/ColladaLoader.cpp +++ b/code/ColladaLoader.cpp @@ -346,8 +346,8 @@ void ColladaLoader::BuildLightsForNode( const ColladaParser& pParser, const Coll { // Need to rely on falloff_exponent. I don't know how to interpret it, so I need to guess .... // epsilon chosen to be 0.1 - out->mAngleOuterCone = AI_DEG_TO_RAD (std::acos(std::pow(0.1f,1.f/srcLight->mFalloffExponent))+ - srcLight->mFalloffAngle); + out->mAngleOuterCone = std::acos(std::pow(0.1f,1.f/srcLight->mFalloffExponent))+ + out->mAngleInnerCone; } else { out->mAngleOuterCone = out->mAngleInnerCone + AI_DEG_TO_RAD( srcLight->mPenumbraAngle ); From 5ad6179bc531210df148c9031a616a0f976ef989 Mon Sep 17 00:00:00 2001 From: wise86Android Date: Tue, 19 May 2015 23:15:18 +0200 Subject: [PATCH 5/6] export the light in the collada file --- code/ColladaExporter.cpp | 41 ++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/code/ColladaExporter.cpp b/code/ColladaExporter.cpp index ba3530491..0f9bdc868 100644 --- a/code/ColladaExporter.cpp +++ b/code/ColladaExporter.cpp @@ -454,13 +454,24 @@ void ColladaExporter::WriteSpotLight(const aiLight *const light){ mOutput << startstr << "" << light->mAttenuationQuadratic <<"" << endstr; -/* mOutput << startstr << "" - << light-> - <<"" << endstr; - mOutput << startstr << "" - << light->mAttenuationLinear - <<"" << endstr; -*/ + /* + out->mAngleOuterCone = AI_DEG_TO_RAD (std::acos(std::pow(0.1f,1.f/srcLight->mFalloffExponent))+ + srcLight->mFalloffAngle); + */ + + const float fallOffAngle = AI_RAD_TO_DEG(light->mAngleInnerCone); + mOutput << startstr <<"" + << fallOffAngle + <<"" << endstr; + double temp = light->mAngleOuterCone-light->mAngleInnerCone; + + temp = std::cos(temp); + temp = std::log(temp)/std::log(0.1); + temp = 1/temp; + mOutput << startstr << "" + << temp + <<"" << endstr; + PopTag(); mOutput << startstr << "" << endstr; @@ -1042,7 +1053,21 @@ void ColladaExporter::WriteNode(aiNode* pNode) mOutput << "" << endstr; if(pNode->mNumMeshes==0){ - mOutput << startstr <<"" << endstr; + //check if it is a camera node + for(size_t i=0; imNumCameras; i++){ + if(mScene->mCameras[i]->mName == pNode->mName){ + mOutput << startstr <<"" << endstr; + break; + } + } + //check if it is a light node + for(size_t i=0; imNumLights; i++){ + if(mScene->mLights[i]->mName == pNode->mName){ + mOutput << startstr <<"" << endstr; + break; + } + } + }else // instance every geometry for( size_t a = 0; a < pNode->mNumMeshes; ++a ) From 26b3328f3b8e1a96b27ada67519824afdd6336d0 Mon Sep 17 00:00:00 2001 From: wise86Android Date: Sat, 23 May 2015 11:03:56 +0200 Subject: [PATCH 6/6] fix xml syntax + more deap test --- code/ColladaExporter.cpp | 14 +++---------- test/unit/utColladaExportLight.cpp | 33 ++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/code/ColladaExporter.cpp b/code/ColladaExporter.cpp index 0f9bdc868..bcd4518e4 100644 --- a/code/ColladaExporter.cpp +++ b/code/ColladaExporter.cpp @@ -430,15 +430,7 @@ void ColladaExporter::WriteDirectionalLight(const aiLight *const light){ } void ColladaExporter::WriteSpotLight(const aiLight *const light){ - /* - 1 1 1 - 1 - 0 - 0.001599967 - 45 - 0.15 - - */ + const aiColor3D &color= light->mColorDiffuse; mOutput << startstr << "" << endstr; PushTag(); @@ -1056,14 +1048,14 @@ void ColladaExporter::WriteNode(aiNode* pNode) //check if it is a camera node for(size_t i=0; imNumCameras; i++){ if(mScene->mCameras[i]->mName == pNode->mName){ - mOutput << startstr <<"" << endstr; + mOutput << startstr <<"" << endstr; break; } } //check if it is a light node for(size_t i=0; imNumLights; i++){ if(mScene->mLights[i]->mName == pNode->mName){ - mOutput << startstr <<"" << endstr; + mOutput << startstr <<"" << endstr; break; } } diff --git a/test/unit/utColladaExportLight.cpp b/test/unit/utColladaExportLight.cpp index 044770be3..510be7ee2 100644 --- a/test/unit/utColladaExportLight.cpp +++ b/test/unit/utColladaExportLight.cpp @@ -57,22 +57,33 @@ TEST_F(ColladaExportLight, testExportLight) EXPECT_TRUE(imported->HasLights()); EXPECT_EQ(pTest->mNumLights,imported->mNumLights); -/* - for(size_t i=0; i< pTest->mNumCameras;i++){ - const aiCamera *orig = pTest->mCameras[i]; - const aiCamera *read = imported->mCameras[i]; + for(size_t i=0; i< pTest->mNumLights;i++){ + + const aiLight *orig = pTest->mLights[i]; + const aiLight *read = imported->mLights[i]; EXPECT_TRUE(orig->mName==read->mName); - EXPECT_FLOAT_EQ(orig->mHorizontalFOV,read->mHorizontalFOV); - EXPECT_FLOAT_EQ(orig->mClipPlaneNear,read->mClipPlaneNear); - EXPECT_FLOAT_EQ(orig->mClipPlaneFar,read->mClipPlaneFar); + EXPECT_EQ(orig->mType,read->mType); + EXPECT_FLOAT_EQ(orig->mAttenuationConstant,read->mAttenuationConstant); + EXPECT_FLOAT_EQ(orig->mAttenuationLinear,read->mAttenuationLinear); + EXPECT_FLOAT_EQ(orig->mAttenuationQuadratic,read->mAttenuationQuadratic); - EXPECT_FLOAT_EQ(orig->mPosition.x,read->mPosition.x); - EXPECT_FLOAT_EQ(orig->mPosition.y,read->mPosition.y); - EXPECT_FLOAT_EQ(orig->mPosition.z,read->mPosition.z); + EXPECT_FLOAT_EQ(orig->mColorAmbient.r,read->mColorAmbient.r); + EXPECT_FLOAT_EQ(orig->mColorAmbient.g,read->mColorAmbient.g); + EXPECT_FLOAT_EQ(orig->mColorAmbient.b,read->mColorAmbient.b); + + EXPECT_FLOAT_EQ(orig->mColorDiffuse.r,read->mColorDiffuse.r); + EXPECT_FLOAT_EQ(orig->mColorDiffuse.g,read->mColorDiffuse.g); + EXPECT_FLOAT_EQ(orig->mColorDiffuse.b,read->mColorDiffuse.b); + + EXPECT_FLOAT_EQ(orig->mColorSpecular.r,read->mColorSpecular.r); + EXPECT_FLOAT_EQ(orig->mColorSpecular.g,read->mColorSpecular.g); + EXPECT_FLOAT_EQ(orig->mColorSpecular.b,read->mColorSpecular.b); + + EXPECT_NEAR(orig->mAngleInnerCone,read->mAngleInnerCone,0.001); + EXPECT_NEAR(orig->mAngleOuterCone,read->mAngleOuterCone,0.001); } -*/ }