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