finish migrate ogrexmlserializer.
parent
b19ebf5d54
commit
deddaf49df
|
@ -126,11 +126,13 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass
|
||||||
{
|
{
|
||||||
/// @note XmlReader does not take ownership of f, hence the scoped ptr.
|
/// @note XmlReader does not take ownership of f, hence the scoped ptr.
|
||||||
std::unique_ptr<IOStream> scopedFile(f);
|
std::unique_ptr<IOStream> scopedFile(f);
|
||||||
std::unique_ptr<CIrrXML_IOStreamReader> xmlStream(new CIrrXML_IOStreamReader(scopedFile.get()));
|
XmlParser xmlParser;
|
||||||
std::unique_ptr<XmlReader> reader(irr::io::createIrrXMLReader(xmlStream.get()));
|
|
||||||
|
|
||||||
|
//std::unique_ptr<CIrrXML_IOStreamReader> xmlStream(new CIrrXML_IOStreamReader(scopedFile.get()));
|
||||||
|
//std::unique_ptr<XmlReader> reader(irr::io::createIrrXMLReader(xmlStream.get()));
|
||||||
|
xmlParser.parse(scopedFile.get());
|
||||||
// Import mesh
|
// Import mesh
|
||||||
std::unique_ptr<MeshXml> mesh(OgreXmlSerializer::ImportMesh(reader.get()));
|
std::unique_ptr<MeshXml> mesh(OgreXmlSerializer::ImportMesh(xmlParser));
|
||||||
|
|
||||||
// Import skeleton
|
// Import skeleton
|
||||||
OgreXmlSerializer::ImportSkeleton(pIOHandler, mesh.get());
|
OgreXmlSerializer::ImportSkeleton(pIOHandler, mesh.get());
|
||||||
|
|
|
@ -42,8 +42,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "OgreXmlSerializer.h"
|
#include "OgreXmlSerializer.h"
|
||||||
#include "OgreBinarySerializer.h"
|
#include "OgreBinarySerializer.h"
|
||||||
#include "OgreParsingUtils.h"
|
#include "OgreParsingUtils.h"
|
||||||
|
|
||||||
#include <assimp/TinyFormatter.h>
|
#include <assimp/TinyFormatter.h>
|
||||||
#include <assimp/DefaultLogger.hpp>
|
#include <assimp/DefaultLogger.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#ifndef ASSIMP_BUILD_NO_OGRE_IMPORTER
|
#ifndef ASSIMP_BUILD_NO_OGRE_IMPORTER
|
||||||
|
@ -63,10 +65,6 @@ AI_WONT_RETURN void ThrowAttibuteError(const std::string &nodeName, const std::s
|
||||||
throw DeadlyImportError("Attribute '" + name + "' does not exist in node '" + nodeName + "'");
|
throw DeadlyImportError("Attribute '" + name + "' does not exist in node '" + nodeName + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static inline bool hasAttribute( XmlNode &xmlNode, const char *name ) {
|
|
||||||
pugi::xml_attribute attr = xmlNode.attribute(name);
|
|
||||||
return !attr.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
int32_t OgreXmlSerializer::ReadAttribute<int32_t>(XmlNode &xmlNode, const char *name) const {
|
int32_t OgreXmlSerializer::ReadAttribute<int32_t>(XmlNode &xmlNode, const char *name) const {
|
||||||
|
@ -133,51 +131,7 @@ bool OgreXmlSerializer::ReadAttribute<bool>(XmlNode &xmlNode, const char *name)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*std::string &OgreXmlSerializer::NextNode() {
|
|
||||||
do {
|
|
||||||
if (!m_reader->read()) {
|
|
||||||
m_currentNodeName = "";
|
|
||||||
return m_currentNodeName;
|
|
||||||
}
|
|
||||||
} while (m_reader->getNodeType() != irr::io::EXN_ELEMENT);
|
|
||||||
|
|
||||||
CurrentNodeName(true);
|
|
||||||
#if (OGRE_XML_SERIALIZER_DEBUG == 1)
|
|
||||||
ASSIMP_LOG_DEBUG"<" + m_currentNodeName + ">");
|
|
||||||
#endif
|
|
||||||
return m_currentNodeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OgreXmlSerializer::CurrentNodeNameEquals(const std::string &name) const {
|
|
||||||
return (ASSIMP_stricmp(m_currentNodeName, name) == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string OgreXmlSerializer::CurrentNodeName(bool forceRead) {
|
|
||||||
if (forceRead)
|
|
||||||
m_currentNodeName = std::string(m_reader->getNodeName());
|
|
||||||
return m_currentNodeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string &OgreXmlSerializer::SkipCurrentNode() {
|
|
||||||
#if (OGRE_XML_SERIALIZER_DEBUG == 1)
|
|
||||||
ASSIMP_LOG_DEBUG("Skipping node <" + m_currentNodeName + ">");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
if (!m_reader->read()) {
|
|
||||||
m_currentNodeName = "";
|
|
||||||
return m_currentNodeName;
|
|
||||||
}
|
|
||||||
if (m_reader->getNodeType() != irr::io::EXN_ELEMENT_END) {
|
|
||||||
continue;
|
|
||||||
} else if (std::string(m_reader->getNodeName()) == m_currentNodeName) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NextNode();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// Mesh XML constants
|
// Mesh XML constants
|
||||||
|
|
||||||
// <mesh>
|
// <mesh>
|
||||||
|
@ -252,8 +206,17 @@ static const char *anZ = "z";
|
||||||
|
|
||||||
// Mesh
|
// Mesh
|
||||||
|
|
||||||
MeshXml *OgreXmlSerializer::ImportMesh(XmlParser *xmlParser) {
|
OgreXmlSerializer::OgreXmlSerializer(XmlParser *parser) :
|
||||||
OgreXmlSerializer serializer(xmlParser);
|
mParser(parser) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
|
MeshXml *OgreXmlSerializer::ImportMesh(XmlParser *parser) {
|
||||||
|
if (nullptr == parser) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
OgreXmlSerializer serializer(parser);
|
||||||
|
|
||||||
MeshXml *mesh = new MeshXml();
|
MeshXml *mesh = new MeshXml();
|
||||||
serializer.ReadMesh(mesh);
|
serializer.ReadMesh(mesh);
|
||||||
|
@ -262,9 +225,9 @@ MeshXml *OgreXmlSerializer::ImportMesh(XmlParser *xmlParser) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OgreXmlSerializer::ReadMesh(MeshXml *mesh) {
|
void OgreXmlSerializer::ReadMesh(MeshXml *mesh) {
|
||||||
const XmlNode *root = mParser->getRootNode();
|
XmlNode *root = mParser->getRootNode();
|
||||||
if (nullptr == root || std::string(nnMesh)!=root->name()) {
|
if (nullptr == root || std::string(nnMesh)!=root->name()) {
|
||||||
throw DeadlyImportError("Root node is <" + m_currentNodeName + "> expecting <mesh>");
|
throw DeadlyImportError("Root node is <" + std::string(root->name()) + "> expecting <mesh>");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (XmlNode currentNode : root->children()) {
|
for (XmlNode currentNode : root->children()) {
|
||||||
|
@ -557,7 +520,7 @@ void OgreXmlSerializer::ReadSubMesh(XmlNode &node, MeshXml *mesh) {
|
||||||
|
|
||||||
submesh->vertexData = new VertexDataXml();
|
submesh->vertexData = new VertexDataXml();
|
||||||
ReadGeometry(currentNode, submesh->vertexData);
|
ReadGeometry(currentNode, submesh->vertexData);
|
||||||
} else if (m_currentNodeName == nnBoneAssignments) {
|
} else if (currentName == nnBoneAssignments) {
|
||||||
ReadBoneAssignments(currentNode, submesh->vertexData);
|
ReadBoneAssignments(currentNode, submesh->vertexData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,21 +49,21 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <assimp/XmlParser.h>
|
#include <assimp/XmlParser.h>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
namespace Ogre {
|
namespace Ogre {
|
||||||
|
|
||||||
//typedef irr::io::IrrXMLReader XmlReader;
|
using XmlParserPtr = std::shared_ptr<::Assimp::XmlParser> ;
|
||||||
using XmlParserPtr = std::shared_ptr<XmlParser> ;
|
|
||||||
|
|
||||||
class OgreXmlSerializer {
|
class OgreXmlSerializer {
|
||||||
public:
|
public:
|
||||||
/// Imports mesh and returns the result.
|
/// Imports mesh and returns the result.
|
||||||
/** @note Fatal unrecoverable errors will throw a DeadlyImportError. */
|
/// @note Fatal unrecoverable errors will throw a DeadlyImportError.
|
||||||
static MeshXml *ImportMesh(XmlParser *parser);
|
static MeshXml *ImportMesh(XmlParser *parser);
|
||||||
|
|
||||||
/// Imports skeleton to @c mesh.
|
/// Imports skeleton to @c mesh.
|
||||||
/** If mesh does not have a skeleton reference or the skeleton file
|
/// If mesh does not have a skeleton reference or the skeleton file
|
||||||
cannot be found it is not a fatal DeadlyImportError.
|
/// cannot be found it is not a fatal DeadlyImportError.
|
||||||
@return If skeleton import was successful. */
|
/// @return If skeleton import was successful.
|
||||||
static bool ImportSkeleton(IOSystem *pIOHandler, MeshXml *mesh);
|
static bool ImportSkeleton(IOSystem *pIOHandler, MeshXml *mesh);
|
||||||
static bool ImportSkeleton(IOSystem *pIOHandler, Mesh *mesh);
|
static bool ImportSkeleton(IOSystem *pIOHandler, Mesh *mesh);
|
||||||
|
|
||||||
|
@ -75,40 +75,25 @@ private:
|
||||||
// Mesh
|
// Mesh
|
||||||
void ReadMesh(MeshXml *mesh);
|
void ReadMesh(MeshXml *mesh);
|
||||||
void ReadSubMesh(XmlNode &node, MeshXml *mesh);
|
void ReadSubMesh(XmlNode &node, MeshXml *mesh);
|
||||||
|
|
||||||
void ReadGeometry(XmlNode &node, VertexDataXml *dest);
|
void ReadGeometry(XmlNode &node, VertexDataXml *dest);
|
||||||
void ReadGeometryVertexBuffer(XmlNode &node, VertexDataXml *dest);
|
void ReadGeometryVertexBuffer(XmlNode &node, VertexDataXml *dest);
|
||||||
|
|
||||||
void ReadBoneAssignments(XmlNode &node, VertexDataXml *dest);
|
void ReadBoneAssignments(XmlNode &node, VertexDataXml *dest);
|
||||||
|
|
||||||
// Skeleton
|
// Skeleton
|
||||||
void ReadSkeleton(XmlNode &node, Skeleton *skeleton);
|
void ReadSkeleton(XmlNode &node, Skeleton *skeleton);
|
||||||
|
|
||||||
void ReadBones(XmlNode &node, Skeleton *skeleton);
|
void ReadBones(XmlNode &node, Skeleton *skeleton);
|
||||||
void ReadBoneHierarchy(XmlNode &node, Skeleton *skeleton);
|
void ReadBoneHierarchy(XmlNode &node, Skeleton *skeleton);
|
||||||
|
|
||||||
void ReadAnimations(XmlNode &node, Skeleton *skeleton);
|
void ReadAnimations(XmlNode &node, Skeleton *skeleton);
|
||||||
void ReadAnimationTracks(XmlNode &node, Animation *dest);
|
void ReadAnimationTracks(XmlNode &node, Animation *dest);
|
||||||
void ReadAnimationKeyFrames(XmlNode &node, Animation *anim, VertexAnimationTrack *dest);
|
void ReadAnimationKeyFrames(XmlNode &node, Animation *anim, VertexAnimationTrack *dest);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T ReadAttribute(XmlNode &xmlNode, const char *name) const;
|
T ReadAttribute(XmlNode &xmlNode, const char *name) const;
|
||||||
//bool HasAttribute(const char *name) const;
|
|
||||||
|
|
||||||
//std::string &NextNode();
|
|
||||||
//std::string &SkipCurrentNode();
|
|
||||||
|
|
||||||
//bool CurrentNodeNameEquals(const std::string &name) const;
|
|
||||||
//std::string CurrentNodeName(bool forceRead = false);
|
|
||||||
|
|
||||||
|
private:
|
||||||
XmlParser *mParser;
|
XmlParser *mParser;
|
||||||
std::string m_currentNodeName;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline OgreXmlSerializer::OgreXmlSerializer(XmlParser *xmlParser) :
|
|
||||||
mParser(xmlParser) {
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Ogre
|
} // namespace Ogre
|
||||||
} // namespace Assimp
|
} // namespace Assimp
|
||||||
|
|
|
@ -154,6 +154,11 @@ private:
|
||||||
using XmlParser = TXmlParser<pugi::xml_node>;
|
using XmlParser = TXmlParser<pugi::xml_node>;
|
||||||
using XmlNode = pugi::xml_node;
|
using XmlNode = pugi::xml_node;
|
||||||
|
|
||||||
|
static inline bool hasAttribute(XmlNode &xmlNode, const char *name) {
|
||||||
|
pugi::xml_attribute attr = xmlNode.attribute(name);
|
||||||
|
return !attr.empty();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Assimp
|
} // namespace Assimp
|
||||||
|
|
||||||
#endif // !! INCLUDED_AI_IRRXML_WRAPPER
|
#endif // !! INCLUDED_AI_IRRXML_WRAPPER
|
||||||
|
|
Loading…
Reference in New Issue