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
pull/1/head
aramis_acg 2008-08-08 15:18:28 +00:00
parent 30ecc82181
commit 4e59426e09
20 changed files with 308 additions and 487 deletions

View File

@ -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 #ifndef AI_3DSFILEHELPER_H_INC
#define 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" #include "SpatialSort.h"
namespace Assimp namespace Assimp {
{ namespace Dot3DS {
namespace Dot3DS
{
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) #include "./Compiler/pushpack1.h"
# pragma pack(push,2)
# define PACK_STRUCT #ifdef _MSC_VER
#elif defined( __GNUC__ ) # define sprintf sprintf_s
# define PACK_STRUCT __attribute__((packed))
#else
# error Compiler not supported
#endif #endif
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -118,9 +115,7 @@ public:
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// enum for all chunks in 3ds files. Unused // enum for all chunks in 3ds files. Unused
// ones are commented, list is not complete since // ones are commented, list is not complete since
// there are many undocumented chunks. // there are many undocumented chunks
//
// Links: http://www.jalix.org/ressources/graphics/3DS/_unofficials/3ds-unofficial.txt
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
enum enum
{ {
@ -317,10 +312,7 @@ public:
}; };
}; };
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) #include "./Compiler/poppack1.h"
# pragma pack( pop )
#endif
#undef PACK_STRUCT
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** Helper structure representing a 3ds mesh face */ /** Helper structure representing a 3ds mesh face */
@ -352,18 +344,18 @@ struct Texture
{ {
//! Default constructor //! Default constructor
Texture() Texture()
: : mScaleU (1.0f)
mScaleU(1.0f), , mScaleV (1.0f)
mScaleV(1.0f), , mOffsetU (0.0f)
mOffsetU(0.0f), , mOffsetV (0.0f)
mOffsetV(0.0f), , mRotation (0.0f)
mRotation(0.0f), , iUVSrc (0)
iUVSrc(0), , mMapMode (aiTextureMapMode_Wrap)
mMapMode(aiTextureMapMode_Wrap)
{ {
mTextureBlend = std::numeric_limits<float>::quiet_NaN(); mTextureBlend = std::numeric_limits<float>::quiet_NaN();
} }
//! Specifies the blending factor for the texture
//! Specifies the blend factor for the texture
float mTextureBlend; float mTextureBlend;
//! Specifies the filename of the texture //! Specifies the filename of the texture
@ -402,7 +394,7 @@ struct Material
static int iCnt = 0; static int iCnt = 0;
char szTemp[128]; char szTemp[128];
sprintf(szTemp,"$$_UNNAMED_%i_$$",iCnt++); sprintf(szTemp,"UNNAMED_%i",iCnt++);
mName = szTemp; mName = szTemp;
} }
@ -458,11 +450,7 @@ struct Mesh
static int iCnt = 0; static int iCnt = 0;
char szTemp[128]; char szTemp[128];
#if _MSC_VER >= 1400 ::sprintf(szTemp,"UNNAMED_%i",iCnt++);
::sprintf_s(szTemp,"$$_UNNAMED_%i_$$",iCnt++);
#else
::sprintf(szTemp,"$$_UNNAMED_%i_$$",iCnt++);
#endif
mName = szTemp; mName = szTemp;
} }
@ -499,11 +487,7 @@ struct Node
static int iCnt = 0; static int iCnt = 0;
char szTemp[128]; char szTemp[128];
#if _MSC_VER >= 1400 ::sprintf(szTemp,"UNNAMED_%i",iCnt++);
::sprintf_s(szTemp,"$$_UNNAMED_%i_$$",iCnt++);
#else
::sprintf(szTemp,"$$_UNNAMED_%i_$$",iCnt++);
#endif
mName = szTemp; mName = szTemp;
#ifdef AI_3DS_KEYFRAME_ANIMATION #ifdef AI_3DS_KEYFRAME_ANIMATION

View File

