XMl-Migration: Migration of IrrMesh.
parent
00ad892a49
commit
c1fcee9c5a
|
@ -92,6 +92,7 @@ void AMFImporter::Clear() {
|
|||
AMFImporter::~AMFImporter() {
|
||||
if (mReader != nullptr) {
|
||||
delete mReader;
|
||||
mReader = nullptr;
|
||||
}
|
||||
|
||||
// Clear() is accounting if data already is deleted. So, just check again if all data is deleted.
|
||||
|
@ -157,11 +158,11 @@ void AMFImporter::Throw_IncorrectAttr(const std::string &nodeName, const std::st
|
|||
}
|
||||
|
||||
void AMFImporter::Throw_IncorrectAttrValue(const std::string &nodeName, const std::string &pAttrName) {
|
||||
throw DeadlyImportError("Attribute \"" + pAttrName + "\" in node <" + std::string(mReader->getNodeName()) + "> has incorrect value.");
|
||||
throw DeadlyImportError("Attribute \"" + pAttrName + "\" in node <" + nodeName + "> has incorrect value.");
|
||||
}
|
||||
|
||||
void AMFImporter::Throw_MoreThanOnceDefined(const std::string &pNodeType, const std::string &pDescription) {
|
||||
throw DeadlyImportError("\"" + pNodeType + "\" node can be used only once in " + mReader->getNodeName() + ". Description: " + pDescription);
|
||||
void AMFImporter::Throw_MoreThanOnceDefined(const std::string &nodeType, const std::string &nodeName, const std::string &pDescription) {
|
||||
throw DeadlyImportError("\"" + nodeType + "\" node can be used only once in " + nodeName + ". Description: " + pDescription);
|
||||
}
|
||||
|
||||
void AMFImporter::Throw_ID_NotFound(const std::string &pID) const {
|
||||
|
@ -172,11 +173,14 @@ void AMFImporter::Throw_ID_NotFound(const std::string &pID) const {
|
|||
/************************************************************* Functions: XML set ************************************************************/
|
||||
/*********************************************************************************************************************************************/
|
||||
|
||||
void AMFImporter::XML_CheckNode_MustHaveChildren() {
|
||||
if (mReader->isEmptyElement()) throw DeadlyImportError(std::string("Node <") + mReader->getNodeName() + "> must have children.");
|
||||
void AMFImporter::XML_CheckNode_MustHaveChildren( XmlNode *node ) {
|
||||
//if (mReader->isEmptyElement()) throw DeadlyImportError(std::string("Node <") + mReader->getNodeName() + "> must have children.");
|
||||
if (node->getNode()->children().begin() == node->getNode()->children().end()) {
|
||||
throw DeadlyImportError(std::string("Node <") + std::string(node->getNode()->name()) + "> must have children.");
|
||||
}
|
||||
}
|
||||
|
||||
void AMFImporter::XML_CheckNode_SkipUnsupported(const std::string &pParentNodeName) {
|
||||
/*void AMFImporter::XML_CheckNode_SkipUnsupported(XmlNode *node, const std::string &pParentNodeName) {
|
||||
static const size_t Uns_Skip_Len = 3;
|
||||
const char *Uns_Skip[Uns_Skip_Len] = { "composite", "edge", "normal" };
|
||||
|
||||
|
@ -216,8 +220,9 @@ casu_cres:
|
|||
ASSIMP_LOG_WARN_F("Skipping node \"", nn, "\" in ", pParentNodeName, ".");
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
bool AMFImporter::XML_SearchNode(const std::string &pNodeName) {
|
||||
|
||||
mReader->while (mReader->read()) {
|
||||
//if((mReader->getNodeType() == irr::io::EXN_ELEMENT) && XML_CheckNode_NameEqual(pNodeName)) return true;
|
||||
if ((mReader->getNodeType() == pugi::node_element) && XML_CheckNode_NameEqual(pNodeName)) {
|
||||
|
@ -615,7 +620,9 @@ void AMFImporter::ParseNode_Object(XmlNode *nodeInst) {
|
|||
for (pugi::xml_node_iterator it = node->children().begin(); it != node->children->end(); ++it) {
|
||||
bool col_read = false;
|
||||
if (it->name() == "mesh") {
|
||||
ParseNode_Mesh( it );
|
||||
ParseNode_Mesh(*it);
|
||||
} else if (it->name() == "metadata") {
|
||||
ParseNode_Metadata(*it);
|
||||
}
|
||||
}
|
||||
if (!mReader->isEmptyElement()) {
|
||||
|
|
|
@ -272,15 +272,15 @@ private:
|
|||
/// \throw DeadlyImportError.
|
||||
/// \param [in] pNodeType - type of node which defined one more time.
|
||||
/// \param [in] pDescription - message about error. E.g. what the node defined while exception raised.
|
||||
void Throw_MoreThanOnceDefined(const std::string& pNodeType, const std::string& pDescription);
|
||||
void Throw_MoreThanOnceDefined(const std::string &nodeType, const std::string &nodeName, const std::string &pDescription);
|
||||
|
||||
/// Call that function when referenced element ID are not found in graph and exception must be raised.
|
||||
/// \param [in] pID - ID of of element which not found.
|
||||
/// \throw DeadlyImportError.
|
||||
void Throw_ID_NotFound(const std::string& pID) const;
|
||||
|
||||
/// Check if current node have children: <node>...</node>. If not then exception will throwed.
|
||||
void XML_CheckNode_MustHaveChildren();
|
||||
/// Check if current node have children: <node>...</node>. If not then exception will thrown.
|
||||
void XML_CheckNode_MustHaveChildren(XmlNode *node);
|
||||
|
||||
/// Check if current node name is equal to pNodeName.
|
||||
/// \param [in] pNodeName - name for checking.
|
||||
|
@ -292,7 +292,7 @@ private:
|
|||
|
||||
/// Skip unsupported node and report about that. Depend on node name can be skipped begin tag of node all whole node.
|
||||
/// \param [in] pParentNodeName - parent node name. Used for reporting.
|
||||
void XML_CheckNode_SkipUnsupported(const std::string& pParentNodeName);
|
||||
//void XML_CheckNode_SkipUnsupported(XmlNode *node, const std::string &pParentNodeName);
|
||||
|
||||
/// Search for specified node in file. XML file read pointer(mReader) will point to found node or file end after search is end.
|
||||
/// \param [in] pNodeName - requested node name.
|
||||
|
|
|
@ -43,24 +43,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
/** @file Implementation of the IrrMesh importer class */
|
||||
|
||||
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_IRRMESH_IMPORTER
|
||||
|
||||
#include "IRRMeshLoader.h"
|
||||
#include <assimp/ParsingUtils.h>
|
||||
#include <assimp/fast_atof.h>
|
||||
#include <memory>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/mesh.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/material.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/importerdesc.h>
|
||||
#include <assimp/material.h>
|
||||
#include <assimp/mesh.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <memory>
|
||||
|
||||
using namespace Assimp;
|
||||
using namespace irr;
|
||||
using namespace irr::io;
|
||||
|
||||
static const aiImporterDesc desc = {
|
||||
"Irrlicht Mesh Reader",
|
||||
|
@ -77,18 +73,15 @@ static const aiImporterDesc desc = {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor to be privately used by Importer
|
||||
IRRMeshImporter::IRRMeshImporter()
|
||||
{}
|
||||
IRRMeshImporter::IRRMeshImporter() {}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor, private as well
|
||||
IRRMeshImporter::~IRRMeshImporter()
|
||||
{}
|
||||
IRRMeshImporter::~IRRMeshImporter() {}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns whether the class can handle the format of the given file.
|
||||
bool IRRMeshImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
|
||||
{
|
||||
bool IRRMeshImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const {
|
||||
/* NOTE: A simple check for the file extension is not enough
|
||||
* here. Irrmesh and irr are easy, but xml is too generic
|
||||
* and could be collada, too. So we need to open the file and
|
||||
|
@ -96,9 +89,9 @@ bool IRRMeshImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, b
|
|||
*/
|
||||
const std::string extension = GetExtension(pFile);
|
||||
|
||||
if (extension == "irrmesh")return true;
|
||||
else if (extension == "xml" || checkSig)
|
||||
{
|
||||
if (extension == "irrmesh")
|
||||
return true;
|
||||
else if (extension == "xml" || checkSig) {
|
||||
/* If CanRead() is called to check whether the loader
|
||||
* supports a specific file extension in general we
|
||||
* must return true here.
|
||||
|
@ -112,8 +105,7 @@ bool IRRMeshImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, b
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get a list of all file extensions which are handled by this class
|
||||
const aiImporterDesc* IRRMeshImporter::GetInfo () const
|
||||
{
|
||||
const aiImporterDesc *IRRMeshImporter::GetInfo() const {
|
||||
return &desc;
|
||||
}
|
||||
|
||||
|
@ -134,8 +126,7 @@ static void releaseMesh( aiMesh **mesh ) {
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
// Imports the given file into the given scene structure.
|
||||
void IRRMeshImporter::InternReadFile(const std::string &pFile,
|
||||
aiScene* pScene, IOSystem* pIOHandler)
|
||||
{
|
||||
aiScene *pScene, IOSystem *pIOHandler) {
|
||||
std::unique_ptr<IOStream> file(pIOHandler->Open(pFile));
|
||||
|
||||
// Check whether we can read from the file
|
||||
|
@ -143,8 +134,10 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
throw DeadlyImportError("Failed to open IRRMESH file " + pFile + "");
|
||||
|
||||
// Construct the irrXML parser
|
||||
CIrrXML_IOStreamReader st(file.get());
|
||||
reader = createIrrXMLReader((IFileReadCallBack*) &st);
|
||||
XmlParser parser;
|
||||
pugi::xml_node *root = parser.parse(file.get());
|
||||
/*CIrrXML_IOStreamReader st(file.get());
|
||||
reader = createIrrXMLReader((IFileReadCallBack*) &st);*/
|
||||
|
||||
// final data
|
||||
std::vector<aiMaterial *> materials;
|
||||
|
@ -167,11 +160,9 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
bool useColors = false;
|
||||
|
||||
// Parse the XML file
|
||||
while (reader->read()) {
|
||||
switch (reader->getNodeType()) {
|
||||
case EXN_ELEMENT:
|
||||
|
||||
if (!ASSIMP_stricmp(reader->getNodeName(),"buffer") && (curMat || curMesh)) {
|
||||
for (pugi::xml_node child : root->children()) {
|
||||
if (child.type() == pugi::node_element) {
|
||||
if (!ASSIMP_stricmp(child.name(), "buffer") && (curMat || curMesh)) {
|
||||
// end of previous buffer. A material and a mesh should be there
|
||||
if (!curMat || !curMesh) {
|
||||
ASSIMP_LOG_ERROR("IRRMESH: A buffer must contain a mesh and a material");
|
||||
|
@ -193,17 +184,17 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
curBitangents.clear();
|
||||
}
|
||||
|
||||
|
||||
if (!ASSIMP_stricmp(reader->getNodeName(),"material")) {
|
||||
if (!ASSIMP_stricmp(child.name(), "material")) {
|
||||
if (curMat) {
|
||||
ASSIMP_LOG_WARN("IRRMESH: Only one material description per buffer, please");
|
||||
releaseMaterial(&curMat);
|
||||
}
|
||||
curMat = ParseMaterial(curMatFlags);
|
||||
}
|
||||
/* no else here! */ if (!ASSIMP_stricmp(reader->getNodeName(),"vertices"))
|
||||
{
|
||||
int num = reader->getAttributeValueAsInt("vertexCount");
|
||||
/* no else here! */ if (!ASSIMP_stricmp(child.name(), "vertices")) {
|
||||
pugi::xml_attribute attr = child.attribute("vertexCount");
|
||||
int num = attr.as_int();
|
||||
//int num = reader->getAttributeValueAsInt("vertexCount");
|
||||
|
||||
if (!num) {
|
||||
// This is possible ... remove the mesh from the list and skip further reading
|
||||
|
@ -221,8 +212,9 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
curUVs.reserve(num);
|
||||
|
||||
// Determine the file format
|
||||
const char* t = reader->getAttributeValueSafe("type");
|
||||
if (!ASSIMP_stricmp("2tcoords", t)) {
|
||||
//const char *t = reader->getAttributeValueSafe("type");
|
||||
pugi::xml_attribute t = child.attribute("type");
|
||||
if (!ASSIMP_stricmp("2tcoords", t.name())) {
|
||||
curUV2s.reserve(num);
|
||||
vertexFormat = 1;
|
||||
|
||||
|
@ -238,28 +230,23 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
|
||||
if (curMatFlags & AI_IRRMESH_MAT_lightmap) {
|
||||
mat->AddProperty(&idx, 1, AI_MATKEY_UVWSRC_LIGHTMAP(0));
|
||||
}
|
||||
else if (curMatFlags & AI_IRRMESH_MAT_normalmap_solid){
|
||||
} else if (curMatFlags & AI_IRRMESH_MAT_normalmap_solid) {
|
||||
mat->AddProperty(&idx, 1, AI_MATKEY_UVWSRC_NORMALS(0));
|
||||
}
|
||||
else if (curMatFlags & AI_IRRMESH_MAT_solid_2layer) {
|
||||
} else if (curMatFlags & AI_IRRMESH_MAT_solid_2layer) {
|
||||
mat->AddProperty(&idx, 1, AI_MATKEY_UVWSRC_DIFFUSE(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!ASSIMP_stricmp("tangents", t)) {
|
||||
} else if (!ASSIMP_stricmp("tangents", t.name())) {
|
||||
curTangents.reserve(num);
|
||||
curBitangents.reserve(num);
|
||||
vertexFormat = 2;
|
||||
}
|
||||
else if (ASSIMP_stricmp("standard", t)) {
|
||||
} else if (ASSIMP_stricmp("standard", t.name())) {
|
||||
releaseMaterial(&curMat);
|
||||
ASSIMP_LOG_WARN("IRRMESH: Unknown vertex format");
|
||||
}
|
||||
else vertexFormat = 0;
|
||||
} else
|
||||
vertexFormat = 0;
|
||||
textMeaning = 1;
|
||||
}
|
||||
else if (!ASSIMP_stricmp(reader->getNodeName(),"indices")) {
|
||||
} else if (!ASSIMP_stricmp(child.name(), "indices")) {
|
||||
if (curVertices.empty() && curMat) {
|
||||
releaseMaterial(&curMat);
|
||||
throw DeadlyImportError("IRRMESH: indices must come after vertices");
|
||||
|
@ -271,7 +258,8 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
curMesh = new aiMesh();
|
||||
|
||||
// allocate storage for all faces
|
||||
curMesh->mNumVertices = reader->getAttributeValueAsInt("indexCount");
|
||||
pugi::xml_attribute attr = child.attribute("indexCount");
|
||||
curMesh->mNumVertices = attr.as_int();
|
||||
if (!curMesh->mNumVertices) {
|
||||
// This is possible ... remove the mesh from the list and skip further reading
|
||||
ASSIMP_LOG_WARN("IRRMESH: Found mesh with zero indices");
|
||||
|
@ -319,18 +307,18 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
curMesh->mTextureCoords[1] = new aiVector3D[curMesh->mNumVertices];
|
||||
}
|
||||
}
|
||||
break;
|
||||
//break;
|
||||
|
||||
case EXN_TEXT:
|
||||
{
|
||||
const char* sz = reader->getNodeData();
|
||||
//case EXN_TEXT: {
|
||||
const char *sz = child.child_value();
|
||||
if (textMeaning == 1) {
|
||||
textMeaning = 0;
|
||||
|
||||
// read vertices
|
||||
do {
|
||||
SkipSpacesAndLineEnd(&sz);
|
||||
aiVector3D temp;aiColor4D c;
|
||||
aiVector3D temp;
|
||||
aiColor4D c;
|
||||
|
||||
// Read the vertex position
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.x);
|
||||
|
@ -364,7 +352,6 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
curColors.push_back(c);
|
||||
SkipSpaces(&sz);
|
||||
|
||||
|
||||
// read the first UV coordinate set
|
||||
sz = fast_atoreal_move<float>(sz, (float &)temp.x);
|
||||
SkipSpaces(&sz);
|
||||
|
@ -418,8 +405,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
*/
|
||||
|
||||
while (SkipLine(&sz));
|
||||
}
|
||||
else if (textMeaning == 2) {
|
||||
} else if (textMeaning == 2) {
|
||||
textMeaning = 0;
|
||||
|
||||
// read indices
|
||||
|
@ -478,14 +464,8 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
aiMaterial *mat = (aiMaterial *)curMat;
|
||||
mat->AddProperty(&curColors[0].a, 1, AI_MATKEY_OPACITY);
|
||||
}
|
||||
}}
|
||||
break;
|
||||
|
||||
default:
|
||||
// GCC complains here ...
|
||||
break;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// End of the last buffer. A material and a mesh should be there
|
||||
|
@ -494,16 +474,15 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
ASSIMP_LOG_ERROR("IRRMESH: A buffer must contain a mesh and a material");
|
||||
releaseMaterial(&curMat);
|
||||
releaseMesh(&curMesh);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
materials.push_back(curMat);
|
||||
meshes.push_back(curMesh);
|
||||
}
|
||||
}
|
||||
|
||||
if (materials.empty())
|
||||
if (materials.empty()) {
|
||||
throw DeadlyImportError("IRRMESH: Unable to read a mesh from this file");
|
||||
|
||||
}
|
||||
|
||||
// now generate the output scene
|
||||
pScene->mNumMeshes = (unsigned int)meshes.size();
|
||||
|
@ -524,12 +503,10 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
pScene->mRootNode->mNumMeshes = pScene->mNumMeshes;
|
||||
pScene->mRootNode->mMeshes = new unsigned int[pScene->mNumMeshes];
|
||||
|
||||
for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
|
||||
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
|
||||
pScene->mRootNode->mMeshes[i] = i;
|
||||
}
|
||||
|
||||
// clean up and return
|
||||
delete reader;
|
||||
AI_DEBUG_INVALIDATE_PTR(reader);
|
||||
}
|
||||
|
||||
#endif // !! ASSIMP_BUILD_NO_IRRMESH_IMPORTER
|
||||
|
|
|
@ -141,43 +141,55 @@ private:
|
|||
}; // ! class CIrrXML_IOStreamReader
|
||||
*/
|
||||
|
||||
class XmlNode {
|
||||
public:
|
||||
XmlNode()
|
||||
: mNode(nullptr){
|
||||
// empty
|
||||
}
|
||||
XmlNode(pugi::xml_node *node)
|
||||
: mNode(node) {
|
||||
struct find_node_by_name_predicate {
|
||||
std::string mName;
|
||||
find_node_by_name_predicate(const std::string &name) :
|
||||
mName(name) {
|
||||
// empty
|
||||
}
|
||||
|
||||
pugi::xml_node *getNode() const {
|
||||
return mNode;
|
||||
bool operator()(pugi::xml_node node) const {
|
||||
return node.name() == mName;
|
||||
}
|
||||
|
||||
private:
|
||||
pugi::xml_node *mNode;
|
||||
};
|
||||
|
||||
class XmlParser {
|
||||
|
||||
template<class TNodeType>
|
||||
class TXmlParser {
|
||||
public:
|
||||
XmlParser() :
|
||||
TXmlParser() :
|
||||
mDoc(nullptr), mRoot(nullptr), mData() {
|
||||
// empty
|
||||
}
|
||||
|
||||
~XmlParser() {
|
||||
~TXmlParser() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
mData.resize(0);
|
||||
mRoot = nullptr;
|
||||
delete mDoc;
|
||||
mDoc = nullptr;
|
||||
}
|
||||
|
||||
XmlNode *parse(IOStream *stream) {
|
||||
TNodeType *findNode(const std::string &name) {
|
||||
if (name.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (nullptr == mDoc) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
find_node_by_name_predicate predicate(name);
|
||||
pugi::xml_node node = mDoc->find_node(predicate);
|
||||
if (node.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TNodeType *parse(IOStream *stream) {
|
||||
if (nullptr == stream) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -187,8 +199,7 @@ public:
|
|||
mDoc = new pugi::xml_document();
|
||||
pugi::xml_parse_result result = mDoc->load_string(&mData[0]);
|
||||
if (result.status == pugi::status_ok) {
|
||||
pugi::xml_node *root = &mDoc->root();
|
||||
mRoot = new XmlNode(root);
|
||||
mRoot = &mDoc->root();
|
||||
}
|
||||
|
||||
return mRoot;
|
||||
|
@ -198,12 +209,18 @@ public:
|
|||
return mDoc;
|
||||
}
|
||||
|
||||
TNodeType *getRootNode() const {
|
||||
return mRoot;
|
||||
}
|
||||
|
||||
private:
|
||||
pugi::xml_document *mDoc;
|
||||
XmlNode *mRoot;
|
||||
TNodeType *mRoot;
|
||||
std::vector<char> mData;
|
||||
};
|
||||
|
||||
using XmlParser = TXmlParser<pugi::xml_node>;
|
||||
|
||||
} // namespace Assimp
|
||||
|
||||
#endif // !! INCLUDED_AI_IRRXML_WRAPPER
|
||||
|
|
Loading…
Reference in New Issue