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