/src/assimp/code/AssetLib/3DS/3DSExporter.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 | | ---------------------------------------------------------------------- |
40 | | */ |
41 | | |
42 | | /** @file 3DSExporter.h |
43 | | * 3DS Exporter Main Header |
44 | | */ |
45 | | #ifndef AI_3DSEXPORTER_H_INC |
46 | | #define AI_3DSEXPORTER_H_INC |
47 | | |
48 | | #include <map> |
49 | | #include <memory> |
50 | | |
51 | | #include <assimp/StreamWriter.h> |
52 | | #include <assimp/material.h> |
53 | | |
54 | | struct aiScene; |
55 | | struct aiNode; |
56 | | struct aiMaterial; |
57 | | struct aiMesh; |
58 | | |
59 | | namespace Assimp { |
60 | | |
61 | | // ------------------------------------------------------------------------------------------------ |
62 | | /** |
63 | | * @brief Helper class to export a given scene to a 3DS file. |
64 | | */ |
65 | | // ------------------------------------------------------------------------------------------------ |
66 | | class Discreet3DSExporter final { |
67 | | public: |
68 | | /// Constructor for a specific scene to export |
69 | | /// @param outfile Output file stream |
70 | | /// @param pScene Scene to export |
71 | | Discreet3DSExporter(std::shared_ptr<IOStream> &outfile, const aiScene* pScene); |
72 | | |
73 | | /// Destructor |
74 | 1.81k | ~Discreet3DSExporter() = default; |
75 | | |
76 | | private: |
77 | | /// Writes all meshes in the scene to the output file |
78 | | void WriteMeshes(); |
79 | | |
80 | | /// Writes all materials in the scene to the output file |
81 | | void WriteMaterials(); |
82 | | |
83 | | /// Writes texture information for a material |
84 | | /// @param mat Material to write texture for |
85 | | /// @param type Texture type (e.g., aiTextureType_DIFFUSE) |
86 | | /// @param chunk_flags 3DS chunk flags for the texture |
87 | | /// @return true if texture was written successfully, false otherwise |
88 | | bool WriteTexture(const aiMaterial& mat, aiTextureType type, uint16_t chunk_flags); |
89 | | |
90 | | /// Writes face material chunk for a mesh |
91 | | /// @param mesh Mesh to write face material for |
92 | | void WriteFaceMaterialChunk(const aiMesh& mesh); |
93 | | |
94 | | /// Writes the node hierarchy to the output file |
95 | | /// @param node Current node to process |
96 | | /// @param level Current hierarchy level |
97 | | /// @param sibling_level Sibling level for hierarchy tracking |
98 | | /// @return Next sequence number for hierarchy |
99 | | int WriteHierarchy(const aiNode& node, int level, int sibling_level); |
100 | | |
101 | | /// Writes a string to the output stream |
102 | | /// @param s String to write |
103 | | void WriteString(const std::string& s); |
104 | | |
105 | | /// Writes an aiString to the output stream |
106 | | /// @param s aiString to write |
107 | | void WriteString(const aiString& s); |
108 | | |
109 | | /// Writes a color to the output stream |
110 | | /// @param color Color to write |
111 | | void WriteColor(const aiColor3D& color); |
112 | | |
113 | | /// Writes a percentage value as float to the output stream |
114 | | /// @param f Percentage value to write |
115 | | void WritePercentChunk(float f); |
116 | | |
117 | | /// Writes a percentage value as double to the output stream |
118 | | /// @param f Percentage value to write |
119 | | void WritePercentChunk(double f); |
120 | | |
121 | | private: |
122 | | /// The scene to be exported |
123 | | const aiScene* const scene; |
124 | | |
125 | | /// Stream writer for output |
126 | | StreamWriterLE writer; |
127 | | |
128 | | /// World transformations for each node |
129 | | std::map<const aiNode*, aiMatrix4x4> trafos; |
130 | | |
131 | | /// Meshes organized by node |
132 | | using MeshesByNodeMap = std::multimap<const aiNode*, unsigned int>; |
133 | | MeshesByNodeMap meshes; |
134 | | }; |
135 | | |
136 | | } // Namespace Assimp |
137 | | |
138 | | #endif // AI_3DSEXPORTER_H_INC |