@ -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

View File

@ -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

View File

@ -59,6 +59,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace Assimp; using namespace Assimp;
#ifdef _MSC_VER
# define sprintf sprintf_s
#endif
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer // Constructor to be privately used by Importer
FixInfacingNormalsProcess::FixInfacingNormalsProcess() FixInfacingNormalsProcess::FixInfacingNormalsProcess()
@ -88,7 +92,7 @@ void FixInfacingNormalsProcess::Execute( aiScene* pScene)
bool bHas = false; bool bHas = false;
for( unsigned int a = 0; a < pScene->mNumMeshes; a++) 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."); if (bHas)DefaultLogger::get()->debug("FixInfacingNormalsProcess finished. At least one mesh' normals have been flipped.");
else DefaultLogger::get()->debug("FixInfacingNormalsProcess finished"); else DefaultLogger::get()->debug("FixInfacingNormalsProcess finished");
@ -96,7 +100,7 @@ void FixInfacingNormalsProcess::Execute( aiScene* pScene)
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Apply the step to the mesh // Apply the step to the mesh
bool FixInfacingNormalsProcess::ProcessMesh( aiMesh* pcMesh) bool FixInfacingNormalsProcess::ProcessMesh( aiMesh* pcMesh, unsigned int index)
{ {
ai_assert(NULL != pcMesh); ai_assert(NULL != pcMesh);
@ -159,8 +163,12 @@ bool FixInfacingNormalsProcess::ProcessMesh( aiMesh* pcMesh)
if (::fabsf(fDelta0_x * fDelta1_yz) < if (::fabsf(fDelta0_x * fDelta1_yz) <
::fabsf(fDelta1_x * fDelta1_y * fDelta1_z)) ::fabsf(fDelta1_x * fDelta1_y * fDelta1_z))
{ {
DefaultLogger::get()->info("Found a mesh whose normals are facing inwards " if (!DefaultLogger::isNullLogger())
"(or the model is too planar or concave). Flipping mesh normals ..."); {
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) for (unsigned int i = 0; i < pcMesh->mNumVertices;++i)
{ {

View File

@ -88,7 +88,7 @@ protected:
/** Executes the step on the given mesh /** Executes the step on the given mesh
* @param pMesh The mesh to process. * @param pMesh The mesh to process.
*/ */
bool ProcessMesh( aiMesh* pMesh); bool ProcessMesh( aiMesh* pMesh, unsigned int index);
}; };
} // end of namespace Assimp } // end of namespace Assimp

133
code/HMPFileData.h 100644
View File

@ -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

View File

@ -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 #ifndef AI_HMPLOADER_H_INCLUDED
#define AI_HMPLOADER_H_INCLUDED #define AI_HMPLOADER_H_INCLUDED
#include "BaseImporter.h" // public ASSIMP headers
#include "../include/aiTypes.h" #include "../include/aiTypes.h"
#include "../include/aiTexture.h" #include "../include/aiTexture.h"
#include "../include/aiMaterial.h" #include "../include/aiMaterial.h"
struct aiNode; // internal headers
#include "BaseImporter.h"
#include "MDLLoader.h" #include "MDLLoader.h"
#include "HMPFileData.h"
namespace Assimp namespace Assimp {
{ using namespace HMP;
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
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** Used to load 3D GameStudio HMP files (terrains) /** Used to load 3D GameStudio HMP files (terrains)

View File

@ -49,21 +49,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_MDLFILEHELPER2_H_INC #ifndef AI_MDLFILEHELPER2_H_INC
#define AI_MDLFILEHELPER2_H_INC #define AI_MDLFILEHELPER2_H_INC
#include "./Compiler/pushpack1.h"
// ugly compiler dependent packing stuff namespace Assimp {
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) namespace MDL {
# 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
{
// magic bytes used in Half Life 2 MDL models // magic bytes used in Half Life 2 MDL models
#define AI_MDL_MAGIC_NUMBER_BE_HL2a 'IDST' #define AI_MDL_MAGIC_NUMBER_BE_HL2a 'IDST'
@ -151,11 +140,7 @@ struct Header_HL2
int32_t transitionindex; int32_t transitionindex;
} PACK_STRUCT; } PACK_STRUCT;
// reset packing to the original value #include "./Compiler/poppack1.h"
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
# pragma pack( pop )
#endif
#undef PACK_STRUCT
};}; // end namespaces };}; // end namespaces
#endif // ! AI_MDLFILEHELPER2_H_INC #endif // ! AI_MDLFILEHELPER2_H_INC

View File

@ -50,15 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../include/aiMesh.h" #include "../include/aiMesh.h"
#include "../include/aiAnim.h" #include "../include/aiAnim.h"
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) #include "./Compiler/pushpack1.h"
# pragma pack(push,1)
# define PACK_STRUCT
#elif defined( __GNUC__ )
# define PACK_STRUCT __attribute__((packed))
#else
# error Compiler not supported
#endif
namespace Assimp namespace Assimp
{ {
@ -159,11 +151,7 @@ struct Skin
char name[AI_MD2_MAXQPATH]; /* texture file name */ char name[AI_MD2_MAXQPATH]; /* texture file name */
} PACK_STRUCT; } PACK_STRUCT;
// reset packing to the original value #include "./Compiler/poppack1.h"
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
# pragma pack( pop )
#endif
#undef PACK_STRUCT
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -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 #ifndef AI_MD3FILEHELPER_H_INC
#define 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/aiMesh.h"
#include "../include/aiAnim.h" #include "../include/aiAnim.h"
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) #include "./Compiler/pushpack1.h"
# pragma pack(push,1)
# define PACK_STRUCT
#elif defined( __GNUC__ )
# define PACK_STRUCT __attribute__((packed))
#else
# error Compiler not supported
#endif
namespace Assimp {
namespace Assimp namespace MD3 {
{
// http://linux.ucla.edu/~phaethon/q3/formats/md3format.html
namespace MD3
{
#define AI_MD3_MAGIC_NUMBER_BE 'IDP3' #define AI_MD3_MAGIC_NUMBER_BE 'IDP3'
#define AI_MD3_MAGIC_NUMBER_LE '3PDI' #define AI_MD3_MAGIC_NUMBER_LE '3PDI'
@ -239,11 +230,7 @@ struct Vertex
uint16_t NORMAL; uint16_t NORMAL;
} PACK_STRUCT; } PACK_STRUCT;
// reset packing to the original value #include "./Compiler/poppack1.h"
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
# pragma pack( pop )
#endif
#undef PACK_STRUCT
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** \brief Unpack a Q3 16 bit vector to its full float3 representation /** \brief Unpack a Q3 16 bit vector to its full float3 representation

View File

@ -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 <boost/scoped_ptr.hpp>
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<IOStream> 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;
}

View File

@ -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

View File

@ -58,15 +58,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../include/aiAnim.h" #include "../include/aiAnim.h"
#include "../include/aiMaterial.h" #include "../include/aiMaterial.h"
// ugly compiler dependent packing stuff #include "./Compiler/pushpack1.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. Never do this again.
#endif
namespace Assimp { namespace Assimp {
namespace MDL { namespace MDL {
@ -116,15 +108,6 @@ namespace MDL {
# define AI_MDL_MAX_TRIANGLES 2048 # define AI_MDL_MAX_TRIANGLES 2048
#endif #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 // material key that is set for dummy materials that are
// just referencing another material // just referencing another material
#if (!defined AI_MDL7_REFERRER_MATERIAL) #if (!defined AI_MDL7_REFERRER_MATERIAL)
@ -747,11 +730,7 @@ struct GroupFrame
SimpleFrame *frames; SimpleFrame *frames;
} PACK_STRUCT; } PACK_STRUCT;
// reset packing to the original value #include "./Compiler/poppack1.h"
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
# pragma pack( pop )
#endif
#undef PACK_STRUCT
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -46,7 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#if (defined _MSC_VER) #if (defined _MSC_VER)
// include stdint.h from the C98 standard // include stdint.h from the C98 standard
# include "Compiler/VisualStudio/stdint.h" # include "Compiler/MSVC/stdint.h"
# undef ASSIMP_API # 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) # if (defined ASSIMP_BUILD_DLL_EXPORT)
# define ASSIMP_API __declspec(dllexport) # define ASSIMP_API __declspec(dllexport)
# pragma warning (disable : 4251)
// ************************************************************ // ************************************************************
// Define ASSIMP_DLL before including Assimp to use ASSIMP in // 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
#endif #endif
#define AI_MATH_PI (3.1415926538)
#define AI_MATH_TWO_PI (AI_MATH_PI * 2.0)
#endif // !! AI_DEFINES_H_INC #endif // !! AI_DEFINES_H_INC

View File

@ -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 /** @file Declares the data structures in which the imported geometry is
returned by ASSIMP */ returned by ASSIMP: aiMesh, aiFace and aiBone data structures. */
#ifndef AI_MESH_H_INC #ifndef AI_MESH_H_INC
#define AI_MESH_H_INC #define AI_MESH_H_INC
@ -110,9 +110,7 @@ struct aiFace
else if (this->mIndices && this->mNumIndices == o.mNumIndices) else if (this->mIndices && this->mNumIndices == o.mNumIndices)
{ {
for (unsigned int i = 0;i < this->mNumIndices;++i) for (unsigned int i = 0;i < this->mNumIndices;++i)
{
if (this->mIndices[i] != o.mIndices[i])return false; if (this->mIndices[i] != o.mIndices[i])return false;
}
return true; return true;
} }
return false; return false;
@ -196,11 +194,11 @@ struct aiBone
if (other.mWeights && other.mNumWeights) if (other.mWeights && other.mNumWeights)
{ {
mWeights = new aiVertexWeight[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() ~aiBone()
{ {
if (mNumWeights)delete [] mWeights; if (mNumWeights)delete [] mWeights;
@ -210,19 +208,24 @@ struct aiBone
#if (!defined AI_MAX_NUMBER_OF_COLOR_SETS) #if (!defined AI_MAX_NUMBER_OF_COLOR_SETS)
// ---------------------------------------------------------------------------
/** Maximum number of vertex color sets per mesh. /** Maximum number of vertex color sets per mesh.
* *
* Normally: Diffuse, specular, ambient and emissive * 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 * \note Some internal structures expect (and assert) this value
* to be at least 4 * 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 #endif // !! AI_MAX_NUMBER_OF_COLOR_SETS
#if (!defined AI_MAX_NUMBER_OF_TEXTURECOORDS) #if (!defined AI_MAX_NUMBER_OF_TEXTURECOORDS)
// ---------------------------------------------------------------------------
/** Maximum number of texture coord sets (UV(W) channels) per mesh /** Maximum number of texture coord sets (UV(W) channels) per mesh
* *
* The material system uses the AI_MATKEY_UVWSRC_XXX keys to specify * 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 * \note Some internal structures expect (and assert) this value
* to be at least 4 * 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 // NOTE (Aramis): If you change these values, make sure that you also
// change the corresponding values in all Assimp ports. // 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 * \note The mPositions member is not optional, although a Has()-Method is
* provided for it. * provided for it.
*/ */
// ---------------------------------------------------------------------------
struct aiMesh struct aiMesh
{ {
/** The number of vertices in this mesh. /** The number of vertices in this mesh.
@ -343,12 +348,24 @@ struct aiMesh
C_STRUCT aiBone** mBones; C_STRUCT aiBone** mBones;
/** The material used by this mesh. /** The material used by this mesh.
* A mesh does use only a single material. If an imported model uses multiple materials, * A mesh does use only a single material. If an imported model uses
* the import splits up the mesh. Use this value as index into the scene's material list. * multiple materials, the import splits up the mesh. Use this value
* as index into the scene's material list.
*/ */
unsigned int mMaterialIndex; 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 #ifdef __cplusplus
//! Default constructor. Initializes all members to 0
aiMesh() aiMesh()
{ {
mNumVertices = 0; mNumFaces = 0; mNumVertices = 0; mNumFaces = 0;
@ -364,8 +381,10 @@ struct aiMesh
mColors[a] = NULL; mColors[a] = NULL;
mNumBones = 0; mBones = NULL; mNumBones = 0; mBones = NULL;
mMaterialIndex = 0; mMaterialIndex = 0;
mMaxSmoothingAngle = (float)AI_MATH_TWO_PI;
} }
//! Deletes all storage allocated for the mesh
~aiMesh() ~aiMesh()
{ {
if ( mNumVertices) // fix to make this work for invalid scenes, too 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 //! 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 inline bool HasPositions() const
{ return mVertices != NULL; } { return mVertices != NULL; }

View File

@ -148,17 +148,6 @@ enum aiPostProcessSteps
*/ */
aiProcess_ValidateDataStructure = 0x400, 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. /** Reorders triangles for vertex cache locality and thus better performance.
* The step tries to improve the ACMR (average post-transform vertex cache * 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 * 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. * can't do that if two meshes have different materials.
*/ */
aiProcess_RemoveRedundantMaterials = 0x1000, 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,
}; };

View File

@ -133,7 +133,8 @@ DWORD WINAPI LoadThreadProc(LPVOID lpParameter)
aiProcess_GenSmoothNormals | // generate smooth normal vectors if not existing aiProcess_GenSmoothNormals | // generate smooth normal vectors if not existing
aiProcess_ConvertToLeftHanded | // convert everything to D3D left handed space aiProcess_ConvertToLeftHanded | // convert everything to D3D left handed space
aiProcess_SplitLargeMeshes | // split large, unrenderable meshes into submeshes 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 // get the end time of zje operation, calculate delta t
double fEnd = (double)timeGetTime(); double fEnd = (double)timeGetTime();

View File

@ -678,10 +678,10 @@
Name="Compiler" Name="Compiler"
> >
<Filter <Filter
Name="VisualStudio" Name="MSVC"
> >
<File <File
RelativePath="..\..\include\Compiler\VisualStudio\stdint.h" RelativePath="..\..\include\Compiler\MSVC\stdint.h"
> >
</File> </File>
</Filter> </Filter>
@ -879,14 +879,14 @@
</File> </File>
</Filter> </Filter>
<Filter <Filter
Name="MD4" Name="Compiler"
> >
<File <File
RelativePath="..\..\code\MD4FileData.h" RelativePath="..\..\code\Compiler\poppack1.h"
> >
</File> </File>
<File <File
RelativePath="..\..\code\MD4Loader.h" RelativePath="..\..\code\Compiler\pushpack1.h"
> >
</File> </File>
</Filter> </Filter>
@ -985,10 +985,18 @@
RelativePath="..\..\code\extra\MakeVerboseFormat.h" RelativePath="..\..\code\extra\MakeVerboseFormat.h"
> >
</File> </File>
<File
RelativePath="..\..\code\extra\MD4FileData.h"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="HMPLoader" Name="HMPLoader"
> >
<File
RelativePath="..\..\code\HMPFileData.h"
>
</File>
<File <File
RelativePath="..\..\code\HMPLoader.h" RelativePath="..\..\code\HMPLoader.h"
> >
@ -1179,12 +1187,8 @@
</File> </File>
</Filter> </Filter>
<Filter <Filter
Name="MD4" Name="Compiler"
> >
<File
RelativePath="..\..\code\MD4Loader.cpp"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="X" Name="X"