You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OgreImporter.cpp 4.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2012, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. #ifndef ASSIMP_BUILD_NO_OGRE_IMPORTER
  34. #include "AssimpPCH.h"
  35. #include "OgreImporter.h"
  36. #include "OgreBinarySerializer.h"
  37. #include "OgreXmlSerializer.h"
  38. static const aiImporterDesc desc = {
  39. "Ogre3D Mesh Importer",
  40. "",
  41. "",
  42. "",
  43. aiImporterFlags_SupportTextFlavour | aiImporterFlags_SupportBinaryFlavour,
  44. 0,
  45. 0,
  46. 0,
  47. 0,
  48. "mesh mesh.xml"
  49. };
  50. namespace Assimp
  51. {
  52. namespace Ogre
  53. {
  54. const aiImporterDesc* OgreImporter::GetInfo() const
  55. {
  56. return &desc;
  57. }
  58. void OgreImporter::SetupProperties(const Importer* pImp)
  59. {
  60. m_userDefinedMaterialLibFile = pImp->GetPropertyString(AI_CONFIG_IMPORT_OGRE_MATERIAL_FILE, "Scene.material");
  61. m_detectTextureTypeFromFilename = pImp->GetPropertyBool(AI_CONFIG_IMPORT_OGRE_TEXTURETYPE_FROM_FILENAME, false);
  62. }
  63. bool OgreImporter::CanRead(const std::string &pFile, Assimp::IOSystem *pIOHandler, bool checkSig) const
  64. {
  65. if (!checkSig) {
  66. return EndsWith(pFile, ".mesh.xml", false) || EndsWith(pFile, ".mesh", false);
  67. }
  68. if (EndsWith(pFile, ".mesh.xml", false))
  69. {
  70. const char* tokens[] = { "<mesh>" };
  71. return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
  72. }
  73. else
  74. {
  75. /// @todo Read and validate first header chunk?
  76. return EndsWith(pFile, ".mesh", false);
  77. }
  78. }
  79. void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Assimp::IOSystem *pIOHandler)
  80. {
  81. // Open source file
  82. IOStream *f = pIOHandler->Open(pFile, "rb");
  83. if (!f) {
  84. throw DeadlyImportError("Failed to open file " + pFile);
  85. }
  86. // Binary .mesh import
  87. if (EndsWith(pFile, ".mesh", false))
  88. {
  89. /// @note MemoryStreamReader takes ownership of f.
  90. MemoryStreamReader reader(f);
  91. // Import mesh
  92. boost::scoped_ptr<Mesh> mesh(OgreBinarySerializer::ImportMesh(&reader));
  93. // Import skeleton
  94. OgreBinarySerializer::ImportSkeleton(pIOHandler, mesh.get());
  95. // Import mesh referenced materials
  96. ReadMaterials(pFile, pIOHandler, pScene, mesh.get());
  97. // Convert to Assimp
  98. mesh->ConvertToAssimpScene(pScene);
  99. }
  100. // XML .mesh.xml import
  101. else
  102. {
  103. /// @note XmlReader does not take ownership of f, hence the scoped ptr.
  104. boost::scoped_ptr<IOStream> scopedFile(f);
  105. boost::scoped_ptr<CIrrXML_IOStreamReader> xmlStream(new CIrrXML_IOStreamReader(scopedFile.get()));
  106. boost::scoped_ptr<XmlReader> reader(irr::io::createIrrXMLReader(xmlStream.get()));
  107. // Import mesh
  108. boost::scoped_ptr<MeshXml> mesh(OgreXmlSerializer::ImportMesh(reader.get()));
  109. // Import skeleton
  110. OgreXmlSerializer::ImportSkeleton(pIOHandler, mesh.get());
  111. // Import mesh referenced materials
  112. ReadMaterials(pFile, pIOHandler, pScene, mesh.get());
  113. // Convert to Assimp
  114. mesh->ConvertToAssimpScene(pScene);
  115. }
  116. }
  117. } // Ogre
  118. } // Assimp
  119. #endif // ASSIMP_BUILD_NO_OGRE_IMPORTER