rev |
line source |
nuclear@0
|
1 /*
|
nuclear@0
|
2 ---------------------------------------------------------------------------
|
nuclear@0
|
3 Open Asset Import Library (assimp)
|
nuclear@0
|
4 ---------------------------------------------------------------------------
|
nuclear@0
|
5
|
nuclear@0
|
6 Copyright (c) 2006-2012, assimp team
|
nuclear@0
|
7
|
nuclear@0
|
8 All rights reserved.
|
nuclear@0
|
9
|
nuclear@0
|
10 Redistribution and use of this software in source and binary forms,
|
nuclear@0
|
11 with or without modification, are permitted provided that the following
|
nuclear@0
|
12 conditions are met:
|
nuclear@0
|
13
|
nuclear@0
|
14 * Redistributions of source code must retain the above
|
nuclear@0
|
15 copyright notice, this list of conditions and the
|
nuclear@0
|
16 following disclaimer.
|
nuclear@0
|
17
|
nuclear@0
|
18 * Redistributions in binary form must reproduce the above
|
nuclear@0
|
19 copyright notice, this list of conditions and the
|
nuclear@0
|
20 following disclaimer in the documentation and/or other
|
nuclear@0
|
21 materials provided with the distribution.
|
nuclear@0
|
22
|
nuclear@0
|
23 * Neither the name of the assimp team, nor the names of its
|
nuclear@0
|
24 contributors may be used to endorse or promote products
|
nuclear@0
|
25 derived from this software without specific prior
|
nuclear@0
|
26 written permission of the assimp team.
|
nuclear@0
|
27
|
nuclear@0
|
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
nuclear@0
|
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
nuclear@0
|
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
nuclear@0
|
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
nuclear@0
|
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
nuclear@0
|
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
nuclear@0
|
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
nuclear@0
|
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
nuclear@0
|
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
nuclear@0
|
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
nuclear@0
|
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
nuclear@0
|
39 ---------------------------------------------------------------------------
|
nuclear@0
|
40 */
|
nuclear@0
|
41 /** @file Assimp.cpp
|
nuclear@0
|
42 * @brief Implementation of the Plain-C API
|
nuclear@0
|
43 */
|
nuclear@0
|
44
|
nuclear@0
|
45 #include "AssimpPCH.h"
|
nuclear@0
|
46 #include "assimp/cimport.h"
|
nuclear@0
|
47
|
nuclear@0
|
48 #include "GenericProperty.h"
|
nuclear@0
|
49 #include "CInterfaceIOWrapper.h"
|
nuclear@0
|
50 #include "Importer.h"
|
nuclear@0
|
51
|
nuclear@0
|
52 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
53 #ifdef AI_C_THREADSAFE
|
nuclear@0
|
54 # include <boost/thread/thread.hpp>
|
nuclear@0
|
55 # include <boost/thread/mutex.hpp>
|
nuclear@0
|
56 #endif
|
nuclear@0
|
57 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
58 using namespace Assimp;
|
nuclear@0
|
59
|
nuclear@0
|
60 namespace Assimp
|
nuclear@0
|
61 {
|
nuclear@0
|
62 // underlying structure for aiPropertyStore
|
nuclear@0
|
63 typedef BatchLoader::PropertyMap PropertyMap;
|
nuclear@0
|
64
|
nuclear@0
|
65 /** Stores the LogStream objects for all active C log streams */
|
nuclear@0
|
66 struct mpred {
|
nuclear@0
|
67 bool operator () (const aiLogStream& s0, const aiLogStream& s1) const {
|
nuclear@0
|
68 return s0.callback<s1.callback&&s0.user<s1.user;
|
nuclear@0
|
69 }
|
nuclear@0
|
70 };
|
nuclear@0
|
71 typedef std::map<aiLogStream, Assimp::LogStream*, mpred> LogStreamMap;
|
nuclear@0
|
72
|
nuclear@0
|
73 /** Stores the LogStream objects allocated by #aiGetPredefinedLogStream */
|
nuclear@0
|
74 typedef std::list<Assimp::LogStream*> PredefLogStreamMap;
|
nuclear@0
|
75
|
nuclear@0
|
76 /** Local storage of all active log streams */
|
nuclear@0
|
77 static LogStreamMap gActiveLogStreams;
|
nuclear@0
|
78
|
nuclear@0
|
79 /** Local storage of LogStreams allocated by #aiGetPredefinedLogStream */
|
nuclear@0
|
80 static PredefLogStreamMap gPredefinedStreams;
|
nuclear@0
|
81
|
nuclear@0
|
82 /** Error message of the last failed import process */
|
nuclear@0
|
83 static std::string gLastErrorString;
|
nuclear@0
|
84
|
nuclear@0
|
85 /** Verbose logging active or not? */
|
nuclear@0
|
86 static aiBool gVerboseLogging = false;
|
nuclear@0
|
87 }
|
nuclear@0
|
88
|
nuclear@0
|
89
|
nuclear@0
|
90 #ifdef AI_C_THREADSAFE
|
nuclear@0
|
91 /** Global mutex to manage the access to the logstream map */
|
nuclear@0
|
92 static boost::mutex gLogStreamMutex;
|
nuclear@0
|
93 #endif
|
nuclear@0
|
94
|
nuclear@0
|
95
|
nuclear@0
|
96 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
97 // Custom LogStream implementation for the C-API
|
nuclear@0
|
98 class LogToCallbackRedirector : public LogStream
|
nuclear@0
|
99 {
|
nuclear@0
|
100 public:
|
nuclear@0
|
101 LogToCallbackRedirector(const aiLogStream& s)
|
nuclear@0
|
102 : stream (s) {
|
nuclear@0
|
103 ai_assert(NULL != s.callback);
|
nuclear@0
|
104 }
|
nuclear@0
|
105
|
nuclear@0
|
106 ~LogToCallbackRedirector() {
|
nuclear@0
|
107 #ifdef AI_C_THREADSAFE
|
nuclear@0
|
108 boost::mutex::scoped_lock lock(gLogStreamMutex);
|
nuclear@0
|
109 #endif
|
nuclear@0
|
110 // (HACK) Check whether the 'stream.user' pointer points to a
|
nuclear@0
|
111 // custom LogStream allocated by #aiGetPredefinedLogStream.
|
nuclear@0
|
112 // In this case, we need to delete it, too. Of course, this
|
nuclear@0
|
113 // might cause strange problems, but the chance is quite low.
|
nuclear@0
|
114
|
nuclear@0
|
115 PredefLogStreamMap::iterator it = std::find(gPredefinedStreams.begin(),
|
nuclear@0
|
116 gPredefinedStreams.end(), (Assimp::LogStream*)stream.user);
|
nuclear@0
|
117
|
nuclear@0
|
118 if (it != gPredefinedStreams.end()) {
|
nuclear@0
|
119 delete *it;
|
nuclear@0
|
120 gPredefinedStreams.erase(it);
|
nuclear@0
|
121 }
|
nuclear@0
|
122 }
|
nuclear@0
|
123
|
nuclear@0
|
124 /** @copydoc LogStream::write */
|
nuclear@0
|
125 void write(const char* message) {
|
nuclear@0
|
126 stream.callback(message,stream.user);
|
nuclear@0
|
127 }
|
nuclear@0
|
128
|
nuclear@0
|
129 private:
|
nuclear@0
|
130 aiLogStream stream;
|
nuclear@0
|
131 };
|
nuclear@0
|
132
|
nuclear@0
|
133 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
134 void ReportSceneNotFoundError()
|
nuclear@0
|
135 {
|
nuclear@0
|
136 DefaultLogger::get()->error("Unable to find the Assimp::Importer for this aiScene. "
|
nuclear@0
|
137 "The C-API does not accept scenes produced by the C++ API and vice versa");
|
nuclear@0
|
138
|
nuclear@0
|
139 assert(false);
|
nuclear@0
|
140 }
|
nuclear@0
|
141
|
nuclear@0
|
142 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
143 // Reads the given file and returns its content.
|
nuclear@0
|
144 const aiScene* aiImportFile( const char* pFile, unsigned int pFlags)
|
nuclear@0
|
145 {
|
nuclear@0
|
146 return aiImportFileEx(pFile,pFlags,NULL);
|
nuclear@0
|
147 }
|
nuclear@0
|
148
|
nuclear@0
|
149 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
150 const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags, aiFileIO* pFS)
|
nuclear@0
|
151 {
|
nuclear@0
|
152 return aiImportFileExWithProperties(pFile, pFlags, pFS, NULL);
|
nuclear@0
|
153 }
|
nuclear@0
|
154
|
nuclear@0
|
155 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
156 const aiScene* aiImportFileExWithProperties( const char* pFile, unsigned int pFlags,
|
nuclear@0
|
157 aiFileIO* pFS,
|
nuclear@0
|
158 const aiPropertyStore* props)
|
nuclear@0
|
159 {
|
nuclear@0
|
160 ai_assert(NULL != pFile);
|
nuclear@0
|
161
|
nuclear@0
|
162 const aiScene* scene = NULL;
|
nuclear@0
|
163 ASSIMP_BEGIN_EXCEPTION_REGION();
|
nuclear@0
|
164
|
nuclear@0
|
165 // create an Importer for this file
|
nuclear@0
|
166 Assimp::Importer* imp = new Assimp::Importer();
|
nuclear@0
|
167
|
nuclear@0
|
168 // copy properties
|
nuclear@0
|
169 if(props) {
|
nuclear@0
|
170 const PropertyMap* pp = reinterpret_cast<const PropertyMap*>(props);
|
nuclear@0
|
171 ImporterPimpl* pimpl = imp->Pimpl();
|
nuclear@0
|
172 pimpl->mIntProperties = pp->ints;
|
nuclear@0
|
173 pimpl->mFloatProperties = pp->floats;
|
nuclear@0
|
174 pimpl->mStringProperties = pp->strings;
|
nuclear@0
|
175 }
|
nuclear@0
|
176 // setup a custom IO system if necessary
|
nuclear@0
|
177 if (pFS) {
|
nuclear@0
|
178 imp->SetIOHandler( new CIOSystemWrapper (pFS) );
|
nuclear@0
|
179 }
|
nuclear@0
|
180
|
nuclear@0
|
181 // and have it read the file
|
nuclear@0
|
182 scene = imp->ReadFile( pFile, pFlags);
|
nuclear@0
|
183
|
nuclear@0
|
184 // if succeeded, store the importer in the scene and keep it alive
|
nuclear@0
|
185 if( scene) {
|
nuclear@0
|
186 ScenePrivateData* priv = const_cast<ScenePrivateData*>( ScenePriv(scene) );
|
nuclear@0
|
187 priv->mOrigImporter = imp;
|
nuclear@0
|
188 }
|
nuclear@0
|
189 else {
|
nuclear@0
|
190 // if failed, extract error code and destroy the import
|
nuclear@0
|
191 gLastErrorString = imp->GetErrorString();
|
nuclear@0
|
192 delete imp;
|
nuclear@0
|
193 }
|
nuclear@0
|
194
|
nuclear@0
|
195 // return imported data. If the import failed the pointer is NULL anyways
|
nuclear@0
|
196 ASSIMP_END_EXCEPTION_REGION(const aiScene*);
|
nuclear@0
|
197 return scene;
|
nuclear@0
|
198 }
|
nuclear@0
|
199
|
nuclear@0
|
200 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
201 const aiScene* aiImportFileFromMemory(
|
nuclear@0
|
202 const char* pBuffer,
|
nuclear@0
|
203 unsigned int pLength,
|
nuclear@0
|
204 unsigned int pFlags,
|
nuclear@0
|
205 const char* pHint)
|
nuclear@0
|
206 {
|
nuclear@0
|
207 return aiImportFileFromMemoryWithProperties(pBuffer, pLength, pFlags, pHint, NULL);
|
nuclear@0
|
208 }
|
nuclear@0
|
209
|
nuclear@0
|
210 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
211 const aiScene* aiImportFileFromMemoryWithProperties(
|
nuclear@0
|
212 const char* pBuffer,
|
nuclear@0
|
213 unsigned int pLength,
|
nuclear@0
|
214 unsigned int pFlags,
|
nuclear@0
|
215 const char* pHint,
|
nuclear@0
|
216 const aiPropertyStore* props)
|
nuclear@0
|
217 {
|
nuclear@0
|
218 ai_assert(NULL != pBuffer && 0 != pLength);
|
nuclear@0
|
219
|
nuclear@0
|
220 const aiScene* scene = NULL;
|
nuclear@0
|
221 ASSIMP_BEGIN_EXCEPTION_REGION();
|
nuclear@0
|
222
|
nuclear@0
|
223 // create an Importer for this file
|
nuclear@0
|
224 Assimp::Importer* imp = new Assimp::Importer();
|
nuclear@0
|
225
|
nuclear@0
|
226 // copy properties
|
nuclear@0
|
227 if(props) {
|
nuclear@0
|
228 const PropertyMap* pp = reinterpret_cast<const PropertyMap*>(props);
|
nuclear@0
|
229 ImporterPimpl* pimpl = imp->Pimpl();
|
nuclear@0
|
230 pimpl->mIntProperties = pp->ints;
|
nuclear@0
|
231 pimpl->mFloatProperties = pp->floats;
|
nuclear@0
|
232 pimpl->mStringProperties = pp->strings;
|
nuclear@0
|
233 }
|
nuclear@0
|
234
|
nuclear@0
|
235 // and have it read the file from the memory buffer
|
nuclear@0
|
236 scene = imp->ReadFileFromMemory( pBuffer, pLength, pFlags,pHint);
|
nuclear@0
|
237
|
nuclear@0
|
238 // if succeeded, store the importer in the scene and keep it alive
|
nuclear@0
|
239 if( scene) {
|
nuclear@0
|
240 ScenePrivateData* priv = const_cast<ScenePrivateData*>( ScenePriv(scene) );
|
nuclear@0
|
241 priv->mOrigImporter = imp;
|
nuclear@0
|
242 }
|
nuclear@0
|
243 else {
|
nuclear@0
|
244 // if failed, extract error code and destroy the import
|
nuclear@0
|
245 gLastErrorString = imp->GetErrorString();
|
nuclear@0
|
246 delete imp;
|
nuclear@0
|
247 }
|
nuclear@0
|
248 // return imported data. If the import failed the pointer is NULL anyways
|
nuclear@0
|
249 ASSIMP_END_EXCEPTION_REGION(const aiScene*);
|
nuclear@0
|
250 return scene;
|
nuclear@0
|
251 }
|
nuclear@0
|
252
|
nuclear@0
|
253 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
254 // Releases all resources associated with the given import process.
|
nuclear@0
|
255 void aiReleaseImport( const aiScene* pScene)
|
nuclear@0
|
256 {
|
nuclear@0
|
257 if (!pScene) {
|
nuclear@0
|
258 return;
|
nuclear@0
|
259 }
|
nuclear@0
|
260
|
nuclear@0
|
261 ASSIMP_BEGIN_EXCEPTION_REGION();
|
nuclear@0
|
262
|
nuclear@0
|
263 // find the importer associated with this data
|
nuclear@0
|
264 const ScenePrivateData* priv = ScenePriv(pScene);
|
nuclear@0
|
265 if( !priv || !priv->mOrigImporter) {
|
nuclear@0
|
266 delete pScene;
|
nuclear@0
|
267 }
|
nuclear@0
|
268 else {
|
nuclear@0
|
269 // deleting the Importer also deletes the scene
|
nuclear@0
|
270 // Note: the reason that this is not written as 'delete priv->mOrigImporter'
|
nuclear@0
|
271 // is a suspected bug in gcc 4.4+ (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52339)
|
nuclear@0
|
272 Importer* importer = priv->mOrigImporter;
|
nuclear@0
|
273 delete importer;
|
nuclear@0
|
274 }
|
nuclear@0
|
275
|
nuclear@0
|
276 ASSIMP_END_EXCEPTION_REGION(void);
|
nuclear@0
|
277 }
|
nuclear@0
|
278
|
nuclear@0
|
279 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
280 ASSIMP_API const aiScene* aiApplyPostProcessing(const aiScene* pScene,
|
nuclear@0
|
281 unsigned int pFlags)
|
nuclear@0
|
282 {
|
nuclear@0
|
283 const aiScene* sc = NULL;
|
nuclear@0
|
284
|
nuclear@0
|
285
|
nuclear@0
|
286 ASSIMP_BEGIN_EXCEPTION_REGION();
|
nuclear@0
|
287
|
nuclear@0
|
288 // find the importer associated with this data
|
nuclear@0
|
289 const ScenePrivateData* priv = ScenePriv(pScene);
|
nuclear@0
|
290 if( !priv || !priv->mOrigImporter) {
|
nuclear@0
|
291 ReportSceneNotFoundError();
|
nuclear@0
|
292 return NULL;
|
nuclear@0
|
293 }
|
nuclear@0
|
294
|
nuclear@0
|
295 sc = priv->mOrigImporter->ApplyPostProcessing(pFlags);
|
nuclear@0
|
296
|
nuclear@0
|
297 if (!sc) {
|
nuclear@0
|
298 aiReleaseImport(pScene);
|
nuclear@0
|
299 return NULL;
|
nuclear@0
|
300 }
|
nuclear@0
|
301
|
nuclear@0
|
302 ASSIMP_END_EXCEPTION_REGION(const aiScene*);
|
nuclear@0
|
303 return sc;
|
nuclear@0
|
304 }
|
nuclear@0
|
305
|
nuclear@0
|
306 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
307 void CallbackToLogRedirector (const char* msg, char* dt)
|
nuclear@0
|
308 {
|
nuclear@0
|
309 ai_assert(NULL != msg && NULL != dt);
|
nuclear@0
|
310 LogStream* s = (LogStream*)dt;
|
nuclear@0
|
311
|
nuclear@0
|
312 s->write(msg);
|
nuclear@0
|
313 }
|
nuclear@0
|
314
|
nuclear@0
|
315 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
316 ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream,const char* file)
|
nuclear@0
|
317 {
|
nuclear@0
|
318 aiLogStream sout;
|
nuclear@0
|
319
|
nuclear@0
|
320 ASSIMP_BEGIN_EXCEPTION_REGION();
|
nuclear@0
|
321 LogStream* stream = LogStream::createDefaultStream(pStream,file);
|
nuclear@0
|
322 if (!stream) {
|
nuclear@0
|
323 sout.callback = NULL;
|
nuclear@0
|
324 sout.user = NULL;
|
nuclear@0
|
325 }
|
nuclear@0
|
326 else {
|
nuclear@0
|
327 sout.callback = &CallbackToLogRedirector;
|
nuclear@0
|
328 sout.user = (char*)stream;
|
nuclear@0
|
329 }
|
nuclear@0
|
330 gPredefinedStreams.push_back(stream);
|
nuclear@0
|
331 ASSIMP_END_EXCEPTION_REGION(aiLogStream);
|
nuclear@0
|
332 return sout;
|
nuclear@0
|
333 }
|
nuclear@0
|
334
|
nuclear@0
|
335 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
336 ASSIMP_API void aiAttachLogStream( const aiLogStream* stream )
|
nuclear@0
|
337 {
|
nuclear@0
|
338 ASSIMP_BEGIN_EXCEPTION_REGION();
|
nuclear@0
|
339
|
nuclear@0
|
340 #ifdef AI_C_THREADSAFE
|
nuclear@0
|
341 boost::mutex::scoped_lock lock(gLogStreamMutex);
|
nuclear@0
|
342 #endif
|
nuclear@0
|
343
|
nuclear@0
|
344 LogStream* lg = new LogToCallbackRedirector(*stream);
|
nuclear@0
|
345 gActiveLogStreams[*stream] = lg;
|
nuclear@0
|
346
|
nuclear@0
|
347 if (DefaultLogger::isNullLogger()) {
|
nuclear@0
|
348 DefaultLogger::create(NULL,(gVerboseLogging == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
|
nuclear@0
|
349 }
|
nuclear@0
|
350 DefaultLogger::get()->attachStream(lg);
|
nuclear@0
|
351 ASSIMP_END_EXCEPTION_REGION(void);
|
nuclear@0
|
352 }
|
nuclear@0
|
353
|
nuclear@0
|
354 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
355 ASSIMP_API aiReturn aiDetachLogStream( const aiLogStream* stream)
|
nuclear@0
|
356 {
|
nuclear@0
|
357 ASSIMP_BEGIN_EXCEPTION_REGION();
|
nuclear@0
|
358
|
nuclear@0
|
359 #ifdef AI_C_THREADSAFE
|
nuclear@0
|
360 boost::mutex::scoped_lock lock(gLogStreamMutex);
|
nuclear@0
|
361 #endif
|
nuclear@0
|
362 // find the logstream associated with this data
|
nuclear@0
|
363 LogStreamMap::iterator it = gActiveLogStreams.find( *stream);
|
nuclear@0
|
364 // it should be there... else the user is playing fools with us
|
nuclear@0
|
365 if( it == gActiveLogStreams.end()) {
|
nuclear@0
|
366 return AI_FAILURE;
|
nuclear@0
|
367 }
|
nuclear@0
|
368 DefaultLogger::get()->detatchStream( it->second );
|
nuclear@0
|
369 delete it->second;
|
nuclear@0
|
370
|
nuclear@0
|
371 gActiveLogStreams.erase( it);
|
nuclear@0
|
372
|
nuclear@0
|
373 if (gActiveLogStreams.empty()) {
|
nuclear@0
|
374 DefaultLogger::kill();
|
nuclear@0
|
375 }
|
nuclear@0
|
376 ASSIMP_END_EXCEPTION_REGION(aiReturn);
|
nuclear@0
|
377 return AI_SUCCESS;
|
nuclear@0
|
378 }
|
nuclear@0
|
379
|
nuclear@0
|
380 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
381 ASSIMP_API void aiDetachAllLogStreams(void)
|
nuclear@0
|
382 {
|
nuclear@0
|
383 ASSIMP_BEGIN_EXCEPTION_REGION();
|
nuclear@0
|
384 #ifdef AI_C_THREADSAFE
|
nuclear@0
|
385 boost::mutex::scoped_lock lock(gLogStreamMutex);
|
nuclear@0
|
386 #endif
|
nuclear@0
|
387 for (LogStreamMap::iterator it = gActiveLogStreams.begin(); it != gActiveLogStreams.end(); ++it) {
|
nuclear@0
|
388 DefaultLogger::get()->detatchStream( it->second );
|
nuclear@0
|
389 delete it->second;
|
nuclear@0
|
390 }
|
nuclear@0
|
391 gActiveLogStreams.clear();
|
nuclear@0
|
392 DefaultLogger::kill();
|
nuclear@0
|
393 ASSIMP_END_EXCEPTION_REGION(void);
|
nuclear@0
|
394 }
|
nuclear@0
|
395
|
nuclear@0
|
396 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
397 ASSIMP_API void aiEnableVerboseLogging(aiBool d)
|
nuclear@0
|
398 {
|
nuclear@0
|
399 if (!DefaultLogger::isNullLogger()) {
|
nuclear@0
|
400 DefaultLogger::get()->setLogSeverity((d == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
|
nuclear@0
|
401 }
|
nuclear@0
|
402 gVerboseLogging = d;
|
nuclear@0
|
403 }
|
nuclear@0
|
404
|
nuclear@0
|
405 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
406 // Returns the error text of the last failed import process.
|
nuclear@0
|
407 const char* aiGetErrorString()
|
nuclear@0
|
408 {
|
nuclear@0
|
409 return gLastErrorString.c_str();
|
nuclear@0
|
410 }
|
nuclear@0
|
411
|
nuclear@0
|
412 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
413 // Returns the error text of the last failed import process.
|
nuclear@0
|
414 aiBool aiIsExtensionSupported(const char* szExtension)
|
nuclear@0
|
415 {
|
nuclear@0
|
416 ai_assert(NULL != szExtension);
|
nuclear@0
|
417 aiBool candoit=AI_FALSE;
|
nuclear@0
|
418 ASSIMP_BEGIN_EXCEPTION_REGION();
|
nuclear@0
|
419
|
nuclear@0
|
420 // FIXME: no need to create a temporary Importer instance just for that ..
|
nuclear@0
|
421 Assimp::Importer tmp;
|
nuclear@0
|
422 candoit = tmp.IsExtensionSupported(std::string(szExtension)) ? AI_TRUE : AI_FALSE;
|
nuclear@0
|
423
|
nuclear@0
|
424 ASSIMP_END_EXCEPTION_REGION(aiBool);
|
nuclear@0
|
425 return candoit;
|
nuclear@0
|
426 }
|
nuclear@0
|
427
|
nuclear@0
|
428 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
429 // Get a list of all file extensions supported by ASSIMP
|
nuclear@0
|
430 void aiGetExtensionList(aiString* szOut)
|
nuclear@0
|
431 {
|
nuclear@0
|
432 ai_assert(NULL != szOut);
|
nuclear@0
|
433 ASSIMP_BEGIN_EXCEPTION_REGION();
|
nuclear@0
|
434
|
nuclear@0
|
435 // FIXME: no need to create a temporary Importer instance just for that ..
|
nuclear@0
|
436 Assimp::Importer tmp;
|
nuclear@0
|
437 tmp.GetExtensionList(*szOut);
|
nuclear@0
|
438
|
nuclear@0
|
439 ASSIMP_END_EXCEPTION_REGION(void);
|
nuclear@0
|
440 }
|
nuclear@0
|
441
|
nuclear@0
|
442 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
443 // Get the memory requirements for a particular import.
|
nuclear@0
|
444 void aiGetMemoryRequirements(const C_STRUCT aiScene* pIn,
|
nuclear@0
|
445 C_STRUCT aiMemoryInfo* in)
|
nuclear@0
|
446 {
|
nuclear@0
|
447 ASSIMP_BEGIN_EXCEPTION_REGION();
|
nuclear@0
|
448
|
nuclear@0
|
449 // find the importer associated with this data
|
nuclear@0
|
450 const ScenePrivateData* priv = ScenePriv(pIn);
|
nuclear@0
|
451 if( !priv || !priv->mOrigImporter) {
|
nuclear@0
|
452 ReportSceneNotFoundError();
|
nuclear@0
|
453 return;
|
nuclear@0
|
454 }
|
nuclear@0
|
455
|
nuclear@0
|
456 return priv->mOrigImporter->GetMemoryRequirements(*in);
|
nuclear@0
|
457 ASSIMP_END_EXCEPTION_REGION(void);
|
nuclear@0
|
458 }
|
nuclear@0
|
459
|
nuclear@0
|
460 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
461 ASSIMP_API aiPropertyStore* aiCreatePropertyStore(void)
|
nuclear@0
|
462 {
|
nuclear@0
|
463 return reinterpret_cast<aiPropertyStore*>( new PropertyMap() );
|
nuclear@0
|
464 }
|
nuclear@0
|
465
|
nuclear@0
|
466
|
nuclear@0
|
467 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
468 ASSIMP_API void aiReleasePropertyStore(aiPropertyStore* p)
|
nuclear@0
|
469 {
|
nuclear@0
|
470 delete reinterpret_cast<PropertyMap*>(p);
|
nuclear@0
|
471 }
|
nuclear@0
|
472
|
nuclear@0
|
473 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
474 // Importer::SetPropertyInteger
|
nuclear@0
|
475 ASSIMP_API void aiSetImportPropertyInteger(aiPropertyStore* p, const char* szName, int value)
|
nuclear@0
|
476 {
|
nuclear@0
|
477 ASSIMP_BEGIN_EXCEPTION_REGION();
|
nuclear@0
|
478 PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
|
nuclear@0
|
479 SetGenericProperty<int>(pp->ints,szName,value,NULL);
|
nuclear@0
|
480 ASSIMP_END_EXCEPTION_REGION(void);
|
nuclear@0
|
481 }
|
nuclear@0
|
482
|
nuclear@0
|
483 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
484 // Importer::SetPropertyFloat
|
nuclear@0
|
485 ASSIMP_API void aiSetImportPropertyFloat(aiPropertyStore* p, const char* szName, float value)
|
nuclear@0
|
486 {
|
nuclear@0
|
487 ASSIMP_BEGIN_EXCEPTION_REGION();
|
nuclear@0
|
488 PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
|
nuclear@0
|
489 SetGenericProperty<float>(pp->floats,szName,value,NULL);
|
nuclear@0
|
490 ASSIMP_END_EXCEPTION_REGION(void);
|
nuclear@0
|
491 }
|
nuclear@0
|
492
|
nuclear@0
|
493 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
494 // Importer::SetPropertyString
|
nuclear@0
|
495 ASSIMP_API void aiSetImportPropertyString(aiPropertyStore* p, const char* szName,
|
nuclear@0
|
496 const C_STRUCT aiString* st)
|
nuclear@0
|
497 {
|
nuclear@0
|
498 if (!st) {
|
nuclear@0
|
499 return;
|
nuclear@0
|
500 }
|
nuclear@0
|
501 ASSIMP_BEGIN_EXCEPTION_REGION();
|
nuclear@0
|
502 PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
|
nuclear@0
|
503 SetGenericProperty<std::string>(pp->strings,szName,std::string(st->C_Str()),NULL);
|
nuclear@0
|
504 ASSIMP_END_EXCEPTION_REGION(void);
|
nuclear@0
|
505 }
|
nuclear@0
|
506
|
nuclear@0
|
507 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
508 // Rotation matrix to quaternion
|
nuclear@0
|
509 ASSIMP_API void aiCreateQuaternionFromMatrix(aiQuaternion* quat,const aiMatrix3x3* mat)
|
nuclear@0
|
510 {
|
nuclear@0
|
511 ai_assert(NULL != quat && NULL != mat);
|
nuclear@0
|
512 *quat = aiQuaternion(*mat);
|
nuclear@0
|
513 }
|
nuclear@0
|
514
|
nuclear@0
|
515 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
516 // Matrix decomposition
|
nuclear@0
|
517 ASSIMP_API void aiDecomposeMatrix(const aiMatrix4x4* mat,aiVector3D* scaling,
|
nuclear@0
|
518 aiQuaternion* rotation,
|
nuclear@0
|
519 aiVector3D* position)
|
nuclear@0
|
520 {
|
nuclear@0
|
521 ai_assert(NULL != rotation && NULL != position && NULL != scaling && NULL != mat);
|
nuclear@0
|
522 mat->Decompose(*scaling,*rotation,*position);
|
nuclear@0
|
523 }
|
nuclear@0
|
524
|
nuclear@0
|
525 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
526 // Matrix transpose
|
nuclear@0
|
527 ASSIMP_API void aiTransposeMatrix3(aiMatrix3x3* mat)
|
nuclear@0
|
528 {
|
nuclear@0
|
529 ai_assert(NULL != mat);
|
nuclear@0
|
530 mat->Transpose();
|
nuclear@0
|
531 }
|
nuclear@0
|
532
|
nuclear@0
|
533 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
534 ASSIMP_API void aiTransposeMatrix4(aiMatrix4x4* mat)
|
nuclear@0
|
535 {
|
nuclear@0
|
536 ai_assert(NULL != mat);
|
nuclear@0
|
537 mat->Transpose();
|
nuclear@0
|
538 }
|
nuclear@0
|
539
|
nuclear@0
|
540 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
541 // Vector transformation
|
nuclear@0
|
542 ASSIMP_API void aiTransformVecByMatrix3(aiVector3D* vec,
|
nuclear@0
|
543 const aiMatrix3x3* mat)
|
nuclear@0
|
544 {
|
nuclear@0
|
545 ai_assert(NULL != mat && NULL != vec);
|
nuclear@0
|
546 *vec *= (*mat);
|
nuclear@0
|
547 }
|
nuclear@0
|
548
|
nuclear@0
|
549 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
550 ASSIMP_API void aiTransformVecByMatrix4(aiVector3D* vec,
|
nuclear@0
|
551 const aiMatrix4x4* mat)
|
nuclear@0
|
552 {
|
nuclear@0
|
553 ai_assert(NULL != mat && NULL != vec);
|
nuclear@0
|
554 *vec *= (*mat);
|
nuclear@0
|
555 }
|
nuclear@0
|
556
|
nuclear@0
|
557 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
558 // Matrix multiplication
|
nuclear@0
|
559 ASSIMP_API void aiMultiplyMatrix4(
|
nuclear@0
|
560 aiMatrix4x4* dst,
|
nuclear@0
|
561 const aiMatrix4x4* src)
|
nuclear@0
|
562 {
|
nuclear@0
|
563 ai_assert(NULL != dst && NULL != src);
|
nuclear@0
|
564 *dst = (*dst) * (*src);
|
nuclear@0
|
565 }
|
nuclear@0
|
566
|
nuclear@0
|
567 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
568 ASSIMP_API void aiMultiplyMatrix3(
|
nuclear@0
|
569 aiMatrix3x3* dst,
|
nuclear@0
|
570 const aiMatrix3x3* src)
|
nuclear@0
|
571 {
|
nuclear@0
|
572 ai_assert(NULL != dst && NULL != src);
|
nuclear@0
|
573 *dst = (*dst) * (*src);
|
nuclear@0
|
574 }
|
nuclear@0
|
575
|
nuclear@0
|
576 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
577 // Matrix identity
|
nuclear@0
|
578 ASSIMP_API void aiIdentityMatrix3(
|
nuclear@0
|
579 aiMatrix3x3* mat)
|
nuclear@0
|
580 {
|
nuclear@0
|
581 ai_assert(NULL != mat);
|
nuclear@0
|
582 *mat = aiMatrix3x3();
|
nuclear@0
|
583 }
|
nuclear@0
|
584
|
nuclear@0
|
585 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
586 ASSIMP_API void aiIdentityMatrix4(
|
nuclear@0
|
587 aiMatrix4x4* mat)
|
nuclear@0
|
588 {
|
nuclear@0
|
589 ai_assert(NULL != mat);
|
nuclear@0
|
590 *mat = aiMatrix4x4();
|
nuclear@0
|
591 }
|
nuclear@0
|
592
|
nuclear@0
|
593
|