2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2021-02-28 11:17:54 +00:00
|
|
|
Copyright (c) 2006-2021, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2017-05-09 17:57:36 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
2015-05-19 03:48:29 +00:00
|
|
|
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 team.
|
|
|
|
|
2016-08-29 16:23:41 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 03:52:10 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 03:48:29 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 03:52:10 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 03:52:10 +00:00
|
|
|
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
|
2015-05-19 03:48:29 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file ASEParser.cpp
|
2015-05-19 03:52:10 +00:00
|
|
|
* @brief Implementation of the ASE parser class
|
2015-05-19 03:48:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ASSIMP_BUILD_NO_ASE_IMPORTER
|
2017-06-26 20:01:15 +00:00
|
|
|
#ifndef ASSIMP_BUILD_NO_3DS_IMPORTER
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// internal headers
|
|
|
|
#include "ASELoader.h"
|
2020-05-02 13:14:38 +00:00
|
|
|
#include "PostProcessing/TextureTransform.h"
|
2019-06-10 21:26:00 +00:00
|
|
|
|
2018-01-06 00:18:33 +00:00
|
|
|
#include <assimp/fast_atof.h>
|
2016-06-06 20:04:29 +00:00
|
|
|
#include <assimp/DefaultLogger.hpp>
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
using namespace Assimp::ASE;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Begin an ASE parsing function
|
|
|
|
|
|
|
|
#define AI_ASE_PARSER_INIT() \
|
2015-05-19 03:57:13 +00:00
|
|
|
int iDepth = 0;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Handle a "top-level" section in the file. EOF is no error in this case.
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
#define AI_ASE_HANDLE_TOP_LEVEL_SECTION() \
|
|
|
|
else if ('{' == *filePtr) iDepth++; \
|
|
|
|
else if ('}' == *filePtr) { \
|
|
|
|
if (0 == --iDepth) { \
|
|
|
|
++filePtr; \
|
|
|
|
SkipToNextToken(); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
else if ('\0' == *filePtr) { \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
if (IsLineEnd(*filePtr) && !bLastWasEndLine) { \
|
|
|
|
++iLineNumber; \
|
|
|
|
bLastWasEndLine = true; \
|
|
|
|
} else \
|
|
|
|
bLastWasEndLine = false; \
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Handle a nested section in the file. EOF is an error in this case
|
|
|
|
// @param level "Depth" of the section
|
|
|
|
// @param msg Full name of the section (including the asterisk)
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
#define AI_ASE_HANDLE_SECTION(level, msg) \
|
|
|
|
if ('{' == *filePtr) \
|
|
|
|
iDepth++; \
|
|
|
|
else if ('}' == *filePtr) { \
|
|
|
|
if (0 == --iDepth) { \
|
|
|
|
++filePtr; \
|
|
|
|
SkipToNextToken(); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} else if ('\0' == *filePtr) { \
|
2015-05-19 03:57:13 +00:00
|
|
|
LogError("Encountered unexpected EOL while parsing a " msg \
|
2020-05-02 13:14:38 +00:00
|
|
|
" chunk (Level " level ")"); \
|
|
|
|
} \
|
|
|
|
if (IsLineEnd(*filePtr) && !bLastWasEndLine) { \
|
|
|
|
++iLineNumber; \
|
|
|
|
bLastWasEndLine = true; \
|
|
|
|
} else \
|
|
|
|
bLastWasEndLine = false; \
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
Parser::Parser(const char *szFile, unsigned int fileFormatDefault) {
|
|
|
|
ai_assert(nullptr != szFile);
|
2015-05-19 03:57:13 +00:00
|
|
|
filePtr = szFile;
|
|
|
|
iFileFormat = fileFormatDefault;
|
|
|
|
|
|
|
|
// make sure that the color values are invalid
|
|
|
|
m_clrBackground.r = get_qnan();
|
2020-05-02 13:14:38 +00:00
|
|
|
m_clrAmbient.r = get_qnan();
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// setup some default values
|
|
|
|
iLineNumber = 0;
|
|
|
|
iFirstFrame = 0;
|
|
|
|
iLastFrame = 0;
|
2020-05-02 13:14:38 +00:00
|
|
|
iFrameSpeed = 30; // use 30 as default value for this property
|
|
|
|
iTicksPerFrame = 1; // use 1 as default value for this property
|
2015-05-19 03:57:13 +00:00
|
|
|
bLastWasEndLine = false; // need to handle \r\n seqs due to binary file mapping
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::LogWarning(const char *szWarn) {
|
|
|
|
ai_assert(nullptr != szWarn);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-04-28 05:39:13 +00:00
|
|
|
char szTemp[2048];
|
2015-05-19 03:48:29 +00:00
|
|
|
#if _MSC_VER >= 1400
|
2020-05-02 13:14:38 +00:00
|
|
|
sprintf_s(szTemp, "Line %u: %s", iLineNumber, szWarn);
|
2015-05-19 03:48:29 +00:00
|
|
|
#else
|
2020-05-02 13:14:38 +00:00
|
|
|
ai_snprintf(szTemp, sizeof(szTemp), "Line %u: %s", iLineNumber, szWarn);
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// output the warning to the logger ...
|
2018-04-19 14:48:43 +00:00
|
|
|
ASSIMP_LOG_WARN(szTemp);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::LogInfo(const char *szWarn) {
|
|
|
|
ai_assert(nullptr != szWarn);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
char szTemp[1024];
|
2015-05-19 03:48:29 +00:00
|
|
|
#if _MSC_VER >= 1400
|
2020-05-02 13:14:38 +00:00
|
|
|
sprintf_s(szTemp, "Line %u: %s", iLineNumber, szWarn);
|
2015-05-19 03:48:29 +00:00
|
|
|
#else
|
2020-05-02 13:14:38 +00:00
|
|
|
ai_snprintf(szTemp, 1024, "Line %u: %s", iLineNumber, szWarn);
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// output the information to the logger ...
|
2018-04-19 14:48:43 +00:00
|
|
|
ASSIMP_LOG_INFO(szTemp);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_WONT_RETURN void Parser::LogError(const char *szWarn) {
|
|
|
|
ai_assert(nullptr != szWarn);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
char szTemp[1024];
|
2015-05-19 03:48:29 +00:00
|
|
|
#if _MSC_VER >= 1400
|
2020-05-02 13:14:38 +00:00
|
|
|
sprintf_s(szTemp, "Line %u: %s", iLineNumber, szWarn);
|
2015-05-19 03:48:29 +00:00
|
|
|
#else
|
2020-05-02 13:14:38 +00:00
|
|
|
ai_snprintf(szTemp, 1024, "Line %u: %s", iLineNumber, szWarn);
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// throw an exception
|
|
|
|
throw DeadlyImportError(szTemp);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
bool Parser::SkipToNextToken() {
|
|
|
|
while (true) {
|
2015-05-19 03:57:13 +00:00
|
|
|
char me = *filePtr;
|
|
|
|
|
|
|
|
// increase the line number counter if necessary
|
2020-05-02 13:14:38 +00:00
|
|
|
if (IsLineEnd(me) && !bLastWasEndLine) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++iLineNumber;
|
|
|
|
bLastWasEndLine = true;
|
2020-05-02 13:14:38 +00:00
|
|
|
} else
|
|
|
|
bLastWasEndLine = false;
|
|
|
|
if ('*' == me || '}' == me || '{' == me) return true;
|
|
|
|
if ('\0' == me) return false;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
++filePtr;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
bool Parser::SkipSection() {
|
2015-05-19 03:57:13 +00:00
|
|
|
// must handle subsections ...
|
|
|
|
int iCnt = 0;
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('}' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
--iCnt;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (0 == iCnt) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// go to the next valid token ...
|
|
|
|
++filePtr;
|
|
|
|
SkipToNextToken();
|
|
|
|
return true;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
} else if ('{' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++iCnt;
|
2020-05-02 13:14:38 +00:00
|
|
|
} else if ('\0' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Unable to parse block: Unexpected EOF, closing bracket \'}\' was expected [#1]");
|
|
|
|
return false;
|
2020-05-02 13:14:38 +00:00
|
|
|
} else if (IsLineEnd(*filePtr))
|
|
|
|
++iLineNumber;
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::Parse() {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
// Version should be 200. Validate this ...
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "3DSMAX_ASCIIEXPORT", 18)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int fmt;
|
|
|
|
ParseLV4MeshLong(fmt);
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
if (fmt > 200) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Unknown file format version: *3DSMAX_ASCIIEXPORT should \
|
|
|
|
be <= 200");
|
|
|
|
}
|
|
|
|
// *************************************************************
|
|
|
|
// - fmt will be 0 if we're unable to read the version number
|
|
|
|
// there are some faulty files without a version number ...
|
|
|
|
// in this case we'll guess the exact file format by looking
|
|
|
|
// at the file extension (ASE, ASK, ASC)
|
|
|
|
// *************************************************************
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
if (fmt) {
|
2018-03-20 17:43:54 +00:00
|
|
|
iFileFormat = fmt;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// main scene information
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "SCENE", 5)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV1SceneBlock();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// "group" - no implementation yet, in facte
|
|
|
|
// we're just ignoring them for the moment
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "GROUP", 5)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
Parse();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// material list
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MATERIAL_LIST", 13)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV1MaterialListBlock();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// geometric object (mesh)
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "GEOMOBJECT", 10))
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
{
|
2018-01-27 16:08:52 +00:00
|
|
|
m_vMeshes.push_back(Mesh("UNNAMED"));
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV1ObjectBlock(m_vMeshes.back());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// helper object = dummy in the hierarchy
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "HELPEROBJECT", 12))
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
m_vDummies.push_back(Dummy());
|
|
|
|
ParseLV1ObjectBlock(m_vDummies.back());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// light object
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "LIGHTOBJECT", 11))
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
{
|
2018-01-27 16:19:17 +00:00
|
|
|
m_vLights.push_back(Light("UNNAMED"));
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV1ObjectBlock(m_vLights.back());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// camera object
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CAMERAOBJECT", 12)) {
|
2018-01-27 16:27:41 +00:00
|
|
|
m_vCameras.push_back(Camera("UNNAMED"));
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV1ObjectBlock(m_vCameras.back());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// comment - print it on the console
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "COMMENT", 7)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string out = "<unknown>";
|
2020-05-02 13:14:38 +00:00
|
|
|
ParseString(out, "*COMMENT");
|
2015-05-19 03:57:13 +00:00
|
|
|
LogInfo(("Comment: " + out).c_str());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// ASC bone weights
|
2020-05-02 13:14:38 +00:00
|
|
|
if (AI_ASE_IS_OLD_FILE_FORMAT() && TokenMatch(filePtr, "MESH_SOFTSKINVERTS", 18)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV1SoftSkinBlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AI_ASE_HANDLE_TOP_LEVEL_SECTION();
|
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV1SoftSkinBlock() {
|
2015-05-19 03:57:13 +00:00
|
|
|
// TODO: fix line counting here
|
|
|
|
|
|
|
|
// **************************************************************
|
|
|
|
// The soft skin block is formatted differently. There are no
|
|
|
|
// nested sections supported and the single elements aren't
|
|
|
|
// marked by keywords starting with an asterisk.
|
|
|
|
|
|
|
|
/**
|
|
|
|
FORMAT BEGIN
|
|
|
|
|
|
|
|
*MESH_SOFTSKINVERTS {
|
|
|
|
<nodename>
|
|
|
|
<number of vertices>
|
|
|
|
|
|
|
|
[for <number of vertices> times:]
|
|
|
|
<number of weights> [for <number of weights> times:] <bone name> <weight>
|
|
|
|
}
|
|
|
|
|
|
|
|
FORMAT END
|
|
|
|
*/
|
|
|
|
// **************************************************************
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if (*filePtr == '}') {
|
|
|
|
++filePtr;
|
|
|
|
return;
|
|
|
|
} else if (*filePtr == '\0')
|
|
|
|
return;
|
|
|
|
else if (*filePtr == '{')
|
|
|
|
++filePtr;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
else // if (!IsSpace(*filePtr) && !IsLineEnd(*filePtr))
|
|
|
|
{
|
2020-05-02 13:14:38 +00:00
|
|
|
ASE::Mesh *curMesh = nullptr;
|
|
|
|
unsigned int numVerts = 0;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
const char *sz = filePtr;
|
|
|
|
while (!IsSpaceOrNewLine(*filePtr))
|
|
|
|
++filePtr;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
const unsigned int diff = (unsigned int)(filePtr - sz);
|
|
|
|
if (diff) {
|
|
|
|
std::string name = std::string(sz, diff);
|
2015-05-19 03:57:13 +00:00
|
|
|
for (std::vector<ASE::Mesh>::iterator it = m_vMeshes.begin();
|
2020-05-02 13:14:38 +00:00
|
|
|
it != m_vMeshes.end(); ++it) {
|
|
|
|
if ((*it).mName == name) {
|
|
|
|
curMesh = &(*it);
|
2015-05-19 03:57:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!curMesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Encountered unknown mesh in *MESH_SOFTSKINVERTS section");
|
|
|
|
|
|
|
|
// Skip the mesh data - until we find a new mesh
|
|
|
|
// or the end of the *MESH_SOFTSKINVERTS section
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipSpacesAndLineEnd(&filePtr);
|
2020-05-02 13:14:38 +00:00
|
|
|
if (*filePtr == '}') {
|
|
|
|
++filePtr;
|
|
|
|
return;
|
|
|
|
} else if (!IsNumeric(*filePtr))
|
2015-05-19 03:57:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
SkipLine(&filePtr);
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
} else {
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipSpacesAndLineEnd(&filePtr);
|
|
|
|
ParseLV4MeshLong(numVerts);
|
|
|
|
|
|
|
|
// Reserve enough storage
|
|
|
|
curMesh->mBoneVertices.reserve(numVerts);
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
for (unsigned int i = 0; i < numVerts; ++i) {
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipSpacesAndLineEnd(&filePtr);
|
|
|
|
unsigned int numWeights;
|
|
|
|
ParseLV4MeshLong(numWeights);
|
|
|
|
|
|
|
|
curMesh->mBoneVertices.push_back(ASE::BoneVertex());
|
2020-05-02 13:14:38 +00:00
|
|
|
ASE::BoneVertex &vert = curMesh->mBoneVertices.back();
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// Reserve enough storage
|
|
|
|
vert.mBoneWeights.reserve(numWeights);
|
|
|
|
|
2018-03-20 17:43:54 +00:00
|
|
|
std::string bone;
|
2020-05-02 13:14:38 +00:00
|
|
|
for (unsigned int w = 0; w < numWeights; ++w) {
|
2018-03-20 17:43:54 +00:00
|
|
|
bone.clear();
|
2020-05-02 13:14:38 +00:00
|
|
|
ParseString(bone, "*MESH_SOFTSKINVERTS.Bone");
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// Find the bone in the mesh's list
|
2020-05-02 13:14:38 +00:00
|
|
|
std::pair<int, ai_real> me;
|
2015-05-19 03:57:13 +00:00
|
|
|
me.first = -1;
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
for (unsigned int n = 0; n < curMesh->mBones.size(); ++n) {
|
2018-03-20 17:43:54 +00:00
|
|
|
if (curMesh->mBones[n].mName == bone) {
|
2015-05-19 03:57:13 +00:00
|
|
|
me.first = n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-03-20 17:43:54 +00:00
|
|
|
if (-1 == me.first) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// We don't have this bone yet, so add it to the list
|
2020-05-02 13:14:38 +00:00
|
|
|
me.first = static_cast<int>(curMesh->mBones.size());
|
|
|
|
curMesh->mBones.push_back(ASE::Bone(bone));
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
ParseLV4MeshFloat(me.second);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// Add the new bone weight to list
|
|
|
|
vert.mBoneWeights.push_back(me);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++filePtr;
|
|
|
|
SkipSpacesAndLineEnd(&filePtr);
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV1SceneBlock() {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "SCENE_BACKGROUND_STATIC", 23))
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// parse a color triple and assume it is really the bg color
|
2020-05-02 13:14:38 +00:00
|
|
|
ParseLV4MeshFloatTriple(&m_clrBackground.r);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "SCENE_AMBIENT_STATIC", 20))
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// parse a color triple and assume it is really the bg color
|
2020-05-02 13:14:38 +00:00
|
|
|
ParseLV4MeshFloatTriple(&m_clrAmbient.r);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "SCENE_FIRSTFRAME", 16)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iFirstFrame);
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "SCENE_LASTFRAME", 15)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iLastFrame);
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "SCENE_FRAMESPEED", 16)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iFrameSpeed);
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "SCENE_TICKSPERFRAME", 19)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iTicksPerFrame);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AI_ASE_HANDLE_TOP_LEVEL_SECTION();
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV1MaterialListBlock() {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
|
|
|
|
unsigned int iMaterialCount = 0;
|
|
|
|
unsigned int iOldMaterialCount = (unsigned int)m_vMaterials.size();
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MATERIAL_COUNT", 14)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iMaterialCount);
|
|
|
|
|
|
|
|
// now allocate enough storage to hold all materials
|
2020-05-02 13:14:38 +00:00
|
|
|
m_vMaterials.resize(iOldMaterialCount + iMaterialCount, Material("INVALID"));
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MATERIAL", 8)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int iIndex = 0;
|
|
|
|
ParseLV4MeshLong(iIndex);
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
if (iIndex >= iMaterialCount) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Out of range: material index is too large");
|
2020-05-02 13:14:38 +00:00
|
|
|
iIndex = iMaterialCount - 1;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// get a reference to the material
|
2020-05-02 13:14:38 +00:00
|
|
|
Material &sMat = m_vMaterials[iIndex + iOldMaterialCount];
|
2015-05-19 03:57:13 +00:00
|
|
|
// parse the material block
|
|
|
|
ParseLV2MaterialBlock(sMat);
|
|
|
|
continue;
|
|
|
|
}
|
2021-04-30 07:37:06 +00:00
|
|
|
if( iDepth == 1 ){
|
|
|
|
// CRUDE HACK: support missing brace after "Ascii Scene Exporter v2.51"
|
|
|
|
LogWarning("Missing closing brace in material list");
|
|
|
|
--filePtr;
|
|
|
|
return;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
AI_ASE_HANDLE_TOP_LEVEL_SECTION();
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV2MaterialBlock(ASE::Material &mat) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
|
|
|
|
unsigned int iNumSubMaterials = 0;
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MATERIAL_NAME", 13)) {
|
|
|
|
if (!ParseString(mat.mName, "*MATERIAL_NAME"))
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipToNextToken();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// ambient material color
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MATERIAL_AMBIENT", 16)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloatTriple(&mat.mAmbient.r);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// diffuse material color
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MATERIAL_DIFFUSE", 16)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloatTriple(&mat.mDiffuse.r);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// specular material color
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MATERIAL_SPECULAR", 17)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloatTriple(&mat.mSpecular.r);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// material shading type
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MATERIAL_SHADING", 16)) {
|
|
|
|
if (TokenMatch(filePtr, "Blinn", 5)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
mat.mShading = Discreet3DS::Blinn;
|
2020-05-02 13:14:38 +00:00
|
|
|
} else if (TokenMatch(filePtr, "Phong", 5)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
mat.mShading = Discreet3DS::Phong;
|
2020-05-02 13:14:38 +00:00
|
|
|
} else if (TokenMatch(filePtr, "Flat", 4)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
mat.mShading = Discreet3DS::Flat;
|
2020-05-02 13:14:38 +00:00
|
|
|
} else if (TokenMatch(filePtr, "Wire", 4)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
mat.mShading = Discreet3DS::Wire;
|
2020-05-02 13:14:38 +00:00
|
|
|
} else {
|
2015-05-19 03:57:13 +00:00
|
|
|
// assume gouraud shading
|
|
|
|
mat.mShading = Discreet3DS::Gouraud;
|
|
|
|
SkipToNextToken();
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// material transparency
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MATERIAL_TRANSPARENCY", 21)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(mat.mTransparency);
|
2020-05-02 13:14:38 +00:00
|
|
|
mat.mTransparency = ai_real(1.0) - mat.mTransparency;
|
2016-11-03 17:37:02 +00:00
|
|
|
continue;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
// material self illumination
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MATERIAL_SELFILLUM", 18)) {
|
2016-07-15 05:38:29 +00:00
|
|
|
ai_real f = 0.0;
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(f);
|
|
|
|
|
|
|
|
mat.mEmissive.r = f;
|
|
|
|
mat.mEmissive.g = f;
|
|
|
|
mat.mEmissive.b = f;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// material shininess
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MATERIAL_SHINE", 14)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(mat.mSpecularExponent);
|
|
|
|
mat.mSpecularExponent *= 15;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// two-sided material
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MATERIAL_TWOSIDED", 17)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
mat.mTwoSided = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// material shininess strength
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MATERIAL_SHINESTRENGTH", 22)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(mat.mShininessStrength);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// diffuse color map
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MAP_DIFFUSE", 11)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// parse the texture block
|
|
|
|
ParseLV3MapBlock(mat.sTexDiffuse);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// ambient color map
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MAP_AMBIENT", 11)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// parse the texture block
|
|
|
|
ParseLV3MapBlock(mat.sTexAmbient);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// specular color map
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MAP_SPECULAR", 12)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// parse the texture block
|
|
|
|
ParseLV3MapBlock(mat.sTexSpecular);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// opacity map
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MAP_OPACITY", 11)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// parse the texture block
|
|
|
|
ParseLV3MapBlock(mat.sTexOpacity);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// emissive map
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MAP_SELFILLUM", 13)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// parse the texture block
|
|
|
|
ParseLV3MapBlock(mat.sTexEmissive);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// bump map
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MAP_BUMP", 8)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// parse the texture block
|
|
|
|
ParseLV3MapBlock(mat.sTexBump);
|
|
|
|
}
|
|
|
|
// specular/shininess map
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MAP_SHINESTRENGTH", 17)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// parse the texture block
|
|
|
|
ParseLV3MapBlock(mat.sTexShininess);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// number of submaterials
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "NUMSUBMTLS", 10)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iNumSubMaterials);
|
|
|
|
|
|
|
|
// allocate enough storage
|
2018-01-23 17:54:16 +00:00
|
|
|
mat.avSubMaterials.resize(iNumSubMaterials, Material("INVALID SUBMATERIAL"));
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
// submaterial chunks
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "SUBMATERIAL", 11)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
unsigned int iIndex = 0;
|
|
|
|
ParseLV4MeshLong(iIndex);
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
if (iIndex >= iNumSubMaterials) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Out of range: submaterial index is too large");
|
2020-05-02 13:14:38 +00:00
|
|
|
iIndex = iNumSubMaterials - 1;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// get a reference to the material
|
2020-05-02 13:14:38 +00:00
|
|
|
Material &sMat = mat.avSubMaterials[iIndex];
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// parse the material block
|
|
|
|
ParseLV2MaterialBlock(sMat);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("2", "*MATERIAL");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV3MapBlock(Texture &map) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
|
|
|
|
// ***********************************************************
|
|
|
|
// *BITMAP should not be there if *MAP_CLASS is not BITMAP,
|
|
|
|
// but we need to expect that case ... if the path is
|
|
|
|
// empty the texture won't be used later.
|
|
|
|
// ***********************************************************
|
|
|
|
bool parsePath = true;
|
2018-03-20 17:43:54 +00:00
|
|
|
std::string temp;
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
// type of map
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MAP_CLASS", 9)) {
|
2018-03-20 17:43:54 +00:00
|
|
|
temp.clear();
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!ParseString(temp, "*MAP_CLASS"))
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipToNextToken();
|
2020-05-02 13:14:38 +00:00
|
|
|
if (temp != "Bitmap" && temp != "Normal Bump") {
|
2021-05-13 09:25:27 +00:00
|
|
|
ASSIMP_LOG_WARN("ASE: Skipping unknown map type: ", temp);
|
2015-05-19 03:57:13 +00:00
|
|
|
parsePath = false;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// path to the texture
|
2020-05-02 13:14:38 +00:00
|
|
|
if (parsePath && TokenMatch(filePtr, "BITMAP", 6)) {
|
|
|
|
if (!ParseString(map.mMapName, "*BITMAP"))
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipToNextToken();
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
if (map.mMapName == "None") {
|
2015-05-19 03:57:13 +00:00
|
|
|
// Files with 'None' as map name are produced by
|
|
|
|
// an Maja to ASE exporter which name I forgot ..
|
2018-04-19 14:48:43 +00:00
|
|
|
ASSIMP_LOG_WARN("ASE: Skipping invalid map entry");
|
2021-04-16 21:43:56 +00:00
|
|
|
map.mMapName = std::string();
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// offset on the u axis
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "UVW_U_OFFSET", 12)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(map.mOffsetU);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// offset on the v axis
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "UVW_V_OFFSET", 12)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(map.mOffsetV);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// tiling on the u axis
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "UVW_U_TILING", 12)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(map.mScaleU);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// tiling on the v axis
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "UVW_V_TILING", 12)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(map.mScaleV);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// rotation around the z-axis
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "UVW_ANGLE", 9)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(map.mRotation);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// map blending factor
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MAP_AMOUNT", 10)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(map.mTextureBlend);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("3", "*MAP_XXXXXX");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
bool Parser::ParseString(std::string &out, const char *szName) {
|
2015-05-19 03:57:13 +00:00
|
|
|
char szBuffer[1024];
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!SkipSpaces(&filePtr)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
ai_snprintf(szBuffer, 1024, "Unable to parse %s block: Unexpected EOL", szName);
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning(szBuffer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// there must be '"'
|
2020-05-02 13:14:38 +00:00
|
|
|
if ('\"' != *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2016-01-11 20:15:30 +00:00
|
|
|
ai_snprintf(szBuffer, 1024, "Unable to parse %s block: Strings are expected "
|
2020-05-02 13:14:38 +00:00
|
|
|
"to be enclosed in double quotation marks",
|
|
|
|
szName);
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning(szBuffer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
++filePtr;
|
2020-05-02 13:14:38 +00:00
|
|
|
const char *sz = filePtr;
|
|
|
|
while (true) {
|
|
|
|
if ('\"' == *sz)
|
|
|
|
break;
|
|
|
|
else if ('\0' == *sz) {
|
2016-01-06 14:35:25 +00:00
|
|
|
ai_snprintf(szBuffer, 1024, "Unable to parse %s block: Strings are expected to "
|
2020-05-02 13:14:38 +00:00
|
|
|
"be enclosed in double quotation marks but EOF was reached before "
|
|
|
|
"a closing quotation mark was encountered",
|
|
|
|
szName);
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning(szBuffer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
sz++;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
out = std::string(filePtr, (uintptr_t)sz - (uintptr_t)filePtr);
|
|
|
|
filePtr = sz + 1;
|
2015-05-19 03:57:13 +00:00
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV1ObjectBlock(ASE::BaseNode &node) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
// first process common tokens such as node name and transform
|
|
|
|
// name of the mesh/node
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "NODE_NAME", 9)) {
|
|
|
|
if (!ParseString(node.mName, "*NODE_NAME"))
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipToNextToken();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// name of the parent of the node
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "NODE_PARENT", 11)) {
|
|
|
|
if (!ParseString(node.mParent, "*NODE_PARENT"))
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipToNextToken();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// transformation matrix of the node
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "NODE_TM", 7)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV2NodeTransformBlock(node);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// animation data of the node
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "TM_ANIMATION", 12)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV2AnimationBlock(node);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
if (node.mType == BaseNode::Light) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// light settings
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "LIGHT_SETTINGS", 14)) {
|
|
|
|
ParseLV2LightSettingsBlock((ASE::Light &)node);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// type of the light source
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "LIGHT_TYPE", 10)) {
|
|
|
|
if (!ASSIMP_strincmp("omni", filePtr, 4)) {
|
|
|
|
((ASE::Light &)node).mLightType = ASE::Light::OMNI;
|
|
|
|
} else if (!ASSIMP_strincmp("target", filePtr, 6)) {
|
|
|
|
((ASE::Light &)node).mLightType = ASE::Light::TARGET;
|
|
|
|
} else if (!ASSIMP_strincmp("free", filePtr, 4)) {
|
|
|
|
((ASE::Light &)node).mLightType = ASE::Light::FREE;
|
|
|
|
} else if (!ASSIMP_strincmp("directional", filePtr, 11)) {
|
|
|
|
((ASE::Light &)node).mLightType = ASE::Light::DIRECTIONAL;
|
|
|
|
} else {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Unknown kind of light source");
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
} else if (node.mType == BaseNode::Camera) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// Camera settings
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CAMERA_SETTINGS", 15)) {
|
|
|
|
ParseLV2CameraSettingsBlock((ASE::Camera &)node);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
2020-05-02 13:14:38 +00:00
|
|
|
} else if (TokenMatch(filePtr, "CAMERA_TYPE", 11)) {
|
|
|
|
if (!ASSIMP_strincmp("target", filePtr, 6)) {
|
|
|
|
((ASE::Camera &)node).mCameraType = ASE::Camera::TARGET;
|
|
|
|
} else if (!ASSIMP_strincmp("free", filePtr, 4)) {
|
|
|
|
((ASE::Camera &)node).mCameraType = ASE::Camera::FREE;
|
|
|
|
} else {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Unknown kind of camera");
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
} else if (node.mType == BaseNode::Mesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// mesh data
|
|
|
|
// FIX: Older files use MESH_SOFTSKIN
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH", 4) ||
|
|
|
|
TokenMatch(filePtr, "MESH_SOFTSKIN", 13)) {
|
|
|
|
ParseLV2MeshBlock((ASE::Mesh &)node);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// mesh material index
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MATERIAL_REF", 12)) {
|
|
|
|
ParseLV4MeshLong(((ASE::Mesh &)node).iMaterialIndex);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AI_ASE_HANDLE_TOP_LEVEL_SECTION();
|
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV2CameraSettingsBlock(ASE::Camera &camera) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CAMERA_NEAR", 11)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(camera.mNear);
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CAMERA_FAR", 10)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(camera.mFar);
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CAMERA_FOV", 10)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(camera.mFOV);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("2", "CAMERA_SETTINGS");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV2LightSettingsBlock(ASE::Light &light) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "LIGHT_COLOR", 11)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloatTriple(&light.mColor.r);
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "LIGHT_INTENS", 12)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(light.mIntensity);
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "LIGHT_HOTSPOT", 13)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(light.mAngle);
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "LIGHT_FALLOFF", 13)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(light.mFalloff);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("2", "LIGHT_SETTINGS");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV2AnimationBlock(ASE::BaseNode &mesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
ASE::Animation *anim = &mesh.mAnim;
|
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "NODE_NAME", 9)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string temp;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!ParseString(temp, "*NODE_NAME"))
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipToNextToken();
|
|
|
|
|
|
|
|
// If the name of the node contains .target it
|
|
|
|
// represents an animated camera or spot light
|
|
|
|
// target.
|
2020-05-02 13:14:38 +00:00
|
|
|
if (std::string::npos != temp.find(".Target")) {
|
|
|
|
if ((mesh.mType != BaseNode::Camera || ((ASE::Camera &)mesh).mCameraType != ASE::Camera::TARGET) &&
|
|
|
|
(mesh.mType != BaseNode::Light || ((ASE::Light &)mesh).mLightType != ASE::Light::TARGET)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2018-04-19 14:48:43 +00:00
|
|
|
ASSIMP_LOG_ERROR("ASE: Found target animation channel "
|
2020-05-02 13:14:38 +00:00
|
|
|
"but the node is neither a camera nor a spot light");
|
2020-06-23 19:05:42 +00:00
|
|
|
anim = nullptr;
|
2020-05-02 13:14:38 +00:00
|
|
|
} else
|
|
|
|
anim = &mesh.mTargetAnim;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// position keyframes
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CONTROL_POS_TRACK", 17) ||
|
|
|
|
TokenMatch(filePtr, "CONTROL_POS_BEZIER", 18) ||
|
|
|
|
TokenMatch(filePtr, "CONTROL_POS_TCB", 15)) {
|
|
|
|
if (!anim)
|
|
|
|
SkipSection();
|
|
|
|
else
|
|
|
|
ParseLV3PosAnimationBlock(*anim);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// scaling keyframes
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CONTROL_SCALE_TRACK", 19) ||
|
|
|
|
TokenMatch(filePtr, "CONTROL_SCALE_BEZIER", 20) ||
|
|
|
|
TokenMatch(filePtr, "CONTROL_SCALE_TCB", 17)) {
|
|
|
|
if (!anim || anim == &mesh.mTargetAnim) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// Target animation channels may have no rotation channels
|
2018-04-19 14:48:43 +00:00
|
|
|
ASSIMP_LOG_ERROR("ASE: Ignoring scaling channel in target animation");
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipSection();
|
2020-05-02 13:14:38 +00:00
|
|
|
} else
|
|
|
|
ParseLV3ScaleAnimationBlock(*anim);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// rotation keyframes
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CONTROL_ROT_TRACK", 17) ||
|
|
|
|
TokenMatch(filePtr, "CONTROL_ROT_BEZIER", 18) ||
|
|
|
|
TokenMatch(filePtr, "CONTROL_ROT_TCB", 15)) {
|
|
|
|
if (!anim || anim == &mesh.mTargetAnim) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// Target animation channels may have no rotation channels
|
2018-04-19 14:48:43 +00:00
|
|
|
ASSIMP_LOG_ERROR("ASE: Ignoring rotation channel in target animation");
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipSection();
|
2020-05-02 13:14:38 +00:00
|
|
|
} else
|
|
|
|
ParseLV3RotAnimationBlock(*anim);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("2", "TM_ANIMATION");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV3ScaleAnimationBlock(ASE::Animation &anim) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
unsigned int iIndex;
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
bool b = false;
|
|
|
|
|
|
|
|
// For the moment we're just reading the three floats -
|
2017-01-08 16:41:10 +00:00
|
|
|
// we ignore the additional information for bezier's and TCBs
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// simple scaling keyframe
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CONTROL_SCALE_SAMPLE", 20)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
b = true;
|
|
|
|
anim.mScalingType = ASE::Animation::TRACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bezier scaling keyframe
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CONTROL_BEZIER_SCALE_KEY", 24)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
b = true;
|
|
|
|
anim.mScalingType = ASE::Animation::BEZIER;
|
|
|
|
}
|
|
|
|
// TCB scaling keyframe
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CONTROL_TCB_SCALE_KEY", 21)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
b = true;
|
|
|
|
anim.mScalingType = ASE::Animation::TCB;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (b) {
|
2015-05-19 03:57:13 +00:00
|
|
|
anim.akeyScaling.push_back(aiVectorKey());
|
2020-05-02 13:14:38 +00:00
|
|
|
aiVectorKey &key = anim.akeyScaling.back();
|
|
|
|
ParseLV4MeshFloatTriple(&key.mValue.x, iIndex);
|
2015-05-19 03:57:13 +00:00
|
|
|
key.mTime = (double)iIndex;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("3", "*CONTROL_POS_TRACK");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV3PosAnimationBlock(ASE::Animation &anim) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
unsigned int iIndex;
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
bool b = false;
|
|
|
|
|
|
|
|
// For the moment we're just reading the three floats -
|
2017-01-08 16:41:10 +00:00
|
|
|
// we ignore the additional information for bezier's and TCBs
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// simple scaling keyframe
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CONTROL_POS_SAMPLE", 18)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
b = true;
|
|
|
|
anim.mPositionType = ASE::Animation::TRACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bezier scaling keyframe
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CONTROL_BEZIER_POS_KEY", 22)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
b = true;
|
|
|
|
anim.mPositionType = ASE::Animation::BEZIER;
|
|
|
|
}
|
|
|
|
// TCB scaling keyframe
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CONTROL_TCB_POS_KEY", 19)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
b = true;
|
|
|
|
anim.mPositionType = ASE::Animation::TCB;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (b) {
|
2015-05-19 03:57:13 +00:00
|
|
|
anim.akeyPositions.push_back(aiVectorKey());
|
2020-05-02 13:14:38 +00:00
|
|
|
aiVectorKey &key = anim.akeyPositions.back();
|
|
|
|
ParseLV4MeshFloatTriple(&key.mValue.x, iIndex);
|
2015-05-19 03:57:13 +00:00
|
|
|
key.mTime = (double)iIndex;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("3", "*CONTROL_POS_TRACK");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV3RotAnimationBlock(ASE::Animation &anim) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
unsigned int iIndex;
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
bool b = false;
|
|
|
|
|
|
|
|
// For the moment we're just reading the floats -
|
2017-01-08 16:41:10 +00:00
|
|
|
// we ignore the additional information for bezier's and TCBs
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// simple scaling keyframe
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CONTROL_ROT_SAMPLE", 18)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
b = true;
|
|
|
|
anim.mRotationType = ASE::Animation::TRACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bezier scaling keyframe
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CONTROL_BEZIER_ROT_KEY", 22)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
b = true;
|
|
|
|
anim.mRotationType = ASE::Animation::BEZIER;
|
|
|
|
}
|
|
|
|
// TCB scaling keyframe
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "CONTROL_TCB_ROT_KEY", 19)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
b = true;
|
|
|
|
anim.mRotationType = ASE::Animation::TCB;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (b) {
|
2015-05-19 03:57:13 +00:00
|
|
|
anim.akeyRotations.push_back(aiQuatKey());
|
2020-05-02 13:14:38 +00:00
|
|
|
aiQuatKey &key = anim.akeyRotations.back();
|
|
|
|
aiVector3D v;
|
|
|
|
ai_real f;
|
|
|
|
ParseLV4MeshFloatTriple(&v.x, iIndex);
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(f);
|
|
|
|
key.mTime = (double)iIndex;
|
2020-05-02 13:14:38 +00:00
|
|
|
key.mValue = aiQuaternion(v, f);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("3", "*CONTROL_ROT_TRACK");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV2NodeTransformBlock(ASE::BaseNode &mesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
2020-05-02 13:14:38 +00:00
|
|
|
int mode = 0;
|
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
// name of the node
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "NODE_NAME", 9)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
std::string temp;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!ParseString(temp, "*NODE_NAME"))
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipToNextToken();
|
|
|
|
|
|
|
|
std::string::size_type s;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (temp == mesh.mName) {
|
2015-05-19 03:57:13 +00:00
|
|
|
mode = 1;
|
2020-05-02 13:14:38 +00:00
|
|
|
} else if (std::string::npos != (s = temp.find(".Target")) &&
|
|
|
|
mesh.mName == temp.substr(0, s)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// This should be either a target light or a target camera
|
2020-05-02 13:14:38 +00:00
|
|
|
if ((mesh.mType == BaseNode::Light && ((ASE::Light &)mesh).mLightType == ASE::Light::TARGET) ||
|
|
|
|
(mesh.mType == BaseNode::Camera && ((ASE::Camera &)mesh).mCameraType == ASE::Camera::TARGET)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
mode = 2;
|
2020-05-02 13:14:38 +00:00
|
|
|
} else {
|
2018-04-19 14:48:43 +00:00
|
|
|
ASSIMP_LOG_ERROR("ASE: Ignoring target transform, "
|
2020-05-02 13:14:38 +00:00
|
|
|
"this is no spot light or target camera");
|
2018-04-19 14:48:43 +00:00
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
} else {
|
2021-05-13 11:05:31 +00:00
|
|
|
ASSIMP_LOG_ERROR("ASE: Unknown node transformation: ", temp);
|
2015-05-19 03:57:13 +00:00
|
|
|
// mode = 0
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (mode) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// fourth row of the transformation matrix - and also the
|
|
|
|
// only information here that is interesting for targets
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "TM_ROW3", 7)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloatTriple((mode == 1 ? mesh.mTransform[3] : &mesh.mTargetPosition.x));
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (mode == 1) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// first row of the transformation matrix
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "TM_ROW0", 7)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloatTriple(mesh.mTransform[0]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// second row of the transformation matrix
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "TM_ROW1", 7)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloatTriple(mesh.mTransform[1]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// third row of the transformation matrix
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "TM_ROW2", 7)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloatTriple(mesh.mTransform[2]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// inherited position axes
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "INHERIT_POS", 11)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int aiVal[3];
|
|
|
|
ParseLV4MeshLongTriple(aiVal);
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
for (unsigned int i = 0; i < 3; ++i)
|
2015-05-19 03:57:13 +00:00
|
|
|
mesh.inherit.abInheritPosition[i] = aiVal[i] != 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// inherited rotation axes
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "INHERIT_ROT", 11)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int aiVal[3];
|
|
|
|
ParseLV4MeshLongTriple(aiVal);
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
for (unsigned int i = 0; i < 3; ++i)
|
2015-05-19 03:57:13 +00:00
|
|
|
mesh.inherit.abInheritRotation[i] = aiVal[i] != 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// inherited scaling axes
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "INHERIT_SCL", 11)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int aiVal[3];
|
|
|
|
ParseLV4MeshLongTriple(aiVal);
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
for (unsigned int i = 0; i < 3; ++i)
|
2015-05-19 03:57:13 +00:00
|
|
|
mesh.inherit.abInheritScaling[i] = aiVal[i] != 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("2", "*NODE_TM");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV2MeshBlock(ASE::Mesh &mesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
|
|
|
|
unsigned int iNumVertices = 0;
|
|
|
|
unsigned int iNumFaces = 0;
|
|
|
|
unsigned int iNumTVertices = 0;
|
|
|
|
unsigned int iNumTFaces = 0;
|
|
|
|
unsigned int iNumCVertices = 0;
|
|
|
|
unsigned int iNumCFaces = 0;
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
// Number of vertices in the mesh
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_NUMVERTEX", 14)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iNumVertices);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Number of texture coordinates in the mesh
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_NUMTVERTEX", 15)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iNumTVertices);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Number of vertex colors in the mesh
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_NUMCVERTEX", 15)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iNumCVertices);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Number of regular faces in the mesh
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_NUMFACES", 13)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iNumFaces);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Number of UVWed faces in the mesh
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_NUMTVFACES", 15)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iNumTFaces);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Number of colored faces in the mesh
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_NUMCVFACES", 15)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iNumCFaces);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// mesh vertex list block
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_VERTEX_LIST", 16)) {
|
|
|
|
ParseLV3MeshVertexListBlock(iNumVertices, mesh);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// mesh face list block
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_FACE_LIST", 14)) {
|
|
|
|
ParseLV3MeshFaceListBlock(iNumFaces, mesh);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// mesh texture vertex list block
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_TVERTLIST", 14)) {
|
|
|
|
ParseLV3MeshTListBlock(iNumTVertices, mesh);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// mesh texture face block
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_TFACELIST", 14)) {
|
|
|
|
ParseLV3MeshTFaceListBlock(iNumTFaces, mesh);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// mesh color vertex list block
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_CVERTLIST", 14)) {
|
|
|
|
ParseLV3MeshCListBlock(iNumCVertices, mesh);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// mesh color face block
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_CFACELIST", 14)) {
|
|
|
|
ParseLV3MeshCFaceListBlock(iNumCFaces, mesh);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// mesh normals
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_NORMALS", 12)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV3MeshNormalListBlock(mesh);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// another mesh UV channel ...
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_MAPPINGCHANNEL", 19)) {
|
|
|
|
unsigned int iIndex(0);
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iIndex);
|
2020-05-02 13:14:38 +00:00
|
|
|
if (0 == iIndex) {
|
|
|
|
LogWarning("Mapping channel has an invalid index. Skipping UV channel");
|
2015-05-19 03:57:13 +00:00
|
|
|
// skip it ...
|
|
|
|
SkipSection();
|
2016-08-29 13:32:27 +00:00
|
|
|
} else {
|
2020-05-02 13:14:38 +00:00
|
|
|
if (iIndex < 2) {
|
|
|
|
LogWarning("Mapping channel has an invalid index. Skipping UV channel");
|
2016-08-29 13:32:27 +00:00
|
|
|
// skip it ...
|
|
|
|
SkipSection();
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (iIndex > AI_MAX_NUMBER_OF_TEXTURECOORDS) {
|
|
|
|
LogWarning("Too many UV channels specified. Skipping channel ..");
|
2016-08-29 13:32:27 +00:00
|
|
|
// skip it ...
|
|
|
|
SkipSection();
|
|
|
|
} else {
|
|
|
|
// parse the mapping channel
|
2020-05-02 13:14:38 +00:00
|
|
|
ParseLV3MappingChannel(iIndex - 1, mesh);
|
2016-08-29 13:32:27 +00:00
|
|
|
}
|
|
|
|
continue;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// mesh animation keyframe. Not supported
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_ANIMATION", 14)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
LogWarning("Found *MESH_ANIMATION element in ASE/ASK file. "
|
2020-05-02 13:14:38 +00:00
|
|
|
"Keyframe animation is not supported by Assimp, this element "
|
|
|
|
"will be ignored");
|
2015-05-19 03:57:13 +00:00
|
|
|
//SkipSection();
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_WEIGHTS", 12)) {
|
|
|
|
ParseLV3MeshWeightsBlock(mesh);
|
|
|
|
continue;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("2", "*MESH");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV3MeshWeightsBlock(ASE::Mesh &mesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
|
|
|
|
unsigned int iNumVertices = 0, iNumBones = 0;
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
// Number of bone vertices ...
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_NUMVERTEX", 14)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iNumVertices);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Number of bones
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_NUMBONE", 12)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iNumBones);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// parse the list of bones
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_BONE_LIST", 14)) {
|
|
|
|
ParseLV4MeshBones(iNumBones, mesh);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// parse the list of bones vertices
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_BONE_VERTEX_LIST", 21)) {
|
|
|
|
ParseLV4MeshBonesVertices(iNumVertices, mesh);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("3", "*MESH_WEIGHTS");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV4MeshBones(unsigned int iNumBones, ASE::Mesh &mesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
2018-01-27 15:42:36 +00:00
|
|
|
mesh.mBones.resize(iNumBones, Bone("UNNAMED"));
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
// Mesh bone with name ...
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_BONE_NAME", 14)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// parse an index ...
|
2020-05-02 13:14:38 +00:00
|
|
|
if (SkipSpaces(&filePtr)) {
|
|
|
|
unsigned int iIndex = strtoul10(filePtr, &filePtr);
|
|
|
|
if (iIndex >= iNumBones) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Bone index is out of bounds");
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!ParseString(mesh.mBones[iIndex].mName, "*MESH_BONE_NAME"))
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipToNextToken();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("3", "*MESH_BONE_LIST");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV4MeshBonesVertices(unsigned int iNumVertices, ASE::Mesh &mesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
mesh.mBoneVertices.resize(iNumVertices);
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
// Mesh bone vertex
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_BONE_VERTEX", 16)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// read the vertex index
|
2020-05-02 13:14:38 +00:00
|
|
|
unsigned int iIndex = strtoul10(filePtr, &filePtr);
|
|
|
|
if (iIndex >= mesh.mPositions.size()) {
|
|
|
|
iIndex = (unsigned int)mesh.mPositions.size() - 1;
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Bone vertex index is out of bounds. Using the largest valid "
|
2020-05-02 13:14:38 +00:00
|
|
|
"bone vertex index instead");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --- ignored
|
2016-07-15 05:38:29 +00:00
|
|
|
ai_real afVert[3];
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloatTriple(afVert);
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
std::pair<int, float> pairOut;
|
|
|
|
while (true) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// first parse the bone index ...
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!SkipSpaces(&filePtr)) break;
|
|
|
|
pairOut.first = strtoul10(filePtr, &filePtr);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// then parse the vertex weight
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!SkipSpaces(&filePtr)) break;
|
|
|
|
filePtr = fast_atoreal_move<float>(filePtr, pairOut.second);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// -1 marks unused entries
|
2020-05-02 13:14:38 +00:00
|
|
|
if (-1 != pairOut.first) {
|
2015-05-19 03:57:13 +00:00
|
|
|
mesh.mBoneVertices[iIndex].mBoneWeights.push_back(pairOut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("4", "*MESH_BONE_VERTEX");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3MeshVertexListBlock(
|
2020-05-02 13:14:38 +00:00
|
|
|
unsigned int iNumVertices, ASE::Mesh &mesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
|
|
|
|
// allocate enough storage in the array
|
|
|
|
mesh.mPositions.resize(iNumVertices);
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
// Vertex entry
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_VERTEX", 11)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
aiVector3D vTemp;
|
|
|
|
unsigned int iIndex;
|
2020-05-02 13:14:38 +00:00
|
|
|
ParseLV4MeshFloatTriple(&vTemp.x, iIndex);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
if (iIndex >= iNumVertices) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Invalid vertex index. It will be ignored");
|
2020-05-02 13:14:38 +00:00
|
|
|
} else
|
|
|
|
mesh.mPositions[iIndex] = vTemp;
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("3", "*MESH_VERTEX_LIST");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV3MeshFaceListBlock(unsigned int iNumFaces, ASE::Mesh &mesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
|
|
|
|
// allocate enough storage in the face array
|
|
|
|
mesh.mFaces.resize(iNumFaces);
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
// Face entry
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_FACE", 9)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
ASE::Face mFace;
|
|
|
|
ParseLV4MeshFace(mFace);
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
if (mFace.iFace >= iNumFaces) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Face has an invalid index. It will be ignored");
|
2020-05-02 13:14:38 +00:00
|
|
|
} else
|
|
|
|
mesh.mFaces[mFace.iFace] = mFace;
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("3", "*MESH_FACE_LIST");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3MeshTListBlock(unsigned int iNumVertices,
|
2020-05-02 13:14:38 +00:00
|
|
|
ASE::Mesh &mesh, unsigned int iChannel) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
|
|
|
|
// allocate enough storage in the array
|
|
|
|
mesh.amTexCoords[iChannel].resize(iNumVertices);
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
// Vertex entry
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_TVERT", 10)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
aiVector3D vTemp;
|
|
|
|
unsigned int iIndex;
|
2020-05-02 13:14:38 +00:00
|
|
|
ParseLV4MeshFloatTriple(&vTemp.x, iIndex);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
if (iIndex >= iNumVertices) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Tvertex has an invalid index. It will be ignored");
|
2020-05-02 13:14:38 +00:00
|
|
|
} else
|
|
|
|
mesh.amTexCoords[iChannel][iIndex] = vTemp;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
if (0.0f != vTemp.z) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// we need 3 coordinate channels
|
|
|
|
mesh.mNumUVComponents[iChannel] = 3;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("3", "*MESH_TVERT_LIST");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Parser::ParseLV3MeshTFaceListBlock(unsigned int iNumFaces,
|
2020-05-02 13:14:38 +00:00
|
|
|
ASE::Mesh &mesh, unsigned int iChannel) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
// Face entry
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_TFACE", 10)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int aiValues[3];
|
|
|
|
unsigned int iIndex = 0;
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
ParseLV4MeshLongTriple(aiValues, iIndex);
|
|
|
|
if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("UV-Face has an invalid index. It will be ignored");
|
2020-05-02 13:14:38 +00:00
|
|
|
} else {
|
2015-05-19 03:57:13 +00:00
|
|
|
// 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];
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("3", "*MESH_TFACE_LIST");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV3MappingChannel(unsigned int iChannel, ASE::Mesh &mesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
|
|
|
|
unsigned int iNumTVertices = 0;
|
|
|
|
unsigned int iNumTFaces = 0;
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
// Number of texture coordinates in the mesh
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_NUMTVERTEX", 15)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iNumTVertices);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Number of UVWed faces in the mesh
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_NUMTVFACES", 15)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(iNumTFaces);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// mesh texture vertex list block
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_TVERTLIST", 14)) {
|
|
|
|
ParseLV3MeshTListBlock(iNumTVertices, mesh, iChannel);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// mesh texture face block
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_TFACELIST", 14)) {
|
|
|
|
ParseLV3MeshTFaceListBlock(iNumTFaces, mesh, iChannel);
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("3", "*MESH_MAPPING_CHANNEL");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV3MeshCListBlock(unsigned int iNumVertices, ASE::Mesh &mesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
|
|
|
|
// allocate enough storage in the array
|
|
|
|
mesh.mVertexColors.resize(iNumVertices);
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
// Vertex entry
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_VERTCOL", 12)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
aiColor4D vTemp;
|
|
|
|
vTemp.a = 1.0f;
|
|
|
|
unsigned int iIndex;
|
2020-05-02 13:14:38 +00:00
|
|
|
ParseLV4MeshFloatTriple(&vTemp.r, iIndex);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
if (iIndex >= iNumVertices) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Vertex color has an invalid index. It will be ignored");
|
2020-05-02 13:14:38 +00:00
|
|
|
} else
|
|
|
|
mesh.mVertexColors[iIndex] = vTemp;
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("3", "*MESH_CVERTEX_LIST");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV3MeshCFaceListBlock(unsigned int iNumFaces, ASE::Mesh &mesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
// Face entry
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_CFACE", 10)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int aiValues[3];
|
|
|
|
unsigned int iIndex = 0;
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
ParseLV4MeshLongTriple(aiValues, iIndex);
|
|
|
|
if (iIndex >= iNumFaces || iIndex >= mesh.mFaces.size()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("UV-Face has an invalid index. It will be ignored");
|
2020-05-02 13:14:38 +00:00
|
|
|
} else {
|
2015-05-19 03:57:13 +00:00
|
|
|
// copy color indices
|
|
|
|
mesh.mFaces[iIndex].mColorIndices[0] = aiValues[0];
|
|
|
|
mesh.mFaces[iIndex].mColorIndices[1] = aiValues[1];
|
|
|
|
mesh.mFaces[iIndex].mColorIndices[2] = aiValues[2];
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("3", "*MESH_CFACE_LIST");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV3MeshNormalListBlock(ASE::Mesh &sMesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
AI_ASE_PARSER_INIT();
|
|
|
|
|
|
|
|
// Allocate enough storage for the normals
|
2020-05-02 13:14:38 +00:00
|
|
|
sMesh.mNormals.resize(sMesh.mFaces.size() * 3, aiVector3D(0.f, 0.f, 0.f));
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int index, faceIdx = UINT_MAX;
|
|
|
|
|
|
|
|
// FIXME: rewrite this and find out how to interpret the normals
|
|
|
|
// correctly. This is crap.
|
|
|
|
|
|
|
|
// Smooth the vertex and face normals together. The result
|
|
|
|
// will be edgy then, but otherwise everything would be soft ...
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
++filePtr;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (faceIdx != UINT_MAX && TokenMatch(filePtr, "MESH_VERTEXNORMAL", 17)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
aiVector3D vNormal;
|
2020-05-02 13:14:38 +00:00
|
|
|
ParseLV4MeshFloatTriple(&vNormal.x, index);
|
|
|
|
if (faceIdx >= sMesh.mFaces.size())
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Make sure we assign it to the correct face
|
2020-05-02 13:14:38 +00:00
|
|
|
const ASE::Face &face = sMesh.mFaces[faceIdx];
|
2015-05-19 03:57:13 +00:00
|
|
|
if (index == face.mIndices[0])
|
|
|
|
index = 0;
|
|
|
|
else if (index == face.mIndices[1])
|
|
|
|
index = 1;
|
|
|
|
else if (index == face.mIndices[2])
|
|
|
|
index = 2;
|
2020-05-02 13:14:38 +00:00
|
|
|
else {
|
2018-04-19 14:48:43 +00:00
|
|
|
ASSIMP_LOG_ERROR("ASE: Invalid vertex index in MESH_VERTEXNORMAL section");
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// We'll renormalize later
|
2020-05-02 13:14:38 +00:00
|
|
|
sMesh.mNormals[faceIdx * 3 + index] += vNormal;
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "MESH_FACENORMAL", 15)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
aiVector3D vNormal;
|
2020-05-02 13:14:38 +00:00
|
|
|
ParseLV4MeshFloatTriple(&vNormal.x, faceIdx);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
if (faceIdx >= sMesh.mFaces.size()) {
|
2018-04-19 14:48:43 +00:00
|
|
|
ASSIMP_LOG_ERROR("ASE: Invalid vertex index in MESH_FACENORMAL section");
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We'll renormalize later
|
2020-05-02 13:14:38 +00:00
|
|
|
sMesh.mNormals[faceIdx * 3] += vNormal;
|
|
|
|
sMesh.mNormals[faceIdx * 3 + 1] += vNormal;
|
|
|
|
sMesh.mNormals[faceIdx * 3 + 2] += vNormal;
|
2015-05-19 03:57:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
AI_ASE_HANDLE_SECTION("3", "*MESH_NORMALS");
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV4MeshFace(ASE::Face &out) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// skip spaces and tabs
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!SkipSpaces(&filePtr)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL [#1]");
|
|
|
|
SkipToNextToken();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse the face index
|
2020-05-02 13:14:38 +00:00
|
|
|
out.iFace = strtoul10(filePtr, &filePtr);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// next character should be ':'
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!SkipSpaces(&filePtr)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// FIX: there are some ASE files which haven't got : here ....
|
|
|
|
LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. \':\' expected [#2]");
|
|
|
|
SkipToNextToken();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// FIX: There are some ASE files which haven't got ':' here
|
2020-05-02 13:14:38 +00:00
|
|
|
if (':' == *filePtr) ++filePtr;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// Parse all mesh indices
|
2020-05-02 13:14:38 +00:00
|
|
|
for (unsigned int i = 0; i < 3; ++i) {
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int iIndex = 0;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!SkipSpaces(&filePtr)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL");
|
|
|
|
SkipToNextToken();
|
|
|
|
return;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
switch (*filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
case 'A':
|
|
|
|
case 'a':
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
case 'b':
|
|
|
|
iIndex = 1;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
case 'c':
|
|
|
|
iIndex = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. "
|
2020-05-02 13:14:38 +00:00
|
|
|
"A,B or C expected [#3]");
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipToNextToken();
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
++filePtr;
|
|
|
|
|
|
|
|
// next character should be ':'
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!SkipSpaces(&filePtr) || ':' != *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Unable to parse *MESH_FACE Element: "
|
2020-05-02 13:14:38 +00:00
|
|
|
"Unexpected EOL. \':\' expected [#2]");
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipToNextToken();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
++filePtr;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!SkipSpaces(&filePtr)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. "
|
2020-05-02 13:14:38 +00:00
|
|
|
"Vertex index ecpected [#4]");
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipToNextToken();
|
|
|
|
return;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
out.mIndices[iIndex] = strtoul10(filePtr, &filePtr);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// now we need to skip the AB, BC, CA blocks.
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) break;
|
|
|
|
if (IsLineEnd(*filePtr)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
//iLineNumber++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
filePtr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse the smoothing group of the face
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "*MESH_SMOOTHING", 15)) {
|
|
|
|
if (!SkipSpaces(&filePtr)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Unable to parse *MESH_SMOOTHING Element: "
|
2020-05-02 13:14:38 +00:00
|
|
|
"Unexpected EOL. Smoothing group(s) expected [#5]");
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipToNextToken();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse smoothing groups until we don't anymore see commas
|
|
|
|
// FIX: There needn't always be a value, sad but true
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if (*filePtr < '9' && *filePtr >= '0') {
|
|
|
|
out.iSmoothGroup |= (1 << strtoul10(filePtr, &filePtr));
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
SkipSpaces(&filePtr);
|
2020-05-02 13:14:38 +00:00
|
|
|
if (',' != *filePtr) {
|
2015-05-19 03:57:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++filePtr;
|
|
|
|
SkipSpaces(&filePtr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// *MESH_MTLID is optional, too
|
2020-05-02 13:14:38 +00:00
|
|
|
while (true) {
|
|
|
|
if ('*' == *filePtr) break;
|
|
|
|
if (IsLineEnd(*filePtr)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
filePtr++;
|
|
|
|
}
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
if (TokenMatch(filePtr, "*MESH_MTLID", 11)) {
|
|
|
|
if (!SkipSpaces(&filePtr)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogWarning("Unable to parse *MESH_MTLID Element: Unexpected EOL. "
|
2020-05-02 13:14:38 +00:00
|
|
|
"Material index expected [#6]");
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipToNextToken();
|
|
|
|
return;
|
|
|
|
}
|
2020-05-02 13:14:38 +00:00
|
|
|
out.iMaterial = strtoul10(filePtr, &filePtr);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
return;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV4MeshLongTriple(unsigned int *apOut) {
|
2020-06-23 19:05:42 +00:00
|
|
|
ai_assert(nullptr != apOut);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
for (unsigned int i = 0; i < 3; ++i)
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshLong(apOut[i]);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV4MeshLongTriple(unsigned int *apOut, unsigned int &rIndexOut) {
|
2020-06-23 19:05:42 +00:00
|
|
|
ai_assert(nullptr != apOut);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// parse the index
|
|
|
|
ParseLV4MeshLong(rIndexOut);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// parse the three others
|
|
|
|
ParseLV4MeshLongTriple(apOut);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV4MeshFloatTriple(ai_real *apOut, unsigned int &rIndexOut) {
|
2020-06-23 19:05:42 +00:00
|
|
|
ai_assert(nullptr != apOut);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// parse the index
|
|
|
|
ParseLV4MeshLong(rIndexOut);
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// parse the three others
|
|
|
|
ParseLV4MeshFloatTriple(apOut);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV4MeshFloatTriple(ai_real *apOut) {
|
2020-06-23 19:05:42 +00:00
|
|
|
ai_assert(nullptr != apOut);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
for (unsigned int i = 0; i < 3; ++i)
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseLV4MeshFloat(apOut[i]);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV4MeshFloat(ai_real &fOut) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// skip spaces and tabs
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!SkipSpaces(&filePtr)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// LOG
|
|
|
|
LogWarning("Unable to parse float: unexpected EOL [#1]");
|
2016-07-15 05:38:29 +00:00
|
|
|
fOut = 0.0;
|
2015-05-19 03:57:13 +00:00
|
|
|
++iLineNumber;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// parse the first float
|
2020-05-02 13:14:38 +00:00
|
|
|
filePtr = fast_atoreal_move<ai_real>(filePtr, fOut);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void Parser::ParseLV4MeshLong(unsigned int &iOut) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// Skip spaces and tabs
|
2020-05-02 13:14:38 +00:00
|
|
|
if (!SkipSpaces(&filePtr)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// LOG
|
|
|
|
LogWarning("Unable to parse long: unexpected EOL [#1]");
|
|
|
|
iOut = 0;
|
|
|
|
++iLineNumber;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// parse the value
|
2020-05-02 13:14:38 +00:00
|
|
|
iOut = strtoul10(filePtr, &filePtr);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
2017-06-26 20:01:15 +00:00
|
|
|
#endif // ASSIMP_BUILD_NO_3DS_IMPORTER
|
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif // !! ASSIMP_BUILD_NO_BASE_IMPORTER
|