From 6fe8c867e8d0a7eda258c23103330e4893012fcb Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Fri, 8 Aug 2008 18:34:14 +0000 Subject: [PATCH] Refactoring ... added documentation, simplified some parts of the code and migrated some class declarations in separate files. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@100 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/ASELoader.cpp | 2 +- code/Assimp.cpp | 4 +- code/BaseImporter.cpp | 29 ++------ code/BaseImporter.h | 8 ++ code/BaseProcess.cpp | 94 ++++++++++++++++++++++++ code/BaseProcess.h | 40 +++++----- code/Importer.cpp | 42 ++++------- code/LimitBoneWeightsProcess.cpp | 31 ++++---- code/LimitBoneWeightsProcess.h | 32 ++++++-- code/SMDLoader.cpp | 21 +++--- code/SMDLoader.h | 7 ++ code/SplitLargeMeshes.cpp | 62 ++++++++-------- code/SplitLargeMeshes.h | 48 ++++++++---- include/assimp.hpp | 2 +- port/jAssimp/assimp.iml | 2 +- port/jAssimp/src/assimp/ShadingMode.java | 20 ++--- workspaces/jidea5.1/jAssimp.ipr | 4 +- workspaces/vc8/assimp.vcproj | 4 + 18 files changed, 285 insertions(+), 167 deletions(-) create mode 100644 code/BaseProcess.cpp diff --git a/code/ASELoader.cpp b/code/ASELoader.cpp index 3f5cf4dd0..0ae153c94 100644 --- a/code/ASELoader.cpp +++ b/code/ASELoader.cpp @@ -473,7 +473,7 @@ void ASEImporter::BuildNodes() aiNode* pcNode = new aiNode(); pcNode->mParent = pcScene->mRootNode; pcNode->mName.Set(szMyName[1]); - this->AddNodes(pcScene,pcNode,pcNode->mName.data); + this->AddNodes(pcNode,pcNode->mName.data); apcNodes.push_back(pcNode); } pcScene->mRootNode->mChildren = new aiNode*[apcNodes.size()]; diff --git a/code/Assimp.cpp b/code/Assimp.cpp index 1a63a3d79..a67c4b4ad 100644 --- a/code/Assimp.cpp +++ b/code/Assimp.cpp @@ -184,7 +184,7 @@ void aiGetExtensionList(aiString* szOut) } // ------------------------------------------------------------------------------------------------ void aiGetMemoryRequirements(const C_STRUCT aiScene* pIn, - C_STRUCT aiMemoryInfo* in); + C_STRUCT aiMemoryInfo* in) { // lock the mutex #if (defined AI_C_THREADSAFE) @@ -198,7 +198,7 @@ void aiGetMemoryRequirements(const C_STRUCT aiScene* pIn, { DefaultLogger::get()->error("Unable to find the Importer instance for this scene. " "Are you sure it has been created by aiImportFile(ex)(...)?"); - return 0; + return; } // get memory statistics it->second->GetMemoryRequirements(*in); diff --git a/code/BaseImporter.cpp b/code/BaseImporter.cpp index 15783e704..f0ce83263 100644 --- a/code/BaseImporter.cpp +++ b/code/BaseImporter.cpp @@ -39,9 +39,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ -/** @file Implementation of the few default functions of the base importer class */ +/** @file Implementation of BaseImporter */ #include "BaseImporter.h" -#include "BaseProcess.h" #include "../include/DefaultLogger.h" #include "../include/aiScene.h" @@ -68,7 +67,7 @@ BaseImporter::~BaseImporter() aiScene* BaseImporter::ReadFile( const std::string& pFile, IOSystem* pIOHandler) { // create a scene object to hold the data - aiScene* scene = new aiScene; + aiScene* scene = new aiScene(); // dispatch importing try @@ -93,26 +92,8 @@ aiScene* BaseImporter::ReadFile( const std::string& pFile, IOSystem* pIOHandler) } // ------------------------------------------------------------------------------------------------ -void BaseProcess::ExecuteOnScene( Importer* pImp) +void BaseImporter::SetupProperties(const Importer* pImp) { - ai_assert(NULL != pImp && NULL != pImp->mScene); - - // catch exceptions thrown inside the PostProcess-Step - try - { - this->Execute(pImp->mScene); - - } catch( ImportErrorException* exception) - { - // extract error description - pImp->mErrorString = exception->GetErrorText(); - - DefaultLogger::get()->error(pImp->mErrorString); - - delete exception; - - // and kill the partially imported data - delete pImp->mScene; - pImp->mScene = NULL; - } + // the default implementation does nothing } + diff --git a/code/BaseImporter.h b/code/BaseImporter.h index 1d0be37a4..dc0ac38fe 100644 --- a/code/BaseImporter.h +++ b/code/BaseImporter.h @@ -137,6 +137,14 @@ public: inline const std::string& GetErrorText() const { return mErrorText; } + + // ------------------------------------------------------------------- + /** Called prior to ReadFile(). + * The function is a request to the importer to update its configuration + * basing on the Importer's configuration property list. + */ + virtual void SetupProperties(const Importer* pImp); + protected: // ------------------------------------------------------------------- diff --git a/code/BaseProcess.cpp b/code/BaseProcess.cpp new file mode 100644 index 000000000..d4fcbacf9 --- /dev/null +++ b/code/BaseProcess.cpp @@ -0,0 +1,94 @@ +/* +--------------------------------------------------------------------------- +Open Asset Import Library (ASSIMP) +--------------------------------------------------------------------------- + +Copyright (c) 2006-2008, ASSIMP Development Team + +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the following +conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the ASSIMP team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the ASSIMP Development Team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--------------------------------------------------------------------------- +*/ + +/** @file Implementation of BaseProcess */ +#include "BaseImporter.h" +#include "BaseProcess.h" + +#include "../include/DefaultLogger.h" +#include "../include/aiScene.h" +#include "../include/aiAssert.h" +#include "../include/assimp.hpp" +using namespace Assimp; + +// ------------------------------------------------------------------------------------------------ +// Constructor to be privately used by Importer +BaseProcess::BaseProcess() +{ + // nothing to do here +} + +// ------------------------------------------------------------------------------------------------ +// Destructor, private as well +BaseProcess::~BaseProcess() +{ + // nothing to do here +} + +// ------------------------------------------------------------------------------------------------ +void BaseProcess::ExecuteOnScene( Importer* pImp) +{ + ai_assert(NULL != pImp && NULL != pImp->mScene); + + // catch exceptions thrown inside the PostProcess-Step + try + { + this->Execute(pImp->mScene); + + } catch( ImportErrorException* exception) + { + // extract error description + pImp->mErrorString = exception->GetErrorText(); + DefaultLogger::get()->error(pImp->mErrorString); + + delete exception; + + // and kill the partially imported data + delete pImp->mScene; + pImp->mScene = NULL; + } +} + +// ------------------------------------------------------------------------------------------------ +void BaseProcess::SetupProperties(const Importer* pImp) +{ + // the default implementation does nothing +} diff --git a/code/BaseProcess.h b/code/BaseProcess.h index 728d14ad9..e0964d357 100644 --- a/code/BaseProcess.h +++ b/code/BaseProcess.h @@ -53,17 +53,19 @@ namespace Assimp // --------------------------------------------------------------------------- /** The BaseProcess defines a common interface for all post processing steps. * A post processing step is run after a successful import if the caller - * specified the corresponding flag when calling ReadFile(). Enum #aiPostProcessSteps - * defines which flags are available. - * After a successful import the Importer iterates over its internal array of processes - * and calls IsActive() on each process to evaluate if the step should be executed. - * If the function returns true, the class' Execute() function is called subsequently. + * specified the corresponding flag when calling ReadFile(). + * Enum #aiPostProcessSteps defines which flags are available. + * After a successful import the Importer iterates over its internal array + * of processes and calls IsActive() on each process to evaluate if the step + * should be executed. If the function returns true, the class' Execute() + * function is called subsequently. */ -class ASSIMP_API BaseProcess +class ASSIMP_API BaseProcess { friend class Importer; public: + /** Constructor to be privately used by Importer */ BaseProcess(); @@ -71,11 +73,13 @@ public: virtual ~BaseProcess(); public: + // ------------------------------------------------------------------- - /** Returns whether the processing step is present in the given flag field. - * @param pFlags The processing flags the importer was called with. A bitwise - * combination of #aiPostProcessSteps. - * @return true if the process is present in this flag fields, false if not. + /** Returns whether the processing step is present in the given flag. + * @param pFlags The processing flags the importer was called with. A + * bitwise combination of #aiPostProcessSteps. + * @return true if the process is present in this flag fields, + * false if not. */ virtual bool IsActive( unsigned int pFlags) const = 0; @@ -87,6 +91,13 @@ public: */ void ExecuteOnScene( Importer* pImp); + // ------------------------------------------------------------------- + /** Called prior to ExecuteOnScene(). + * The function is a request to the process to update its configuration + * basing on the Importer's configuration property list. + */ + virtual void SetupProperties(const Importer* pImp); + // ------------------------------------------------------------------- /** Executes the post processing step on the given imported data. * A process should throw an ImportErrorException* if it fails. @@ -96,15 +107,6 @@ public: virtual void Execute( aiScene* pScene) = 0; }; -/** Constructor, dummy implementation to keep the compiler from complaining */ -inline BaseProcess::BaseProcess() -{ -} - -/** Destructor */ -inline BaseProcess::~BaseProcess() -{ -} } // end of namespace Assimp diff --git a/code/Importer.cpp b/code/Importer.cpp index 0cf1c379c..b8184c2fa 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -100,9 +100,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if (!defined AI_BUILD_NO_MD5_IMPORTER) # include "MD5Loader.h" #endif -#if (!defined AI_BUILD_NO_MD5_IMPORTER) -# include "MD5Loader.h" -#endif #if (!defined AI_BUILD_NO_STL_IMPORTER) # include "STLLoader.h" #endif @@ -266,21 +263,6 @@ Importer::Importer() : #if (!defined AI_BUILD_NO_IMPROVECACHELOCALITY_PROCESS) mPostProcessingSteps.push_back( new ImproveCacheLocalityProcess()); #endif - - //// store the *this* pointer in all BaseImporter instances - //for (std::vector::iterator - // i = mImporter.begin(); - // i != mImporter.end();++i) - //{ - // (**i).mImporter = this; - //} - //// store the *this* pointer in all BaseProcess instances - //for (std::vector::iterator - // i = mPostProcessingSteps.begin(); - // i != mPostProcessingSteps.end();++i) - //{ - // (**i).mImporter = this; - //} } // ------------------------------------------------------------------------------------------------ @@ -327,6 +309,7 @@ bool Importer::IsDefaultIOHandler() { return mIsDefaultHandler; } +#ifdef _DEBUG // ------------------------------------------------------------------------------------------------ // Validate post process step flags bool ValidateFlags(unsigned int pFlags) @@ -341,6 +324,7 @@ bool ValidateFlags(unsigned int pFlags) return true; } +#endif // ! DEBUG // ------------------------------------------------------------------------------------------------ // Reads the given file and returns its contents if successful. const aiScene* Importer::ReadFile( const std::string& pFile, unsigned int pFlags) @@ -384,11 +368,13 @@ const aiScene* Importer::ReadFile( const std::string& pFile, unsigned int pFlags } // dispatch the reading to the worker class for this format + imp->SetupProperties( this ); mScene = imp->ReadFile( pFile, mIOHandler); // if successful, apply all active post processing steps to the imported data if( mScene) { +#ifdef _DEBUG if (bExtraVerbose) { pFlags |= aiProcess_ValidateDataStructure; @@ -397,15 +383,17 @@ const aiScene* Importer::ReadFile( const std::string& pFile, unsigned int pFlags // TODO: temporary solution, clean up later mScene->mFlags |= 0x80000000; } +#endif // ! DEBUG for( unsigned int a = 0; a < mPostProcessingSteps.size(); a++) { BaseProcess* process = mPostProcessingSteps[a]; if( process->IsActive( pFlags)) { - process->ExecuteOnScene( this ); + process->SetupProperties( this ); + process->ExecuteOnScene ( this ); } - if( !mScene)break; // error string has already been set ... - + if( !mScene)break; +#ifdef _DEBUG // if the extra verbose mode is active execute the // VaidateDataStructureStep again after each step if (bExtraVerbose && a) @@ -415,18 +403,18 @@ const aiScene* Importer::ReadFile( const std::string& pFile, unsigned int pFlags if( !mScene) { DefaultLogger::get()->error("Extra verbose: failed to revalidate data structures"); - break; // error string has already been set ... + break; } } +#endif // ! DEBUG } +#ifdef _DEBUG if (bExtraVerbose)mScene->mFlags &= ~0x80000000; +#endif // ! DEBUG } // if failed, extract the error string - else if( !mScene) - { - mErrorString = imp->GetErrorText(); - } + else if( !mScene)mErrorString = imp->GetErrorText(); // either successful or failure - the pointer expresses it anyways return mScene; @@ -497,7 +485,7 @@ int Importer::SetProperty(const char* szName, int iValue) // ------------------------------------------------------------------------------------------------ // Get a configuration property int Importer::GetProperty(const char* szName, - int iErrorReturn /*= 0xffffffff*/) + int iErrorReturn /*= 0xffffffff*/) const { ai_assert(NULL != szName); diff --git a/code/LimitBoneWeightsProcess.cpp b/code/LimitBoneWeightsProcess.cpp index 84de5b755..15a01d1e7 100644 --- a/code/LimitBoneWeightsProcess.cpp +++ b/code/LimitBoneWeightsProcess.cpp @@ -49,29 +49,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../include/aiMesh.h" #include "../include/aiScene.h" #include "../include/aiAssert.h" +#include "../include/assimp.hpp" #include "../include/DefaultLogger.h" using namespace Assimp; -/*static*/ unsigned int LimitBoneWeightsProcess::mMaxWeights = AI_LMW_MAX_WEIGHTS; - -extern "C" { -// ------------------------------------------------------------------------------------------------ -aiReturn aiSetBoneWeightLimit(unsigned int pLimit) -{ - if (0 == pLimit) - { - LimitBoneWeightsProcess::mMaxWeights = 0xFFFFFFFF; - return AI_FAILURE; - } - - LimitBoneWeightsProcess::mMaxWeights = pLimit; - DefaultLogger::get()->debug("aiSetBoneWeightLimit() - bone weight limit was changed"); - return AI_SUCCESS; -} -}; - // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer LimitBoneWeightsProcess::LimitBoneWeightsProcess() @@ -100,6 +83,18 @@ void LimitBoneWeightsProcess::Execute( aiScene* pScene) ProcessMesh( pScene->mMeshes[a]); } +// ------------------------------------------------------------------------------------------------ +// Executes the post processing step on the given imported data. +void LimitBoneWeightsProcess::SetupProperties(const Importer* pImp) +{ + // get the current value of the property + if(0xffffffff == (this->mMaxWeights = pImp->GetProperty( + AI_CONFIG_PP_LBW_MAX_WEIGHTS,0xffffffff))) + { + this->mMaxWeights = AI_LMW_MAX_WEIGHTS; + } +} + // ------------------------------------------------------------------------------------------------ // Unites identical vertices in the given mesh void LimitBoneWeightsProcess::ProcessMesh( aiMesh* pMesh) diff --git a/code/LimitBoneWeightsProcess.h b/code/LimitBoneWeightsProcess.h index 7d4ec02ec..f32c946fc 100644 --- a/code/LimitBoneWeightsProcess.h +++ b/code/LimitBoneWeightsProcess.h @@ -91,35 +91,53 @@ public: bool IsActive( unsigned int pFlags) const; // ------------------------------------------------------------------- - /** Executes the post processing step on the given imported data. - * At the moment a process is not supposed to fail. - * @param pScene The imported data to work at. + /** Called prior to ExecuteOnScene(). + * The function is a request to the process to update its configuration + * basing on the Importer's configuration property list. */ - void Execute( aiScene* pScene); + virtual void SetupProperties(const Importer* pImp); protected: + // ------------------------------------------------------------------- /** Limits the bone weight count for all vertices in the given mesh. * @param pMesh The mesh to process. */ void ProcessMesh( aiMesh* pMesh); + // ------------------------------------------------------------------- + /** Executes the post processing step on the given imported data. + * At the moment a process is not supposed to fail. + * @param pScene The imported data to work at. + */ + void Execute( aiScene* pScene); + + protected: + + // ------------------------------------------------------------------- /** Describes a bone weight on a vertex */ struct Weight { unsigned int mBone; ///< Index of the bone float mWeight; ///< Weight of that bone on this vertex Weight() { } - Weight( unsigned int pBone, float pWeight) { mBone = pBone; mWeight = pWeight; } + Weight( unsigned int pBone, float pWeight) + { + mBone = pBone; + mWeight = pWeight; + } /** Comparision operator to sort bone weights by descending weight */ - bool operator < (const Weight& pWeight) const { return mWeight > pWeight.mWeight; } + bool operator < (const Weight& pWeight) const + { + return mWeight > pWeight.mWeight; + } }; public: /** Maximum number of bones influencing any single vertex. */ - static unsigned int mMaxWeights; + unsigned int mMaxWeights; }; } // end of namespace Assimp diff --git a/code/SMDLoader.cpp b/code/SMDLoader.cpp index 5e365fbbc..be617e885 100644 --- a/code/SMDLoader.cpp +++ b/code/SMDLoader.cpp @@ -105,6 +105,18 @@ bool SMDImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler) const return true; } // ------------------------------------------------------------------------------------------------ +// Setup configuration properties +void SMDImporter::SetupProperties(const Importer* pImp) +{ + // The AI_CONFIG_IMPORT_SMD_KEYFRAME option overrides the + // AI_CONFIG_IMPORT_GLOBAL_KEYFRAME option. + if(0xffffffff == (this->configFrameID = pImp->GetProperty( + AI_CONFIG_IMPORT_SMD_KEYFRAME,0xffffffff))) + { + this->configFrameID = pImp->GetProperty(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME,0); + } +} +// ------------------------------------------------------------------------------------------------ // Imports the given file into the given scene structure. void SMDImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) @@ -139,15 +151,6 @@ void SMDImporter::InternReadFile( // reserve enough space for ... hm ... 20 bones this->asBones.reserve(20); - // The AI_CONFIG_IMPORT_SMD_KEYFRAME option overrides the - // AI_CONFIG_IMPORT_GLOBAL_KEYFRAME option. - if(0xffffffff == (this->configFrameID = this->mImporter->GetProperty( - AI_CONFIG_IMPORT_SMD_KEYFRAME,0xffffffff))) - { - this->configFrameID = this->mImporter->GetProperty( - AI_CONFIG_IMPORT_GLOBAL_KEYFRAME,0); - } - try { // parse the file ... diff --git a/code/SMDLoader.h b/code/SMDLoader.h index ba09df30c..0c469f881 100644 --- a/code/SMDLoader.h +++ b/code/SMDLoader.h @@ -189,6 +189,13 @@ public: * See BaseImporter::CanRead() for details. */ bool CanRead( const std::string& pFile, IOSystem* pIOHandler) const; + // ------------------------------------------------------------------- + /** Called prior to ReadFile(). + * The function is a request to the importer to update its configuration + * basing on the Importer's configuration property list. + */ + void SetupProperties(const Importer* pImp); + protected: diff --git a/code/SplitLargeMeshes.cpp b/code/SplitLargeMeshes.cpp index 4c7113a51..e58b83bc0 100644 --- a/code/SplitLargeMeshes.cpp +++ b/code/SplitLargeMeshes.cpp @@ -46,41 +46,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../include/aiPostProcess.h" #include "../include/aiMesh.h" #include "../include/aiScene.h" +#include "../include/assimp.hpp" using namespace Assimp; -/*static*/ unsigned int SplitLargeMeshesProcess_Triangle::LIMIT = AI_SLM_DEFAULT_MAX_TRIANGLES; -/*static*/ unsigned int SplitLargeMeshesProcess_Vertex::LIMIT = AI_SLM_DEFAULT_MAX_VERTICES; -extern "C" { - -// ------------------------------------------------------------------------------------------------ -aiReturn aiSetVertexSplitLimit(unsigned int pLimit) -{ - if (0 == pLimit) - { - SplitLargeMeshesProcess_Vertex::LIMIT = 0xFFFFFFFF; - return AI_FAILURE; - } - - SplitLargeMeshesProcess_Vertex::LIMIT = pLimit; - DefaultLogger::get()->debug("aiSetVertexSplitLimit() - vertex split limit was changed"); - return AI_SUCCESS; -} -// ------------------------------------------------------------------------------------------------ -aiReturn aiSetTriangleSplitLimit(unsigned int pLimit) -{ - if (0 == pLimit) - { - SplitLargeMeshesProcess_Triangle::LIMIT = 0xFFFFFFFF; - return AI_FAILURE; - } - - SplitLargeMeshesProcess_Triangle::LIMIT = pLimit; - DefaultLogger::get()->debug("aiSetTriangleSplitLimit() - triangle split limit was changed"); - return AI_SUCCESS; -} -}; //! extern "C" // ------------------------------------------------------------------------------------------------ SplitLargeMeshesProcess_Triangle::SplitLargeMeshesProcess_Triangle() @@ -96,12 +66,14 @@ SplitLargeMeshesProcess_Triangle::~SplitLargeMeshesProcess_Triangle() // Returns whether the processing step is present in the given flag field. bool SplitLargeMeshesProcess_Triangle::IsActive( unsigned int pFlags) const { - return (pFlags & aiProcess_SplitLargeMeshes) != 0 && (0xFFFFFFFF != LIMIT); + return (pFlags & aiProcess_SplitLargeMeshes) != 0; } // ------------------------------------------------------------------------------------------------ // Executes the post processing step on the given imported data. void SplitLargeMeshesProcess_Triangle::Execute( aiScene* pScene) { + if (0xffffffff == this->LIMIT)return; + DefaultLogger::get()->debug("SplitLargeMeshesProcess_Triangle begin"); std::vector > avList; @@ -126,6 +98,17 @@ void SplitLargeMeshesProcess_Triangle::Execute( aiScene* pScene) return; } // ------------------------------------------------------------------------------------------------ +// Setup properties +void SplitLargeMeshesProcess_Triangle::SetupProperties( const Importer* pImp) +{ + // get the current value of the split property + if(0xcdcdcdcd == (this->LIMIT = pImp->GetProperty( + AI_CONFIG_PP_SLM_TRIANGLE_LIMIT,0xcdcdcdcd))) + { + this->LIMIT = AI_SLM_DEFAULT_MAX_TRIANGLES; + } +} +// ------------------------------------------------------------------------------------------------ // Update a node after some meshes have been split void SplitLargeMeshesProcess_Triangle::UpdateNode(aiNode* pcNode, const std::vector >& avList) @@ -368,7 +351,7 @@ SplitLargeMeshesProcess_Vertex::~SplitLargeMeshesProcess_Vertex() // Returns whether the processing step is present in the given flag field. bool SplitLargeMeshesProcess_Vertex::IsActive( unsigned int pFlags) const { - return (pFlags & aiProcess_SplitLargeMeshes) != 0 && (0xFFFFFFFF != LIMIT); + return (pFlags & aiProcess_SplitLargeMeshes) != 0; } // ------------------------------------------------------------------------------------------------ // Executes the post processing step on the given imported data. @@ -376,6 +359,8 @@ void SplitLargeMeshesProcess_Vertex::Execute( aiScene* pScene) { std::vector > avList; + if (0xffffffff == this->LIMIT)return; + DefaultLogger::get()->debug("SplitLargeMeshesProcess_Vertex begin"); for( unsigned int a = 0; a < pScene->mNumMeshes; a++) this->SplitMesh(a, pScene->mMeshes[a],avList); @@ -398,6 +383,17 @@ void SplitLargeMeshesProcess_Vertex::Execute( aiScene* pScene) return; } // ------------------------------------------------------------------------------------------------ +// Setup properties +void SplitLargeMeshesProcess_Vertex::SetupProperties( const Importer* pImp) +{ + // get the current value of the split property + if(0xcdcdcdcd == (this->LIMIT = pImp->GetProperty( + AI_CONFIG_PP_SLM_VERTEX_LIMIT,0xcdcdcdcd))) + { + this->LIMIT = AI_SLM_DEFAULT_MAX_VERTICES; + } +} +// ------------------------------------------------------------------------------------------------ // Executes the post processing step on the given imported data. void SplitLargeMeshesProcess_Vertex::SplitMesh( unsigned int a, diff --git a/code/SplitLargeMeshes.h b/code/SplitLargeMeshes.h index 195cdb6dc..c6a5f6ddf 100644 --- a/code/SplitLargeMeshes.h +++ b/code/SplitLargeMeshes.h @@ -96,13 +96,25 @@ protected: public: // ------------------------------------------------------------------- - /** Returns whether the processing step is present in the given flag field. - * @param pFlags The processing flags the importer was called with. A bitwise - * combination of #aiPostProcessSteps. - * @return true if the process is present in this flag fields, false if not. + /** Returns whether the processing step is present in the given flag. + * @param pFlags The processing flags the importer was called with. A + * bitwise combination of #aiPostProcessSteps. + * @return true if the process is present in this flag fields, + * false if not. */ bool IsActive( unsigned int pFlags) const; + + // ------------------------------------------------------------------- + /** Called prior to ExecuteOnScene(). + * The function is a request to the process to update its configuration + * basing on the Importer's configuration property list. + */ + virtual void SetupProperties(const Importer* pImp); + + +protected: + // ------------------------------------------------------------------- /** Executes the post processing step on the given imported data. * At the moment a process is not supposed to fail. @@ -110,20 +122,20 @@ public: */ void Execute( aiScene* pScene); - -private: - + // ------------------------------------------------------------------- //! Apply the algorithm to a given mesh void SplitMesh (unsigned int a, aiMesh* pcMesh, std::vector >& avList); - //! Update a node in the asset after a few of its meshes have been split + // ------------------------------------------------------------------- + //! Update a node in the asset after a few of its meshes + //! have been split static void UpdateNode(aiNode* pcNode, const std::vector >& avList); public: - //! Triangle limit set via aiSetTriangleSplitLimit() - static unsigned int LIMIT; + //! Triangle limit + unsigned int LIMIT; }; @@ -154,6 +166,15 @@ public: */ bool IsActive( unsigned int pFlags) const; + // ------------------------------------------------------------------- + /** Called prior to ExecuteOnScene(). + * The function is a request to the process to update its configuration + * basing on the Importer's configuration property list. + */ + virtual void SetupProperties(const Importer* pImp); + +protected: + // ------------------------------------------------------------------- /** Executes the post processing step on the given imported data. * At the moment a process is not supposed to fail. @@ -161,8 +182,7 @@ public: */ void Execute( aiScene* pScene); -private: - + // ------------------------------------------------------------------- //! Apply the algorithm to a given mesh void SplitMesh (unsigned int a, aiMesh* pcMesh, std::vector >& avList); @@ -170,8 +190,8 @@ private: // NOTE: Reuse SplitLargeMeshesProcess_Triangle::UpdateNode() public: - //! Triangle limit set via aiSetTriangleSplitLimit() - static unsigned int LIMIT; + //! Triangle limit + unsigned int LIMIT; }; } // end of namespace Assimp diff --git a/include/assimp.hpp b/include/assimp.hpp index 0b4e64f6f..f364c8017 100644 --- a/include/assimp.hpp +++ b/include/assimp.hpp @@ -154,7 +154,7 @@ public: * for the requested property is returned! * @return Current value of the property */ - int GetProperty(const char* szName, int iErrorReturn = 0xffffffff); + int GetProperty(const char* szName, int iErrorReturn = 0xffffffff) const; // ------------------------------------------------------------------- diff --git a/port/jAssimp/assimp.iml b/port/jAssimp/assimp.iml index c375dc905..c208f5980 100644 --- a/port/jAssimp/assimp.iml +++ b/port/jAssimp/assimp.iml @@ -7,7 +7,7 @@ - + diff --git a/port/jAssimp/src/assimp/ShadingMode.java b/port/jAssimp/src/assimp/ShadingMode.java index 9bc2dd6c3..4248818b5 100644 --- a/port/jAssimp/src/assimp/ShadingMode.java +++ b/port/jAssimp/src/assimp/ShadingMode.java @@ -52,16 +52,18 @@ package assimp; */ public class ShadingMode { + private ShadingMode() {} + /** * Flat shading. Shading is done on per-face base, * diffuse only. */ - int Flat = 0x1; + public static final int Flat = 0x1; /** * Diffuse gouraud shading. Shading on per-vertex base */ - int Gouraud = 0x2; + public static final int Gouraud = 0x2; /** * Diffuse/Specular Phong-Shading @@ -69,7 +71,7 @@ public class ShadingMode { * Shading is applied on per-pixel base. This is the * slowest algorithm, but generates the best results. */ - int Phong = 0x3; + public static final int Phong = 0x3; /** * Diffuse/Specular Phong-Blinn-Shading @@ -78,7 +80,7 @@ public class ShadingMode { * bit faster than phong and in some cases even * more realistic */ - int Blinn = 0x4; + public static final int Blinn = 0x4; /** * Toon-Shading per pixel @@ -86,7 +88,7 @@ public class ShadingMode { * Shading is applied on per-pixel base. The output looks * like a comic. Often combined with edge detection. */ - int Toon = 0x5; + public static final int Toon = 0x5; /** * OrenNayar-Shading per pixel @@ -94,7 +96,7 @@ public class ShadingMode { * Extension to standard lambertian shading, taking the * roughness of the material into account */ - int OrenNayar = 0x6; + public static final int OrenNayar = 0x6; /** * Minnaert-Shading per pixel @@ -102,15 +104,15 @@ public class ShadingMode { * Extension to standard lambertian shading, taking the * "darkness" of the material into account */ - int Minnaert = 0x7; + public static final int Minnaert = 0x7; /** * CookTorrance-Shading per pixel */ - int CookTorrance = 0x8; + public static final int CookTorrance = 0x8; /** * No shading at all */ - int NoShading = 0x8; + public static final int NoShading = 0x8; } diff --git a/workspaces/jidea5.1/jAssimp.ipr b/workspaces/jidea5.1/jAssimp.ipr index ded5e0d28..9a09146f2 100644 --- a/workspaces/jidea5.1/jAssimp.ipr +++ b/workspaces/jidea5.1/jAssimp.ipr @@ -49,7 +49,7 @@