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

@ -52,22 +52,12 @@ class X3DExporter {
struct SAttribute {
const std::string Name;
const std::string Value;
SAttribute() :
Name(),
Value() {
// empty
}
SAttribute() = default;
SAttribute(const std::string &name, const std::string &value) :
Name(name),
Value(value) {
// empty
}
SAttribute(SAttribute &&rhs) AI_NO_EXCEPT :
Name(rhs.Name),
Value(rhs.Value) {
// empty
}
};
/***********************************************/

View file

@ -188,12 +188,57 @@ mg_m_err:
pFaces.clear();
}
void X3DGeoHelper::coordIdx_str2lines_arr(const std::vector<int32_t> &pCoordIdx, std::vector<aiFace> &pFaces) {
std::vector<int32_t> f_data(pCoordIdx);
if (f_data.back() != (-1)) {
f_data.push_back(-1);
}
// reserve average size.
pFaces.reserve(f_data.size() / 2);
for (std::vector<int32_t>::const_iterator startIt = f_data.cbegin(), endIt = f_data.cbegin(); endIt != f_data.cend(); ++endIt) {
// check for end of current polyline
if (*endIt != -1)
continue;
// found end of polyline, check if this is a valid polyline
std::size_t numIndices = std::distance(startIt, endIt);
if (numIndices <= 1)
goto mg_m_err;
// create line faces out of polyline indices
for (int32_t idx0 = *startIt++; startIt != endIt; ++startIt) {
int32_t idx1 = *startIt;
aiFace tface;
tface.mNumIndices = 2;
tface.mIndices = new unsigned int[2];
tface.mIndices[0] = idx0;
tface.mIndices[1] = idx1;
pFaces.push_back(tface);
idx0 = idx1;
}
++startIt;
}
return;
mg_m_err:
for (size_t i = 0, i_e = pFaces.size(); i < i_e; i++)
delete[] pFaces[i].mIndices;
pFaces.clear();
}
void X3DGeoHelper::add_color(aiMesh &pMesh, const std::list<aiColor3D> &pColors, const bool pColorPerVertex) {
std::list<aiColor4D> tcol;
// create RGBA array from RGB.
for (std::list<aiColor3D>::const_iterator it = pColors.begin(); it != pColors.end(); ++it)
tcol.emplace_back((*it).r, (*it).g, (*it).b, 1);
tcol.emplace_back((*it).r, (*it).g, (*it).b, static_cast<ai_real>(1));
// call existing function for adding RGBA colors
add_color(pMesh, tcol, pColorPerVertex);
@ -238,7 +283,7 @@ void X3DGeoHelper::add_color(aiMesh &pMesh, const std::vector<int32_t> &pCoordId
// create RGBA array from RGB.
for (std::list<aiColor3D>::const_iterator it = pColors.begin(); it != pColors.end(); ++it) {
tcol.emplace_back((*it).r, (*it).g, (*it).b, 1);
tcol.emplace_back((*it).r, (*it).g, (*it).b, static_cast<ai_real>(1));
}
// call existing function for adding RGBA colors
@ -440,7 +485,7 @@ void X3DGeoHelper::add_tex_coord(aiMesh &pMesh, const std::vector<int32_t> &pCoo
// copy list to array because we are need indexed access to normals.
texcoord_arr_copy.reserve(pTexCoords.size());
for (std::list<aiVector2D>::const_iterator it = pTexCoords.begin(); it != pTexCoords.end(); ++it) {
texcoord_arr_copy.emplace_back((*it).x, (*it).y, 0);
texcoord_arr_copy.emplace_back((*it).x, (*it).y, static_cast<ai_real>(0));
}
if (pTexCoordIdx.size() > 0) {
@ -480,7 +525,7 @@ void X3DGeoHelper::add_tex_coord(aiMesh &pMesh, const std::list<aiVector2D> &pTe
// copy list to array because we are need convert aiVector2D to aiVector3D and also get indexed access as a bonus.
tc_arr_copy.reserve(pTexCoords.size());
for (std::list<aiVector2D>::const_iterator it = pTexCoords.begin(); it != pTexCoords.end(); ++it) {
tc_arr_copy.emplace_back((*it).x, (*it).y, 0);
tc_arr_copy.emplace_back((*it).x, (*it).y, static_cast<ai_real>(0));
}
// copy texture coordinates to mesh
@ -528,4 +573,40 @@ aiMesh *X3DGeoHelper::make_mesh(const std::vector<int32_t> &pCoordIdx, const std
return tmesh;
}
aiMesh *X3DGeoHelper::make_line_mesh(const std::vector<int32_t> &pCoordIdx, const std::list<aiVector3D> &pVertices) {
std::vector<aiFace> faces;
// create faces array from input string with vertices indices.
X3DGeoHelper::coordIdx_str2lines_arr(pCoordIdx, faces);
if (!faces.size()) {
throw DeadlyImportError("Failed to create mesh, faces list is empty.");
}
//
// Create new mesh and copy geometry data.
//
aiMesh *tmesh = new aiMesh;
size_t ts = faces.size();
// faces
tmesh->mFaces = new aiFace[ts];
tmesh->mNumFaces = static_cast<unsigned int>(ts);
for (size_t i = 0; i < ts; i++)
tmesh->mFaces[i] = faces[i];
// vertices
std::list<aiVector3D>::const_iterator vit = pVertices.begin();
ts = pVertices.size();
tmesh->mVertices = new aiVector3D[ts];
tmesh->mNumVertices = static_cast<unsigned int>(ts);
for (size_t i = 0; i < ts; i++) {
tmesh->mVertices[i] = *vit++;
}
// set primitive type and return result.
tmesh->mPrimitiveTypes = aiPrimitiveType_LINE;
return tmesh;
}
} // namespace Assimp

View file

@ -21,6 +21,7 @@ public:
static void polylineIdx_to_lineIdx(const std::list<int32_t> &pPolylineCoordIdx, std::list<int32_t> &pLineCoordIdx);
static void rect_parallel_epiped(const aiVector3D &pSize, std::list<aiVector3D> &pVertices);
static void coordIdx_str2faces_arr(const std::vector<int32_t> &pCoordIdx, std::vector<aiFace> &pFaces, unsigned int &pPrimitiveTypes);
static void coordIdx_str2lines_arr(const std::vector<int32_t> &pCoordIdx, std::vector<aiFace> &pFaces);
static void add_color(aiMesh &pMesh, const std::list<aiColor3D> &pColors, const bool pColorPerVertex);
static void add_color(aiMesh &pMesh, const std::list<aiColor4D> &pColors, const bool pColorPerVertex);
static void add_color(aiMesh &pMesh, const std::vector<int32_t> &pCoordIdx, const std::vector<int32_t> &pColorIdx,
@ -34,6 +35,7 @@ public:
const std::list<aiVector2D> &pTexCoords);
static void add_tex_coord(aiMesh &pMesh, const std::list<aiVector2D> &pTexCoords);
static aiMesh *make_mesh(const std::vector<int32_t> &pCoordIdx, const std::list<aiVector3D> &pVertices);
static aiMesh *make_line_mesh(const std::vector<int32_t> &pCoordIdx, const std::list<aiVector3D> &pVertices);
};
} // namespace Assimp

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -207,7 +207,7 @@ void X3DImporter::ParseFile(const std::string &file, IOSystem *pIOHandler) {
static const std::string mode = "rb";
std::unique_ptr<IOStream> fileStream(pIOHandler->Open(file, mode));
if (!fileStream.get()) {
if (!fileStream) {
throw DeadlyImportError("Failed to open file " + file + ".");
}
@ -471,7 +471,7 @@ void X3DImporter::ParseHelper_Node_Enter(X3DNodeElementBase *pNode) {
mNodeElementCur->Children.push_back(pNode); // add new element to current element child list.
mNodeElementCur = pNode; // switch current element to new one.
}
}
void X3DImporter::ParseHelper_Node_Exit() {
// check if we can walk up.

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -55,6 +55,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string>
namespace Assimp {
AI_WONT_RETURN inline void Throw_ArgOutOfRange(const std::string &argument) AI_WONT_RETURN_SUFFIX;
AI_WONT_RETURN inline void Throw_CloseNotFound(const std::string &node) AI_WONT_RETURN_SUFFIX;
AI_WONT_RETURN inline void Throw_ConvertFail_Str2ArrF(const std::string &nodeName, const std::string &pAttrValue) AI_WONT_RETURN_SUFFIX;
AI_WONT_RETURN inline void Throw_ConvertFail_Str2ArrD(const std::string &nodeName, const std::string &pAttrValue) AI_WONT_RETURN_SUFFIX;
AI_WONT_RETURN inline void Throw_ConvertFail_Str2ArrB(const std::string &nodeName, const std::string &pAttrValue) AI_WONT_RETURN_SUFFIX;
AI_WONT_RETURN inline void Throw_ConvertFail_Str2ArrI(const std::string &nodeName, const std::string &pAttrValue) AI_WONT_RETURN_SUFFIX;
AI_WONT_RETURN inline void Throw_DEF_And_USE(const std::string &nodeName) AI_WONT_RETURN_SUFFIX;
AI_WONT_RETURN inline void Throw_IncorrectAttr(const std::string &nodeName, const std::string &pAttrName) AI_WONT_RETURN_SUFFIX;
AI_WONT_RETURN inline void Throw_IncorrectAttrValue(const std::string &nodeName, const std::string &pAttrName) AI_WONT_RETURN_SUFFIX;
AI_WONT_RETURN inline void Throw_MoreThanOnceDefined(const std::string &nodeName, const std::string &pNodeType, const std::string &pDescription) AI_WONT_RETURN_SUFFIX;
AI_WONT_RETURN inline void Throw_TagCountIncorrect(const std::string &pNode) AI_WONT_RETURN_SUFFIX;
AI_WONT_RETURN inline void Throw_USE_NotFound(const std::string &nodeName, const std::string &pAttrValue) AI_WONT_RETURN_SUFFIX;
inline void Throw_ArgOutOfRange(const std::string &argument) {
throw DeadlyImportError("Argument value is out of range for: \"" + argument + "\".");

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -151,7 +151,7 @@ void X3DImporter::readArcClose2D(XmlNode &node) {
std::list<aiVector3D> &vlist = ((X3DNodeElementGeometry2D *)ne)->Vertices; // just short alias.
if ((closureType == "PIE") || (closureType == "\"PIE\""))
vlist.emplace_back(0, 0, 0); // center point - first radial line
vlist.emplace_back(static_cast<ai_real>(0), static_cast<ai_real>(0), static_cast<ai_real>(0)); // center point - first radial line
else if ((closureType != "CHORD") && (closureType != "\"CHORD\""))
Throw_IncorrectAttrValue("ArcClose2D", "closureType");
@ -263,7 +263,7 @@ void X3DImporter::readDisk2D(XmlNode &node) {
//
if (tlist_i.size() < 2) {
// tlist_i and tlist_o has equal size.
throw DeadlyImportError("Disk2D. Not enough points for creating quad list.");
throw DeadlyImportError("Disk2D. Not enough points for creating quad list.");
}
// add all quads except last
@ -323,7 +323,7 @@ void X3DImporter::readPolyline2D(XmlNode &node) {
// convert vec2 to vec3
for (std::list<aiVector2D>::iterator it2 = lineSegments.begin(); it2 != lineSegments.end(); ++it2)
tlist.emplace_back(it2->x, it2->y, 0);
tlist.emplace_back(it2->x, it2->y, static_cast<ai_real>(0));
// convert point set to line set
X3DGeoHelper::extend_point_to_line(tlist, ((X3DNodeElementGeometry2D *)ne)->Vertices);
@ -361,7 +361,7 @@ void X3DImporter::readPolypoint2D(XmlNode &node) {
// convert vec2 to vec3
for (std::list<aiVector2D>::iterator it2 = point.begin(); it2 != point.end(); ++it2) {
((X3DNodeElementGeometry2D *)ne)->Vertices.emplace_back(it2->x, it2->y, 0);
((X3DNodeElementGeometry2D *)ne)->Vertices.emplace_back(it2->x, it2->y, static_cast<ai_real>(0));
}
((X3DNodeElementGeometry2D *)ne)->NumIndices = 1;
@ -405,10 +405,10 @@ void X3DImporter::readRectangle2D(XmlNode &node) {
float y2 = size.y / 2.0f;
std::list<aiVector3D> &vlist = ((X3DNodeElementGeometry2D *)ne)->Vertices; // just short alias.
vlist.emplace_back(x2, y1, 0); // 1st point
vlist.emplace_back(x2, y2, 0); // 2nd point
vlist.emplace_back(x1, y2, 0); // 3rd point
vlist.emplace_back(x1, y1, 0); // 4th point
vlist.emplace_back(x2, y1, static_cast<ai_real>(0)); // 1st point
vlist.emplace_back(x2, y2, static_cast<ai_real>(0)); // 2nd point
vlist.emplace_back(x1, y2, static_cast<ai_real>(0)); // 3rd point
vlist.emplace_back(x1, y1, static_cast<ai_real>(0)); // 4th point
((X3DNodeElementGeometry2D *)ne)->Solid = solid;
((X3DNodeElementGeometry2D *)ne)->NumIndices = 4;
// check for X3DMetadataObject childs.
@ -449,7 +449,7 @@ void X3DImporter::readTriangleSet2D(XmlNode &node) {
// convert vec2 to vec3
for (std::list<aiVector2D>::iterator it2 = vertices.begin(); it2 != vertices.end(); ++it2) {
((X3DNodeElementGeometry2D *)ne)->Vertices.emplace_back(it2->x, it2->y, 0);
((X3DNodeElementGeometry2D *)ne)->Vertices.emplace_back(it2->x, it2->y, static_cast<ai_real>(0));
}
((X3DNodeElementGeometry2D *)ne)->Solid = solid;

View file

@ -108,9 +108,7 @@ struct X3DNodeElementBase {
std::list<X3DNodeElementBase *> Children;
X3DElemType Type;
virtual ~X3DNodeElementBase() {
// empty
}
virtual ~X3DNodeElementBase() = default;
protected:
X3DNodeElementBase(X3DElemType type, X3DNodeElementBase *pParent) :
@ -367,9 +365,7 @@ struct X3DNodeElementMeta : X3DNodeElementBase {
std::string Name; ///< Name of metadata object.
std::string Reference;
virtual ~X3DNodeElementMeta() {
// empty
}
virtual ~X3DNodeElementMeta() = default;
protected:
X3DNodeElementMeta(X3DElemType type, X3DNodeElementBase *parent) :

View file

@ -320,7 +320,7 @@ void X3DImporter::Postprocess_BuildMesh(const X3DNodeElementBase &pNodeElement,
// at first search for <Coordinate> node and create mesh.
for (std::list<X3DNodeElementBase *>::iterator ch_it = tnemesh.Children.begin(); ch_it != tnemesh.Children.end(); ++ch_it) {
if ((*ch_it)->Type == X3DElemType::ENET_Coordinate) {
*pMesh = X3DGeoHelper::make_mesh(tnemesh.CoordIndex, ((X3DNodeElementCoordinate *)*ch_it)->Value);
*pMesh = X3DGeoHelper::make_line_mesh(tnemesh.CoordIndex, ((X3DNodeElementCoordinate *)*ch_it)->Value);
}
}

View file

@ -12,7 +12,6 @@ bool X3DXmlHelper::getColor3DAttribute(XmlNode &node, const char *attributeName,
tokenize<std::string>(val, values, " ");
if (values.size() != 3) {
Throw_ConvertFail_Str2ArrF(node.name(), attributeName);
return false;
}
auto it = values.begin();
color.r = stof(*it++);
@ -30,7 +29,6 @@ bool X3DXmlHelper::getVector2DAttribute(XmlNode &node, const char *attributeName
tokenize<std::string>(val, values, " ");
if (values.size() != 2) {
Throw_ConvertFail_Str2ArrF(node.name(), attributeName);
return false;
}
auto it = values.begin();
color.x = stof(*it++);
@ -47,7 +45,6 @@ bool X3DXmlHelper::getVector3DAttribute(XmlNode &node, const char *attributeName
tokenize<std::string>(val, values, " ");
if (values.size() != 3) {
Throw_ConvertFail_Str2ArrF(node.name(), attributeName);
return false;
}
auto it = values.begin();
color.x = stof(*it++);