Coverage Report

Created: 2025-06-22 07:30

/src/assimp/code/AssetLib/FBX/FBXExporter.h
Line
Count
Source
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
/** @file FBXExporter.h
43
* Declares the exporter class to write a scene to an fbx file
44
*/
45
#ifndef AI_FBXEXPORTER_H_INC
46
#define AI_FBXEXPORTER_H_INC
47
48
#ifndef ASSIMP_BUILD_NO_FBX_EXPORTER
49
50
#include "FBXExportNode.h" // FBX::Node
51
#include "FBXCommon.h" // FBX::TransformInheritance
52
53
#include <assimp/types.h>
54
#include <assimp/StreamWriter.h> // StreamWriterLE
55
#include <assimp/Exceptional.h> // DeadlyExportError
56
57
#include <vector>
58
#include <map>
59
#include <unordered_set>
60
#include <memory> // shared_ptr
61
#include <sstream> // stringstream
62
63
struct aiScene;
64
struct aiNode;
65
struct aiLight;
66
67
namespace Assimp {
68
    class IOSystem;
69
    class IOStream;
70
    class ExportProperties;
71
72
    // ---------------------------------------------------------------------
73
    /** Helper class to export a given scene to an FBX file. */
74
    // ---------------------------------------------------------------------
75
    class FBXExporter
76
    {
77
    public:
78
        /// Constructor for a specific scene to export
79
        FBXExporter(const aiScene* pScene, const ExportProperties* pProperties);
80
81
        // call one of these methods to export
82
        void ExportBinary(const char* pFile, IOSystem* pIOSystem);
83
        void ExportAscii(const char* pFile, IOSystem* pIOSystem);
84
85
    private:
86
        bool binary; // whether current export is in binary or ascii format
87
        const aiScene* mScene; // the scene to export
88
        const ExportProperties* mProperties; // currently unused
89
        std::shared_ptr<IOStream> outfile; // file to write to
90
91
        std::vector<FBX::Node> connections; // connection storage
92
93
        std::map<const aiNode*, int64_t> mesh_uids;
94
        std::vector<int64_t> blendshape_uids;
95
        std::vector<int64_t> material_uids;
96
        std::map<const aiNode*,int64_t> node_uids;
97
        std::map<std::string,int64_t> lights_uids;
98
99
        // this crude unique-ID system is actually fine
100
        int64_t last_uid = 999999;
101
62.6k
        int64_t generate_uid() { return ++last_uid; }
102
103
        // binary files have a specific header and footer,
104
        // in addition to the actual data
105
        void WriteBinaryHeader();
106
        void WriteBinaryFooter();
107
108
        // ascii files have a comment at the top
109
        void WriteAsciiHeader();
110
111
        // WriteAllNodes does the actual export.
112
        // It just calls all the Write<Section> methods below in order.
113
        void WriteAllNodes();
114
115
        // Methods to write individual sections.
116
        // The order here matches the order inside an FBX file.
117
        // Each method corresponds to a top-level FBX section,
118
        // except WriteHeader which also includes some binary-only sections
119
        // and WriteFooter which is binary data only.
120
        void WriteHeaderExtension();
121
        // WriteFileId(); // binary-only, included in WriteHeader
122
        // WriteCreationTime(); // binary-only, included in WriteHeader
123
        // WriteCreator(); // binary-only, included in WriteHeader
124
        void WriteGlobalSettings();
125
        void WriteDocuments();
126
        void WriteReferences();
127
        void WriteDefinitions();
128
        void WriteObjects();
129
        void WriteConnections();
130
        // WriteTakes(); // deprecated since at least 2015 (fbx 7.4)
131
132
        // helpers
133
        void WriteAsciiSectionHeader(const std::string& title);
134
        void WriteModelNodes(
135
            Assimp::StreamWriterLE& s,
136
            const aiNode* node,
137
            int64_t parent_uid,
138
            const std::unordered_set<const aiNode*>& limbnodes
139
        );
140
        void WriteModelNodes( // usually don't call this directly
141
            StreamWriterLE& s,
142
            const aiNode* node,
143
            int64_t parent_uid,
144
            const std::unordered_set<const aiNode*>& limbnodes,
145
            std::vector<std::pair<std::string,aiVector3D>>& transform_chain
146
        );
147
        void WriteModelNode( // nor this
148
            StreamWriterLE& s,
149
            bool binary,
150
            const aiNode* node,
151
            int64_t node_uid,
152
            const std::string& type,
153
            const std::vector<std::pair<std::string,aiVector3D>>& xfm_chain,
154
            FBX::TransformInheritance ti_type=FBX::TransformInheritance_RSrs
155
        );
156
        void WriteAnimationCurveNode(
157
                StreamWriterLE &outstream,
158
                int64_t uid,
159
                const std::string &name, // "T", "R", or "S"
160
                aiVector3D default_value,
161
                const std::string &property_name, // "Lcl Translation" etc
162
                int64_t animation_layer_uid,
163
                int64_t node_uid);
164
        void WriteAnimationCurve(
165
            StreamWriterLE& outstream,
166
            double default_value,
167
            const std::vector<int64_t>& times,
168
            const std::vector<float>& values,
169
            int64_t curvenode_id,
170
            const std::string& property_link // "d|X", "d|Y", etc
171
        );
172
    };
173
}
174
175
#endif // ASSIMP_BUILD_NO_FBX_EXPORTER
176
177
#endif // AI_FBXEXPORTER_H_INC