/src/assimp/code/AssetLib/3MF/D3MFImporter.cpp
Line | Count | Source |
1 | | /* |
2 | | Open Asset Import Library (assimp) |
3 | | ---------------------------------------------------------------------- |
4 | | |
5 | | Copyright (c) 2006-2026, 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_3MF_IMPORTER |
43 | | |
44 | | #include "D3MFImporter.h" |
45 | | #include "3MFXmlTags.h" |
46 | | #include "D3MFOpcPackage.h" |
47 | | #include "XmlSerializer.h" |
48 | | |
49 | | #include <assimp/StringComparison.h> |
50 | | #include <assimp/StringUtils.h> |
51 | | #include <assimp/XmlParser.h> |
52 | | #include <assimp/ZipArchiveIOSystem.h> |
53 | | #include <assimp/importerdesc.h> |
54 | | #include <assimp/scene.h> |
55 | | #include <assimp/DefaultLogger.hpp> |
56 | | #include <assimp/IOSystem.hpp> |
57 | | #include <assimp/fast_atof.h> |
58 | | |
59 | | #include <cassert> |
60 | | #include <map> |
61 | | #include <memory> |
62 | | #include <string> |
63 | | #include <vector> |
64 | | #include <iomanip> |
65 | | #include <cstring> |
66 | | |
67 | | namespace Assimp { |
68 | | |
69 | | using namespace D3MF; |
70 | | |
71 | | static constexpr aiImporterDesc desc = { |
72 | | "3mf Importer", |
73 | | "", |
74 | | "", |
75 | | "http://3mf.io/", |
76 | | aiImporterFlags_SupportBinaryFlavour | aiImporterFlags_SupportCompressedFlavour, |
77 | | 0, |
78 | | 0, |
79 | | 0, |
80 | | 0, |
81 | | "3mf" |
82 | | }; |
83 | | |
84 | 51 | bool D3MFImporter::CanRead(const std::string &filename, IOSystem *pIOHandler, bool ) const { |
85 | 51 | if (!ZipArchiveIOSystem::isZipArchive(pIOHandler, filename)) { |
86 | 44 | return false; |
87 | 44 | } |
88 | 7 | static constexpr char ModelRef[] = "3D/3dmodel.model"; |
89 | 7 | ZipArchiveIOSystem archive(pIOHandler, filename); |
90 | 7 | if (!archive.Exists(ModelRef)) { |
91 | 7 | return false; |
92 | 7 | } |
93 | | |
94 | 0 | return true; |
95 | 7 | } |
96 | | |
97 | 0 | void D3MFImporter::SetupProperties(const Importer*) { |
98 | | // empty |
99 | 0 | } |
100 | | |
101 | 26.1k | const aiImporterDesc *D3MFImporter::GetInfo() const { |
102 | 26.1k | return &desc; |
103 | 26.1k | } |
104 | | |
105 | 0 | void D3MFImporter::InternReadFile(const std::string &filename, aiScene *pScene, IOSystem *pIOHandler) { |
106 | 0 | D3MFOpcPackage opcPackage(pIOHandler, filename); |
107 | |
|
108 | 0 | XmlParser xmlParser; |
109 | 0 | if (xmlParser.parse(opcPackage.RootStream())) { |
110 | 0 | XmlSerializer xmlSerializer(xmlParser); |
111 | 0 | xmlSerializer.ImportXml(pScene); |
112 | |
|
113 | 0 | const std::vector<aiTexture*> &tex = opcPackage.GetEmbeddedTextures(); |
114 | 0 | if (!tex.empty()) { |
115 | 0 | pScene->mNumTextures = static_cast<unsigned int>(tex.size()); |
116 | 0 | pScene->mTextures = new aiTexture *[pScene->mNumTextures]; |
117 | 0 | for (unsigned int i = 0; i < pScene->mNumTextures; ++i) { |
118 | 0 | pScene->mTextures[i] = tex[i]; |
119 | 0 | } |
120 | 0 | } |
121 | 0 | } |
122 | 0 | } |
123 | | |
124 | | } // Namespace Assimp |
125 | | |
126 | | #endif // ASSIMP_BUILD_NO_3MF_IMPORTER |