xml-migration: introduce xmlnode.

pull/2966/head
Kim Kulling 2020-01-27 22:11:27 +01:00
parent 6a471b4390
commit 8ef106e185
3 changed files with 146 additions and 124 deletions

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2020, 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,
@ -65,6 +63,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Assimp { namespace Assimp {
class XmlNode;
/// \class AMFImporter /// \class AMFImporter
/// Class that holding scene graph which include: geometry, metadata, materials etc. /// Class that holding scene graph which include: geometry, metadata, materials etc.
/// ///
@ -345,7 +345,7 @@ private:
void ParseHelper_Decode_Base64(const std::string& pInputBase64, std::vector<uint8_t>& pOutputData) const; void ParseHelper_Decode_Base64(const std::string& pInputBase64, std::vector<uint8_t>& pOutputData) const;
/// Parse <AMF> node of the file. /// Parse <AMF> node of the file.
void ParseNode_Root(); void ParseNode_Root(XmlNode *root);
/// Parse <constellation> node of the file. /// Parse <constellation> node of the file.
void ParseNode_Constellation(); void ParseNode_Constellation();

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2020, 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,
@ -564,6 +562,10 @@ void IRRImporter::ComputeAnimations(Node *root, aiNode *real, std::vector<aiNode
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// This function is maybe more generic than we'd need it here // This function is maybe more generic than we'd need it here
void SetupMapping(aiMaterial *mat, aiTextureMapping mode, const aiVector3D &axis = aiVector3D(0.f, 0.f, -1.f)) { void SetupMapping(aiMaterial *mat, aiTextureMapping mode, const aiVector3D &axis = aiVector3D(0.f, 0.f, -1.f)) {
if (nullptr == mat) {
return;
}
// Check whether there are texture properties defined - setup // Check whether there are texture properties defined - setup
// the desired texture mapping mode for all of them and ignore // the desired texture mapping mode for all of them and ignore
// all UV settings we might encounter. WE HAVE NO UVS! // all UV settings we might encounter. WE HAVE NO UVS!
@ -668,7 +670,7 @@ void IRRImporter::GenerateGraph(Node *root, aiNode *rootOut, aiScene *scene,
} }
// NOTE: Each mesh should have exactly one material assigned, // NOTE: Each mesh should have exactly one material assigned,
// but we do it in a separate loop if this behaviour changes // but we do it in a separate loop if this behavior changes
// in future. // in future.
for (unsigned int i = 0; i < localScene->mNumMeshes; ++i) { for (unsigned int i = 0; i < localScene->mNumMeshes; ++i) {
// Process material flags // Process material flags
@ -701,9 +703,9 @@ void IRRImporter::GenerateGraph(Node *root, aiNode *rootOut, aiScene *scene,
} }
// If we have a second texture coordinate set and a second texture // If we have a second texture coordinate set and a second texture
// (either lightmap, normalmap, 2layered material) we need to // (either light-map, normal-map, 2layered material) we need to
// setup the correct UV index for it. The texture can either // setup the correct UV index for it. The texture can either
// be diffuse (lightmap & 2layer) or a normal map (normal & parallax) // be diffuse (light-map & 2layer) or a normal map (normal & parallax)
if (mesh->HasTextureCoords(1)) { if (mesh->HasTextureCoords(1)) {
int idx = 1; int idx = 1;
@ -726,8 +728,8 @@ void IRRImporter::GenerateGraph(Node *root, aiNode *rootOut, aiScene *scene,
// Generate the sphere model. Our input parameter to // Generate the sphere model. Our input parameter to
// the sphere generation algorithm is the number of // the sphere generation algorithm is the number of
// subdivisions of each triangle - but here we have // subdivisions of each triangle - but here we have
// the number of poylgons on a specific axis. Just // the number of polygons on a specific axis. Just
// use some hardcoded limits to approximate this ... // use some hard-coded limits to approximate this ...
unsigned int mul = root->spherePolyCountX * root->spherePolyCountY; unsigned int mul = root->spherePolyCountX * root->spherePolyCountY;
if (mul < 100) if (mul < 100)
mul = 2; mul = 2;
@ -767,13 +769,13 @@ void IRRImporter::GenerateGraph(Node *root, aiNode *rootOut, aiScene *scene,
} break; } break;
case Node::SKYBOX: { case Node::SKYBOX: {
// A skybox is defined by six materials // A sky-box is defined by six materials
if (root->materials.size() < 6) { if (root->materials.size() < 6) {
ASSIMP_LOG_ERROR("IRR: There should be six materials for a skybox"); ASSIMP_LOG_ERROR("IRR: There should be six materials for a skybox");
break; break;
} }
// copy those materials and generate 6 meshes for our new skybox // copy those materials and generate 6 meshes for our new sky-box
materials.reserve(materials.size() + 6); materials.reserve(materials.size() + 6);
for (unsigned int i = 0; i < 6; ++i) for (unsigned int i = 0; i < 6; ++i)
materials.insert(materials.end(), root->materials[i].first); materials.insert(materials.end(), root->materials[i].first);
@ -880,7 +882,7 @@ void IRRImporter::InternReadFile(const std::string &pFile,
// Current node parent // Current node parent
Node *curParent = root; Node *curParent = root;
// Scenegraph node we're currently working on // Scene-graph node we're currently working on
Node *curNode = nullptr; Node *curNode = nullptr;
// List of output cameras // List of output cameras
@ -1019,7 +1021,7 @@ void IRRImporter::InternReadFile(const std::string &pFile,
/* Parse all elements in the attributes block /* Parse all elements in the attributes block
* and process them. * and process them.
*/ */
// while (reader->read()) { // while (reader->read()) {
for (pugi::xml_node attrib : child.children()) { for (pugi::xml_node attrib : child.children()) {
if (attrib.type() == pugi::node_element) { if (attrib.type() == pugi::node_element) {
//if (reader->getNodeType() == EXN_ELEMENT) { //if (reader->getNodeType() == EXN_ELEMENT) {
@ -1373,8 +1375,8 @@ void IRRImporter::InternReadFile(const std::string &pFile,
pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE; pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
} }
// Finished ... everything destructs automatically and all // Finished ... everything destructs automatically and all
// temporary scenes have already been deleted by MergeScenes() // temporary scenes have already been deleted by MergeScenes()
delete root; delete root;
} }

View File

@ -141,6 +141,25 @@ private:
}; // ! class CIrrXML_IOStreamReader }; // ! class CIrrXML_IOStreamReader
*/ */
class XmlNode {
public:
XmlNode()
: mNode(nullptr){
// empty
}
XmlNode(pugi::xml_node *node)
: mNode(node) {
// empty
}
pugi::xml_node *getNode() const {
return mNode;
}
private:
pugi::xml_node *mNode;
};
class XmlParser { class XmlParser {
public: public:
XmlParser() : XmlParser() :
@ -158,7 +177,7 @@ public:
mDoc = nullptr; mDoc = nullptr;
} }
pugi::xml_node *parse(IOStream *stream) { XmlNode *parse(IOStream *stream) {
if (nullptr == stream) { if (nullptr == stream) {
return nullptr; return nullptr;
} }
@ -168,7 +187,8 @@ public:
mDoc = new pugi::xml_document(); mDoc = new pugi::xml_document();
pugi::xml_parse_result result = mDoc->load_string(&mData[0]); pugi::xml_parse_result result = mDoc->load_string(&mData[0]);
if (result.status == pugi::status_ok) { if (result.status == pugi::status_ok) {
mRoot = &mDoc->root(); pugi::xml_node *root = &mDoc->root();
mRoot = new XmlNode(root);
} }
return mRoot; return mRoot;
@ -180,7 +200,7 @@ public:
private: private:
pugi::xml_document *mDoc; pugi::xml_document *mDoc;
pugi::xml_node *mRoot; XmlNode *mRoot;
std::vector<char> mData; std::vector<char> mData;
}; };