HMP loader returns quads now, cleaned up the code a bit. Still longer than necessary.

BVH loader supports arbitrary rotation/translation orders now. Fixed a crash issue, added test models with ZYX and ZXY rotation order.
Updated CREDITS.
'Beautified' pushpack/poppack.
Collada loader does now also load XML files if 'COLLADA' is found in the header.
Fixed path issues in several IRR test files.


git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@282 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
This commit is contained in:
aramis_acg
2009-01-10 17:58:06 +00:00
parent 39bfb7608b
commit b73cb1c569
23 changed files with 8194 additions and 265 deletions

View File

@@ -51,14 +51,12 @@ using namespace Assimp;
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
BVHLoader::BVHLoader()
{
}
{}
// ------------------------------------------------------------------------------------------------
// Destructor, private as well
BVHLoader::~BVHLoader()
{
}
{}
// ------------------------------------------------------------------------------------------------
// Returns whether the class can handle the format of the given file.
@@ -73,10 +71,7 @@ bool BVHLoader::CanRead( const std::string& pFile, IOSystem* pIOHandler) const
for( std::string::iterator it = extension.begin(); it != extension.end(); ++it)
*it = tolower( *it);
if( extension == ".bvh")
return true;
return false;
return ( extension == ".bvh");
}
// ------------------------------------------------------------------------------------------------
@@ -410,31 +405,54 @@ void BVHLoader::CreateAnimation( aiScene* pScene)
// now generate the tracks for all nodes
anim->mNumChannels = mNodes.size();
anim->mChannels = new aiNodeAnim*[anim->mNumChannels];
// FIX: set the array elements to NULL to ensure proper deletion if an exception is thrown
for (unsigned int i = 0; i < anim->mNumChannels;++i)
anim->mChannels[i] = NULL;
for( unsigned int a = 0; a < anim->mNumChannels; a++)
{
const Node& node = mNodes[a];
const char* nodeName = node.mNode->mName.data;
const std::string nodeName = std::string( node.mNode->mName.data );
aiNodeAnim* nodeAnim = new aiNodeAnim;
anim->mChannels[a] = nodeAnim;
nodeAnim->mNodeName.Set( std::string( nodeName));
nodeAnim->mNodeName.Set( nodeName);
// translational part, if given
if( node.mChannels.size() == 6)
{
if( node.mChannels[0] != Channel_PositionX || node.mChannels[1] != Channel_PositionY
|| node.mChannels[2] != Channel_PositionZ)
{
throw new ImportErrorException( boost::str( boost::format( "Unexpected animation "
"channel setup at node \"%s\".") % nodeName));
}
nodeAnim->mNumPositionKeys = mAnimNumFrames;
nodeAnim->mPositionKeys = new aiVectorKey[mAnimNumFrames];
aiVectorKey* poskey = nodeAnim->mPositionKeys;
for( unsigned int fr = 0; fr < mAnimNumFrames; ++fr)
{
poskey->mTime = double( fr);
poskey->mValue.x = node.mChannelValues[fr * node.mChannels.size() + 0];
// Now compute all translations in the right order
switch (node.mChannels[0])
{
case Channel_PositionX: poskey->mValue.x = node.mChannelValues[fr * node.mChannels.size() + 0];break;
case Channel_PositionY: poskey->mValue.y = node.mChannelValues[fr * node.mChannels.size() + 0];break;
case Channel_PositionZ: poskey->mValue.z = node.mChannelValues[fr * node.mChannels.size() + 0];break;
default: throw new ImportErrorException( "Unexpected animation channel setup at node " + nodeName );
}
switch (node.mChannels[1])
{
case Channel_PositionX: poskey->mValue.x = node.mChannelValues[fr * node.mChannels.size() + 1];break;
case Channel_PositionY: poskey->mValue.y = node.mChannelValues[fr * node.mChannels.size() + 1];break;
case Channel_PositionZ: poskey->mValue.z = node.mChannelValues[fr * node.mChannels.size() + 1];break;
default: throw new ImportErrorException( "Unexpected animation channel setup at node " + nodeName );
}
switch (node.mChannels[2])
{
case Channel_PositionX: poskey->mValue.x = node.mChannelValues[fr * node.mChannels.size() + 2];break;
case Channel_PositionY: poskey->mValue.y = node.mChannelValues[fr * node.mChannels.size() + 2];break;
case Channel_PositionZ: poskey->mValue.z = node.mChannelValues[fr * node.mChannels.size() + 2];break;
default: throw new ImportErrorException( "Unexpected animation channel setup at node " + nodeName );
}
poskey->mValue.z = node.mChannelValues[fr * node.mChannels.size() + 1];
poskey->mValue.y = node.mChannelValues[fr * node.mChannels.size() + 2];
++poskey;
@@ -451,25 +469,12 @@ void BVHLoader::CreateAnimation( aiScene* pScene)
// rotation part. Always present. First find value offsets
{
unsigned int rotOffset = 0;
unsigned int rotOffset = 0;
if( node.mChannels.size() == 6)
{
if( node.mChannels[3] != Channel_RotationZ || node.mChannels[4] != Channel_RotationX
|| node.mChannels[5] != Channel_RotationY)
{
throw new ImportErrorException( boost::str( boost::format( "Unexpected animation "
"channel setup at node \"%s\".") % nodeName));
}
// Offset all further calculations
rotOffset = 3;
} else
{
if( node.mChannels[0] != Channel_RotationZ || node.mChannels[1] != Channel_RotationX
|| node.mChannels[2] != Channel_RotationY || node.mChannels.size() != 3)
{
throw new ImportErrorException( boost::str( boost::format( "Unexpected animation "
"channel setup at node \"%s\".") % nodeName));
}
}
}
// Then create the number of rotation keys
nodeAnim->mNumRotationKeys = mAnimNumFrames;
@@ -478,14 +483,35 @@ void BVHLoader::CreateAnimation( aiScene* pScene)
for( unsigned int fr = 0; fr < mAnimNumFrames; ++fr)
{
// translate ZXY euler angels into a quaternion
float angleZ = node.mChannelValues[fr * node.mChannels.size() + rotOffset + 0] * float( AI_MATH_PI) / 180.0f;
float angleX = node.mChannelValues[fr * node.mChannels.size() + rotOffset + 1] * float( AI_MATH_PI) / 180.0f;
float angleY = node.mChannelValues[fr * node.mChannels.size() + rotOffset + 2] * float( AI_MATH_PI) / 180.0f;
const float angle0 = node.mChannelValues[fr * node.mChannels.size() + rotOffset ] * float( AI_MATH_PI) / 180.0f;
const float angle1 = node.mChannelValues[fr * node.mChannels.size() + rotOffset+1] * float( AI_MATH_PI) / 180.0f;
const float angle2 = node.mChannelValues[fr * node.mChannels.size() + rotOffset+2] * float( AI_MATH_PI) / 180.0f;
aiMatrix4x4 temp;
aiMatrix3x3 rotMatrix;
aiMatrix4x4::RotationZ( angleZ, temp); rotMatrix *= aiMatrix3x3( temp);
aiMatrix4x4::RotationX( angleX, temp); rotMatrix *= aiMatrix3x3( temp);
aiMatrix4x4::RotationY( angleY, temp); rotMatrix *= aiMatrix3x3( temp);
// Compute rotation transformations in the right order
switch (node.mChannels[rotOffset])
{
case Channel_RotationX: aiMatrix4x4::RotationX( angle0, temp); rotMatrix *= aiMatrix3x3( temp); break;
case Channel_RotationY: aiMatrix4x4::RotationY( angle0, temp); rotMatrix *= aiMatrix3x3( temp); break;
case Channel_RotationZ: aiMatrix4x4::RotationZ( angle0, temp); rotMatrix *= aiMatrix3x3( temp); break;
default: throw new ImportErrorException( "Unexpected animation channel setup at node " + nodeName );
}
switch (node.mChannels[rotOffset+1])
{
case Channel_RotationX: aiMatrix4x4::RotationX( angle1, temp); rotMatrix *= aiMatrix3x3( temp); break;
case Channel_RotationY: aiMatrix4x4::RotationY( angle1, temp); rotMatrix *= aiMatrix3x3( temp); break;
case Channel_RotationZ: aiMatrix4x4::RotationZ( angle1, temp); rotMatrix *= aiMatrix3x3( temp); break;
default: throw new ImportErrorException( "Unexpected animation channel setup at node " + nodeName );
}
switch (node.mChannels[rotOffset+2])
{
case Channel_RotationX: aiMatrix4x4::RotationX( angle2, temp); rotMatrix *= aiMatrix3x3( temp); break;
case Channel_RotationY: aiMatrix4x4::RotationY( angle2, temp); rotMatrix *= aiMatrix3x3( temp); break;
case Channel_RotationZ: aiMatrix4x4::RotationZ( angle2, temp); rotMatrix *= aiMatrix3x3( temp); break;
default: throw new ImportErrorException( "Unexpected animation channel setup at node " + nodeName );
}
rotkey->mTime = double( fr);
rotkey->mValue = aiQuaternion( rotMatrix);

View File

@@ -132,7 +132,11 @@ bool BaseImporter::SearchFileHeaderForToken(IOSystem* pIOHandler,
for (unsigned int i = 0; i < numTokens;++i)
{
ai_assert(NULL != tokens[i]);
if (::strstr(buffer,tokens[i]))return true;
if (::strstr(buffer,tokens[i]))
{
DefaultLogger::get()->debug(std::string("Found positive match for header keyword: ") + tokens[i]);
return true;
}
}
}
return false;

View File

@@ -1,4 +1,3 @@
/** Implementation of the Collada loader */
/*
---------------------------------------------------------------------------
Open Asset Import Library (ASSIMP)
@@ -40,6 +39,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
/** @file Implementation of the Collada loader */
#include "AssimpPCH.h"
#include "../include/aiAnim.h"
#include "ColladaLoader.h"
@@ -50,14 +51,12 @@ using namespace Assimp;
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
ColladaLoader::ColladaLoader()
{
}
{}
// ------------------------------------------------------------------------------------------------
// Destructor, private as well
ColladaLoader::~ColladaLoader()
{
}
{}
// ------------------------------------------------------------------------------------------------
// Returns whether the class can handle the format of the given file.
@@ -75,6 +74,16 @@ bool ColladaLoader::CanRead( const std::string& pFile, IOSystem* pIOHandler) con
if( extension == ".dae")
return true;
// XML - too generic, we need to open the file and search for typical keywords
if( extension == ".xml") {
/* If CanRead() is called in order to check whether we
* support a specific file extension in general pIOHandler
* might be NULL and it's our duty to return true here.
*/
if (!pIOHandler)return true;
const char* tokens[] = {"collada"};
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1);
}
return false;
}
@@ -88,7 +97,7 @@ void ColladaLoader::InternReadFile( const std::string& pFile, aiScene* pScene, I
ColladaParser parser( pFile);
if( !parser.mRootNode)
throw new ImportErrorException( "File came out empty. Somethings wrong here.");
throw new ImportErrorException( "File came out empty. Something is wrong here.");
// create the materials first, for the meshes to find
BuildMaterials( parser, pScene);
@@ -110,7 +119,6 @@ void ColladaLoader::InternReadFile( const std::string& pFile, aiScene* pScene, I
0, 1, 0, 0,
0, 0, 0, 1);
// store all meshes
StoreSceneMeshes( pScene);
}

View File

@@ -48,7 +48,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "HMPLoader.h"
#include "MD2FileData.h"
using namespace Assimp;
// ------------------------------------------------------------------------------------------------
@@ -72,76 +71,69 @@ bool HMPImporter::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;
if( pos == std::string::npos)return false;
std::string extension = pFile.substr( pos);
if (extension.length() < 4)return false;
if (extension[0] != '.')return false;
if (extension[1] != 'h' && extension[1] != 'H')return false;
if (extension[2] != 'm' && extension[2] != 'M')return false;
if (extension[3] != 'p' && extension[3] != 'P')return false;
for( std::string::iterator it = extension.begin(); it != extension.end(); ++it)
*it = tolower( *it);
return true;
return extension == ".hmp";
}
// ------------------------------------------------------------------------------------------------
// Imports the given file into the given scene structure.
void HMPImporter::InternReadFile(
const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler)
void HMPImporter::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 HMP file " + pFile + ".");
}
// check whether the HMP file is large enough to contain
// Check whether the HMP file is large enough to contain
// at least the file header
size_t fileSize = file->FileSize();
const size_t fileSize = file->FileSize();
if( fileSize < 50)
{
throw new ImportErrorException( "HMP File is too small.");
}
// allocate storage and copy the contents of the file to a memory buffer
// Allocate storage and copy the contents of the file to a memory buffer
this->pScene = pScene;
this->pIOHandler = pIOHandler;
this->mBuffer = new unsigned char[fileSize+1];
std::vector<uint8_t> buffer(fileSize+1);
mBuffer = &buffer[0];
file->Read( (void*)mBuffer, 1, fileSize);
iFileSize = (unsigned int)fileSize;
this->iFileSize = (unsigned int)fileSize;
// determine the file subtype and call the appropriate member function
// Determine the file subtype and call the appropriate member function
uint32_t iMagic = *((uint32_t*)this->mBuffer);
try {
// HMP4 format
if (AI_HMP_MAGIC_NUMBER_LE_4 == iMagic ||
AI_HMP_MAGIC_NUMBER_BE_4 == iMagic)
{
DefaultLogger::get()->debug("HMP subtype: 3D GameStudio A4, magic word is HMP4");
this->InternReadFile_HMP4();
InternReadFile_HMP4();
}
// HMP5 format
else if (AI_HMP_MAGIC_NUMBER_LE_5 == iMagic ||
AI_HMP_MAGIC_NUMBER_BE_5 == iMagic)
{
DefaultLogger::get()->debug("HMP subtype: 3D GameStudio A5, magic word is HMP5");
this->InternReadFile_HMP5();
InternReadFile_HMP5();
}
// HMP7 format
else if (AI_HMP_MAGIC_NUMBER_LE_7 == iMagic ||
AI_HMP_MAGIC_NUMBER_BE_7 == iMagic)
{
DefaultLogger::get()->debug("HMP subtype: 3D GameStudio A7, magic word is HMP7");
this->InternReadFile_HMP7();
InternReadFile_HMP7();
}
else
{
// print the magic word to the logger
// Print the magic word to the logger
char szBuffer[5];
szBuffer[0] = ((char*)&iMagic)[0];
szBuffer[1] = ((char*)&iMagic)[1];
@@ -149,20 +141,17 @@ void HMPImporter::InternReadFile(
szBuffer[3] = ((char*)&iMagic)[3];
szBuffer[4] = '\0';
// we're definitely unable to load this file
// We're definitely unable to load this file
throw new ImportErrorException( "Unknown HMP subformat " + pFile +
". Magic word (" + szBuffer + ") is not known");
}
} catch (ImportErrorException* ex) {
delete[] this->mBuffer;
throw ex;
}
// Set the AI_SCENE_FLAGS_TERRAIN bit
pScene->mFlags |= AI_SCENE_FLAGS_TERRAIN;
// delete the file buffer
delete[] this->mBuffer;
return;
// File buffer destructs automatically now
}
// ------------------------------------------------------------------------------------------------
void HMPImporter::ValidateHeader_HMP457( )
{
@@ -175,51 +164,49 @@ void HMPImporter::ValidateHeader_HMP457( )
}
if (!pcHeader->ftrisize_x || !pcHeader->ftrisize_y)
{
throw new ImportErrorException("Size of triangles in either x or y direction is zero");
}
if(pcHeader->fnumverts_x < 1.0f || (pcHeader->numverts/pcHeader->fnumverts_x) < 1.0f)
{
throw new ImportErrorException("Number of triangles in either x or y direction is zero");
}
if(!pcHeader->numframes)
{
throw new ImportErrorException("There are no frames. At least one should be there");
}
}
// ------------------------------------------------------------------------------------------------
void HMPImporter::InternReadFile_HMP4( )
{
throw new ImportErrorException("HMP4 is currently not supported");
}
// ------------------------------------------------------------------------------------------------
void HMPImporter::InternReadFile_HMP5( )
{
// read the file header and skip everything to byte 84
const HMP::Header_HMP5* pcHeader = (const HMP::Header_HMP5*)this->mBuffer;
const unsigned char* szCurrent = (const unsigned char*)(this->mBuffer+84);
this->ValidateHeader_HMP457();
const HMP::Header_HMP5* pcHeader = (const HMP::Header_HMP5*)mBuffer;
const unsigned char* szCurrent = (const unsigned char*)(mBuffer+84);
ValidateHeader_HMP457();
// generate an output mesh
this->pScene->mNumMeshes = 1;
this->pScene->mMeshes = new aiMesh*[1];
aiMesh* pcMesh = this->pScene->mMeshes[0] = new aiMesh();
pScene->mNumMeshes = 1;
pScene->mMeshes = new aiMesh*[1];
aiMesh* pcMesh = pScene->mMeshes[0] = new aiMesh();
pcMesh->mMaterialIndex = 0;
pcMesh->mVertices = new aiVector3D[pcHeader->numverts];
pcMesh->mNormals = new aiVector3D[pcHeader->numverts];
const unsigned int height = (unsigned int)(pcHeader->numverts / pcHeader->fnumverts_x);
const unsigned int width = (unsigned int)pcHeader->fnumverts_x;
const unsigned int width = (unsigned int)pcHeader->fnumverts_x;
// generate/load a material for the terrain
this->CreateMaterial(szCurrent,&szCurrent);
CreateMaterial(szCurrent,&szCurrent);
// goto offset 120, I don't know why ...
// (fixme) is this the frame header? I assume yes since it starts with 2.
szCurrent += 36;
this->SizeCheck(szCurrent + sizeof(const HMP::Vertex_HMP7)*height*width);
SizeCheck(szCurrent + sizeof(const HMP::Vertex_HMP7)*height*width);
// now load all vertices from the file
aiVector3D* pcVertOut = pcMesh->mVertices;
@@ -238,31 +225,31 @@ void HMPImporter::InternReadFile_HMP5( )
}
// generate texture coordinates if necessary
if (pcHeader->numskins)this->GenerateTextureCoords(width,height);
if (pcHeader->numskins)GenerateTextureCoords(width,height);
// now build a list of faces
this->CreateOutputFaceList(width,height);
CreateOutputFaceList(width,height);
// there is no nodegraph in HMP files. Simply assign the one mesh
// (no, not the one ring) to the root node
this->pScene->mRootNode = new aiNode();
this->pScene->mRootNode->mName.Set("terrain_root");
this->pScene->mRootNode->mNumMeshes = 1;
this->pScene->mRootNode->mMeshes = new unsigned int[1];
this->pScene->mRootNode->mMeshes[0] = 0;
pScene->mRootNode = new aiNode();
pScene->mRootNode->mName.Set("terrain_root");
pScene->mRootNode->mNumMeshes = 1;
pScene->mRootNode->mMeshes = new unsigned int[1];
pScene->mRootNode->mMeshes[0] = 0;
}
// ------------------------------------------------------------------------------------------------
void HMPImporter::InternReadFile_HMP7( )
{
// read the file header and skip everything to byte 84
const HMP::Header_HMP5* const pcHeader = (const HMP::Header_HMP5*)this->mBuffer;
const unsigned char* szCurrent = (const unsigned char*)(this->mBuffer+84);
this->ValidateHeader_HMP457();
const HMP::Header_HMP5* const pcHeader = (const HMP::Header_HMP5*)mBuffer;
const unsigned char* szCurrent = (const unsigned char*)(mBuffer+84);
ValidateHeader_HMP457();
// generate an output mesh
this->pScene->mNumMeshes = 1;
this->pScene->mMeshes = new aiMesh*[1];
aiMesh* pcMesh = this->pScene->mMeshes[0] = new aiMesh();
pScene->mNumMeshes = 1;
pScene->mMeshes = new aiMesh*[1];
aiMesh* pcMesh = pScene->mMeshes[0] = new aiMesh();
pcMesh->mMaterialIndex = 0;
pcMesh->mVertices = new aiVector3D[pcHeader->numverts];
@@ -272,13 +259,13 @@ void HMPImporter::InternReadFile_HMP7( )
const unsigned int width = (unsigned int)pcHeader->fnumverts_x;
// generate/load a material for the terrain
this->CreateMaterial(szCurrent,&szCurrent);
CreateMaterial(szCurrent,&szCurrent);
// goto offset 120, I don't know why ...
// (fixme) is this the frame header? I assume yes since it starts with 2.
szCurrent += 36;
this->SizeCheck(szCurrent + sizeof(const HMP::Vertex_HMP7)*height*width);
SizeCheck(szCurrent + sizeof(const HMP::Vertex_HMP7)*height*width);
// now load all vertices from the file
aiVector3D* pcVertOut = pcMesh->mVertices;
@@ -306,25 +293,26 @@ void HMPImporter::InternReadFile_HMP7( )
}
// generate texture coordinates if necessary
if (pcHeader->numskins)this->GenerateTextureCoords(width,height);
if (pcHeader->numskins)GenerateTextureCoords(width,height);
// now build a list of faces
this->CreateOutputFaceList(width,height);
CreateOutputFaceList(width,height);
// there is no nodegraph in HMP files. Simply assign the one mesh
// (no, not the One Ring) to the root node
this->pScene->mRootNode = new aiNode();
this->pScene->mRootNode->mName.Set("terrain_root");
this->pScene->mRootNode->mNumMeshes = 1;
this->pScene->mRootNode->mMeshes = new unsigned int[1];
this->pScene->mRootNode->mMeshes[0] = 0;
pScene->mRootNode = new aiNode();
pScene->mRootNode->mName.Set("terrain_root");
pScene->mRootNode->mNumMeshes = 1;
pScene->mRootNode->mMeshes = new unsigned int[1];
pScene->mRootNode->mMeshes[0] = 0;
}
// ------------------------------------------------------------------------------------------------
void HMPImporter::CreateMaterial(const unsigned char* szCurrent,
const unsigned char** szCurrentOut)
{
aiMesh* const pcMesh = this->pScene->mMeshes[0];
const HMP::Header_HMP5* const pcHeader = (const HMP::Header_HMP5*)this->mBuffer;
aiMesh* const pcMesh = pScene->mMeshes[0];
const HMP::Header_HMP5* const pcHeader = (const HMP::Header_HMP5*)mBuffer;
// we don't need to generate texture coordinates if
// we have no textures in the file ...
@@ -334,7 +322,7 @@ void HMPImporter::CreateMaterial(const unsigned char* szCurrent,
pcMesh->mNumUVComponents[0] = 2;
// now read the first skin and skip all others
this->ReadFirstSkin(pcHeader->numskins,szCurrent,&szCurrent);
ReadFirstSkin(pcHeader->numskins,szCurrent,&szCurrent);
}
else
{
@@ -356,25 +344,25 @@ void HMPImporter::CreateMaterial(const unsigned char* szCurrent,
pcHelper->AddProperty(&szName,AI_MATKEY_NAME);
// add the material to the scene
this->pScene->mNumMaterials = 1;
this->pScene->mMaterials = new aiMaterial*[1];
this->pScene->mMaterials[0] = pcHelper;
pScene->mNumMaterials = 1;
pScene->mMaterials = new aiMaterial*[1];
pScene->mMaterials[0] = pcHelper;
}
*szCurrentOut = szCurrent;
}
// ------------------------------------------------------------------------------------------------
void HMPImporter::CreateOutputFaceList(unsigned int width,unsigned int height)
{
aiMesh* const pcMesh = this->pScene->mMeshes[0];
// allocate enough storage
const unsigned int iNumSquares = (width-1) * (height-1);
pcMesh->mNumFaces = iNumSquares << 1;
// Allocate enough storage
pcMesh->mNumFaces = (width-1) * (height-1);
pcMesh->mFaces = new aiFace[pcMesh->mNumFaces];
pcMesh->mNumVertices = pcMesh->mNumFaces*3;
pcMesh->mNumVertices = pcMesh->mNumFaces*4;
aiVector3D* pcVertices = new aiVector3D[pcMesh->mNumVertices];
aiVector3D* pcNormals = new aiVector3D[pcMesh->mNumVertices];
aiVector3D* pcNormals = new aiVector3D[pcMesh->mNumVertices];
aiFace* pcFaceOut(pcMesh->mFaces);
aiVector3D* pcVertOut = pcVertices;
@@ -383,59 +371,34 @@ void HMPImporter::CreateOutputFaceList(unsigned int width,unsigned int height)
aiVector3D* pcUVs = pcMesh->mTextureCoords[0] ? new aiVector3D[pcMesh->mNumVertices] : NULL;
aiVector3D* pcUVOut(pcUVs);
// build the terrain square
// Build the terrain square
unsigned int iCurrent = 0;
for (unsigned int y = 0; y < height-1;++y)
{
for (unsigned int x = 0; x < width-1;++x)
{
// first triangle of the square
pcFaceOut->mNumIndices = 3;
pcFaceOut->mIndices = new unsigned int[3];
for (unsigned int y = 0; y < height-1;++y) {
for (unsigned int x = 0; x < width-1;++x,++pcFaceOut) {
pcFaceOut->mNumIndices = 4;
pcFaceOut->mIndices = new unsigned int[4];
*pcVertOut++ = pcMesh->mVertices[y*width+x];
*pcVertOut++ = pcMesh->mVertices[y*width+x+1];
*pcVertOut++ = pcMesh->mVertices[(y+1)*width+x];
*pcVertOut++ = pcMesh->mVertices[(y+1)*width+x+1];
*pcVertOut++ = pcMesh->mVertices[y*width+x+1];
*pcNorOut++ = pcMesh->mNormals[y*width+x];
*pcNorOut++ = pcMesh->mNormals[y*width+x+1];
*pcNorOut++ = pcMesh->mNormals[(y+1)*width+x];
*pcNorOut++ = pcMesh->mNormals[(y+1)*width+x+1];
*pcNorOut++ = pcMesh->mNormals[y*width+x+1];
if (pcMesh->mTextureCoords[0])
{
*pcUVOut++ = pcMesh->mTextureCoords[0][y*width+x];
*pcUVOut++ = pcMesh->mTextureCoords[0][y*width+x+1];
*pcUVOut++ = pcMesh->mTextureCoords[0][(y+1)*width+x];
}
pcFaceOut->mIndices[2] = iCurrent++;
pcFaceOut->mIndices[1] = iCurrent++;
pcFaceOut->mIndices[0] = iCurrent++;
++pcFaceOut;
// second triangle of the square
pcFaceOut->mNumIndices = 3;
pcFaceOut->mIndices = new unsigned int[3];
*pcVertOut++ = pcMesh->mVertices[(y+1)*width+x];
*pcVertOut++ = pcMesh->mVertices[y*width+x+1];
*pcVertOut++ = pcMesh->mVertices[(y+1)*width+x+1];
*pcNorOut++ = pcMesh->mNormals[(y+1)*width+x];
*pcNorOut++ = pcMesh->mNormals[y*width+x+1];
*pcNorOut++ = pcMesh->mNormals[(y+1)*width+x+1];
if (pcMesh->mTextureCoords[0])
{
*pcUVOut++ = pcMesh->mTextureCoords[0][(y+1)*width+x];
*pcUVOut++ = pcMesh->mTextureCoords[0][y*width+x+1];
*pcUVOut++ = pcMesh->mTextureCoords[0][(y+1)*width+x+1];
*pcUVOut++ = pcMesh->mTextureCoords[0][y*width+x+1];
}
pcFaceOut->mIndices[2] = iCurrent++;
pcFaceOut->mIndices[1] = iCurrent++;
pcFaceOut->mIndices[0] = iCurrent++;
++pcFaceOut;
for (unsigned int i = 0; i < 4;++i)
pcFaceOut->mIndices[i] = iCurrent++;
}
}
delete[] pcMesh->mVertices;
@@ -450,6 +413,7 @@ void HMPImporter::CreateOutputFaceList(unsigned int width,unsigned int height)
pcMesh->mTextureCoords[0] = pcUVs;
}
}
// ------------------------------------------------------------------------------------------------
void HMPImporter::ReadFirstSkin(unsigned int iNumSkins, const unsigned char* szCursor,
const unsigned char** szCursorOut)
@@ -461,69 +425,58 @@ void HMPImporter::ReadFirstSkin(unsigned int iNumSkins, const unsigned char* szC
uint32_t iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
if (0 == iType)
{
DefaultLogger::get()->warn("Skin type is 0. Skipping 12 bytes to "
"the next valid value, which seems to be the real skin type. "
"However, it is not known whether or not this is correct.");
szCursor += sizeof(uint32_t) * 2;
iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
if (0 == iType)
{
if (!iType)
throw new ImportErrorException("Unable to read HMP7 skin chunk");
}
}
// read width and height
uint32_t iWidth = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
uint32_t iHeight = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
uint32_t iWidth = *((uint32_t*)szCursor); szCursor += sizeof(uint32_t);
uint32_t iHeight = *((uint32_t*)szCursor); szCursor += sizeof(uint32_t);
// allocate an output material
MaterialHelper* pcMat = new MaterialHelper();
// read the skin, this works exactly as for MDL7
this->ParseSkinLump_3DGS_MDL7(szCursor,&szCursor,
ParseSkinLump_3DGS_MDL7(szCursor,&szCursor,
pcMat,iType,iWidth,iHeight);
// now we need to skip any other skins ...
for (unsigned int i = 1; i< iNumSkins;++i)
{
iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
iWidth = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
iHeight = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
iType = *((uint32_t*)szCursor); szCursor += sizeof(uint32_t);
iWidth = *((uint32_t*)szCursor); szCursor += sizeof(uint32_t);
iHeight = *((uint32_t*)szCursor); szCursor += sizeof(uint32_t);
this->SkipSkinLump_3DGS_MDL7(szCursor,&szCursor,
iType,iWidth,iHeight);
this->SizeCheck(szCursor);
SkipSkinLump_3DGS_MDL7(szCursor,&szCursor,iType,iWidth,iHeight);
SizeCheck(szCursor);
}
// setup the material ...
this->pScene->mNumMaterials = 1;
this->pScene->mMaterials = new aiMaterial*[1];
this->pScene->mMaterials[0] = pcMat;
pScene->mNumMaterials = 1;
pScene->mMaterials = new aiMaterial*[1];
pScene->mMaterials[0] = pcMat;
*szCursorOut = szCursor;
return;
}
// ------------------------------------------------------------------------------------------------
void HMPImporter::GenerateTextureCoords(
const unsigned int width, const unsigned int height)
{
ai_assert(NULL != this->pScene->mMeshes && NULL != this->pScene->mMeshes[0] &&
NULL != this->pScene->mMeshes[0]->mTextureCoords[0]);
ai_assert(NULL != pScene->mMeshes && NULL != pScene->mMeshes[0] &&
NULL != pScene->mMeshes[0]->mTextureCoords[0]);
aiVector3D* uv = this->pScene->mMeshes[0]->mTextureCoords[0];
aiVector3D* uv = pScene->mMeshes[0]->mTextureCoords[0];
const float fY = (1.0f / height) + (1.0f / height) / (height-1);
const float fX = (1.0f / width) + (1.0f / width) / (width-1);
for (unsigned int y = 0; y < height;++y)
{
for (unsigned int x = 0; x < width;++x)
{
for (unsigned int y = 0; y < height;++y) {
for (unsigned int x = 0; x < width;++x,++uv) {
uv->y = 1.0f-fY*y;
uv->x = fX*x;
uv->z = 0.0f;
++uv;
}
}
return;
}

View File

@@ -102,9 +102,9 @@ bool IRRImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler) const
if (extension == ".irr")return true;
else if (extension == ".xml")
{
/* If CanRead() is called to check whether the loader
* supports a specific file extension in general we
* must return true here.
/* If CanRead() is called in order to check whether we
* support a specific file extension in general pIOHandler
* might be NULL and it's our duty to return true here.
*/
if (!pIOHandler)return true;
const char* tokens[] = {"irr_scene"};

View File

@@ -217,6 +217,9 @@ void TerragenImporter::InternReadFile( const std::string& pFile,
// Check whether we have a mesh now
if (pScene->mNumMeshes != 1)
throw new ImportErrorException("TER: Unable to load terrain");
// Set the AI_SCENE_FLAGS_TERRAIN bit
pScene->mFlags |= AI_SCENE_FLAGS_TERRAIN;
}
#endif // !! AI_BUILD_NO_TERRAGEN_IMPORTER