mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-11 22:54:34 +00:00
update assimp lib
This commit is contained in:
parent
03a348deb7
commit
d3f8fee74e
1725 changed files with 196314 additions and 62009 deletions
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, assimp team
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ using namespace Assimp;
|
|||
// Minimum weight value. Weights inside [-n ... n] are ignored
|
||||
#define AI_MD5_WEIGHT_EPSILON Math::getEpsilon<float>()
|
||||
|
||||
static const aiImporterDesc desc = {
|
||||
static constexpr aiImporterDesc desc = {
|
||||
"Doom 3 / MD5 Mesh Importer",
|
||||
"",
|
||||
"",
|
||||
|
|
@ -92,10 +92,6 @@ MD5Importer::MD5Importer() :
|
|||
// empty
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor, private as well
|
||||
MD5Importer::~MD5Importer() = default;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns whether the class can handle the format of the given file.
|
||||
bool MD5Importer::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const {
|
||||
|
|
@ -214,7 +210,7 @@ void MD5Importer::MakeDataUnique(MD5::MeshDesc &meshSrc) {
|
|||
const unsigned int guess = (unsigned int)(fWeightsPerVert * iNewNum);
|
||||
meshSrc.mWeights.reserve(guess + (guess >> 3)); // + 12.5% as buffer
|
||||
|
||||
for (FaceList::const_iterator iter = meshSrc.mFaces.begin(), iterEnd = meshSrc.mFaces.end(); iter != iterEnd; ++iter) {
|
||||
for (FaceArray::const_iterator iter = meshSrc.mFaces.begin(), iterEnd = meshSrc.mFaces.end(); iter != iterEnd; ++iter) {
|
||||
const aiFace &face = *iter;
|
||||
for (unsigned int i = 0; i < 3; ++i) {
|
||||
if (face.mIndices[0] >= meshSrc.mVertices.size()) {
|
||||
|
|
@ -235,7 +231,7 @@ void MD5Importer::MakeDataUnique(MD5::MeshDesc &meshSrc) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Recursive node graph construction from a MD5MESH
|
||||
void MD5Importer::AttachChilds_Mesh(int iParentID, aiNode *piParent, BoneList &bones) {
|
||||
void MD5Importer::AttachChilds_Mesh(int iParentID, aiNode *piParent, BoneArray &bones) {
|
||||
ai_assert(nullptr != piParent);
|
||||
ai_assert(!piParent->mNumChildren);
|
||||
|
||||
|
|
@ -286,7 +282,7 @@ void MD5Importer::AttachChilds_Mesh(int iParentID, aiNode *piParent, BoneList &b
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Recursive node graph construction from a MD5ANIM
|
||||
void MD5Importer::AttachChilds_Anim(int iParentID, aiNode *piParent, AnimBoneList &bones, const aiNodeAnim **node_anims) {
|
||||
void MD5Importer::AttachChilds_Anim(int iParentID, aiNode *piParent, AnimBoneArray &bones, const aiNodeAnim **node_anims) {
|
||||
ai_assert(nullptr != piParent);
|
||||
ai_assert(!piParent->mNumChildren);
|
||||
|
||||
|
|
@ -331,7 +327,7 @@ void MD5Importer::LoadMD5MeshFile() {
|
|||
std::unique_ptr<IOStream> file(mIOHandler->Open(filename, "rb"));
|
||||
|
||||
// Check whether we can read from the file
|
||||
if (file.get() == nullptr || !file->FileSize()) {
|
||||
if (file == nullptr || !file->FileSize()) {
|
||||
ASSIMP_LOG_WARN("Failed to access MD5MESH file: ", filename);
|
||||
return;
|
||||
}
|
||||
|
|
@ -406,7 +402,7 @@ void MD5Importer::LoadMD5MeshFile() {
|
|||
|
||||
// copy texture coordinates
|
||||
aiVector3D *pv = mesh->mTextureCoords[0];
|
||||
for (MD5::VertexList::const_iterator iter = meshSrc.mVertices.begin(); iter != meshSrc.mVertices.end(); ++iter, ++pv) {
|
||||
for (MD5::VertexArray::const_iterator iter = meshSrc.mVertices.begin(); iter != meshSrc.mVertices.end(); ++iter, ++pv) {
|
||||
pv->x = (*iter).mUV.x;
|
||||
pv->y = 1.0f - (*iter).mUV.y; // D3D to OpenGL
|
||||
pv->z = 0.0f;
|
||||
|
|
@ -416,7 +412,7 @@ void MD5Importer::LoadMD5MeshFile() {
|
|||
unsigned int *piCount = new unsigned int[meshParser.mJoints.size()];
|
||||
::memset(piCount, 0, sizeof(unsigned int) * meshParser.mJoints.size());
|
||||
|
||||
for (MD5::VertexList::const_iterator iter = meshSrc.mVertices.begin(); iter != meshSrc.mVertices.end(); ++iter, ++pv) {
|
||||
for (MD5::VertexArray::const_iterator iter = meshSrc.mVertices.begin(); iter != meshSrc.mVertices.end(); ++iter, ++pv) {
|
||||
for (unsigned int jub = (*iter).mFirstWeight, w = jub; w < jub + (*iter).mNumWeights; ++w) {
|
||||
MD5::WeightDesc &weightDesc = meshSrc.mWeights[w];
|
||||
/* FIX for some invalid exporters */
|
||||
|
|
@ -451,7 +447,7 @@ void MD5Importer::LoadMD5MeshFile() {
|
|||
}
|
||||
|
||||
pv = mesh->mVertices;
|
||||
for (MD5::VertexList::const_iterator iter = meshSrc.mVertices.begin(); iter != meshSrc.mVertices.end(); ++iter, ++pv) {
|
||||
for (MD5::VertexArray::const_iterator iter = meshSrc.mVertices.begin(); iter != meshSrc.mVertices.end(); ++iter, ++pv) {
|
||||
// compute the final vertex position from all single weights
|
||||
*pv = aiVector3D();
|
||||
|
||||
|
|
@ -553,7 +549,7 @@ void MD5Importer::LoadMD5AnimFile() {
|
|||
std::unique_ptr<IOStream> file(mIOHandler->Open(pFile, "rb"));
|
||||
|
||||
// Check whether we can read from the file
|
||||
if (!file.get() || !file->FileSize()) {
|
||||
if (!file || !file->FileSize()) {
|
||||
ASSIMP_LOG_WARN("Failed to read MD5ANIM file: ", pFile);
|
||||
return;
|
||||
}
|
||||
|
|
@ -589,14 +585,14 @@ void MD5Importer::LoadMD5AnimFile() {
|
|||
// 1 tick == 1 frame
|
||||
anim->mTicksPerSecond = animParser.fFrameRate;
|
||||
|
||||
for (FrameList::const_iterator iter = animParser.mFrames.begin(), iterEnd = animParser.mFrames.end(); iter != iterEnd; ++iter) {
|
||||
for (FrameArray::const_iterator iter = animParser.mFrames.begin(), iterEnd = animParser.mFrames.end(); iter != iterEnd; ++iter) {
|
||||
double dTime = (double)(*iter).iIndex;
|
||||
aiNodeAnim **pcAnimNode = anim->mChannels;
|
||||
if (!(*iter).mValues.empty() || iter == animParser.mFrames.begin()) /* be sure we have at least one frame */
|
||||
{
|
||||
// now process all values in there ... read all joints
|
||||
MD5::BaseFrameDesc *pcBaseFrame = &animParser.mBaseFrames[0];
|
||||
for (AnimBoneList::const_iterator iter2 = animParser.mAnimatedBones.begin(); iter2 != animParser.mAnimatedBones.end(); ++iter2,
|
||||
for (AnimBoneArray::const_iterator iter2 = animParser.mAnimatedBones.begin(); iter2 != animParser.mAnimatedBones.end(); ++iter2,
|
||||
++pcAnimNode, ++pcBaseFrame) {
|
||||
if ((*iter2).iFirstKeyIndex >= (*iter).mValues.size()) {
|
||||
|
||||
|
|
@ -661,7 +657,7 @@ void MD5Importer::LoadMD5CameraFile() {
|
|||
std::unique_ptr<IOStream> file(mIOHandler->Open(pFile, "rb"));
|
||||
|
||||
// Check whether we can read from the file
|
||||
if (!file.get() || !file->FileSize()) {
|
||||
if (!file || !file->FileSize()) {
|
||||
throw DeadlyImportError("Failed to read MD5CAMERA file: ", pFile);
|
||||
}
|
||||
mHadMD5Camera = true;
|
||||
|
|
@ -711,7 +707,7 @@ void MD5Importer::LoadMD5CameraFile() {
|
|||
for (std::vector<unsigned int>::const_iterator it = cuts.begin(); it != cuts.end() - 1; ++it) {
|
||||
|
||||
aiAnimation *anim = *tmp++ = new aiAnimation();
|
||||
anim->mName.length = ::ai_snprintf(anim->mName.data, MAXLEN, "anim%u_from_%u_to_%u", (unsigned int)(it - cuts.begin()), (*it), *(it + 1));
|
||||
anim->mName.length = ::ai_snprintf(anim->mName.data, AI_MAXLEN, "anim%u_from_%u_to_%u", (unsigned int)(it - cuts.begin()), (*it), *(it + 1));
|
||||
|
||||
anim->mTicksPerSecond = cameraParser.fFrameRate;
|
||||
anim->mChannels = new aiNodeAnim *[anim->mNumChannels = 1];
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, assimp team
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ using namespace Assimp::MD5;
|
|||
class MD5Importer : public BaseImporter {
|
||||
public:
|
||||
MD5Importer();
|
||||
~MD5Importer() override;
|
||||
~MD5Importer() override = default;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Returns whether the class can handle the format of the given file.
|
||||
|
|
@ -118,7 +118,7 @@ protected:
|
|||
* @param node_anims Generated node animations
|
||||
*/
|
||||
void AttachChilds_Anim(int iParentID, aiNode *piParent,
|
||||
AnimBoneList &bones, const aiNodeAnim **node_anims);
|
||||
AnimBoneArray &bones, const aiNodeAnim **node_anims);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Construct node hierarchy from a given MD5MESH
|
||||
|
|
@ -126,7 +126,7 @@ protected:
|
|||
* @param piParent Parent node to attach to
|
||||
* @param bones Input bones
|
||||
*/
|
||||
void AttachChilds_Mesh(int iParentID, aiNode *piParent, BoneList &bones);
|
||||
void AttachChilds_Mesh(int iParentID, aiNode *piParent, BoneArray &bones);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Build unique vertex buffers from a given MD5ANIM
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, assimp team
|
||||
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -60,14 +58,11 @@ using namespace Assimp::MD5;
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Parse the segment structure for an MD5 file
|
||||
MD5Parser::MD5Parser(char *_buffer, unsigned int _fileSize) {
|
||||
MD5Parser::MD5Parser(char *_buffer, unsigned int _fileSize) : buffer(_buffer), bufferEnd(nullptr), fileSize(_fileSize), lineNumber(0) {
|
||||
ai_assert(nullptr != _buffer);
|
||||
ai_assert(0 != _fileSize);
|
||||
|
||||
buffer = _buffer;
|
||||
fileSize = _fileSize;
|
||||
lineNumber = 0;
|
||||
|
||||
bufferEnd = buffer + fileSize;
|
||||
ASSIMP_LOG_DEBUG("MD5Parser begin");
|
||||
|
||||
// parse the file header
|
||||
|
|
@ -92,7 +87,7 @@ MD5Parser::MD5Parser(char *_buffer, unsigned int _fileSize) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Report error to the log stream
|
||||
/*static*/ AI_WONT_RETURN void MD5Parser::ReportError(const char *error, unsigned int line) {
|
||||
AI_WONT_RETURN void MD5Parser::ReportError(const char *error, unsigned int line) {
|
||||
char szBuffer[1024];
|
||||
::ai_snprintf(szBuffer, 1024, "[MD5] Line %u: %s", line, error);
|
||||
throw DeadlyImportError(szBuffer);
|
||||
|
|
@ -100,9 +95,9 @@ MD5Parser::MD5Parser(char *_buffer, unsigned int _fileSize) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Report warning to the log stream
|
||||
/*static*/ void MD5Parser::ReportWarning(const char *warn, unsigned int line) {
|
||||
void MD5Parser::ReportWarning(const char *warn, unsigned int line) {
|
||||
char szBuffer[1024];
|
||||
::sprintf(szBuffer, "[MD5] Line %u: %s", line, warn);
|
||||
::snprintf(szBuffer, sizeof(szBuffer), "[MD5] Line %u: %s", line, warn);
|
||||
ASSIMP_LOG_WARN(szBuffer);
|
||||
}
|
||||
|
||||
|
|
@ -120,12 +115,15 @@ void MD5Parser::ParseHeader() {
|
|||
ReportError("MD5 version tag is unknown (10 is expected)");
|
||||
}
|
||||
SkipLine();
|
||||
if (buffer == bufferEnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
// print the command line options to the console
|
||||
// FIX: can break the log length limit, so we need to be careful
|
||||
char *sz = buffer;
|
||||
while (!IsLineEnd(*buffer++))
|
||||
;
|
||||
while (!IsLineEnd(*buffer++));
|
||||
|
||||
ASSIMP_LOG_INFO(std::string(sz, std::min((uintptr_t)MAX_LOG_MESSAGE_LENGTH, (uintptr_t)(buffer - sz))));
|
||||
SkipSpacesAndLineEnd();
|
||||
}
|
||||
|
|
@ -138,23 +136,41 @@ bool MD5Parser::ParseSection(Section &out) {
|
|||
|
||||
// first parse the name of the section
|
||||
char *sz = buffer;
|
||||
while (!IsSpaceOrNewLine(*buffer))
|
||||
buffer++;
|
||||
while (!IsSpaceOrNewLine(*buffer)) {
|
||||
++buffer;
|
||||
if (buffer == bufferEnd) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
out.mName = std::string(sz, (uintptr_t)(buffer - sz));
|
||||
SkipSpaces();
|
||||
while (IsSpace(*buffer)) {
|
||||
++buffer;
|
||||
if (buffer == bufferEnd) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool running = true;
|
||||
while (running) {
|
||||
if ('{' == *buffer) {
|
||||
// it is a normal section so read all lines
|
||||
buffer++;
|
||||
++buffer;
|
||||
if (buffer == bufferEnd) {
|
||||
return false;
|
||||
}
|
||||
bool run = true;
|
||||
while (run) {
|
||||
if (!SkipSpacesAndLineEnd()) {
|
||||
while (IsSpaceOrNewLine(*buffer)) {
|
||||
++buffer;
|
||||
if (buffer == bufferEnd) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ('\0' == *buffer) {
|
||||
return false; // seems this was the last section
|
||||
}
|
||||
if ('}' == *buffer) {
|
||||
buffer++;
|
||||
++buffer;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -163,89 +179,135 @@ bool MD5Parser::ParseSection(Section &out) {
|
|||
|
||||
elem.iLineNumber = lineNumber;
|
||||
elem.szStart = buffer;
|
||||
elem.end = bufferEnd;
|
||||
|
||||
// terminate the line with zero
|
||||
while (!IsLineEnd(*buffer))
|
||||
buffer++;
|
||||
while (!IsLineEnd(*buffer)) {
|
||||
++buffer;
|
||||
if (buffer == bufferEnd) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (*buffer) {
|
||||
++lineNumber;
|
||||
*buffer++ = '\0';
|
||||
if (buffer == bufferEnd) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else if (!IsSpaceOrNewLine(*buffer)) {
|
||||
// it is an element at global scope. Parse its value and go on
|
||||
sz = buffer;
|
||||
while (!IsSpaceOrNewLine(*buffer++))
|
||||
;
|
||||
while (!IsSpaceOrNewLine(*buffer++)) {
|
||||
if (buffer == bufferEnd) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
out.mGlobalValue = std::string(sz, (uintptr_t)(buffer - sz));
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return SkipSpacesAndLineEnd();
|
||||
if (buffer == bufferEnd) {
|
||||
return false;
|
||||
}
|
||||
while (IsSpaceOrNewLine(*buffer)) {
|
||||
if (buffer == bufferEnd) {
|
||||
break;
|
||||
}
|
||||
++buffer;
|
||||
}
|
||||
return '\0' != *buffer;
|
||||
}
|
||||
|
||||
// skip all spaces ... handle EOL correctly
|
||||
inline void AI_MD5_SKIP_SPACES(const char **sz, const char *bufferEnd, int linenumber) {
|
||||
if (!SkipSpaces(sz, bufferEnd)) {
|
||||
MD5Parser::ReportWarning("Unexpected end of line", linenumber);
|
||||
}
|
||||
}
|
||||
|
||||
// read a triple float in brackets: (1.0 1.0 1.0)
|
||||
inline void AI_MD5_READ_TRIPLE(aiVector3D &vec, const char **sz, const char *bufferEnd, int linenumber) {
|
||||
AI_MD5_SKIP_SPACES(sz, bufferEnd, linenumber);
|
||||
if ('(' != **sz) {
|
||||
MD5Parser::ReportWarning("Unexpected token: ( was expected", linenumber);
|
||||
if (*sz == bufferEnd)
|
||||
return;
|
||||
++*sz;
|
||||
}
|
||||
if (*sz == bufferEnd)
|
||||
return;
|
||||
++*sz;
|
||||
AI_MD5_SKIP_SPACES(sz, bufferEnd, linenumber);
|
||||
*sz = fast_atoreal_move<float>(*sz, (float &)vec.x);
|
||||
AI_MD5_SKIP_SPACES(sz, bufferEnd, linenumber);
|
||||
*sz = fast_atoreal_move<float>(*sz, (float &)vec.y);
|
||||
AI_MD5_SKIP_SPACES(sz, bufferEnd, linenumber);
|
||||
*sz = fast_atoreal_move<float>(*sz, (float &)vec.z);
|
||||
AI_MD5_SKIP_SPACES(sz, bufferEnd, linenumber);
|
||||
if (')' != **sz) {
|
||||
MD5Parser::ReportWarning("Unexpected token: ) was expected", linenumber);
|
||||
}
|
||||
if (*sz == bufferEnd)
|
||||
return;
|
||||
++*sz;
|
||||
}
|
||||
|
||||
// parse a string, enclosed in quotation marks or not
|
||||
inline bool AI_MD5_PARSE_STRING(const char **sz, const char *bufferEnd, aiString &out, int linenumber) {
|
||||
bool bQuota = (**sz == '\"');
|
||||
const char *szStart = *sz;
|
||||
while (!IsSpaceOrNewLine(**sz)) {
|
||||
++*sz;
|
||||
if (*sz == bufferEnd) break;
|
||||
}
|
||||
const char *szEnd = *sz;
|
||||
if (bQuota) {
|
||||
szStart++;
|
||||
if ('\"' != *(szEnd -= 1)) {
|
||||
MD5Parser::ReportWarning("Expected closing quotation marks in string", linenumber);
|
||||
++*sz;
|
||||
}
|
||||
}
|
||||
out.length = (ai_uint32)(szEnd - szStart);
|
||||
::memcpy(out.data, szStart, out.length);
|
||||
out.data[out.length] = '\0';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// parse a string, enclosed in quotation marks
|
||||
inline void AI_MD5_PARSE_STRING_IN_QUOTATION(const char **sz, const char *bufferEnd, aiString &out) {
|
||||
out.length = 0u;
|
||||
while (('\"' != **sz && '\0' != **sz) && *sz != bufferEnd) {
|
||||
++*sz;
|
||||
}
|
||||
if ('\0' != **sz) {
|
||||
const char *szStart = ++(*sz);
|
||||
|
||||
while (('\"' != **sz && '\0' != **sz) && *sz != bufferEnd) {
|
||||
++*sz;
|
||||
}
|
||||
if ('\0' != **sz) {
|
||||
const char *szEnd = *sz;
|
||||
++*sz;
|
||||
out.length = (ai_uint32)(szEnd - szStart);
|
||||
::memcpy(out.data, szStart, out.length);
|
||||
}
|
||||
}
|
||||
out.data[out.length] = '\0';
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Some dirty macros just because they're so funny and easy to debug
|
||||
|
||||
// skip all spaces ... handle EOL correctly
|
||||
#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)) { \
|
||||
MD5Parser::ReportWarning("Expected closing quotation marks in string", \
|
||||
elem.iLineNumber); \
|
||||
continue; \
|
||||
} \
|
||||
} \
|
||||
out.length = (size_t)(szEnd - szStart); \
|
||||
::memcpy(out.data, szStart, out.length); \
|
||||
out.data[out.length] = '\0';
|
||||
|
||||
// parse a string, enclosed in quotation marks
|
||||
#define AI_MD5_PARSE_STRING_IN_QUOTATION(out) \
|
||||
while ('\"' != *sz) \
|
||||
++sz; \
|
||||
const char *szStart = ++sz; \
|
||||
while ('\"' != *sz) \
|
||||
++sz; \
|
||||
const char *szEnd = (sz++); \
|
||||
out.length = (ai_uint32)(szEnd - szStart); \
|
||||
::memcpy(out.data, szStart, out.length); \
|
||||
out.data[out.length] = '\0';
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// .MD5MESH parsing function
|
||||
MD5MeshParser::MD5MeshParser(SectionList &mSections) {
|
||||
MD5MeshParser::MD5MeshParser(SectionArray &mSections) {
|
||||
ASSIMP_LOG_DEBUG("MD5MeshParser begin");
|
||||
|
||||
// now parse all sections
|
||||
for (SectionList::const_iterator iter = mSections.begin(), iterEnd = mSections.end(); iter != iterEnd; ++iter) {
|
||||
for (SectionArray::const_iterator iter = mSections.begin(), iterEnd = mSections.end(); iter != iterEnd; ++iter) {
|
||||
if ((*iter).mName == "numMeshes") {
|
||||
mMeshes.reserve(::strtoul10((*iter).mGlobalValue.c_str()));
|
||||
} else if ((*iter).mName == "numJoints") {
|
||||
|
|
@ -257,14 +319,15 @@ MD5MeshParser::MD5MeshParser(SectionList &mSections) {
|
|||
BoneDesc &desc = mJoints.back();
|
||||
|
||||
const char *sz = elem.szStart;
|
||||
AI_MD5_PARSE_STRING_IN_QUOTATION(desc.mName);
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_PARSE_STRING_IN_QUOTATION(&sz, elem.end, desc.mName);
|
||||
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
|
||||
// negative values, at least -1, is allowed here
|
||||
desc.mParentIndex = (int)strtol10(sz, &sz);
|
||||
|
||||
AI_MD5_READ_TRIPLE(desc.mPositionXYZ);
|
||||
AI_MD5_READ_TRIPLE(desc.mRotationQuat); // normalized quaternion, so w is not there
|
||||
AI_MD5_READ_TRIPLE(desc.mPositionXYZ, &sz, elem.end, elem.iLineNumber);
|
||||
AI_MD5_READ_TRIPLE(desc.mRotationQuat, &sz, elem.end, elem.iLineNumber); // normalized quaternion, so w is not there
|
||||
}
|
||||
} else if ((*iter).mName == "mesh") {
|
||||
mMeshes.emplace_back();
|
||||
|
|
@ -275,52 +338,52 @@ MD5MeshParser::MD5MeshParser(SectionList &mSections) {
|
|||
|
||||
// shader attribute
|
||||
if (TokenMatch(sz, "shader", 6)) {
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_PARSE_STRING_IN_QUOTATION(desc.mShader);
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
AI_MD5_PARSE_STRING_IN_QUOTATION(&sz, elem.end, desc.mShader);
|
||||
}
|
||||
// numverts attribute
|
||||
else if (TokenMatch(sz, "numverts", 8)) {
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
desc.mVertices.resize(strtoul10(sz));
|
||||
}
|
||||
// numtris attribute
|
||||
else if (TokenMatch(sz, "numtris", 7)) {
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
desc.mFaces.resize(strtoul10(sz));
|
||||
}
|
||||
// numweights attribute
|
||||
else if (TokenMatch(sz, "numweights", 10)) {
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
desc.mWeights.resize(strtoul10(sz));
|
||||
}
|
||||
// vert attribute
|
||||
// "vert 0 ( 0.394531 0.513672 ) 0 1"
|
||||
else if (TokenMatch(sz, "vert", 4)) {
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
const unsigned int idx = ::strtoul10(sz, &sz);
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
if (idx >= desc.mVertices.size())
|
||||
desc.mVertices.resize(idx + 1);
|
||||
|
||||
VertexDesc &vert = desc.mVertices[idx];
|
||||
if ('(' != *sz++)
|
||||
MD5Parser::ReportWarning("Unexpected token: ( was expected", elem.iLineNumber);
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
sz = fast_atoreal_move<float>(sz, (float &)vert.mUV.x);
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
sz = fast_atoreal_move<float>(sz, (float &)vert.mUV.y);
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
if (')' != *sz++)
|
||||
MD5Parser::ReportWarning("Unexpected token: ) was expected", elem.iLineNumber);
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
vert.mFirstWeight = ::strtoul10(sz, &sz);
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
vert.mNumWeights = ::strtoul10(sz, &sz);
|
||||
}
|
||||
// tri attribute
|
||||
// "tri 0 15 13 12"
|
||||
else if (TokenMatch(sz, "tri", 3)) {
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
const unsigned int idx = strtoul10(sz, &sz);
|
||||
if (idx >= desc.mFaces.size())
|
||||
desc.mFaces.resize(idx + 1);
|
||||
|
|
@ -328,24 +391,24 @@ MD5MeshParser::MD5MeshParser(SectionList &mSections) {
|
|||
aiFace &face = desc.mFaces[idx];
|
||||
face.mIndices = new unsigned int[face.mNumIndices = 3];
|
||||
for (unsigned int i = 0; i < 3; ++i) {
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
face.mIndices[i] = strtoul10(sz, &sz);
|
||||
}
|
||||
}
|
||||
// weight attribute
|
||||
// "weight 362 5 0.500000 ( -3.553583 11.893474 9.719339 )"
|
||||
else if (TokenMatch(sz, "weight", 6)) {
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
const unsigned int idx = strtoul10(sz, &sz);
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
if (idx >= desc.mWeights.size())
|
||||
desc.mWeights.resize(idx + 1);
|
||||
|
||||
WeightDesc &weight = desc.mWeights[idx];
|
||||
weight.mBone = strtoul10(sz, &sz);
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
sz = fast_atoreal_move<float>(sz, weight.mWeight);
|
||||
AI_MD5_READ_TRIPLE(weight.vOffsetPosition);
|
||||
AI_MD5_READ_TRIPLE(weight.vOffsetPosition, &sz, elem.end, elem.iLineNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -355,12 +418,12 @@ MD5MeshParser::MD5MeshParser(SectionList &mSections) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// .MD5ANIM parsing function
|
||||
MD5AnimParser::MD5AnimParser(SectionList &mSections) {
|
||||
MD5AnimParser::MD5AnimParser(SectionArray &mSections) {
|
||||
ASSIMP_LOG_DEBUG("MD5AnimParser begin");
|
||||
|
||||
fFrameRate = 24.0f;
|
||||
mNumAnimatedComponents = UINT_MAX;
|
||||
for (SectionList::const_iterator iter = mSections.begin(), iterEnd = mSections.end(); iter != iterEnd; ++iter) {
|
||||
for (SectionArray::const_iterator iter = mSections.begin(), iterEnd = mSections.end(); iter != iterEnd; ++iter) {
|
||||
if ((*iter).mName == "hierarchy") {
|
||||
// "sheath" 0 63 6
|
||||
for (const auto &elem : (*iter).mElements) {
|
||||
|
|
@ -368,18 +431,18 @@ MD5AnimParser::MD5AnimParser(SectionList &mSections) {
|
|||
AnimBoneDesc &desc = mAnimatedBones.back();
|
||||
|
||||
const char *sz = elem.szStart;
|
||||
AI_MD5_PARSE_STRING_IN_QUOTATION(desc.mName);
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_PARSE_STRING_IN_QUOTATION(&sz, elem.end, desc.mName);
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
|
||||
// parent index - negative values are allowed (at least -1)
|
||||
desc.mParentIndex = ::strtol10(sz, &sz);
|
||||
|
||||
// flags (highest is 2^6-1)
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
if (63 < (desc.iFlags = ::strtoul10(sz, &sz))) {
|
||||
MD5Parser::ReportWarning("Invalid flag combination in hierarchy section", elem.iLineNumber);
|
||||
}
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_SKIP_SPACES(& sz, elem.end, elem.iLineNumber);
|
||||
|
||||
// index of the first animation keyframe component for this joint
|
||||
desc.iFirstKeyIndex = ::strtoul10(sz, &sz);
|
||||
|
|
@ -392,8 +455,8 @@ MD5AnimParser::MD5AnimParser(SectionList &mSections) {
|
|||
mBaseFrames.emplace_back();
|
||||
BaseFrameDesc &desc = mBaseFrames.back();
|
||||
|
||||
AI_MD5_READ_TRIPLE(desc.vPositionXYZ);
|
||||
AI_MD5_READ_TRIPLE(desc.vRotationQuat);
|
||||
AI_MD5_READ_TRIPLE(desc.vPositionXYZ, &sz, elem.end, elem.iLineNumber);
|
||||
AI_MD5_READ_TRIPLE(desc.vRotationQuat, &sz, elem.end, elem.iLineNumber);
|
||||
}
|
||||
} else if ((*iter).mName == "frame") {
|
||||
if (!(*iter).mGlobalValue.length()) {
|
||||
|
|
@ -413,7 +476,7 @@ MD5AnimParser::MD5AnimParser(SectionList &mSections) {
|
|||
// now read all elements (continuous list of floats)
|
||||
for (const auto &elem : (*iter).mElements) {
|
||||
const char *sz = elem.szStart;
|
||||
while (SkipSpacesAndLineEnd(&sz)) {
|
||||
while (SkipSpacesAndLineEnd(&sz, elem.end)) {
|
||||
float f;
|
||||
sz = fast_atoreal_move<float>(sz, f);
|
||||
desc.mValues.push_back(f);
|
||||
|
|
@ -440,11 +503,11 @@ MD5AnimParser::MD5AnimParser(SectionList &mSections) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// .MD5CAMERA parsing function
|
||||
MD5CameraParser::MD5CameraParser(SectionList &mSections) {
|
||||
MD5CameraParser::MD5CameraParser(SectionArray &mSections) {
|
||||
ASSIMP_LOG_DEBUG("MD5CameraParser begin");
|
||||
fFrameRate = 24.0f;
|
||||
|
||||
for (SectionList::const_iterator iter = mSections.begin(), iterEnd = mSections.end(); iter != iterEnd; ++iter) {
|
||||
for (SectionArray::const_iterator iter = mSections.begin(), iterEnd = mSections.end(); iter != iterEnd; ++iter) {
|
||||
if ((*iter).mName == "numFrames") {
|
||||
frames.reserve(strtoul10((*iter).mGlobalValue.c_str()));
|
||||
} else if ((*iter).mName == "frameRate") {
|
||||
|
|
@ -461,9 +524,9 @@ MD5CameraParser::MD5CameraParser(SectionList &mSections) {
|
|||
|
||||
frames.emplace_back();
|
||||
CameraAnimFrameDesc &cur = frames.back();
|
||||
AI_MD5_READ_TRIPLE(cur.vPositionXYZ);
|
||||
AI_MD5_READ_TRIPLE(cur.vRotationQuat);
|
||||
AI_MD5_SKIP_SPACES();
|
||||
AI_MD5_READ_TRIPLE(cur.vPositionXYZ, &sz, elem.end, elem.iLineNumber);
|
||||
AI_MD5_READ_TRIPLE(cur.vRotationQuat, &sz, elem.end, elem.iLineNumber);
|
||||
AI_MD5_SKIP_SPACES(&sz, elem.end, elem.iLineNumber);
|
||||
cur.fFOV = fast_atof(sz);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2022, assimp team
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -39,7 +38,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/** @file MD5Parser.h
|
||||
* @brief Definition of the .MD5 parser class.
|
||||
|
|
@ -51,61 +50,60 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/types.h>
|
||||
#include <assimp/ParsingUtils.h>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
struct aiFace;
|
||||
|
||||
namespace Assimp {
|
||||
namespace MD5 {
|
||||
namespace Assimp {
|
||||
namespace MD5 {
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Represents a single element in a MD5 file
|
||||
*
|
||||
* Elements are always contained in sections.
|
||||
*/
|
||||
struct Element
|
||||
{
|
||||
struct Element {
|
||||
//! Points to the starting point of the element
|
||||
//! Whitespace at the beginning and at the end have been removed,
|
||||
//! Elements are terminated with \0
|
||||
char* szStart;
|
||||
|
||||
const char *end;
|
||||
|
||||
//! Original line number (can be used in error messages
|
||||
//! if a parsing error occurs)
|
||||
unsigned int iLineNumber;
|
||||
};
|
||||
|
||||
typedef std::vector< Element > ElementList;
|
||||
using ElementArray = std::vector<Element>;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Represents a section of a MD5 file (such as the mesh or the joints section)
|
||||
*
|
||||
* A section is always enclosed in { and } brackets.
|
||||
*/
|
||||
struct Section
|
||||
{
|
||||
struct Section {
|
||||
//! Original line number (can be used in error messages
|
||||
//! if a parsing error occurs)
|
||||
unsigned int iLineNumber;
|
||||
|
||||
//! List of all elements which have been parsed in this section.
|
||||
ElementList mElements;
|
||||
ElementArray mElements;
|
||||
|
||||
//! Name of the section
|
||||
std::string mName;
|
||||
|
||||
//! For global elements: the value of the element as string
|
||||
//! Iif !length() the section is not a global element
|
||||
//! if !length() the section is not a global element
|
||||
std::string mGlobalValue;
|
||||
};
|
||||
|
||||
typedef std::vector< Section> SectionList;
|
||||
using SectionArray = std::vector<Section>;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Basic information about a joint
|
||||
*/
|
||||
struct BaseJointDescription
|
||||
{
|
||||
struct BaseJointDescription {
|
||||
//! Name of the bone
|
||||
aiString mName;
|
||||
|
||||
|
|
@ -116,8 +114,7 @@ struct BaseJointDescription
|
|||
// ---------------------------------------------------------------------------
|
||||
/** Represents a bone (joint) descriptor in a MD5Mesh file
|
||||
*/
|
||||
struct BoneDesc : BaseJointDescription
|
||||
{
|
||||
struct BoneDesc : BaseJointDescription {
|
||||
//! Absolute position of the bone
|
||||
aiVector3D mPositionXYZ;
|
||||
|
||||
|
|
@ -137,13 +134,12 @@ struct BoneDesc : BaseJointDescription
|
|||
unsigned int mMap;
|
||||
};
|
||||
|
||||
typedef std::vector< BoneDesc > BoneList;
|
||||
using BoneArray = std::vector<BoneDesc>;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Represents a bone (joint) descriptor in a MD5Anim file
|
||||
*/
|
||||
struct AnimBoneDesc : BaseJointDescription
|
||||
{
|
||||
struct AnimBoneDesc : BaseJointDescription {
|
||||
//! Flags (AI_MD5_ANIMATION_FLAG_xxx)
|
||||
unsigned int iFlags;
|
||||
|
||||
|
|
@ -151,35 +147,31 @@ struct AnimBoneDesc : BaseJointDescription
|
|||
unsigned int iFirstKeyIndex;
|
||||
};
|
||||
|
||||
typedef std::vector< AnimBoneDesc > AnimBoneList;
|
||||
|
||||
using AnimBoneArray = std::vector< AnimBoneDesc >;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Represents a base frame descriptor in a MD5Anim file
|
||||
*/
|
||||
struct BaseFrameDesc
|
||||
{
|
||||
struct BaseFrameDesc {
|
||||
aiVector3D vPositionXYZ;
|
||||
aiVector3D vRotationQuat;
|
||||
};
|
||||
|
||||
typedef std::vector< BaseFrameDesc > BaseFrameList;
|
||||
using BaseFrameArray = std::vector<BaseFrameDesc>;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Represents a camera animation frame in a MDCamera file
|
||||
*/
|
||||
struct CameraAnimFrameDesc : BaseFrameDesc
|
||||
{
|
||||
struct CameraAnimFrameDesc : BaseFrameDesc {
|
||||
float fFOV;
|
||||
};
|
||||
|
||||
typedef std::vector< CameraAnimFrameDesc > CameraFrameList;
|
||||
using CameraFrameArray = std::vector<CameraAnimFrameDesc>;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Represents a frame descriptor in a MD5Anim file
|
||||
*/
|
||||
struct FrameDesc
|
||||
{
|
||||
struct FrameDesc {
|
||||
//! Index of the frame
|
||||
unsigned int iIndex;
|
||||
|
||||
|
|
@ -187,15 +179,14 @@ struct FrameDesc
|
|||
std::vector< float > mValues;
|
||||
};
|
||||
|
||||
typedef std::vector< FrameDesc > FrameList;
|
||||
using FrameArray = std::vector<FrameDesc>;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Represents a vertex descriptor in a MD5 file
|
||||
*/
|
||||
struct VertexDesc {
|
||||
VertexDesc() AI_NO_EXCEPT
|
||||
: mFirstWeight(0)
|
||||
, mNumWeights(0) {
|
||||
: mFirstWeight(0), mNumWeights(0) {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
|
@ -210,13 +201,12 @@ struct VertexDesc {
|
|||
unsigned int mNumWeights;
|
||||
};
|
||||
|
||||
typedef std::vector< VertexDesc > VertexList;
|
||||
using VertexArray = std::vector<VertexDesc>;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Represents a vertex weight descriptor in a MD5 file
|
||||
*/
|
||||
struct WeightDesc
|
||||
{
|
||||
struct WeightDesc {
|
||||
//! Index of the bone to which this weight refers
|
||||
unsigned int mBone;
|
||||
|
||||
|
|
@ -228,28 +218,27 @@ struct WeightDesc
|
|||
aiVector3D vOffsetPosition;
|
||||
};
|
||||
|
||||
typedef std::vector< WeightDesc > WeightList;
|
||||
typedef std::vector< aiFace > FaceList;
|
||||
using WeightArray = std::vector<WeightDesc>;
|
||||
using FaceArray = std::vector<aiFace>;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Represents a mesh in a MD5 file
|
||||
*/
|
||||
struct MeshDesc
|
||||
{
|
||||
struct MeshDesc {
|
||||
//! Weights of the mesh
|
||||
WeightList mWeights;
|
||||
WeightArray mWeights;
|
||||
|
||||
//! Vertices of the mesh
|
||||
VertexList mVertices;
|
||||
VertexArray mVertices;
|
||||
|
||||
//! Faces of the mesh
|
||||
FaceList mFaces;
|
||||
FaceArray mFaces;
|
||||
|
||||
//! Name of the shader (=texture) to be assigned to the mesh
|
||||
aiString mShader;
|
||||
};
|
||||
|
||||
typedef std::vector< MeshDesc > MeshList;
|
||||
using MeshArray = std::vector<MeshDesc>;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Convert a quaternion to its usual representation
|
||||
|
|
@ -261,9 +250,11 @@ inline void ConvertQuaternion (const aiVector3D& in, aiQuaternion& out) {
|
|||
|
||||
const float t = 1.0f - (in.x*in.x) - (in.y*in.y) - (in.z*in.z);
|
||||
|
||||
if (t < 0.0f)
|
||||
if (t < 0.0f) {
|
||||
out.w = 0.0f;
|
||||
else out.w = std::sqrt (t);
|
||||
} else {
|
||||
out.w = std::sqrt (t);
|
||||
}
|
||||
|
||||
// Assimp convention.
|
||||
out.w *= -1.f;
|
||||
|
|
@ -272,23 +263,21 @@ inline void ConvertQuaternion (const aiVector3D& in, aiQuaternion& out) {
|
|||
// ---------------------------------------------------------------------------
|
||||
/** Parses the data sections of a MD5 mesh file
|
||||
*/
|
||||
class MD5MeshParser
|
||||
{
|
||||
class MD5MeshParser {
|
||||
public:
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Constructs a new MD5MeshParser instance from an existing
|
||||
* preparsed list of file sections.
|
||||
*
|
||||
* @param mSections List of file sections (output of MD5Parser)
|
||||
*/
|
||||
explicit MD5MeshParser(SectionList& mSections);
|
||||
explicit MD5MeshParser(SectionArray& mSections);
|
||||
|
||||
//! List of all meshes
|
||||
MeshList mMeshes;
|
||||
MeshArray mMeshes;
|
||||
|
||||
//! List of all joints
|
||||
BoneList mJoints;
|
||||
BoneArray mJoints;
|
||||
};
|
||||
|
||||
// remove this flag if you need to the bounding box data
|
||||
|
|
@ -297,30 +286,28 @@ public:
|
|||
// ---------------------------------------------------------------------------
|
||||
/** Parses the data sections of a MD5 animation file
|
||||
*/
|
||||
class MD5AnimParser
|
||||
{
|
||||
class MD5AnimParser {
|
||||
public:
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Constructs a new MD5AnimParser instance from an existing
|
||||
* preparsed list of file sections.
|
||||
*
|
||||
* @param mSections List of file sections (output of MD5Parser)
|
||||
*/
|
||||
explicit MD5AnimParser(SectionList& mSections);
|
||||
explicit MD5AnimParser(SectionArray& mSections);
|
||||
|
||||
|
||||
//! Output frame rate
|
||||
float fFrameRate;
|
||||
|
||||
//! List of animation bones
|
||||
AnimBoneList mAnimatedBones;
|
||||
AnimBoneArray mAnimatedBones;
|
||||
|
||||
//! List of base frames
|
||||
BaseFrameList mBaseFrames;
|
||||
BaseFrameArray mBaseFrames;
|
||||
|
||||
//! List of animation frames
|
||||
FrameList mFrames;
|
||||
FrameArray mFrames;
|
||||
|
||||
//! Number of animated components
|
||||
unsigned int mNumAnimatedComponents;
|
||||
|
|
@ -329,18 +316,15 @@ public:
|
|||
// ---------------------------------------------------------------------------
|
||||
/** Parses the data sections of a MD5 camera animation file
|
||||
*/
|
||||
class MD5CameraParser
|
||||
{
|
||||
class MD5CameraParser {
|
||||
public:
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Constructs a new MD5CameraParser instance from an existing
|
||||
* preparsed list of file sections.
|
||||
*
|
||||
* @param mSections List of file sections (output of MD5Parser)
|
||||
*/
|
||||
explicit MD5CameraParser(SectionList& mSections);
|
||||
|
||||
explicit MD5CameraParser(SectionArray& mSections);
|
||||
|
||||
//! Output frame rate
|
||||
float fFrameRate;
|
||||
|
|
@ -349,17 +333,15 @@ public:
|
|||
std::vector<unsigned int> cuts;
|
||||
|
||||
//! Frames
|
||||
CameraFrameList frames;
|
||||
CameraFrameArray frames;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Parses the block structure of MD5MESH and MD5ANIM files (but does no
|
||||
* further processing)
|
||||
*/
|
||||
class MD5Parser
|
||||
{
|
||||
class MD5Parser {
|
||||
public:
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Constructs a new MD5Parser instance from an existing buffer.
|
||||
*
|
||||
|
|
@ -368,100 +350,112 @@ public:
|
|||
*/
|
||||
MD5Parser(char* buffer, unsigned int fileSize);
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Report a specific error message and throw an exception
|
||||
* @param error Error message to be reported
|
||||
* @param line Index of the line where the error occurred
|
||||
*/
|
||||
AI_WONT_RETURN static void ReportError (const char* error, unsigned int line) AI_WONT_RETURN_SUFFIX;
|
||||
AI_WONT_RETURN static void ReportError(const char* error, unsigned int line) AI_WONT_RETURN_SUFFIX;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Report a specific warning
|
||||
* @param warn Warn message to be reported
|
||||
* @param line Index of the line where the error occurred
|
||||
*/
|
||||
static void ReportWarning (const char* warn, unsigned int line);
|
||||
static void ReportWarning(const char* warn, unsigned int line);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Report a specific error
|
||||
* @param error Error message to be reported
|
||||
*/
|
||||
AI_WONT_RETURN void ReportError (const char* error) AI_WONT_RETURN_SUFFIX;
|
||||
|
||||
void ReportError (const char* error) {
|
||||
return ReportError(error, lineNumber);
|
||||
}
|
||||
|
||||
void ReportWarning (const char* warn) {
|
||||
return ReportWarning(warn, lineNumber);
|
||||
}
|
||||
|
||||
public:
|
||||
// -------------------------------------------------------------------
|
||||
/** Report a specific warning
|
||||
* @param error Warn message to be reported
|
||||
*/
|
||||
void ReportWarning (const char* warn);
|
||||
|
||||
//! List of all sections which have been read
|
||||
SectionList mSections;
|
||||
SectionArray mSections;
|
||||
|
||||
private:
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Parses a file section. The current file pointer must be outside
|
||||
* of a section.
|
||||
* @param out Receives the section data
|
||||
* @return true if the end of the file has been reached
|
||||
* @throws ImportErrorException if an error occurs
|
||||
*/
|
||||
bool ParseSection(Section& out);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Parses the file header
|
||||
* @throws ImportErrorException if an error occurs
|
||||
*/
|
||||
void ParseHeader();
|
||||
bool SkipLine(const char* in, const char** out);
|
||||
bool SkipLine( );
|
||||
bool SkipSpacesAndLineEnd( const char* in, const char** out);
|
||||
bool SkipSpacesAndLineEnd();
|
||||
bool SkipSpaces();
|
||||
|
||||
|
||||
// override these functions to make sure the line counter gets incremented
|
||||
// -------------------------------------------------------------------
|
||||
bool SkipLine( const char* in, const char** out)
|
||||
{
|
||||
++lineNumber;
|
||||
return Assimp::SkipLine(in,out);
|
||||
}
|
||||
// -------------------------------------------------------------------
|
||||
bool SkipLine( )
|
||||
{
|
||||
return SkipLine(buffer,(const char**)&buffer);
|
||||
}
|
||||
// -------------------------------------------------------------------
|
||||
bool SkipSpacesAndLineEnd( const char* in, const char** out)
|
||||
{
|
||||
bool bHad = false;
|
||||
bool running = true;
|
||||
while (running) {
|
||||
if( *in == '\r' || *in == '\n') {
|
||||
// we open files in binary mode, so there could be \r\n sequences ...
|
||||
if (!bHad) {
|
||||
bHad = true;
|
||||
++lineNumber;
|
||||
}
|
||||
}
|
||||
else if (*in == '\t' || *in == ' ')bHad = false;
|
||||
else break;
|
||||
in++;
|
||||
}
|
||||
*out = in;
|
||||
return *in != '\0';
|
||||
}
|
||||
// -------------------------------------------------------------------
|
||||
bool SkipSpacesAndLineEnd( )
|
||||
{
|
||||
return SkipSpacesAndLineEnd(buffer,(const char**)&buffer);
|
||||
}
|
||||
// -------------------------------------------------------------------
|
||||
bool SkipSpaces( )
|
||||
{
|
||||
return Assimp::SkipSpaces((const char**)&buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
char* buffer;
|
||||
const char* bufferEnd;
|
||||
unsigned int fileSize;
|
||||
unsigned int lineNumber;
|
||||
};
|
||||
}}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
inline void MD5Parser::ReportWarning (const char* warn) {
|
||||
return ReportWarning(warn, lineNumber);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
inline void MD5Parser::ReportError(const char* error) {
|
||||
ReportError(error, lineNumber);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
inline bool MD5Parser::SkipLine(const char* in, const char** out) {
|
||||
++lineNumber;
|
||||
return Assimp::SkipLine(in, out, bufferEnd);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
inline bool MD5Parser::SkipLine( ) {
|
||||
return SkipLine(buffer,(const char**)&buffer);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
inline bool MD5Parser::SkipSpacesAndLineEnd( const char* in, const char** out) {
|
||||
if (in == bufferEnd) {
|
||||
*out = in;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool bHad = false, running = true;
|
||||
while (running) {
|
||||
if( *in == '\r' || *in == '\n') {
|
||||
// we open files in binary mode, so there could be \r\n sequences ...
|
||||
if (!bHad) {
|
||||
bHad = true;
|
||||
++lineNumber;
|
||||
}
|
||||
} else if (*in == '\t' || *in == ' ') {
|
||||
bHad = false;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
++in;
|
||||
if (in == bufferEnd) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
*out = in;
|
||||
return *in != '\0';
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
inline bool MD5Parser::SkipSpacesAndLineEnd() {
|
||||
return SkipSpacesAndLineEnd(buffer,(const char**)&buffer);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
inline bool MD5Parser::SkipSpaces() {
|
||||
return Assimp::SkipSpaces((const char**)&buffer, bufferEnd);
|
||||
}
|
||||
|
||||
} // namespace Assimp
|
||||
} // namespace MD5
|
||||
|
||||
#endif // AI_MD5PARSER_H_INCLUDED
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue