update assimp lib

This commit is contained in:
marauder2k7 2024-12-09 20:22:47 +00:00
parent 03a348deb7
commit d3f8fee74e
1725 changed files with 196314 additions and 62009 deletions

View file

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -48,8 +48,28 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/ByteSwapper.h>
#include <assimp/fast_atof.h>
#include <assimp/DefaultLogger.hpp>
#include <unordered_set>
#include <utility>
using namespace Assimp;
namespace Assimp {
std::string to_string(EElementSemantic e) {
switch (e) {
case EEST_Vertex:
return std::string{ "vertex" };
case EEST_TriStrip:
return std::string{ "tristrips" };
case EEST_Edge:
return std::string{ "edge" };
case EEST_Material:
return std::string{ "material" };
case EEST_TextureFile:
return std::string{ "TextureFile" };
default:
return std::string{ "invalid" };
}
}
// ------------------------------------------------------------------------------------------------
PLY::EDataType PLY::Property::ParseDataType(std::vector<char> &buffer) {
@ -280,6 +300,8 @@ bool PLY::Element::ParseElement(IOStreamBuffer<char> &streamBuffer, std::vector<
// if the exact semantic can't be determined, just store
// the original string identifier
pOut->szName = std::string(&buffer[0], &buffer[0] + strlen(&buffer[0]));
auto pos = pOut->szName.find_last_of(' ');
pOut->szName.erase(pos, pOut->szName.size());
}
if (!PLY::DOM::SkipSpaces(buffer))
@ -295,7 +317,7 @@ bool PLY::Element::ParseElement(IOStreamBuffer<char> &streamBuffer, std::vector<
return true;
}
//parse the number of occurrences of this element
// parse the number of occurrences of this element
const char *pCur = (char *)&buffer[0];
pOut->NumOccur = strtoul10(pCur, &pCur);
@ -307,8 +329,8 @@ bool PLY::Element::ParseElement(IOStreamBuffer<char> &streamBuffer, std::vector<
streamBuffer.getNextLine(buffer);
pCur = (char *)&buffer[0];
// skip all comments
PLY::DOM::SkipComments(buffer);
// skip all comments and go to next line
if (PLY::DOM::SkipComments(buffer)) continue;
PLY::Property prop;
if (!PLY::Property::ParseProperty(buffer, &prop))
@ -320,13 +342,13 @@ bool PLY::Element::ParseElement(IOStreamBuffer<char> &streamBuffer, std::vector<
return true;
}
// ------------------------------------------------------------------------------------------------
bool PLY::DOM::SkipSpaces(std::vector<char> &buffer) {
const char *pCur = buffer.empty() ? nullptr : (char *)&buffer[0];
const char *end = pCur + buffer.size();
bool ret = false;
if (pCur) {
const char *szCur = pCur;
ret = Assimp::SkipSpaces(pCur, &pCur);
ret = Assimp::SkipSpaces(pCur, &pCur, end);
uintptr_t iDiff = (uintptr_t)pCur - (uintptr_t)szCur;
buffer.erase(buffer.begin(), buffer.begin() + iDiff);
@ -338,10 +360,11 @@ bool PLY::DOM::SkipSpaces(std::vector<char> &buffer) {
bool PLY::DOM::SkipLine(std::vector<char> &buffer) {
const char *pCur = buffer.empty() ? nullptr : (char *)&buffer[0];
const char *end = pCur + buffer.size();
bool ret = false;
if (pCur) {
const char *szCur = pCur;
ret = Assimp::SkipLine(pCur, &pCur);
ret = Assimp::SkipLine(pCur, &pCur, end);
uintptr_t iDiff = (uintptr_t)pCur - (uintptr_t)szCur;
buffer.erase(buffer.begin(), buffer.begin() + iDiff);
@ -368,10 +391,11 @@ bool PLY::DOM::TokenMatch(std::vector<char> &buffer, const char *token, unsigned
bool PLY::DOM::SkipSpacesAndLineEnd(std::vector<char> &buffer) {
const char *pCur = buffer.empty() ? nullptr : (char *)&buffer[0];
const char *end = pCur + buffer.size();
bool ret = false;
if (pCur) {
const char *szCur = pCur;
ret = Assimp::SkipSpacesAndLineEnd(pCur, &pCur);
ret = Assimp::SkipSpacesAndLineEnd(pCur, &pCur, end);
uintptr_t iDiff = (uintptr_t)pCur - (uintptr_t)szCur;
buffer.erase(buffer.begin(), buffer.begin() + iDiff);
@ -381,10 +405,10 @@ bool PLY::DOM::SkipSpacesAndLineEnd(std::vector<char> &buffer) {
return ret;
}
bool PLY::DOM::SkipComments(std::vector<char> &buffer) {
bool PLY::DOM::SkipComments(std::vector<char> buffer) {
ai_assert(!buffer.empty());
std::vector<char> nbuffer = buffer;
std::vector<char> nbuffer = std::move(buffer);
// skip spaces
if (!SkipSpaces(nbuffer)) {
return false;
@ -410,6 +434,7 @@ bool PLY::DOM::SkipComments(std::vector<char> &buffer) {
bool PLY::DOM::ParseHeader(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffer, bool isBinary) {
ASSIMP_LOG_VERBOSE_DEBUG("PLY::DOM::ParseHeader() begin");
std::unordered_set<std::string> definedAlElements;
// parse all elements
while (!buffer.empty()) {
// skip all comments
@ -418,13 +443,21 @@ bool PLY::DOM::ParseHeader(IOStreamBuffer<char> &streamBuffer, std::vector<char>
PLY::Element out;
if (PLY::Element::ParseElement(streamBuffer, buffer, &out)) {
// add the element to the list of elements
const auto propertyName = (out.szName.empty()) ? to_string(out.eSemantic) : out.szName;
auto alreadyDefined = definedAlElements.find(propertyName);
if (alreadyDefined != definedAlElements.end()) {
throw DeadlyImportError("Property '" + propertyName + "' in header already defined ");
}
definedAlElements.insert(propertyName);
alElements.push_back(out);
} else if (TokenMatch(buffer, "end_header", 10)) { //checks for /n ending, if it doesn't end with /r/n
} else if (TokenMatch(buffer, "end_header", 10)) {
// we have reached the end of the header
break;
} else {
// ignore unknown header elements
streamBuffer.getNextLine(buffer);
if (!streamBuffer.getNextLine(buffer))
return false;
}
}
@ -444,7 +477,7 @@ bool PLY::DOM::ParseElementInstanceLists(IOStreamBuffer<char> &streamBuffer, std
std::vector<PLY::ElementInstanceList>::iterator a = alElementData.begin();
// parse all element instances
//construct vertices and faces
// construct vertices and faces
for (; i != alElements.end(); ++i, ++a) {
if ((*i).eSemantic == EEST_Vertex || (*i).eSemantic == EEST_Face || (*i).eSemantic == EEST_TriStrip) {
PLY::ElementInstanceList::ParseInstanceList(streamBuffer, buffer, &(*i), nullptr, loader);
@ -501,10 +534,6 @@ bool PLY::DOM::ParseInstanceBinary(IOStreamBuffer<char> &streamBuffer, DOM *p_pc
streamBuffer.getNextBlock(buffer);
// remove first char if it's /n in case of file with /r/n
if (((char *)&buffer[0])[0] == '\n')
buffer.erase(buffer.begin(), buffer.begin() + 1);
unsigned int bufferSize = static_cast<unsigned int>(buffer.size());
const char *pCur = (char *)&buffer[0];
if (!p_pcOut->ParseElementInstanceListsBinary(streamBuffer, buffer, pCur, bufferSize, loader, p_bBE)) {
@ -530,7 +559,7 @@ bool PLY::DOM::ParseInstance(IOStreamBuffer<char> &streamBuffer, DOM *p_pcOut, P
return false;
}
//get next line after header
// get next line after header
streamBuffer.getNextLine(buffer);
if (!p_pcOut->ParseElementInstanceLists(streamBuffer, buffer, loader)) {
ASSIMP_LOG_VERBOSE_DEBUG("PLY::DOM::ParseInstance() failure");
@ -560,23 +589,24 @@ bool PLY::ElementInstanceList::ParseInstanceList(
}
} else {
const char *pCur = (const char *)&buffer[0];
const char *end = pCur + buffer.size();
// be sure to have enough storage
for (unsigned int i = 0; i < pcElement->NumOccur; ++i) {
if (p_pcOut)
PLY::ElementInstance::ParseInstance(pCur, pcElement, &p_pcOut->alInstances[i]);
PLY::ElementInstance::ParseInstance(pCur, end, pcElement, &p_pcOut->alInstances[i]);
else {
ElementInstance elt;
PLY::ElementInstance::ParseInstance(pCur, pcElement, &elt);
PLY::ElementInstance::ParseInstance(pCur, end, pcElement, &elt);
// Create vertex or face
if (pcElement->eSemantic == EEST_Vertex) {
//call loader instance from here
// call loader instance from here
loader->LoadVertex(pcElement, &elt, i);
} else if (pcElement->eSemantic == EEST_Face) {
//call loader instance from here
// call loader instance from here
loader->LoadFace(pcElement, &elt, i);
} else if (pcElement->eSemantic == EEST_TriStrip) {
//call loader instance from here
// call loader instance from here
loader->LoadFace(pcElement, &elt, i);
}
}
@ -613,13 +643,13 @@ bool PLY::ElementInstanceList::ParseInstanceListBinary(
// Create vertex or face
if (pcElement->eSemantic == EEST_Vertex) {
//call loader instance from here
// call loader instance from here
loader->LoadVertex(pcElement, &elt, i);
} else if (pcElement->eSemantic == EEST_Face) {
//call loader instance from here
// call loader instance from here
loader->LoadFace(pcElement, &elt, i);
} else if (pcElement->eSemantic == EEST_TriStrip) {
//call loader instance from here
// call loader instance from here
loader->LoadFace(pcElement, &elt, i);
}
}
@ -628,7 +658,7 @@ bool PLY::ElementInstanceList::ParseInstanceListBinary(
}
// ------------------------------------------------------------------------------------------------
bool PLY::ElementInstance::ParseInstance(const char *&pCur,
bool PLY::ElementInstance::ParseInstance(const char *&pCur, const char *end,
const PLY::Element *pcElement,
PLY::ElementInstance *p_pcOut) {
ai_assert(nullptr != pcElement);
@ -640,7 +670,7 @@ bool PLY::ElementInstance::ParseInstance(const char *&pCur,
std::vector<PLY::PropertyInstance>::iterator i = p_pcOut->alProperties.begin();
std::vector<PLY::Property>::const_iterator a = pcElement->alProperties.begin();
for (; i != p_pcOut->alProperties.end(); ++i, ++a) {
if (!(PLY::PropertyInstance::ParseInstance(pCur, &(*a), &(*i)))) {
if (!(PLY::PropertyInstance::ParseInstance(pCur, end, &(*a), &(*i)))) {
ASSIMP_LOG_WARN("Unable to parse property instance. "
"Skipping this element instance");
@ -680,13 +710,13 @@ bool PLY::ElementInstance::ParseInstanceBinary(
}
// ------------------------------------------------------------------------------------------------
bool PLY::PropertyInstance::ParseInstance(const char *&pCur,
const PLY::Property *prop, PLY::PropertyInstance *p_pcOut) {
bool PLY::PropertyInstance::ParseInstance(const char *&pCur, const char *end, const PLY::Property *prop,
PLY::PropertyInstance *p_pcOut) {
ai_assert(nullptr != prop);
ai_assert(nullptr != p_pcOut);
// skip spaces at the beginning
if (!SkipSpaces(&pCur)) {
if (!SkipSpaces(&pCur, end)) {
return false;
}
@ -701,7 +731,7 @@ bool PLY::PropertyInstance::ParseInstance(const char *&pCur,
// parse all list elements
p_pcOut->avList.resize(iNum);
for (unsigned int i = 0; i < iNum; ++i) {
if (!SkipSpaces(&pCur))
if (!SkipSpaces(&pCur, end))
return false;
PLY::PropertyInstance::ParseValue(pCur, prop->eType, &p_pcOut->avList[i]);
@ -713,7 +743,7 @@ bool PLY::PropertyInstance::ParseInstance(const char *&pCur,
PLY::PropertyInstance::ParseValue(pCur, prop->eType, &v);
p_pcOut->avList.push_back(v);
}
SkipSpacesAndLineEnd(&pCur);
SkipSpacesAndLineEnd(&pCur, end);
return true;
}
@ -776,7 +806,7 @@ bool PLY::PropertyInstance::ParseValue(const char *&pCur,
ai_assert(nullptr != pCur);
ai_assert(nullptr != out);
//calc element size
// calc element size
bool ret = true;
switch (eType) {
case EDT_UInt:
@ -826,7 +856,7 @@ bool PLY::PropertyInstance::ParseValueBinary(IOStreamBuffer<char> &streamBuffer,
bool p_bBE) {
ai_assert(nullptr != out);
//calc element size
// calc element size
unsigned int lsize = 0;
switch (eType) {
case EDT_Char:
@ -854,11 +884,11 @@ bool PLY::PropertyInstance::ParseValueBinary(IOStreamBuffer<char> &streamBuffer,
break;
}
//read the next file block if needed
// read the next file block if needed
if (bufferSize < lsize) {
std::vector<char> nbuffer;
if (streamBuffer.getNextBlock(nbuffer)) {
//concat buffer contents
// concat buffer contents
buffer = std::vector<char>(buffer.end() - bufferSize, buffer.end());
buffer.insert(buffer.end(), nbuffer.begin(), nbuffer.end());
nbuffer.clear();
@ -960,4 +990,6 @@ bool PLY::PropertyInstance::ParseValueBinary(IOStreamBuffer<char> &streamBuffer,
return ret;
}
} // namespace Assimp
#endif // !! ASSIMP_BUILD_NO_PLY_IMPORTER