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-10-13 16:45:48 +00:00
|
|
|
#include "AssimpPCH.h"
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
using namespace Assimp::ASE;
|
|
|
|
|
|
|
|
#if (defined BLUBB)
|
|
|
|
# undef BLUBB
|
|
|
|
#endif
|
|
|
|
#define BLUBB(_message_) \
|
2008-09-27 16:46:05 +00:00
|
|
|
{LogError(_message_);return;}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-08-28 17:35:36 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-07-18 20:29:46 +00:00
|
|
|
#define AI_ASE_HANDLE_TOP_LEVEL_SECTION(iDepth) \
|
2008-09-27 16:46:05 +00:00
|
|
|
else if ('{' == *m_szFile)iDepth++; \
|
|
|
|
else if ('}' == *m_szFile) \
|
2008-07-18 20:29:46 +00:00
|
|
|
{ \
|
|
|
|
if (0 == --iDepth) \
|
|
|
|
{ \
|
2008-09-27 16:46:05 +00:00
|
|
|
++m_szFile; \
|
|
|
|
SkipToNextToken(); \
|
2008-07-18 20:29:46 +00:00
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} \
|
2008-09-27 16:46:05 +00:00
|
|
|
else if ('\0' == *m_szFile) \
|
2008-07-18 20:29:46 +00:00
|
|
|
{ \
|
|
|
|
return; \
|
|
|
|
} \
|
2008-09-27 16:46:05 +00:00
|
|
|
if(IsLineEnd(*m_szFile) && !bLastWasEndLine) \
|
2008-07-30 23:00:25 +00:00
|
|
|
{ \
|
2008-09-27 16:46:05 +00:00
|
|
|
++iLineNumber; \
|
2008-07-30 23:00:25 +00:00
|
|
|
bLastWasEndLine = true; \
|
|
|
|
} else bLastWasEndLine = false; \
|
2008-09-27 16:46:05 +00:00
|
|
|
++m_szFile;
|
2008-07-18 20:29:46 +00:00
|
|
|
|
2008-08-28 17:35:36 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-07-18 20:29:46 +00:00
|
|
|
#define AI_ASE_HANDLE_SECTION(iDepth, level, msg) \
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('{' == *m_szFile)iDepth++; \
|
|
|
|
else if ('}' == *m_szFile) \
|
2008-07-18 20:29:46 +00:00
|
|
|
{ \
|
|
|
|
if (0 == --iDepth) \
|
|
|
|
{ \
|
2008-09-27 16:46:05 +00:00
|
|
|
++m_szFile; \
|
|
|
|
SkipToNextToken(); \
|
2008-07-18 20:29:46 +00:00
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} \
|
2008-09-27 16:46:05 +00:00
|
|
|
else if ('\0' == *m_szFile) \
|
2008-07-18 20:29:46 +00:00
|
|
|
{ \
|
2008-09-27 16:46:05 +00:00
|
|
|
LogError("Encountered unexpected EOL while parsing a " msg \
|
2008-07-18 20:29:46 +00:00
|
|
|
" chunk (Level " level ")"); \
|
|
|
|
} \
|
2008-09-27 16:46:05 +00:00
|
|
|
if(IsLineEnd(*m_szFile) && !bLastWasEndLine) \
|
2008-07-30 23:00:25 +00:00
|
|
|
{ \
|
2008-09-27 16:46:05 +00:00
|
|
|
++iLineNumber; \
|
2008-07-30 23:00:25 +00:00
|
|
|
bLastWasEndLine = true; \
|
|
|
|
} else bLastWasEndLine = false; \
|
2008-09-27 16:46:05 +00:00
|
|
|
++m_szFile;
|
2008-07-18 20:29:46 +00:00
|
|
|
|
2008-08-08 23:58:40 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# define sprintf sprintf_s
|
|
|
|
#endif
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Parser::Parser (const char* szFile)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != szFile);
|
2008-09-27 16:46:05 +00:00
|
|
|
m_szFile = szFile;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// makre sure that the color values are invalid
|
2008-09-27 16:46:05 +00:00
|
|
|
m_clrBackground.r = std::numeric_limits<float>::quiet_NaN();
|
|
|
|
m_clrAmbient.r = std::numeric_limits<float>::quiet_NaN();
|
|
|
|
|
|
|
|
iLineNumber = 0;
|
|
|
|
iFirstFrame = 0;
|
|
|
|
iLastFrame = 0;
|
|
|
|
iFrameSpeed = 30; // use 30 as default value for this property
|
|
|
|
iTicksPerFrame = 1; // use 1 as default value for this property
|
|
|
|
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
|
2008-09-27 16:46:05 +00:00
|
|
|
sprintf_s(szTemp,"Line %i: %s",iLineNumber,szWarn);
|
2008-06-15 10:27:08 +00:00
|
|
|
#else
|
|
|
|
ai_assert(strlen(szWarn) < 950);
|
2008-09-27 16:46:05 +00:00
|
|
|
sprintf(szTemp,"Line %i: %s",iLineNumber,szWarn);
|
2008-06-15 10:27:08 +00:00
|
|
|
#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
|
2008-09-27 16:46:05 +00:00
|
|
|
sprintf_s(szTemp,"Line %i: %s",iLineNumber,szWarn);
|
2008-06-15 10:27:08 +00:00
|
|
|
#else
|
|
|
|
ai_assert(strlen(szWarn) < 950);
|
2008-09-27 16:46:05 +00:00
|
|
|
sprintf(szTemp,"Line %i: %s",iLineNumber,szWarn);
|
2008-06-15 10:27:08 +00:00
|
|
|
#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
|
2008-09-27 16:46:05 +00:00
|
|
|
sprintf_s(szTemp,"Line %i: %s",iLineNumber,szWarn);
|
2008-06-15 10:27:08 +00:00
|
|
|
#else
|
|
|
|
ai_assert(strlen(szWarn) < 950);
|
2008-09-27 16:46:05 +00:00
|
|
|
sprintf(szTemp,"Line %i: %s",iLineNumber,szWarn);
|
2008-06-15 10:27:08 +00:00
|
|
|
#endif
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// throw an exception
|
|
|
|
throw new ImportErrorException(szTemp);
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Parser::SkipToNextToken()
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
char me = *m_szFile;
|
2008-06-15 10:27:08 +00:00
|
|
|
|
|
|
|
// increase the line number counter if necessary
|
2008-07-30 23:00:25 +00:00
|
|
|
if (IsLineEnd(me) && !bLastWasEndLine)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
++iLineNumber;
|
2008-07-30 23:00:25 +00:00
|
|
|
bLastWasEndLine = true;
|
|
|
|
}
|
|
|
|
else bLastWasEndLine = false;
|
2008-07-10 16:49:01 +00:00
|
|
|
if ('*' == me || '}' == me || '{' == me)return true;
|
2008-08-08 18:25:55 +00:00
|
|
|
if ('\0' == me)return false;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-09-27 16:46:05 +00:00
|
|
|
++m_szFile;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('}' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
--iCnt;
|
|
|
|
if (0 == iCnt)
|
|
|
|
{
|
|
|
|
// go to the next valid token ...
|
2008-09-27 16:46:05 +00:00
|
|
|
++m_szFile;
|
|
|
|
SkipToNextToken();
|
2008-05-09 17:24:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
else if ('{' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
++iCnt;
|
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
else if ('\0' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Unable to parse block: Unexpected EOF, closing bracket \'}\' was expected [#1]");
|
2008-05-09 17:24:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
else if(IsLineEnd(*m_szFile))++iLineNumber;
|
|
|
|
++m_szFile;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::Parse()
|
|
|
|
{
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// version should be 200. Validate this ...
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"3DSMAX_ASCIIEXPORT",18) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+18)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=19;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
unsigned int iVersion;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iVersion);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
if (200 != iVersion)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Unknown file format version: *3DSMAX_ASCIIEXPORT should \
|
2008-05-09 17:24:28 +00:00
|
|
|
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-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"SCENE",5) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+5)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=6;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV1SceneBlock();
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// material list
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MATERIAL_LIST",13) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+13)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=14;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV1MaterialListBlock();
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// geometric object (mesh)
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"GEOMOBJECT",10) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+10)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=11;
|
2008-09-27 16:46:05 +00:00
|
|
|
m_vMeshes.push_back(Mesh());
|
|
|
|
ParseLV1GeometryObjectBlock(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
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"HELPEROBJECT",12) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+12)))
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=13;
|
2008-09-27 16:46:05 +00:00
|
|
|
m_vMeshes.push_back(Mesh());
|
|
|
|
ParseLV1GeometryObjectBlock(m_vMeshes.back());
|
2008-07-18 20:29:46 +00:00
|
|
|
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)
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"LIGHTOBJECT",11) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+11)))
|
2008-06-01 12:46:17 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=12;
|
2008-09-27 16:46:05 +00:00
|
|
|
LogInfo("Found light source (*LIGHTOBJECT chunk). It will be ignored");
|
2008-08-28 23:00:03 +00:00
|
|
|
SkipSection();
|
2008-06-01 12:46:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"CAMERAOBJECT",12) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+122)))
|
2008-06-01 12:46:17 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=13;
|
2008-09-27 16:46:05 +00:00
|
|
|
LogInfo("Found virtual camera (*CAMERAOBJECT chunk). It will be ignored");
|
2008-08-28 23:00:03 +00:00
|
|
|
SkipSection();
|
2008-06-01 12:46:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"COMMENT",7) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+7)))
|
2008-06-01 12:46:17 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=8;
|
2008-06-01 12:46:17 +00:00
|
|
|
std::string out = "<unknown>";
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseString(out,"*COMMENT");
|
|
|
|
LogInfo(("Comment: " + out).c_str());
|
2008-06-01 12:46:17 +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::ParseLV1SceneBlock()
|
|
|
|
{
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
|
|
|
if (0 == strncmp(m_szFile,"SCENE_BACKGROUND_STATIC",23) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+23)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=24;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// parse a color triple and assume it is really the bg color
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple( &m_clrBackground.r );
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"SCENE_AMBIENT_STATIC",20) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+20)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=21;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// parse a color triple and assume it is really the bg color
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple( &m_clrAmbient.r );
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"SCENE_FIRSTFRAME",16) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+16)))
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=17;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iFirstFrame);
|
2008-07-18 20:29:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"SCENE_LASTFRAME",15) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+15)))
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=16;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iLastFrame);
|
2008-07-18 20:29:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"SCENE_FRAMESPEED",16) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+16)))
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=17;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iFrameSpeed);
|
2008-07-18 20:29:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"SCENE_TICKSPERFRAME",19) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+19)))
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=20;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iTicksPerFrame);
|
2008-07-18 20:29:46 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
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-09-27 16:46:05 +00:00
|
|
|
unsigned int iOldMaterialCount = (unsigned int)m_vMaterials.size();
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
|
|
|
if (0 == strncmp(m_szFile,"MATERIAL_COUNT",14) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+14)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=15;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iMaterialCount);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// now allocate enough storage to hold all materials
|
2008-09-27 16:46:05 +00:00
|
|
|
m_vMaterials.resize(iOldMaterialCount+iMaterialCount);
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MATERIAL",8) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+8)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=9;
|
2008-05-09 17:24:28 +00:00
|
|
|
unsigned int iIndex = 0;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iIndex);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
if (iIndex >= iMaterialCount)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Out of range: material index is too large");
|
2008-05-09 17:24:28 +00:00
|
|
|
iIndex = iMaterialCount-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get a reference to the material
|
2008-09-27 16:46:05 +00:00
|
|
|
Material& sMat = m_vMaterials[iIndex+iOldMaterialCount];
|
2008-05-09 17:24:28 +00:00
|
|
|
// parse the material block
|
2008-09-27 16:46:05 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
|
|
|
if (0 == strncmp(m_szFile,"MATERIAL_NAME",13) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+13)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=14;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-09-27 16:46:05 +00:00
|
|
|
if (!ParseString(mat.mName,"*MATERIAL_NAME"))SkipToNextToken();
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// ambient material color
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MATERIAL_AMBIENT",16) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+16)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=17;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple(&mat.mAmbient.r);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// diffuse material color
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MATERIAL_DIFFUSE",16) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+16)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=17;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple(&mat.mDiffuse.r);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// specular material color
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MATERIAL_SPECULAR",17) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+17)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=16;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple(&mat.mSpecular.r);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// material shading type
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MATERIAL_SHADING",16) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+16)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=17;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-09-27 16:46:05 +00:00
|
|
|
if (0 == strncmp(m_szFile,"Blinn",5) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+5)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
mat.mShading = Dot3DSFile::Blinn;
|
2008-09-27 16:46:05 +00:00
|
|
|
m_szFile+=6;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
else if (0 == strncmp(m_szFile,"Phong",5) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+5)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
mat.mShading = Dot3DSFile::Phong;
|
2008-09-27 16:46:05 +00:00
|
|
|
m_szFile+=6;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
else if (0 == strncmp(m_szFile,"Flat",4) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+4)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
mat.mShading = Dot3DSFile::Flat;
|
2008-09-27 16:46:05 +00:00
|
|
|
m_szFile+=5;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
else if (0 == strncmp(m_szFile,"Wire",4) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+4)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
mat.mShading = Dot3DSFile::Wire;
|
2008-09-27 16:46:05 +00:00
|
|
|
m_szFile+=5;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// assume gouraud shading
|
|
|
|
mat.mShading = Dot3DSFile::Gouraud;
|
2008-09-27 16:46:05 +00:00
|
|
|
SkipToNextToken();
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// material transparency
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MATERIAL_TRANSPARENCY",21) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+21)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=22;
|
2008-09-27 16:46:05 +00:00
|
|
|
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-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MATERIAL_SELFILLUM",18) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+18)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=19;
|
2008-05-09 17:24:28 +00:00
|
|
|
float f = 0.0f;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloat(f);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
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-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MATERIAL_SHINE",14) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+14)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=15;
|
2008-09-27 16:46:05 +00:00
|
|
|
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
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MATERIAL_SHINESTRENGTH",22) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+22)))
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=23;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloat(mat.mShininessStrength);continue;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
// diffuse color map
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MAP_DIFFUSE",11) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+11)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=12;
|
2008-05-09 17:24:28 +00:00
|
|
|
// parse the texture block
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3MapBlock(mat.sTexDiffuse);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// ambient color map
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MAP_AMBIENT",11) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+11)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=12;
|
2008-05-09 17:24:28 +00:00
|
|
|
// parse the texture block
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3MapBlock(mat.sTexAmbient);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// specular color map
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MAP_SPECULAR",122) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+12)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=11;
|
2008-05-09 17:24:28 +00:00
|
|
|
// parse the texture block
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3MapBlock(mat.sTexSpecular);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// opacity map
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MAP_OPACITY",11) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+11)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=12;
|
2008-05-09 17:24:28 +00:00
|
|
|
// parse the texture block
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3MapBlock(mat.sTexOpacity);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// emissive map
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MAP_SELFILLUM",13) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+13)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=14;
|
2008-05-09 17:24:28 +00:00
|
|
|
// parse the texture block
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3MapBlock(mat.sTexEmissive);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// bump map
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MAP_BUMP",8) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+8)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=9;
|
2008-05-09 17:24:28 +00:00
|
|
|
// parse the texture block
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3MapBlock(mat.sTexBump);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// specular/shininess map
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MAP_SHINESTRENGTH",17) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+17)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=18;
|
2008-05-09 17:24:28 +00:00
|
|
|
// parse the texture block
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3MapBlock(mat.sTexShininess);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// number of submaterials
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"NUMSUBMTLS",10) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+10)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=11;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iNumSubMaterials);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// allocate enough storage
|
|
|
|
mat.avSubMaterials.resize(iNumSubMaterials);
|
|
|
|
}
|
|
|
|
// submaterial chunks
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"SUBMATERIAL",11) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+11)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=12;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
unsigned int iIndex = 0;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iIndex);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
if (iIndex >= iNumSubMaterials)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Out of range: submaterial index is too large");
|
2008-05-09 17:24:28 +00:00
|
|
|
iIndex = iNumSubMaterials-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get a reference to the material
|
|
|
|
Material& sMat = mat.avSubMaterials[iIndex];
|
|
|
|
|
|
|
|
// parse the material block
|
2008-09-27 16:46:05 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3MapBlock(Texture& map)
|
|
|
|
{
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
2008-05-09 17:24:28 +00:00
|
|
|
// path to the texture
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"BITMAP" ,6) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+6)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=7;
|
2008-09-27 16:46:05 +00:00
|
|
|
if(!ParseString(map.mMapName,"*BITMAP"))SkipToNextToken();
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// offset on the u axis
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"UVW_U_OFFSET" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+12)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=13;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloat(map.mOffsetU);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// offset on the v axis
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"UVW_V_OFFSET" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+12)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=13;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloat(map.mOffsetV);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// tiling on the u axis
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"UVW_U_TILING" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+12)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=13;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloat(map.mScaleU);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// tiling on the v axis
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"UVW_V_TILING" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+12)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=13;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloat(map.mScaleV);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// rotation around the z-axis
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"UVW_ANGLE" ,9) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+9)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=10;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloat(map.mRotation);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// map blending factor
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MAP_AMOUNT" ,10) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+10)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=9;
|
2008-09-27 16:46:05 +00:00
|
|
|
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-09-27 16:46:05 +00:00
|
|
|
if (!SkipSpaces(&m_szFile))
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
|
|
|
sprintf(szBuffer,"Unable to parse %s block: Unexpected EOL",szName);
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning(szBuffer);
|
2008-05-28 21:05:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// there must be "
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('\"' != *m_szFile)
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
sprintf(szBuffer,"Unable to parse %s block: Strings are expected "
|
2008-05-28 21:05:05 +00:00
|
|
|
"to be enclosed in double quotation marks",szName);
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning(szBuffer);
|
2008-05-28 21:05:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
++m_szFile;
|
|
|
|
const char* sz = m_szFile;
|
2008-05-28 21:05:05 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if ('\"' == *sz)break;
|
|
|
|
else if ('\0' == sz)
|
2008-08-08 23:58:40 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
sprintf(szBuffer,"Unable to parse %s block: Strings are expected to be "
|
2008-05-28 21:05:05 +00:00
|
|
|
"enclosed in double quotation marks but EOF was reached before a closing "
|
|
|
|
"quotation mark was found",szName);
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning(szBuffer);
|
2008-05-28 21:05:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
sz++;
|
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
out = std::string(m_szFile,(uintptr_t)sz-(uintptr_t)m_szFile);
|
|
|
|
m_szFile = sz;
|
2008-05-28 21:05:05 +00:00
|
|
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
2008-05-09 17:24:28 +00:00
|
|
|
// name of the mesh/node
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"NODE_NAME" ,9) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+9)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=10;
|
2008-09-27 16:46:05 +00:00
|
|
|
if(!ParseString(mesh.mName,"*NODE_NAME"))SkipToNextToken();
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
// name of the parent of the node
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"NODE_PARENT" ,11) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+11)))
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=12;
|
2008-09-27 16:46:05 +00:00
|
|
|
if(!ParseString(mesh.mParent,"*NODE_PARENT"))SkipToNextToken();
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// transformation matrix of the node
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"NODE_TM" ,7) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+7)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=8;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV2NodeTransformBlock(mesh);continue;
|
2008-08-09 22:39:57 +00:00
|
|
|
//mesh.mTransform.Transpose();
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh data
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH" ,4) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+4)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=5;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV2MeshBlock(mesh);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-05-28 21:05:05 +00:00
|
|
|
// mesh material index
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MATERIAL_REF" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+12)))
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=13;
|
2008-09-27 16:46:05 +00:00
|
|
|
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
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"TM_ANIMATION" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+12)))
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=13;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV2AnimationBlock(mesh);continue;
|
2008-07-18 20:29:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
AI_ASE_HANDLE_TOP_LEVEL_SECTION(iDepth);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV2AnimationBlock(ASE::Mesh& mesh)
|
|
|
|
{
|
|
|
|
int iDepth = 0;
|
|
|
|
while (true)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
2008-07-18 20:29:46 +00:00
|
|
|
// position keyframes
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"CONTROL_POS_TRACK" ,17) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+17)))
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=18;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3PosAnimationBlock(mesh);continue;
|
2008-07-18 20:29:46 +00:00
|
|
|
}
|
|
|
|
// rotation keyframes
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"CONTROL_ROT_TRACK" ,17) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+17)))
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=18;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3RotAnimationBlock(mesh);continue;
|
2008-07-18 20:29:46 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
2008-07-18 20:29:46 +00:00
|
|
|
// position keyframe
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"CONTROL_POS_SAMPLE" ,18) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+18)))
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=19;
|
2008-07-18 20:29:46 +00:00
|
|
|
|
|
|
|
unsigned int iIndex;
|
|
|
|
mesh.mAnim.akeyPositions.push_back(aiVectorKey());
|
|
|
|
aiVectorKey& key = mesh.mAnim.akeyPositions.back();
|
|
|
|
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple(&key.mValue.x,iIndex);
|
2008-07-18 20:29:46 +00:00
|
|
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
2008-07-18 20:29:46 +00:00
|
|
|
// rotation keyframe
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"CONTROL_ROT_SAMPLE" ,18) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+18)))
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=19;
|
2008-07-18 20:29:46 +00:00
|
|
|
|
|
|
|
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;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple(&v.x,iIndex);
|
|
|
|
ParseLV4MeshFloat(f);
|
2008-07-18 20:29:46 +00:00
|
|
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
2008-05-09 17:24:28 +00:00
|
|
|
// first row of the transformation matrix
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"TM_ROW0" ,7) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+7)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=8;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple(mesh.mTransform[0]);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// second row of the transformation matrix
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"TM_ROW1" ,7) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+7)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=8;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple(mesh.mTransform[1]);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// third row of the transformation matrix
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"TM_ROW2" ,7) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+7)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=8;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple(mesh.mTransform[2]);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// fourth row of the transformation matrix
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"TM_ROW3" ,7) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+7)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=8;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple(mesh.mTransform[3]);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-07-18 20:29:46 +00:00
|
|
|
// inherited position axes
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"INHERIT_POS" ,11) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+11)))
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=12;
|
2008-07-18 20:29:46 +00:00
|
|
|
unsigned int aiVal[3];
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLongTriple(aiVal);
|
2008-07-18 20:29:46 +00:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 3;++i)
|
|
|
|
mesh.inherit.abInheritPosition[i] = aiVal[i] != 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// inherited rotation axes
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"INHERIT_ROT" ,11) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+11)))
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=12;
|
2008-07-18 20:29:46 +00:00
|
|
|
unsigned int aiVal[3];
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLongTriple(aiVal);
|
2008-07-18 20:29:46 +00:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 3;++i)
|
|
|
|
mesh.inherit.abInheritRotation[i] = aiVal[i] != 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// inherited scaling axes
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"INHERIT_SCL" ,11) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+11)))
|
2008-07-18 20:29:46 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=12;
|
2008-07-18 20:29:46 +00:00
|
|
|
unsigned int aiVal[3];
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLongTriple(aiVal);
|
2008-07-18 20:29:46 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
2008-05-09 17:24:28 +00:00
|
|
|
// Number of vertices in the mesh
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_NUMVERTEX" ,14) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+14)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=15;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iNumVertices);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// Number of texture coordinates in the mesh
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_NUMTVERTEX" ,15) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+15)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=16;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iNumTVertices);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// Number of vertex colors in the mesh
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_NUMCVERTEX" ,14) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+14)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=15;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iNumCVertices);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// Number of regular faces in the mesh
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_NUMFACES" ,13) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+13)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=14;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iNumFaces);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// Number of UVWed faces in the mesh
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_NUMTVFACES" ,15) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+15)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=16;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iNumTFaces);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// Number of colored faces in the mesh
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_NUMCVFACES" ,15) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+15)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=16;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iNumCFaces);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh vertex list block
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_VERTEX_LIST" ,16) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+16)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=17;
|
2008-09-27 16:46:05 +00:00
|
|
|
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-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_FACE_LIST" ,14) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+14)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=15;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3MeshFaceListBlock(iNumFaces,mesh);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh texture vertex list block
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_TVERTLIST" ,14) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+14)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=15;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3MeshTListBlock(iNumTVertices,mesh);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh texture face block
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_TFACELIST" ,14) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+14)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=15;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3MeshTFaceListBlock(iNumTFaces,mesh);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh color vertex list block
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_CVERTLIST" ,14) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+14)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=15;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3MeshCListBlock(iNumCVertices,mesh);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh color face block
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_CFACELIST" ,14) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+14)))
|
2008-09-27 16:46:05 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=15;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3MeshCFaceListBlock(iNumCFaces,mesh);continue;
|
|
|
|
}
|
|
|
|
// mesh normals
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_NORMALS" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+12)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=13;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3MeshNormalListBlock(mesh);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// another mesh UV channel ...
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_MAPPINGCHANNEL" ,19) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+19)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=20;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
unsigned int iIndex = 0;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iIndex);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
if (iIndex < 2)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Mapping channel has an invalid index. Skipping UV channel");
|
2008-05-09 17:24:28 +00:00
|
|
|
// skip it ...
|
2008-09-27 16:46:05 +00:00
|
|
|
SkipSection();
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
if (iIndex > AI_MAX_NUMBER_OF_TEXTURECOORDS)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Too many UV channels specified. Skipping channel ..");
|
2008-05-09 17:24:28 +00:00
|
|
|
// skip it ...
|
2008-09-27 16:46:05 +00:00
|
|
|
SkipSection();
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// parse the mapping channel
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV3MappingChannel(iIndex-1,mesh);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
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-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_ANIMATION" ,14) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+14)))
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=15;
|
2008-05-28 21:05:05 +00:00
|
|
|
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Found *MESH_ANIMATION element in ASE/ASK file. "
|
2008-05-28 21:05:05 +00:00
|
|
|
"Keyframe animation is not supported by Assimp, this element "
|
|
|
|
"will be ignored");
|
2008-09-27 16:46:05 +00:00
|
|
|
//SkipSection();
|
2008-05-30 23:01:25 +00:00
|
|
|
continue;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
// mesh animation keyframe. Not supported
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_WEIGHTS" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+12)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=13;
|
2008-09-27 16:46:05 +00:00
|
|
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
|
|
|
|
2008-05-28 21:05:05 +00:00
|
|
|
// Number of bone vertices ...
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_NUMVERTEX" ,14) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+14)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=15;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iNumVertices);continue;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
// Number of bones
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_NUMBONE" ,11) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+11)))
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=12;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iNumBones);continue;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
// parse the list of bones
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_BONE_LIST" ,14) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+14)))
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=15;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshBones(iNumBones,mesh);continue;
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
|
|
|
// parse the list of bones vertices
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_BONE_VERTEX_LIST" ,21) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+21)))
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=22;
|
2008-09-27 16:46:05 +00:00
|
|
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
|
|
|
|
2008-05-28 21:05:05 +00:00
|
|
|
// Mesh bone with name ...
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_BONE_NAME" ,16) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+16)))
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=17;
|
2008-05-28 21:05:05 +00:00
|
|
|
|
|
|
|
// parse an index ...
|
2008-09-27 16:46:05 +00:00
|
|
|
if(SkipSpaces(&m_szFile))
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
unsigned int iIndex = strtol10(m_szFile,&m_szFile);
|
2008-05-28 21:05:05 +00:00
|
|
|
if (iIndex >= iNumBones)
|
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
continue;
|
|
|
|
LogWarning("Bone index is out of bounds");
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
if (!ParseString(mesh.mBones[iIndex].mName,"*MESH_BONE_NAME"))
|
|
|
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
|
|
|
|
2008-05-28 21:05:05 +00:00
|
|
|
// Mesh bone vertex
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_BONE_VERTEX" ,16) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+16)))
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=17;
|
2008-05-28 21:05:05 +00:00
|
|
|
|
|
|
|
// read the vertex index
|
2008-09-27 16:46:05 +00:00
|
|
|
unsigned int iIndex = strtol10(m_szFile,&m_szFile);
|
2008-05-28 21:05:05 +00:00
|
|
|
if (iIndex >= mesh.mPositions.size())
|
|
|
|
{
|
2008-06-01 12:46:17 +00:00
|
|
|
iIndex = (unsigned int)mesh.mPositions.size()-1;
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Bone vertex index is out of bounds. Using the largest valid "
|
2008-05-28 21:05:05 +00:00
|
|
|
"bone vertex index instead");
|
|
|
|
}
|
|
|
|
|
2008-09-30 20:20:56 +00:00
|
|
|
// --- ignored
|
2008-05-28 21:05:05 +00:00
|
|
|
float afVert[3];
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple(afVert);
|
2008-05-28 21:05:05 +00:00
|
|
|
|
|
|
|
std::pair<int,float> pairOut;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
// first parse the bone index ...
|
2008-09-27 16:46:05 +00:00
|
|
|
if (!SkipSpaces(&m_szFile))break;
|
|
|
|
pairOut.first = strtol10(m_szFile,&m_szFile);
|
2008-05-28 21:05:05 +00:00
|
|
|
|
|
|
|
// then parse the vertex weight
|
2008-09-27 16:46:05 +00:00
|
|
|
if (!SkipSpaces(&m_szFile))break;
|
|
|
|
m_szFile = fast_atof_move(m_szFile,pairOut.second);
|
2008-05-28 21:05:05 +00:00
|
|
|
|
|
|
|
// -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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// Vertex entry
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_VERTEX" ,11) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+11)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=12;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
aiVector3D vTemp;
|
|
|
|
unsigned int iIndex;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple(&vTemp.x,iIndex);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
if (iIndex >= iNumVertices)
|
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
LogWarning("Invalid vertex index. It will be ignored");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// Face entry
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_FACE" ,9) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+9)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=10;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
ASE::Face mFace;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFace(mFace);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
if (mFace.iFace >= iNumFaces)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Face has an invalid index. It will be ignored");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// Vertex entry
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_TVERT" ,10) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+10)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=11;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
aiVector3D vTemp;
|
|
|
|
unsigned int iIndex;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple(&vTemp.x,iIndex);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
if (iIndex >= iNumVertices)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Tvertex has an invalid index. It will be ignored");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// Face entry
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_TFACE" ,11) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+11)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=12;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
unsigned int aiValues[3];
|
|
|
|
unsigned int iIndex = 0;
|
|
|
|
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLongTriple(aiValues,iIndex);
|
2008-05-09 17:24:28 +00:00
|
|
|
if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size())
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("UV-Face has an invalid index. It will be ignored");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// Number of texture coordinates in the mesh
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_NUMTVERTEX" ,15) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+15)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=16;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iNumTVertices);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// Number of UVWed faces in the mesh
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_NUMTVFACES" ,15) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+15)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=16;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLong(iNumTFaces);continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// mesh texture vertex list block
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_TVERTLIST" ,14) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+14)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=15;
|
2008-09-27 16:46:05 +00:00
|
|
|
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-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_TFACELIST" ,14) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+14)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=15;
|
2008-09-27 16:46:05 +00:00
|
|
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// Vertex entry
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_VERTCOL" ,12) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+12)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=13;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
aiColor4D vTemp;
|
|
|
|
vTemp.a = 1.0f;
|
|
|
|
unsigned int iIndex;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple(&vTemp.r,iIndex);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
if (iIndex >= iNumVertices)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Vertex color has an invalid index. It will be ignored");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// Face entry
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_CFACE" ,11) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+11)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile+=12;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
unsigned int aiValues[3];
|
|
|
|
unsigned int iIndex = 0;
|
|
|
|
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLongTriple(aiValues,iIndex);
|
2008-05-09 17:24:28 +00:00
|
|
|
if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size())
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("UV-Face has an invalid index. It will be ignored");
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
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
|
2008-09-27 16:46:05 +00:00
|
|
|
sMesh.mNormals.resize(sMesh.mPositions.size(),aiVector3D( 0.f, 0.f, 0.f ));
|
2008-05-23 22:38:35 +00:00
|
|
|
int iDepth = 0;
|
2008-09-27 16:46:05 +00:00
|
|
|
unsigned int iIndex = 0;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-09-27 16:46:05 +00:00
|
|
|
// just smooth both vertex and face normals together, so it will still
|
|
|
|
// work if one oneof the two is missing ...
|
2008-09-30 20:20:56 +00:00
|
|
|
// TODO: find out why many models have invalid normals ... some docs
|
|
|
|
// say ASE normals needn't be orthonormal, so it could be it is OK
|
2008-05-09 17:24:28 +00:00
|
|
|
while (true)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
++m_szFile;
|
|
|
|
|
|
|
|
if (0 == strncmp(m_szFile,"MESH_VERTEXNORMAL",17) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+17)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile += 18;
|
2008-05-09 17:24:28 +00:00
|
|
|
aiVector3D vNormal;
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple(&vNormal.x,iIndex);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
if (iIndex >= sMesh.mNormals.size())
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Normal index is too large");
|
|
|
|
continue;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
sMesh.mNormals[iIndex] += vNormal;
|
|
|
|
continue;
|
|
|
|
}
|
2008-09-30 20:20:56 +00:00
|
|
|
if (0 == strncmp(m_szFile,"MESH_FACENORMAL",15) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+15)))
|
2008-09-27 16:46:05 +00:00
|
|
|
{
|
2008-09-30 20:20:56 +00:00
|
|
|
m_szFile += 16;
|
2008-09-27 16:46:05 +00:00
|
|
|
aiVector3D vNormal;
|
|
|
|
ParseLV4MeshFloatTriple(&vNormal.x,iIndex);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-09-27 16:46:05 +00:00
|
|
|
if (iIndex >= sMesh.mFaces.size())
|
|
|
|
{
|
|
|
|
LogWarning("Face normal index is too large");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (unsigned int i = 0; i<3; ++i)
|
|
|
|
{
|
|
|
|
sMesh.mNormals[sMesh.mFaces[iIndex].mIndices[i]] += 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
|
2008-09-27 16:46:05 +00:00
|
|
|
if(!SkipSpaces(&m_szFile))
|
2008-06-03 21:50:53 +00:00
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL [#1]");
|
|
|
|
SkipToNextToken();
|
2008-06-03 21:50:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// parse the face index
|
2008-09-27 16:46:05 +00:00
|
|
|
out.iFace = strtol10(m_szFile,&m_szFile);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// next character should be ':'
|
2008-09-27 16:46:05 +00:00
|
|
|
if(!SkipSpaces(&m_szFile))
|
2008-06-03 21:50:53 +00:00
|
|
|
{
|
|
|
|
// FIX: there are some ASE files which haven't got : here ....
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. \':\' expected [#2]");
|
|
|
|
SkipToNextToken();
|
2008-06-03 21:50:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// FIX: there are some ASE files which haven't got : here ....
|
2008-09-27 16:46:05 +00:00
|
|
|
if(':' == *m_szFile)++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;
|
2008-09-27 16:46:05 +00:00
|
|
|
if(!SkipSpaces(&m_szFile))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
// LOG
|
|
|
|
__EARTHQUAKE_XXL:
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. "
|
2008-06-03 21:50:53 +00:00
|
|
|
"A,B or C expected [#3]");
|
2008-09-27 16:46:05 +00:00
|
|
|
SkipToNextToken();
|
2008-06-03 21:50:53 +00:00
|
|
|
return;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
switch (*m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
case 'A':
|
|
|
|
case 'a':
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
case 'b':
|
|
|
|
iIndex = 1;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
case 'c':
|
|
|
|
iIndex = 2;
|
|
|
|
break;
|
|
|
|
default: goto __EARTHQUAKE_XXL;
|
|
|
|
};
|
2008-09-27 16:46:05 +00:00
|
|
|
++m_szFile;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// next character should be ':'
|
2008-09-27 16:46:05 +00:00
|
|
|
if(!SkipSpaces(&m_szFile) || ':' != *m_szFile)
|
2008-06-03 21:50:53 +00:00
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Unable to parse *MESH_FACE Element: "
|
2008-06-03 21:50:53 +00:00
|
|
|
"Unexpected EOL. \':\' expected [#2]");
|
2008-09-27 16:46:05 +00:00
|
|
|
SkipToNextToken();
|
2008-06-03 21:50:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-09-27 16:46:05 +00:00
|
|
|
++m_szFile;
|
|
|
|
if(!SkipSpaces(&m_szFile))
|
2008-06-03 21:50:53 +00:00
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. "
|
2008-06-03 21:50:53 +00:00
|
|
|
"Vertex index ecpected [#4]");
|
2008-09-27 16:46:05 +00:00
|
|
|
SkipToNextToken();
|
2008-06-03 21:50:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
out.mIndices[iIndex] = strtol10(m_szFile,&m_szFile);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// now we need to skip the AB, BC, CA blocks.
|
|
|
|
while (true)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)break;
|
|
|
|
if (IsLineEnd(*m_szFile))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
//iLineNumber++;
|
2008-05-09 17:24:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
m_szFile++;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// parse the smoothing group of the face
|
2008-09-27 16:46:05 +00:00
|
|
|
if (0 == strncmp(m_szFile,"*MESH_SMOOTHING",15) &&
|
|
|
|
IsSpaceOrNewLine(*(m_szFile+15)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
m_szFile+=16;
|
|
|
|
if(!SkipSpaces(&m_szFile))
|
2008-06-03 21:50:53 +00:00
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Unable to parse *MESH_SMOOTHING Element: "
|
2008-06-03 21:50:53 +00:00
|
|
|
"Unexpected EOL. Smoothing group(s) expected [#5]");
|
2008-09-27 16:46:05 +00:00
|
|
|
SkipToNextToken();
|
2008-06-03 21:50:53 +00:00
|
|
|
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-09-27 16:46:05 +00:00
|
|
|
if (*m_szFile < '9' && *m_szFile >= '0')
|
2008-05-28 21:05:05 +00:00
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
out.iSmoothGroup |= (1 << strtol10(m_szFile,&m_szFile));
|
2008-05-28 21:05:05 +00:00
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
SkipSpaces(&m_szFile);
|
|
|
|
if (',' != *m_szFile)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
++m_szFile;
|
|
|
|
SkipSpaces(&m_szFile);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// *MESH_MTLID is optional, too
|
|
|
|
while (true)
|
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
if ('*' == *m_szFile)break;
|
|
|
|
if (IsLineEnd(*m_szFile))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
//iLineNumber++;
|
2008-05-09 17:24:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
m_szFile++;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
|
2008-09-27 16:46:05 +00:00
|
|
|
if (0 == strncmp(m_szFile,"*MESH_MTLID",11) && IsSpaceOrNewLine(*(m_szFile+11)))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
m_szFile+=12;
|
|
|
|
if(!SkipSpaces(&m_szFile))
|
2008-06-03 21:50:53 +00:00
|
|
|
{
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Unable to parse *MESH_MTLID Element: Unexpected EOL. "
|
2008-06-03 21:50:53 +00:00
|
|
|
"Material index expected [#6]");
|
2008-09-27 16:46:05 +00:00
|
|
|
SkipToNextToken();
|
2008-06-03 21:50:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-09-27 16:46:05 +00:00
|
|
|
out.iMaterial = strtol10(m_szFile,&m_szFile);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
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-08-28 17:35:36 +00:00
|
|
|
ParseLV4MeshLong(apOut[i]);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV4MeshLongTriple(unsigned int* apOut, unsigned int& rIndexOut)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != apOut);
|
|
|
|
|
|
|
|
// parse the index
|
2008-08-28 17:35:36 +00:00
|
|
|
ParseLV4MeshLong(rIndexOut);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// parse the three others
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshLongTriple(apOut);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV4MeshFloatTriple(float* apOut, unsigned int& rIndexOut)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != apOut);
|
|
|
|
|
|
|
|
// parse the index
|
2008-08-28 17:35:36 +00:00
|
|
|
ParseLV4MeshLong(rIndexOut);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// parse the three others
|
2008-09-27 16:46:05 +00:00
|
|
|
ParseLV4MeshFloatTriple(apOut);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
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-08-28 17:35:36 +00:00
|
|
|
ParseLV4MeshFloat(apOut[i]);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV4MeshFloat(float& fOut)
|
|
|
|
{
|
|
|
|
// skip spaces and tabs
|
2008-09-27 16:46:05 +00:00
|
|
|
if(!SkipSpaces(&m_szFile))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
// LOG
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Unable to parse float: unexpected EOL [#1]");
|
2008-05-09 17:24:28 +00:00
|
|
|
fOut = 0.0f;
|
2008-09-27 16:46:05 +00:00
|
|
|
++iLineNumber;
|
2008-05-09 17:24:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// parse the first float
|
2008-09-27 16:46:05 +00:00
|
|
|
m_szFile = fast_atof_move(m_szFile,fOut);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV4MeshLong(unsigned int& iOut)
|
|
|
|
{
|
|
|
|
// skip spaces and tabs
|
2008-09-27 16:46:05 +00:00
|
|
|
if(!SkipSpaces(&m_szFile))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
// LOG
|
2008-09-27 16:46:05 +00:00
|
|
|
LogWarning("Unable to parse long: unexpected EOL [#1]");
|
2008-05-09 17:24:28 +00:00
|
|
|
iOut = 0;
|
2008-09-27 16:46:05 +00:00
|
|
|
++iLineNumber;
|
2008-05-09 17:24:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// parse the value
|
2008-09-27 16:46:05 +00:00
|
|
|
iOut = strtol10(m_szFile,&m_szFile);
|
2008-09-12 20:25:11 +00:00
|
|
|
}
|