2008-05-09 17:24:28 +00:00
|
|
|
|
/*
|
|
|
|
|
---------------------------------------------------------------------------
|
2008-05-22 10:20:31 +00:00
|
|
|
|
Open Asset Import Library (ASSIMP)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
2009-01-20 21:41:17 +00:00
|
|
|
|
/** @file MDLLoader.cpp
|
|
|
|
|
* @brief Implementation of the main parts of the MDL importer class
|
|
|
|
|
* *TODO* Cleanup and further testing of some parts necessary
|
|
|
|
|
*/
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// internal headers
|
2008-10-13 16:45:48 +00:00
|
|
|
|
#include "AssimpPCH.h"
|
2009-01-18 23:48:25 +00:00
|
|
|
|
#ifndef ASSIMP_BUILD_NO_MDL_IMPORTER
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
|
#include "MDLLoader.h"
|
|
|
|
|
#include "MDLDefaultColorMap.h"
|
2008-06-22 10:09:26 +00:00
|
|
|
|
#include "MD2FileData.h"
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Ugly stuff ... nevermind
|
|
|
|
|
#define _AI_MDL7_ACCESS(_data, _index, _limit, _type) \
|
2008-06-22 10:09:26 +00:00
|
|
|
|
(*((const _type*)(((const char*)_data) + _index * _limit)))
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
|
|
|
|
#define _AI_MDL7_ACCESS_PTR(_data, _index, _limit, _type) \
|
2008-11-02 22:21:07 +00:00
|
|
|
|
((BE_NCONST _type*)(((const char*)_data) + _index * _limit))
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
|
|
|
|
#define _AI_MDL7_ACCESS_VERT(_data, _index, _limit) \
|
2008-06-22 10:09:26 +00:00
|
|
|
|
_AI_MDL7_ACCESS(_data,_index,_limit,MDL::Vertex_MDL7)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Constructor to be privately used by Importer
|
|
|
|
|
MDLImporter::MDLImporter()
|
2009-01-20 21:41:17 +00:00
|
|
|
|
{}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Destructor, private as well
|
|
|
|
|
MDLImporter::~MDLImporter()
|
2009-01-20 21:41:17 +00:00
|
|
|
|
{}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// 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 MDLImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
|
2008-05-09 17:24:28 +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 == "mdl" )
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// if check for extension is not enough, check for the magic tokens
|
|
|
|
|
if (!extension.length() || checkSig) {
|
|
|
|
|
uint32_t tokens[8];
|
|
|
|
|
tokens[0] = AI_MDL_MAGIC_NUMBER_LE_HL2a;
|
|
|
|
|
tokens[1] = AI_MDL_MAGIC_NUMBER_LE_HL2b;
|
|
|
|
|
tokens[2] = AI_MDL_MAGIC_NUMBER_LE_GS7;
|
|
|
|
|
tokens[3] = AI_MDL_MAGIC_NUMBER_LE_GS5b;
|
|
|
|
|
tokens[4] = AI_MDL_MAGIC_NUMBER_LE_GS5a;
|
|
|
|
|
tokens[5] = AI_MDL_MAGIC_NUMBER_LE_GS4;
|
|
|
|
|
tokens[6] = AI_MDL_MAGIC_NUMBER_LE_GS3;
|
|
|
|
|
tokens[7] = AI_MDL_MAGIC_NUMBER_LE;
|
|
|
|
|
return CheckMagicToken(pIOHandler,pFile,tokens,7,0);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-08-09 22:39:57 +00:00
|
|
|
|
// Setup configuration properties
|
|
|
|
|
void MDLImporter::SetupProperties(const Importer* pImp)
|
|
|
|
|
{
|
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
|
|
|
|
configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_MDL_KEYFRAME,0xffffffff);
|
|
|
|
|
|
|
|
|
|
// The
|
|
|
|
|
// AI_CONFIG_IMPORT_MDL_KEYFRAME option overrides the
|
2008-08-09 22:39:57 +00:00
|
|
|
|
// AI_CONFIG_IMPORT_GLOBAL_KEYFRAME option.
|
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(0xffffffff == configFrameID) {
|
2009-01-20 21:41:17 +00:00
|
|
|
|
configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME,0);
|
2008-08-09 22:39:57 +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
|
|
|
|
|
|
|
|
|
// AI_CONFIG_IMPORT_MDL_COLORMAP - pallette file
|
2009-01-20 21:41:17 +00:00
|
|
|
|
configPalette = pImp->GetPropertyString(AI_CONFIG_IMPORT_MDL_COLORMAP,"colormap.lmp");
|
2008-08-09 22:39:57 +00:00
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
// Get a list of all supported extensions
|
2010-03-02 17:38:01 +00:00
|
|
|
|
void MDLImporter::GetExtensionList(std::set<std::string>& extensions)
|
2009-01-20 21:41:17 +00:00
|
|
|
|
{
|
2010-03-02 17:38:01 +00:00
|
|
|
|
extensions.insert( "mdl" );
|
2009-01-20 21:41:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-09 22:39:57 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// Imports the given file into the given scene structure.
|
2008-08-09 22:39:57 +00:00
|
|
|
|
void MDLImporter::InternReadFile( const std::string& pFile,
|
2009-01-20 21:41:17 +00:00
|
|
|
|
aiScene* _pScene, IOSystem* _pIOHandler)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2009-01-20 21:41:17 +00:00
|
|
|
|
pScene = _pScene;
|
|
|
|
|
pIOHandler = _pIOHandler;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile));
|
|
|
|
|
|
|
|
|
|
// Check whether we can read from the file
|
2010-03-18 17:00:12 +00:00
|
|
|
|
if( file.get() == NULL) {
|
|
|
|
|
throw DeadlyImportError( "Failed to open MDL file " + pFile + ".");
|
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// This should work for all other types of MDL files, too ...
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// the quake header is one of the smallest, afaik
|
2009-01-20 21:41:17 +00:00
|
|
|
|
iFileSize = (unsigned int)file->FileSize();
|
2010-03-18 17:00:12 +00:00
|
|
|
|
if( iFileSize < sizeof(MDL::Header)) {
|
|
|
|
|
throw DeadlyImportError( "MDL File is too small.");
|
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Allocate storage and copy the contents of the file to a memory buffer
|
2010-03-18 17:00:12 +00:00
|
|
|
|
std::vector<unsigned char> buffer(iFileSize+1);
|
|
|
|
|
mBuffer = &buffer[0];
|
2009-01-20 21:41:17 +00:00
|
|
|
|
file->Read( (void*)mBuffer, 1, iFileSize);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Append a binary zero to the end of the buffer.
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// this is just for safety that string parsing routines
|
|
|
|
|
// find the end of the buffer ...
|
2009-03-15 00:40:30 +00:00
|
|
|
|
mBuffer[iFileSize] = '\0';
|
|
|
|
|
const uint32_t iMagicWord = *((uint32_t*)mBuffer);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Determine the file subtype and call the appropriate member function
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2010-03-18 17:00:12 +00:00
|
|
|
|
// Original Quake1 format
|
|
|
|
|
if (AI_MDL_MAGIC_NUMBER_BE == iMagicWord || AI_MDL_MAGIC_NUMBER_LE == iMagicWord) {
|
|
|
|
|
DefaultLogger::get()->debug("MDL subtype: Quake 1, magic word is IDPO");
|
|
|
|
|
iGSFileVersion = 0;
|
|
|
|
|
InternReadFile_Quake1();
|
|
|
|
|
}
|
|
|
|
|
// GameStudio A<old> MDL2 format - used by some test models that come with 3DGS
|
|
|
|
|
else if (AI_MDL_MAGIC_NUMBER_BE_GS3 == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_GS3 == iMagicWord) {
|
|
|
|
|
DefaultLogger::get()->debug("MDL subtype: 3D GameStudio A2, magic word is MDL2");
|
|
|
|
|
iGSFileVersion = 2;
|
|
|
|
|
InternReadFile_Quake1();
|
|
|
|
|
}
|
|
|
|
|
// GameStudio A4 MDL3 format
|
|
|
|
|
else if (AI_MDL_MAGIC_NUMBER_BE_GS4 == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_GS4 == iMagicWord) {
|
|
|
|
|
DefaultLogger::get()->debug("MDL subtype: 3D GameStudio A4, magic word is MDL3");
|
|
|
|
|
iGSFileVersion = 3;
|
|
|
|
|
InternReadFile_3DGS_MDL345();
|
|
|
|
|
}
|
|
|
|
|
// GameStudio A5+ MDL4 format
|
|
|
|
|
else if (AI_MDL_MAGIC_NUMBER_BE_GS5a == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_GS5a == iMagicWord) {
|
|
|
|
|
DefaultLogger::get()->debug("MDL subtype: 3D GameStudio A4, magic word is MDL4");
|
|
|
|
|
iGSFileVersion = 4;
|
|
|
|
|
InternReadFile_3DGS_MDL345();
|
|
|
|
|
}
|
|
|
|
|
// GameStudio A5+ MDL5 format
|
|
|
|
|
else if (AI_MDL_MAGIC_NUMBER_BE_GS5b == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_GS5b == iMagicWord) {
|
|
|
|
|
DefaultLogger::get()->debug("MDL subtype: 3D GameStudio A5, magic word is MDL5");
|
|
|
|
|
iGSFileVersion = 5;
|
|
|
|
|
InternReadFile_3DGS_MDL345();
|
|
|
|
|
}
|
|
|
|
|
// GameStudio A7 MDL7 format
|
|
|
|
|
else if (AI_MDL_MAGIC_NUMBER_BE_GS7 == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_GS7 == iMagicWord) {
|
|
|
|
|
DefaultLogger::get()->debug("MDL subtype: 3D GameStudio A7, magic word is MDL7");
|
|
|
|
|
iGSFileVersion = 7;
|
|
|
|
|
InternReadFile_3DGS_MDL7();
|
|
|
|
|
}
|
|
|
|
|
// IDST/IDSQ Format (CS:S/HL<48>, etc ...)
|
|
|
|
|
else if (AI_MDL_MAGIC_NUMBER_BE_HL2a == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_HL2a == iMagicWord ||
|
|
|
|
|
AI_MDL_MAGIC_NUMBER_BE_HL2b == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_HL2b == iMagicWord)
|
|
|
|
|
{
|
|
|
|
|
DefaultLogger::get()->debug("MDL subtype: CS:S\\HL<EFBFBD>, magic word is IDST/IDSQ");
|
|
|
|
|
iGSFileVersion = 0;
|
|
|
|
|
InternReadFile_HL2();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// print the magic word to the log file
|
|
|
|
|
throw DeadlyImportError( "Unknown MDL subformat " + pFile +
|
|
|
|
|
". Magic word (" + std::string((char*)&iMagicWord,4) + ") is not known");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
// Now rotate the whole scene 90 degrees around the x axis to convert to internal coordinate system
|
|
|
|
|
pScene->mRootNode->mTransformation = aiMatrix4x4(1.f,0.f,0.f,0.f,
|
|
|
|
|
0.f,0.f,1.f,0.f,0.f,-1.f,0.f,0.f,0.f,0.f,0.f,1.f);
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// delete the file buffer and cleanup
|
2009-03-15 00:40:30 +00:00
|
|
|
|
AI_DEBUG_INVALIDATE_PTR(mBuffer);
|
|
|
|
|
AI_DEBUG_INVALIDATE_PTR(pIOHandler);
|
|
|
|
|
AI_DEBUG_INVALIDATE_PTR(pScene);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Check whether we're still inside the valid file range
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::SizeCheck(const void* szPos)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2008-06-22 10:09:26 +00:00
|
|
|
|
if (!szPos || (const unsigned char*)szPos > this->mBuffer + this->iFileSize)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2010-03-18 17:00:12 +00:00
|
|
|
|
throw DeadlyImportError("Invalid MDL file. The file is too small "
|
2008-06-22 10:09:26 +00:00
|
|
|
|
"or contains invalid data.");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Just for debgging purposes
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::SizeCheck(const void* szPos, const char* szFile, unsigned int iLine)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2009-01-20 21:41:17 +00:00
|
|
|
|
ai_assert(NULL != szFile);
|
|
|
|
|
if (!szPos || (const unsigned char*)szPos > mBuffer + iFileSize)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// remove a directory if there is one
|
|
|
|
|
const char* szFilePtr = ::strrchr(szFile,'\\');
|
2009-01-20 21:41:17 +00:00
|
|
|
|
if (!szFilePtr) {
|
|
|
|
|
if(!(szFilePtr = ::strrchr(szFile,'/')))
|
|
|
|
|
szFilePtr = szFile;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
if (szFilePtr)++szFilePtr;
|
|
|
|
|
|
|
|
|
|
char szBuffer[1024];
|
2008-08-09 22:39:57 +00:00
|
|
|
|
::sprintf(szBuffer,"Invalid MDL file. The file is too small "
|
2008-06-22 10:09:26 +00:00
|
|
|
|
"or contains invalid data (File: %s Line: %i)",szFilePtr,iLine);
|
|
|
|
|
|
2010-03-18 17:00:12 +00:00
|
|
|
|
throw DeadlyImportError(szBuffer);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Validate a quake file header
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::ValidateHeader_Quake1(const MDL::Header* pcHeader)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// some values may not be NULL
|
|
|
|
|
if (!pcHeader->num_frames)
|
2010-03-18 17:00:12 +00:00
|
|
|
|
throw DeadlyImportError( "[Quake 1 MDL] There are no frames in the file");
|
2008-08-09 22:39:57 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
if (!pcHeader->num_verts)
|
2010-03-18 17:00:12 +00:00
|
|
|
|
throw DeadlyImportError( "[Quake 1 MDL] There are no vertices in the file");
|
2008-08-09 22:39:57 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
if (!pcHeader->num_tris)
|
2010-03-18 17:00:12 +00:00
|
|
|
|
throw DeadlyImportError( "[Quake 1 MDL] There are no triangles in the file");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
|
// check whether the maxima are exceeded ...however, this applies for Quake 1 MDLs only
|
|
|
|
|
if (!this->iGSFileVersion)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2008-08-06 23:01:38 +00:00
|
|
|
|
if (pcHeader->num_verts > AI_MDL_MAX_VERTS)
|
|
|
|
|
DefaultLogger::get()->warn("Quake 1 MDL model has more than AI_MDL_MAX_VERTS vertices");
|
2008-08-09 22:39:57 +00:00
|
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
|
if (pcHeader->num_tris > AI_MDL_MAX_TRIANGLES)
|
|
|
|
|
DefaultLogger::get()->warn("Quake 1 MDL model has more than AI_MDL_MAX_TRIANGLES triangles");
|
2008-08-09 22:39:57 +00:00
|
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
|
if (pcHeader->num_frames > AI_MDL_MAX_FRAMES)
|
|
|
|
|
DefaultLogger::get()->warn("Quake 1 MDL model has more than AI_MDL_MAX_FRAMES frames");
|
2008-08-09 22:39:57 +00:00
|
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
|
// (this does not apply for 3DGS MDLs)
|
|
|
|
|
if (!this->iGSFileVersion && pcHeader->version != AI_MDL_VERSION)
|
|
|
|
|
DefaultLogger::get()->warn("Quake 1 MDL model has an unknown version: AI_MDL_VERSION (=6) is "
|
|
|
|
|
"the expected file format version");
|
2008-08-09 22:39:57 +00:00
|
|
|
|
if(pcHeader->num_skins && (!pcHeader->skinwidth || !pcHeader->skinheight))
|
|
|
|
|
DefaultLogger::get()->warn("Skin width or height are 0");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-10-30 22:42:35 +00:00
|
|
|
|
|
2008-08-09 22:39:57 +00:00
|
|
|
|
#ifdef AI_BUILD_BIG_ENDIAN
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
void FlipQuakeHeader(BE_NCONST MDL::Header* pcHeader)
|
|
|
|
|
{
|
2008-10-30 22:42:35 +00:00
|
|
|
|
AI_SWAP4( pcHeader->ident);
|
|
|
|
|
AI_SWAP4( pcHeader->version);
|
|
|
|
|
AI_SWAP4( pcHeader->boundingradius);
|
|
|
|
|
AI_SWAP4( pcHeader->flags);
|
|
|
|
|
AI_SWAP4( pcHeader->num_frames);
|
|
|
|
|
AI_SWAP4( pcHeader->num_skins);
|
|
|
|
|
AI_SWAP4( pcHeader->num_tris);
|
|
|
|
|
AI_SWAP4( pcHeader->num_verts);
|
2008-08-09 22:39:57 +00:00
|
|
|
|
for (unsigned int i = 0; i < 3;++i)
|
|
|
|
|
{
|
2008-10-30 22:42:35 +00:00
|
|
|
|
AI_SWAP4( pcHeader->scale[i]);
|
|
|
|
|
AI_SWAP4( pcHeader->translate[i]);
|
2008-08-09 22:39:57 +00:00
|
|
|
|
}
|
2008-10-30 22:42:35 +00:00
|
|
|
|
AI_SWAP4( pcHeader->size);
|
|
|
|
|
AI_SWAP4( pcHeader->skinheight);
|
2009-01-20 21:41:17 +00:00
|
|
|
|
AI_SWAP4( pcHeader->skinwidth);
|
|
|
|
|
AI_SWAP4( pcHeader->synctype);
|
2008-08-09 22:39:57 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Read a Quake 1 file
|
2008-05-09 17:24:28 +00:00
|
|
|
|
void MDLImporter::InternReadFile_Quake1( )
|
|
|
|
|
{
|
|
|
|
|
ai_assert(NULL != pScene);
|
2008-11-02 22:21:07 +00:00
|
|
|
|
BE_NCONST MDL::Header *pcHeader = (BE_NCONST MDL::Header*)this->mBuffer;
|
2008-08-09 22:39:57 +00:00
|
|
|
|
|
|
|
|
|
#ifdef AI_BUILD_BIG_ENDIAN
|
2008-11-02 22:21:07 +00:00
|
|
|
|
FlipQuakeHeader(pcHeader);
|
2008-08-09 22:39:57 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2008-11-02 22:21:07 +00:00
|
|
|
|
ValidateHeader_Quake1(pcHeader);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// current cursor position in the file
|
2008-11-02 22:21:07 +00:00
|
|
|
|
const unsigned char* szCurrent = (const unsigned char*)(pcHeader+1);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// need to read all textures
|
2008-11-02 22:21:07 +00:00
|
|
|
|
for (unsigned int i = 0; i < (unsigned int)pcHeader->num_skins;++i)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2008-08-09 22:39:57 +00:00
|
|
|
|
union{BE_NCONST MDL::Skin* pcSkin;BE_NCONST MDL::GroupSkin* pcGroupSkin;};
|
|
|
|
|
pcSkin = (BE_NCONST MDL::Skin*)szCurrent;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-08-09 22:39:57 +00:00
|
|
|
|
AI_SWAP4( pcSkin->group );
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// Quake 1 groupskins
|
|
|
|
|
if (1 == pcSkin->group)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2008-08-09 22:39:57 +00:00
|
|
|
|
AI_SWAP4( pcGroupSkin->nb );
|
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// need to skip multiple images
|
|
|
|
|
const unsigned int iNumImages = (unsigned int)pcGroupSkin->nb;
|
|
|
|
|
szCurrent += sizeof(uint32_t) * 2;
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
if (0 != iNumImages)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2008-06-22 10:09:26 +00:00
|
|
|
|
if (!i) {
|
|
|
|
|
// however, create only one output image (the first)
|
|
|
|
|
this->CreateTextureARGB8_3DGS_MDL3(szCurrent + iNumImages * sizeof(float));
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// go to the end of the skin section / the beginning of the next skin
|
2008-11-02 22:21:07 +00:00
|
|
|
|
szCurrent += pcHeader->skinheight * pcHeader->skinwidth +
|
2008-06-22 10:09:26 +00:00
|
|
|
|
sizeof(float) * iNumImages;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// 3DGS has a few files that are using other 3DGS like texture formats here
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
szCurrent += sizeof(uint32_t);
|
|
|
|
|
unsigned int iSkip = i ? 0xffffffff : 0;
|
|
|
|
|
this->CreateTexture_3DGS_MDL4(szCurrent,pcSkin->group,&iSkip);
|
|
|
|
|
szCurrent += iSkip;
|
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
// get a pointer to the texture coordinates
|
2008-10-28 23:18:06 +00:00
|
|
|
|
BE_NCONST MDL::TexCoord* pcTexCoords = (BE_NCONST MDL::TexCoord*)szCurrent;
|
2008-11-02 22:21:07 +00:00
|
|
|
|
szCurrent += sizeof(MDL::TexCoord) * pcHeader->num_verts;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// get a pointer to the triangles
|
2008-10-28 23:18:06 +00:00
|
|
|
|
BE_NCONST MDL::Triangle* pcTriangles = (BE_NCONST MDL::Triangle*)szCurrent;
|
2008-11-02 22:21:07 +00:00
|
|
|
|
szCurrent += sizeof(MDL::Triangle) * pcHeader->num_tris;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
VALIDATE_FILE_SIZE(szCurrent);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// now get a pointer to the first frame in the file
|
2008-10-28 23:18:06 +00:00
|
|
|
|
BE_NCONST MDL::Frame* pcFrames = (BE_NCONST MDL::Frame*)szCurrent;
|
|
|
|
|
BE_NCONST MDL::SimpleFrame* pcFirstFrame;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
if (0 == pcFrames->type)
|
|
|
|
|
{
|
|
|
|
|
// get address of single frame
|
|
|
|
|
pcFirstFrame = &pcFrames->frame;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// get the first frame in the group
|
2008-10-28 23:18:06 +00:00
|
|
|
|
BE_NCONST MDL::GroupFrame* pcFrames2 = (BE_NCONST MDL::GroupFrame*)pcFrames;
|
|
|
|
|
pcFirstFrame = (BE_NCONST MDL::SimpleFrame*)(&pcFrames2->time + pcFrames->type);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
BE_NCONST MDL::Vertex* pcVertices = (BE_NCONST MDL::Vertex*) ((pcFirstFrame->name) + sizeof(pcFirstFrame->name));
|
2008-11-02 22:21:07 +00:00
|
|
|
|
VALIDATE_FILE_SIZE((const unsigned char*)(pcVertices + pcHeader->num_verts));
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-08-09 22:39:57 +00:00
|
|
|
|
#ifdef AI_BUILD_BIG_ENDIAN
|
2008-11-02 22:21:07 +00:00
|
|
|
|
for (int i = 0; i<pcHeader->num_verts;++i)
|
2008-08-09 22:39:57 +00:00
|
|
|
|
{
|
|
|
|
|
AI_SWAP4( pcTexCoords[i].onseam );
|
|
|
|
|
AI_SWAP4( pcTexCoords[i].s );
|
|
|
|
|
AI_SWAP4( pcTexCoords[i].t );
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-02 22:21:07 +00:00
|
|
|
|
for (int i = 0; i<pcHeader->num_tris;++i)
|
2008-08-09 22:39:57 +00:00
|
|
|
|
{
|
|
|
|
|
AI_SWAP4( pcTriangles[i].facesfront);
|
|
|
|
|
AI_SWAP4( pcTriangles[i].vertex[0]);
|
|
|
|
|
AI_SWAP4( pcTriangles[i].vertex[1]);
|
|
|
|
|
AI_SWAP4( pcTriangles[i].vertex[2]);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// setup materials
|
2009-01-20 21:41:17 +00:00
|
|
|
|
SetupMaterialProperties_3DGS_MDL5_Quake1();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// allocate enough storage to hold all vertices and triangles
|
|
|
|
|
aiMesh* pcMesh = new aiMesh();
|
2008-09-30 20:20:56 +00:00
|
|
|
|
|
|
|
|
|
pcMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
2008-11-02 22:21:07 +00:00
|
|
|
|
pcMesh->mNumVertices = pcHeader->num_tris * 3;
|
|
|
|
|
pcMesh->mNumFaces = pcHeader->num_tris;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices];
|
|
|
|
|
pcMesh->mTextureCoords[0] = new aiVector3D[pcMesh->mNumVertices];
|
|
|
|
|
pcMesh->mFaces = new aiFace[pcMesh->mNumFaces];
|
|
|
|
|
pcMesh->mNormals = new aiVector3D[pcMesh->mNumVertices];
|
|
|
|
|
pcMesh->mNumUVComponents[0] = 2;
|
|
|
|
|
|
|
|
|
|
// there won't be more than one mesh inside the file
|
|
|
|
|
pScene->mRootNode = new aiNode();
|
|
|
|
|
pScene->mRootNode->mNumMeshes = 1;
|
|
|
|
|
pScene->mRootNode->mMeshes = new unsigned int[1];
|
|
|
|
|
pScene->mRootNode->mMeshes[0] = 0;
|
|
|
|
|
pScene->mNumMeshes = 1;
|
|
|
|
|
pScene->mMeshes = new aiMesh*[1];
|
|
|
|
|
pScene->mMeshes[0] = pcMesh;
|
|
|
|
|
|
|
|
|
|
// now iterate through all triangles
|
|
|
|
|
unsigned int iCurrent = 0;
|
2008-11-02 22:21:07 +00:00
|
|
|
|
for (unsigned int i = 0; i < (unsigned int) pcHeader->num_tris;++i)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
|
|
|
|
pcMesh->mFaces[i].mIndices = new unsigned int[3];
|
|
|
|
|
pcMesh->mFaces[i].mNumIndices = 3;
|
|
|
|
|
|
2008-05-25 22:29:05 +00:00
|
|
|
|
unsigned int iTemp = iCurrent;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
for (unsigned int c = 0; c < 3;++c,++iCurrent)
|
|
|
|
|
{
|
|
|
|
|
pcMesh->mFaces[i].mIndices[c] = iCurrent;
|
|
|
|
|
|
|
|
|
|
// read vertices
|
|
|
|
|
unsigned int iIndex = pcTriangles->vertex[c];
|
2008-11-02 22:21:07 +00:00
|
|
|
|
if (iIndex >= (unsigned int)pcHeader->num_verts)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2008-11-02 22:21:07 +00:00
|
|
|
|
iIndex = pcHeader->num_verts-1;
|
2008-05-13 23:26:52 +00:00
|
|
|
|
DefaultLogger::get()->warn("Index overflow in Q1-MDL vertex list.");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aiVector3D& vec = pcMesh->mVertices[iCurrent];
|
2008-11-02 22:21:07 +00:00
|
|
|
|
vec.x = (float)pcVertices[iIndex].v[0] * pcHeader->scale[0];
|
|
|
|
|
vec.x += pcHeader->translate[0];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-11-02 22:21:07 +00:00
|
|
|
|
vec.y = (float)pcVertices[iIndex].v[1] * pcHeader->scale[1];
|
|
|
|
|
vec.y += pcHeader->translate[1];
|
2009-03-15 00:40:30 +00:00
|
|
|
|
//vec.y *= -1.0f;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-11-02 22:21:07 +00:00
|
|
|
|
vec.z = (float)pcVertices[iIndex].v[2] * pcHeader->scale[2];
|
|
|
|
|
vec.z += pcHeader->translate[2];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// read the normal vector from the precalculated normal table
|
2008-06-22 10:09:26 +00:00
|
|
|
|
MD2::LookupNormalIndex(pcVertices[iIndex].normalIndex,pcMesh->mNormals[iCurrent]);
|
2009-03-15 00:40:30 +00:00
|
|
|
|
//pcMesh->mNormals[iCurrent].y *= -1.0f;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// read texture coordinates
|
|
|
|
|
float s = (float)pcTexCoords[iIndex].s;
|
|
|
|
|
float t = (float)pcTexCoords[iIndex].t;
|
|
|
|
|
|
|
|
|
|
// translate texture coordinates
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (0 == pcTriangles->facesfront && 0 != pcTexCoords[iIndex].onseam) {
|
2008-11-02 22:21:07 +00:00
|
|
|
|
s += pcHeader->skinwidth * 0.5f;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Scale s and t to range from 0.0 to 1.0
|
2008-11-02 22:21:07 +00:00
|
|
|
|
pcMesh->mTextureCoords[0][iCurrent].x = (s + 0.5f) / pcHeader->skinwidth;
|
|
|
|
|
pcMesh->mTextureCoords[0][iCurrent].y = 1.0f-(t + 0.5f) / pcHeader->skinheight;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
}
|
2008-05-25 22:29:05 +00:00
|
|
|
|
pcMesh->mFaces[i].mIndices[0] = iTemp+2;
|
|
|
|
|
pcMesh->mFaces[i].mIndices[1] = iTemp+1;
|
|
|
|
|
pcMesh->mFaces[i].mIndices[2] = iTemp+0;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
pcTriangles++;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Setup material properties for Quake and older GameStudio files
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::SetupMaterialProperties_3DGS_MDL5_Quake1( )
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2008-06-22 10:09:26 +00:00
|
|
|
|
const MDL::Header* const pcHeader = (const MDL::Header*)this->mBuffer;
|
|
|
|
|
|
|
|
|
|
// allocate ONE material
|
2009-01-20 21:41:17 +00:00
|
|
|
|
pScene->mMaterials = new aiMaterial*[1];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pScene->mMaterials[0] = new MaterialHelper();
|
|
|
|
|
pScene->mNumMaterials = 1;
|
|
|
|
|
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// setup the material's properties
|
2008-06-22 10:09:26 +00:00
|
|
|
|
const int iMode = (int)aiShadingMode_Gouraud;
|
|
|
|
|
MaterialHelper* const pcHelper = (MaterialHelper*)pScene->mMaterials[0];
|
|
|
|
|
pcHelper->AddProperty<int>(&iMode, 1, AI_MATKEY_SHADING_MODEL);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
aiColor4D clr;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
if (0 != pcHeader->num_skins && pScene->mNumTextures) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// can we replace the texture with a single color?
|
|
|
|
|
clr = this->ReplaceTextureWithColor(pScene->mTextures[0]);
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (is_not_qnan(clr.r)) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
delete pScene->mTextures[0];
|
|
|
|
|
delete[] pScene->mTextures;
|
|
|
|
|
pScene->mNumTextures = 0;
|
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
|
else {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
clr.b = clr.a = clr.g = clr.r = 1.0f;
|
|
|
|
|
aiString szString;
|
|
|
|
|
::memcpy(szString.data,AI_MAKE_EMBEDDED_TEXNAME(0),3);
|
|
|
|
|
szString.length = 2;
|
|
|
|
|
pcHelper->AddProperty(&szString,AI_MATKEY_TEXTURE_DIFFUSE(0));
|
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcHelper->AddProperty<aiColor4D>(&clr, 1,AI_MATKEY_COLOR_DIFFUSE);
|
|
|
|
|
pcHelper->AddProperty<aiColor4D>(&clr, 1,AI_MATKEY_COLOR_SPECULAR);
|
|
|
|
|
|
|
|
|
|
clr.r *= 0.05f;clr.g *= 0.05f;
|
|
|
|
|
clr.b *= 0.05f;clr.a = 1.0f;
|
|
|
|
|
pcHelper->AddProperty<aiColor4D>(&clr, 1,AI_MATKEY_COLOR_AMBIENT);
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Read a MDL 3,4,5 file
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::InternReadFile_3DGS_MDL345( )
|
|
|
|
|
{
|
|
|
|
|
ai_assert(NULL != pScene);
|
|
|
|
|
|
|
|
|
|
// the header of MDL 3/4/5 is nearly identical to the original Quake1 header
|
2008-11-02 22:21:07 +00:00
|
|
|
|
BE_NCONST MDL::Header *pcHeader = (BE_NCONST MDL::Header*)this->mBuffer;
|
2008-08-09 22:39:57 +00:00
|
|
|
|
#ifdef AI_BUILD_BIG_ENDIAN
|
2008-11-02 22:21:07 +00:00
|
|
|
|
FlipQuakeHeader(pcHeader);
|
2008-08-09 22:39:57 +00:00
|
|
|
|
#endif
|
2009-01-20 21:41:17 +00:00
|
|
|
|
ValidateHeader_Quake1(pcHeader);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// current cursor position in the file
|
2008-11-02 22:21:07 +00:00
|
|
|
|
const unsigned char* szCurrent = (const unsigned char*)(pcHeader+1);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// need to read all textures
|
2009-01-20 21:41:17 +00:00
|
|
|
|
for (unsigned int i = 0; i < (unsigned int)pcHeader->num_skins;++i) {
|
2008-10-30 22:42:35 +00:00
|
|
|
|
BE_NCONST MDL::Skin* pcSkin;
|
|
|
|
|
pcSkin = (BE_NCONST MDL::Skin*)szCurrent;
|
|
|
|
|
AI_SWAP4( pcSkin->group);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// create one output image
|
2008-06-22 10:09:26 +00:00
|
|
|
|
unsigned int iSkip = i ? 0xffffffff : 0;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
if (5 <= iGSFileVersion)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
|
|
|
|
// MDL5 format could contain MIPmaps
|
2009-01-20 21:41:17 +00:00
|
|
|
|
CreateTexture_3DGS_MDL5((unsigned char*)pcSkin + sizeof(uint32_t),
|
2008-05-09 17:24:28 +00:00
|
|
|
|
pcSkin->group,&iSkip);
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
else {
|
|
|
|
|
CreateTexture_3DGS_MDL4((unsigned char*)pcSkin + sizeof(uint32_t),
|
2008-05-09 17:24:28 +00:00
|
|
|
|
pcSkin->group,&iSkip);
|
|
|
|
|
}
|
|
|
|
|
// need to skip one image
|
|
|
|
|
szCurrent += iSkip + sizeof(uint32_t);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// get a pointer to the texture coordinates
|
2008-10-28 23:18:06 +00:00
|
|
|
|
BE_NCONST MDL::TexCoord_MDL3* pcTexCoords = (BE_NCONST MDL::TexCoord_MDL3*)szCurrent;
|
2008-11-02 22:21:07 +00:00
|
|
|
|
szCurrent += sizeof(MDL::TexCoord_MDL3) * pcHeader->synctype;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// NOTE: for MDLn formats "synctype" corresponds to the number of UV coords
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// get a pointer to the triangles
|
2008-10-28 23:18:06 +00:00
|
|
|
|
BE_NCONST MDL::Triangle_MDL3* pcTriangles = (BE_NCONST MDL::Triangle_MDL3*)szCurrent;
|
2008-11-02 22:21:07 +00:00
|
|
|
|
szCurrent += sizeof(MDL::Triangle_MDL3) * pcHeader->num_tris;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-08-09 22:39:57 +00:00
|
|
|
|
#ifdef AI_BUILD_BIG_ENDIAN
|
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (int i = 0; i<pcHeader->synctype;++i) {
|
2008-08-09 22:39:57 +00:00
|
|
|
|
AI_SWAP2( pcTexCoords[i].u );
|
|
|
|
|
AI_SWAP2( pcTexCoords[i].v );
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (int i = 0; i<pcHeader->num_tris;++i) {
|
2008-10-30 22:42:35 +00:00
|
|
|
|
AI_SWAP2( pcTriangles[i].index_xyz[0]);
|
|
|
|
|
AI_SWAP2( pcTriangles[i].index_xyz[1]);
|
|
|
|
|
AI_SWAP2( pcTriangles[i].index_xyz[2]);
|
|
|
|
|
AI_SWAP2( pcTriangles[i].index_uv[0]);
|
|
|
|
|
AI_SWAP2( pcTriangles[i].index_uv[1]);
|
|
|
|
|
AI_SWAP2( pcTriangles[i].index_uv[2]);
|
2008-08-09 22:39:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
VALIDATE_FILE_SIZE(szCurrent);
|
|
|
|
|
|
|
|
|
|
// setup materials
|
2009-01-20 21:41:17 +00:00
|
|
|
|
SetupMaterialProperties_3DGS_MDL5_Quake1();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// allocate enough storage to hold all vertices and triangles
|
|
|
|
|
aiMesh* pcMesh = new aiMesh();
|
2008-09-30 20:20:56 +00:00
|
|
|
|
pcMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-11-02 22:21:07 +00:00
|
|
|
|
pcMesh->mNumVertices = pcHeader->num_tris * 3;
|
|
|
|
|
pcMesh->mNumFaces = pcHeader->num_tris;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
pcMesh->mFaces = new aiFace[pcMesh->mNumFaces];
|
|
|
|
|
|
|
|
|
|
// there won't be more than one mesh inside the file
|
|
|
|
|
pScene->mRootNode = new aiNode();
|
|
|
|
|
pScene->mRootNode->mNumMeshes = 1;
|
|
|
|
|
pScene->mRootNode->mMeshes = new unsigned int[1];
|
|
|
|
|
pScene->mRootNode->mMeshes[0] = 0;
|
|
|
|
|
pScene->mNumMeshes = 1;
|
|
|
|
|
pScene->mMeshes = new aiMesh*[1];
|
|
|
|
|
pScene->mMeshes[0] = pcMesh;
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// allocate output storage
|
2008-11-02 22:21:07 +00:00
|
|
|
|
pcMesh->mNumVertices = (unsigned int)pcHeader->num_tris*3;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices];
|
|
|
|
|
pcMesh->mNormals = new aiVector3D[pcMesh->mNumVertices];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (pcHeader->synctype) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcMesh->mTextureCoords[0] = new aiVector3D[pcMesh->mNumVertices];
|
|
|
|
|
pcMesh->mNumUVComponents[0] = 2;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// now get a pointer to the first frame in the file
|
2008-10-30 22:42:35 +00:00
|
|
|
|
BE_NCONST MDL::Frame* pcFrames = (BE_NCONST MDL::Frame*)szCurrent;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
AI_SWAP4(pcFrames->type);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// byte packed vertices
|
2009-03-15 00:40:30 +00:00
|
|
|
|
// FIXME: these two snippets below are almost identical ... join them?
|
2009-01-20 21:41:17 +00:00
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (0 == pcFrames->type || 3 >= this->iGSFileVersion) {
|
|
|
|
|
|
2008-08-09 22:39:57 +00:00
|
|
|
|
const MDL::SimpleFrame* pcFirstFrame = (const MDL::SimpleFrame*)(szCurrent + sizeof(uint32_t));
|
2009-01-20 21:41:17 +00:00
|
|
|
|
const MDL::Vertex* pcVertices = (const MDL::Vertex*) ((pcFirstFrame->name) + sizeof(pcFirstFrame->name));
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-11-02 22:21:07 +00:00
|
|
|
|
VALIDATE_FILE_SIZE(pcVertices + pcHeader->num_verts);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// now iterate through all triangles
|
|
|
|
|
unsigned int iCurrent = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int i = 0; i < (unsigned int) pcHeader->num_tris;++i) {
|
2008-05-09 17:24:28 +00:00
|
|
|
|
pcMesh->mFaces[i].mIndices = new unsigned int[3];
|
|
|
|
|
pcMesh->mFaces[i].mNumIndices = 3;
|
|
|
|
|
|
2008-05-25 22:29:05 +00:00
|
|
|
|
unsigned int iTemp = iCurrent;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int c = 0; c < 3;++c,++iCurrent) {
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// read vertices
|
|
|
|
|
unsigned int iIndex = pcTriangles->index_xyz[c];
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (iIndex >= (unsigned int)pcHeader->num_verts) {
|
2008-11-02 22:21:07 +00:00
|
|
|
|
iIndex = pcHeader->num_verts-1;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
DefaultLogger::get()->warn("Index overflow in MDLn vertex list");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
aiVector3D& vec = pcMesh->mVertices[iCurrent];
|
2008-11-02 22:21:07 +00:00
|
|
|
|
vec.x = (float)pcVertices[iIndex].v[0] * pcHeader->scale[0];
|
|
|
|
|
vec.x += pcHeader->translate[0];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-11-02 22:21:07 +00:00
|
|
|
|
vec.y = (float)pcVertices[iIndex].v[1] * pcHeader->scale[1];
|
|
|
|
|
vec.y += pcHeader->translate[1];
|
2009-03-15 00:40:30 +00:00
|
|
|
|
// vec.y *= -1.0f;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-11-02 22:21:07 +00:00
|
|
|
|
vec.z = (float)pcVertices[iIndex].v[2] * pcHeader->scale[2];
|
|
|
|
|
vec.z += pcHeader->translate[2];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// read the normal vector from the precalculated normal table
|
2008-06-22 10:09:26 +00:00
|
|
|
|
MD2::LookupNormalIndex(pcVertices[iIndex].normalIndex,pcMesh->mNormals[iCurrent]);
|
2009-03-15 00:40:30 +00:00
|
|
|
|
// pcMesh->mNormals[iCurrent].y *= -1.0f;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// read texture coordinates
|
2009-01-20 21:41:17 +00:00
|
|
|
|
if (pcHeader->synctype) {
|
|
|
|
|
ImportUVCoordinate_3DGS_MDL345(pcMesh->mTextureCoords[0][iCurrent],
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcTexCoords,pcTriangles->index_uv[c]);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-05-25 22:29:05 +00:00
|
|
|
|
pcMesh->mFaces[i].mIndices[0] = iTemp+2;
|
|
|
|
|
pcMesh->mFaces[i].mIndices[1] = iTemp+1;
|
|
|
|
|
pcMesh->mFaces[i].mIndices[2] = iTemp+0;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
pcTriangles++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// short packed vertices
|
2009-01-20 21:41:17 +00:00
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////
|
2009-03-15 00:40:30 +00:00
|
|
|
|
else {
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// now get a pointer to the first frame in the file
|
2008-08-09 22:39:57 +00:00
|
|
|
|
const MDL::SimpleFrame_MDLn_SP* pcFirstFrame = (const MDL::SimpleFrame_MDLn_SP*) (szCurrent + sizeof(uint32_t));
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// get a pointer to the vertices
|
2009-03-15 00:40:30 +00:00
|
|
|
|
const MDL::Vertex_MDL4* pcVertices = (const MDL::Vertex_MDL4*) ((pcFirstFrame->name) +
|
2008-08-09 22:39:57 +00:00
|
|
|
|
sizeof(pcFirstFrame->name));
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-11-02 22:21:07 +00:00
|
|
|
|
VALIDATE_FILE_SIZE(pcVertices + pcHeader->num_verts);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// now iterate through all triangles
|
|
|
|
|
unsigned int iCurrent = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int i = 0; i < (unsigned int) pcHeader->num_tris;++i) {
|
2008-05-09 17:24:28 +00:00
|
|
|
|
pcMesh->mFaces[i].mIndices = new unsigned int[3];
|
|
|
|
|
pcMesh->mFaces[i].mNumIndices = 3;
|
|
|
|
|
|
2008-05-25 22:29:05 +00:00
|
|
|
|
unsigned int iTemp = iCurrent;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int c = 0; c < 3;++c,++iCurrent) {
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// read vertices
|
|
|
|
|
unsigned int iIndex = pcTriangles->index_xyz[c];
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (iIndex >= (unsigned int)pcHeader->num_verts) {
|
2008-11-02 22:21:07 +00:00
|
|
|
|
iIndex = pcHeader->num_verts-1;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
DefaultLogger::get()->warn("Index overflow in MDLn vertex list");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
aiVector3D& vec = pcMesh->mVertices[iCurrent];
|
2008-11-02 22:21:07 +00:00
|
|
|
|
vec.x = (float)pcVertices[iIndex].v[0] * pcHeader->scale[0];
|
|
|
|
|
vec.x += pcHeader->translate[0];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-11-02 22:21:07 +00:00
|
|
|
|
vec.y = (float)pcVertices[iIndex].v[1] * pcHeader->scale[1];
|
|
|
|
|
vec.y += pcHeader->translate[1];
|
2009-03-15 00:40:30 +00:00
|
|
|
|
// vec.y *= -1.0f;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-11-02 22:21:07 +00:00
|
|
|
|
vec.z = (float)pcVertices[iIndex].v[2] * pcHeader->scale[2];
|
|
|
|
|
vec.z += pcHeader->translate[2];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// read the normal vector from the precalculated normal table
|
2008-06-22 10:09:26 +00:00
|
|
|
|
MD2::LookupNormalIndex(pcVertices[iIndex].normalIndex,pcMesh->mNormals[iCurrent]);
|
2009-03-15 00:40:30 +00:00
|
|
|
|
// pcMesh->mNormals[iCurrent].y *= -1.0f;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// read texture coordinates
|
2009-01-20 21:41:17 +00:00
|
|
|
|
if (pcHeader->synctype) {
|
|
|
|
|
ImportUVCoordinate_3DGS_MDL345(pcMesh->mTextureCoords[0][iCurrent],
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcTexCoords,pcTriangles->index_uv[c]);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-05-25 22:29:05 +00:00
|
|
|
|
pcMesh->mFaces[i].mIndices[0] = iTemp+2;
|
|
|
|
|
pcMesh->mFaces[i].mIndices[1] = iTemp+1;
|
|
|
|
|
pcMesh->mFaces[i].mIndices[2] = iTemp+0;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
pcTriangles++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For MDL5 we will need to build valid texture coordinates
|
|
|
|
|
// basing upon the file loaded (only support one file as skin)
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (0x5 == iGSFileVersion)
|
|
|
|
|
CalculateUVCoordinates_MDL5();
|
2008-05-09 17:24:28 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Get a single UV coordinate for Quake and older GameStudio files
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::ImportUVCoordinate_3DGS_MDL345(
|
|
|
|
|
aiVector3D& vOut,
|
|
|
|
|
const MDL::TexCoord_MDL3* pcSrc,
|
|
|
|
|
unsigned int iIndex)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2008-06-22 10:09:26 +00:00
|
|
|
|
ai_assert(NULL != pcSrc);
|
|
|
|
|
const MDL::Header* const pcHeader = (const MDL::Header*)this->mBuffer;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// validate UV indices
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (iIndex >= (unsigned int) pcHeader->synctype) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
iIndex = pcHeader->synctype-1;
|
|
|
|
|
DefaultLogger::get()->warn("Index overflow in MDLn UV coord list");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
float s = (float)pcSrc[iIndex].u;
|
|
|
|
|
float t = (float)pcSrc[iIndex].v;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// Scale s and t to range from 0.0 to 1.0
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (0x5 != iGSFileVersion) {
|
2009-01-20 21:41:17 +00:00
|
|
|
|
s = (s + 0.5f) / pcHeader->skinwidth;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
t = 1.0f-(t + 0.5f) / pcHeader->skinheight;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
vOut.x = s;
|
|
|
|
|
vOut.y = t;
|
|
|
|
|
vOut.z = 0.0f;
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Compute UV coordinates for a MDL5 file
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::CalculateUVCoordinates_MDL5()
|
|
|
|
|
{
|
|
|
|
|
const MDL::Header* const pcHeader = (const MDL::Header*)this->mBuffer;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (pcHeader->num_skins && this->pScene->mNumTextures) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
const aiTexture* pcTex = this->pScene->mTextures[0];
|
|
|
|
|
|
|
|
|
|
// if the file is loaded in DDS format: get the size of the
|
|
|
|
|
// texture from the header of the DDS file
|
|
|
|
|
// skip three DWORDs and read first height, then the width
|
|
|
|
|
unsigned int iWidth, iHeight;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (!pcTex->mHeight) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
const uint32_t* piPtr = (uint32_t*)pcTex->pcData;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
piPtr += 3;
|
|
|
|
|
iHeight = (unsigned int)*piPtr++;
|
2008-09-30 20:20:56 +00:00
|
|
|
|
iWidth = (unsigned int)*piPtr;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
if (!iHeight || !iWidth)
|
2008-05-13 23:26:52 +00:00
|
|
|
|
{
|
2008-06-22 10:09:26 +00:00
|
|
|
|
DefaultLogger::get()->warn("Either the width or the height of the "
|
|
|
|
|
"embedded DDS texture is zero. Unable to compute final texture "
|
|
|
|
|
"coordinates. The texture coordinates remain in their original "
|
|
|
|
|
"0-x/0-y (x,y = texture size) range.");
|
2009-01-20 21:41:17 +00:00
|
|
|
|
iWidth = 1;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
iHeight = 1;
|
2008-05-13 23:26:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
|
else {
|
2009-01-20 21:41:17 +00:00
|
|
|
|
iWidth = pcTex->mWidth;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
iHeight = pcTex->mHeight;
|
2008-05-13 23:26:52 +00:00
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2009-01-20 21:41:17 +00:00
|
|
|
|
if (1 != iWidth || 1 != iHeight) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
const float fWidth = (float)iWidth;
|
|
|
|
|
const float fHeight = (float)iHeight;
|
|
|
|
|
aiMesh* pcMesh = this->pScene->mMeshes[0];
|
|
|
|
|
for (unsigned int i = 0; i < pcMesh->mNumVertices;++i)
|
|
|
|
|
{
|
|
|
|
|
pcMesh->mTextureCoords[0][i].x /= fWidth;
|
|
|
|
|
pcMesh->mTextureCoords[0][i].y /= fHeight;
|
|
|
|
|
pcMesh->mTextureCoords[0][i].y = 1.0f - pcMesh->mTextureCoords[0][i].y; // DX to OGL
|
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Validate the header of a MDL7 file
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::ValidateHeader_3DGS_MDL7(const MDL::Header_MDL7* pcHeader)
|
|
|
|
|
{
|
|
|
|
|
ai_assert(NULL != pcHeader);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// There are some fixed sizes ...
|
|
|
|
|
if (sizeof(MDL::ColorValue_MDL7) != pcHeader->colorvalue_stc_size) {
|
2010-03-18 17:00:12 +00:00
|
|
|
|
throw DeadlyImportError(
|
2009-01-20 21:41:17 +00:00
|
|
|
|
"[3DGS MDL7] sizeof(MDL::ColorValue_MDL7) != pcHeader->colorvalue_stc_size");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
if (sizeof(MDL::TexCoord_MDL7) != pcHeader->skinpoint_stc_size) {
|
2010-03-18 17:00:12 +00:00
|
|
|
|
throw DeadlyImportError(
|
2009-01-20 21:41:17 +00:00
|
|
|
|
"[3DGS MDL7] sizeof(MDL::TexCoord_MDL7) != pcHeader->skinpoint_stc_size");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
if (sizeof(MDL::Skin_MDL7) != pcHeader->skin_stc_size) {
|
2010-03-18 17:00:12 +00:00
|
|
|
|
throw DeadlyImportError(
|
2009-01-20 21:41:17 +00:00
|
|
|
|
"sizeof(MDL::Skin_MDL7) != pcHeader->skin_stc_size");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if there are no groups ... how should we load such a file?
|
2009-01-20 21:41:17 +00:00
|
|
|
|
if(!pcHeader->groups_num) {
|
2010-03-18 17:00:12 +00:00
|
|
|
|
throw DeadlyImportError( "[3DGS MDL7] No frames found");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// resolve bone animation matrices
|
2008-11-02 22:21:07 +00:00
|
|
|
|
void MDLImporter::CalcAbsBoneMatrices_3DGS_MDL7(MDL::IntBone_MDL7** apcOutBones)
|
2008-06-03 21:50:53 +00:00
|
|
|
|
{
|
2008-11-02 22:21:07 +00:00
|
|
|
|
const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7*)this->mBuffer;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
const MDL::Bone_MDL7* pcBones = (const MDL::Bone_MDL7*)(pcHeader+1);
|
2008-06-03 21:50:53 +00:00
|
|
|
|
ai_assert(NULL != apcOutBones);
|
|
|
|
|
|
|
|
|
|
// first find the bone that has NO parent, calculate the
|
|
|
|
|
// animation matrix for it, then go on and search for the next parent
|
|
|
|
|
// index (0) and so on until we can't find a new node.
|
|
|
|
|
uint16_t iParent = 0xffff;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
uint32_t iIterations = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
while (iIterations++ < pcHeader->bones_num) {
|
|
|
|
|
for (uint32_t iBone = 0; iBone < pcHeader->bones_num;++iBone) {
|
2008-11-02 22:21:07 +00:00
|
|
|
|
BE_NCONST MDL::Bone_MDL7* pcBone = _AI_MDL7_ACCESS_PTR(pcBones,iBone,
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcHeader->bone_stc_size,MDL::Bone_MDL7);
|
2009-03-15 00:40:30 +00:00
|
|
|
|
|
|
|
|
|
AI_SWAP2(pcBone->parent_index);
|
|
|
|
|
AI_SWAP4(pcBone->x);
|
|
|
|
|
AI_SWAP4(pcBone->y);
|
|
|
|
|
AI_SWAP4(pcBone->z);
|
|
|
|
|
|
|
|
|
|
if (iParent == pcBone->parent_index) {
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// MDL7 readme
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
/*
|
2008-06-03 21:50:53 +00:00
|
|
|
|
The animation matrix is then calculated the following way:
|
|
|
|
|
|
|
|
|
|
vector3 bPos = <absolute bone position>
|
|
|
|
|
matrix44 laM; // local animation matrix
|
|
|
|
|
sphrvector key_rotate = <bone rotation>
|
|
|
|
|
|
|
|
|
|
matrix44 m1,m2;
|
|
|
|
|
create_trans_matrix(m1, -bPos.x, -bPos.y, -bPos.z);
|
|
|
|
|
create_trans_matrix(m2, -bPos.x, -bPos.y, -bPos.z);
|
|
|
|
|
|
|
|
|
|
create_rotation_matrix(laM,key_rotate);
|
|
|
|
|
|
|
|
|
|
laM = sm1 * laM;
|
|
|
|
|
laM = laM * sm2;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
*/
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
MDL::IntBone_MDL7* const pcOutBone = apcOutBones[iBone];
|
|
|
|
|
|
|
|
|
|
// store the parent index of the bone
|
|
|
|
|
pcOutBone->iParent = pcBone->parent_index;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (0xffff != iParent) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
const MDL::IntBone_MDL7* pcParentBone = apcOutBones[iParent];
|
|
|
|
|
pcOutBone->mOffsetMatrix.a4 = -pcParentBone->vPosition.x;
|
|
|
|
|
pcOutBone->mOffsetMatrix.b4 = -pcParentBone->vPosition.y;
|
|
|
|
|
pcOutBone->mOffsetMatrix.c4 = -pcParentBone->vPosition.z;
|
|
|
|
|
}
|
|
|
|
|
pcOutBone->vPosition.x = pcBone->x;
|
|
|
|
|
pcOutBone->vPosition.y = pcBone->y;
|
|
|
|
|
pcOutBone->vPosition.z = pcBone->z;
|
|
|
|
|
pcOutBone->mOffsetMatrix.a4 -= pcBone->x;
|
|
|
|
|
pcOutBone->mOffsetMatrix.b4 -= pcBone->y;
|
|
|
|
|
pcOutBone->mOffsetMatrix.c4 -= pcBone->z;
|
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_NOT_THERE == pcHeader->bone_stc_size) {
|
2008-08-09 22:39:57 +00:00
|
|
|
|
// no real name for our poor bone is specified :-(
|
|
|
|
|
pcOutBone->mName.length = ::sprintf(pcOutBone->mName.data,
|
|
|
|
|
"UnnamedBone_%i",iBone);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
|
else {
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Make sure we won't run over the buffer's end if there is no
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// terminal 0 character (however the documentation says there
|
|
|
|
|
// should be one)
|
|
|
|
|
uint32_t iMaxLen = pcHeader->bone_stc_size-16;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
for (uint32_t qq = 0; qq < iMaxLen;++qq) {
|
|
|
|
|
if (!pcBone->name[qq]) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
iMaxLen = qq;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// store the name of the bone
|
|
|
|
|
pcOutBone->mName.length = (size_t)iMaxLen;
|
|
|
|
|
::memcpy(pcOutBone->mName.data,pcBone->name,pcOutBone->mName.length);
|
|
|
|
|
pcOutBone->mName.data[pcOutBone->mName.length] = '\0';
|
2008-06-03 21:50:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
++iParent;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-06-03 21:50:53 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// read bones from a MDL7 file
|
2008-06-22 10:09:26 +00:00
|
|
|
|
MDL::IntBone_MDL7** MDLImporter::LoadBones_3DGS_MDL7()
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2008-11-02 22:21:07 +00:00
|
|
|
|
const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7*)this->mBuffer;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (pcHeader->bones_num) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// validate the size of the bone data structure in the file
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_20_CHARS != pcHeader->bone_stc_size &&
|
|
|
|
|
AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_32_CHARS != pcHeader->bone_stc_size &&
|
2008-06-22 10:09:26 +00:00
|
|
|
|
AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_NOT_THERE != pcHeader->bone_stc_size)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2008-06-22 10:09:26 +00:00
|
|
|
|
DefaultLogger::get()->warn("Unknown size of bone data structure");
|
|
|
|
|
return NULL;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
MDL::IntBone_MDL7** apcBonesOut = new MDL::IntBone_MDL7*[pcHeader->bones_num];
|
|
|
|
|
for (uint32_t crank = 0; crank < pcHeader->bones_num;++crank)
|
|
|
|
|
apcBonesOut[crank] = new MDL::IntBone_MDL7();
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// and calculate absolute bone offset matrices ...
|
2009-01-20 21:41:17 +00:00
|
|
|
|
CalcAbsBoneMatrices_3DGS_MDL7(apcBonesOut);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
return apcBonesOut;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// read faces from a MDL7 file
|
2009-03-15 00:40:30 +00:00
|
|
|
|
void MDLImporter::ReadFaces_3DGS_MDL7(const MDL::IntGroupInfo_MDL7& groupInfo,
|
2008-06-22 10:09:26 +00:00
|
|
|
|
MDL::IntGroupData_MDL7& groupData)
|
|
|
|
|
{
|
2008-11-02 22:21:07 +00:00
|
|
|
|
const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7*)this->mBuffer;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
BE_NCONST MDL::Triangle_MDL7* pcGroupTris = groupInfo.pcGroupTris;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// iterate through all triangles and build valid display lists
|
2009-03-15 00:40:30 +00:00
|
|
|
|
unsigned int iOutIndex = 0;
|
|
|
|
|
for (unsigned int iTriangle = 0; iTriangle < (unsigned int)groupInfo.pcGroup->numtris; ++iTriangle) {
|
|
|
|
|
AI_SWAP2(pcGroupTris->v_index[0]);
|
|
|
|
|
AI_SWAP2(pcGroupTris->v_index[1]);
|
|
|
|
|
AI_SWAP2(pcGroupTris->v_index[2]);
|
|
|
|
|
|
|
|
|
|
// iterate through all indices of the current triangle
|
|
|
|
|
for (unsigned int c = 0; c < 3;++c,++iOutIndex) {
|
|
|
|
|
|
|
|
|
|
// validate the vertex index
|
|
|
|
|
unsigned int iIndex = pcGroupTris->v_index[c];
|
|
|
|
|
if(iIndex > (unsigned int)groupInfo.pcGroup->numverts) {
|
|
|
|
|
// (we might need to read this section a second time - to process frame vertices correctly)
|
|
|
|
|
const_cast<MDL::Triangle_MDL7*>(pcGroupTris)->v_index[c] = iIndex = groupInfo.pcGroup->numverts-1;
|
|
|
|
|
DefaultLogger::get()->warn("Index overflow in MDL7 vertex list");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// write the output face index
|
|
|
|
|
groupData.pcFaces[iTriangle].mIndices[2-c] = iOutIndex;
|
|
|
|
|
|
|
|
|
|
aiVector3D& vPosition = groupData.vPositions[ iOutIndex ];
|
|
|
|
|
vPosition.x = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex, pcHeader->mainvertex_stc_size) .x;
|
|
|
|
|
vPosition.y = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .y;
|
|
|
|
|
vPosition.z = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .z;
|
|
|
|
|
|
|
|
|
|
// if we have bones, save the index
|
|
|
|
|
if (!groupData.aiBones.empty()) {
|
|
|
|
|
groupData.aiBones[iOutIndex] = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,
|
|
|
|
|
iIndex,pcHeader->mainvertex_stc_size).vertindex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// now read the normal vector
|
|
|
|
|
if (AI_MDL7_FRAMEVERTEX030305_STCSIZE <= pcHeader->mainvertex_stc_size) {
|
|
|
|
|
// read the full normal vector
|
|
|
|
|
aiVector3D& vNormal = groupData.vNormals[ iOutIndex ];
|
|
|
|
|
vNormal.x = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .norm[0];
|
|
|
|
|
AI_SWAP4(vNormal.x);
|
|
|
|
|
vNormal.y = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .norm[1];
|
|
|
|
|
AI_SWAP4(vNormal.y);
|
|
|
|
|
vNormal.z = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .norm[2];
|
|
|
|
|
AI_SWAP4(vNormal.z);
|
|
|
|
|
}
|
|
|
|
|
else if (AI_MDL7_FRAMEVERTEX120503_STCSIZE <= pcHeader->mainvertex_stc_size) {
|
|
|
|
|
// read the normal vector from Quake2's smart table
|
|
|
|
|
aiVector3D& vNormal = groupData.vNormals[ iOutIndex ];
|
|
|
|
|
MD2::LookupNormalIndex(_AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,
|
|
|
|
|
pcHeader->mainvertex_stc_size) .norm162index,vNormal);
|
|
|
|
|
}
|
|
|
|
|
// validate and process the first uv coordinate set
|
|
|
|
|
if (pcHeader->triangle_stc_size >= AI_MDL7_TRIANGLE_STD_SIZE_ONE_UV) {
|
|
|
|
|
|
|
|
|
|
if (groupInfo.pcGroup->num_stpts) {
|
|
|
|
|
AI_SWAP2(pcGroupTris->skinsets[0].st_index[0]);
|
|
|
|
|
AI_SWAP2(pcGroupTris->skinsets[0].st_index[1]);
|
|
|
|
|
AI_SWAP2(pcGroupTris->skinsets[0].st_index[2]);
|
|
|
|
|
|
|
|
|
|
iIndex = pcGroupTris->skinsets[0].st_index[c];
|
|
|
|
|
if(iIndex > (unsigned int)groupInfo.pcGroup->num_stpts) {
|
|
|
|
|
iIndex = groupInfo.pcGroup->num_stpts-1;
|
|
|
|
|
DefaultLogger::get()->warn("Index overflow in MDL7 UV coordinate list (#1)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float u = groupInfo.pcGroupUVs[iIndex].u;
|
|
|
|
|
float v = 1.0f-groupInfo.pcGroupUVs[iIndex].v; // DX to OGL
|
|
|
|
|
|
|
|
|
|
groupData.vTextureCoords1[iOutIndex].x = u;
|
|
|
|
|
groupData.vTextureCoords1[iOutIndex].y = v;
|
|
|
|
|
}
|
|
|
|
|
// assign the material index, but only if it is existing
|
|
|
|
|
if (pcHeader->triangle_stc_size >= AI_MDL7_TRIANGLE_STD_SIZE_ONE_UV_WITH_MATINDEX){
|
|
|
|
|
AI_SWAP4(pcGroupTris->skinsets[0].material);
|
|
|
|
|
groupData.pcFaces[iTriangle].iMatIndex[0] = pcGroupTris->skinsets[0].material;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// validate and process the second uv coordinate set
|
|
|
|
|
if (pcHeader->triangle_stc_size >= AI_MDL7_TRIANGLE_STD_SIZE_TWO_UV) {
|
|
|
|
|
|
|
|
|
|
if (groupInfo.pcGroup->num_stpts) {
|
|
|
|
|
AI_SWAP2(pcGroupTris->skinsets[1].st_index[0]);
|
|
|
|
|
AI_SWAP2(pcGroupTris->skinsets[1].st_index[1]);
|
|
|
|
|
AI_SWAP2(pcGroupTris->skinsets[1].st_index[2]);
|
|
|
|
|
AI_SWAP4(pcGroupTris->skinsets[1].material);
|
|
|
|
|
|
|
|
|
|
iIndex = pcGroupTris->skinsets[1].st_index[c];
|
|
|
|
|
if(iIndex > (unsigned int)groupInfo.pcGroup->num_stpts) {
|
|
|
|
|
iIndex = groupInfo.pcGroup->num_stpts-1;
|
|
|
|
|
DefaultLogger::get()->warn("Index overflow in MDL7 UV coordinate list (#2)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float u = groupInfo.pcGroupUVs[ iIndex ].u;
|
|
|
|
|
float v = 1.0f-groupInfo.pcGroupUVs[ iIndex ].v;
|
|
|
|
|
|
|
|
|
|
groupData.vTextureCoords2[ iOutIndex ].x = u;
|
|
|
|
|
groupData.vTextureCoords2[ iOutIndex ].y = v; // DX to OGL
|
|
|
|
|
|
|
|
|
|
// check whether we do really need the second texture
|
|
|
|
|
// coordinate set ... wastes memory and loading time
|
|
|
|
|
if (0 != iIndex && (u != groupData.vTextureCoords1[ iOutIndex ].x ||
|
|
|
|
|
v != groupData.vTextureCoords1[ iOutIndex ].y ) )
|
|
|
|
|
groupData.bNeed2UV = true;
|
|
|
|
|
|
|
|
|
|
// if the material differs, we need a second skin, too
|
|
|
|
|
if (pcGroupTris->skinsets[ 1 ].material != pcGroupTris->skinsets[ 0 ].material)
|
|
|
|
|
groupData.bNeed2UV = true;
|
|
|
|
|
}
|
|
|
|
|
// assign the material index
|
|
|
|
|
groupData.pcFaces[ iTriangle ].iMatIndex[ 1 ] = pcGroupTris->skinsets[ 1 ].material;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// get the next triangle in the list
|
|
|
|
|
pcGroupTris = (BE_NCONST MDL::Triangle_MDL7*)((const char*)pcGroupTris + pcHeader->triangle_stc_size);
|
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// handle frames in a MDL7 file
|
2008-06-22 10:09:26 +00:00
|
|
|
|
bool MDLImporter::ProcessFrames_3DGS_MDL7(const MDL::IntGroupInfo_MDL7& groupInfo,
|
2009-01-20 21:41:17 +00:00
|
|
|
|
MDL::IntGroupData_MDL7& groupData,
|
2008-06-22 10:09:26 +00:00
|
|
|
|
MDL::IntSharedData_MDL7& shared,
|
2009-01-20 21:41:17 +00:00
|
|
|
|
const unsigned char* szCurrent,
|
|
|
|
|
const unsigned char** szCurrentOut)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
|
|
|
|
ai_assert(NULL != szCurrent && NULL != szCurrentOut);
|
2009-01-20 21:41:17 +00:00
|
|
|
|
const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7*)mBuffer;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// if we have no bones we can simply skip all frames,
|
|
|
|
|
// otherwise we'll need to process them.
|
2008-08-06 23:01:38 +00:00
|
|
|
|
// FIX: If we need another frame than the first we must apply frame vertex replacements ...
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for(unsigned int iFrame = 0; iFrame < (unsigned int)groupInfo.pcGroup->numframes;++iFrame) {
|
2008-11-02 22:21:07 +00:00
|
|
|
|
MDL::IntFrameInfo_MDL7 frame ((BE_NCONST MDL::Frame_MDL7*)szCurrent,iFrame);
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
|
|
|
|
AI_SWAP4(frame.pcFrame->vertices_count);
|
|
|
|
|
AI_SWAP4(frame.pcFrame->transmatrix_count);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
const unsigned int iAdd = pcHeader->frame_stc_size +
|
|
|
|
|
frame.pcFrame->vertices_count * pcHeader->framevertex_stc_size +
|
|
|
|
|
frame.pcFrame->transmatrix_count * pcHeader->bonetrans_stc_size;
|
|
|
|
|
|
2009-01-20 21:41:17 +00:00
|
|
|
|
if (((const char*)szCurrent - (const char*)pcHeader) + iAdd > (unsigned int)pcHeader->data_size) {
|
2008-08-06 23:01:38 +00:00
|
|
|
|
DefaultLogger::get()->warn("Index overflow in frame area. "
|
|
|
|
|
"Ignoring all frames and all further mesh groups, too.");
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// don't parse more groups if we can't even read one
|
|
|
|
|
// FIXME: sometimes this seems to occur even for valid files ...
|
|
|
|
|
*szCurrentOut = szCurrent;
|
|
|
|
|
return false;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2008-08-06 23:01:38 +00:00
|
|
|
|
// our output frame?
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (configFrameID == iFrame) {
|
2008-11-02 22:21:07 +00:00
|
|
|
|
BE_NCONST MDL::Vertex_MDL7* pcFrameVertices = (BE_NCONST MDL::Vertex_MDL7*)(szCurrent+pcHeader->frame_stc_size);
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int qq = 0; qq < frame.pcFrame->vertices_count;++qq) {
|
|
|
|
|
// I assume this are simple replacements for normal vertices, the bone index serving
|
|
|
|
|
// as the index of the vertex to be replaced.
|
|
|
|
|
uint16_t iIndex = _AI_MDL7_ACCESS(pcFrameVertices,qq,pcHeader->framevertex_stc_size,MDL::Vertex_MDL7).vertindex;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
AI_SWAP2(iIndex);
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (iIndex >= groupInfo.pcGroup->numverts) {
|
2008-08-09 22:39:57 +00:00
|
|
|
|
DefaultLogger::get()->warn("Invalid vertex index in frame vertex section");
|
2008-08-06 23:01:38 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aiVector3D vPosition,vNormal;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
|
vPosition.x = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .x;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
AI_SWAP4(vPosition.x);
|
2009-03-15 00:40:30 +00:00
|
|
|
|
vPosition.y = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .y;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
AI_SWAP4(vPosition.y);
|
|
|
|
|
vPosition.z = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .z;
|
|
|
|
|
AI_SWAP4(vPosition.z);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
|
// now read the normal vector
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (AI_MDL7_FRAMEVERTEX030305_STCSIZE <= pcHeader->mainvertex_stc_size) {
|
2008-08-06 23:01:38 +00:00
|
|
|
|
// read the full normal vector
|
|
|
|
|
vNormal.x = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .norm[0];
|
2009-01-20 21:41:17 +00:00
|
|
|
|
AI_SWAP4(vNormal.x);
|
2009-03-15 00:40:30 +00:00
|
|
|
|
vNormal.y = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .norm[1];
|
2009-01-20 21:41:17 +00:00
|
|
|
|
AI_SWAP4(vNormal.y);
|
|
|
|
|
vNormal.z = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .norm[2];
|
|
|
|
|
AI_SWAP4(vNormal.z);
|
2008-08-06 23:01:38 +00:00
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
|
else if (AI_MDL7_FRAMEVERTEX120503_STCSIZE <= pcHeader->mainvertex_stc_size) {
|
2008-08-06 23:01:38 +00:00
|
|
|
|
// read the normal vector from Quake2's smart table
|
|
|
|
|
MD2::LookupNormalIndex(_AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,
|
|
|
|
|
pcHeader->framevertex_stc_size) .norm162index,vNormal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FIXME: O(n^2) at the moment ...
|
2008-11-02 22:21:07 +00:00
|
|
|
|
BE_NCONST MDL::Triangle_MDL7* pcGroupTris = groupInfo.pcGroupTris;
|
2008-08-06 23:01:38 +00:00
|
|
|
|
unsigned int iOutIndex = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int iTriangle = 0; iTriangle < (unsigned int)groupInfo.pcGroup->numtris; ++iTriangle) {
|
2008-08-06 23:01:38 +00:00
|
|
|
|
// iterate through all indices of the current triangle
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int c = 0; c < 3;++c,++iOutIndex) {
|
2008-08-06 23:01:38 +00:00
|
|
|
|
// replace the vertex with the new data
|
|
|
|
|
const unsigned int iCurIndex = pcGroupTris->v_index[c];
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (iCurIndex == iIndex) {
|
2008-08-06 23:01:38 +00:00
|
|
|
|
groupData.vPositions[iOutIndex] = vPosition;
|
|
|
|
|
groupData.vNormals[iOutIndex] = vNormal;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// get the next triangle in the list
|
2008-11-02 22:21:07 +00:00
|
|
|
|
pcGroupTris = (BE_NCONST MDL::Triangle_MDL7*)((const char*)
|
2008-08-09 22:39:57 +00:00
|
|
|
|
pcGroupTris + pcHeader->triangle_stc_size);
|
2008-08-06 23:01:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// parse bone trafo matrix keys (only if there are bones ...)
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (shared.apcOutBones) {
|
|
|
|
|
ParseBoneTrafoKeys_3DGS_MDL7(groupInfo,frame,shared);
|
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
szCurrent += iAdd;
|
|
|
|
|
}
|
|
|
|
|
*szCurrentOut = szCurrent;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Sort faces by material, handle multiple UVs correctly
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::SortByMaterials_3DGS_MDL7(
|
2009-01-20 21:41:17 +00:00
|
|
|
|
const MDL::IntGroupInfo_MDL7& groupInfo,
|
|
|
|
|
MDL::IntGroupData_MDL7& groupData,
|
2008-06-22 10:09:26 +00:00
|
|
|
|
MDL::IntSplittedGroupData_MDL7& splittedGroupData)
|
|
|
|
|
{
|
|
|
|
|
const unsigned int iNumMaterials = (unsigned int)splittedGroupData.shared.pcMats.size();
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (!groupData.bNeed2UV) {
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// if we don't need a second set of texture coordinates there is no reason to keep it in memory ...
|
2008-06-22 10:09:26 +00:00
|
|
|
|
groupData.vTextureCoords2.clear();
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// allocate the array
|
|
|
|
|
splittedGroupData.aiSplit = new std::vector<unsigned int>*[iNumMaterials];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
for (unsigned int m = 0; m < iNumMaterials;++m)
|
|
|
|
|
splittedGroupData.aiSplit[m] = new std::vector<unsigned int>();
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// iterate through all faces and sort by material
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int iFace = 0; iFace < (unsigned int)groupInfo.pcGroup->numtris;++iFace) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// check range
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (groupData.pcFaces[iFace].iMatIndex[0] >= iNumMaterials) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// use the last material instead
|
|
|
|
|
splittedGroupData.aiSplit[iNumMaterials-1]->push_back(iFace);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// sometimes MED writes -1, but normally only if there is only
|
|
|
|
|
// one skin assigned. No warning in this case
|
|
|
|
|
if(0xFFFFFFFF != groupData.pcFaces[iFace].iMatIndex[0])
|
|
|
|
|
DefaultLogger::get()->warn("Index overflow in MDL7 material list [#0]");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
else splittedGroupData.aiSplit[groupData.pcFaces[iFace].
|
|
|
|
|
iMatIndex[0]]->push_back(iFace);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// we need to build combined materials for each combination of
|
|
|
|
|
std::vector<MDL::IntMaterial_MDL7> avMats;
|
|
|
|
|
avMats.reserve(iNumMaterials*2);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// fixme: why on the heap?
|
|
|
|
|
std::vector<std::vector<unsigned int>* > aiTempSplit(iNumMaterials*2);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
for (unsigned int m = 0; m < iNumMaterials;++m)
|
|
|
|
|
aiTempSplit[m] = new std::vector<unsigned int>();
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// iterate through all faces and sort by material
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int iFace = 0; iFace < (unsigned int)groupInfo.pcGroup->numtris;++iFace) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// check range
|
|
|
|
|
unsigned int iMatIndex = groupData.pcFaces[iFace].iMatIndex[0];
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (iMatIndex >= iNumMaterials) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// sometimes MED writes -1, but normally only if there is only
|
|
|
|
|
// one skin assigned. No warning in this case
|
|
|
|
|
if(0xffffffff != iMatIndex)
|
|
|
|
|
DefaultLogger::get()->warn("Index overflow in MDL7 material list [#1]");
|
|
|
|
|
iMatIndex = iNumMaterials-1;
|
|
|
|
|
}
|
|
|
|
|
unsigned int iMatIndex2 = groupData.pcFaces[iFace].iMatIndex[1];
|
2008-05-13 23:26:52 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
unsigned int iNum = iMatIndex;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (0xffffffff != iMatIndex2 && iMatIndex != iMatIndex2) {
|
|
|
|
|
if (iMatIndex2 >= iNumMaterials) {
|
2008-05-13 23:26:52 +00:00
|
|
|
|
// sometimes MED writes -1, but normally only if there is only
|
|
|
|
|
// one skin assigned. No warning in this case
|
2008-06-22 10:09:26 +00:00
|
|
|
|
DefaultLogger::get()->warn("Index overflow in MDL7 material list [#2]");
|
|
|
|
|
iMatIndex2 = iNumMaterials-1;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// do a slow seach in the list ...
|
|
|
|
|
iNum = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
bool bFound = false;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (std::vector<MDL::IntMaterial_MDL7>::iterator i = avMats.begin();i != avMats.end();++i,++iNum){
|
|
|
|
|
if ((*i).iOldMatIndices[0] == iMatIndex && (*i).iOldMatIndices[1] == iMatIndex2) {
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// reuse this material
|
|
|
|
|
bFound = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (!bFound) {
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// build a new material ...
|
|
|
|
|
MDL::IntMaterial_MDL7 sHelper;
|
|
|
|
|
sHelper.pcMat = new MaterialHelper();
|
|
|
|
|
sHelper.iOldMatIndices[0] = iMatIndex;
|
|
|
|
|
sHelper.iOldMatIndices[1] = iMatIndex2;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
JoinSkins_3DGS_MDL7(splittedGroupData.shared.pcMats[iMatIndex],
|
2008-06-22 10:09:26 +00:00
|
|
|
|
splittedGroupData.shared.pcMats[iMatIndex2],sHelper.pcMat);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// and add it to the list
|
|
|
|
|
avMats.push_back(sHelper);
|
2008-06-01 12:46:17 +00:00
|
|
|
|
iNum = (unsigned int)avMats.size()-1;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
// adjust the size of the file array
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (iNum == aiTempSplit.size()) {
|
2008-05-09 17:24:28 +00:00
|
|
|
|
aiTempSplit.push_back(new std::vector<unsigned int>());
|
2009-03-15 00:40:30 +00:00
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
aiTempSplit[iNum]->push_back(iFace);
|
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// now add the newly created materials to the old list
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (0 == groupInfo.iIndex) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
splittedGroupData.shared.pcMats.resize(avMats.size());
|
|
|
|
|
for (unsigned int o = 0; o < avMats.size();++o)
|
|
|
|
|
splittedGroupData.shared.pcMats[o] = avMats[o].pcMat;
|
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
|
else {
|
|
|
|
|
// This might result in redundant materials ...
|
2008-06-22 10:09:26 +00:00
|
|
|
|
splittedGroupData.shared.pcMats.resize(iNumMaterials + avMats.size());
|
|
|
|
|
for (unsigned int o = iNumMaterials; o < avMats.size();++o)
|
|
|
|
|
splittedGroupData.shared.pcMats[o] = avMats[o].pcMat;
|
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// and build the final face-to-material array
|
|
|
|
|
splittedGroupData.aiSplit = new std::vector<unsigned int>*[aiTempSplit.size()];
|
|
|
|
|
for (unsigned int m = 0; m < iNumMaterials;++m)
|
|
|
|
|
splittedGroupData.aiSplit[m] = aiTempSplit[m];
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Read a MDL7 file
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::InternReadFile_3DGS_MDL7( )
|
|
|
|
|
{
|
|
|
|
|
ai_assert(NULL != pScene);
|
|
|
|
|
|
|
|
|
|
MDL::IntSharedData_MDL7 sharedData;
|
|
|
|
|
|
|
|
|
|
// current cursor position in the file
|
2008-11-02 22:21:07 +00:00
|
|
|
|
BE_NCONST MDL::Header_MDL7 *pcHeader = (BE_NCONST MDL::Header_MDL7*)this->mBuffer;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
const unsigned char* szCurrent = (const unsigned char*)(pcHeader+1);
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
|
|
|
|
AI_SWAP4(pcHeader->version);
|
|
|
|
|
AI_SWAP4(pcHeader->bones_num);
|
|
|
|
|
AI_SWAP4(pcHeader->groups_num);
|
|
|
|
|
AI_SWAP4(pcHeader->data_size);
|
|
|
|
|
AI_SWAP4(pcHeader->entlump_size);
|
|
|
|
|
AI_SWAP4(pcHeader->medlump_size);
|
|
|
|
|
AI_SWAP2(pcHeader->bone_stc_size);
|
|
|
|
|
AI_SWAP2(pcHeader->skin_stc_size);
|
|
|
|
|
AI_SWAP2(pcHeader->colorvalue_stc_size);
|
|
|
|
|
AI_SWAP2(pcHeader->material_stc_size);
|
|
|
|
|
AI_SWAP2(pcHeader->skinpoint_stc_size);
|
|
|
|
|
AI_SWAP2(pcHeader->triangle_stc_size);
|
|
|
|
|
AI_SWAP2(pcHeader->mainvertex_stc_size);
|
|
|
|
|
AI_SWAP2(pcHeader->framevertex_stc_size);
|
|
|
|
|
AI_SWAP2(pcHeader->bonetrans_stc_size);
|
|
|
|
|
AI_SWAP2(pcHeader->frame_stc_size);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// validate the header of the file. There are some structure
|
|
|
|
|
// sizes that are expected by the loader to be constant
|
|
|
|
|
this->ValidateHeader_3DGS_MDL7(pcHeader);
|
|
|
|
|
|
|
|
|
|
// load all bones (they are shared by all groups, so
|
|
|
|
|
// we'll need to add them to all groups/meshes later)
|
|
|
|
|
// apcBonesOut is a list of all bones or NULL if they could not been loaded
|
|
|
|
|
szCurrent += pcHeader->bones_num * pcHeader->bone_stc_size;
|
|
|
|
|
sharedData.apcOutBones = this->LoadBones_3DGS_MDL7();
|
|
|
|
|
|
|
|
|
|
// vector to held all created meshes
|
|
|
|
|
std::vector<aiMesh*>* avOutList;
|
|
|
|
|
|
|
|
|
|
// 3 meshes per group - that should be OK for most models
|
|
|
|
|
avOutList = new std::vector<aiMesh*>[pcHeader->groups_num];
|
|
|
|
|
for (uint32_t i = 0; i < pcHeader->groups_num;++i)
|
|
|
|
|
avOutList[i].reserve(3);
|
|
|
|
|
|
|
|
|
|
// buffer to held the names of all groups in the file
|
|
|
|
|
char* aszGroupNameBuffer = new char[AI_MDL7_MAX_GROUPNAMESIZE*pcHeader->groups_num];
|
|
|
|
|
|
|
|
|
|
// read all groups
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int iGroup = 0; iGroup < (unsigned int)pcHeader->groups_num;++iGroup) {
|
2008-11-02 22:21:07 +00:00
|
|
|
|
MDL::IntGroupInfo_MDL7 groupInfo((BE_NCONST MDL::Group_MDL7*)szCurrent,iGroup);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
szCurrent = (const unsigned char*)(groupInfo.pcGroup+1);
|
|
|
|
|
|
|
|
|
|
VALIDATE_FILE_SIZE(szCurrent);
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
|
|
|
|
AI_SWAP4(groupInfo.pcGroup->groupdata_size);
|
|
|
|
|
AI_SWAP4(groupInfo.pcGroup->numskins);
|
|
|
|
|
AI_SWAP4(groupInfo.pcGroup->num_stpts);
|
|
|
|
|
AI_SWAP4(groupInfo.pcGroup->numtris);
|
|
|
|
|
AI_SWAP4(groupInfo.pcGroup->numverts);
|
|
|
|
|
AI_SWAP4(groupInfo.pcGroup->numframes);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (1 != groupInfo.pcGroup->typ) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// Not a triangle-based mesh
|
2009-01-20 21:41:17 +00:00
|
|
|
|
DefaultLogger::get()->warn("[3DGS MDL7] Not a triangle mesh group. Continuing happily");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// store the name of the group
|
2008-08-06 23:01:38 +00:00
|
|
|
|
const unsigned int ofs = iGroup*AI_MDL7_MAX_GROUPNAMESIZE;
|
|
|
|
|
::memcpy(&aszGroupNameBuffer[ofs],
|
2008-06-22 10:09:26 +00:00
|
|
|
|
groupInfo.pcGroup->name,AI_MDL7_MAX_GROUPNAMESIZE);
|
|
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
|
// make sure '\0' is at the end
|
|
|
|
|
aszGroupNameBuffer[ofs+AI_MDL7_MAX_GROUPNAMESIZE-1] = '\0';
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// read all skins
|
|
|
|
|
sharedData.pcMats.reserve(sharedData.pcMats.size() + groupInfo.pcGroup->numskins);
|
|
|
|
|
sharedData.abNeedMaterials.resize(sharedData.abNeedMaterials.size() +
|
|
|
|
|
groupInfo.pcGroup->numskins,false);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int iSkin = 0; iSkin < (unsigned int)groupInfo.pcGroup->numskins;++iSkin) {
|
|
|
|
|
ParseSkinLump_3DGS_MDL7(szCurrent,&szCurrent,sharedData.pcMats);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// if we have absolutely no skin loaded we need to generate a default material
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (sharedData.pcMats.empty()) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
const int iMode = (int)aiShadingMode_Gouraud;
|
|
|
|
|
sharedData.pcMats.push_back(new MaterialHelper());
|
|
|
|
|
MaterialHelper* pcHelper = (MaterialHelper*)sharedData.pcMats[0];
|
|
|
|
|
pcHelper->AddProperty<int>(&iMode, 1, AI_MATKEY_SHADING_MODEL);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +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);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
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);
|
2008-08-06 23:01:38 +00:00
|
|
|
|
|
|
|
|
|
sharedData.abNeedMaterials.resize(1,false);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// now get a pointer to all texture coords in the group
|
2008-11-02 22:21:07 +00:00
|
|
|
|
groupInfo.pcGroupUVs = (BE_NCONST MDL::TexCoord_MDL7*)szCurrent;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
for(int i = 0; i < groupInfo.pcGroup->num_stpts; ++i){
|
|
|
|
|
AI_SWAP4(groupInfo.pcGroupUVs[i].u);
|
|
|
|
|
AI_SWAP4(groupInfo.pcGroupUVs[i].v);
|
|
|
|
|
}
|
|
|
|
|
szCurrent += pcHeader->skinpoint_stc_size * groupInfo.pcGroup->num_stpts;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// now get a pointer to all triangle in the group
|
2008-11-02 22:21:07 +00:00
|
|
|
|
groupInfo.pcGroupTris = (BE_NCONST MDL::Triangle_MDL7*)szCurrent;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
szCurrent += pcHeader->triangle_stc_size * groupInfo.pcGroup->numtris;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// now get a pointer to all vertices in the group
|
2008-11-02 22:21:07 +00:00
|
|
|
|
groupInfo.pcGroupVerts = (BE_NCONST MDL::Vertex_MDL7*)szCurrent;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
for(int i = 0; i < groupInfo.pcGroup->numverts; ++i){
|
|
|
|
|
AI_SWAP4(groupInfo.pcGroupVerts[i].x);
|
|
|
|
|
AI_SWAP4(groupInfo.pcGroupVerts[i].y);
|
|
|
|
|
AI_SWAP4(groupInfo.pcGroupVerts[i].z);
|
|
|
|
|
|
|
|
|
|
AI_SWAP2(groupInfo.pcGroupVerts[i].vertindex);
|
|
|
|
|
//We can not swap the normal information now as we don't know which of the two kinds it is
|
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
szCurrent += pcHeader->mainvertex_stc_size * groupInfo.pcGroup->numverts;
|
|
|
|
|
VALIDATE_FILE_SIZE(szCurrent);
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
|
|
|
|
MDL::IntSplittedGroupData_MDL7 splittedGroupData(sharedData,avOutList[iGroup]);
|
2008-08-06 23:01:38 +00:00
|
|
|
|
MDL::IntGroupData_MDL7 groupData;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
if (groupInfo.pcGroup->numtris && groupInfo.pcGroup->numverts)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// build output vectors
|
|
|
|
|
const unsigned int iNumVertices = groupInfo.pcGroup->numtris*3;
|
|
|
|
|
groupData.vPositions.resize(iNumVertices);
|
|
|
|
|
groupData.vNormals.resize(iNumVertices);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
if (sharedData.apcOutBones)groupData.aiBones.resize(iNumVertices,0xffffffff);
|
|
|
|
|
|
|
|
|
|
// it is also possible that there are 0 UV coordinate sets
|
2009-01-20 21:41:17 +00:00
|
|
|
|
if (groupInfo.pcGroup->num_stpts){
|
2008-06-22 10:09:26 +00:00
|
|
|
|
groupData.vTextureCoords1.resize(iNumVertices,aiVector3D());
|
|
|
|
|
|
|
|
|
|
// check whether the triangle data structure is large enough
|
|
|
|
|
// to contain a second UV coodinate set
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (pcHeader->triangle_stc_size >= AI_MDL7_TRIANGLE_STD_SIZE_TWO_UV) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
groupData.vTextureCoords2.resize(iNumVertices,aiVector3D());
|
|
|
|
|
groupData.bNeed2UV = true;
|
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
groupData.pcFaces = new MDL::IntFace_MDL7[groupInfo.pcGroup->numtris];
|
|
|
|
|
|
|
|
|
|
// read all faces into the preallocated arrays
|
2009-01-20 21:41:17 +00:00
|
|
|
|
ReadFaces_3DGS_MDL7(groupInfo, groupData);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// sort by materials
|
2009-01-20 21:41:17 +00:00
|
|
|
|
SortByMaterials_3DGS_MDL7(groupInfo, groupData,
|
2008-06-22 10:09:26 +00:00
|
|
|
|
splittedGroupData);
|
|
|
|
|
|
2009-01-20 21:41:17 +00:00
|
|
|
|
for (unsigned int qq = 0; qq < sharedData.pcMats.size();++qq) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
if (!splittedGroupData.aiSplit[qq]->empty())
|
|
|
|
|
sharedData.abNeedMaterials[qq] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else DefaultLogger::get()->warn("[3DGS MDL7] Mesh group consists of 0 "
|
|
|
|
|
"vertices or faces. It will be skipped.");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-08-09 22:39:57 +00:00
|
|
|
|
// process all frames and generate output meshes
|
2009-01-20 21:41:17 +00:00
|
|
|
|
ProcessFrames_3DGS_MDL7(groupInfo,groupData, sharedData,szCurrent,&szCurrent);
|
|
|
|
|
GenerateOutputMeshes_3DGS_MDL7(groupData,splittedGroupData);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// generate a nodegraph and subnodes for each group
|
2009-01-20 21:41:17 +00:00
|
|
|
|
pScene->mRootNode = new aiNode();
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// now we need to build a final mesh list
|
2008-06-22 10:09:26 +00:00
|
|
|
|
for (uint32_t i = 0; i < pcHeader->groups_num;++i)
|
2009-01-20 21:41:17 +00:00
|
|
|
|
pScene->mNumMeshes += (unsigned int)avOutList[i].size();
|
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes]; {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
unsigned int p = 0,q = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (uint32_t i = 0; i < pcHeader->groups_num;++i) {
|
|
|
|
|
for (unsigned int a = 0; a < avOutList[i].size();++a) {
|
|
|
|
|
pScene->mMeshes[p++] = avOutList[i][a];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
if (!avOutList[i].empty())++pScene->mRootNode->mNumChildren;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
// we will later need an extra node to serve as parent for all bones
|
2009-01-20 21:41:17 +00:00
|
|
|
|
if (sharedData.apcOutBones)++pScene->mRootNode->mNumChildren;
|
|
|
|
|
this->pScene->mRootNode->mChildren = new aiNode*[pScene->mRootNode->mNumChildren];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
p = 0;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
for (uint32_t i = 0; i < pcHeader->groups_num;++i) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
if (avOutList[i].empty())continue;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
|
|
|
|
aiNode* const pcNode = pScene->mRootNode->mChildren[p] = new aiNode();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcNode->mNumMeshes = (unsigned int)avOutList[i].size();
|
|
|
|
|
pcNode->mMeshes = new unsigned int[pcNode->mNumMeshes];
|
|
|
|
|
pcNode->mParent = this->pScene->mRootNode;
|
|
|
|
|
for (unsigned int a = 0; a < pcNode->mNumMeshes;++a)
|
|
|
|
|
pcNode->mMeshes[a] = q + a;
|
|
|
|
|
q += (unsigned int)avOutList[i].size();
|
|
|
|
|
|
|
|
|
|
// setup the name of the node
|
|
|
|
|
char* const szBuffer = &aszGroupNameBuffer[i*AI_MDL7_MAX_GROUPNAMESIZE];
|
2009-01-20 21:41:17 +00:00
|
|
|
|
if ('\0' == *szBuffer)
|
|
|
|
|
pcNode->mName.length = ::sprintf(szBuffer,"Group_%i",p);
|
2008-08-09 22:39:57 +00:00
|
|
|
|
else pcNode->mName.length = ::strlen(szBuffer);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
::strcpy(pcNode->mName.data,szBuffer);
|
|
|
|
|
++p;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// if there is only one root node with a single child we can optimize it a bit ...
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (1 == pScene->mRootNode->mNumChildren && !sharedData.apcOutBones) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
aiNode* pcOldRoot = this->pScene->mRootNode;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
pScene->mRootNode = pcOldRoot->mChildren[0];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcOldRoot->mChildren[0] = NULL;
|
|
|
|
|
delete pcOldRoot;
|
2009-01-20 21:41:17 +00:00
|
|
|
|
pScene->mRootNode->mParent = NULL;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
else pScene->mRootNode->mName.Set("<mesh_root>");
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
delete[] avOutList;
|
|
|
|
|
delete[] aszGroupNameBuffer;
|
2008-08-06 23:01:38 +00:00
|
|
|
|
AI_DEBUG_INVALIDATE_PTR(avOutList);
|
|
|
|
|
AI_DEBUG_INVALIDATE_PTR(aszGroupNameBuffer);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// build a final material list.
|
2009-01-20 21:41:17 +00:00
|
|
|
|
CopyMaterials_3DGS_MDL7(sharedData);
|
|
|
|
|
HandleMaterialReferences_3DGS_MDL7();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// generate output bone animations and add all bones to the scenegraph
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (sharedData.apcOutBones) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// this step adds empty dummy bones to the nodegraph
|
|
|
|
|
// insert another dummy node to avoid name conflicts
|
2009-01-20 21:41:17 +00:00
|
|
|
|
aiNode* const pc = pScene->mRootNode->mChildren[pScene->mRootNode->mNumChildren-1] = new aiNode();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-08-09 22:39:57 +00:00
|
|
|
|
pc->mName.Set("<skeleton_root>");
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// add bones to the nodegraph
|
2009-01-20 21:41:17 +00:00
|
|
|
|
AddBonesToNodeGraph_3DGS_MDL7((const Assimp::MDL::IntBone_MDL7 **)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
sharedData.apcOutBones,pc,0xffff);
|
|
|
|
|
|
|
|
|
|
// this steps build a valid output animation
|
2009-01-20 21:41:17 +00:00
|
|
|
|
BuildOutputAnims_3DGS_MDL7((const Assimp::MDL::IntBone_MDL7 **)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
sharedData.apcOutBones);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-15 00:40:30 +00:00
|
|
|
|
// Copy materials
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::CopyMaterials_3DGS_MDL7(MDL::IntSharedData_MDL7 &shared)
|
|
|
|
|
{
|
2009-01-20 21:41:17 +00:00
|
|
|
|
pScene->mNumMaterials = (unsigned int)shared.pcMats.size();
|
|
|
|
|
pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials];
|
|
|
|
|
for (unsigned int i = 0; i < pScene->mNumMaterials;++i)
|
|
|
|
|
pScene->mMaterials[i] = shared.pcMats[i];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-15 00:40:30 +00:00
|
|
|
|
// Process material references
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::HandleMaterialReferences_3DGS_MDL7()
|
|
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// search for referrer materials
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int i = 0; i < pScene->mNumMaterials;++i) {
|
2008-05-09 17:24:28 +00:00
|
|
|
|
int iIndex = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (AI_SUCCESS == aiGetMaterialInteger(pScene->mMaterials[i],AI_MDL7_REFERRER_MATERIAL, &iIndex) ) {
|
|
|
|
|
for (unsigned int a = 0; a < pScene->mNumMeshes;++a) {
|
2009-01-20 21:41:17 +00:00
|
|
|
|
aiMesh* const pcMesh = pScene->mMeshes[a];
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (i == pcMesh->mMaterialIndex) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcMesh->mMaterialIndex = iIndex;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// collapse the rest of the array
|
2009-01-20 21:41:17 +00:00
|
|
|
|
delete pScene->mMaterials[i];
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int pp = i; pp < pScene->mNumMaterials-1;++pp) {
|
|
|
|
|
|
|
|
|
|
pScene->mMaterials[pp] = pScene->mMaterials[pp+1];
|
|
|
|
|
for (unsigned int a = 0; a < pScene->mNumMeshes;++a) {
|
2009-01-20 21:41:17 +00:00
|
|
|
|
aiMesh* const pcMesh = pScene->mMeshes[a];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
if (pcMesh->mMaterialIndex > i)--pcMesh->mMaterialIndex;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
--pScene->mNumMaterials;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Read bone transformation keys
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::ParseBoneTrafoKeys_3DGS_MDL7(
|
|
|
|
|
const MDL::IntGroupInfo_MDL7& groupInfo,
|
2009-01-20 21:41:17 +00:00
|
|
|
|
IntFrameInfo_MDL7& frame,
|
|
|
|
|
MDL::IntSharedData_MDL7& shared)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
|
|
|
|
const MDL::Header_MDL7* const pcHeader = (const MDL::Header_MDL7*)this->mBuffer;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// only the first group contains bone animation keys
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (frame.pcFrame->transmatrix_count) {
|
|
|
|
|
if (!groupInfo.iIndex) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// skip all frames vertices. We can't support them
|
|
|
|
|
const MDL::BoneTransform_MDL7* pcBoneTransforms = (const MDL::BoneTransform_MDL7*)
|
|
|
|
|
(((const char*)frame.pcFrame) + pcHeader->frame_stc_size +
|
|
|
|
|
frame.pcFrame->vertices_count * pcHeader->framevertex_stc_size);
|
|
|
|
|
|
|
|
|
|
// read all transformation matrices
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int iTrafo = 0; iTrafo < frame.pcFrame->transmatrix_count;++iTrafo) {
|
2009-01-20 21:41:17 +00:00
|
|
|
|
if(pcBoneTransforms->bone_index >= pcHeader->bones_num) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
DefaultLogger::get()->warn("Index overflow in frame area. "
|
|
|
|
|
"Unable to parse this bone transformation");
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
else {
|
|
|
|
|
AddAnimationBoneTrafoKey_3DGS_MDL7(frame.iIndex,
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcBoneTransforms,shared.apcOutBones);
|
|
|
|
|
}
|
|
|
|
|
pcBoneTransforms = (const MDL::BoneTransform_MDL7*)(
|
|
|
|
|
(const char*)pcBoneTransforms + pcHeader->bonetrans_stc_size);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
|
else {
|
|
|
|
|
DefaultLogger::get()->warn("Ignoring animation keyframes in groups != 0");
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Attach bones to the output nodegraph
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::AddBonesToNodeGraph_3DGS_MDL7(const MDL::IntBone_MDL7** apcBones,
|
|
|
|
|
aiNode* pcParent,uint16_t iParentIndex)
|
2008-05-09 17:24:28 +00:00
|
|
|
|
{
|
2008-06-22 10:09:26 +00:00
|
|
|
|
ai_assert(NULL != apcBones && NULL != pcParent);
|
|
|
|
|
|
|
|
|
|
// get a pointer to the header ...
|
|
|
|
|
const MDL::Header_MDL7* const pcHeader = (const MDL::Header_MDL7*)this->mBuffer;
|
2008-05-22 10:20:31 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
const MDL::IntBone_MDL7** apcBones2 = apcBones;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (uint32_t i = 0; i < pcHeader->bones_num;++i) {
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
const MDL::IntBone_MDL7* const pcBone = *apcBones2++;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (pcBone->iParent == iParentIndex) {
|
|
|
|
|
++pcParent->mNumChildren;
|
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
pcParent->mChildren = new aiNode*[pcParent->mNumChildren];
|
|
|
|
|
unsigned int qq = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (uint32_t i = 0; i < pcHeader->bones_num;++i) {
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
const MDL::IntBone_MDL7* const pcBone = *apcBones++;
|
|
|
|
|
if (pcBone->iParent != iParentIndex)continue;
|
|
|
|
|
|
|
|
|
|
aiNode* pcNode = pcParent->mChildren[qq++] = new aiNode();
|
|
|
|
|
pcNode->mName = aiString( pcBone->mName );
|
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
AddBonesToNodeGraph_3DGS_MDL7(apcBones,pcNode,(uint16_t)i);
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Build output animations
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::BuildOutputAnims_3DGS_MDL7(
|
|
|
|
|
const MDL::IntBone_MDL7** apcBonesOut)
|
|
|
|
|
{
|
|
|
|
|
ai_assert(NULL != apcBonesOut);
|
2009-01-20 21:41:17 +00:00
|
|
|
|
const MDL::Header_MDL7* const pcHeader = (const MDL::Header_MDL7*)mBuffer;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// one animation ...
|
|
|
|
|
aiAnimation* pcAnim = new aiAnimation();
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (uint32_t i = 0; i < pcHeader->bones_num;++i) {
|
|
|
|
|
if (!apcBonesOut[i]->pkeyPositions.empty()) {
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// get the last frame ... (needn't be equal to pcHeader->frames_num)
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (size_t qq = 0; qq < apcBonesOut[i]->pkeyPositions.size();++qq) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcAnim->mDuration = std::max(pcAnim->mDuration, (double)
|
|
|
|
|
apcBonesOut[i]->pkeyPositions[qq].mTime);
|
|
|
|
|
}
|
2008-09-30 13:05:48 +00:00
|
|
|
|
++pcAnim->mNumChannels;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (pcAnim->mDuration) {
|
2008-09-30 13:05:48 +00:00
|
|
|
|
pcAnim->mChannels = new aiNodeAnim*[pcAnim->mNumChannels];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
unsigned int iCnt = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (uint32_t i = 0; i < pcHeader->bones_num;++i) {
|
|
|
|
|
if (!apcBonesOut[i]->pkeyPositions.empty()) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
const MDL::IntBone_MDL7* const intBone = apcBonesOut[i];
|
|
|
|
|
|
2008-09-30 13:05:48 +00:00
|
|
|
|
aiNodeAnim* const pcNodeAnim = pcAnim->mChannels[iCnt++] = new aiNodeAnim();
|
|
|
|
|
pcNodeAnim->mNodeName = aiString( intBone->mName );
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-08-09 22:39:57 +00:00
|
|
|
|
// allocate enough storage for all keys
|
2008-09-30 13:05:48 +00:00
|
|
|
|
pcNodeAnim->mNumPositionKeys = (unsigned int)intBone->pkeyPositions.size();
|
|
|
|
|
pcNodeAnim->mNumScalingKeys = (unsigned int)intBone->pkeyPositions.size();
|
|
|
|
|
pcNodeAnim->mNumRotationKeys = (unsigned int)intBone->pkeyPositions.size();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
2008-09-30 13:05:48 +00:00
|
|
|
|
pcNodeAnim->mPositionKeys = new aiVectorKey[pcNodeAnim->mNumPositionKeys];
|
2009-01-20 21:41:17 +00:00
|
|
|
|
pcNodeAnim->mScalingKeys = new aiVectorKey[pcNodeAnim->mNumPositionKeys];
|
2008-09-30 13:05:48 +00:00
|
|
|
|
pcNodeAnim->mRotationKeys = new aiQuatKey[pcNodeAnim->mNumPositionKeys];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// copy all keys
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int qq = 0; qq < pcNodeAnim->mNumPositionKeys;++qq) {
|
2008-09-30 13:05:48 +00:00
|
|
|
|
pcNodeAnim->mPositionKeys[qq] = intBone->pkeyPositions[qq];
|
|
|
|
|
pcNodeAnim->mScalingKeys[qq] = intBone->pkeyScalings[qq];
|
|
|
|
|
pcNodeAnim->mRotationKeys[qq] = intBone->pkeyRotations[qq];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// store the output animation
|
2009-01-20 21:41:17 +00:00
|
|
|
|
pScene->mNumAnimations = 1;
|
|
|
|
|
pScene->mAnimations = new aiAnimation*[1];
|
|
|
|
|
pScene->mAnimations[0] = pcAnim;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
else delete pcAnim;
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
void MDLImporter::AddAnimationBoneTrafoKey_3DGS_MDL7(unsigned int iTrafo,
|
|
|
|
|
const MDL::BoneTransform_MDL7* pcBoneTransforms,
|
|
|
|
|
MDL::IntBone_MDL7** apcBonesOut)
|
|
|
|
|
{
|
|
|
|
|
ai_assert(NULL != pcBoneTransforms);
|
|
|
|
|
ai_assert(NULL != apcBonesOut);
|
|
|
|
|
|
|
|
|
|
// first .. get the transformation matrix
|
|
|
|
|
aiMatrix4x4 mTransform;
|
|
|
|
|
mTransform.a1 = pcBoneTransforms->m[0];
|
|
|
|
|
mTransform.b1 = pcBoneTransforms->m[1];
|
|
|
|
|
mTransform.c1 = pcBoneTransforms->m[2];
|
|
|
|
|
mTransform.d1 = pcBoneTransforms->m[3];
|
|
|
|
|
|
|
|
|
|
mTransform.a2 = pcBoneTransforms->m[4];
|
|
|
|
|
mTransform.b2 = pcBoneTransforms->m[5];
|
|
|
|
|
mTransform.c2 = pcBoneTransforms->m[6];
|
|
|
|
|
mTransform.d2 = pcBoneTransforms->m[7];
|
|
|
|
|
|
|
|
|
|
mTransform.a3 = pcBoneTransforms->m[8];
|
|
|
|
|
mTransform.b3 = pcBoneTransforms->m[9];
|
|
|
|
|
mTransform.c3 = pcBoneTransforms->m[10];
|
|
|
|
|
mTransform.d3 = pcBoneTransforms->m[11];
|
|
|
|
|
|
|
|
|
|
// now decompose the transformation matrix into separate
|
|
|
|
|
// scaling, rotation and translation
|
|
|
|
|
aiVectorKey vScaling,vPosition;
|
|
|
|
|
aiQuatKey qRotation;
|
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
// FIXME: Decompose will assert in debug builds if the matrix is invalid ...
|
2008-06-22 10:09:26 +00:00
|
|
|
|
mTransform.Decompose(vScaling.mValue,qRotation.mValue,vPosition.mValue);
|
|
|
|
|
|
|
|
|
|
// now generate keys
|
|
|
|
|
vScaling.mTime = qRotation.mTime = vPosition.mTime = (double)iTrafo;
|
|
|
|
|
|
|
|
|
|
// add the keys to the bone
|
|
|
|
|
MDL::IntBone_MDL7* const pcBoneOut = apcBonesOut[pcBoneTransforms->bone_index];
|
|
|
|
|
pcBoneOut->pkeyPositions.push_back ( vPosition );
|
|
|
|
|
pcBoneOut->pkeyScalings.push_back ( vScaling );
|
|
|
|
|
pcBoneOut->pkeyRotations.push_back ( qRotation );
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Construct output meshes
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::GenerateOutputMeshes_3DGS_MDL7(
|
|
|
|
|
MDL::IntGroupData_MDL7& groupData,
|
|
|
|
|
MDL::IntSplittedGroupData_MDL7& splittedGroupData)
|
|
|
|
|
{
|
|
|
|
|
const MDL::IntSharedData_MDL7& shared = splittedGroupData.shared;
|
|
|
|
|
|
|
|
|
|
// get a pointer to the header ...
|
|
|
|
|
const MDL::Header_MDL7* const pcHeader = (const MDL::Header_MDL7*)this->mBuffer;
|
|
|
|
|
const unsigned int iNumOutBones = pcHeader->bones_num;
|
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (std::vector<MaterialHelper*>::size_type i = 0; i < shared.pcMats.size();++i) {
|
|
|
|
|
if (!splittedGroupData.aiSplit[i]->empty()) {
|
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// allocate the output mesh
|
|
|
|
|
aiMesh* pcMesh = new aiMesh();
|
2008-09-30 20:20:56 +00:00
|
|
|
|
|
|
|
|
|
pcMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcMesh->mMaterialIndex = (unsigned int)i;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// allocate output storage
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcMesh->mNumFaces = (unsigned int)splittedGroupData.aiSplit[i]->size();
|
2008-05-09 17:24:28 +00:00
|
|
|
|
pcMesh->mFaces = new aiFace[pcMesh->mNumFaces];
|
|
|
|
|
|
|
|
|
|
pcMesh->mNumVertices = pcMesh->mNumFaces*3;
|
|
|
|
|
pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices];
|
|
|
|
|
pcMesh->mNormals = new aiVector3D[pcMesh->mNumVertices];
|
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (!groupData.vTextureCoords1.empty()) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcMesh->mNumUVComponents[0] = 2;
|
|
|
|
|
pcMesh->mTextureCoords[0] = new aiVector3D[pcMesh->mNumVertices];
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (!groupData.vTextureCoords2.empty()) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcMesh->mNumUVComponents[1] = 2;
|
|
|
|
|
pcMesh->mTextureCoords[1] = new aiVector3D[pcMesh->mNumVertices];
|
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// iterate through all faces and build an unique set of vertices
|
|
|
|
|
unsigned int iCurrent = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int iFace = 0; iFace < pcMesh->mNumFaces;++iFace) {
|
2008-05-09 17:24:28 +00:00
|
|
|
|
pcMesh->mFaces[iFace].mNumIndices = 3;
|
|
|
|
|
pcMesh->mFaces[iFace].mIndices = new unsigned int[3];
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
unsigned int iSrcFace = splittedGroupData.aiSplit[i]->operator[](iFace);
|
|
|
|
|
const MDL::IntFace_MDL7& oldFace = groupData.pcFaces[iSrcFace];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// iterate through all face indices
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int c = 0; c < 3;++c) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
const uint32_t iIndex = oldFace.mIndices[c];
|
|
|
|
|
pcMesh->mVertices[iCurrent] = groupData.vPositions[iIndex];
|
|
|
|
|
pcMesh->mNormals[iCurrent] = groupData.vNormals[iIndex];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (!groupData.vTextureCoords1.empty()) {
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcMesh->mTextureCoords[0][iCurrent] = groupData.vTextureCoords1[iIndex];
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (!groupData.vTextureCoords2.empty()) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcMesh->mTextureCoords[1][iCurrent] = groupData.vTextureCoords2[iIndex];
|
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcMesh->mFaces[iFace].mIndices[c] = iCurrent++;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-22 10:09:26 +00:00
|
|
|
|
// if we have bones in the mesh we'll need to generate
|
|
|
|
|
// proper vertex weights for them
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (!groupData.aiBones.empty()) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
std::vector<std::vector<unsigned int> > aaiVWeightList;
|
|
|
|
|
aaiVWeightList.resize(iNumOutBones);
|
|
|
|
|
|
|
|
|
|
int iCurrent = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int iFace = 0; iFace < pcMesh->mNumFaces;++iFace) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
unsigned int iSrcFace = splittedGroupData.aiSplit[i]->operator[](iFace);
|
|
|
|
|
const MDL::IntFace_MDL7& oldFace = groupData.pcFaces[iSrcFace];
|
|
|
|
|
|
|
|
|
|
// iterate through all face indices
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int c = 0; c < 3;++c) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
unsigned int iBone = groupData.aiBones[ oldFace.mIndices[c] ];
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if (0xffffffff != iBone) {
|
|
|
|
|
if (iBone >= iNumOutBones) {
|
2008-06-22 10:09:26 +00:00
|
|
|
|
DefaultLogger::get()->error("Bone index overflow. "
|
|
|
|
|
"The bone index of a vertex exceeds the allowed range. ");
|
|
|
|
|
iBone = iNumOutBones-1;
|
|
|
|
|
}
|
|
|
|
|
aaiVWeightList[ iBone ].push_back ( iCurrent );
|
|
|
|
|
}
|
|
|
|
|
++iCurrent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// now check which bones are required ...
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (std::vector<std::vector<unsigned int> >::const_iterator k = aaiVWeightList.begin();k != aaiVWeightList.end();++k) {
|
|
|
|
|
if (!(*k).empty()) {
|
|
|
|
|
++pcMesh->mNumBones;
|
|
|
|
|
}
|
2008-06-22 10:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
pcMesh->mBones = new aiBone*[pcMesh->mNumBones];
|
|
|
|
|
iCurrent = 0;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (std::vector<std::vector<unsigned int> >::const_iterator k = aaiVWeightList.begin();k!= aaiVWeightList.end();++k,++iCurrent)
|
2008-06-22 10:09:26 +00:00
|
|
|
|
{
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if ((*k).empty())
|
|
|
|
|
continue;
|
2008-06-22 10:09:26 +00:00
|
|
|
|
|
|
|
|
|
// seems we'll need this node
|
|
|
|
|
aiBone* pcBone = pcMesh->mBones[ iCurrent ] = new aiBone();
|
|
|
|
|
pcBone->mName = aiString(shared.apcOutBones[ iCurrent ]->mName);
|
|
|
|
|
pcBone->mOffsetMatrix = shared.apcOutBones[ iCurrent ]->mOffsetMatrix;
|
|
|
|
|
|
|
|
|
|
// setup vertex weights
|
2009-03-15 00:40:30 +00:00
|
|
|
|
pcBone->mNumWeights = (unsigned int)(*k).size();
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcBone->mWeights = new aiVertexWeight[pcBone->mNumWeights];
|
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
|
for (unsigned int weight = 0; weight < pcBone->mNumWeights;++weight) {
|
|
|
|
|
pcBone->mWeights[weight].mVertexId = (*k)[weight];
|
2008-06-22 10:09:26 +00:00
|
|
|
|
pcBone->mWeights[weight].mWeight = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// add the mesh to the list of output meshes
|
2008-06-22 10:09:26 +00:00
|
|
|
|
splittedGroupData.avOutList.push_back(pcMesh);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Join to materials
|
2008-06-22 10:09:26 +00:00
|
|
|
|
void MDLImporter::JoinSkins_3DGS_MDL7(
|
2008-05-09 17:24:28 +00:00
|
|
|
|
MaterialHelper* pcMat1,
|
|
|
|
|
MaterialHelper* pcMat2,
|
|
|
|
|
MaterialHelper* pcMatOut)
|
|
|
|
|
{
|
2008-06-22 10:09:26 +00:00
|
|
|
|
ai_assert(NULL != pcMat1 && NULL != pcMat2 && NULL != pcMatOut);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
|
|
// first create a full copy of the first skin property set
|
|
|
|
|
// and assign it to the output material
|
|
|
|
|
MaterialHelper::CopyPropertyList(pcMatOut,pcMat1);
|
|
|
|
|
|
|
|
|
|
int iVal = 0;
|
|
|
|
|
pcMatOut->AddProperty<int>(&iVal,1,AI_MATKEY_UVWSRC_DIFFUSE(0));
|
|
|
|
|
|
|
|
|
|
// then extract the diffuse texture from the second skin,
|
|
|
|
|
// setup 1 as UV source and we have it
|
|
|
|
|
aiString sString;
|
2009-03-15 00:40:30 +00:00
|
|
|
|
if(AI_SUCCESS == aiGetMaterialString ( pcMat2, AI_MATKEY_TEXTURE_DIFFUSE(0),&sString )) {
|
2008-05-09 17:24:28 +00:00
|
|
|
|
iVal = 1;
|
|
|
|
|
pcMatOut->AddProperty<int>(&iVal,1,AI_MATKEY_UVWSRC_DIFFUSE(1));
|
|
|
|
|
pcMatOut->AddProperty(&sString,AI_MATKEY_TEXTURE_DIFFUSE(1));
|
|
|
|
|
}
|
2008-05-22 10:20:31 +00:00
|
|
|
|
}
|
2009-01-20 21:41:17 +00:00
|
|
|
|
|
2008-05-22 10:20:31 +00:00
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-20 21:41:17 +00:00
|
|
|
|
// Read a half-life 2 MDL
|
2008-05-22 10:20:31 +00:00
|
|
|
|
void MDLImporter::InternReadFile_HL2( )
|
|
|
|
|
{
|
2008-09-12 20:25:11 +00:00
|
|
|
|
//const MDL::Header_HL2* pcHeader = (const MDL::Header_HL2*)this->mBuffer;
|
2010-04-05 19:50:25 +00:00
|
|
|
|
throw DeadlyImportError("HL2 MDLs are not implemented");
|
2008-09-12 20:25:11 +00:00
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
|
|
|
|
|
#endif // !! ASSIMP_BUILD_NO_MDL_IMPORTER
|