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