2008-06-22 10:09:26 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (ASSIMP)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Copyright (c) 2006-2008, ASSIMP Development Team
|
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
|
|
|
conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the ASSIMP team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the ASSIMP Development Team.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file Implementation of the MDL importer class */
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
#include "AssimpPCH.h"
|
2009-01-18 23:48:25 +00:00
|
|
|
#ifndef ASSIMP_BUILD_NO_HMP_IMPORTER
|
2008-10-13 16:45:48 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// internal headers
|
2008-06-22 10:09:26 +00:00
|
|
|
#include "MaterialSystem.h"
|
|
|
|
#include "HMPLoader.h"
|
2008-08-06 23:01:38 +00:00
|
|
|
#include "MD2FileData.h"
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Constructor to be privately used by Importer
|
|
|
|
HMPImporter::HMPImporter()
|
|
|
|
{
|
|
|
|
// nothing to do here
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Destructor, private as well
|
|
|
|
HMPImporter::~HMPImporter()
|
|
|
|
{
|
|
|
|
// nothing to do here
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Returns whether the class can handle the format of the given file.
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
bool HMPImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool cs) const
|
2008-06-22 10:09:26 +00:00
|
|
|
{
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
const std::string extension = GetExtension(pFile);
|
|
|
|
if (extension == "hmp" )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// if check for extension is not enough, check for the magic tokens
|
|
|
|
if (!extension.length() || cs) {
|
|
|
|
uint32_t tokens[3];
|
|
|
|
tokens[0] = AI_HMP_MAGIC_NUMBER_LE_4;
|
|
|
|
tokens[1] = AI_HMP_MAGIC_NUMBER_LE_5;
|
|
|
|
tokens[2] = AI_HMP_MAGIC_NUMBER_LE_7;
|
|
|
|
return CheckMagicToken(pIOHandler,pFile,tokens,3,0);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Get list of all file extensions that are handled by this loader
|
2010-03-02 17:38:01 +00:00
|
|
|
void HMPImporter::GetExtensionList(std::set<std::string>& extensions)
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
{
|
2010-03-02 17:38:01 +00:00
|
|
|
extensions.insert("hmp");
|
2008-06-22 10:09:26 +00:00
|
|
|
}
|
2009-01-10 17:58:06 +00:00
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Imports the given file into the given scene structure.
|
2009-01-10 17:58:06 +00:00
|
|
|
void HMPImporter::InternReadFile( const std::string& pFile,
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
aiScene* _pScene, IOSystem* _pIOHandler)
|
2008-06-22 10:09:26 +00:00
|
|
|
{
|
2009-01-20 21:41:17 +00:00
|
|
|
pScene = _pScene;
|
|
|
|
pIOHandler = _pIOHandler;
|
2008-06-22 10:09:26 +00:00
|
|
|
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 + ".");
|
|
|
|
|
2009-01-10 17:58:06 +00:00
|
|
|
// Check whether the HMP file is large enough to contain
|
2008-06-22 10:09:26 +00:00
|
|
|
// at least the file header
|
2009-01-10 17:58:06 +00:00
|
|
|
const size_t fileSize = file->FileSize();
|
2008-06-22 10:09:26 +00:00
|
|
|
if( fileSize < 50)
|
2008-08-06 23:01:38 +00:00
|
|
|
throw new ImportErrorException( "HMP File is too small.");
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2009-01-10 17:58:06 +00:00
|
|
|
// Allocate storage and copy the contents of the file to a memory buffer
|
2009-01-20 11:32:39 +00:00
|
|
|
std::vector<uint8_t> buffer(fileSize);
|
2009-01-10 17:58:06 +00:00
|
|
|
mBuffer = &buffer[0];
|
|
|
|
file->Read( (void*)mBuffer, 1, fileSize);
|
|
|
|
iFileSize = (unsigned int)fileSize;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2009-01-10 17:58:06 +00:00
|
|
|
// Determine the file subtype and call the appropriate member function
|
2009-01-20 21:41:17 +00:00
|
|
|
const uint32_t iMagic = *((uint32_t*)this->mBuffer);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
// 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");
|
2009-01-10 17:58:06 +00:00
|
|
|
InternReadFile_HMP4();
|
2008-06-22 10:09:26 +00:00
|
|
|
}
|
|
|
|
// 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");
|
2009-01-10 17:58:06 +00:00
|
|
|
InternReadFile_HMP5();
|
2008-06-22 10:09:26 +00:00
|
|
|
}
|
|
|
|
// 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");
|
2009-01-10 17:58:06 +00:00
|
|
|
InternReadFile_HMP7();
|
2008-06-22 10:09:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-10 17:58:06 +00:00
|
|
|
// Print the magic word to the logger
|
2008-08-06 23:01:38 +00:00
|
|
|
char szBuffer[5];
|
|
|
|
szBuffer[0] = ((char*)&iMagic)[0];
|
|
|
|
szBuffer[1] = ((char*)&iMagic)[1];
|
|
|
|
szBuffer[2] = ((char*)&iMagic)[2];
|
|
|
|
szBuffer[3] = ((char*)&iMagic)[3];
|
|
|
|
szBuffer[4] = '\0';
|
|
|
|
|
2009-01-10 17:58:06 +00:00
|
|
|
// We're definitely unable to load this file
|
2008-06-22 10:09:26 +00:00
|
|
|
throw new ImportErrorException( "Unknown HMP subformat " + pFile +
|
2008-08-06 23:01:38 +00:00
|
|
|
". Magic word (" + szBuffer + ") is not known");
|
2008-06-22 10:09:26 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 17:58:06 +00:00
|
|
|
// Set the AI_SCENE_FLAGS_TERRAIN bit
|
|
|
|
pScene->mFlags |= AI_SCENE_FLAGS_TERRAIN;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2009-01-10 17:58:06 +00:00
|
|
|
// File buffer destructs automatically now
|
2008-06-22 10:09:26 +00:00
|
|
|
}
|
2009-01-10 17:58:06 +00:00
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-08-06 23:01:38 +00:00
|
|
|
void HMPImporter::ValidateHeader_HMP457( )
|
2008-06-22 10:09:26 +00:00
|
|
|
{
|
2009-01-18 23:48:25 +00:00
|
|
|
const HMP::Header_HMP5* const pcHeader = (const HMP::Header_HMP5*)mBuffer;
|
2008-08-06 23:01:38 +00:00
|
|
|
|
2009-01-18 23:48:25 +00:00
|
|
|
if (120 > iFileSize)
|
2008-08-06 23:01:38 +00:00
|
|
|
{
|
|
|
|
throw new ImportErrorException("HMP file is too small (header size is "
|
|
|
|
"120 bytes, this file is smaller)");
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
if (!pcHeader->ftrisize_x || !pcHeader->ftrisize_y)
|
|
|
|
throw new ImportErrorException("Size of triangles in either x or y direction is zero");
|
2009-01-10 17:58:06 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
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");
|
2009-01-10 17:58:06 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
if(!pcHeader->numframes)
|
|
|
|
throw new ImportErrorException("There are no frames. At least one should be there");
|
2009-01-10 17:58:06 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
2009-01-10 17:58:06 +00:00
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-08-06 23:01:38 +00:00
|
|
|
void HMPImporter::InternReadFile_HMP4( )
|
2008-06-22 10:09:26 +00:00
|
|
|
{
|
|
|
|
throw new ImportErrorException("HMP4 is currently not supported");
|
|
|
|
}
|
2009-01-10 17:58:06 +00:00
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-08-06 23:01:38 +00:00
|
|
|
void HMPImporter::InternReadFile_HMP5( )
|
2008-06-22 10:09:26 +00:00
|
|
|
{
|
|
|
|
// read the file header and skip everything to byte 84
|
2009-01-10 17:58:06 +00:00
|
|
|
const HMP::Header_HMP5* pcHeader = (const HMP::Header_HMP5*)mBuffer;
|
|
|
|
const unsigned char* szCurrent = (const unsigned char*)(mBuffer+84);
|
|
|
|
ValidateHeader_HMP457();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
// generate an output mesh
|
2009-01-10 17:58:06 +00:00
|
|
|
pScene->mNumMeshes = 1;
|
|
|
|
pScene->mMeshes = new aiMesh*[1];
|
|
|
|
aiMesh* pcMesh = pScene->mMeshes[0] = new aiMesh();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
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);
|
2009-01-10 17:58:06 +00:00
|
|
|
const unsigned int width = (unsigned int)pcHeader->fnumverts_x;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// generate/load a material for the terrain
|
2009-01-10 17:58:06 +00:00
|
|
|
CreateMaterial(szCurrent,&szCurrent);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// goto offset 120, I don't know why ...
|
|
|
|
// (fixme) is this the frame header? I assume yes since it starts with 2.
|
|
|
|
szCurrent += 36;
|
2009-01-10 17:58:06 +00:00
|
|
|
SizeCheck(szCurrent + sizeof(const HMP::Vertex_HMP7)*height*width);
|
2008-08-06 23:01:38 +00:00
|
|
|
|
|
|
|
// now load all vertices from the file
|
|
|
|
aiVector3D* pcVertOut = pcMesh->mVertices;
|
|
|
|
aiVector3D* pcNorOut = pcMesh->mNormals;
|
|
|
|
const HMP::Vertex_HMP5* src = (const HMP::Vertex_HMP5*) szCurrent;
|
|
|
|
for (unsigned int y = 0; y < height;++y)
|
2008-06-22 10:09:26 +00:00
|
|
|
{
|
2008-08-06 23:01:38 +00:00
|
|
|
for (unsigned int x = 0; x < width;++x)
|
|
|
|
{
|
|
|
|
pcVertOut->x = x * pcHeader->ftrisize_x;
|
|
|
|
pcVertOut->y = y * pcHeader->ftrisize_y;
|
|
|
|
pcVertOut->z = (((float)src->z / 0xffff)-0.5f) * pcHeader->ftrisize_x * 8.0f;
|
|
|
|
MD2::LookupNormalIndex(src->normals162index, *pcNorOut );
|
|
|
|
++pcVertOut;++pcNorOut;++src;
|
|
|
|
}
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// generate texture coordinates if necessary
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
if (pcHeader->numskins)
|
|
|
|
GenerateTextureCoords(width,height);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// now build a list of faces
|
2009-01-10 17:58:06 +00:00
|
|
|
CreateOutputFaceList(width,height);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// there is no nodegraph in HMP files. Simply assign the one mesh
|
|
|
|
// (no, not the one ring) to the root node
|
2009-01-10 17:58:06 +00:00
|
|
|
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;
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void HMPImporter::InternReadFile_HMP7( )
|
|
|
|
{
|
|
|
|
// read the file header and skip everything to byte 84
|
2009-01-10 17:58:06 +00:00
|
|
|
const HMP::Header_HMP5* const pcHeader = (const HMP::Header_HMP5*)mBuffer;
|
|
|
|
const unsigned char* szCurrent = (const unsigned char*)(mBuffer+84);
|
|
|
|
ValidateHeader_HMP457();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// generate an output mesh
|
2009-01-10 17:58:06 +00:00
|
|
|
pScene->mNumMeshes = 1;
|
|
|
|
pScene->mMeshes = new aiMesh*[1];
|
|
|
|
aiMesh* pcMesh = pScene->mMeshes[0] = new aiMesh();
|
2008-08-06 23:01:38 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// generate/load a material for the terrain
|
2009-01-10 17:58:06 +00:00
|
|
|
CreateMaterial(szCurrent,&szCurrent);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
// goto offset 120, I don't know why ...
|
2008-08-06 23:01:38 +00:00
|
|
|
// (fixme) is this the frame header? I assume yes since it starts with 2.
|
2008-06-22 10:09:26 +00:00
|
|
|
szCurrent += 36;
|
|
|
|
|
2009-01-10 17:58:06 +00:00
|
|
|
SizeCheck(szCurrent + sizeof(const HMP::Vertex_HMP7)*height*width);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
// now load all vertices from the file
|
|
|
|
aiVector3D* pcVertOut = pcMesh->mVertices;
|
|
|
|
aiVector3D* pcNorOut = pcMesh->mNormals;
|
|
|
|
const HMP::Vertex_HMP7* src = (const HMP::Vertex_HMP7*) szCurrent;
|
|
|
|
for (unsigned int y = 0; y < height;++y)
|
|
|
|
{
|
|
|
|
for (unsigned int x = 0; x < width;++x)
|
|
|
|
{
|
|
|
|
pcVertOut->x = x * pcHeader->ftrisize_x;
|
|
|
|
pcVertOut->y = y * pcHeader->ftrisize_y;
|
2008-08-06 23:01:38 +00:00
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
// FIXME: What exctly is the correct scaling factor to use?
|
|
|
|
// possibly pcHeader->scale_origin[2] in combination with a
|
|
|
|
// signed interpretation of src->z?
|
|
|
|
pcVertOut->z = (((float)src->z / 0xffff)-0.5f) * pcHeader->ftrisize_x * 8.0f;
|
|
|
|
|
|
|
|
pcNorOut->x = ((float)src->normal_x / 0x80 ); // * pcHeader->scale_origin[0];
|
|
|
|
pcNorOut->y = ((float)src->normal_y / 0x80 ); // * pcHeader->scale_origin[1];
|
|
|
|
pcNorOut->z = 1.0f;
|
|
|
|
pcNorOut->Normalize();
|
|
|
|
|
|
|
|
++pcVertOut;++pcNorOut;++src;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate texture coordinates if necessary
|
2009-01-10 17:58:06 +00:00
|
|
|
if (pcHeader->numskins)GenerateTextureCoords(width,height);
|
2008-08-06 23:01:38 +00:00
|
|
|
|
|
|
|
// now build a list of faces
|
2009-01-10 17:58:06 +00:00
|
|
|
CreateOutputFaceList(width,height);
|
2008-08-06 23:01:38 +00:00
|
|
|
|
|
|
|
// there is no nodegraph in HMP files. Simply assign the one mesh
|
|
|
|
// (no, not the One Ring) to the root node
|
2009-01-10 17:58:06 +00:00
|
|
|
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;
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
2009-01-10 17:58:06 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void HMPImporter::CreateMaterial(const unsigned char* szCurrent,
|
|
|
|
const unsigned char** szCurrentOut)
|
|
|
|
{
|
2009-01-10 17:58:06 +00:00
|
|
|
aiMesh* const pcMesh = pScene->mMeshes[0];
|
|
|
|
const HMP::Header_HMP5* const pcHeader = (const HMP::Header_HMP5*)mBuffer;
|
2008-08-06 23:01:38 +00:00
|
|
|
|
|
|
|
// we don't need to generate texture coordinates if
|
|
|
|
// we have no textures in the file ...
|
2008-06-22 10:09:26 +00:00
|
|
|
if (pcHeader->numskins)
|
|
|
|
{
|
2008-08-06 23:01:38 +00:00
|
|
|
pcMesh->mTextureCoords[0] = new aiVector3D[pcHeader->numverts];
|
|
|
|
pcMesh->mNumUVComponents[0] = 2;
|
|
|
|
|
|
|
|
// now read the first skin and skip all others
|
2009-01-10 17:58:06 +00:00
|
|
|
ReadFirstSkin(pcHeader->numskins,szCurrent,&szCurrent);
|
2008-06-22 10:09:26 +00:00
|
|
|
}
|
2008-08-06 23:01:38 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// generate a default material
|
|
|
|
const int iMode = (int)aiShadingMode_Gouraud;
|
|
|
|
MaterialHelper* pcHelper = new MaterialHelper();
|
|
|
|
pcHelper->AddProperty<int>(&iMode, 1, AI_MATKEY_SHADING_MODEL);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
aiColor3D clr;
|
|
|
|
clr.b = clr.g = clr.r = 0.6f;
|
|
|
|
pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_DIFFUSE);
|
|
|
|
pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_SPECULAR);
|
|
|
|
|
|
|
|
clr.b = clr.g = clr.r = 0.05f;
|
|
|
|
pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_AMBIENT);
|
|
|
|
|
|
|
|
aiString szName;
|
|
|
|
szName.Set(AI_DEFAULT_MATERIAL_NAME);
|
|
|
|
pcHelper->AddProperty(&szName,AI_MATKEY_NAME);
|
|
|
|
|
|
|
|
// add the material to the scene
|
2009-01-10 17:58:06 +00:00
|
|
|
pScene->mNumMaterials = 1;
|
|
|
|
pScene->mMaterials = new aiMaterial*[1];
|
|
|
|
pScene->mMaterials[0] = pcHelper;
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
|
|
|
*szCurrentOut = szCurrent;
|
|
|
|
}
|
2009-01-10 17:58:06 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void HMPImporter::CreateOutputFaceList(unsigned int width,unsigned int height)
|
|
|
|
{
|
|
|
|
aiMesh* const pcMesh = this->pScene->mMeshes[0];
|
|
|
|
|
2009-01-10 17:58:06 +00:00
|
|
|
// Allocate enough storage
|
|
|
|
pcMesh->mNumFaces = (width-1) * (height-1);
|
2008-06-22 10:09:26 +00:00
|
|
|
pcMesh->mFaces = new aiFace[pcMesh->mNumFaces];
|
|
|
|
|
2009-01-10 17:58:06 +00:00
|
|
|
pcMesh->mNumVertices = pcMesh->mNumFaces*4;
|
2008-06-22 10:09:26 +00:00
|
|
|
aiVector3D* pcVertices = new aiVector3D[pcMesh->mNumVertices];
|
2009-01-10 17:58:06 +00:00
|
|
|
aiVector3D* pcNormals = new aiVector3D[pcMesh->mNumVertices];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
aiFace* pcFaceOut(pcMesh->mFaces);
|
2008-08-06 23:01:38 +00:00
|
|
|
aiVector3D* pcVertOut = pcVertices;
|
|
|
|
aiVector3D* pcNorOut = pcNormals;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
aiVector3D* pcUVs = pcMesh->mTextureCoords[0] ? new aiVector3D[pcMesh->mNumVertices] : NULL;
|
|
|
|
aiVector3D* pcUVOut(pcUVs);
|
|
|
|
|
2009-01-10 17:58:06 +00:00
|
|
|
// Build the terrain square
|
2008-06-22 10:09:26 +00:00
|
|
|
unsigned int iCurrent = 0;
|
2009-01-10 17:58:06 +00:00
|
|
|
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];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
*pcVertOut++ = pcMesh->mVertices[y*width+x];
|
|
|
|
*pcVertOut++ = pcMesh->mVertices[(y+1)*width+x];
|
|
|
|
*pcVertOut++ = pcMesh->mVertices[(y+1)*width+x+1];
|
2009-01-10 17:58:06 +00:00
|
|
|
*pcVertOut++ = pcMesh->mVertices[y*width+x+1];
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2009-01-10 17:58:06 +00:00
|
|
|
*pcNorOut++ = pcMesh->mNormals[y*width+x];
|
2008-06-22 10:09:26 +00:00
|
|
|
*pcNorOut++ = pcMesh->mNormals[(y+1)*width+x];
|
|
|
|
*pcNorOut++ = pcMesh->mNormals[(y+1)*width+x+1];
|
2009-01-10 17:58:06 +00:00
|
|
|
*pcNorOut++ = pcMesh->mNormals[y*width+x+1];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
if (pcMesh->mTextureCoords[0])
|
|
|
|
{
|
2009-01-10 17:58:06 +00:00
|
|
|
*pcUVOut++ = pcMesh->mTextureCoords[0][y*width+x];
|
2008-06-22 10:09:26 +00:00
|
|
|
*pcUVOut++ = pcMesh->mTextureCoords[0][(y+1)*width+x];
|
|
|
|
*pcUVOut++ = pcMesh->mTextureCoords[0][(y+1)*width+x+1];
|
2009-01-10 17:58:06 +00:00
|
|
|
*pcUVOut++ = pcMesh->mTextureCoords[0][y*width+x+1];
|
2008-06-22 10:09:26 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 17:58:06 +00:00
|
|
|
for (unsigned int i = 0; i < 4;++i)
|
|
|
|
pcFaceOut->mIndices[i] = iCurrent++;
|
2008-06-22 10:09:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
delete[] pcMesh->mVertices;
|
|
|
|
pcMesh->mVertices = pcVertices;
|
|
|
|
|
|
|
|
delete[] pcMesh->mNormals;
|
|
|
|
pcMesh->mNormals = pcNormals;
|
|
|
|
|
|
|
|
if (pcMesh->mTextureCoords[0])
|
|
|
|
{
|
|
|
|
delete[] pcMesh->mTextureCoords[0];
|
|
|
|
pcMesh->mTextureCoords[0] = pcUVs;
|
|
|
|
}
|
|
|
|
}
|
2009-01-10 17:58:06 +00:00
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void HMPImporter::ReadFirstSkin(unsigned int iNumSkins, const unsigned char* szCursor,
|
|
|
|
const unsigned char** szCursorOut)
|
|
|
|
{
|
|
|
|
ai_assert(0 != iNumSkins && NULL != szCursor);
|
|
|
|
|
|
|
|
// read the type of the skin ...
|
|
|
|
// sometimes we need to skip 12 bytes here, I don't know why ...
|
|
|
|
uint32_t iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
|
|
|
|
if (0 == iType)
|
|
|
|
{
|
|
|
|
szCursor += sizeof(uint32_t) * 2;
|
|
|
|
iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
|
2009-01-10 17:58:06 +00:00
|
|
|
if (!iType)
|
2008-06-22 10:09:26 +00:00
|
|
|
throw new ImportErrorException("Unable to read HMP7 skin chunk");
|
2009-01-10 17:58:06 +00:00
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
}
|
|
|
|
// read width and height
|
2009-01-10 17:58:06 +00:00
|
|
|
uint32_t iWidth = *((uint32_t*)szCursor); szCursor += sizeof(uint32_t);
|
|
|
|
uint32_t iHeight = *((uint32_t*)szCursor); szCursor += sizeof(uint32_t);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
// allocate an output material
|
|
|
|
MaterialHelper* pcMat = new MaterialHelper();
|
|
|
|
|
|
|
|
// read the skin, this works exactly as for MDL7
|
2009-01-10 17:58:06 +00:00
|
|
|
ParseSkinLump_3DGS_MDL7(szCursor,&szCursor,
|
2008-06-22 10:09:26 +00:00
|
|
|
pcMat,iType,iWidth,iHeight);
|
|
|
|
|
|
|
|
// now we need to skip any other skins ...
|
|
|
|
for (unsigned int i = 1; i< iNumSkins;++i)
|
|
|
|
{
|
2009-01-10 17:58:06 +00:00
|
|
|
iType = *((uint32_t*)szCursor); szCursor += sizeof(uint32_t);
|
|
|
|
iWidth = *((uint32_t*)szCursor); szCursor += sizeof(uint32_t);
|
|
|
|
iHeight = *((uint32_t*)szCursor); szCursor += sizeof(uint32_t);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2009-01-10 17:58:06 +00:00
|
|
|
SkipSkinLump_3DGS_MDL7(szCursor,&szCursor,iType,iWidth,iHeight);
|
|
|
|
SizeCheck(szCursor);
|
2008-06-22 10:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// setup the material ...
|
2009-01-10 17:58:06 +00:00
|
|
|
pScene->mNumMaterials = 1;
|
|
|
|
pScene->mMaterials = new aiMaterial*[1];
|
|
|
|
pScene->mMaterials[0] = pcMat;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
*szCursorOut = szCursor;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-18 23:48:25 +00:00
|
|
|
// Generate proepr texture coords
|
2008-06-22 10:09:26 +00:00
|
|
|
void HMPImporter::GenerateTextureCoords(
|
|
|
|
const unsigned int width, const unsigned int height)
|
|
|
|
{
|
2009-01-10 17:58:06 +00:00
|
|
|
ai_assert(NULL != pScene->mMeshes && NULL != pScene->mMeshes[0] &&
|
|
|
|
NULL != pScene->mMeshes[0]->mTextureCoords[0]);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2009-01-10 17:58:06 +00:00
|
|
|
aiVector3D* uv = pScene->mMeshes[0]->mTextureCoords[0];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
const float fY = (1.0f / height) + (1.0f / height) / (height-1);
|
|
|
|
const float fX = (1.0f / width) + (1.0f / width) / (width-1);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
2009-01-10 17:58:06 +00:00
|
|
|
for (unsigned int y = 0; y < height;++y) {
|
|
|
|
for (unsigned int x = 0; x < width;++x,++uv) {
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
uv->y = fY*y;
|
2008-08-06 23:01:38 +00:00
|
|
|
uv->x = fX*x;
|
|
|
|
uv->z = 0.0f;
|
2008-06-22 10:09:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
|
|
|
#endif // !! ASSIMP_BUILD_NO_HMP_IMPORTER
|