worked on be stuff for mdl loader

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@223 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
alil 2008-11-02 22:21:07 +00:00
parent d54c695be4
commit 49b66d47dc
4 changed files with 223 additions and 123 deletions

View File

@ -813,7 +813,7 @@ struct IntBone_MDL7 : aiBone
struct IntFrameInfo_MDL7 struct IntFrameInfo_MDL7
{ {
//! Construction from an existing frame header //! Construction from an existing frame header
IntFrameInfo_MDL7(const MDL::Frame_MDL7* _pcFrame,unsigned int _iIndex) IntFrameInfo_MDL7(BE_NCONST MDL::Frame_MDL7* _pcFrame,unsigned int _iIndex)
: iIndex(_iIndex) : iIndex(_iIndex)
, pcFrame(_pcFrame) , pcFrame(_pcFrame)
{} {}
@ -822,7 +822,7 @@ struct IntFrameInfo_MDL7
unsigned int iIndex; unsigned int iIndex;
//! Points to the header of the frame //! Points to the header of the frame
const MDL::Frame_MDL7* pcFrame; BE_NCONST MDL::Frame_MDL7* pcFrame;
}; };
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -839,7 +839,7 @@ struct IntGroupInfo_MDL7
{} {}
//! Construction from an existing group header //! Construction from an existing group header
IntGroupInfo_MDL7(const MDL::Group_MDL7* _pcGroup,unsigned int _iIndex) IntGroupInfo_MDL7(BE_NCONST MDL::Group_MDL7* _pcGroup, unsigned int _iIndex)
: iIndex(_iIndex) : iIndex(_iIndex)
, pcGroup(_pcGroup) , pcGroup(_pcGroup)
{} {}
@ -848,16 +848,16 @@ struct IntGroupInfo_MDL7
unsigned int iIndex; unsigned int iIndex;
//! Points to the header of the group //! Points to the header of the group
const MDL::Group_MDL7* pcGroup; BE_NCONST MDL::Group_MDL7* pcGroup;
//! Points to the beginning of the uv coordinate section //! Points to the beginning of the uv coordinate section
const MDL::TexCoord_MDL7* pcGroupUVs; BE_NCONST MDL::TexCoord_MDL7* pcGroupUVs;
//! Points to the beginning of the triangle section //! Points to the beginning of the triangle section
const MDL::Triangle_MDL7* pcGroupTris; BE_NCONST MDL::Triangle_MDL7* pcGroupTris;
//! Points to the beginning of the vertex section //! Points to the beginning of the vertex section
const MDL::Vertex_MDL7* pcGroupVerts; BE_NCONST MDL::Vertex_MDL7* pcGroupVerts;
}; };
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -61,7 +61,7 @@ using namespace Assimp;
#endif #endif
#if (!defined _AI_MDL7_ACCESS_PTR) #if (!defined _AI_MDL7_ACCESS_PTR)
# define _AI_MDL7_ACCESS_PTR(_data, _index, _limit, _type) \ # define _AI_MDL7_ACCESS_PTR(_data, _index, _limit, _type) \
((const _type*)(((const char*)_data) + _index * _limit)) ((BE_NCONST _type*)(((const char*)_data) + _index * _limit))
#endif #endif
#if (!defined _AI_MDL7_ACCESS_VERT) #if (!defined _AI_MDL7_ACCESS_VERT)
# define _AI_MDL7_ACCESS_VERT(_data, _index, _limit) \ # define _AI_MDL7_ACCESS_VERT(_data, _index, _limit) \
@ -86,6 +86,7 @@ MDLImporter::~MDLImporter()
// Returns whether the class can handle the format of the given file. // Returns whether the class can handle the format of the given file.
bool MDLImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler) const bool MDLImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler) const
{ {
(void)pIOHandler; //this avoids the compiler warning of unused element
// simple check of file extension is enough for the moment // simple check of file extension is enough for the moment
std::string::size_type pos = pFile.find_last_of('.'); std::string::size_type pos = pFile.find_last_of('.');
// no file extension - can't read // no file extension - can't read
@ -330,19 +331,19 @@ void MDLImporter::InternReadFile_Quake1( )
{ {
ai_assert(NULL != pScene); ai_assert(NULL != pScene);
mpcHeader = (BE_NCONST MDL::Header*)this->mBuffer; BE_NCONST MDL::Header *pcHeader = (BE_NCONST MDL::Header*)this->mBuffer;
#ifdef AI_BUILD_BIG_ENDIAN #ifdef AI_BUILD_BIG_ENDIAN
FlipQuakeHeader(mpcHeader); FlipQuakeHeader(pcHeader);
#endif #endif
ValidateHeader_Quake1(mpcHeader); ValidateHeader_Quake1(pcHeader);
// current cursor position in the file // current cursor position in the file
const unsigned char* szCurrent = (const unsigned char*)(mpcHeader+1); const unsigned char* szCurrent = (const unsigned char*)(pcHeader+1);
// need to read all textures // need to read all textures
for (unsigned int i = 0; i < (unsigned int)mpcHeader->num_skins;++i) for (unsigned int i = 0; i < (unsigned int)pcHeader->num_skins;++i)
{ {
union{BE_NCONST MDL::Skin* pcSkin;BE_NCONST MDL::GroupSkin* pcGroupSkin;}; union{BE_NCONST MDL::Skin* pcSkin;BE_NCONST MDL::GroupSkin* pcGroupSkin;};
pcSkin = (BE_NCONST MDL::Skin*)szCurrent; pcSkin = (BE_NCONST MDL::Skin*)szCurrent;
@ -365,7 +366,7 @@ void MDLImporter::InternReadFile_Quake1( )
this->CreateTextureARGB8_3DGS_MDL3(szCurrent + iNumImages * sizeof(float)); this->CreateTextureARGB8_3DGS_MDL3(szCurrent + iNumImages * sizeof(float));
} }
// go to the end of the skin section / the beginning of the next skin // go to the end of the skin section / the beginning of the next skin
szCurrent += mpcHeader->skinheight * mpcHeader->skinwidth + szCurrent += pcHeader->skinheight * pcHeader->skinwidth +
sizeof(float) * iNumImages; sizeof(float) * iNumImages;
} }
} }
@ -380,11 +381,11 @@ void MDLImporter::InternReadFile_Quake1( )
} }
// get a pointer to the texture coordinates // get a pointer to the texture coordinates
BE_NCONST MDL::TexCoord* pcTexCoords = (BE_NCONST MDL::TexCoord*)szCurrent; BE_NCONST MDL::TexCoord* pcTexCoords = (BE_NCONST MDL::TexCoord*)szCurrent;
szCurrent += sizeof(MDL::TexCoord) * mpcHeader->num_verts; szCurrent += sizeof(MDL::TexCoord) * pcHeader->num_verts;
// get a pointer to the triangles // get a pointer to the triangles
BE_NCONST MDL::Triangle* pcTriangles = (BE_NCONST MDL::Triangle*)szCurrent; BE_NCONST MDL::Triangle* pcTriangles = (BE_NCONST MDL::Triangle*)szCurrent;
szCurrent += sizeof(MDL::Triangle) * mpcHeader->num_tris; szCurrent += sizeof(MDL::Triangle) * pcHeader->num_tris;
VALIDATE_FILE_SIZE(szCurrent); VALIDATE_FILE_SIZE(szCurrent);
// now get a pointer to the first frame in the file // now get a pointer to the first frame in the file
@ -405,18 +406,18 @@ void MDLImporter::InternReadFile_Quake1( )
BE_NCONST MDL::Vertex* pcVertices = (BE_NCONST MDL::Vertex*) ((pcFirstFrame->name) + BE_NCONST MDL::Vertex* pcVertices = (BE_NCONST MDL::Vertex*) ((pcFirstFrame->name) +
sizeof(pcFirstFrame->name)); sizeof(pcFirstFrame->name));
VALIDATE_FILE_SIZE((const unsigned char*)(pcVertices + mpcHeader->num_verts)); VALIDATE_FILE_SIZE((const unsigned char*)(pcVertices + pcHeader->num_verts));
#ifdef AI_BUILD_BIG_ENDIAN #ifdef AI_BUILD_BIG_ENDIAN
for (unsigned int i = 0; i<mpcHeader->num_verts;++i) for (int i = 0; i<pcHeader->num_verts;++i)
{ {
AI_SWAP4( pcTexCoords[i].onseam ); AI_SWAP4( pcTexCoords[i].onseam );
AI_SWAP4( pcTexCoords[i].s ); AI_SWAP4( pcTexCoords[i].s );
AI_SWAP4( pcTexCoords[i].t ); AI_SWAP4( pcTexCoords[i].t );
} }
for (unsigned int i = 0; i<mpcHeader->num_tris;++i) for (int i = 0; i<pcHeader->num_tris;++i)
{ {
AI_SWAP4( pcTriangles[i].facesfront); AI_SWAP4( pcTriangles[i].facesfront);
AI_SWAP4( pcTriangles[i].vertex[0]); AI_SWAP4( pcTriangles[i].vertex[0]);
@ -434,8 +435,8 @@ void MDLImporter::InternReadFile_Quake1( )
aiMesh* pcMesh = new aiMesh(); aiMesh* pcMesh = new aiMesh();
pcMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE; pcMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
pcMesh->mNumVertices = mpcHeader->num_tris * 3; pcMesh->mNumVertices = pcHeader->num_tris * 3;
pcMesh->mNumFaces = mpcHeader->num_tris; pcMesh->mNumFaces = pcHeader->num_tris;
pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices]; pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices];
pcMesh->mTextureCoords[0] = new aiVector3D[pcMesh->mNumVertices]; pcMesh->mTextureCoords[0] = new aiVector3D[pcMesh->mNumVertices];
pcMesh->mFaces = new aiFace[pcMesh->mNumFaces]; pcMesh->mFaces = new aiFace[pcMesh->mNumFaces];
@ -453,7 +454,7 @@ void MDLImporter::InternReadFile_Quake1( )
// now iterate through all triangles // now iterate through all triangles
unsigned int iCurrent = 0; unsigned int iCurrent = 0;
for (unsigned int i = 0; i < (unsigned int) mpcHeader->num_tris;++i) for (unsigned int i = 0; i < (unsigned int) pcHeader->num_tris;++i)
{ {
pcMesh->mFaces[i].mIndices = new unsigned int[3]; pcMesh->mFaces[i].mIndices = new unsigned int[3];
pcMesh->mFaces[i].mNumIndices = 3; pcMesh->mFaces[i].mNumIndices = 3;
@ -465,22 +466,22 @@ void MDLImporter::InternReadFile_Quake1( )
// read vertices // read vertices
unsigned int iIndex = pcTriangles->vertex[c]; unsigned int iIndex = pcTriangles->vertex[c];
if (iIndex >= (unsigned int)mpcHeader->num_verts) if (iIndex >= (unsigned int)pcHeader->num_verts)
{ {
iIndex = mpcHeader->num_verts-1; iIndex = pcHeader->num_verts-1;
DefaultLogger::get()->warn("Index overflow in Q1-MDL vertex list."); DefaultLogger::get()->warn("Index overflow in Q1-MDL vertex list.");
} }
aiVector3D& vec = pcMesh->mVertices[iCurrent]; aiVector3D& vec = pcMesh->mVertices[iCurrent];
vec.x = (float)pcVertices[iIndex].v[0] * mpcHeader->scale[0]; vec.x = (float)pcVertices[iIndex].v[0] * pcHeader->scale[0];
vec.x += mpcHeader->translate[0]; vec.x += pcHeader->translate[0];
vec.y = (float)pcVertices[iIndex].v[1] * mpcHeader->scale[1]; vec.y = (float)pcVertices[iIndex].v[1] * pcHeader->scale[1];
vec.y += mpcHeader->translate[1]; vec.y += pcHeader->translate[1];
vec.y *= -1.0f; vec.y *= -1.0f;
vec.z = (float)pcVertices[iIndex].v[2] * mpcHeader->scale[2]; vec.z = (float)pcVertices[iIndex].v[2] * pcHeader->scale[2];
vec.z += mpcHeader->translate[2]; vec.z += pcHeader->translate[2];
// read the normal vector from the precalculated normal table // read the normal vector from the precalculated normal table
MD2::LookupNormalIndex(pcVertices[iIndex].normalIndex,pcMesh->mNormals[iCurrent]); MD2::LookupNormalIndex(pcVertices[iIndex].normalIndex,pcMesh->mNormals[iCurrent]);
@ -494,12 +495,12 @@ void MDLImporter::InternReadFile_Quake1( )
if (0 == pcTriangles->facesfront && if (0 == pcTriangles->facesfront &&
0 != pcTexCoords[iIndex].onseam) 0 != pcTexCoords[iIndex].onseam)
{ {
s += mpcHeader->skinwidth * 0.5f; s += pcHeader->skinwidth * 0.5f;
} }
// Scale s and t to range from 0.0 to 1.0 // Scale s and t to range from 0.0 to 1.0
pcMesh->mTextureCoords[0][iCurrent].x = (s + 0.5f) / mpcHeader->skinwidth; pcMesh->mTextureCoords[0][iCurrent].x = (s + 0.5f) / pcHeader->skinwidth;
pcMesh->mTextureCoords[0][iCurrent].y = 1.0f-(t + 0.5f) / mpcHeader->skinheight; pcMesh->mTextureCoords[0][iCurrent].y = 1.0f-(t + 0.5f) / pcHeader->skinheight;
} }
pcMesh->mFaces[i].mIndices[0] = iTemp+2; pcMesh->mFaces[i].mIndices[0] = iTemp+2;
@ -559,17 +560,17 @@ void MDLImporter::InternReadFile_3DGS_MDL345( )
ai_assert(NULL != pScene); ai_assert(NULL != pScene);
// the header of MDL 3/4/5 is nearly identical to the original Quake1 header // the header of MDL 3/4/5 is nearly identical to the original Quake1 header
mpcHeader = (BE_NCONST MDL::Header*)this->mBuffer; BE_NCONST MDL::Header *pcHeader = (BE_NCONST MDL::Header*)this->mBuffer;
#ifdef AI_BUILD_BIG_ENDIAN #ifdef AI_BUILD_BIG_ENDIAN
FlipQuakeHeader(mpcHeader); FlipQuakeHeader(pcHeader);
#endif #endif
this->ValidateHeader_Quake1(mpcHeader); this->ValidateHeader_Quake1(pcHeader);
// current cursor position in the file // current cursor position in the file
const unsigned char* szCurrent = (const unsigned char*)(mpcHeader+1); const unsigned char* szCurrent = (const unsigned char*)(pcHeader+1);
// need to read all textures // need to read all textures
for (unsigned int i = 0; i < (unsigned int)mpcHeader->num_skins;++i) for (unsigned int i = 0; i < (unsigned int)pcHeader->num_skins;++i)
{ {
BE_NCONST MDL::Skin* pcSkin; BE_NCONST MDL::Skin* pcSkin;
pcSkin = (BE_NCONST MDL::Skin*)szCurrent; pcSkin = (BE_NCONST MDL::Skin*)szCurrent;
@ -593,23 +594,23 @@ void MDLImporter::InternReadFile_3DGS_MDL345( )
} }
// get a pointer to the texture coordinates // get a pointer to the texture coordinates
BE_NCONST MDL::TexCoord_MDL3* pcTexCoords = (BE_NCONST MDL::TexCoord_MDL3*)szCurrent; BE_NCONST MDL::TexCoord_MDL3* pcTexCoords = (BE_NCONST MDL::TexCoord_MDL3*)szCurrent;
szCurrent += sizeof(MDL::TexCoord_MDL3) * mpcHeader->synctype; szCurrent += sizeof(MDL::TexCoord_MDL3) * pcHeader->synctype;
// NOTE: for MDLn formats "synctype" corresponds to the number of UV coords // NOTE: for MDLn formats "synctype" corresponds to the number of UV coords
// get a pointer to the triangles // get a pointer to the triangles
BE_NCONST MDL::Triangle_MDL3* pcTriangles = (BE_NCONST MDL::Triangle_MDL3*)szCurrent; BE_NCONST MDL::Triangle_MDL3* pcTriangles = (BE_NCONST MDL::Triangle_MDL3*)szCurrent;
szCurrent += sizeof(MDL::Triangle_MDL3) * mpcHeader->num_tris; szCurrent += sizeof(MDL::Triangle_MDL3) * pcHeader->num_tris;
#ifdef AI_BUILD_BIG_ENDIAN #ifdef AI_BUILD_BIG_ENDIAN
for (unsigned int i = 0; i<mpcHeader->synctype;++i) for (int i = 0; i<pcHeader->synctype;++i)
{ {
AI_SWAP2( pcTexCoords[i].u ); AI_SWAP2( pcTexCoords[i].u );
AI_SWAP2( pcTexCoords[i].v ); AI_SWAP2( pcTexCoords[i].v );
} }
for (unsigned int i = 0; i<mpcHeader->num_tris;++i) for (int i = 0; i<pcHeader->num_tris;++i)
{ {
AI_SWAP2( pcTriangles[i].index_xyz[0]); AI_SWAP2( pcTriangles[i].index_xyz[0]);
AI_SWAP2( pcTriangles[i].index_xyz[1]); AI_SWAP2( pcTriangles[i].index_xyz[1]);
@ -630,8 +631,8 @@ void MDLImporter::InternReadFile_3DGS_MDL345( )
aiMesh* pcMesh = new aiMesh(); aiMesh* pcMesh = new aiMesh();
pcMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE; pcMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
pcMesh->mNumVertices = mpcHeader->num_tris * 3; pcMesh->mNumVertices = pcHeader->num_tris * 3;
pcMesh->mNumFaces = mpcHeader->num_tris; pcMesh->mNumFaces = pcHeader->num_tris;
pcMesh->mFaces = new aiFace[pcMesh->mNumFaces]; pcMesh->mFaces = new aiFace[pcMesh->mNumFaces];
// there won't be more than one mesh inside the file // there won't be more than one mesh inside the file
@ -644,11 +645,11 @@ void MDLImporter::InternReadFile_3DGS_MDL345( )
pScene->mMeshes[0] = pcMesh; pScene->mMeshes[0] = pcMesh;
// allocate output storage // allocate output storage
pcMesh->mNumVertices = (unsigned int)mpcHeader->num_tris*3; pcMesh->mNumVertices = (unsigned int)pcHeader->num_tris*3;
pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices]; pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices];
pcMesh->mNormals = new aiVector3D[pcMesh->mNumVertices]; pcMesh->mNormals = new aiVector3D[pcMesh->mNumVertices];
if (mpcHeader->synctype) if (pcHeader->synctype)
{ {
pcMesh->mTextureCoords[0] = new aiVector3D[pcMesh->mNumVertices]; pcMesh->mTextureCoords[0] = new aiVector3D[pcMesh->mNumVertices];
pcMesh->mNumUVComponents[0] = 2; pcMesh->mNumUVComponents[0] = 2;
@ -669,11 +670,11 @@ void MDLImporter::InternReadFile_3DGS_MDL345( )
const MDL::Vertex* pcVertices = (const MDL::Vertex*) ((pcFirstFrame->name) const MDL::Vertex* pcVertices = (const MDL::Vertex*) ((pcFirstFrame->name)
+ sizeof(pcFirstFrame->name)); + sizeof(pcFirstFrame->name));
VALIDATE_FILE_SIZE(pcVertices + mpcHeader->num_verts); VALIDATE_FILE_SIZE(pcVertices + pcHeader->num_verts);
// now iterate through all triangles // now iterate through all triangles
unsigned int iCurrent = 0; unsigned int iCurrent = 0;
for (unsigned int i = 0; i < (unsigned int) mpcHeader->num_tris;++i) for (unsigned int i = 0; i < (unsigned int) pcHeader->num_tris;++i)
{ {
pcMesh->mFaces[i].mIndices = new unsigned int[3]; pcMesh->mFaces[i].mIndices = new unsigned int[3];
pcMesh->mFaces[i].mNumIndices = 3; pcMesh->mFaces[i].mNumIndices = 3;
@ -683,29 +684,29 @@ void MDLImporter::InternReadFile_3DGS_MDL345( )
{ {
// read vertices // read vertices
unsigned int iIndex = pcTriangles->index_xyz[c]; unsigned int iIndex = pcTriangles->index_xyz[c];
if (iIndex >= (unsigned int)mpcHeader->num_verts) if (iIndex >= (unsigned int)pcHeader->num_verts)
{ {
iIndex = mpcHeader->num_verts-1; iIndex = pcHeader->num_verts-1;
DefaultLogger::get()->warn("Index overflow in MDLn vertex list"); DefaultLogger::get()->warn("Index overflow in MDLn vertex list");
} }
aiVector3D& vec = pcMesh->mVertices[iCurrent]; aiVector3D& vec = pcMesh->mVertices[iCurrent];
vec.x = (float)pcVertices[iIndex].v[0] * mpcHeader->scale[0]; vec.x = (float)pcVertices[iIndex].v[0] * pcHeader->scale[0];
vec.x += mpcHeader->translate[0]; vec.x += pcHeader->translate[0];
vec.y = (float)pcVertices[iIndex].v[1] * mpcHeader->scale[1]; vec.y = (float)pcVertices[iIndex].v[1] * pcHeader->scale[1];
vec.y += mpcHeader->translate[1]; vec.y += pcHeader->translate[1];
vec.y *= -1.0f; vec.y *= -1.0f;
vec.z = (float)pcVertices[iIndex].v[2] * mpcHeader->scale[2]; vec.z = (float)pcVertices[iIndex].v[2] * pcHeader->scale[2];
vec.z += mpcHeader->translate[2]; vec.z += pcHeader->translate[2];
// read the normal vector from the precalculated normal table // read the normal vector from the precalculated normal table
MD2::LookupNormalIndex(pcVertices[iIndex].normalIndex,pcMesh->mNormals[iCurrent]); MD2::LookupNormalIndex(pcVertices[iIndex].normalIndex,pcMesh->mNormals[iCurrent]);
pcMesh->mNormals[iCurrent].y *= -1.0f; pcMesh->mNormals[iCurrent].y *= -1.0f;
// read texture coordinates // read texture coordinates
if (mpcHeader->synctype) if (pcHeader->synctype)
{ {
this->ImportUVCoordinate_3DGS_MDL345(pcMesh->mTextureCoords[0][iCurrent], this->ImportUVCoordinate_3DGS_MDL345(pcMesh->mTextureCoords[0][iCurrent],
pcTexCoords,pcTriangles->index_uv[c]); pcTexCoords,pcTriangles->index_uv[c]);
@ -729,11 +730,11 @@ void MDLImporter::InternReadFile_3DGS_MDL345( )
const MDL::Vertex_MDL4* pcVertices = (const MDL::Vertex_MDL4*) ((pcFirstFrame->name) + const MDL::Vertex_MDL4* pcVertices = (const MDL::Vertex_MDL4*) ((pcFirstFrame->name) +
sizeof(pcFirstFrame->name)); sizeof(pcFirstFrame->name));
VALIDATE_FILE_SIZE(pcVertices + mpcHeader->num_verts); VALIDATE_FILE_SIZE(pcVertices + pcHeader->num_verts);
// now iterate through all triangles // now iterate through all triangles
unsigned int iCurrent = 0; unsigned int iCurrent = 0;
for (unsigned int i = 0; i < (unsigned int) mpcHeader->num_tris;++i) for (unsigned int i = 0; i < (unsigned int) pcHeader->num_tris;++i)
{ {
pcMesh->mFaces[i].mIndices = new unsigned int[3]; pcMesh->mFaces[i].mIndices = new unsigned int[3];
pcMesh->mFaces[i].mNumIndices = 3; pcMesh->mFaces[i].mNumIndices = 3;
@ -743,29 +744,29 @@ void MDLImporter::InternReadFile_3DGS_MDL345( )
{ {
// read vertices // read vertices
unsigned int iIndex = pcTriangles->index_xyz[c]; unsigned int iIndex = pcTriangles->index_xyz[c];
if (iIndex >= (unsigned int)mpcHeader->num_verts) if (iIndex >= (unsigned int)pcHeader->num_verts)
{ {
iIndex = mpcHeader->num_verts-1; iIndex = pcHeader->num_verts-1;
DefaultLogger::get()->warn("Index overflow in MDLn vertex list"); DefaultLogger::get()->warn("Index overflow in MDLn vertex list");
} }
aiVector3D& vec = pcMesh->mVertices[iCurrent]; aiVector3D& vec = pcMesh->mVertices[iCurrent];
vec.x = (float)pcVertices[iIndex].v[0] * mpcHeader->scale[0]; vec.x = (float)pcVertices[iIndex].v[0] * pcHeader->scale[0];
vec.x += mpcHeader->translate[0]; vec.x += pcHeader->translate[0];
vec.y = (float)pcVertices[iIndex].v[1] * mpcHeader->scale[1]; vec.y = (float)pcVertices[iIndex].v[1] * pcHeader->scale[1];
vec.y += mpcHeader->translate[1]; vec.y += pcHeader->translate[1];
vec.y *= -1.0f; vec.y *= -1.0f;
vec.z = (float)pcVertices[iIndex].v[2] * mpcHeader->scale[2]; vec.z = (float)pcVertices[iIndex].v[2] * pcHeader->scale[2];
vec.z += mpcHeader->translate[2]; vec.z += pcHeader->translate[2];
// read the normal vector from the precalculated normal table // read the normal vector from the precalculated normal table
MD2::LookupNormalIndex(pcVertices[iIndex].normalIndex,pcMesh->mNormals[iCurrent]); MD2::LookupNormalIndex(pcVertices[iIndex].normalIndex,pcMesh->mNormals[iCurrent]);
pcMesh->mNormals[iCurrent].y *= -1.0f; pcMesh->mNormals[iCurrent].y *= -1.0f;
// read texture coordinates // read texture coordinates
if (mpcHeader->synctype) if (pcHeader->synctype)
{ {
this->ImportUVCoordinate_3DGS_MDL345(pcMesh->mTextureCoords[0][iCurrent], this->ImportUVCoordinate_3DGS_MDL345(pcMesh->mTextureCoords[0][iCurrent],
pcTexCoords,pcTriangles->index_uv[c]); pcTexCoords,pcTriangles->index_uv[c]);
@ -898,14 +899,12 @@ void MDLImporter::ValidateHeader_3DGS_MDL7(const MDL::Header_MDL7* pcHeader)
return; return;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void MDLImporter::CalcAbsBoneMatrices_3DGS_MDL7(const MDL::Bone_MDL7* pcBones, void MDLImporter::CalcAbsBoneMatrices_3DGS_MDL7(MDL::IntBone_MDL7** apcOutBones)
MDL::IntBone_MDL7** apcOutBones)
{ {
ai_assert(NULL != pcBones); const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7*)this->mBuffer;
const MDL::Bone_MDL7* pcBones = (const MDL::Bone_MDL7*)(pcHeader+1);
ai_assert(NULL != apcOutBones); ai_assert(NULL != apcOutBones);
const MDL::Header_MDL7* const pcHeader = (const MDL::Header_MDL7*)this->mBuffer;
// first find the bone that has NO parent, calculate the // first find the bone that has NO parent, calculate the
// animation matrix for it, then go on and search for the next parent // animation matrix for it, then go on and search for the next parent
// index (0) and so on until we can't find a new node. // index (0) and so on until we can't find a new node.
@ -915,9 +914,14 @@ void MDLImporter::CalcAbsBoneMatrices_3DGS_MDL7(const MDL::Bone_MDL7* pcBones,
{ {
for (uint32_t iBone = 0; iBone < pcHeader->bones_num;++iBone) for (uint32_t iBone = 0; iBone < pcHeader->bones_num;++iBone)
{ {
const MDL::Bone_MDL7* pcBone = _AI_MDL7_ACCESS_PTR(pcBones,iBone, BE_NCONST MDL::Bone_MDL7* pcBone = _AI_MDL7_ACCESS_PTR(pcBones,iBone,
pcHeader->bone_stc_size,MDL::Bone_MDL7); pcHeader->bone_stc_size,MDL::Bone_MDL7);
AI_SWAP2(pcBone->parent_index);
AI_SWAP4(pcBone->x);
AI_SWAP4(pcBone->y);
AI_SWAP4(pcBone->z);
if (iParent == pcBone->parent_index) if (iParent == pcBone->parent_index)
{ {
// extract from MDL7 readme ... // extract from MDL7 readme ...
@ -990,11 +994,7 @@ void MDLImporter::CalcAbsBoneMatrices_3DGS_MDL7(const MDL::Bone_MDL7* pcBones,
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
MDL::IntBone_MDL7** MDLImporter::LoadBones_3DGS_MDL7() MDL::IntBone_MDL7** MDLImporter::LoadBones_3DGS_MDL7()
{ {
// again, get a pointer to the file header, the bone data const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7*)this->mBuffer;
// is stored directly behind it
const MDL::Header_MDL7* const pcHeader = (const MDL::Header_MDL7*)this->mBuffer;
const MDL::Bone_MDL7* pcBones = (const MDL::Bone_MDL7*)(pcHeader+1);
if (pcHeader->bones_num) if (pcHeader->bones_num)
{ {
// validate the size of the bone data structure in the file // validate the size of the bone data structure in the file
@ -1011,7 +1011,7 @@ MDL::IntBone_MDL7** MDLImporter::LoadBones_3DGS_MDL7()
apcBonesOut[crank] = new MDL::IntBone_MDL7(); apcBonesOut[crank] = new MDL::IntBone_MDL7();
// and calculate absolute bone offset matrices ... // and calculate absolute bone offset matrices ...
this->CalcAbsBoneMatrices_3DGS_MDL7(pcBones,apcBonesOut); this->CalcAbsBoneMatrices_3DGS_MDL7(apcBonesOut);
return apcBonesOut; return apcBonesOut;
} }
return NULL; return NULL;
@ -1021,14 +1021,27 @@ void MDLImporter::ReadFaces_3DGS_MDL7(
const MDL::IntGroupInfo_MDL7& groupInfo, const MDL::IntGroupInfo_MDL7& groupInfo,
MDL::IntGroupData_MDL7& groupData) MDL::IntGroupData_MDL7& groupData)
{ {
// get a pointer to the file header const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7*)this->mBuffer;
const MDL::Header_MDL7* const pcHeader = (const MDL::Header_MDL7*)this->mBuffer; BE_NCONST MDL::Triangle_MDL7* pcGroupTris = groupInfo.pcGroupTris;
const MDL::Triangle_MDL7* pcGroupTris = groupInfo.pcGroupTris;
// iterate through all triangles and build valid display lists // iterate through all triangles and build valid display lists
unsigned int iOutIndex = 0; unsigned int iOutIndex = 0;
for (unsigned int iTriangle = 0; iTriangle < (unsigned int)groupInfo.pcGroup->numtris; ++iTriangle) for (unsigned int iTriangle = 0; iTriangle < (unsigned int)groupInfo.pcGroup->numtris; ++iTriangle)
{ {
AI_SWAP2(pcGroupTris->v_index[0]);
AI_SWAP2(pcGroupTris->v_index[1]);
AI_SWAP2(pcGroupTris->v_index[2]);
AI_SWAP2(pcGroupTris->skinsets[0].st_index[0]);
AI_SWAP2(pcGroupTris->skinsets[0].st_index[1]);
AI_SWAP2(pcGroupTris->skinsets[0].st_index[2]);
AI_SWAP4(pcGroupTris->skinsets[0].material);
AI_SWAP2(pcGroupTris->skinsets[1].st_index[0]);
AI_SWAP2(pcGroupTris->skinsets[1].st_index[1]);
AI_SWAP2(pcGroupTris->skinsets[1].st_index[2]);
AI_SWAP4(pcGroupTris->skinsets[1].material);
// iterate through all indices of the current triangle // iterate through all indices of the current triangle
for (unsigned int c = 0; c < 3;++c,++iOutIndex) for (unsigned int c = 0; c < 3;++c,++iOutIndex)
{ {
@ -1046,7 +1059,7 @@ void MDLImporter::ReadFaces_3DGS_MDL7(
groupData.pcFaces[iTriangle].mIndices[2-c] = iOutIndex; groupData.pcFaces[iTriangle].mIndices[2-c] = iOutIndex;
aiVector3D& vPosition = groupData.vPositions[ iOutIndex ]; aiVector3D& vPosition = groupData.vPositions[ iOutIndex ];
vPosition.x = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .x; vPosition.x = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex, pcHeader->mainvertex_stc_size) .x;
vPosition.y = -1.0f*_AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .y; vPosition.y = -1.0f*_AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .y;
vPosition.z = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .z; vPosition.z = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .z;
@ -1061,8 +1074,11 @@ void MDLImporter::ReadFaces_3DGS_MDL7(
// read the full normal vector // read the full normal vector
aiVector3D& vNormal = groupData.vNormals[ iOutIndex ]; aiVector3D& vNormal = groupData.vNormals[ iOutIndex ];
vNormal.x = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .norm[0]; vNormal.x = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .norm[0];
AI_SWAP4(vNormal.x);
vNormal.y = -1.0f*_AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .norm[1]; vNormal.y = -1.0f*_AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .norm[1];
AI_SWAP4(vNormal.y);
vNormal.z = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .norm[2]; vNormal.z = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .norm[2];
AI_SWAP4(vNormal.z);
} }
else if (AI_MDL7_FRAMEVERTEX120503_STCSIZE <= pcHeader->mainvertex_stc_size) else if (AI_MDL7_FRAMEVERTEX120503_STCSIZE <= pcHeader->mainvertex_stc_size)
{ {
@ -1129,7 +1145,7 @@ void MDLImporter::ReadFaces_3DGS_MDL7(
} }
} }
// get the next triangle in the list // get the next triangle in the list
pcGroupTris = (const MDL::Triangle_MDL7*)((const char*)pcGroupTris + pcGroupTris = (BE_NCONST MDL::Triangle_MDL7*)((const char*)pcGroupTris +
pcHeader->triangle_stc_size); pcHeader->triangle_stc_size);
} }
} }
@ -1142,15 +1158,17 @@ bool MDLImporter::ProcessFrames_3DGS_MDL7(const MDL::IntGroupInfo_MDL7& groupInf
{ {
ai_assert(NULL != szCurrent && NULL != szCurrentOut); ai_assert(NULL != szCurrent && NULL != szCurrentOut);
// get a pointer to the file header const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7*)this->mBuffer;
const MDL::Header_MDL7* const pcHeader = (const MDL::Header_MDL7*)this->mBuffer;
// if we have no bones we can simply skip all frames, // if we have no bones we can simply skip all frames,
// otherwise we'll need to process them. // otherwise we'll need to process them.
// FIX: If we need another frame than the first we must apply frame vertex replacements ... // FIX: If we need another frame than the first we must apply frame vertex replacements ...
for(unsigned int iFrame = 0; iFrame < (unsigned int)groupInfo.pcGroup->numframes;++iFrame) for(unsigned int iFrame = 0; iFrame < (unsigned int)groupInfo.pcGroup->numframes;++iFrame)
{ {
MDL::IntFrameInfo_MDL7 frame ((const MDL::Frame_MDL7*)szCurrent,iFrame); MDL::IntFrameInfo_MDL7 frame ((BE_NCONST MDL::Frame_MDL7*)szCurrent,iFrame);
AI_SWAP4(frame.pcFrame->vertices_count);
AI_SWAP4(frame.pcFrame->transmatrix_count);
const unsigned int iAdd = pcHeader->frame_stc_size + const unsigned int iAdd = pcHeader->frame_stc_size +
frame.pcFrame->vertices_count * pcHeader->framevertex_stc_size + frame.pcFrame->vertices_count * pcHeader->framevertex_stc_size +
@ -1169,15 +1187,16 @@ bool MDLImporter::ProcessFrames_3DGS_MDL7(const MDL::IntGroupInfo_MDL7& groupInf
// our output frame? // our output frame?
if (configFrameID == iFrame) if (configFrameID == iFrame)
{ {
const MDL::Vertex_MDL7* pcFrameVertices = (const MDL::Vertex_MDL7*)(szCurrent+pcHeader->frame_stc_size); BE_NCONST MDL::Vertex_MDL7* pcFrameVertices = (BE_NCONST MDL::Vertex_MDL7*)(szCurrent+pcHeader->frame_stc_size);
for (unsigned int qq = 0; qq < frame.pcFrame->vertices_count;++qq)
for (unsigned int qq = 0; qq < frame.pcFrame->vertices_count;++qq)
{ {
// I assume this are simple replacements for normal // I assume this are simple replacements for normal
// vertices, the bone index serving as the index of the // vertices, the bone index serving as the index of the
// vertex to be replaced. // vertex to be replaced.
uint16_t iIndex = _AI_MDL7_ACCESS(pcFrameVertices,qq, uint16_t iIndex = _AI_MDL7_ACCESS(pcFrameVertices,qq,
pcHeader->framevertex_stc_size,MDL::Vertex_MDL7).vertindex; pcHeader->framevertex_stc_size,MDL::Vertex_MDL7).vertindex;
AI_SWAP2(iIndex);
if (iIndex >= groupInfo.pcGroup->numverts) if (iIndex >= groupInfo.pcGroup->numverts)
{ {
DefaultLogger::get()->warn("Invalid vertex index in frame vertex section"); DefaultLogger::get()->warn("Invalid vertex index in frame vertex section");
@ -1187,16 +1206,22 @@ bool MDLImporter::ProcessFrames_3DGS_MDL7(const MDL::IntGroupInfo_MDL7& groupInf
aiVector3D vPosition,vNormal; aiVector3D vPosition,vNormal;
vPosition.x = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .x; vPosition.x = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .x;
AI_SWAP4(vPosition.x);
vPosition.y = -1.0f*_AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .y; vPosition.y = -1.0f*_AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .y;
vPosition.z = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .z; AI_SWAP4(vPosition.y);
vPosition.z = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .z;
AI_SWAP4(vPosition.z);
// now read the normal vector // now read the normal vector
if (AI_MDL7_FRAMEVERTEX030305_STCSIZE <= pcHeader->mainvertex_stc_size) if (AI_MDL7_FRAMEVERTEX030305_STCSIZE <= pcHeader->mainvertex_stc_size)
{ {
// read the full normal vector // read the full normal vector
vNormal.x = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .norm[0]; vNormal.x = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .norm[0];
AI_SWAP4(vNormal.x);
vNormal.y = -1.0f* _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .norm[1]; vNormal.y = -1.0f* _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .norm[1];
vNormal.z = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .norm[2]; AI_SWAP4(vNormal.y);
vNormal.z = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .norm[2];
AI_SWAP4(vNormal.z);
} }
else if (AI_MDL7_FRAMEVERTEX120503_STCSIZE <= pcHeader->mainvertex_stc_size) else if (AI_MDL7_FRAMEVERTEX120503_STCSIZE <= pcHeader->mainvertex_stc_size)
{ {
@ -1207,7 +1232,7 @@ bool MDLImporter::ProcessFrames_3DGS_MDL7(const MDL::IntGroupInfo_MDL7& groupInf
} }
// FIXME: O(n^2) at the moment ... // FIXME: O(n^2) at the moment ...
const MDL::Triangle_MDL7* pcGroupTris = groupInfo.pcGroupTris; BE_NCONST MDL::Triangle_MDL7* pcGroupTris = groupInfo.pcGroupTris;
unsigned int iOutIndex = 0; unsigned int iOutIndex = 0;
for (unsigned int iTriangle = 0; iTriangle < (unsigned int)groupInfo.pcGroup->numtris; ++iTriangle) for (unsigned int iTriangle = 0; iTriangle < (unsigned int)groupInfo.pcGroup->numtris; ++iTriangle)
{ {
@ -1223,7 +1248,7 @@ bool MDLImporter::ProcessFrames_3DGS_MDL7(const MDL::IntGroupInfo_MDL7& groupInf
} }
} }
// get the next triangle in the list // get the next triangle in the list
pcGroupTris = (const MDL::Triangle_MDL7*)((const char*) pcGroupTris = (BE_NCONST MDL::Triangle_MDL7*)((const char*)
pcGroupTris + pcHeader->triangle_stc_size); pcGroupTris + pcHeader->triangle_stc_size);
} }
} }
@ -1377,9 +1402,26 @@ void MDLImporter::InternReadFile_3DGS_MDL7( )
MDL::IntSharedData_MDL7 sharedData; MDL::IntSharedData_MDL7 sharedData;
// current cursor position in the file // current cursor position in the file
const MDL::Header_MDL7* const pcHeader = (const MDL::Header_MDL7*)this->mBuffer; BE_NCONST MDL::Header_MDL7 *pcHeader = (BE_NCONST MDL::Header_MDL7*)this->mBuffer;
const unsigned char* szCurrent = (const unsigned char*)(pcHeader+1); const unsigned char* szCurrent = (const unsigned char*)(pcHeader+1);
AI_SWAP4(pcHeader->version);
AI_SWAP4(pcHeader->bones_num);
AI_SWAP4(pcHeader->groups_num);
AI_SWAP4(pcHeader->data_size);
AI_SWAP4(pcHeader->entlump_size);
AI_SWAP4(pcHeader->medlump_size);
AI_SWAP2(pcHeader->bone_stc_size);
AI_SWAP2(pcHeader->skin_stc_size);
AI_SWAP2(pcHeader->colorvalue_stc_size);
AI_SWAP2(pcHeader->material_stc_size);
AI_SWAP2(pcHeader->skinpoint_stc_size);
AI_SWAP2(pcHeader->triangle_stc_size);
AI_SWAP2(pcHeader->mainvertex_stc_size);
AI_SWAP2(pcHeader->framevertex_stc_size);
AI_SWAP2(pcHeader->bonetrans_stc_size);
AI_SWAP2(pcHeader->frame_stc_size);
// validate the header of the file. There are some structure // validate the header of the file. There are some structure
// sizes that are expected by the loader to be constant // sizes that are expected by the loader to be constant
this->ValidateHeader_3DGS_MDL7(pcHeader); this->ValidateHeader_3DGS_MDL7(pcHeader);
@ -1404,11 +1446,18 @@ void MDLImporter::InternReadFile_3DGS_MDL7( )
// read all groups // read all groups
for (unsigned int iGroup = 0; iGroup < (unsigned int)pcHeader->groups_num;++iGroup) for (unsigned int iGroup = 0; iGroup < (unsigned int)pcHeader->groups_num;++iGroup)
{ {
MDL::IntGroupInfo_MDL7 groupInfo((const MDL::Group_MDL7*)szCurrent,iGroup); MDL::IntGroupInfo_MDL7 groupInfo((BE_NCONST MDL::Group_MDL7*)szCurrent,iGroup);
szCurrent = (const unsigned char*)(groupInfo.pcGroup+1); szCurrent = (const unsigned char*)(groupInfo.pcGroup+1);
VALIDATE_FILE_SIZE(szCurrent); VALIDATE_FILE_SIZE(szCurrent);
AI_SWAP4(groupInfo.pcGroup->groupdata_size);
AI_SWAP4(groupInfo.pcGroup->numskins);
AI_SWAP4(groupInfo.pcGroup->num_stpts);
AI_SWAP4(groupInfo.pcGroup->numtris);
AI_SWAP4(groupInfo.pcGroup->numverts);
AI_SWAP4(groupInfo.pcGroup->numframes);
if (1 != groupInfo.pcGroup->typ) if (1 != groupInfo.pcGroup->typ)
{ {
// Not a triangle-based mesh // Not a triangle-based mesh
@ -1457,20 +1506,32 @@ void MDLImporter::InternReadFile_3DGS_MDL7( )
} }
// now get a pointer to all texture coords in the group // now get a pointer to all texture coords in the group
groupInfo.pcGroupUVs = (const MDL::TexCoord_MDL7*)szCurrent; groupInfo.pcGroupUVs = (BE_NCONST MDL::TexCoord_MDL7*)szCurrent;
szCurrent += pcHeader->skinpoint_stc_size * groupInfo.pcGroup->num_stpts; for(int i = 0; i < groupInfo.pcGroup->num_stpts; ++i){
AI_SWAP4(groupInfo.pcGroupUVs[i].u);
AI_SWAP4(groupInfo.pcGroupUVs[i].v);
}
szCurrent += pcHeader->skinpoint_stc_size * groupInfo.pcGroup->num_stpts;
// now get a pointer to all triangle in the group // now get a pointer to all triangle in the group
groupInfo.pcGroupTris = (const MDL::Triangle_MDL7*)szCurrent; groupInfo.pcGroupTris = (BE_NCONST MDL::Triangle_MDL7*)szCurrent;
szCurrent += pcHeader->triangle_stc_size * groupInfo.pcGroup->numtris; szCurrent += pcHeader->triangle_stc_size * groupInfo.pcGroup->numtris;
// now get a pointer to all vertices in the group // now get a pointer to all vertices in the group
groupInfo.pcGroupVerts = (const MDL::Vertex_MDL7*)szCurrent; groupInfo.pcGroupVerts = (BE_NCONST MDL::Vertex_MDL7*)szCurrent;
for(int i = 0; i < groupInfo.pcGroup->numverts; ++i){
AI_SWAP4(groupInfo.pcGroupVerts[i].x);
AI_SWAP4(groupInfo.pcGroupVerts[i].y);
AI_SWAP4(groupInfo.pcGroupVerts[i].z);
AI_SWAP2(groupInfo.pcGroupVerts[i].vertindex);
//We can not swap the normal information now as we don't know which of the two kinds it is
}
szCurrent += pcHeader->mainvertex_stc_size * groupInfo.pcGroup->numverts; szCurrent += pcHeader->mainvertex_stc_size * groupInfo.pcGroup->numverts;
VALIDATE_FILE_SIZE(szCurrent); VALIDATE_FILE_SIZE(szCurrent);
MDL::IntSplittedGroupData_MDL7 splittedGroupData(sharedData,avOutList[iGroup]); MDL::IntSplittedGroupData_MDL7 splittedGroupData(sharedData,avOutList[iGroup]);
MDL::IntGroupData_MDL7 groupData; MDL::IntGroupData_MDL7 groupData;
if (groupInfo.pcGroup->numtris && groupInfo.pcGroup->numverts) if (groupInfo.pcGroup->numtris && groupInfo.pcGroup->numverts)
{ {

View File

@ -353,11 +353,9 @@ protected:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Calculate absolute bone animation matrices for each bone /** Calculate absolute bone animation matrices for each bone
* \param pcBones Pointer to the bone section in the file
* \param apcOutBones Output bones array * \param apcOutBones Output bones array
*/ */
void CalcAbsBoneMatrices_3DGS_MDL7(const MDL::Bone_MDL7* pcBones, void CalcAbsBoneMatrices_3DGS_MDL7(MDL::IntBone_MDL7** apcOutBones);
MDL::IntBone_MDL7** apcOutBones);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Add all bones to the nodegraph (as children of the root node) /** Add all bones to the nodegraph (as children of the root node)
@ -447,10 +445,7 @@ protected:
/** Buffer to hold the loaded file */ /** Buffer to hold the loaded file */
unsigned char* mBuffer; unsigned char* mBuffer;
/**Endian converted header of the file. This is espcially important for be targets */ /** For GameStudio MDL files: The number in the magic word, either 3,4 or 5
BE_NCONST MDL::Header *mpcHeader;
/** For GameStudio MDL files: The number in the magic word, either 3,4 or 5
* (MDL7 doesn't need this, the format has a separate loader) */ * (MDL7 doesn't need this, the format has a separate loader) */
unsigned int iGSFileVersion; unsigned int iGSFileVersion;

View File

@ -114,13 +114,15 @@ aiColor4D MDLImporter::ReplaceTextureWithColor(const aiTexture* pcTexture)
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void MDLImporter::CreateTextureARGB8_3DGS_MDL3(const unsigned char* szData) void MDLImporter::CreateTextureARGB8_3DGS_MDL3(const unsigned char* szData)
{ {
VALIDATE_FILE_SIZE(szData + mpcHeader->skinwidth * const MDL::Header *pcHeader = (const MDL::Header*)this->mBuffer; //the endianess is allready corrected in the InternReadFile_3DGS_MDL345 function
mpcHeader->skinheight);
VALIDATE_FILE_SIZE(szData + pcHeader->skinwidth *
pcHeader->skinheight);
// allocate a new texture object // allocate a new texture object
aiTexture* pcNew = new aiTexture(); aiTexture* pcNew = new aiTexture();
pcNew->mWidth = mpcHeader->skinwidth; pcNew->mWidth = pcHeader->skinwidth;
pcNew->mHeight = mpcHeader->skinheight; pcNew->mHeight = pcHeader->skinheight;
pcNew->pcData = new aiTexel[pcNew->mWidth * pcNew->mHeight]; pcNew->pcData = new aiTexel[pcNew->mWidth * pcNew->mHeight];
@ -159,6 +161,8 @@ void MDLImporter::CreateTexture_3DGS_MDL4(const unsigned char* szData,
{ {
ai_assert(NULL != piSkip); ai_assert(NULL != piSkip);
const MDL::Header *pcHeader = (const MDL::Header*)this->mBuffer; //the endianess is allready corrected in the InternReadFile_3DGS_MDL345 function
if (iType == 1 || iType > 3) if (iType == 1 || iType > 3)
{ {
DefaultLogger::get()->error("Unsupported texture file format"); DefaultLogger::get()->error("Unsupported texture file format");
@ -169,8 +173,8 @@ void MDLImporter::CreateTexture_3DGS_MDL4(const unsigned char* szData,
// allocate a new texture object // allocate a new texture object
aiTexture* pcNew = new aiTexture(); aiTexture* pcNew = new aiTexture();
pcNew->mWidth = mpcHeader->skinwidth; pcNew->mWidth = pcHeader->skinwidth;
pcNew->mHeight = mpcHeader->skinheight; pcNew->mHeight = pcHeader->skinheight;
if (bNoRead)pcNew->pcData = (aiTexel*)0xffffffff; if (bNoRead)pcNew->pcData = (aiTexel*)0xffffffff;
this->ParseTextureColorData(szData,iType,piSkip,pcNew); this->ParseTextureColorData(szData,iType,piSkip,pcNew);
@ -565,7 +569,7 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
// check whether a material definition is contained in the skin // check whether a material definition is contained in the skin
if (iType & AI_MDL7_SKINTYPE_MATERIAL) if (iType & AI_MDL7_SKINTYPE_MATERIAL)
{ {
const MDL::Material_MDL7* pcMatIn = (const MDL::Material_MDL7*)szCurrent; BE_NCONST MDL::Material_MDL7* pcMatIn = (BE_NCONST MDL::Material_MDL7*)szCurrent;
szCurrent = (unsigned char*)(pcMatIn+1); szCurrent = (unsigned char*)(pcMatIn+1);
VALIDATE_FILE_SIZE(szCurrent); VALIDATE_FILE_SIZE(szCurrent);
@ -581,40 +585,54 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
// read diffuse color // read diffuse color
clrTemp.r = pcMatIn->Diffuse.r; clrTemp.r = pcMatIn->Diffuse.r;
AI_SWAP4(clrTemp.r);
clrTemp.g = pcMatIn->Diffuse.g; clrTemp.g = pcMatIn->Diffuse.g;
AI_SWAP4(clrTemp.g);
clrTemp.b = pcMatIn->Diffuse.b; clrTemp.b = pcMatIn->Diffuse.b;
AI_SWAP4(clrTemp.b);
COLOR_MULTIPLY_RGB(); COLOR_MULTIPLY_RGB();
pcMatOut->AddProperty<aiColor3D>(&clrTemp,1,AI_MATKEY_COLOR_DIFFUSE); pcMatOut->AddProperty<aiColor3D>(&clrTemp,1,AI_MATKEY_COLOR_DIFFUSE);
// read specular color // read specular color
clrTemp.r = pcMatIn->Specular.r; clrTemp.r = pcMatIn->Specular.r;
AI_SWAP4(clrTemp.r);
clrTemp.g = pcMatIn->Specular.g; clrTemp.g = pcMatIn->Specular.g;
AI_SWAP4(clrTemp.g);
clrTemp.b = pcMatIn->Specular.b; clrTemp.b = pcMatIn->Specular.b;
AI_SWAP4(clrTemp.b);
COLOR_MULTIPLY_RGB(); COLOR_MULTIPLY_RGB();
pcMatOut->AddProperty<aiColor3D>(&clrTemp,1,AI_MATKEY_COLOR_SPECULAR); pcMatOut->AddProperty<aiColor3D>(&clrTemp,1,AI_MATKEY_COLOR_SPECULAR);
// read ambient color // read ambient color
clrTemp.r = pcMatIn->Ambient.r; clrTemp.r = pcMatIn->Ambient.r;
AI_SWAP4(clrTemp.r);
clrTemp.g = pcMatIn->Ambient.g; clrTemp.g = pcMatIn->Ambient.g;
AI_SWAP4(clrTemp.g);
clrTemp.b = pcMatIn->Ambient.b; clrTemp.b = pcMatIn->Ambient.b;
AI_SWAP4(clrTemp.b);
COLOR_MULTIPLY_RGB(); COLOR_MULTIPLY_RGB();
pcMatOut->AddProperty<aiColor3D>(&clrTemp,1,AI_MATKEY_COLOR_AMBIENT); pcMatOut->AddProperty<aiColor3D>(&clrTemp,1,AI_MATKEY_COLOR_AMBIENT);
// read emissive color // read emissive color
clrTemp.r = pcMatIn->Emissive.r; clrTemp.r = pcMatIn->Emissive.r;
AI_SWAP4(clrTemp.r);
clrTemp.g = pcMatIn->Emissive.g; clrTemp.g = pcMatIn->Emissive.g;
AI_SWAP4(clrTemp.g);
clrTemp.b = pcMatIn->Emissive.b; clrTemp.b = pcMatIn->Emissive.b;
AI_SWAP4(clrTemp.b);
pcMatOut->AddProperty<aiColor3D>(&clrTemp,1,AI_MATKEY_COLOR_EMISSIVE); pcMatOut->AddProperty<aiColor3D>(&clrTemp,1,AI_MATKEY_COLOR_EMISSIVE);
// FIX: Take the opacity from the ambient color // FIX: Take the opacity from the ambient color
// the doc says something else, but it is fact that MED exports the // the doc says something else, but it is fact that MED exports the
// opacity like this .... ARRRGGHH! // opacity like this .... ARRRGGHH!
clrTemp.r = pcMatIn->Ambient.a; clrTemp.r = pcMatIn->Ambient.a;
AI_SWAP4(clrTemp.r);
if (is_not_qnan(clrTexture.r))clrTemp.r *= clrTexture.a; if (is_not_qnan(clrTexture.r))clrTemp.r *= clrTexture.a;
pcMatOut->AddProperty<float>(&clrTemp.r,1,AI_MATKEY_OPACITY); pcMatOut->AddProperty<float>(&clrTemp.r,1,AI_MATKEY_OPACITY);
// read phong power // read phong power
int iShadingMode = (int)aiShadingMode_Gouraud; int iShadingMode = (int)aiShadingMode_Gouraud;
AI_SWAP4(pcMatIn->Power);
if (0.0f != pcMatIn->Power) if (0.0f != pcMatIn->Power)
{ {
iShadingMode = (int)aiShadingMode_Phong; iShadingMode = (int)aiShadingMode_Phong;
@ -641,6 +659,7 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
{ {
VALIDATE_FILE_SIZE(szCurrent); VALIDATE_FILE_SIZE(szCurrent);
int32_t iMe = *((int32_t*)szCurrent); int32_t iMe = *((int32_t*)szCurrent);
AI_SWAP4(iMe);
szCurrent += sizeof(char) * iMe + sizeof(int32_t); szCurrent += sizeof(char) * iMe + sizeof(int32_t);
VALIDATE_FILE_SIZE(szCurrent); VALIDATE_FILE_SIZE(szCurrent);
} }
@ -728,7 +747,29 @@ void MDLImporter::SkipSkinLump_3DGS_MDL7(
// check whether a material definition is contained in the skin // check whether a material definition is contained in the skin
if (iType & AI_MDL7_SKINTYPE_MATERIAL) if (iType & AI_MDL7_SKINTYPE_MATERIAL)
{ {
const MDL::Material_MDL7* pcMatIn = (const MDL::Material_MDL7*)szCurrent; BE_NCONST MDL::Material_MDL7* pcMatIn = (BE_NCONST MDL::Material_MDL7*)szCurrent;
AI_SWAP4(pcMatIn->Diffuse.r);
AI_SWAP4(pcMatIn->Diffuse.g);
AI_SWAP4(pcMatIn->Diffuse.b);
AI_SWAP4(pcMatIn->Diffuse.a);
AI_SWAP4(pcMatIn->Ambient.r);
AI_SWAP4(pcMatIn->Ambient.g);
AI_SWAP4(pcMatIn->Ambient.b);
AI_SWAP4(pcMatIn->Ambient.a);
AI_SWAP4(pcMatIn->Specular.r);
AI_SWAP4(pcMatIn->Specular.g);
AI_SWAP4(pcMatIn->Specular.b);
AI_SWAP4(pcMatIn->Specular.a);
AI_SWAP4(pcMatIn->Emissive.r);
AI_SWAP4(pcMatIn->Emissive.g);
AI_SWAP4(pcMatIn->Emissive.b);
AI_SWAP4(pcMatIn->Emissive.a);
AI_SWAP4(pcMatIn->Power);
szCurrent = (unsigned char*)(pcMatIn+1); szCurrent = (unsigned char*)(pcMatIn+1);
} }
@ -737,6 +778,7 @@ void MDLImporter::SkipSkinLump_3DGS_MDL7(
if (iType & AI_MDL7_SKINTYPE_MATERIAL_ASCDEF) if (iType & AI_MDL7_SKINTYPE_MATERIAL_ASCDEF)
{ {
int32_t iMe = *((int32_t*)szCurrent); int32_t iMe = *((int32_t*)szCurrent);
AI_SWAP4(iMe);
szCurrent += sizeof(char) * iMe + sizeof(int32_t); szCurrent += sizeof(char) * iMe + sizeof(int32_t);
} }
*szCurrentOut = szCurrent; *szCurrentOut = szCurrent;
@ -751,7 +793,9 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
ai_assert(NULL != szCurrentOut); ai_assert(NULL != szCurrentOut);
*szCurrentOut = szCurrent; *szCurrentOut = szCurrent;
const MDL::Skin_MDL7* pcSkin = (const MDL::Skin_MDL7*)szCurrent; BE_NCONST MDL::Skin_MDL7* pcSkin = (BE_NCONST MDL::Skin_MDL7*)szCurrent;
AI_SWAP4(pcSkin->width);
AI_SWAP4(pcSkin->height);
szCurrent += 12; szCurrent += 12;
// allocate an output material // allocate an output material