- Fix model parsing

pull/3882/head
kkulling 2021-05-05 13:10:52 +02:00
parent cbce6d3dad
commit f15dcfa981
2 changed files with 26 additions and 26 deletions

View File

@ -163,7 +163,7 @@ public:
} }
XmlNode resNode = node.child(XmlTag::resources); XmlNode resNode = node.child(XmlTag::resources);
for (auto &currentNode : resNode.children()) { for (auto &currentNode : resNode.children()) {
const std::string &currentNodeName = currentNode.name(); const std::string currentNodeName = currentNode.name();
if (currentNodeName == XmlTag::object) { if (currentNodeName == XmlTag::object) {
ReadObject(currentNode); ReadObject(currentNode);
} else if (currentNodeName == XmlTag::basematerials) { } else if (currentNodeName == XmlTag::basematerials) {
@ -173,8 +173,9 @@ public:
} }
} }
for (auto &currentNode : resNode.children()) { XmlNode buildNode = node.child(XmlTag::build);
const std::string &currentNodeName = currentNode.name(); for (auto &currentNode : buildNode.children()) {
const std::string currentNodeName = currentNode.name();
if (currentNodeName == XmlTag::item) { if (currentNodeName == XmlTag::item) {
int objectId = -1; int objectId = -1;
std::string transformationMatrixStr; std::string transformationMatrixStr;
@ -196,7 +197,7 @@ public:
// import the metadata // import the metadata
if (!mMetaData.empty()) { if (!mMetaData.empty()) {
const size_t numMeta(mMetaData.size()); const size_t numMeta = mMetaData.size();
scene->mMetaData = aiMetadata::Alloc(static_cast<unsigned int>(numMeta)); scene->mMetaData = aiMetadata::Alloc(static_cast<unsigned int>(numMeta));
for (size_t i = 0; i < numMeta; ++i) { for (size_t i = 0; i < numMeta; ++i) {
aiString val(mMetaData[i].value); aiString val(mMetaData[i].value);
@ -211,6 +212,7 @@ public:
for (auto it = mResourcesDictionnary.begin(); it != mResourcesDictionnary.end(); ++it) { for (auto it = mResourcesDictionnary.begin(); it != mResourcesDictionnary.end(); ++it) {
if (it->second->getType() == ResourceType::RT_Object) { if (it->second->getType() == ResourceType::RT_Object) {
Object *obj = static_cast<Object *>(it->second); Object *obj = static_cast<Object *>(it->second);
ai_assert(nullptr != obj);
for (unsigned int i = 0; i < obj->mMeshes.size(); ++i) { for (unsigned int i = 0; i < obj->mMeshes.size(); ++i) {
scene->mMeshes[obj->mMeshIndex[i]] = obj->mMeshes[i]; scene->mMeshes[obj->mMeshIndex[i]] = obj->mMeshes[i];
} }
@ -352,7 +354,8 @@ private:
mMeshCount++; mMeshCount++;
} else if (currentName == D3MF::XmlTag::components) { } else if (currentName == D3MF::XmlTag::components) {
for (XmlNode &currentSubNode : currentNode.children()) { for (XmlNode &currentSubNode : currentNode.children()) {
if (currentSubNode.name() == D3MF::XmlTag::component) { const std::string subNodeName = currentSubNode.name();
if (subNodeName == D3MF::XmlTag::component) {
int objectId = -1; int objectId = -1;
std::string componentTransformStr; std::string componentTransformStr;
aiMatrix4x4 componentTransform; aiMatrix4x4 componentTransform;
@ -360,12 +363,13 @@ private:
componentTransform = parseTransformMatrix(componentTransformStr); componentTransform = parseTransformMatrix(componentTransformStr);
} }
if (getNodeAttribute(currentSubNode, D3MF::XmlTag::objectid, objectId)) if (getNodeAttribute(currentSubNode, D3MF::XmlTag::objectid, objectId)) {
obj->mComponents.push_back({ objectId, componentTransform }); obj->mComponents.push_back({ objectId, componentTransform });
} }
} }
} }
} }
}
mResourcesDictionnary.insert(std::make_pair(id, obj)); mResourcesDictionnary.insert(std::make_pair(id, obj));
} }
@ -374,7 +378,7 @@ private:
aiMesh *mesh = new aiMesh(); aiMesh *mesh = new aiMesh();
for (XmlNode &currentNode : node.children()) { for (XmlNode &currentNode : node.children()) {
const std::string &currentName = currentNode.name(); const std::string currentName = currentNode.name();
if (currentName == XmlTag::vertices) { if (currentName == XmlTag::vertices) {
ImportVertices(currentNode, mesh); ImportVertices(currentNode, mesh);
} else if (currentName == XmlTag::triangles) { } else if (currentName == XmlTag::triangles) {
@ -402,8 +406,8 @@ private:
void ImportVertices(XmlNode &node, aiMesh *mesh) { void ImportVertices(XmlNode &node, aiMesh *mesh) {
std::vector<aiVector3D> vertices; std::vector<aiVector3D> vertices;
for (XmlNode &currentNode : node.children()) { for (XmlNode &currentNode : node.children()) {
const std::string &currentName = currentNode.name(); const std::string currentName = currentNode.name();
if (currentName == D3MF::XmlTag::vertex) { if (currentName == XmlTag::vertex) {
vertices.push_back(ReadVertex(currentNode)); vertices.push_back(ReadVertex(currentNode));
} }
} }
@ -415,22 +419,22 @@ private:
aiVector3D ReadVertex(XmlNode &node) { aiVector3D ReadVertex(XmlNode &node) {
aiVector3D vertex; aiVector3D vertex;
vertex.x = ai_strtof(node.attribute(D3MF::XmlTag::x).as_string(), nullptr); vertex.x = ai_strtof(node.attribute(XmlTag::x).as_string(), nullptr);
vertex.y = ai_strtof(node.attribute(D3MF::XmlTag::y).as_string(), nullptr); vertex.y = ai_strtof(node.attribute(XmlTag::y).as_string(), nullptr);
vertex.z = ai_strtof(node.attribute(D3MF::XmlTag::z).as_string(), nullptr); vertex.z = ai_strtof(node.attribute(XmlTag::z).as_string(), nullptr);
return vertex; return vertex;
} }
void ImportTriangles(XmlNode &node, aiMesh *mesh) { void ImportTriangles(XmlNode &node, aiMesh *mesh) {
std::vector<aiFace> faces; std::vector<aiFace> faces;
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) { for (XmlNode &currentNode : node.children()) {
const std::string &currentName = currentNode.name(); const std::string currentName = currentNode.name();
if (currentName == D3MF::XmlTag::triangle) { if (currentName == XmlTag::triangle) {
aiFace face = ReadTriangle(currentNode); aiFace face = ReadTriangle(currentNode);
faces.push_back(face); faces.push_back(face);
int pid = 0, p1; int pid = 0, p1 = 0;
bool hasPid = getNodeAttribute(currentNode, D3MF::XmlTag::pid, pid); bool hasPid = getNodeAttribute(currentNode, D3MF::XmlTag::pid, pid);
bool hasP1 = getNodeAttribute(currentNode, D3MF::XmlTag::p1, p1); bool hasP1 = getNodeAttribute(currentNode, D3MF::XmlTag::p1, p1);
@ -472,10 +476,11 @@ private:
BaseMaterials *baseMaterials = new BaseMaterials(id); BaseMaterials *baseMaterials = new BaseMaterials(id);
for (XmlNode &currentNode : node.children()) { for (XmlNode &currentNode : node.children()) {
if (currentNode.name() == XmlTag::basematerials_base) { const std::string currentName = currentNode.name();
if (currentName == XmlTag::basematerials_base) {
baseMaterials->mMaterialIndex.push_back(mMaterialCount); baseMaterials->mMaterialIndex.push_back(mMaterialCount);
baseMaterials->mMaterials.push_back(readMaterialDef(currentNode, id)); baseMaterials->mMaterials.push_back(readMaterialDef(currentNode, id));
mMaterialCount++; ++mMaterialCount;
} }
} }
@ -489,11 +494,7 @@ private:
} }
//format of the color string: #RRGGBBAA or #RRGGBB (3MF Core chapter 5.1.1) //format of the color string: #RRGGBBAA or #RRGGBB (3MF Core chapter 5.1.1)
#ifdef _WIN32 const size_t len = strlen(color);
const size_t len = strnlen_s(color, 9);
#else
const size_t len = strnlen(color, 9);
#endif
if (9 != len && 7 != len) { if (9 != len && 7 != len) {
return false; return false;
} }
@ -603,7 +604,7 @@ bool D3MFImporter::CanRead(const std::string &filename, IOSystem *pIOHandler, bo
if (!ZipArchiveIOSystem::isZipArchive(pIOHandler, filename)) { if (!ZipArchiveIOSystem::isZipArchive(pIOHandler, filename)) {
return false; return false;
} }
D3MF::D3MFOpcPackage opcPackage(pIOHandler, filename); D3MFOpcPackage opcPackage(pIOHandler, filename);
return opcPackage.validate(); return opcPackage.validate();
} }

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2021, assimp team Copyright (c) 2006-2021, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -249,4 +248,4 @@ AI_FORCE_INLINE std::string ai_str_toupper(const std::string &in) {
return out; return out;
} }
#endif #endif // INCLUDED_AI_STRINGUTILS_H