From 4e59426e090051db5b96c9ad7688d04173a88733 Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Fri, 8 Aug 2008 15:18:28 +0000 Subject: [PATCH] Added pushpack1.h and poppack1.h, integrated "FixInfacingNormals"-Step. Removed MD4 loader, MD4FileData.h remains in the extra directory. Renamed "VisualStudio" directory to "MSVC". git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@93 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/3DSHelper.h | 62 +++----- code/Compiler/poppack1.h | 16 +++ code/Compiler/pushpack1.h | 37 +++++ code/FixNormalsStep.cpp | 16 ++- code/FixNormalsStep.h | 2 +- code/HMPFileData.h | 133 ++++++++++++++++++ code/HMPLoader.h | 117 +-------------- code/HalfLifeFileData.h | 23 +-- code/MD2FileData.h | 16 +-- code/MD3FileData.h | 27 +--- code/MD4Loader.cpp | 115 --------------- code/MD4Loader.h | 107 -------------- code/MDLFileData.h | 25 +--- code/{ => extra}/MD4FileData.h | 0 .../Compiler/{VisualStudio => MSVC}/stdint.h | 0 include/aiDefines.h | 6 +- include/aiMesh.h | 44 ++++-- include/aiPostProcess.h | 22 +-- tools/assimp_view/assimp_view.cpp | 3 +- workspaces/vc8/assimp.vcproj | 24 ++-- 20 files changed, 308 insertions(+), 487 deletions(-) create mode 100644 code/Compiler/poppack1.h create mode 100644 code/Compiler/pushpack1.h create mode 100644 code/HMPFileData.h delete mode 100644 code/MD4Loader.cpp delete mode 100644 code/MD4Loader.h rename code/{ => extra}/MD4FileData.h (100%) rename include/Compiler/{VisualStudio => MSVC}/stdint.h (100%) diff --git a/code/3DSHelper.h b/code/3DSHelper.h index c0a0f498a..99650da07 100644 --- a/code/3DSHelper.h +++ b/code/3DSHelper.h @@ -38,7 +38,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ -/** @file Defines the helper data structures for importing XFiles */ +/** @file Defines the helper data structures for importing 3DS files. +http://www.jalix.org/ressources/graphics/3DS/_unofficials/3ds-unofficial.txt */ + #ifndef AI_3DSFILEHELPER_H_INC #define AI_3DSFILEHELPER_H_INC @@ -54,18 +56,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SpatialSort.h" -namespace Assimp -{ - namespace Dot3DS - { +namespace Assimp { +namespace Dot3DS { -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) -# pragma pack(push,2) -# define PACK_STRUCT -#elif defined( __GNUC__ ) -# define PACK_STRUCT __attribute__((packed)) -#else -# error Compiler not supported +#include "./Compiler/pushpack1.h" + +#ifdef _MSC_VER +# define sprintf sprintf_s #endif // --------------------------------------------------------------------------- @@ -118,9 +115,7 @@ public: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // enum for all chunks in 3ds files. Unused // ones are commented, list is not complete since - // there are many undocumented chunks. - // - // Links: http://www.jalix.org/ressources/graphics/3DS/_unofficials/3ds-unofficial.txt + // there are many undocumented chunks // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ enum { @@ -317,10 +312,7 @@ public: }; }; -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) -# pragma pack( pop ) -#endif -#undef PACK_STRUCT +#include "./Compiler/poppack1.h" // --------------------------------------------------------------------------- /** Helper structure representing a 3ds mesh face */ @@ -352,18 +344,18 @@ struct Texture { //! Default constructor Texture() - : - mScaleU(1.0f), - mScaleV(1.0f), - mOffsetU(0.0f), - mOffsetV(0.0f), - mRotation(0.0f), - iUVSrc(0), - mMapMode(aiTextureMapMode_Wrap) + : mScaleU (1.0f) + , mScaleV (1.0f) + , mOffsetU (0.0f) + , mOffsetV (0.0f) + , mRotation (0.0f) + , iUVSrc (0) + , mMapMode (aiTextureMapMode_Wrap) { mTextureBlend = std::numeric_limits::quiet_NaN(); } - //! Specifies the blending factor for the texture + + //! Specifies the blend factor for the texture float mTextureBlend; //! Specifies the filename of the texture @@ -402,7 +394,7 @@ struct Material static int iCnt = 0; char szTemp[128]; - sprintf(szTemp,"$$_UNNAMED_%i_$$",iCnt++); + sprintf(szTemp,"UNNAMED_%i",iCnt++); mName = szTemp; } @@ -458,11 +450,7 @@ struct Mesh static int iCnt = 0; char szTemp[128]; -#if _MSC_VER >= 1400 - ::sprintf_s(szTemp,"$$_UNNAMED_%i_$$",iCnt++); -#else - ::sprintf(szTemp,"$$_UNNAMED_%i_$$",iCnt++); -#endif + ::sprintf(szTemp,"UNNAMED_%i",iCnt++); mName = szTemp; } @@ -499,11 +487,7 @@ struct Node static int iCnt = 0; char szTemp[128]; -#if _MSC_VER >= 1400 - ::sprintf_s(szTemp,"$$_UNNAMED_%i_$$",iCnt++); -#else - ::sprintf(szTemp,"$$_UNNAMED_%i_$$",iCnt++); -#endif + ::sprintf(szTemp,"UNNAMED_%i",iCnt++); mName = szTemp; #ifdef AI_3DS_KEYFRAME_ANIMATION diff --git a/code/Compiler/poppack1.h b/code/Compiler/poppack1.h new file mode 100644 index 000000000..f4f312377 --- /dev/null +++ b/code/Compiler/poppack1.h @@ -0,0 +1,16 @@ + +// may be included multiple times - resets structure packing to default +// for all supported compilers. A pushpack1.h include must preceed +// each inclusion of this header. + +#ifndef AI_PUSHPACK_IS_DEFINED +# error pushpack1.h must be included after poppack1.h +#endif + +// reset packing to the original value +#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) +# pragma pack( pop ) +#endif +#undef PACK_STRUCT + +#undef AI_PUSHPACK_IS_DEFINED \ No newline at end of file diff --git a/code/Compiler/pushpack1.h b/code/Compiler/pushpack1.h new file mode 100644 index 000000000..87fa38ff9 --- /dev/null +++ b/code/Compiler/pushpack1.h @@ -0,0 +1,37 @@ + +// may be included multiple times - sets structure packing to 1 +// for all supported compilers. A poppack1.h include must follow +// each inclusion of this header. + + +/* + +PACK_STRUCT must follow each structure declaration: + +struct X +{ +} PACK_STRUCT; + + */ + +// + +#ifdef AI_PUSHPACK_IS_DEFINED +# error poppack1.h must be included after pushpack1.h +#endif + +#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) +# pragma pack(push,1) +# define PACK_STRUCT +#elif defined( __GNUC__ ) +# define PACK_STRUCT __attribute__((packed)) +#else +# error Compiler not supported +#endif + +#if defined(_MSC_VER) +// packing was changed after the inclusion of the header, propably missing #pragma pop +# pragma warning (disable : 4103) +#endif + +#define AI_PUSHPACK_IS_DEFINED diff --git a/code/FixNormalsStep.cpp b/code/FixNormalsStep.cpp index 23afc5d41..304b7da0a 100644 --- a/code/FixNormalsStep.cpp +++ b/code/FixNormalsStep.cpp @@ -59,6 +59,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; +#ifdef _MSC_VER +# define sprintf sprintf_s +#endif + // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer FixInfacingNormalsProcess::FixInfacingNormalsProcess() @@ -88,7 +92,7 @@ void FixInfacingNormalsProcess::Execute( aiScene* pScene) bool bHas = false; for( unsigned int a = 0; a < pScene->mNumMeshes; a++) - if(ProcessMesh( pScene->mMeshes[a]))bHas = true; + if(ProcessMesh( pScene->mMeshes[a],a))bHas = true; if (bHas)DefaultLogger::get()->debug("FixInfacingNormalsProcess finished. At least one mesh' normals have been flipped."); else DefaultLogger::get()->debug("FixInfacingNormalsProcess finished"); @@ -96,7 +100,7 @@ void FixInfacingNormalsProcess::Execute( aiScene* pScene) // ------------------------------------------------------------------------------------------------ // Apply the step to the mesh -bool FixInfacingNormalsProcess::ProcessMesh( aiMesh* pcMesh) +bool FixInfacingNormalsProcess::ProcessMesh( aiMesh* pcMesh, unsigned int index) { ai_assert(NULL != pcMesh); @@ -159,8 +163,12 @@ bool FixInfacingNormalsProcess::ProcessMesh( aiMesh* pcMesh) if (::fabsf(fDelta0_x * fDelta1_yz) < ::fabsf(fDelta1_x * fDelta1_y * fDelta1_z)) { - DefaultLogger::get()->info("Found a mesh whose normals are facing inwards " - "(or the model is too planar or concave). Flipping mesh normals ..."); + if (!DefaultLogger::isNullLogger()) + { + char buffer[128]; // should be sufficiently large + ::sprintf(buffer,"Mesh %i: Normals are facing inwards (or the mesh is planar)",index); + DefaultLogger::get()->info(buffer); + } for (unsigned int i = 0; i < pcMesh->mNumVertices;++i) { diff --git a/code/FixNormalsStep.h b/code/FixNormalsStep.h index 60d709d29..8c08d7af8 100644 --- a/code/FixNormalsStep.h +++ b/code/FixNormalsStep.h @@ -88,7 +88,7 @@ protected: /** Executes the step on the given mesh * @param pMesh The mesh to process. */ - bool ProcessMesh( aiMesh* pMesh); + bool ProcessMesh( aiMesh* pMesh, unsigned int index); }; } // end of namespace Assimp diff --git a/code/HMPFileData.h b/code/HMPFileData.h new file mode 100644 index 000000000..a61c3b407 --- /dev/null +++ b/code/HMPFileData.h @@ -0,0 +1,133 @@ +/* +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 Data structures for the 3D Game Studio Heightmap format (HMP) +//! + +namespace Assimp { +namespace HMP { + +#include "./Compiler/pushpack1.h" + +#define AI_HMP_MAGIC_NUMBER_BE_4 'HMP4' +#define AI_HMP_MAGIC_NUMBER_LE_4 '4PMH' + +#define AI_HMP_MAGIC_NUMBER_BE_5 'HMP5' +#define AI_HMP_MAGIC_NUMBER_LE_5 '5PMH' + +#define AI_HMP_MAGIC_NUMBER_BE_7 'HMP7' +#define AI_HMP_MAGIC_NUMBER_LE_7 '7PMH' + +// --------------------------------------------------------------------------- +/** Data structure for the header of a HMP5 file. + * This is also used by HMP4 and HMP7, but with modifications +*/ +struct Header_HMP5 +{ + int8_t ident[4]; // "HMP5" + int32_t version; + + // ignored + float scale[3]; + float scale_origin[3]; + float boundingradius; + + //! Size of one triangle in x direction + float ftrisize_x; + //! Size of one triangle in y direction + float ftrisize_y; + //! Number of vertices in x direction + float fnumverts_x; + + //! Number of skins in the file + int32_t numskins; + + // can ignore this? + int32_t skinwidth; + int32_t skinheight; + + //!Number of vertices in the file + int32_t numverts; + + // ignored and zero + int32_t numtris; + + //! only one supported ... + int32_t numframes; + + //! Always 0 ... + int32_t num_stverts; + int32_t flags; + float size; +} PACK_STRUCT; + +// --------------------------------------------------------------------------- +/** Data structure for a terrain vertex in a HMP4 file +*/ +struct Vertex_HMP4 +{ + uint16_t p_pos[3]; + uint8_t normals162index; + uint8_t pad; +} PACK_STRUCT; + +// --------------------------------------------------------------------------- +/** Data structure for a terrain vertex in a HMP5 file +*/ +struct Vertex_HMP5 +{ + uint16_t z; + uint8_t normals162index; + uint8_t pad; +} PACK_STRUCT; + +// --------------------------------------------------------------------------- +/** Data structure for a terrain vertex in a HMP7 file +*/ +struct Vertex_HMP7 +{ + uint16_t z; + int8_t normal_x,normal_y; +} PACK_STRUCT; + +#include "./Compiler/poppack1.h" + +} //! namespace HMP +} //! namespace Assimp \ No newline at end of file diff --git a/code/HMPLoader.h b/code/HMPLoader.h index 4012dbe87..2633b08eb 100644 --- a/code/HMPLoader.h +++ b/code/HMPLoader.h @@ -37,128 +37,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ - - //! -//! @file Definition of HMP importer class +//! @file Declaration of the HMP importer class //! #ifndef AI_HMPLOADER_H_INCLUDED #define AI_HMPLOADER_H_INCLUDED -#include "BaseImporter.h" +// public ASSIMP headers #include "../include/aiTypes.h" #include "../include/aiTexture.h" #include "../include/aiMaterial.h" -struct aiNode; +// internal headers +#include "BaseImporter.h" #include "MDLLoader.h" +#include "HMPFileData.h" -namespace Assimp -{ -class MaterialHelper; - -#define AI_HMP_MAGIC_NUMBER_BE_4 'HMP4' -#define AI_HMP_MAGIC_NUMBER_LE_4 '4PMH' - -#define AI_HMP_MAGIC_NUMBER_BE_5 'HMP5' -#define AI_HMP_MAGIC_NUMBER_LE_5 '5PMH' - -#define AI_HMP_MAGIC_NUMBER_BE_7 'HMP7' -#define AI_HMP_MAGIC_NUMBER_LE_7 '7PMH' - -namespace HMP -{ - -// ugly compiler dependent packing stuff -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) -# pragma pack(push,1) -# define PACK_STRUCT -#elif defined( __GNUC__ ) -# define PACK_STRUCT __attribute__((packed)) -#else -# error Compiler not supported. Never do this again. -#endif - -// --------------------------------------------------------------------------- -/** Data structure for the header of a HMP5 file. - * This is also used by HMP4 and HMP7, but with modifications -*/ -struct Header_HMP5 -{ - int8_t ident[4]; // "HMP5" - int32_t version; - - // ignored - float scale[3]; - float scale_origin[3]; - float boundingradius; - - //! Size of one triangle in x direction - float ftrisize_x; - //! Size of one triangle in y direction - float ftrisize_y; - //! Number of vertices in x direction - float fnumverts_x; - - //! Number of skins in the file - int32_t numskins; - - // can ignore this? - int32_t skinwidth; - int32_t skinheight; - - //!Number of vertices in the file - int32_t numverts; - - // ignored and zero - int32_t numtris; - - //! only one supported ... - int32_t numframes; - - //! Always 0 ... - int32_t num_stverts; - int32_t flags; - float size; -} PACK_STRUCT; - -// --------------------------------------------------------------------------- -/** Data structure for a terrain vertex in a HMP4 file -*/ -struct Vertex_HMP4 -{ - uint16_t p_pos[3]; - uint8_t normals162index; - uint8_t pad; -} PACK_STRUCT; - -// --------------------------------------------------------------------------- -/** Data structure for a terrain vertex in a HMP5 file -*/ -struct Vertex_HMP5 -{ - uint16_t z; - uint8_t normals162index; - uint8_t pad; -} PACK_STRUCT; - -// --------------------------------------------------------------------------- -/** Data structure for a terrain vertex in a HMP7 file -*/ -struct Vertex_HMP7 -{ - uint16_t z; - int8_t normal_x,normal_y; -} PACK_STRUCT; - -// reset packing to the original value -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) -# pragma pack( pop ) -#endif -#undef PACK_STRUCT - -}; //! namespace HMP +namespace Assimp { +using namespace HMP; // --------------------------------------------------------------------------- /** Used to load 3D GameStudio HMP files (terrains) diff --git a/code/HalfLifeFileData.h b/code/HalfLifeFileData.h index fb55bec31..7e0aa4ff2 100644 --- a/code/HalfLifeFileData.h +++ b/code/HalfLifeFileData.h @@ -49,21 +49,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef AI_MDLFILEHELPER2_H_INC #define AI_MDLFILEHELPER2_H_INC +#include "./Compiler/pushpack1.h" -// ugly compiler dependent packing stuff -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) -# pragma pack(push,1) -# define PACK_STRUCT -#elif defined( __GNUC__ ) -# define PACK_STRUCT __attribute__((packed)) -#else -# error Compiler not supported. Never do this again. -#endif - -namespace Assimp -{ -namespace MDL -{ +namespace Assimp { +namespace MDL { // magic bytes used in Half Life 2 MDL models #define AI_MDL_MAGIC_NUMBER_BE_HL2a 'IDST' @@ -151,11 +140,7 @@ struct Header_HL2 int32_t transitionindex; } PACK_STRUCT; -// reset packing to the original value -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) -# pragma pack( pop ) -#endif -#undef PACK_STRUCT +#include "./Compiler/poppack1.h" };}; // end namespaces #endif // ! AI_MDLFILEHELPER2_H_INC \ No newline at end of file diff --git a/code/MD2FileData.h b/code/MD2FileData.h index 67b1796a7..d9749d4de 100644 --- a/code/MD2FileData.h +++ b/code/MD2FileData.h @@ -50,15 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../include/aiMesh.h" #include "../include/aiAnim.h" -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) -# pragma pack(push,1) -# define PACK_STRUCT -#elif defined( __GNUC__ ) -# define PACK_STRUCT __attribute__((packed)) -#else -# error Compiler not supported -#endif - +#include "./Compiler/pushpack1.h" namespace Assimp { @@ -159,11 +151,7 @@ struct Skin char name[AI_MD2_MAXQPATH]; /* texture file name */ } PACK_STRUCT; -// reset packing to the original value -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) -# pragma pack( pop ) -#endif -#undef PACK_STRUCT +#include "./Compiler/poppack1.h" // --------------------------------------------------------------------------- diff --git a/code/MD3FileData.h b/code/MD3FileData.h index b3305c03c..36f5168c4 100644 --- a/code/MD3FileData.h +++ b/code/MD3FileData.h @@ -38,7 +38,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ -/** @file Defines the helper data structures for importing MD3 files */ +/** @file Defines the helper data structures for importing MD3 files. + http://linux.ucla.edu/~phaethon/q3/formats/md3format.html +*/ #ifndef AI_MD3FILEHELPER_H_INC #define AI_MD3FILEHELPER_H_INC @@ -50,21 +52,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../include/aiMesh.h" #include "../include/aiAnim.h" -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) -# pragma pack(push,1) -# define PACK_STRUCT -#elif defined( __GNUC__ ) -# define PACK_STRUCT __attribute__((packed)) -#else -# error Compiler not supported -#endif +#include "./Compiler/pushpack1.h" - -namespace Assimp -{ -// http://linux.ucla.edu/~phaethon/q3/formats/md3format.html -namespace MD3 -{ +namespace Assimp { +namespace MD3 { #define AI_MD3_MAGIC_NUMBER_BE 'IDP3' #define AI_MD3_MAGIC_NUMBER_LE '3PDI' @@ -239,11 +230,7 @@ struct Vertex uint16_t NORMAL; } PACK_STRUCT; -// reset packing to the original value -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) -# pragma pack( pop ) -#endif -#undef PACK_STRUCT +#include "./Compiler/poppack1.h" // --------------------------------------------------------------------------- /** \brief Unpack a Q3 16 bit vector to its full float3 representation diff --git a/code/MD4Loader.cpp b/code/MD4Loader.cpp deleted file mode 100644 index 7a353bfac..000000000 --- a/code/MD4Loader.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* ---------------------------------------------------------------------------- -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 the MD4 importer class */ -#include "MD4Loader.h" -#include "MaterialSystem.h" - -#include "../include/IOStream.h" -#include "../include/IOSystem.h" -#include "../include/aiMesh.h" -#include "../include/aiScene.h" -#include "../include/aiAssert.h" - -#include - -using namespace Assimp; - -// ------------------------------------------------------------------------------------------------ -// Constructor to be privately used by Importer -MD4Importer::MD4Importer() -{ -} -// ------------------------------------------------------------------------------------------------ -// Destructor, private as well -MD4Importer::~MD4Importer() -{ -} -// ------------------------------------------------------------------------------------------------ -// Returns whether the class can handle the format of the given file. -bool MD4Importer::CanRead( const std::string& pFile, IOSystem* pIOHandler) const -{ - // simple check of file extension is enough for the moment - std::string::size_type pos = pFile.find_last_of('.'); - // no file extension - can't read - if( pos == std::string::npos) - return false; - std::string extension = pFile.substr( pos); - - if (extension.length() < 4)return false; - if (extension[0] != '.')return false; - - // not brilliant but working ;-) - if( extension == ".md4" || extension == ".MD4" || - extension == ".mD4" || extension == ".Md4") - { - return true; - } -#if (!defined AI_MD4_DONT_SUPPORT_RAVENSOFT_MDR) - if (extension[1] != 'm' && extension[1] != 'M')return false; - if (extension[2] != 'd' && extension[2] != 'D')return false; - if (extension[3] != 'r' && extension[3] != 'R')return false; -#endif - - return true; -} -// ------------------------------------------------------------------------------------------------ -// Imports the given file into the given scene structure. -void MD4Importer::InternReadFile( - const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) -{ - boost::scoped_ptr file( pIOHandler->Open( pFile)); - - // Check whether we can read from the file - if( file.get() == NULL) - { - throw new ImportErrorException( "Failed to open md4/mdr file " + pFile + "."); - } - - // check whether the md4 file is large enough to contain - // at least the file header - size_t fileSize = file->FileSize(); - if( fileSize < sizeof(MD4::Header)) - { - throw new ImportErrorException( ".md4 File is too small."); - } - return; -} \ No newline at end of file diff --git a/code/MD4Loader.h b/code/MD4Loader.h deleted file mode 100644 index 2560f0cb1..000000000 --- a/code/MD4Loader.h +++ /dev/null @@ -1,107 +0,0 @@ -/* -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 Definition of the .MD4 importer class. */ -#ifndef AI_MD4LOADER_H_INCLUDED -#define AI_MD4LOADER_H_INCLUDED - -#include "BaseImporter.h" -#include "../include/aiTypes.h" - -struct aiNode; -#include "MD4FileData.h" - -namespace Assimp -{ -class MaterialHelper; - -using namespace MD4; - -// --------------------------------------------------------------------------- -/** Used to load MD4 files -*/ -class MD4Importer : public BaseImporter -{ - friend class Importer; - -protected: - /** Constructor to be privately used by Importer */ - MD4Importer(); - - /** Destructor, private as well */ - ~MD4Importer(); - -public: - - // ------------------------------------------------------------------- - /** Returns whether the class can handle the format of the given file. - * See BaseImporter::CanRead() for details. */ - bool CanRead( const std::string& pFile, IOSystem* pIOHandler) const; - -protected: - - // ------------------------------------------------------------------- - /** Called by Importer::GetExtensionList() for each loaded importer. - * See BaseImporter::GetExtensionList() for details - */ - void GetExtensionList(std::string& append) - { - append.append("*.md4;*.mdr"); - } - - // ------------------------------------------------------------------- - /** Imports the given file into the given scene structure. - * See BaseImporter::InternReadFile() for details - */ - void InternReadFile( const std::string& pFile, aiScene* pScene, - IOSystem* pIOHandler); - -protected: - - /** Header of the MD4 file */ - const MD4::Header* m_pcHeader; - - /** Buffer to hold the loaded file */ - const unsigned char* mBuffer; -}; - -} // end of namespace Assimp - -#endif // AI_3DSIMPORTER_H_INC \ No newline at end of file diff --git a/code/MDLFileData.h b/code/MDLFileData.h index 2cfe73950..d4910e198 100644 --- a/code/MDLFileData.h +++ b/code/MDLFileData.h @@ -58,15 +58,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../include/aiAnim.h" #include "../include/aiMaterial.h" -// ugly compiler dependent packing stuff -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) -# pragma pack(push,1) -# define PACK_STRUCT -#elif defined( __GNUC__ ) -# define PACK_STRUCT __attribute__((packed)) -#else -# error Compiler not supported. Never do this again. -#endif +#include "./Compiler/pushpack1.h" namespace Assimp { namespace MDL { @@ -116,15 +108,6 @@ namespace MDL { # define AI_MDL_MAX_TRIANGLES 2048 #endif -// helper macro that sets a pointer to NULL in debug builds -#if (!defined DEBUG_INVALIDATE_PTR) -# if (defined _DEBUG) -# define DEBUG_INVALIDATE_PTR(x) x = NULL; -# else -# define DEBUG_INVALIDATE_PTR(x) -# endif -#endif - // material key that is set for dummy materials that are // just referencing another material #if (!defined AI_MDL7_REFERRER_MATERIAL) @@ -747,11 +730,7 @@ struct GroupFrame SimpleFrame *frames; } PACK_STRUCT; -// reset packing to the original value -#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) -# pragma pack( pop ) -#endif -#undef PACK_STRUCT +#include "./Compiler/poppack1.h" // --------------------------------------------------------------------------- diff --git a/code/MD4FileData.h b/code/extra/MD4FileData.h similarity index 100% rename from code/MD4FileData.h rename to code/extra/MD4FileData.h diff --git a/include/Compiler/VisualStudio/stdint.h b/include/Compiler/MSVC/stdint.h similarity index 100% rename from include/Compiler/VisualStudio/stdint.h rename to include/Compiler/MSVC/stdint.h diff --git a/include/aiDefines.h b/include/aiDefines.h index 0cffe47ff..2eb0024a5 100644 --- a/include/aiDefines.h +++ b/include/aiDefines.h @@ -46,7 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if (defined _MSC_VER) // include stdint.h from the C98 standard -# include "Compiler/VisualStudio/stdint.h" +# include "Compiler/MSVC/stdint.h" # undef ASSIMP_API @@ -55,6 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ************************************************************ # if (defined ASSIMP_BUILD_DLL_EXPORT) # define ASSIMP_API __declspec(dllexport) +# pragma warning (disable : 4251) // ************************************************************ // Define ASSIMP_DLL before including Assimp to use ASSIMP in @@ -103,4 +104,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # endif #endif +#define AI_MATH_PI (3.1415926538) +#define AI_MATH_TWO_PI (AI_MATH_PI * 2.0) + #endif // !! AI_DEFINES_H_INC diff --git a/include/aiMesh.h b/include/aiMesh.h index 97d6ebe5e..98182f549 100644 --- a/include/aiMesh.h +++ b/include/aiMesh.h @@ -39,8 +39,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ -/** @file Defines the data structures in which the imported geometry is - returned by ASSIMP */ +/** @file Declares the data structures in which the imported geometry is + returned by ASSIMP: aiMesh, aiFace and aiBone data structures. */ #ifndef AI_MESH_H_INC #define AI_MESH_H_INC @@ -110,9 +110,7 @@ struct aiFace else if (this->mIndices && this->mNumIndices == o.mNumIndices) { for (unsigned int i = 0;i < this->mNumIndices;++i) - { if (this->mIndices[i] != o.mIndices[i])return false; - } return true; } return false; @@ -196,11 +194,11 @@ struct aiBone if (other.mWeights && other.mNumWeights) { mWeights = new aiVertexWeight[mNumWeights]; - memcpy(mWeights,other.mWeights,mNumWeights * sizeof(aiVertexWeight)); + ::memcpy(mWeights,other.mWeights,mNumWeights * sizeof(aiVertexWeight)); } } - //! Destructor to delete the array of vertex weights + //! Destructor - deletes the array of vertex weights ~aiBone() { if (mNumWeights)delete [] mWeights; @@ -210,19 +208,24 @@ struct aiBone #if (!defined AI_MAX_NUMBER_OF_COLOR_SETS) + +// --------------------------------------------------------------------------- /** Maximum number of vertex color sets per mesh. * * Normally: Diffuse, specular, ambient and emissive -* However, one could use the vertex color sets for any other purpose, too. +* However one could use the vertex color sets for any other purpose, too. * * \note Some internal structures expect (and assert) this value * to be at least 4 */ -#define AI_MAX_NUMBER_OF_COLOR_SETS 0x4 +// --------------------------------------------------------------------------- +# define AI_MAX_NUMBER_OF_COLOR_SETS 0x4 #endif // !! AI_MAX_NUMBER_OF_COLOR_SETS #if (!defined AI_MAX_NUMBER_OF_TEXTURECOORDS) + +// --------------------------------------------------------------------------- /** Maximum number of texture coord sets (UV(W) channels) per mesh * * The material system uses the AI_MATKEY_UVWSRC_XXX keys to specify @@ -231,7 +234,8 @@ struct aiBone * \note Some internal structures expect (and assert) this value * to be at least 4 */ -#define AI_MAX_NUMBER_OF_TEXTURECOORDS 0x4 +// --------------------------------------------------------------------------- +# define AI_MAX_NUMBER_OF_TEXTURECOORDS 0x4 // NOTE (Aramis): If you change these values, make sure that you also // change the corresponding values in all Assimp ports. @@ -260,6 +264,7 @@ struct aiBone * \note The mPositions member is not optional, although a Has()-Method is * provided for it. */ +// --------------------------------------------------------------------------- struct aiMesh { /** The number of vertices in this mesh. @@ -343,12 +348,24 @@ struct aiMesh C_STRUCT aiBone** mBones; /** The material used by this mesh. - * A mesh does use only a single material. If an imported model uses multiple materials, - * the import splits up the mesh. Use this value as index into the scene's material list. + * A mesh does use only a single material. If an imported model uses + * multiple materials, the import splits up the mesh. Use this value + * as index into the scene's material list. */ unsigned int mMaterialIndex; + /** The maximum vertex smooth angle for the mesh. + * If the angle between two vertex normals is larger, + * the vertex normals should not be smoothed. The GenVertexNormals-Step + * takes care of this value. The angle is specified in radians. + * It is 2PI if the source file didn't contain any additional + * information related to the calculation of vertex normals. + */ + float mMaxSmoothingAngle; + #ifdef __cplusplus + + //! Default constructor. Initializes all members to 0 aiMesh() { mNumVertices = 0; mNumFaces = 0; @@ -364,8 +381,10 @@ struct aiMesh mColors[a] = NULL; mNumBones = 0; mBones = NULL; mMaterialIndex = 0; + mMaxSmoothingAngle = (float)AI_MATH_TWO_PI; } + //! Deletes all storage allocated for the mesh ~aiMesh() { if ( mNumVertices) // fix to make this work for invalid scenes, too @@ -392,7 +411,8 @@ struct aiMesh } //! Check whether the mesh contains positions. If no special scene flags - //! are set this should always return true + //! (such as AI_SCENE_FLAGS_ANIM_SKELETON_ONLY) are set this MUST + //! always return true inline bool HasPositions() const { return mVertices != NULL; } diff --git a/include/aiPostProcess.h b/include/aiPostProcess.h index ed5dc00ac..c9ccdca07 100644 --- a/include/aiPostProcess.h +++ b/include/aiPostProcess.h @@ -148,17 +148,6 @@ enum aiPostProcessSteps */ aiProcess_ValidateDataStructure = 0x400, - /** This step tries to determine which meshes have normal vectors - * that are facing inwards. The algorithm is simple but effective: - * the bounding box of all vertices + their normals is compared against - * the volume of the bounding box of all vertices without their normals. - * This works well for most objects, problems might occur with planar - * surfaces. However the step tries to filter such cases out. - * The step inverts all infacing normals. Generally it is recommended - * to enable this step. - */ - aiProcess_FixInfacingNormals = 0x800, - /** Reorders triangles for vertex cache locality and thus better performance. * The step tries to improve the ACMR (average post-transform vertex cache * miss ratio) for all meshes. The step runs in O(n) and is roughly @@ -174,6 +163,17 @@ enum aiPostProcessSteps * can't do that if two meshes have different materials. */ aiProcess_RemoveRedundantMaterials = 0x1000, + + /** This step tries to determine which meshes have normal vectors + * that are facing inwards. The algorithm is simple but effective: + * the bounding box of all vertices + their normals is compared against + * the volume of the bounding box of all vertices without their normals. + * This works well for most objects, problems might occur with planar + * surfaces. However the step tries to filter such cases out. + * The step inverts all infacing normals. Generally it is recommended + * to enable this step. + */ + aiProcess_FixInfacingNormals = 0x2000, }; diff --git a/tools/assimp_view/assimp_view.cpp b/tools/assimp_view/assimp_view.cpp index af6413bab..3202ebf44 100644 --- a/tools/assimp_view/assimp_view.cpp +++ b/tools/assimp_view/assimp_view.cpp @@ -133,7 +133,8 @@ DWORD WINAPI LoadThreadProc(LPVOID lpParameter) aiProcess_GenSmoothNormals | // generate smooth normal vectors if not existing aiProcess_ConvertToLeftHanded | // convert everything to D3D left handed space aiProcess_SplitLargeMeshes | // split large, unrenderable meshes into submeshes - aiProcess_ValidateDataStructure | aiProcess_ImproveCacheLocality | aiProcess_RemoveRedundantMaterials); // validate the output data structure + aiProcess_ValidateDataStructure | aiProcess_ImproveCacheLocality + | aiProcess_RemoveRedundantMaterials | aiProcess_FixInfacingNormals); // validate the output data structure // get the end time of zje operation, calculate delta t double fEnd = (double)timeGetTime(); diff --git a/workspaces/vc8/assimp.vcproj b/workspaces/vc8/assimp.vcproj index d85405d8b..6ad2d4482 100644 --- a/workspaces/vc8/assimp.vcproj +++ b/workspaces/vc8/assimp.vcproj @@ -678,10 +678,10 @@ Name="Compiler" > @@ -879,14 +879,14 @@ @@ -985,10 +985,18 @@ RelativePath="..\..\code\extra\MakeVerboseFormat.h" > + + + + @@ -1179,12 +1187,8 @@ - -