Fixed HMP typo.

Further work on 3DS target animations.
FixNormals-Step inverts face order now.
Further work on the doc to aiCamera.h, added helper function to get a view matrix.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@312 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2009-01-20 21:41:17 +00:00
parent 601d1c572e
commit 4727ad6c6a
9 changed files with 607 additions and 549 deletions

View File

@ -54,14 +54,14 @@ using namespace Assimp;
// Setup final material indices, generae a default material if necessary
void Discreet3DSImporter::ReplaceDefaultMaterial()
{
// *******************************************************************
// try to find an existing material that matches the
//////////////////////////////////////////////////////////////////////////
// Try to find an existing material that matches the
// typical default material setting:
// - no textures
// - diffuse color (in grey!)
// NOTE: This is here to workaround the fact that some
// exporters are writing a default material, too.
// *******************************************************************
//////////////////////////////////////////////////////////////////////////
unsigned int idx = 0xcdcdcdcd;
for (unsigned int i = 0; i < mScene->mMaterials.size();++i)
{
@ -350,7 +350,7 @@ void Discreet3DSImporter::ConvertMeshes(aiScene* pcOut)
// we need to split all meshes by their materials
for (std::vector<D3DS::Mesh>::iterator i = mScene->mMeshes.begin();
i != mScene->mMeshes.end();++i)
i != mScene->mMeshes.end();++i)
{
std::vector<unsigned int>* aiSplit = new std::vector<unsigned int>[
mScene->mMaterials.size()];
@ -490,6 +490,9 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut,
}
}
// Setup the name of the node
pcOut->mName.Set(pcIn->mName);
// Now build the transformation matrix of the node
// ROTATION
if (pcIn->aRotationKeys.size())
@ -546,7 +549,7 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut,
q.mValue = aiQuaternion(0.f,0.f,AI_DEG_TO_RAD(- f.mValue));
}
}
#if 0
if (pcIn->aTargetPositionKeys.size() > 1)
{
DefaultLogger::get()->debug("3DS: Converting target track ...");
@ -583,9 +586,24 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut,
nda->mPositionKeys = new aiVectorKey[nda->mNumPositionKeys];
::memcpy(nda->mPositionKeys,&distanceTrack[0],
sizeof(aiVectorKey)*nda->mNumPositionKeys);
}
// Allocate a new nda, increment the nda index
// The target animation is now encoded in the local transformation
// matrix of the camera, so we must clear the corresponding
// fields in aiCamera or aiLight.
for (unsigned int n = 0; n < pcSOut->mNumCameras;++n) {
if (pcSOut->mCameras[n]->mName == pcOut->mName) {
pcSOut->mCameras[n]->mLookAt = aiVector3D(0.f,0.f,1.f);
}
}
for (unsigned int n = 0; n < pcSOut->mNumLights;++n) {
if (pcSOut->mLights[n]->mName == pcOut->mName) {
pcSOut->mLights[n]->mDirection = aiVector3D(0.f,0.f,1.f);
}
}
}
#endif
// Allocate a new node anim and setup its name
aiNodeAnim* nda = anim->mChannels[anim->mNumChannels++] = new aiNodeAnim();
nda->mNodeName.Set(pcIn->mName);
@ -626,9 +644,6 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut,
}
}
// Setup the name of the node
pcOut->mName.Set(pcIn->mName);
// Allocate storage for children
pcOut->mNumChildren = (unsigned int)pcIn->mChildren.size();
pcOut->mChildren = new aiNode*[pcIn->mChildren.size()];
@ -647,6 +662,7 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut,
// Find out how many node animation channels we'll have finally
void CountTracks(D3DS::Node* node, unsigned int& cnt)
{
//////////////////////////////////////////////////////////////////////////////
// We will never generate more than one channel for a node, so
// this is rather easy here.
@ -656,6 +672,7 @@ void CountTracks(D3DS::Node* node, unsigned int& cnt)
{
++cnt;
// account for the additional channel for the camera/spotlight target position
if (node->aTargetPositionKeys.size() > 1)++cnt;
}
@ -669,10 +686,10 @@ void CountTracks(D3DS::Node* node, unsigned int& cnt)
void Discreet3DSImporter::GenerateNodeGraph(aiScene* pcOut)
{
pcOut->mRootNode = new aiNode();
if (0 == mRootNode->mChildren.size())
{
// seems the file has not even a hierarchy.
//////////////////////////////////////////////////////////////////////////////
// It seems the file is so fucked up that it has not even a hierarchy.
// generate a flat hiearachy which looks like this:
//
// ROOT_NODE
@ -747,18 +764,10 @@ void Discreet3DSImporter::GenerateNodeGraph(aiScene* pcOut)
aiMatrix4x4 m;
AddNodeToGraph(pcOut, pcOut->mRootNode, mRootNode,m);
// If the root node is unnamed name it "<3DSRoot>"
if (::strstr( pcOut->mRootNode->mName.data, "UNNAMED" )
|| pcOut->mRootNode->mName.data[0] == '$'
&& pcOut->mRootNode->mName.data[1] == '$')
{
pcOut->mRootNode->mName.Set("<3DSRoot>");
}
}
// We used the first vertex color set to store some
// temporary values, so we need to cleanup here
// temporary values so we need to cleanup here
for (unsigned int a = 0; a < pcOut->mNumMeshes;++a)
pcOut->mMeshes[a]->mColors[0] = NULL;
@ -771,6 +780,13 @@ void Discreet3DSImporter::GenerateNodeGraph(aiScene* pcOut)
pcOld->mChildren[0] = NULL;
delete pcOld;
}
// If the root node is unnamed name it "<3DSRoot>"
if (::strstr( pcOut->mRootNode->mName.data, "UNNAMED" ) ||
pcOut->mRootNode->mName.data[0] == '$' && pcOut->mRootNode->mName.data[1] == '$')
{
pcOut->mRootNode->mName.Set("<3DSRoot>");
}
}
// ------------------------------------------------------------------------------------------------

