/src/assimp/code/AssetLib/X/XFileExporter.h
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 | | @author: Richard Steffen, 2014 |
40 | | |
41 | | ---------------------------------------------------------------------- |
42 | | */ |
43 | | |
44 | | /** @file XFileExporter.h |
45 | | * Declares the exporter class to write a scene to a Collada file |
46 | | */ |
47 | | #ifndef AI_XFILEEXPORTER_H_INC |
48 | | #define AI_XFILEEXPORTER_H_INC |
49 | | |
50 | | #include <assimp/ai_assert.h> |
51 | | #include <assimp/matrix4x4.h> |
52 | | #include <assimp/Exporter.hpp> |
53 | | #include <sstream> |
54 | | |
55 | | struct aiScene; |
56 | | struct aiNode; |
57 | | struct aiMesh; |
58 | | struct aiString; |
59 | | |
60 | | namespace Assimp { |
61 | | |
62 | | class IOSystem; |
63 | | |
64 | | |
65 | | /// Helper class to export a given scene to a X-file. |
66 | | /// Note: an xFile uses a left hand system. Assimp used a right hand system (OpenGL), therefore we have to transform everything |
67 | | class XFileExporter |
68 | | { |
69 | | public: |
70 | | /// Constructor for a specific scene to export |
71 | | XFileExporter(const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file, const ExportProperties* pProperties); |
72 | | |
73 | | /// Destructor |
74 | | virtual ~XFileExporter(); |
75 | | |
76 | | protected: |
77 | | /// Starts writing the contents |
78 | | void WriteFile(); |
79 | | |
80 | | /// Writes the asset header |
81 | | void WriteHeader(); |
82 | | |
83 | | /// write a frame transform |
84 | | void WriteFrameTransform(aiMatrix4x4& m); |
85 | | |
86 | | /// Recursively writes the given node |
87 | | void WriteNode( aiNode* pNode ); |
88 | | |
89 | | /// write a mesh entry of the scene |
90 | | void WriteMesh( aiMesh* mesh); |
91 | | |
92 | | /// Enters a new xml element, which increases the indentation |
93 | 0 | void PushTag() { startstr.append( " "); } |
94 | | |
95 | | /// Leaves an element, decreasing the indentation |
96 | 0 | void PopTag() { |
97 | 0 | ai_assert( startstr.length() > 1); |
98 | 0 | startstr.erase( startstr.length() - 2); |
99 | 0 | } |
100 | | |
101 | | public: |
102 | | /// Stringstream to write all output into |
103 | | std::stringstream mOutput; |
104 | | |
105 | | protected: |
106 | | |
107 | | /// normalize the name to be accepted by xfile readers |
108 | | std::string toXFileString(aiString &name); |
109 | | |
110 | | /// hold the properties pointer |
111 | | const ExportProperties* mProperties; |
112 | | |
113 | | /// write a path |
114 | | void writePath(const aiString &path); |
115 | | |
116 | | /// The IOSystem for output |
117 | | IOSystem* mIOSystem; |
118 | | |
119 | | /// Path of the directory where the scene will be exported |
120 | | const std::string mPath; |
121 | | |
122 | | /// Name of the file (without extension) where the scene will be exported |
123 | | const std::string mFile; |
124 | | |
125 | | /// The scene to be written |
126 | | const aiScene* mScene; |
127 | | bool mSceneOwned; |
128 | | |
129 | | /// current line start string, contains the current indentation for simple stream insertion |
130 | | std::string startstr; |
131 | | |
132 | | /// current line end string for simple stream insertion |
133 | | std::string endstr; |
134 | | |
135 | | }; |
136 | | |
137 | | } |
138 | | |
139 | | #endif // !! AI_XFILEEXPORTER_H_INC |