2008-08-06 23:01:38 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (ASSIMP)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2010-04-10 15:30:22 +00:00
|
|
|
Copyright (c) 2006-2010, ASSIMP Development Team
|
2008-08-06 23:01:38 +00:00
|
|
|
|
|
|
|
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-03-08 15:29:34 +00:00
|
|
|
/** @file MD5Parser.cpp
|
|
|
|
* @brief Implementation of the MD5 parser class
|
|
|
|
*/
|
2008-10-13 16:45:48 +00:00
|
|
|
#include "AssimpPCH.h"
|
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// internal headers
|
|
|
|
#include "MD5Loader.h"
|
|
|
|
#include "MaterialSystem.h"
|
|
|
|
#include "fast_atof.h"
|
|
|
|
#include "ParsingUtils.h"
|
|
|
|
#include "StringComparison.h"
|
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
using namespace Assimp::MD5;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-08 15:29:34 +00:00
|
|
|
// Parse the segment structure fo a MD5 file
|
2009-10-26 18:41:58 +00:00
|
|
|
MD5Parser::MD5Parser(char* _buffer, unsigned int _fileSize )
|
2008-08-06 23:01:38 +00:00
|
|
|
{
|
2009-03-08 15:29:34 +00:00
|
|
|
ai_assert(NULL != _buffer && 0 != _fileSize);
|
2008-08-06 23:01:38 +00:00
|
|
|
|
2009-03-08 15:29:34 +00:00
|
|
|
buffer = _buffer;
|
2009-10-22 08:08:04 +00:00
|
|
|
fileSize = _fileSize;
|
2009-03-08 15:29:34 +00:00
|
|
|
lineNumber = 0;
|
2008-08-06 23:01:38 +00:00
|
|
|
|
|
|
|
DefaultLogger::get()->debug("MD5Parser begin");
|
|
|
|
|
|
|
|
// parse the file header
|
2009-03-08 15:29:34 +00:00
|
|
|
ParseHeader();
|
2008-08-06 23:01:38 +00:00
|
|
|
|
|
|
|
// and read all sections until we're finished
|
2009-10-11 11:31:49 +00:00
|
|
|
bool running = true;
|
|
|
|
while (running) {
|
2009-03-08 15:29:34 +00:00
|
|
|
mSections.push_back(Section());
|
|
|
|
Section& sec = mSections.back();
|
|
|
|
if(!ParseSection(sec)) {
|
2008-08-06 23:01:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-08 15:29:34 +00:00
|
|
|
if ( !DefaultLogger::isNullLogger()) {
|
2008-08-06 23:01:38 +00:00
|
|
|
char szBuffer[128]; // should be sufficiently large
|
2009-03-08 15:29:34 +00:00
|
|
|
::sprintf(szBuffer,"MD5Parser end. Parsed %i sections",(int)mSections.size());
|
2008-08-06 23:01:38 +00:00
|
|
|
DefaultLogger::get()->debug(szBuffer);
|
|
|
|
}
|
|
|
|
}
|
2009-03-08 15:29:34 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-08 15:29:34 +00:00
|
|
|
// Report error to the log stream
|
2008-09-13 09:01:24 +00:00
|
|
|
/*static*/ void MD5Parser::ReportError (const char* error, unsigned int line)
|
2008-08-06 23:01:38 +00:00
|
|
|
{
|
2009-03-08 15:29:34 +00:00
|
|
|
char szBuffer[1024];
|
|
|
|
::sprintf(szBuffer,"[MD5] Line %i: %s",line,error);
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError(szBuffer);
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
2009-03-08 15:29:34 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-08 15:29:34 +00:00
|
|
|
// Report warning to the log stream
|
2008-09-13 09:01:24 +00:00
|
|
|
/*static*/ void MD5Parser::ReportWarning (const char* warn, unsigned int line)
|
2008-08-06 23:01:38 +00:00
|
|
|
{
|
2009-03-08 15:29:34 +00:00
|
|
|
char szBuffer[1024];
|
|
|
|
::sprintf(szBuffer,"[MD5] Line %i: %s",line,warn);
|
2008-08-06 23:01:38 +00:00
|
|
|
DefaultLogger::get()->warn(szBuffer);
|
|
|
|
}
|
2009-03-08 15:29:34 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-08 15:29:34 +00:00
|
|
|
// Parse and validate the MD5 header
|
2008-08-06 23:01:38 +00:00
|
|
|
void MD5Parser::ParseHeader()
|
|
|
|
{
|
|
|
|
// parse and validate the file version
|
|
|
|
SkipSpaces();
|
2009-03-08 15:29:34 +00:00
|
|
|
if (!TokenMatch(buffer,"MD5Version",10)) {
|
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
|
|
|
ReportError("Invalid MD5 file: MD5Version tag has not been found");
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
|
|
|
SkipSpaces();
|
2011-03-23 14:26:19 +00:00
|
|
|
unsigned int iVer = ::strtoul10(buffer,(const char**)&buffer);
|
2009-03-08 15:29:34 +00:00
|
|
|
if (10 != iVer) {
|
2009-04-09 21:37:49 +00:00
|
|
|
ReportError("MD5 version tag is unknown (10 is expected)");
|
2008-08-06 23:01:38 +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
|
|
|
SkipLine();
|
2008-08-06 23:01:38 +00:00
|
|
|
|
|
|
|
// print the command line options to the console
|
2009-03-08 15:29:34 +00:00
|
|
|
// FIX: can break the log length limit, so we need to be careful
|
2008-08-06 23:01:38 +00:00
|
|
|
char* sz = buffer;
|
|
|
|
while (!IsLineEnd( *buffer++));
|
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
|
|
|
DefaultLogger::get()->info(std::string(sz,std::min((uintptr_t)MAX_LOG_MESSAGE_LENGTH, (uintptr_t)(buffer-sz))));
|
|
|
|
SkipSpacesAndLineEnd();
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
2009-03-08 15:29:34 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-08 15:29:34 +00:00
|
|
|
// Recursive MD5 parsing function
|
2008-08-06 23:01:38 +00:00
|
|
|
bool MD5Parser::ParseSection(Section& out)
|
|
|
|
{
|
|
|
|
// store the current line number for use in error messages
|
2009-03-08 15:29:34 +00:00
|
|
|
out.iLineNumber = lineNumber;
|
2008-08-06 23:01:38 +00:00
|
|
|
|
|
|
|
// first parse the name of the section
|
|
|
|
char* sz = buffer;
|
|
|
|
while (!IsSpaceOrNewLine( *buffer))buffer++;
|
|
|
|
out.mName = std::string(sz,(uintptr_t)(buffer-sz));
|
|
|
|
SkipSpaces();
|
|
|
|
|
2009-10-11 11:31:49 +00:00
|
|
|
bool running = true;
|
|
|
|
while (running) {
|
2009-03-08 15:29:34 +00:00
|
|
|
if ('{' == *buffer) {
|
2008-08-06 23:01:38 +00:00
|
|
|
// it is a normal section so read all lines
|
|
|
|
buffer++;
|
2009-10-11 11:31:49 +00:00
|
|
|
bool run = true;
|
|
|
|
while (run)
|
2008-08-06 23:01:38 +00:00
|
|
|
{
|
2009-03-08 15:29:34 +00:00
|
|
|
if (!SkipSpacesAndLineEnd()) {
|
2008-08-06 23:01:38 +00:00
|
|
|
return false; // seems this was the last section
|
|
|
|
}
|
2009-03-08 15:29:34 +00:00
|
|
|
if ('}' == *buffer) {
|
2008-08-06 23:01:38 +00:00
|
|
|
buffer++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out.mElements.push_back(Element());
|
|
|
|
Element& elem = out.mElements.back();
|
|
|
|
|
|
|
|
elem.iLineNumber = lineNumber;
|
|
|
|
elem.szStart = buffer;
|
|
|
|
|
2009-03-08 20:12:43 +00:00
|
|
|
// terminate the line with zero
|
2008-08-06 23:01:38 +00:00
|
|
|
while (!IsLineEnd( *buffer))buffer++;
|
2009-03-08 20:12:43 +00:00
|
|
|
if (*buffer) {
|
|
|
|
++lineNumber;
|
|
|
|
*buffer++ = '\0';
|
|
|
|
}
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-03-08 15:29:34 +00:00
|
|
|
else if (!IsSpaceOrNewLine(*buffer)) {
|
2008-08-06 23:01:38 +00:00
|
|
|
// it is an element at global scope. Parse its value and go on
|
|
|
|
sz = buffer;
|
|
|
|
while (!IsSpaceOrNewLine( *buffer++));
|
|
|
|
out.mGlobalValue = std::string(sz,(uintptr_t)(buffer-sz));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return SkipSpacesAndLineEnd();
|
|
|
|
}
|
2009-03-08 15:29:34 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-08 15:29:34 +00:00
|
|
|
// Some dirty macros just because they're so funny and easy to debug
|
2008-08-06 23:01:38 +00:00
|
|
|
|
|
|
|
// skip all spaces ... handle EOL correctly
|
|
|
|
#define AI_MD5_SKIP_SPACES() if(!SkipSpaces(&sz)) \
|
|
|
|
MD5Parser::ReportWarning("Unexpected end of line",(*eit).iLineNumber);
|
|
|
|
|
|
|
|
// read a triple float in brackets: (1.0 1.0 1.0)
|
|
|
|
#define AI_MD5_READ_TRIPLE(vec) \
|
|
|
|
AI_MD5_SKIP_SPACES(); \
|
|
|
|
if ('(' != *sz++) \
|
|
|
|
MD5Parser::ReportWarning("Unexpected token: ( was expected",(*eit).iLineNumber); \
|
|
|
|
AI_MD5_SKIP_SPACES(); \
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)vec.x); \
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES(); \
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)vec.y); \
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES(); \
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)vec.z); \
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES(); \
|
|
|
|
if (')' != *sz++) \
|
|
|
|
MD5Parser::ReportWarning("Unexpected token: ) was expected",(*eit).iLineNumber);
|
|
|
|
|
|
|
|
// parse a string, enclosed in quotation marks or not
|
|
|
|
#define AI_MD5_PARSE_STRING(out) \
|
2009-03-08 20:12:43 +00:00
|
|
|
bool bQuota = (*sz == '\"'); \
|
2008-08-06 23:01:38 +00:00
|
|
|
const char* szStart = sz; \
|
|
|
|
while (!IsSpaceOrNewLine(*sz))++sz; \
|
|
|
|
const char* szEnd = sz; \
|
2009-03-08 20:12:43 +00:00
|
|
|
if (bQuota) { \
|
2008-08-06 23:01:38 +00:00
|
|
|
szStart++; \
|
2009-03-08 20:12:43 +00:00
|
|
|
if ('\"' != *(szEnd-=1)) { \
|
2008-08-06 23:01:38 +00:00
|
|
|
MD5Parser::ReportWarning("Expected closing quotation marks in string", \
|
|
|
|
(*eit).iLineNumber); \
|
2009-03-08 20:12:43 +00:00
|
|
|
continue; \
|
2008-08-06 23:01:38 +00:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
out.length = (size_t)(szEnd - szStart); \
|
|
|
|
::memcpy(out.data,szStart,out.length); \
|
|
|
|
out.data[out.length] = '\0';
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-08 15:29:34 +00:00
|
|
|
// .MD5MESH parsing function
|
2008-08-06 23:01:38 +00:00
|
|
|
MD5MeshParser::MD5MeshParser(SectionList& mSections)
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->debug("MD5MeshParser begin");
|
|
|
|
|
|
|
|
// now parse all sections
|
2009-03-08 15:29:34 +00:00
|
|
|
for (SectionList::const_iterator iter = mSections.begin(), iterEnd = mSections.end();iter != iterEnd;++iter){
|
2009-03-08 20:12:43 +00:00
|
|
|
if ( (*iter).mName == "numMeshes") {
|
2011-03-23 14:26:19 +00:00
|
|
|
mMeshes.reserve(::strtoul10((*iter).mGlobalValue.c_str()));
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
2009-03-08 20:12:43 +00:00
|
|
|
else if ( (*iter).mName == "numJoints") {
|
2011-03-23 14:26:19 +00:00
|
|
|
mJoints.reserve(::strtoul10((*iter).mGlobalValue.c_str()));
|
2009-03-08 20:12:43 +00:00
|
|
|
}
|
|
|
|
else if ((*iter).mName == "joints") {
|
2008-08-06 23:01:38 +00:00
|
|
|
// "origin" -1 ( -0.000000 0.016430 -0.006044 ) ( 0.707107 0.000000 0.707107 )
|
2009-03-08 15:29:34 +00:00
|
|
|
for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end();eit != eitEnd; ++eit){
|
2008-08-06 23:01:38 +00:00
|
|
|
mJoints.push_back(BoneDesc());
|
|
|
|
BoneDesc& desc = mJoints.back();
|
|
|
|
|
|
|
|
const char* sz = (*eit).szStart;
|
|
|
|
AI_MD5_PARSE_STRING(desc.mName);
|
|
|
|
AI_MD5_SKIP_SPACES();
|
|
|
|
|
2009-03-08 20:12:43 +00:00
|
|
|
// negative values, at least -1, is allowed here
|
2011-03-23 14:26:19 +00:00
|
|
|
desc.mParentIndex = (int)strtol10(sz,&sz);
|
2009-03-08 20:12:43 +00:00
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_READ_TRIPLE(desc.mPositionXYZ);
|
|
|
|
AI_MD5_READ_TRIPLE(desc.mRotationQuat); // normalized quaternion, so w is not there
|
|
|
|
}
|
|
|
|
}
|
2009-03-08 20:12:43 +00:00
|
|
|
else if ((*iter).mName == "mesh") {
|
2008-08-06 23:01:38 +00:00
|
|
|
mMeshes.push_back(MeshDesc());
|
|
|
|
MeshDesc& desc = mMeshes.back();
|
|
|
|
|
2009-03-08 15:29:34 +00:00
|
|
|
for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end();eit != eitEnd; ++eit){
|
2008-08-06 23:01:38 +00:00
|
|
|
const char* sz = (*eit).szStart;
|
|
|
|
|
|
|
|
// shader attribute
|
2009-03-08 20:12:43 +00:00
|
|
|
if (TokenMatch(sz,"shader",6)) {
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES();
|
|
|
|
AI_MD5_PARSE_STRING(desc.mShader);
|
|
|
|
}
|
|
|
|
// numverts attribute
|
2009-03-08 20:12:43 +00:00
|
|
|
else if (TokenMatch(sz,"numverts",8)) {
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES();
|
2011-03-23 14:26:19 +00:00
|
|
|
desc.mVertices.resize(strtoul10(sz));
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
|
|
|
// numtris attribute
|
2009-03-08 20:12:43 +00:00
|
|
|
else if (TokenMatch(sz,"numtris",7)) {
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES();
|
2011-03-23 14:26:19 +00:00
|
|
|
desc.mFaces.resize(strtoul10(sz));
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
|
|
|
// numweights attribute
|
2009-03-08 20:12:43 +00:00
|
|
|
else if (TokenMatch(sz,"numweights",10)) {
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES();
|
2011-03-23 14:26:19 +00:00
|
|
|
desc.mWeights.resize(strtoul10(sz));
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
|
|
|
// vert attribute
|
|
|
|
// "vert 0 ( 0.394531 0.513672 ) 0 1"
|
2009-03-08 20:12:43 +00:00
|
|
|
else if (TokenMatch(sz,"vert",4)) {
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES();
|
2011-03-23 14:26:19 +00:00
|
|
|
const unsigned int idx = ::strtoul10(sz,&sz);
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES();
|
|
|
|
if (idx >= desc.mVertices.size())
|
|
|
|
desc.mVertices.resize(idx+1);
|
|
|
|
|
|
|
|
VertexDesc& vert = desc.mVertices[idx];
|
|
|
|
if ('(' != *sz++)
|
|
|
|
MD5Parser::ReportWarning("Unexpected token: ( was expected",(*eit).iLineNumber);
|
|
|
|
AI_MD5_SKIP_SPACES();
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)vert.mUV.x);
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES();
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,(float&)vert.mUV.y);
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES();
|
|
|
|
if (')' != *sz++)
|
|
|
|
MD5Parser::ReportWarning("Unexpected token: ) was expected",(*eit).iLineNumber);
|
|
|
|
AI_MD5_SKIP_SPACES();
|
2011-03-23 14:26:19 +00:00
|
|
|
vert.mFirstWeight = ::strtoul10(sz,&sz);
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES();
|
2011-03-23 14:26:19 +00:00
|
|
|
vert.mNumWeights = ::strtoul10(sz,&sz);
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
|
|
|
// tri attribute
|
|
|
|
// "tri 0 15 13 12"
|
2009-03-08 15:29:34 +00:00
|
|
|
else if (TokenMatch(sz,"tri",3)) {
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES();
|
2011-03-23 14:26:19 +00:00
|
|
|
const unsigned int idx = strtoul10(sz,&sz);
|
2008-08-06 23:01:38 +00:00
|
|
|
if (idx >= desc.mFaces.size())
|
|
|
|
desc.mFaces.resize(idx+1);
|
|
|
|
|
|
|
|
aiFace& face = desc.mFaces[idx];
|
|
|
|
face.mIndices = new unsigned int[face.mNumIndices = 3];
|
2009-03-08 20:12:43 +00:00
|
|
|
for (unsigned int i = 0; i < 3;++i) {
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES();
|
2011-03-23 14:26:19 +00:00
|
|
|
face.mIndices[i] = strtoul10(sz,&sz);
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// weight attribute
|
|
|
|
// "weight 362 5 0.500000 ( -3.553583 11.893474 9.719339 )"
|
2009-03-08 20:12:43 +00:00
|
|
|
else if (TokenMatch(sz,"weight",6)) {
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES();
|
2011-03-23 14:26:19 +00:00
|
|
|
const unsigned int idx = strtoul10(sz,&sz);
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES();
|
|
|
|
if (idx >= desc.mWeights.size())
|
|
|
|
desc.mWeights.resize(idx+1);
|
|
|
|
|
|
|
|
WeightDesc& weight = desc.mWeights[idx];
|
2011-03-23 14:26:19 +00:00
|
|
|
weight.mBone = strtoul10(sz,&sz);
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_SKIP_SPACES();
|
2012-01-31 16:18:32 +00:00
|
|
|
sz = fast_atoreal_move<float>(sz,weight.mWeight);
|
2008-08-06 23:01:38 +00:00
|
|
|
AI_MD5_READ_TRIPLE(weight.vOffsetPosition);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DefaultLogger::get()->debug("MD5MeshParser end");
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-03-08 15:29:34 +00:00
|
|
|
// .MD5ANIM parsing function
|
2008-08-06 23:01:38 +00:00
|
|
|
MD5AnimParser::MD5AnimParser(SectionList& mSections)
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->debug("MD5AnimParser begin");
|
|
|
|
|
|
|
|
fFrameRate = 24.0f;
|
2011-04-22 21:29:18 +00:00
|
|
|
mNumAnimatedComponents = UINT_MAX;
|
2009-03-08 15:29:34 +00:00
|
|
|
for (SectionList::const_iterator iter = mSections.begin(), iterEnd = mSections.end();iter != iterEnd;++iter) {
|
|
|
|
if ((*iter).mName == "hierarchy") {
|
2008-08-06 23:01:38 +00:00
|
|
|
// "sheath" 0 63 6
|
2009-03-08 15:29:34 +00:00
|
|
|
for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end();eit != eitEnd; ++eit) {
|
2008-08-06 23:01:38 +00:00
|
|
|
mAnimatedBones.push_back ( AnimBoneDesc () );
|
|
|
|
AnimBoneDesc& desc = mAnimatedBones.back();
|
|
|
|
|
|
|
|
const char* sz = (*eit).szStart;
|
|
|
|
AI_MD5_PARSE_STRING(desc.mName);
|
|
|
|
AI_MD5_SKIP_SPACES();
|
|
|
|
|
2009-03-08 15:29:34 +00:00
|
|
|
// parent index - negative values are allowed (at least -1)
|
2011-03-23 14:26:19 +00:00
|
|
|
desc.mParentIndex = ::strtol10(sz,&sz);
|
2008-08-06 23:01:38 +00:00
|
|
|
|
|
|
|
// flags (highest is 2^6-1)
|
|
|
|
AI_MD5_SKIP_SPACES();
|
2011-03-23 14:26:19 +00:00
|
|
|
if(63 < (desc.iFlags = ::strtoul10(sz,&sz))){
|
2009-03-08 15:29:34 +00:00
|
|
|
MD5Parser::ReportWarning("Invalid flag combination in hierarchy section",(*eit).iLineNumber);
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
|
|
|
AI_MD5_SKIP_SPACES();
|
|
|
|
|
|
|
|
// index of the first animation keyframe component for this joint
|
2011-03-23 14:26:19 +00:00
|
|
|
desc.iFirstKeyIndex = ::strtoul10(sz,&sz);
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-08 15:29:34 +00:00
|
|
|
else if((*iter).mName == "baseframe") {
|
2008-08-06 23:01:38 +00:00
|
|
|
// ( -0.000000 0.016430 -0.006044 ) ( 0.707107 0.000242 0.707107 )
|
2009-03-08 15:29:34 +00:00
|
|
|
for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end(); eit != eitEnd; ++eit) {
|
2008-08-06 23:01:38 +00:00
|
|
|
const char* sz = (*eit).szStart;
|
|
|
|
|
|
|
|
mBaseFrames.push_back ( BaseFrameDesc () );
|
|
|
|
BaseFrameDesc& desc = mBaseFrames.back();
|
|
|
|
|
|
|
|
AI_MD5_READ_TRIPLE(desc.vPositionXYZ);
|
|
|
|
AI_MD5_READ_TRIPLE(desc.vRotationQuat);
|
|
|
|
}
|
|
|
|
}
|
2009-03-08 15:29:34 +00:00
|
|
|
else if((*iter).mName == "frame") {
|
2009-03-08 20:12:43 +00:00
|
|
|
if (!(*iter).mGlobalValue.length()) {
|
2009-03-08 15:29:34 +00:00
|
|
|
MD5Parser::ReportWarning("A frame section must have a frame index",(*iter).iLineNumber);
|
2008-08-06 23:01:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFrames.push_back ( FrameDesc () );
|
|
|
|
FrameDesc& desc = mFrames.back();
|
2011-03-23 14:26:19 +00:00
|
|
|
desc.iIndex = strtoul10((*iter).mGlobalValue.c_str());
|
2008-08-06 23:01:38 +00:00
|
|
|
|
|
|
|
// we do already know how much storage we will presumably need
|
2011-04-22 21:29:18 +00:00
|
|
|
if (UINT_MAX != mNumAnimatedComponents) {
|
2008-08-06 23:01:38 +00:00
|
|
|
desc.mValues.reserve(mNumAnimatedComponents);
|
2011-04-22 21:29:18 +00:00
|
|
|
}
|
2008-08-06 23:01:38 +00:00
|
|
|
|
2009-03-08 15:29:34 +00:00
|
|
|
// now read all elements (continous list of floats)
|
|
|
|
for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end(); eit != eitEnd; ++eit){
|
2008-08-06 23:01:38 +00:00
|
|
|
const char* sz = (*eit).szStart;
|
2009-03-08 15:29:34 +00:00
|
|
|
while (SkipSpacesAndLineEnd(&sz)) {
|
2012-01-31 16:18:32 +00:00
|
|
|
float f;sz = fast_atoreal_move<float>(sz,f);
|
2008-08-06 23:01:38 +00:00
|
|
|
desc.mValues.push_back(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-08 15:29:34 +00:00
|
|
|
else if((*iter).mName == "numFrames") {
|
2011-03-23 14:26:19 +00:00
|
|
|
mFrames.reserve(strtoul10((*iter).mGlobalValue.c_str()));
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
2009-03-08 15:29:34 +00:00
|
|
|
else if((*iter).mName == "numJoints") {
|
2011-03-23 14:26:19 +00:00
|
|
|
const unsigned int num = strtoul10((*iter).mGlobalValue.c_str());
|
2009-03-08 15:29:34 +00:00
|
|
|
mAnimatedBones.reserve(num);
|
2008-08-06 23:01:38 +00:00
|
|
|
|
2009-03-08 15:29:34 +00:00
|
|
|
// try to guess the number of animated components if that element is not given
|
2011-04-22 21:29:18 +00:00
|
|
|
if (UINT_MAX == mNumAnimatedComponents) {
|
2009-03-08 15:29:34 +00:00
|
|
|
mNumAnimatedComponents = num * 6;
|
2011-04-22 21:29:18 +00:00
|
|
|
}
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
2009-03-08 15:29:34 +00:00
|
|
|
else if((*iter).mName == "numAnimatedComponents") {
|
2011-03-23 14:26:19 +00:00
|
|
|
mAnimatedBones.reserve( strtoul10((*iter).mGlobalValue.c_str()));
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
2009-03-08 15:29:34 +00:00
|
|
|
else if((*iter).mName == "frameRate") {
|
2012-01-31 16:18:32 +00:00
|
|
|
fast_atoreal_move<float>((*iter).mGlobalValue.c_str(),fFrameRate);
|
2008-08-06 23:01:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
DefaultLogger::get()->debug("MD5AnimParser end");
|
|
|
|
}
|
|
|
|
|
2009-03-08 15:29:34 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// .MD5CAMERA parsing function
|
|
|
|
MD5CameraParser::MD5CameraParser(SectionList& mSections)
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->debug("MD5CameraParser begin");
|
|
|
|
fFrameRate = 24.0f;
|
|
|
|
|
2009-03-08 20:12:43 +00:00
|
|
|
for (SectionList::const_iterator iter = mSections.begin(), iterEnd = mSections.end();iter != iterEnd;++iter) {
|
|
|
|
if ((*iter).mName == "numFrames") {
|
2011-03-23 14:26:19 +00:00
|
|
|
frames.reserve(strtoul10((*iter).mGlobalValue.c_str()));
|
2009-03-08 20:12:43 +00:00
|
|
|
}
|
|
|
|
else if ((*iter).mName == "frameRate") {
|
|
|
|
fFrameRate = fast_atof ((*iter).mGlobalValue.c_str());
|
|
|
|
}
|
|
|
|
else if ((*iter).mName == "numCuts") {
|
2011-03-23 14:26:19 +00:00
|
|
|
cuts.reserve(strtoul10((*iter).mGlobalValue.c_str()));
|
2009-03-08 20:12:43 +00:00
|
|
|
}
|
|
|
|
else if ((*iter).mName == "cuts") {
|
|
|
|
for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end(); eit != eitEnd; ++eit){
|
2011-03-23 14:26:19 +00:00
|
|
|
cuts.push_back(strtoul10((*eit).szStart)+1);
|
2009-03-08 20:12:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((*iter).mName == "camera") {
|
|
|
|
for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end(); eit != eitEnd; ++eit){
|
|
|
|
const char* sz = (*eit).szStart;
|
|
|
|
|
|
|
|
frames.push_back(CameraAnimFrameDesc());
|
|
|
|
CameraAnimFrameDesc& cur = frames.back();
|
|
|
|
AI_MD5_READ_TRIPLE(cur.vPositionXYZ);
|
|
|
|
AI_MD5_READ_TRIPLE(cur.vRotationQuat);
|
|
|
|
AI_MD5_SKIP_SPACES();
|
|
|
|
cur.fFOV = fast_atof(sz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-08 15:29:34 +00:00
|
|
|
DefaultLogger::get()->debug("MD5CameraParser end");
|
|
|
|
}
|
|
|
|
|