Ogre: fix xml migration.
parent
d6892b3f58
commit
9234fee35e
|
@ -131,7 +131,6 @@ bool OgreXmlSerializer::ReadAttribute<bool>(XmlNode &xmlNode, const char *name)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Mesh XML constants
|
// Mesh XML constants
|
||||||
|
|
||||||
// <mesh>
|
// <mesh>
|
||||||
|
@ -226,17 +225,26 @@ MeshXml *OgreXmlSerializer::ImportMesh(XmlParser *parser) {
|
||||||
|
|
||||||
void OgreXmlSerializer::ReadMesh(MeshXml *mesh) {
|
void OgreXmlSerializer::ReadMesh(MeshXml *mesh) {
|
||||||
XmlNode root = mParser->getRootNode();
|
XmlNode root = mParser->getRootNode();
|
||||||
if (nullptr == root || std::string(nnMesh) != root.name()) {
|
if (nullptr == root) {
|
||||||
throw DeadlyImportError("Root node is <" + std::string(root.name()) + "> expecting <mesh>");
|
throw DeadlyImportError("Root node is <" + std::string(root.name()) + "> expecting <mesh>");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (XmlNode currentNode : root.children()) {
|
XmlNode startNode = root.child(nnMesh);
|
||||||
|
if (startNode.empty()) {
|
||||||
|
throw DeadlyImportError("Root node is <" + std::string(root.name()) + "> expecting <mesh>");
|
||||||
|
}
|
||||||
|
for (XmlNode currentNode : startNode.children()) {
|
||||||
const std::string currentName = currentNode.name();
|
const std::string currentName = currentNode.name();
|
||||||
if (currentName == nnSharedGeometry) {
|
if (currentName == nnSharedGeometry) {
|
||||||
mesh->sharedVertexData = new VertexDataXml();
|
mesh->sharedVertexData = new VertexDataXml();
|
||||||
ReadGeometry(currentNode, mesh->sharedVertexData);
|
ReadGeometry(currentNode, mesh->sharedVertexData);
|
||||||
} else if (currentName == nnSubMesh) {
|
} else if (currentName == nnSubMeshes) {
|
||||||
ReadSubMesh(currentNode, mesh);
|
for (XmlNode &subMeshesNode : currentNode.children()) {
|
||||||
|
const std::string ¤tSMName = subMeshesNode.name();
|
||||||
|
if (currentSMName == nnSubMesh) {
|
||||||
|
ReadSubMesh(subMeshesNode, mesh);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (currentName == nnBoneAssignments) {
|
} else if (currentName == nnBoneAssignments) {
|
||||||
ReadBoneAssignments(currentNode, mesh->sharedVertexData);
|
ReadBoneAssignments(currentNode, mesh->sharedVertexData);
|
||||||
} else if (currentName == nnSkeletonLink) {
|
} else if (currentName == nnSkeletonLink) {
|
||||||
|
@ -289,32 +297,34 @@ void OgreXmlSerializer::ReadGeometryVertexBuffer(XmlNode &node, VertexDataXml *d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (XmlNode currentNode : node.children()) {
|
for (XmlNode currentNode : node.children("vertex")) {
|
||||||
const std::string ¤tName = currentNode.name();
|
for (XmlNode vertexNode : currentNode.children()) {
|
||||||
if (positions && currentName == nnPosition) {
|
const std::string ¤tName = vertexNode.name();
|
||||||
aiVector3D pos;
|
if (positions && currentName == nnPosition) {
|
||||||
pos.x = ReadAttribute<float>(currentNode, anX);
|
aiVector3D pos;
|
||||||
pos.y = ReadAttribute<float>(currentNode, anY);
|
pos.x = ReadAttribute<float>(vertexNode, anX);
|
||||||
pos.z = ReadAttribute<float>(currentNode, anZ);
|
pos.y = ReadAttribute<float>(vertexNode, anY);
|
||||||
dest->positions.push_back(pos);
|
pos.z = ReadAttribute<float>(vertexNode, anZ);
|
||||||
} else if (normals && currentName == nnNormal) {
|
dest->positions.push_back(pos);
|
||||||
aiVector3D normal;
|
} else if (normals && currentName == nnNormal) {
|
||||||
normal.x = ReadAttribute<float>(currentNode, anX);
|
aiVector3D normal;
|
||||||
normal.y = ReadAttribute<float>(currentNode, anY);
|
normal.x = ReadAttribute<float>(vertexNode, anX);
|
||||||
normal.z = ReadAttribute<float>(currentNode, anZ);
|
normal.y = ReadAttribute<float>(vertexNode, anY);
|
||||||
dest->normals.push_back(normal);
|
normal.z = ReadAttribute<float>(vertexNode, anZ);
|
||||||
} else if (tangents && currentName == nnTangent) {
|
dest->normals.push_back(normal);
|
||||||
aiVector3D tangent;
|
} else if (tangents && currentName == nnTangent) {
|
||||||
tangent.x = ReadAttribute<float>(currentNode, anX);
|
aiVector3D tangent;
|
||||||
tangent.y = ReadAttribute<float>(currentNode, anY);
|
tangent.x = ReadAttribute<float>(vertexNode, anX);
|
||||||
tangent.z = ReadAttribute<float>(currentNode, anZ);
|
tangent.y = ReadAttribute<float>(vertexNode, anY);
|
||||||
dest->tangents.push_back(tangent);
|
tangent.z = ReadAttribute<float>(vertexNode, anZ);
|
||||||
} else if (uvs > 0 && currentName == nnTexCoord) {
|
dest->tangents.push_back(tangent);
|
||||||
for (auto &curUvs : dest->uvs) {
|
} else if (uvs > 0 && currentName == nnTexCoord) {
|
||||||
aiVector3D uv;
|
for (auto &curUvs : dest->uvs) {
|
||||||
uv.x = ReadAttribute<float>(currentNode, "u");
|
aiVector3D uv;
|
||||||
uv.y = (ReadAttribute<float>(currentNode, "v") * -1) + 1; // Flip UV from Ogre to Assimp form
|
uv.x = ReadAttribute<float>(vertexNode, "u");
|
||||||
curUvs.push_back(uv);
|
uv.y = (ReadAttribute<float>(vertexNode, "v") * -1) + 1; // Flip UV from Ogre to Assimp form
|
||||||
|
curUvs.push_back(uv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,7 +342,7 @@ void OgreXmlSerializer::ReadGeometryVertexBuffer(XmlNode &node, VertexDataXml *d
|
||||||
for (unsigned int i = 0; i < dest->uvs.size(); ++i) {
|
for (unsigned int i = 0; i < dest->uvs.size(); ++i) {
|
||||||
if (dest->uvs[i].size() != dest->count) {
|
if (dest->uvs[i].size() != dest->count) {
|
||||||
throw DeadlyImportError("Read only ", dest->uvs[i].size(),
|
throw DeadlyImportError("Read only ", dest->uvs[i].size(),
|
||||||
" uvs for uv index ", i, " when should have read ", dest->count);
|
" uvs for uv index ", i, " when should have read ", dest->count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -371,7 +381,7 @@ void OgreXmlSerializer::ReadSubMesh(XmlNode &node, MeshXml *mesh) {
|
||||||
submesh->indexData->faceCount = ReadAttribute<uint32_t>(currentNode, anCount);
|
submesh->indexData->faceCount = ReadAttribute<uint32_t>(currentNode, anCount);
|
||||||
submesh->indexData->faces.reserve(submesh->indexData->faceCount);
|
submesh->indexData->faces.reserve(submesh->indexData->faceCount);
|
||||||
for (XmlNode currentChildNode : currentNode.children()) {
|
for (XmlNode currentChildNode : currentNode.children()) {
|
||||||
const std::string ¤tChildName = currentNode.name();
|
const std::string ¤tChildName = currentChildNode.name();
|
||||||
if (currentChildName == nnFace) {
|
if (currentChildName == nnFace) {
|
||||||
aiFace face;
|
aiFace face;
|
||||||
face.mNumIndices = 3;
|
face.mNumIndices = 3;
|
||||||
|
@ -384,6 +394,7 @@ void OgreXmlSerializer::ReadSubMesh(XmlNode &node, MeshXml *mesh) {
|
||||||
ASSIMP_LOG_WARN("Submesh <face> has quads with <v4>, only triangles are supported at the moment!");
|
ASSIMP_LOG_WARN("Submesh <face> has quads with <v4>, only triangles are supported at the moment!");
|
||||||
quadWarned = true;
|
quadWarned = true;
|
||||||
}
|
}
|
||||||
|
submesh->indexData->faces.push_back(face);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (submesh->indexData->faces.size() == submesh->indexData->faceCount) {
|
if (submesh->indexData->faces.size() == submesh->indexData->faceCount) {
|
||||||
|
@ -561,14 +572,14 @@ void OgreXmlSerializer::ReadAnimations(XmlNode &node, Skeleton *skeleton) {
|
||||||
if (currentName == nnAnimation) {
|
if (currentName == nnAnimation) {
|
||||||
Animation *anim = new Animation(skeleton);
|
Animation *anim = new Animation(skeleton);
|
||||||
anim->name = ReadAttribute<std::string>(currentNode, "name");
|
anim->name = ReadAttribute<std::string>(currentNode, "name");
|
||||||
anim->length = ReadAttribute<float>(currentNode , "length");
|
anim->length = ReadAttribute<float>(currentNode, "length");
|
||||||
for (XmlNode ¤tChildNode : currentNode.children()) {
|
for (XmlNode ¤tChildNode : currentNode.children()) {
|
||||||
const std::string currentChildName = currentNode.name();
|
const std::string currentChildName = currentNode.name();
|
||||||
if (currentChildName == nnTracks) {
|
if (currentChildName == nnTracks) {
|
||||||
ReadAnimationTracks(currentChildNode, anim);
|
ReadAnimationTracks(currentChildNode, anim);
|
||||||
skeleton->animations.push_back(anim);
|
skeleton->animations.push_back(anim);
|
||||||
} else {
|
} else {
|
||||||
throw DeadlyImportError( "No <tracks> found in <animation> ", anim->name);
|
throw DeadlyImportError("No <tracks> found in <animation> ", anim->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -588,10 +599,9 @@ void OgreXmlSerializer::ReadAnimationTracks(XmlNode &node, Animation *dest) {
|
||||||
ReadAnimationKeyFrames(currentChildNode, dest, &track);
|
ReadAnimationKeyFrames(currentChildNode, dest, &track);
|
||||||
dest->tracks.push_back(track);
|
dest->tracks.push_back(track);
|
||||||
} else {
|
} else {
|
||||||
throw DeadlyImportError( "No <keyframes> found in <track> ", dest->name);
|
throw DeadlyImportError("No <keyframes> found in <track> ", dest->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -631,9 +641,7 @@ void OgreXmlSerializer::ReadAnimationKeyFrames(XmlNode &node, Animation *anim, V
|
||||||
keyframe.scale.x = ReadAttribute<float>(currentChildNode, anX);
|
keyframe.scale.x = ReadAttribute<float>(currentChildNode, anX);
|
||||||
keyframe.scale.y = ReadAttribute<float>(currentChildNode, anY);
|
keyframe.scale.y = ReadAttribute<float>(currentChildNode, anY);
|
||||||
keyframe.scale.z = ReadAttribute<float>(currentChildNode, anZ);
|
keyframe.scale.z = ReadAttribute<float>(currentChildNode, anZ);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dest->transformKeyFrames.push_back(keyframe);
|
dest->transformKeyFrames.push_back(keyframe);
|
||||||
|
@ -704,7 +712,7 @@ void OgreXmlSerializer::ReadBones(XmlNode &node, Skeleton *skeleton) {
|
||||||
|
|
||||||
bone->rotation = aiQuaternion(axis, angle);
|
bone->rotation = aiQuaternion(axis, angle);
|
||||||
} else {
|
} else {
|
||||||
throw DeadlyImportError( "No axis specified for bone rotation in bone ", bone->id);
|
throw DeadlyImportError("No axis specified for bone rotation in bone ", bone->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (currentChildName == nnScale) {
|
} else if (currentChildName == nnScale) {
|
||||||
|
|
|
@ -47,15 +47,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef INCLUDED_AI_X3D_IMPORTER_H
|
#ifndef INCLUDED_AI_X3D_IMPORTER_H
|
||||||
#define INCLUDED_AI_X3D_IMPORTER_H
|
#define INCLUDED_AI_X3D_IMPORTER_H
|
||||||
|
|
||||||
|
|
||||||
// Header files, Assimp.
|
// Header files, Assimp.
|
||||||
#include <assimp/DefaultLogger.hpp>
|
|
||||||
#include <assimp/importerdesc.h>
|
|
||||||
#include <assimp/ProgressHandler.hpp>
|
|
||||||
#include <assimp/types.h>
|
|
||||||
#include <assimp/BaseImporter.h>
|
#include <assimp/BaseImporter.h>
|
||||||
#include <assimp/XmlParser.h>
|
#include <assimp/XmlParser.h>
|
||||||
|
#include <assimp/importerdesc.h>
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
|
#include <assimp/types.h>
|
||||||
|
#include <assimp/DefaultLogger.hpp>
|
||||||
|
#include <assimp/ProgressHandler.hpp>
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
|
@ -102,8 +101,6 @@ inline void LogInfo(const std::string &message) {
|
||||||
DefaultLogger::get()->info(message);
|
DefaultLogger::get()->info(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// \class X3DImporter
|
/// \class X3DImporter
|
||||||
/// Class that holding scene graph which include: groups, geometry, metadata etc.
|
/// Class that holding scene graph which include: groups, geometry, metadata etc.
|
||||||
///
|
///
|
||||||
|
@ -289,16 +286,11 @@ struct X3DNodeElementBase {
|
||||||
X3DElemType Type;
|
X3DElemType Type;
|
||||||
};
|
};
|
||||||
|
|
||||||
class X3DImporter : public BaseImporter
|
class X3DImporter : public BaseImporter {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
std::list<X3DNodeElementBase*> NodeElement_List;///< All elements of scene graph.
|
std::list<X3DNodeElementBase *> NodeElement_List; ///< All elements of scene graph.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/***********************************************/
|
|
||||||
/****************** Functions ******************/
|
|
||||||
/***********************************************/
|
|
||||||
|
|
||||||
/// Default constructor.
|
/// Default constructor.
|
||||||
X3DImporter();
|
X3DImporter();
|
||||||
|
|
||||||
|
@ -313,20 +305,20 @@ public:
|
||||||
/// Also exception can be thrown if trouble will found.
|
/// Also exception can be thrown if trouble will found.
|
||||||
/// \param [in] pFile - name of file to be parsed.
|
/// \param [in] pFile - name of file to be parsed.
|
||||||
/// \param [in] pIOHandler - pointer to IO helper object.
|
/// \param [in] pIOHandler - pointer to IO helper object.
|
||||||
void ParseFile( const std::string& pFile, IOSystem* pIOHandler );
|
void ParseFile(const std::string &pFile, IOSystem *pIOHandler);
|
||||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool pCheckSig ) const;
|
bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool pCheckSig) const;
|
||||||
void GetExtensionList( std::set<std::string>& pExtensionList );
|
void GetExtensionList(std::set<std::string> &pExtensionList);
|
||||||
void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler );
|
void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler);
|
||||||
const aiImporterDesc* GetInfo()const;
|
const aiImporterDesc *GetInfo() const;
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const aiImporterDesc Description;
|
static const aiImporterDesc Description;
|
||||||
X3DNodeElementBase* mNodeElementCur;///< Current element.
|
X3DNodeElementBase *mNodeElementCur; ///< Current element.
|
||||||
XmlParser *mXmlParser;
|
XmlParser *mXmlParser;
|
||||||
IOSystem *mpIOHandler;
|
IOSystem *mpIOHandler;
|
||||||
};// class X3DImporter
|
}; // class X3DImporter
|
||||||
|
|
||||||
}// namespace Assimp
|
} // namespace Assimp
|
||||||
|
|
||||||
#endif // INCLUDED_AI_X3D_IMPORTER_H
|
#endif // INCLUDED_AI_X3D_IMPORTER_H
|
||||||
|
|
Loading…
Reference in New Issue