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.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file Implementation of the ASE parser class */
|
|
|
|
|
2008-07-10 16:49:01 +00:00
|
|
|
// internal headers
|
2008-06-01 12:46:17 +00:00
|
|
|
#include "TextureTransform.h"
|
2008-05-09 17:24:28 +00:00
|
|
|
#include "ASELoader.h"
|
|
|
|
#include "MaterialSystem.h"
|
|
|
|
#include "fast_atof.h"
|
|
|
|
|
2008-07-10 16:49:01 +00:00
|
|
|
// public ASSIMP headers
|
|
|
|
#include "../include/DefaultLogger.h"
|
2008-05-09 17:24:28 +00:00
|
|
|
#include "../include/IOStream.h"
|
|
|
|
#include "../include/IOSystem.h"
|
|
|
|
#include "../include/aiMesh.h"
|
|
|
|
#include "../include/aiScene.h"
|
|
|
|
#include "../include/aiAssert.h"
|
|
|
|
|
2008-07-10 16:49:01 +00:00
|
|
|
// boost headers
|
2008-05-09 17:24:28 +00:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
using namespace Assimp::ASE;
|
|
|
|
|
|
|
|
#if (defined BLUBB)
|
|
|
|
# undef BLUBB
|
|
|
|
#endif
|
|
|
|
#define BLUBB(_message_) \
|
|
|
|
{this->LogError(_message_);return;}
|
|
|
|
|
2008-07-18 20:29:46 +00:00
|
|
|
|
|
|
|
#define AI_ASE_HANDLE_TOP_LEVEL_SECTION(iDepth) \
|
|
|
|
else if ('{' == *this->m_szFile)iDepth++; \
|
|
|
|
else if ('}' == *this->m_szFile) \
|
|
|
|
{ \
|
|
|
|
if (0 == --iDepth) \
|
|
|
|
{ \
|
|
|
|
++this->m_szFile; \
|
|
|
|
this->SkipToNextToken(); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
else if ('\0' == *this->m_szFile) \
|
|
|
|
{ \
|
|
|
|
return; \
|
|
|
|
} \
|
2008-07-30 23:00:25 +00:00
|
|
|
if(IsLineEnd(*this->m_szFile) && !bLastWasEndLine) \
|
|
|
|
{ \
|
|
|
|
++this->iLineNumber; \
|
|
|
|
bLastWasEndLine = true; \
|
|
|
|
} else bLastWasEndLine = false; \
|
2008-07-18 20:29:46 +00:00
|
|
|
++this->m_szFile;
|
|
|
|
|
|
|
|
#define AI_ASE_HANDLE_SECTION(iDepth, level, msg) \
|
|
|
|
else if ('{' == *this->m_szFile)iDepth++; \
|
|
|
|
else if ('}' == *this->m_szFile) \
|
|
|
|
{ \
|
|
|
|
if (0 == --iDepth) \
|
|
|
|
{ \
|
|
|
|
++this->m_szFile; \
|
|
|
|
this->SkipToNextToken(); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
else if ('\0' == *this->m_szFile) \
|
|
|
|
{ \
|
|
|
|
this->LogError("Encountered unexpected EOL while parsing a " msg \
|
|
|
|
" chunk (Level " level ")"); \
|
|
|
|
} \
|
2008-07-30 23:00:25 +00:00
|
|
|
if(IsLineEnd(*this->m_szFile) && !bLastWasEndLine) \
|
|
|
|
{ \
|
|
|
|
++this->iLineNumber; \
|
|
|
|
bLastWasEndLine = true; \
|
|
|
|
} else bLastWasEndLine = false; \
|
2008-07-18 20:29:46 +00:00
|
|
|
++this->m_szFile;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Parser::Parser (const char* szFile)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != szFile);
|
|
|
|
this->m_szFile = szFile;
|
|
|
|
|
|
|
|
// makre sure that the color values are invalid
|
|
|
|
this->m_clrBackground.r = std::numeric_limits<float>::quiet_NaN();
|
|
|
|
this->m_clrAmbient.r = std::numeric_limits<float>::quiet_NaN();
|
|
|
|
|
|
|
|
this->iLineNumber = 0;
|
2008-07-18 20:29:46 +00:00
|
|
|
this->iFirstFrame = 0;
|
|
|
|
this->iLastFrame = 0;
|
|
|
|
this->iFrameSpeed = 30; // use 30 as default value for this property
|
|
|
|
this->iTicksPerFrame = 1; // use 1 as default value for this property
|
2008-07-30 23:00:25 +00:00
|
|
|
this->bLastWasEndLine = false; // need to handle \r\n seqs due to binary file mapping
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::LogWarning(const char* szWarn)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != szWarn);
|
|
|
|
|
|
|
|
char szTemp[1024];
|
2008-06-15 10:27:08 +00:00
|
|
|
#if _MSC_VER >= 1400
|
|
|
|
sprintf_s(szTemp,"Line %i: %s",this->iLineNumber,szWarn);
|
|
|
|
#else
|
|
|
|
ai_assert(strlen(szWarn) < 950);
|
|
|
|
sprintf(szTemp,"Line %i: %s",this->iLineNumber,szWarn);
|
|
|
|
#endif
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// output the warning to the logger ...
|
|
|
|
DefaultLogger::get()->warn(szTemp);
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-06-01 12:46:17 +00:00
|
|
|
void Parser::LogInfo(const char* szWarn)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != szWarn);
|
|
|
|
|
|
|
|
char szTemp[1024];
|
2008-06-15 10:27:08 +00:00
|
|
|
#if _MSC_VER >= 1400
|
|
|
|
sprintf_s(szTemp,"Line %i: %s",this->iLineNumber,szWarn);
|
|
|
|
#else
|
|
|
|
ai_assert(strlen(szWarn) < 950);
|
|
|
|
sprintf(szTemp,"Line %i: %s",this->iLineNumber,szWarn);
|
|
|
|
#endif
|
2008-06-01 12:46:17 +00:00
|
|
|
|
|
|
|
// output the information to the logger ...
|
|
|
|
DefaultLogger::get()->info(szTemp);
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-09 17:24:28 +00:00
|
|
|
void Parser::LogError(const char* szWarn)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != szWarn);
|
|
|
|
|
|
|
|
char szTemp[1024];
|
2008-06-15 10:27:08 +00:00
|
|
|
#if _MSC_VER >= 1400
|
|
|
|
sprintf_s(szTemp,"Line %i: %s",this->iLineNumber,szWarn);
|
|
|
|
#else
|
|
|
|
ai_assert(strlen(szWarn) < 950);
|
|
|
|
sprintf(szTemp,"Line %i: %s",this->iLineNumber,szWarn);
|
|
|
|
#endif
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// throw an exception
|
|
|
|
throw new ImportErrorException(szTemp);
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Parser::SkipToNextToken()
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
2008-06-15 10:27:08 +00:00
|
|
|
char me = *this->m_szFile;
|
|
|
|
|
|
|
|
// increase the line number counter if necessary
|
2008-07-30 23:00:25 +00:00
|
|
|
if (IsLineEnd(me) && !bLastWasEndLine)
|
|
|
|
{
|
|
|
|
++this->iLineNumber;
|
|
|
|
bLastWasEndLine = true;
|
|
|
|
}
|
|
|
|
else bLastWasEndLine = false;
|
2008-07-10 16:49:01 +00:00
|
|
|
if ('*' == me || '}' == me || '{' == me)return true;
|
2008-06-15 10:27:08 +00:00
|
|
|
else if ('\0' == me)return false;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
++this->m_szFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Parser::SkipOpeningBracket()
|
|
|
|
{
|
|
|
|
if (!SkipSpaces(this->m_szFile,&this->m_szFile))return false;
|
|
|
|
if ('{' != *this->m_szFile)
|
|
|
|
{
|
|
|
|
this->LogWarning("Unable to parse block: Unexpected character, \'{\' expected [#1]");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this->SkipToNextToken();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Parser::SkipSection()
|
|
|
|
{
|
|
|
|
// must handle subsections ...
|
2008-05-23 22:38:35 +00:00
|
|
|
int iCnt = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('}' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
--iCnt;
|
|
|
|
if (0 == iCnt)
|
|
|
|
{
|
|
|
|
// go to the next valid token ...
|
|
|
|
++this->m_szFile;
|
|
|
|
this->SkipToNextToken();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ('{' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
++iCnt;
|
|
|
|
}
|
|
|
|
else if ('\0' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
this->LogWarning("Unable to parse block: Unexpected EOF, closing bracket \'}\' was expected [#1]");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(IsLineEnd(*this->m_szFile))++this->iLineNumber;
|
|
|
|
++this->m_szFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::Parse()
|
|
|
|
{
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// version should be 200. Validate this ...
|
|
|
|
if (0 == strncmp(this->m_szFile,"*3DSMAX_ASCIIEXPORT",19) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+19)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=20;
|
|
|
|
|
|
|
|
unsigned int iVersion;
|
|
|
|
this->ParseLV4MeshLong(iVersion);
|
|
|
|
|
|
|
|
if (200 != iVersion)
|
|
|
|
{
|
|
|
|
this->LogWarning("Unknown file format version: *3DSMAX_ASCIIEXPORT should \
|
|
|
|
be 200. Continuing happily ...");
|
|
|
|
}
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// main scene information
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*SCENE",6) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+6)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=7;
|
|
|
|
this->ParseLV1SceneBlock();
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// material list
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MATERIAL_LIST",14) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+14)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=15;
|
|
|
|
this->ParseLV1MaterialListBlock();
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// geometric object (mesh)
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*GEOMOBJECT",11) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+11)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=12;
|
|
|
|
this->m_vMeshes.push_back(Mesh());
|
|
|
|
this->ParseLV1GeometryObjectBlock(this->m_vMeshes.back());
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
// helper object = dummy in the hierarchy
|
|
|
|
if (0 == strncmp(this->m_szFile,"*HELPEROBJECT",13) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+13)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=14;
|
|
|
|
this->m_vMeshes.push_back(Mesh());
|
|
|
|
this->ParseLV1GeometryObjectBlock(this->m_vMeshes.back());
|
|
|
|
continue;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
// ignore comments, lights and cameras
|
2008-06-01 12:46:17 +00:00
|
|
|
// (display comments on the console)
|
|
|
|
if (0 == strncmp(this->m_szFile,"*LIGHTOBJECT",12) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+12)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=13;
|
|
|
|
this->LogInfo("Found light source (*LIGHTOBJECT chunk). It will be ignored");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (0 == strncmp(this->m_szFile,"*CAMERAOBJECT",13) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+13)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=14;
|
|
|
|
this->LogInfo("Found virtual camera (*CAMERAOBJECT chunk). It will be ignored");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (0 == strncmp(this->m_szFile,"*COMMENT",8) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+8)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=9;
|
|
|
|
std::string out = "<unknown>";
|
|
|
|
this->ParseString(out,"*COMMENT");
|
|
|
|
this->LogInfo(("Comment: " + out).c_str());
|
|
|
|
continue;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_TOP_LEVEL_SECTION(iDepth);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV1SceneBlock()
|
|
|
|
{
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
if (0 == strncmp(this->m_szFile,"*SCENE_BACKGROUND_STATIC",24) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+24)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=25;
|
|
|
|
|
|
|
|
// parse a color triple and assume it is really the bg color
|
|
|
|
this->ParseLV4MeshFloatTriple( &this->m_clrBackground.r );
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*SCENE_AMBIENT_STATIC",21) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+21)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=22;
|
|
|
|
|
|
|
|
// parse a color triple and assume it is really the bg color
|
|
|
|
this->ParseLV4MeshFloatTriple( &this->m_clrAmbient.r );
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*SCENE_FIRSTFRAME",17) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+17)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=18;
|
|
|
|
this->ParseLV4MeshLong(this->iFirstFrame);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (0 == strncmp(this->m_szFile,"*SCENE_LASTFRAME",16) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+16)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=17;
|
|
|
|
this->ParseLV4MeshLong(this->iLastFrame);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (0 == strncmp(this->m_szFile,"*SCENE_FRAMESPEED",17) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+17)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=18;
|
|
|
|
this->ParseLV4MeshLong(this->iFrameSpeed);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (0 == strncmp(this->m_szFile,"*SCENE_TICKSPERFRAME",20) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+20)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=21;
|
|
|
|
this->ParseLV4MeshLong(this->iTicksPerFrame);
|
|
|
|
continue;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_TOP_LEVEL_SECTION(iDepth);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV1MaterialListBlock()
|
|
|
|
{
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
unsigned int iMaterialCount = 0;
|
2008-06-01 12:46:17 +00:00
|
|
|
unsigned int iOldMaterialCount = (unsigned int)this->m_vMaterials.size();
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MATERIAL_COUNT",15) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+15)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=16;
|
|
|
|
this->ParseLV4MeshLong(iMaterialCount);
|
|
|
|
|
|
|
|
// now allocate enough storage to hold all materials
|
2008-05-30 23:01:25 +00:00
|
|
|
this->m_vMaterials.resize(iOldMaterialCount+iMaterialCount);
|
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MATERIAL",9) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+9)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=10;
|
|
|
|
unsigned int iIndex = 0;
|
|
|
|
this->ParseLV4MeshLong(iIndex);
|
|
|
|
|
|
|
|
if (iIndex >= iMaterialCount)
|
|
|
|
{
|
|
|
|
this->LogWarning("Out of range: material index is too large");
|
|
|
|
iIndex = iMaterialCount-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get a reference to the material
|
2008-05-30 23:01:25 +00:00
|
|
|
Material& sMat = this->m_vMaterials[iIndex+iOldMaterialCount];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// skip the '{'
|
|
|
|
this->SkipOpeningBracket();
|
|
|
|
|
|
|
|
// parse the material block
|
|
|
|
this->ParseLV2MaterialBlock(sMat);
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_TOP_LEVEL_SECTION(iDepth);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV2MaterialBlock(ASE::Material& mat)
|
|
|
|
{
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
unsigned int iNumSubMaterials = 0;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MATERIAL_NAME",14) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+14)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=15;
|
|
|
|
|
2008-05-30 23:01:25 +00:00
|
|
|
if (!this->ParseString(mat.mName,"*MATERIAL_NAME"))this->SkipToNextToken();
|
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// ambient material color
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MATERIAL_AMBIENT",17) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+17)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=18;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshFloatTriple(&mat.mAmbient.r);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// diffuse material color
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MATERIAL_DIFFUSE",17) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+17)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=18;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshFloatTriple(&mat.mDiffuse.r);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// specular material color
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MATERIAL_SPECULAR",18) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+18)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=19;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshFloatTriple(&mat.mSpecular.r);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// material shading type
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MATERIAL_SHADING",17) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+17)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=18;
|
|
|
|
|
|
|
|
if (0 == strncmp(this->m_szFile,"Blinn",5) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+5)))
|
|
|
|
{
|
|
|
|
mat.mShading = Dot3DSFile::Blinn;
|
|
|
|
this->m_szFile+=6;
|
|
|
|
}
|
|
|
|
else if (0 == strncmp(this->m_szFile,"Phong",5) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+5)))
|
|
|
|
{
|
|
|
|
mat.mShading = Dot3DSFile::Phong;
|
|
|
|
this->m_szFile+=6;
|
|
|
|
}
|
|
|
|
else if (0 == strncmp(this->m_szFile,"Flat",4) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+4)))
|
|
|
|
{
|
|
|
|
mat.mShading = Dot3DSFile::Flat;
|
|
|
|
this->m_szFile+=5;
|
|
|
|
}
|
|
|
|
else if (0 == strncmp(this->m_szFile,"Wire",4) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+4)))
|
|
|
|
{
|
|
|
|
mat.mShading = Dot3DSFile::Wire;
|
|
|
|
this->m_szFile+=5;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// assume gouraud shading
|
|
|
|
mat.mShading = Dot3DSFile::Gouraud;
|
|
|
|
this->SkipToNextToken();
|
|
|
|
}
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// material transparency
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MATERIAL_TRANSPARENCY",22) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+22)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=23;
|
|
|
|
this->ParseLV4MeshFloat(mat.mTransparency);
|
2008-05-30 23:01:25 +00:00
|
|
|
mat.mTransparency = 1.0f - mat.mTransparency;continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// material self illumination
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MATERIAL_SELFILLUM",19) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+19)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=20;
|
|
|
|
float f = 0.0f;
|
|
|
|
this->ParseLV4MeshFloat(f);
|
|
|
|
|
|
|
|
mat.mEmissive.r = f;
|
|
|
|
mat.mEmissive.g = f;
|
|
|
|
mat.mEmissive.b = f;
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// material shininess
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MATERIAL_SHINE",15) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+15)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=16;
|
|
|
|
this->ParseLV4MeshFloat(mat.mSpecularExponent);
|
2008-05-30 23:01:25 +00:00
|
|
|
mat.mSpecularExponent *= 15;continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-05-28 21:05:05 +00:00
|
|
|
// material shininess strength
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MATERIAL_SHINESTRENGTH",23) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+23)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=24;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshFloat(mat.mShininessStrength);continue;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
// diffuse color map
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MAP_DIFFUSE",12) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+12)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=13;
|
|
|
|
// skip the opening bracket
|
|
|
|
this->SkipOpeningBracket();
|
|
|
|
// parse the texture block
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV3MapBlock(mat.sTexDiffuse);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// ambient color map
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MAP_AMBIENT",12) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+12)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=13;
|
|
|
|
// skip the opening bracket
|
|
|
|
this->SkipOpeningBracket();
|
|
|
|
// parse the texture block
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV3MapBlock(mat.sTexAmbient);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// specular color map
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MAP_SPECULAR",13) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+13)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=14;
|
|
|
|
// skip the opening bracket
|
|
|
|
this->SkipOpeningBracket();
|
|
|
|
// parse the texture block
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV3MapBlock(mat.sTexSpecular);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// opacity map
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MAP_OPACITY",12) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+12)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=13;
|
|
|
|
// skip the opening bracket
|
|
|
|
this->SkipOpeningBracket();
|
|
|
|
// parse the texture block
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV3MapBlock(mat.sTexOpacity);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// emissive map
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MAP_SELFILLUM",14) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+14)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=15;
|
|
|
|
// skip the opening bracket
|
|
|
|
this->SkipOpeningBracket();
|
|
|
|
// parse the texture block
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV3MapBlock(mat.sTexEmissive);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// bump map
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MAP_BUMP",9) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+9)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=10;
|
|
|
|
// skip the opening bracket
|
|
|
|
this->SkipOpeningBracket();
|
|
|
|
// parse the texture block
|
|
|
|
this->ParseLV3MapBlock(mat.sTexBump);
|
|
|
|
}
|
|
|
|
// specular/shininess map
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MAP_SHINE",10) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+10)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=11;
|
|
|
|
// skip the opening bracket
|
|
|
|
this->SkipOpeningBracket();
|
|
|
|
// parse the texture block
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV3MapBlock(mat.sTexShininess);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// number of submaterials
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*NUMSUBMTLS",11) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+11)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=12;
|
|
|
|
this->ParseLV4MeshLong(iNumSubMaterials);
|
|
|
|
|
|
|
|
// allocate enough storage
|
|
|
|
mat.avSubMaterials.resize(iNumSubMaterials);
|
|
|
|
}
|
|
|
|
// submaterial chunks
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*SUBMATERIAL",12) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+12)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=13;
|
|
|
|
|
|
|
|
unsigned int iIndex = 0;
|
|
|
|
this->ParseLV4MeshLong(iIndex);
|
|
|
|
|
|
|
|
if (iIndex >= iNumSubMaterials)
|
|
|
|
{
|
|
|
|
this->LogWarning("Out of range: submaterial index is too large");
|
|
|
|
iIndex = iNumSubMaterials-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get a reference to the material
|
|
|
|
Material& sMat = mat.avSubMaterials[iIndex];
|
|
|
|
|
|
|
|
// skip the '{'
|
|
|
|
this->SkipOpeningBracket();
|
|
|
|
|
|
|
|
// parse the material block
|
|
|
|
this->ParseLV2MaterialBlock(sMat);
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"2","*MATERIAL");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3MapBlock(Texture& map)
|
|
|
|
{
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
unsigned int iNumSubMaterials = 0;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// path to the texture
|
|
|
|
if (0 == strncmp(this->m_szFile,"*BITMAP" ,7) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+7)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=8;
|
2008-05-30 23:01:25 +00:00
|
|
|
if(!this->ParseString(map.mMapName,"*BITMAP"))SkipToNextToken();
|
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// offset on the u axis
|
|
|
|
if (0 == strncmp(this->m_szFile,"*UVW_U_OFFSET" ,13) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+13)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=14;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshFloat(map.mOffsetU);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// offset on the v axis
|
|
|
|
if (0 == strncmp(this->m_szFile,"*UVW_V_OFFSET" ,13) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+13)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=14;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshFloat(map.mOffsetV);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// tiling on the u axis
|
|
|
|
if (0 == strncmp(this->m_szFile,"*UVW_U_TILING" ,13) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+13)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=14;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshFloat(map.mScaleU);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// tiling on the v axis
|
|
|
|
if (0 == strncmp(this->m_szFile,"*UVW_V_TILING" ,13) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+13)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=14;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshFloat(map.mScaleV);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// rotation around the z-axis
|
|
|
|
if (0 == strncmp(this->m_szFile,"*UVW_ANGLE" ,10) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+10)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=11;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshFloat(map.mRotation);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// map blending factor
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MAP_AMOUNT" ,11) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+11)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=12;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshFloat(map.mTextureBlend);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"3","*MAP_XXXXXX");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-28 21:05:05 +00:00
|
|
|
bool Parser::ParseString(std::string& out,const char* szName)
|
|
|
|
{
|
|
|
|
char szBuffer[1024];
|
2008-06-15 10:27:08 +00:00
|
|
|
|
|
|
|
#if (!defined _MSC_VER) || ( _MSC_VER < 1400)
|
2008-05-30 23:01:25 +00:00
|
|
|
ai_assert(strlen(szName) < 750);
|
2008-06-15 10:27:08 +00:00
|
|
|
#endif
|
2008-05-28 21:05:05 +00:00
|
|
|
|
|
|
|
// NOTE: The name could also be the texture in some cases
|
|
|
|
// be prepared that this might occur ...
|
|
|
|
if (!SkipSpaces(this->m_szFile,&this->m_szFile))
|
|
|
|
{
|
2008-06-15 10:27:08 +00:00
|
|
|
#if _MSC_VER >= 1400
|
|
|
|
sprintf_s(szBuffer,"Unable to parse %s block: Unexpected EOL",szName);
|
|
|
|
#else
|
2008-05-28 21:05:05 +00:00
|
|
|
sprintf(szBuffer,"Unable to parse %s block: Unexpected EOL",szName);
|
2008-06-15 10:27:08 +00:00
|
|
|
#endif
|
2008-05-28 21:05:05 +00:00
|
|
|
this->LogWarning(szBuffer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// there must be "
|
|
|
|
if ('\"' != *this->m_szFile)
|
|
|
|
{
|
2008-06-15 10:27:08 +00:00
|
|
|
#if _MSC_VER >= 1400
|
|
|
|
sprintf_s(szBuffer,"Unable to parse %s block: String is expected "
|
|
|
|
"to be enclosed in double quotation marks",szName);
|
|
|
|
#else
|
2008-05-28 21:05:05 +00:00
|
|
|
sprintf(szBuffer,"Unable to parse %s block: String is expected "
|
|
|
|
"to be enclosed in double quotation marks",szName);
|
2008-06-15 10:27:08 +00:00
|
|
|
#endif
|
2008-05-28 21:05:05 +00:00
|
|
|
this->LogWarning(szBuffer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
++this->m_szFile;
|
|
|
|
const char* sz = this->m_szFile;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('\"' == *sz)break;
|
|
|
|
else if ('\0' == sz)
|
|
|
|
{
|
2008-06-15 10:27:08 +00:00
|
|
|
#if _MSC_VER >= 1400
|
|
|
|
sprintf_s(szBuffer,"Unable to parse %s block: String is expected to be "
|
|
|
|
"enclosed in double quotation marks but EOF was reached before a closing "
|
|
|
|
"quotation mark was found",szName);
|
|
|
|
#else
|
2008-05-28 21:05:05 +00:00
|
|
|
sprintf(szBuffer,"Unable to parse %s block: String is expected to be "
|
|
|
|
"enclosed in double quotation marks but EOF was reached before a closing "
|
|
|
|
"quotation mark was found",szName);
|
2008-06-15 10:27:08 +00:00
|
|
|
#endif
|
2008-05-28 21:05:05 +00:00
|
|
|
this->LogWarning(szBuffer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
sz++;
|
|
|
|
}
|
|
|
|
out = std::string(this->m_szFile,(uintptr_t)sz-(uintptr_t)this->m_szFile);
|
|
|
|
this->m_szFile = sz;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-09 17:24:28 +00:00
|
|
|
void Parser::ParseLV1GeometryObjectBlock(ASE::Mesh& mesh)
|
|
|
|
{
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// name of the mesh/node
|
|
|
|
if (0 == strncmp(this->m_szFile,"*NODE_NAME" ,10) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+10)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=11;
|
2008-05-30 23:01:25 +00:00
|
|
|
if(!this->ParseString(mesh.mName,"*NODE_NAME"))this->SkipToNextToken();
|
|
|
|
continue;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
// name of the parent of the node
|
|
|
|
if (0 == strncmp(this->m_szFile,"*NODE_PARENT" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+12)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=13;
|
2008-05-30 23:01:25 +00:00
|
|
|
if(!this->ParseString(mesh.mParent,"*NODE_PARENT"))this->SkipToNextToken();
|
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// transformation matrix of the node
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*NODE_TM" ,8) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+8)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=9;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV2NodeTransformBlock(mesh);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh data
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH" ,5) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+5)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=6;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV2MeshBlock(mesh);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-05-28 21:05:05 +00:00
|
|
|
// mesh material index
|
2008-05-30 23:01:25 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MATERIAL_REF" ,13) &&
|
2008-05-28 21:05:05 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+13)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=14;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshLong(mesh.iMaterialIndex);continue;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
// animation data of the node
|
|
|
|
if (0 == strncmp(this->m_szFile,"*TM_ANIMATION" ,13) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+13)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=14;
|
|
|
|
this->ParseLV2AnimationBlock(mesh);continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AI_ASE_HANDLE_TOP_LEVEL_SECTION(iDepth);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV2AnimationBlock(ASE::Mesh& mesh)
|
|
|
|
{
|
|
|
|
int iDepth = 0;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// position keyframes
|
|
|
|
if (0 == strncmp(this->m_szFile,"*CONTROL_POS_TRACK" ,18) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+18)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=19;
|
|
|
|
this->ParseLV3PosAnimationBlock(mesh);continue;
|
|
|
|
}
|
|
|
|
// rotation keyframes
|
|
|
|
if (0 == strncmp(this->m_szFile,"*CONTROL_ROT_TRACK" ,18) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+18)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=19;
|
|
|
|
this->ParseLV3RotAnimationBlock(mesh);continue;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"2","TM_ANIMATION");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3PosAnimationBlock(ASE::Mesh& mesh)
|
|
|
|
{
|
|
|
|
int iDepth = 0;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-07-18 20:29:46 +00:00
|
|
|
// position keyframe
|
|
|
|
if (0 == strncmp(this->m_szFile,"*CONTROL_POS_SAMPLE" ,19) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+19)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=20;
|
|
|
|
|
|
|
|
unsigned int iIndex;
|
|
|
|
mesh.mAnim.akeyPositions.push_back(aiVectorKey());
|
|
|
|
aiVectorKey& key = mesh.mAnim.akeyPositions.back();
|
|
|
|
|
|
|
|
this->ParseLV4MeshFloatTriple(&key.mValue.x,iIndex);
|
|
|
|
key.mTime = (double)iIndex;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"3","*CONTROL_POS_TRACK");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3RotAnimationBlock(ASE::Mesh& mesh)
|
|
|
|
{
|
|
|
|
int iDepth = 0;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-07-18 20:29:46 +00:00
|
|
|
// rotation keyframe
|
|
|
|
if (0 == strncmp(this->m_szFile,"*CONTROL_ROT_SAMPLE" ,19) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+19)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=20;
|
|
|
|
|
|
|
|
unsigned int iIndex;
|
|
|
|
mesh.mAnim.akeyRotations.push_back(aiQuatKey());
|
|
|
|
aiQuatKey& key = mesh.mAnim.akeyRotations.back();
|
|
|
|
|
|
|
|
// first read the axis, then the angle in radians
|
|
|
|
aiVector3D v;float f;
|
|
|
|
this->ParseLV4MeshFloatTriple(&v.x,iIndex);
|
|
|
|
this->ParseLV4MeshFloat(f);
|
|
|
|
key.mTime = (double)iIndex;
|
|
|
|
key.mValue = aiQuaternion(v,f);
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"3","*CONTROL_ROT_TRACK");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV2NodeTransformBlock(ASE::Mesh& mesh)
|
|
|
|
{
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// first row of the transformation matrix
|
|
|
|
if (0 == strncmp(this->m_szFile,"*TM_ROW0" ,8) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+8)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=9;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshFloatTriple(mesh.mTransform[0]);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// second row of the transformation matrix
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*TM_ROW1" ,8) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+8)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=9;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshFloatTriple(mesh.mTransform[1]);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// third row of the transformation matrix
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*TM_ROW2" ,8) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+8)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=9;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshFloatTriple(mesh.mTransform[2]);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// fourth row of the transformation matrix
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*TM_ROW3" ,8) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+8)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=9;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshFloatTriple(mesh.mTransform[3]);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
// inherited position axes
|
|
|
|
if (0 == strncmp(this->m_szFile,"*INHERIT_POS" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+12)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=13;
|
|
|
|
unsigned int aiVal[3];
|
|
|
|
this->ParseLV4MeshLongTriple(aiVal);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 3;++i)
|
|
|
|
mesh.inherit.abInheritPosition[i] = aiVal[i] != 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// inherited rotation axes
|
|
|
|
if (0 == strncmp(this->m_szFile,"*INHERIT_ROT" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+12)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=13;
|
|
|
|
unsigned int aiVal[3];
|
|
|
|
this->ParseLV4MeshLongTriple(aiVal);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 3;++i)
|
|
|
|
mesh.inherit.abInheritRotation[i] = aiVal[i] != 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// inherited scaling axes
|
|
|
|
if (0 == strncmp(this->m_szFile,"*INHERIT_SCL" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+12)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=13;
|
|
|
|
unsigned int aiVal[3];
|
|
|
|
this->ParseLV4MeshLongTriple(aiVal);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 3;++i)
|
|
|
|
mesh.inherit.abInheritScaling[i] = aiVal[i] != 0;
|
|
|
|
continue;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"2","*NODE_TM");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV2MeshBlock(ASE::Mesh& mesh)
|
|
|
|
{
|
|
|
|
unsigned int iNumVertices = 0;
|
|
|
|
unsigned int iNumFaces = 0;
|
|
|
|
unsigned int iNumTVertices = 0;
|
|
|
|
unsigned int iNumTFaces = 0;
|
|
|
|
unsigned int iNumCVertices = 0;
|
|
|
|
unsigned int iNumCFaces = 0;
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// Number of vertices in the mesh
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_NUMVERTEX" ,15) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+15)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=16;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshLong(iNumVertices);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// Number of texture coordinates in the mesh
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_NUMTVERTEX" ,16) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+16)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=17;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshLong(iNumTVertices);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// Number of vertex colors in the mesh
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_NUMCVERTEX" ,16) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+16)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=17;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshLong(iNumCVertices);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// Number of regular faces in the mesh
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_NUMFACES" ,14) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+14)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=15;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshLong(iNumFaces);continue;
|
|
|
|
// fix ...
|
|
|
|
//mesh.mFaces.resize(iNumFaces);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// Number of UVWed faces in the mesh
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_NUMTVFACES" ,16) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+16)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=17;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshLong(iNumTFaces);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// Number of colored faces in the mesh
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_NUMCVFACES" ,16) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+16)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=17;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshLong(iNumCFaces);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh vertex list block
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_VERTEX_LIST" ,17) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+17)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=18;
|
|
|
|
this->ParseLV3MeshVertexListBlock(iNumVertices,mesh);
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh face list block
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_FACE_LIST" ,15) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+15)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=16;
|
|
|
|
this->SkipOpeningBracket();
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV3MeshFaceListBlock(iNumFaces,mesh);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh texture vertex list block
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_TVERTLIST" ,15) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+15)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=16;
|
|
|
|
this->SkipOpeningBracket();
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV3MeshTListBlock(iNumTVertices,mesh);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh texture face block
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_TFACELIST" ,15) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+15)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=16;
|
|
|
|
this->SkipOpeningBracket();
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV3MeshTFaceListBlock(iNumTFaces,mesh);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh color vertex list block
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_CVERTLIST" ,15) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+15)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=16;
|
|
|
|
this->SkipOpeningBracket();
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV3MeshCListBlock(iNumCVertices,mesh);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh color face block
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_CFACELIST" ,15) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+15)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=16;
|
|
|
|
this->SkipOpeningBracket();
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV3MeshCFaceListBlock(iNumCFaces,mesh);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// another mesh UV channel ...
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_MAPPINGCHANNEL" ,20) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+20)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=21;
|
|
|
|
|
|
|
|
unsigned int iIndex = 0;
|
|
|
|
this->ParseLV4MeshLong(iIndex);
|
|
|
|
|
|
|
|
if (iIndex < 2)
|
|
|
|
{
|
|
|
|
this->LogWarning("Mapping channel has an invalid index. Skipping UV channel");
|
|
|
|
// skip it ...
|
|
|
|
this->SkipOpeningBracket();
|
|
|
|
this->SkipSection();
|
|
|
|
}
|
|
|
|
if (iIndex > AI_MAX_NUMBER_OF_TEXTURECOORDS)
|
|
|
|
{
|
|
|
|
this->LogWarning("Too many UV channels specified. Skipping channel ..");
|
|
|
|
// skip it ...
|
|
|
|
this->SkipOpeningBracket();
|
|
|
|
this->SkipSection();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// skip the '{'
|
|
|
|
this->SkipOpeningBracket();
|
|
|
|
|
|
|
|
// parse the mapping channel
|
|
|
|
this->ParseLV3MappingChannel(iIndex-1,mesh);
|
|
|
|
}
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-05-28 21:05:05 +00:00
|
|
|
// mesh animation keyframe. Not supported
|
2008-05-30 23:01:25 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_ANIMATION" ,15) &&
|
2008-05-28 21:05:05 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+15)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=16;
|
|
|
|
|
|
|
|
this->LogWarning("Found *MESH_ANIMATION element in ASE/ASK file. "
|
|
|
|
"Keyframe animation is not supported by Assimp, this element "
|
|
|
|
"will be ignored");
|
2008-06-15 10:27:08 +00:00
|
|
|
//this->SkipSection();
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
// mesh animation keyframe. Not supported
|
2008-05-30 23:01:25 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_WEIGHTS" ,13) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+13)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=14;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV3MeshWeightsBlock(mesh);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"2","*MESH");
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3MeshWeightsBlock(ASE::Mesh& mesh)
|
|
|
|
{
|
|
|
|
unsigned int iNumVertices = 0;
|
|
|
|
unsigned int iNumBones = 0;
|
|
|
|
int iDepth = 0;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// Number of bone vertices ...
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_NUMVERTEX" ,15) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+15)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-05-28 21:05:05 +00:00
|
|
|
this->m_szFile+=16;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshLong(iNumVertices);continue;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
// Number of bones
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_NUMBONE" ,13) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+13)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=14;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshLong(iNumBones);continue;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
// parse the list of bones
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_BONE_LIST" ,15) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+15)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=16;
|
|
|
|
this->SkipOpeningBracket();
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshBones(iNumBones,mesh);continue;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
// parse the list of bones vertices
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_BONE_VERTEX_LIST" ,22) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+22)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=23;
|
|
|
|
this->SkipOpeningBracket();
|
|
|
|
this->ParseLV4MeshBonesVertices(iNumVertices,mesh);
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_WEIGHTS");
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV4MeshBones(unsigned int iNumBones,ASE::Mesh& mesh)
|
|
|
|
{
|
|
|
|
mesh.mBones.resize(iNumBones);
|
|
|
|
int iDepth = 0;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// Mesh bone with name ...
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_BONE_NAME" ,17) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+17)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=18;
|
|
|
|
|
|
|
|
// parse an index ...
|
|
|
|
if(SkipSpaces(this->m_szFile,&this->m_szFile))
|
|
|
|
{
|
|
|
|
unsigned int iIndex = strtol10(this->m_szFile,&this->m_szFile);
|
|
|
|
if (iIndex >= iNumBones)
|
|
|
|
{
|
|
|
|
iIndex = iNumBones-1;
|
|
|
|
this->LogWarning("Bone index is out of bounds. Using the largest valid "
|
|
|
|
"bone index instead");
|
|
|
|
}
|
|
|
|
if (!this->ParseString(mesh.mBones[iIndex].mName,"*MESH_BONE_NAME"))
|
|
|
|
this->SkipToNextToken();
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_BONE_LIST");
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV4MeshBonesVertices(unsigned int iNumVertices,ASE::Mesh& mesh)
|
|
|
|
{
|
|
|
|
mesh.mBoneVertices.resize(iNumVertices);
|
|
|
|
int iDepth = 0;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// Mesh bone vertex
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_BONE_VERTEX" ,17) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+17)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=18;
|
|
|
|
|
|
|
|
// read the vertex index
|
|
|
|
unsigned int iIndex = strtol10(this->m_szFile,&this->m_szFile);
|
|
|
|
if (iIndex >= mesh.mPositions.size())
|
|
|
|
{
|
2008-06-01 12:46:17 +00:00
|
|
|
iIndex = (unsigned int)mesh.mPositions.size()-1;
|
2008-05-28 21:05:05 +00:00
|
|
|
this->LogWarning("Bone vertex index is out of bounds. Using the largest valid "
|
|
|
|
"bone vertex index instead");
|
|
|
|
}
|
|
|
|
|
|
|
|
// now there there are 3 normal floats, the
|
|
|
|
// should be identical to the vertex positions
|
|
|
|
// contained in the *VERTEX_LIST block. Well, we check this
|
|
|
|
// in debug builds to be sure ;-)
|
|
|
|
float afVert[3];
|
|
|
|
this->ParseLV4MeshFloatTriple(afVert);
|
|
|
|
|
|
|
|
std::pair<int,float> pairOut;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
// first parse the bone index ...
|
|
|
|
if (!SkipSpaces(this->m_szFile,&this->m_szFile))break;
|
|
|
|
pairOut.first = strtol10(this->m_szFile,&this->m_szFile);
|
|
|
|
|
|
|
|
// then parse the vertex weight
|
|
|
|
if (!SkipSpaces(this->m_szFile,&this->m_szFile))break;
|
|
|
|
this->m_szFile = fast_atof_move(this->m_szFile,pairOut.second);
|
|
|
|
|
|
|
|
// -1 designates unused entries
|
|
|
|
if (-1 != pairOut.first)
|
|
|
|
{
|
|
|
|
mesh.mBoneVertices[iIndex].mBoneWeights.push_back(pairOut);
|
|
|
|
}
|
|
|
|
}
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"4","*MESH_BONE_VERTEX");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3MeshVertexListBlock(
|
|
|
|
unsigned int iNumVertices, ASE::Mesh& mesh)
|
|
|
|
{
|
|
|
|
// allocate enough storage in the array
|
|
|
|
mesh.mPositions.resize(iNumVertices);
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// Vertex entry
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_VERTEX" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+12)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=13;
|
|
|
|
|
|
|
|
aiVector3D vTemp;
|
|
|
|
unsigned int iIndex;
|
|
|
|
this->ParseLV4MeshFloatTriple(&vTemp.x,iIndex);
|
|
|
|
|
|
|
|
if (iIndex >= iNumVertices)
|
|
|
|
{
|
|
|
|
this->LogWarning("Vertex has an invalid index. It will be ignored");
|
|
|
|
}
|
|
|
|
else mesh.mPositions[iIndex] = vTemp;
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_VERTEX_LIST");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3MeshFaceListBlock(unsigned int iNumFaces, ASE::Mesh& mesh)
|
|
|
|
{
|
|
|
|
// allocate enough storage in the face array
|
|
|
|
mesh.mFaces.resize(iNumFaces);
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// Face entry
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_FACE" ,10) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+10)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=11;
|
|
|
|
|
|
|
|
ASE::Face mFace;
|
|
|
|
this->ParseLV4MeshFace(mFace);
|
|
|
|
|
|
|
|
if (mFace.iFace >= iNumFaces)
|
|
|
|
{
|
|
|
|
this->LogWarning("Face has an invalid index. It will be ignored");
|
|
|
|
}
|
|
|
|
else mesh.mFaces[mFace.iFace] = mFace;
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_FACE_LIST");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3MeshTListBlock(unsigned int iNumVertices,
|
|
|
|
ASE::Mesh& mesh, unsigned int iChannel)
|
|
|
|
{
|
|
|
|
// allocate enough storage in the array
|
|
|
|
mesh.amTexCoords[iChannel].resize(iNumVertices);
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// Vertex entry
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_TVERT" ,11) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+11)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=12;
|
|
|
|
|
|
|
|
aiVector3D vTemp;
|
|
|
|
unsigned int iIndex;
|
|
|
|
this->ParseLV4MeshFloatTriple(&vTemp.x,iIndex);
|
|
|
|
|
|
|
|
if (iIndex >= iNumVertices)
|
|
|
|
{
|
|
|
|
this->LogWarning("Tvertex has an invalid index. It will be ignored");
|
|
|
|
}
|
|
|
|
else mesh.amTexCoords[iChannel][iIndex] = vTemp;
|
|
|
|
|
|
|
|
if (0.0f != vTemp.z)
|
|
|
|
{
|
|
|
|
// we need 3 coordinate channels
|
|
|
|
mesh.mNumUVComponents[iChannel] = 3;
|
|
|
|
}
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_TVERT_LIST");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3MeshTFaceListBlock(unsigned int iNumFaces,
|
|
|
|
ASE::Mesh& mesh, unsigned int iChannel)
|
|
|
|
{
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// Face entry
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_TFACE" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+12)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=13;
|
|
|
|
|
|
|
|
unsigned int aiValues[3];
|
|
|
|
unsigned int iIndex = 0;
|
|
|
|
|
|
|
|
this->ParseLV4MeshLongTriple(aiValues,iIndex);
|
|
|
|
if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size())
|
|
|
|
{
|
|
|
|
this->LogWarning("UV-Face has an invalid index. It will be ignored");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// copy UV indices
|
|
|
|
mesh.mFaces[iIndex].amUVIndices[iChannel][0] = aiValues[0];
|
|
|
|
mesh.mFaces[iIndex].amUVIndices[iChannel][1] = aiValues[1];
|
|
|
|
mesh.mFaces[iIndex].amUVIndices[iChannel][2] = aiValues[2];
|
|
|
|
}
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_TFACE_LIST");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3MappingChannel(unsigned int iChannel, ASE::Mesh& mesh)
|
|
|
|
{
|
|
|
|
unsigned int iNumTVertices = 0;
|
|
|
|
unsigned int iNumTFaces = 0;
|
|
|
|
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// Number of texture coordinates in the mesh
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_NUMTVERTEX" ,16) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+16)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=17;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshLong(iNumTVertices);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// Number of UVWed faces in the mesh
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_NUMTVFACES" ,16) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+16)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=17;
|
2008-05-30 23:01:25 +00:00
|
|
|
this->ParseLV4MeshLong(iNumTFaces);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh texture vertex list block
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_TVERTLIST" ,15) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+15)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=16;
|
|
|
|
this->SkipOpeningBracket();
|
|
|
|
this->ParseLV3MeshTListBlock(iNumTVertices,mesh,iChannel);
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh texture face block
|
2008-05-23 22:38:35 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_TFACELIST" ,15) &&
|
2008-05-09 17:24:28 +00:00
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+15)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=16;
|
|
|
|
this->SkipOpeningBracket();
|
|
|
|
this->ParseLV3MeshTFaceListBlock(iNumTFaces,mesh, iChannel);
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_MAPPING_CHANNEL");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3MeshCListBlock(unsigned int iNumVertices, ASE::Mesh& mesh)
|
|
|
|
{
|
|
|
|
// allocate enough storage in the array
|
|
|
|
mesh.mVertexColors.resize(iNumVertices);
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// Vertex entry
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_VERTCOL" ,13) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+13)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=14;
|
|
|
|
|
|
|
|
aiColor4D vTemp;
|
|
|
|
vTemp.a = 1.0f;
|
|
|
|
unsigned int iIndex;
|
|
|
|
this->ParseLV4MeshFloatTriple(&vTemp.r,iIndex);
|
|
|
|
|
|
|
|
if (iIndex >= iNumVertices)
|
|
|
|
{
|
|
|
|
this->LogWarning("Vertex color has an invalid index. It will be ignored");
|
|
|
|
}
|
|
|
|
else mesh.mVertexColors[iIndex] = vTemp;
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_CVERTEX_LIST");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3MeshCFaceListBlock(unsigned int iNumFaces, ASE::Mesh& mesh)
|
|
|
|
{
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
|
|
|
// Face entry
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_CFACE" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+12)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=13;
|
|
|
|
|
|
|
|
unsigned int aiValues[3];
|
|
|
|
unsigned int iIndex = 0;
|
|
|
|
|
|
|
|
this->ParseLV4MeshLongTriple(aiValues,iIndex);
|
|
|
|
if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size())
|
|
|
|
{
|
|
|
|
this->LogWarning("UV-Face has an invalid index. It will be ignored");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// copy color indices
|
|
|
|
mesh.mFaces[iIndex].mColorIndices[0] = aiValues[0];
|
|
|
|
mesh.mFaces[iIndex].mColorIndices[1] = aiValues[1];
|
|
|
|
mesh.mFaces[iIndex].mColorIndices[2] = aiValues[2];
|
|
|
|
}
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_CFACE_LIST");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3MeshNormalListBlock(ASE::Mesh& sMesh)
|
|
|
|
{
|
|
|
|
// allocate enough storage for the normals
|
|
|
|
sMesh.mNormals.resize(sMesh.mPositions.size());
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// we need the *MESH_VERTEXNORMAL blocks, ignore the face normals
|
|
|
|
// if there are only face normals we calculate them outselfes using the SGs
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)
|
|
|
|
{
|
2008-07-18 20:29:46 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_VERTEXNORMAL",18) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+18)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
this->m_szFile += 19;
|
|
|
|
|
|
|
|
// parse a simple float triple
|
|
|
|
aiVector3D vNormal;
|
|
|
|
unsigned int iIndex = 0;
|
|
|
|
this->ParseLV4MeshFloatTriple(&vNormal.x,iIndex);
|
|
|
|
|
|
|
|
if (iIndex >= sMesh.mNormals.size())
|
|
|
|
{
|
|
|
|
this->LogWarning("Normal index is too large");
|
2008-06-01 12:46:17 +00:00
|
|
|
iIndex = (unsigned int)sMesh.mNormals.size()-1;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// important: this->m_szFile might now point to '}' ...
|
|
|
|
sMesh.mNormals[iIndex] = vNormal;
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
AI_ASE_HANDLE_SECTION(iDepth,"3","*MESH_NORMALS");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV4MeshFace(ASE::Face& out)
|
2008-06-03 21:50:53 +00:00
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
// skip spaces and tabs
|
|
|
|
if(!SkipSpaces(this->m_szFile,&this->m_szFile))
|
2008-06-03 21:50:53 +00:00
|
|
|
{
|
|
|
|
this->LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL [#1]");
|
|
|
|
this->SkipToNextToken();
|
|
|
|
return;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// parse the face index
|
|
|
|
out.iFace = strtol10(this->m_szFile,&this->m_szFile);
|
|
|
|
|
|
|
|
// next character should be ':'
|
2008-06-03 21:50:53 +00:00
|
|
|
if(!SkipSpaces(this->m_szFile,&this->m_szFile))
|
|
|
|
{
|
|
|
|
// FIX: there are some ASE files which haven't got : here ....
|
|
|
|
this->LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. \':\' expected [#2]");
|
|
|
|
this->SkipToNextToken();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// FIX: there are some ASE files which haven't got : here ....
|
|
|
|
if(':' == *this->m_szFile)++this->m_szFile;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// parse all mesh indices
|
|
|
|
for (unsigned int i = 0; i < 3;++i)
|
|
|
|
{
|
|
|
|
unsigned int iIndex = 0;
|
|
|
|
if(!SkipSpaces(this->m_szFile,&this->m_szFile))
|
|
|
|
{
|
|
|
|
// LOG
|
|
|
|
__EARTHQUAKE_XXL:
|
2008-06-03 21:50:53 +00:00
|
|
|
this->LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. "
|
|
|
|
"A,B or C expected [#3]");
|
|
|
|
this->SkipToNextToken();
|
|
|
|
return;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
switch (*this->m_szFile)
|
|
|
|
{
|
|
|
|
case 'A':
|
|
|
|
case 'a':
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
case 'b':
|
|
|
|
iIndex = 1;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
case 'c':
|
|
|
|
iIndex = 2;
|
|
|
|
break;
|
|
|
|
default: goto __EARTHQUAKE_XXL;
|
|
|
|
};
|
|
|
|
++this->m_szFile;
|
|
|
|
|
|
|
|
// next character should be ':'
|
|
|
|
if(!SkipSpaces(this->m_szFile,&this->m_szFile) || ':' != *this->m_szFile)
|
2008-06-03 21:50:53 +00:00
|
|
|
{
|
|
|
|
this->LogWarning("Unable to parse *MESH_FACE Element: "
|
|
|
|
"Unexpected EOL. \':\' expected [#2]");
|
|
|
|
this->SkipToNextToken();
|
|
|
|
return;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
++this->m_szFile;
|
|
|
|
if(!SkipSpaces(this->m_szFile,&this->m_szFile))
|
2008-06-03 21:50:53 +00:00
|
|
|
{
|
|
|
|
this->LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. "
|
|
|
|
"Vertex index ecpected [#4]");
|
|
|
|
this->SkipToNextToken();
|
|
|
|
return;
|
|
|
|
}
|
2008-05-29 11:07:25 +00:00
|
|
|
out.mIndices[iIndex] = strtol10(this->m_szFile,&this->m_szFile);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// now we need to skip the AB, BC, CA blocks.
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)break;
|
|
|
|
if (IsLineEnd(*this->m_szFile))
|
|
|
|
{
|
2008-05-28 21:05:05 +00:00
|
|
|
//this->iLineNumber++;
|
2008-05-09 17:24:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->m_szFile++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse the smoothing group of the face
|
2008-06-03 21:50:53 +00:00
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_SMOOTHING",15) &&
|
|
|
|
IsSpaceOrNewLine(*(this->m_szFile+15)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
this->m_szFile+=16;
|
|
|
|
if(!SkipSpaces(this->m_szFile,&this->m_szFile))
|
2008-06-03 21:50:53 +00:00
|
|
|
{
|
|
|
|
this->LogWarning("Unable to parse *MESH_SMOOTHING Element: "
|
|
|
|
"Unexpected EOL. Smoothing group(s) expected [#5]");
|
|
|
|
this->SkipToNextToken();
|
|
|
|
return;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// parse smoothing groups until we don_t anymore see commas
|
2008-05-28 21:05:05 +00:00
|
|
|
// FIX: There needn't always be a value, sad but true
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
2008-05-28 21:05:05 +00:00
|
|
|
if (*this->m_szFile < '9' && *this->m_szFile >= '0')
|
|
|
|
{
|
|
|
|
out.iSmoothGroup |= (1 << strtol10(this->m_szFile,&this->m_szFile));
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
SkipSpaces(this->m_szFile,&this->m_szFile);
|
|
|
|
if (',' != *this->m_szFile)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++this->m_szFile;
|
|
|
|
SkipSpaces(this->m_szFile,&this->m_szFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// *MESH_MTLID is optional, too
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('*' == *this->m_szFile)break;
|
|
|
|
if (IsLineEnd(*this->m_szFile))
|
|
|
|
{
|
2008-05-28 21:05:05 +00:00
|
|
|
//this->iLineNumber++;
|
2008-05-09 17:24:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->m_szFile++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == strncmp(this->m_szFile,"*MESH_MTLID",11) && IsSpaceOrNewLine(*(this->m_szFile+11)))
|
|
|
|
{
|
|
|
|
this->m_szFile+=12;
|
|
|
|
if(!SkipSpaces(this->m_szFile,&this->m_szFile))
|
2008-06-03 21:50:53 +00:00
|
|
|
{
|
|
|
|
this->LogWarning("Unable to parse *MESH_MTLID Element: Unexpected EOL. "
|
|
|
|
"Material index expected [#6]");
|
|
|
|
this->SkipToNextToken();
|
|
|
|
return;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
out.iMaterial = strtol10(this->m_szFile,&this->m_szFile);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV4MeshLongTriple(unsigned int* apOut)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != apOut);
|
|
|
|
|
2008-07-18 20:29:46 +00:00
|
|
|
for (unsigned int i = 0; i < 3;++i)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-07-18 20:29:46 +00:00
|
|
|
// skip spaces and tabs
|
|
|
|
if(!SkipSpaces(this->m_szFile,&this->m_szFile))
|
|
|
|
{
|
|
|
|
// LOG
|
|
|
|
this->LogWarning("Unable to parse indexable long triple: unexpected EOL [#1]");
|
|
|
|
++this->iLineNumber;
|
|
|
|
apOut[0] = apOut[1] = apOut[2] = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
apOut[i] = strtol10(this->m_szFile,&this->m_szFile);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV4MeshLongTriple(unsigned int* apOut, unsigned int& rIndexOut)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != apOut);
|
|
|
|
|
|
|
|
// skip spaces and tabs
|
|
|
|
if(!SkipSpaces(this->m_szFile,&this->m_szFile))
|
|
|
|
{
|
|
|
|
// LOG
|
2008-07-18 20:29:46 +00:00
|
|
|
this->LogWarning("Unable to parse indexed long triple: unexpected EOL [#4]");
|
2008-05-09 17:24:28 +00:00
|
|
|
rIndexOut = 0;
|
|
|
|
apOut[0] = apOut[1] = apOut[2] = 0;
|
|
|
|
++this->iLineNumber;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// parse the index
|
|
|
|
rIndexOut = strtol10(this->m_szFile,&this->m_szFile);
|
|
|
|
|
|
|
|
// parse the three others
|
|
|
|
this->ParseLV4MeshLongTriple(apOut);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV4MeshFloatTriple(float* apOut, unsigned int& rIndexOut)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != apOut);
|
|
|
|
|
|
|
|
// skip spaces and tabs
|
|
|
|
if(!SkipSpaces(this->m_szFile,&this->m_szFile))
|
|
|
|
{
|
|
|
|
// LOG
|
2008-07-18 20:29:46 +00:00
|
|
|
this->LogWarning("Unable to parse indexed float triple: unexpected EOL [#1]");
|
2008-05-09 17:24:28 +00:00
|
|
|
rIndexOut = 0;
|
|
|
|
apOut[0] = apOut[1] = apOut[2] = 0.0f;
|
|
|
|
++this->iLineNumber;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// parse the index
|
|
|
|
rIndexOut = strtol10(this->m_szFile,&this->m_szFile);
|
|
|
|
|
|
|
|
// parse the three others
|
|
|
|
this->ParseLV4MeshFloatTriple(apOut);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV4MeshFloatTriple(float* apOut)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != apOut);
|
2008-07-18 20:29:46 +00:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 3;++i)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-07-18 20:29:46 +00:00
|
|
|
// skip spaces and tabs
|
|
|
|
if(!SkipSpaces(this->m_szFile,&this->m_szFile))
|
|
|
|
{
|
|
|
|
// LOG
|
|
|
|
this->LogWarning("Unable to parse float triple: unexpected EOL [#5]");
|
|
|
|
apOut[0] = apOut[1] = apOut[2] = 0.0f;
|
|
|
|
++this->iLineNumber;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// parse the float
|
|
|
|
this->m_szFile = fast_atof_move(this->m_szFile,apOut[i]);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV4MeshFloat(float& fOut)
|
|
|
|
{
|
|
|
|
// skip spaces and tabs
|
|
|
|
if(!SkipSpaces(this->m_szFile,&this->m_szFile))
|
|
|
|
{
|
|
|
|
// LOG
|
|
|
|
this->LogWarning("Unable to parse float: unexpected EOL [#1]");
|
|
|
|
fOut = 0.0f;
|
|
|
|
++this->iLineNumber;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// parse the first float
|
|
|
|
this->m_szFile = fast_atof_move(this->m_szFile,fOut);
|
|
|
|
// go to the next valid sequence
|
2008-05-28 21:05:05 +00:00
|
|
|
//this->SkipToNextToken();
|
2008-05-09 17:24:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV4MeshLong(unsigned int& iOut)
|
|
|
|
{
|
|
|
|
// skip spaces and tabs
|
|
|
|
if(!SkipSpaces(this->m_szFile,&this->m_szFile))
|
|
|
|
{
|
|
|
|
// LOG
|
|
|
|
this->LogWarning("Unable to parse long: unexpected EOL [#1]");
|
|
|
|
iOut = 0;
|
|
|
|
++this->iLineNumber;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// parse the value
|
|
|
|
iOut = strtol10(this->m_szFile,&this->m_szFile);
|
|
|
|
// go to the next valid sequence
|
2008-05-28 21:05:05 +00:00
|
|
|
//this->SkipToNextToken();
|
2008-05-09 17:24:28 +00:00
|
|
|
return;
|
|
|
|
}
|