View File

@ -356,7 +356,7 @@ void Discreet3DSImporter::ParseChunk(const char* name, unsigned int num)
}
break;
case Discreet3DS::CHUNK_LIGHT:
case Discreet3DS::CHUNK_LIGHT:
{
// This starts a new light
aiLight* light = new aiLight();
@ -415,7 +415,7 @@ void Discreet3DSImporter::ParseChunk(const char* name, unsigned int num)
// And finally - the camera rotation angle, in
// counter clockwise direction
float angle = AI_DEG_TO_RAD( stream->GetF4() );
const float angle = AI_DEG_TO_RAD( stream->GetF4() );
aiQuaternion quat(camera->mLookAt,angle);
camera->mUp = quat.GetMatrix() * aiVector3D(0.f,1.f,0.f);
@ -576,12 +576,12 @@ void Discreet3DSImporter::SkipTCBInfo()
if (!flags)
{
// ******************************************************************
//////////////////////////////////////////////////////////////////////////
// Currently we can't do anything with these values. They occur
// quite rare, so it wouldn't be worth the effort implementing
// them. 3DS ist not really suitable for complex animations,
// so full support is not required.
// ******************************************************************
//////////////////////////////////////////////////////////////////////////
DefaultLogger::get()->warn("3DS: Skipping TCB animation info");
}
@ -696,7 +696,7 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent)
break;
// **************************************************************
// ////////////////////////////////////////////////////////////////////
// POSITION KEYFRAME
case Discreet3DS::CHUNK_TRACKPOS:
{
@ -744,7 +744,7 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent)
break;
// **************************************************************
// ////////////////////////////////////////////////////////////////////
// CAMERA ROLL KEYFRAME
case Discreet3DS::CHUNK_TRACKROLL:
{
@ -789,7 +789,7 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent)
break;
// **************************************************************
// ////////////////////////////////////////////////////////////////////
// CAMERA FOV KEYFRAME
case Discreet3DS::CHUNK_TRACKFOV:
{
@ -799,7 +799,7 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent)
break;
// **************************************************************
// ////////////////////////////////////////////////////////////////////
// ROTATION KEYFRAME
case Discreet3DS::CHUNK_TRACKROTATE:
{
@ -846,7 +846,7 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent)
}}
break;
// **************************************************************
// ////////////////////////////////////////////////////////////////////
// SCALING KEYFRAME
case Discreet3DS::CHUNK_TRACKSCALE:
{
@ -956,13 +956,11 @@ void Discreet3DSImporter::ParseFaceChunk()
// Now continue and read all material indices
cnt = (uint16_t)stream->GetI2();
for (unsigned int i = 0; i < cnt;++i)
{
for (unsigned int i = 0; i < cnt;++i) {
unsigned int fidx = (uint16_t)stream->GetI2();
// check range
if (fidx >= mMesh.mFaceMaterials.size())
{
if (fidx >= mMesh.mFaceMaterials.size()) {
DefaultLogger::get()->error("3DS: Invalid face index in face material list");
}
else mMesh.mFaceMaterials[fidx] = idx;
@ -1020,8 +1018,7 @@ void Discreet3DSImporter::ParseMeshChunk()
// Now check whether the matrix has got a negative determinant
// If yes, we need to flip all vertices' Z axis ....
// This code has been taken from lib3ds
if (mMesh.mMat.Determinant() < 0.0f)
{
if (mMesh.mMat.Determinant() < 0.0f) {
// Compute the inverse of the matrix
aiMatrix4x4 mInv = mMesh.mMat;
mInv.Inverse();
@ -1431,7 +1428,6 @@ void Discreet3DSImporter::ParseColorChunk(aiColor3D* out,
default:
stream->IncPtr(diff);
// Skip unknown chunks, hope this won't cause any problems.
return ParseColorChunk(out,acceptPercent);
};

View File

@ -47,14 +47,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// internal headers
#include "FixNormalsStep.h"
#include "SpatialSort.h"
using namespace Assimp;
#ifdef _MSC_VER
# define sprintf sprintf_s
#endif
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
@ -87,8 +82,9 @@ void FixInfacingNormalsProcess::Execute( aiScene* pScene)
for( unsigned int a = 0; a < pScene->mNumMeshes; a++)
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");
if (bHas)
DefaultLogger::get()->debug("FixInfacingNormalsProcess finished. Found issues.");
else DefaultLogger::get()->debug("FixInfacingNormalsProcess finished. No changes to the scene.");
}
// ------------------------------------------------------------------------------------------------
@ -97,18 +93,19 @@ bool FixInfacingNormalsProcess::ProcessMesh( aiMesh* pcMesh, unsigned int index)
{
ai_assert(NULL != pcMesh);
// Nothing to do if there are no model normals
if (!pcMesh->HasNormals())return false;
// compute the bounding box of both the model vertices + normals and
// Compute the bounding box of both the model vertices + normals and
// the umodified model vertices. Then check whether the first BB
// is smaller than the second. In this case we can assume that the
// normals need to be flipped, although there are a few special cases ..
// convex, concave, planar models ...
aiVector3D vMin0(1e10f,1e10f,1e10f);
aiVector3D vMin1(1e10f,1e10f,1e10f);
aiVector3D vMax0(-1e10f,-1e10f,-1e10f);
aiVector3D vMax1(-1e10f,-1e10f,-1e10f);
aiVector3D vMin0 (1e10f,1e10f,1e10f);
aiVector3D vMin1 (1e10f,1e10f,1e10f);
aiVector3D vMax0 (-1e10f,-1e10f,-1e10f);
aiVector3D vMax1 (-1e10f,-1e10f,-1e10f);
for (unsigned int i = 0; i < pcMesh->mNumVertices;++i)
{
@ -120,7 +117,7 @@ bool FixInfacingNormalsProcess::ProcessMesh( aiMesh* pcMesh, unsigned int index)
vMax1.y = std::max(vMax1.y,pcMesh->mVertices[i].y);
vMax1.z = std::max(vMax1.z,pcMesh->mVertices[i].z);
aiVector3D vWithNormal = pcMesh->mVertices[i] + pcMesh->mNormals[i];
const aiVector3D vWithNormal = pcMesh->mVertices[i] + pcMesh->mNormals[i];
vMin0.x = std::min(vMin0.x,vWithNormal.x);
vMin0.y = std::min(vMin0.y,vWithNormal.y);
@ -139,20 +136,19 @@ bool FixInfacingNormalsProcess::ProcessMesh( aiMesh* pcMesh, unsigned int index)
const float fDelta1_y = (vMax1.y - vMin1.y);
const float fDelta1_z = (vMax1.z - vMin1.z);
// check the case where the boxes are overlapping
// Check whether the boxes are overlapping
if (fDelta0_x > 0.0f != fDelta1_x > 0.0f)return false;
if (fDelta0_y > 0.0f != fDelta1_y > 0.0f)return false;
if (fDelta0_z > 0.0f != fDelta1_z > 0.0f)return false;
// check the case of a very planar surface
// Check whether this is a planar surface
const float fDelta1_yz = fDelta1_y * fDelta1_z;
if (fDelta1_x < 0.05f * sqrtf( fDelta1_yz ))return false;
if (fDelta1_y < 0.05f * sqrtf( fDelta1_z * fDelta1_x ))return false;
if (fDelta1_z < 0.05f * sqrtf( fDelta1_y * fDelta1_x ))return false;
// now compare the volume of the bounding boxes
// now compare the volumes of the bounding boxes
if (::fabsf(fDelta0_x * fDelta1_yz) <
::fabsf(fDelta1_x * fDelta1_y * fDelta1_z))
{
@ -163,9 +159,16 @@ bool FixInfacingNormalsProcess::ProcessMesh( aiMesh* pcMesh, unsigned int index)
DefaultLogger::get()->info(buffer);
}
// Invert normals
for (unsigned int i = 0; i < pcMesh->mNumVertices;++i)
{
pcMesh->mNormals[i] *= -1.0f;
// ... and flip faces
for (unsigned int i = 0; i < pcMesh->mNumFaces;++i)
{
aiFace& face = pcMesh->mFaces[i];
for( unsigned int b = 0; b < face.mNumIndices / 2; b++)
std::swap( face.mIndices[b], face.mIndices[ face.mNumIndices - 1 - b]);
}
return true;
}

View File

@ -69,6 +69,7 @@ HMPImporter::~HMPImporter()
// Returns whether the class can handle the format of the given file.
bool HMPImporter::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
std::string::size_type pos = pFile.find_last_of('.');
// no file extension - can't read
@ -84,8 +85,10 @@ bool HMPImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler) const
// ------------------------------------------------------------------------------------------------
// Imports the given file into the given scene structure.
void HMPImporter::InternReadFile( const std::string& pFile,
aiScene* pScene, IOSystem* pIOHandler)
aiScene* _pScene, IOSystem* _pIOHandler)
{
pScene = _pScene;
pIOHandler = _pIOHandler;
boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile));
// Check whether we can read from the file
@ -99,17 +102,13 @@ void HMPImporter::InternReadFile( const std::string& pFile,
throw new ImportErrorException( "HMP File is too small.");
// Allocate storage and copy the contents of the file to a memory buffer
this->pScene = pScene;
this->pIOHandler = pIOHandler;
std::vector<uint8_t> buffer(fileSize);
mBuffer = &buffer[0];
file->Read( (void*)mBuffer, 1, fileSize);
iFileSize = (unsigned int)fileSize;
// Determine the file subtype and call the appropriate member function
uint32_t iMagic = *((uint32_t*)this->mBuffer);
const uint32_t iMagic = *((uint32_t*)this->mBuffer);
// HMP4 format
if (AI_HMP_MAGIC_NUMBER_LE_4 == iMagic ||

View File

@ -39,30 +39,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//
//! @file Definition of in-memory structures for the MDL file format.
//
// The specification has been taken from various sources on the internet.
// - http://tfc.duke.free.fr/coding/mdl-specs-en.html
// - Conitec's MED SDK
// - Many quite long HEX-editor sessions
/**
* @file MDLFileData.h
* @brief Definition of in-memory structures for the MDL file format.
*
* The specification has been taken from various sources on the internet.
* - http://tfc.duke.free.fr/coding/mdl-specs-en.html
* - Conitec's MED SDK
* - Many quite long HEX-editor sessions
*/
#ifndef AI_MDLFILEHELPER_H_INC
#define AI_MDLFILEHELPER_H_INC
#include <string>
#include <vector>
#include "../include/aiTypes.h"
#include "../include/aiMesh.h"
#include "../include/aiAnim.h"
#include "../include/aiMaterial.h"
#include "./../include/Compiler/pushpack1.h"
namespace Assimp {
namespace MDL {
// -------------------------------------------------------------------------------------
// to make it easier for ourselfes, we test the magic word against both "endianesses"
#define MDL_MAKE(string) ((uint32_t)((string[0] << 24) + (string[1] << 16) + (string[2] << 8) + string[3]))
@ -113,7 +108,7 @@ namespace MDL {
# define AI_MDL7_REFERRER_MATERIAL "&&&referrer&&&",0,0
#endif
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct Header
* \brief Data structure for the MDL main header
*/
@ -167,7 +162,7 @@ struct Header
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct Header_MDL7
* \brief Data structure for the MDL 7 main header
*/
@ -226,7 +221,8 @@ struct Header_MDL7
uint16_t frame_stc_size;
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct Bone_MDL7
* \brief Data structure for a bone in a MDL7 file
*/
@ -261,7 +257,7 @@ struct Bone_MDL7
# define AI_MDL7_MAX_GROUPNAMESIZE 16
#endif // ! AI_MDL7_MAX_GROUPNAMESIZE
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct Group_MDL7
* \brief Group in a MDL7 file
*/
@ -303,7 +299,7 @@ struct Group_MDL7
# define AI_MDL7_MAX_BONENAMESIZE 20
#endif // !! AI_MDL7_MAX_BONENAMESIZE
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct Deformer_MDL7
* \brief Deformer in a MDL7 file
*/
@ -318,7 +314,7 @@ struct Deformer_MDL7
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct DeformerElement_MDL7
* \brief Deformer element in a MDL7 file
*/
@ -331,7 +327,7 @@ struct DeformerElement_MDL7
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct DeformerWeight_MDL7
* \brief Deformer weight in a MDL7 file
*/
@ -346,7 +342,7 @@ struct DeformerWeight_MDL7
// don't know why this was in the original headers ...
typedef int32_t MD7_MATERIAL_ASCDEFSIZE;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct ColorValue_MDL7
* \brief Data structure for a color value in a MDL7 file
*/
@ -355,7 +351,7 @@ struct ColorValue_MDL7
float r,g,b,a;
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct Material_MDL7
* \brief Data structure for a Material in a MDL7 file
*/
@ -378,7 +374,7 @@ struct Material_MDL7
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct Skin
* \brief Skin data structure #1 - used by Quake1, MDL2, MDL3 and MDL4
*/
@ -402,7 +398,7 @@ struct Skin
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct Skin
* \brief Skin data structure #2 - used by MDL5, MDL6 and MDL7
* \see Skin
@ -431,7 +427,7 @@ struct Skin_MDL7
char texture_name[AI_MDL7_MAX_TEXNAMESIZE];
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct RGB565
* \brief Data structure for a RGB565 pixel in a texture
*/
@ -442,7 +438,7 @@ struct RGB565
uint16_t b : 5;
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct ARGB4
* \brief Data structure for a ARGB4444 pixel in a texture
*/
@ -454,7 +450,7 @@ struct ARGB4
uint16_t b : 4;
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct GroupSkin
* \brief Skin data structure #2 (group of pictures)
*/
@ -473,7 +469,7 @@ struct GroupSkin
uint8_t **data;
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct TexCoord
* \brief Texture coordinate data structure used by the Quake1 MDL format
*/
@ -489,7 +485,7 @@ struct TexCoord
int32_t t;
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct TexCoord_MDL3
* \brief Data structure for an UV coordinate in the 3DGS MDL3 format
*/
@ -502,7 +498,7 @@ struct TexCoord_MDL3
int16_t v;
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct TexCoord_MDL7
* \brief Data structure for an UV coordinate in the 3DGS MDL7 format
*/
@ -515,7 +511,7 @@ struct TexCoord_MDL7
float v;
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct SkinSet_MDL7
* \brief Skin set data structure for the 3DGS MDL7 format
* MDL7 references UV coordinates per face via an index list.
@ -531,7 +527,7 @@ struct SkinSet_MDL7
int32_t material; // size 4
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct Triangle
* \brief Triangle data structure for the Quake1 MDL format
*/
@ -544,7 +540,7 @@ struct Triangle
int32_t vertex[3];
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct Triangle_MDL3
* \brief Triangle data structure for the 3DGS MDL3 format
*/
@ -557,7 +553,7 @@ struct Triangle_MDL3
uint16_t index_uv[3];
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct Triangle_MDL7
* \brief Triangle data structure for the 3DGS MDL7 format
*/
@ -588,7 +584,7 @@ struct Triangle_MDL7
# define AI_MDL_FRONTFACE 0x1
#endif
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct Vertex
* \brief Vertex data structure
*/
@ -599,7 +595,7 @@ struct Vertex
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
struct Vertex_MDL4
{
uint16_t v[3];
@ -610,7 +606,7 @@ struct Vertex_MDL4
#define AI_MDL7_FRAMEVERTEX120503_STCSIZE 16
#define AI_MDL7_FRAMEVERTEX030305_STCSIZE 26
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct Vertex_MDL7
* \brief Vertex data structure used in MDL7 files
*/
@ -625,7 +621,7 @@ struct Vertex_MDL7
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct BoneTransform_MDL7
* \brief bone transformation matrix structure used in MDL7 files
*/
@ -646,7 +642,7 @@ struct BoneTransform_MDL7
#define AI_MDL7_MAX_FRAMENAMESIZE 16
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct Frame_MDL7
* \brief Frame data structure used by MDL7 files
*/
@ -658,7 +654,7 @@ struct Frame_MDL7
};
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct SimpleFrame
* \brief Data structure for a simple frame
*/
@ -677,7 +673,7 @@ struct SimpleFrame
Vertex *verts;
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct Frame
* \brief Model frame data structure
*/
@ -691,7 +687,7 @@ struct Frame
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
struct SimpleFrame_MDLn_SP
{
//! Minimum vertex of the bounding box
@ -707,7 +703,7 @@ struct SimpleFrame_MDLn_SP
Vertex_MDL4 *verts;
} PACK_STRUCT;
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct GroupFrame
* \brief Data structure for a group of frames
*/
@ -731,8 +727,7 @@ struct GroupFrame
#include "./../include/Compiler/poppack1.h"
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct IntFace_MDL7
* \brief Internal data structure to temporarily represent a face
*/
@ -753,8 +748,7 @@ struct IntFace_MDL7
unsigned int iMatIndex[2];
};
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct IntMaterial_MDL7
* \brief Internal data structure to temporarily represent a material
* which has been created from two single materials along with the
@ -776,8 +770,7 @@ struct IntMaterial_MDL7
unsigned int iOldMatIndices[2];
};
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
/** \struct IntBone_MDL7
* \brief Internal data structure to represent a bone in a MDL7 file with
* all of its animation channels assigned to it.
@ -808,7 +801,7 @@ struct IntBone_MDL7 : aiBone
std::vector<aiQuatKey> pkeyRotations;
};
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
//! Describes a MDL7 frame
struct IntFrameInfo_MDL7
{
@ -825,7 +818,7 @@ struct IntFrameInfo_MDL7
BE_NCONST MDL::Frame_MDL7* pcFrame;
};
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
//! Describes a MDL7 mesh group
struct IntGroupInfo_MDL7
{
@ -860,7 +853,7 @@ struct IntGroupInfo_MDL7
BE_NCONST MDL::Vertex_MDL7* pcGroupVerts;
};
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
//! Holds the data that belongs to a MDL7 mesh group
struct IntGroupData_MDL7
{
@ -891,7 +884,7 @@ struct IntGroupData_MDL7
bool bNeed2UV;
};
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
//! Holds data from an MDL7 file that is shared by all mesh groups
struct IntSharedData_MDL7
{
@ -926,7 +919,7 @@ struct IntSharedData_MDL7
unsigned int iNum;
};
// ---------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
//! Contains input data for GenerateOutputMeshes_3DGS_MDL7
struct IntSplittedGroupData_MDL7
{

File diff suppressed because it is too large Load Diff

View File

@ -39,17 +39,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//!
//! @file Definition of MDL importer class
//!
/** @file MDLLoader.h
* @brief Declaration of the loader for MDL files
*/
#ifndef AI_MDLLOADER_H_INCLUDED
#define AI_MDLLOADER_H_INCLUDED
#include "BaseImporter.h"
#include "../include/aiTypes.h"
#include "../include/aiTexture.h"
#include "../include/aiMaterial.h"
struct aiNode;
#include "MDLFileData.h"
@ -60,13 +57,28 @@ class MaterialHelper;
using namespace MDL;
#if (!defined VALIDATE_FILE_SIZE)
# define VALIDATE_FILE_SIZE(msg) this->SizeCheck(msg,__FILE__,__LINE__)
// --------------------------------------------------------------------------------------
// Include file/line information in debug builds
#ifdef ASSIMP_BUILD_DEBUG
# define VALIDATE_FILE_SIZE(msg) SizeCheck(msg,__FILE__,__LINE__)
#else
# define VALIDATE_FILE_SIZE(msg) SizeCheck(msg)
#endif
// ---------------------------------------------------------------------------
/** Used to load MDL files
// --------------------------------------------------------------------------------------
/** @brief Class to load MDL files.
*
* Several subformats exist:
* <ul>
* <li>Quake I</li>
* <li>3D Game Studio MDL3, MDL4</li>
* <li>3D Game Studio MDL5</li>
* <li>3D Game Studio MDL7</li>
* <li>Halflife 2</li>
* </ul>
* These formats are partially identical and it would be possible to load
* them all with a single 1000-line function-beast. However, it has been
* splitted to several code paths to make the code easier to read and maintain.
*/
class MDLImporter : public BaseImporter
{
@ -101,10 +113,7 @@ protected:
/** Called by Importer::GetExtensionList() for each loaded importer.
* See BaseImporter::GetExtensionList() for details
*/
void GetExtensionList(std::string& append)
{
append.append("*.mdl");
}
void GetExtensionList(std::string& append);
// -------------------------------------------------------------------
/** Imports the given file into the given scene structure.
@ -135,11 +144,6 @@ protected:
*/
void InternReadFile_HL2( );
// *******************************************************************
// Debugging/validation functions
// -------------------------------------------------------------------
/** Check whether a given position is inside the valid range
* Throw a new ImportErrorException if it is not
@ -164,10 +168,6 @@ protected:
void ValidateHeader_Quake1(const MDL::Header* pcHeader);
// *******************************************************************
// Material import
// -------------------------------------------------------------------
/** Try to load a palette from the current directory (colormap.lmp)
* If it is not found the default palette of Quake1 is returned
@ -195,6 +195,7 @@ protected:
unsigned int iType,
unsigned int* piSkip);
// -------------------------------------------------------------------
/** Used to load textures from MDL5
* \param szData Input data
@ -218,16 +219,13 @@ protected:
aiColor4D ReplaceTextureWithColor(const aiTexture* pcTexture);
// *******************************************************************
// Quake1, MDL 3,4,5 import
// -------------------------------------------------------------------
/** Converts the absolute texture coordinates in MDL5 files to
* relative in a range between 0 and 1
*/
void CalculateUVCoordinates_MDL5();
// -------------------------------------------------------------------
/** Read an UV coordinate from the file. If the file format is not
* MDL5, the function calculates relative texture coordinates
@ -248,9 +246,6 @@ protected:
void SetupMaterialProperties_3DGS_MDL5_Quake1( );
// *******************************************************************
// MDL7 import
// -------------------------------------------------------------------
/** Parse a skin lump in a MDL7/HMP7 file with all of its features
* variant 1: Current cursor position is the beginning of the skin header
@ -445,7 +440,7 @@ protected:
/** Buffer to hold the loaded file */
unsigned char* mBuffer;
/** For GameStudio MDL files: The number in the magic word, either 3,4 or 5
/** 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) */
unsigned int iGSFileVersion;

View File

@ -120,8 +120,8 @@ aiColor4D MDLImporter::ReplaceTextureWithColor(const aiTexture* pcTexture)
void MDLImporter::CreateTextureARGB8_3DGS_MDL3(const unsigned char* szData)
{
const MDL::Header *pcHeader = (const MDL::Header*)mBuffer; //the endianess is allready corrected in the InternReadFile_3DGS_MDL345 function
VALIDATE_FILE_SIZE(szData + pcHeader->skinwidth *
VALIDATE_FILE_SIZE(szData + pcHeader->skinwidth *
pcHeader->skinheight);
// allocate a new texture object
@ -164,11 +164,11 @@ void MDLImporter::CreateTextureARGB8_3DGS_MDL3(const unsigned char* szData)
// Read a texture from a MDL4 file
void MDLImporter::CreateTexture_3DGS_MDL4(const unsigned char* szData,
unsigned int iType,
unsigned int* piSkip)
unsigned int* 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
const MDL::Header *pcHeader = (const MDL::Header*)mBuffer; //the endianess is allready corrected in the InternReadFile_3DGS_MDL345 function
if (iType == 1 || iType > 3)
{
@ -182,9 +182,9 @@ void MDLImporter::CreateTexture_3DGS_MDL4(const unsigned char* szData,
aiTexture* pcNew = new aiTexture();
pcNew->mWidth = pcHeader->skinwidth;
pcNew->mHeight = pcHeader->skinheight;
if (bNoRead)pcNew->pcData = (aiTexel*)0xffffffff;
this->ParseTextureColorData(szData,iType,piSkip,pcNew);
ParseTextureColorData(szData,iType,piSkip,pcNew);
// store the texture
if (!bNoRead)

View File

@ -61,8 +61,39 @@ extern "C" {
* writes the target point as a subnode of the camera's main node,
* called "<camName>.Target". However, this is just additional information
* then, the transformation tracks of the camera main node make the
* camera already point in the right direction.
* camera already look in the right direction.
* <br>
* An important aspect is that the camera itself is also part of the
* scenegraph. This means, any values such as the look-at vector are not
* *absolute*, they're <b>relative</b> to the coordinate system defined
* by the node which corresponds to the camera. This allows for camera
* animations. For static cameras parameters like the 'look-at' or 'up' vectors
* are usually specified directly in aiCamera, but beware, they could also
* be encoded in the node transformation. The following (pseudo)code sample
* shows how to do it:
* @code
* // Get the camera matrix for a camera at a specific time
* // if the node hierarchy for the camera does not contain
* // at least one animated node this is a static computation
* get-camera-matrix (node sceneRoot, camera cam) : matrix
* {
* node cnd = find-node-for-camera(cam)
* matrix cmt = identity()
*
* // as usual - get the absolute camera transformation for this frame
* for each node nd in hierarchy from sceneRoot to cnd
* matrix cur
* if (is-animated(nd))
* cur = eval-animation(nd)
* else cur = nd->mTransformation;
* cmt = mult-matrices( cmt, cur )
* end for
*
* // now multiply with the camera's own local transform
* cam = mult-matrices (cam, get-camera-matrix(cmt) )
* }
* @endcode
*
*/
struct aiCamera
{
@ -149,6 +180,38 @@ struct aiCamera
, mAspect (0.f)
{}
/** @brief Get a *right-handed* camera matrix from me
* @param out Camera matrix to be filled
*/
void GetCameraMatrix (aiMatrix4x4& out) const
{
/** todo: test ... should work, but i'm not absolutely sure */
/** We don't know whether these vectors are already normalized ...*/
aiVector3D zaxis = mLookAt; zaxis.Normalize();
aiVector3D yaxis = mUp; yaxis.Normalize();
aiVector3D xaxis = mUp^mLookAt; xaxis.Normalize();
out.a3 = -(xaxis * mPosition);
out.b3 = -(yaxis * mPosition);
out.c3 = -(zaxis * mPosition);
out.a1 = xaxis.x;
out.a2 = xaxis.y;
out.a3 = xaxis.z;
out.b1 = yaxis.x;
out.b2 = yaxis.y;
out.b3 = yaxis.z;
out.c1 = zaxis.x;
out.c2 = zaxis.y;
out.c3 = zaxis.z;
out.d1 = out.d2 = out.d3 = 0.f;
out.d4 = 1.f;
}
#endif
};