1/*
2---------------------------------------------------------------------------
3Open Asset Import Library (assimp)
4---------------------------------------------------------------------------
5
6Copyright (c) 2006-2017, assimp team
7
8
9All rights reserved.
10
11Redistribution and use of this software in source and binary forms,
12with or without modification, are permitted provided that the following
13conditions are met:
14
15* Redistributions of source code must retain the above
16 copyright notice, this list of conditions and the
17 following disclaimer.
18
19* Redistributions in binary form must reproduce the above
20 copyright notice, this list of conditions and the
21 following disclaimer in the documentation and/or other
22 materials provided with the distribution.
23
24* Neither the name of the assimp team, nor the names of its
25 contributors may be used to endorse or promote products
26 derived from this software without specific prior
27 written permission of the assimp team.
28
29THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40---------------------------------------------------------------------------
41*/
42
43/** @file AssimpCExport.cpp
44Assimp C export interface. See Exporter.cpp for some notes.
45*/
46
47#ifndef ASSIMP_BUILD_NO_EXPORT
48
49#include "CInterfaceIOWrapper.h"
50#include <assimp/SceneCombiner.h>
51#include "ScenePrivate.h"
52#include <assimp/Exporter.hpp>
53
54using namespace Assimp;
55
56// ------------------------------------------------------------------------------------------------
57ASSIMP_API size_t aiGetExportFormatCount(void)
58{
59 return Exporter().GetExportFormatCount();
60}
61
62
63// ------------------------------------------------------------------------------------------------
64ASSIMP_API const aiExportFormatDesc* aiGetExportFormatDescription( size_t index)
65{
66 // Note: this is valid as the index always pertains to a built-in exporter,
67 // for which the returned structure is guaranteed to be of static storage duration.
68 Exporter exporter;
69 const aiExportFormatDesc* orig( exporter.GetExportFormatDescription( index ) );
70 if (NULL == orig) {
71 return NULL;
72 }
73
74 aiExportFormatDesc *desc = new aiExportFormatDesc;
75 desc->description = new char[ strlen( orig->description ) + 1 ]();
76 ::strncpy( (char*) desc->description, orig->description, strlen( orig->description ) );
77 desc->fileExtension = new char[ strlen( orig->fileExtension ) + 1 ]();
78 ::strncpy( ( char* ) desc->fileExtension, orig->fileExtension, strlen( orig->fileExtension ) );
79 desc->id = new char[ strlen( orig->id ) + 1 ]();
80 ::strncpy( ( char* ) desc->id, orig->id, strlen( orig->id ) );
81
82 return desc;
83}
84
85// ------------------------------------------------------------------------------------------------
86ASSIMP_API void aiReleaseExportFormatDescription( const aiExportFormatDesc *desc ) {
87 if (NULL == desc) {
88 return;
89 }
90
91 delete [] desc->description;
92 delete [] desc->fileExtension;
93 delete [] desc->id;
94 delete desc;
95}
96
97// ------------------------------------------------------------------------------------------------
98ASSIMP_API void aiCopyScene(const aiScene* pIn, aiScene** pOut)
99{
100 if (!pOut || !pIn) {
101 return;
102 }
103
104 SceneCombiner::CopyScene(pOut,pIn,true);
105 ScenePriv(*pOut)->mIsCopy = true;
106}
107
108
109// ------------------------------------------------------------------------------------------------
110ASSIMP_API void aiFreeScene(const C_STRUCT aiScene* pIn)
111{
112 // note: aiReleaseImport() is also able to delete scene copies, but in addition
113 // it also handles scenes with import metadata.
114 delete pIn;
115}
116
117
118// ------------------------------------------------------------------------------------------------
119ASSIMP_API aiReturn aiExportScene( const aiScene* pScene, const char* pFormatId, const char* pFileName, unsigned int pPreprocessing )
120{
121 return ::aiExportSceneEx(pScene,pFormatId,pFileName,NULL,pPreprocessing);
122}
123
124
125// ------------------------------------------------------------------------------------------------
126ASSIMP_API aiReturn aiExportSceneEx( const aiScene* pScene, const char* pFormatId, const char* pFileName, aiFileIO* pIO, unsigned int pPreprocessing )
127{
128 Exporter exp;
129
130 if (pIO) {
131 exp.SetIOHandler(new CIOSystemWrapper(pIO));
132 }
133 return exp.Export(pScene,pFormatId,pFileName,pPreprocessing);
134}
135
136
137// ------------------------------------------------------------------------------------------------
138ASSIMP_API const C_STRUCT aiExportDataBlob* aiExportSceneToBlob( const aiScene* pScene, const char* pFormatId, unsigned int pPreprocessing )
139{
140 Exporter exp;
141 if (!exp.ExportToBlob(pScene,pFormatId,pPreprocessing)) {
142 return NULL;
143 }
144 const aiExportDataBlob* blob = exp.GetOrphanedBlob();
145 ai_assert(blob);
146
147 return blob;
148}
149
150// ------------------------------------------------------------------------------------------------
151ASSIMP_API C_STRUCT void aiReleaseExportBlob( const aiExportDataBlob* pData )
152{
153 delete pData;
154}
155
156#endif // !ASSIMP_BUILD_NO_EXPORT
157