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
All rights reserved.
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 {
class XmlNode;
/// \class AMFImporter
/// 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;
/// Parse <AMF> node of the file.
void ParseNode_Root();
void ParseNode_Root(XmlNode *root);
/// Parse <constellation> node of the file.
void ParseNode_Constellation();

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team
All rights reserved.
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
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
// the desired texture mapping mode for all of them and ignore
// 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,
// 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.
for (unsigned int i = 0; i < localScene->mNumMeshes; ++i) {
// 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
// (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
// 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)) {
int idx = 1;
@ -726,8 +728,8 @@ void IRRImporter::GenerateGraph(Node *root, aiNode *rootOut, aiScene *scene,
// Generate the sphere model. Our input parameter to
// the sphere generation algorithm is the number of
// subdivisions of each triangle - but here we have
// the number of poylgons on a specific axis. Just
// use some hardcoded limits to approximate this ...
// the number of polygons on a specific axis. Just
// use some hard-coded limits to approximate this ...
unsigned int mul = root->spherePolyCountX * root->spherePolyCountY;
if (mul < 100)
mul = 2;
@ -767,13 +769,13 @@ void IRRImporter::GenerateGraph(Node *root, aiNode *rootOut, aiScene *scene,
} break;
case Node::SKYBOX: {
// A skybox is defined by six materials
// A sky-box is defined by six materials
if (root->materials.size() < 6) {
ASSIMP_LOG_ERROR("IRR: There should be six materials for a skybox");
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);
for (unsigned int i = 0; i < 6; ++i)
materials.insert(materials.end(), root->materials[i].first);
@ -880,7 +882,7 @@ void IRRImporter::InternReadFile(const std::string &pFile,
// Current node parent
Node *curParent = root;
// Scenegraph node we're currently working on
// Scene-graph node we're currently working on
Node *curNode = nullptr;
// List of output cameras
@ -1019,7 +1021,7 @@ void IRRImporter::InternReadFile(const std::string &pFile,
/* Parse all elements in the attributes block
* and process them.
*/
// while (reader->read()) {
// while (reader->read()) {
for (pugi::xml_node attrib : child.children()) {
if (attrib.type() == pugi::node_element) {
//if (reader->getNodeType() == EXN_ELEMENT) {
@ -1373,8 +1375,8 @@ void IRRImporter::InternReadFile(const std::string &pFile,
pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
}
// Finished ... everything destructs automatically and all
// temporary scenes have already been deleted by MergeScenes()
// Finished ... everything destructs automatically and all
// temporary scenes have already been deleted by MergeScenes()
delete root;
}

View File

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