summaryrefslogtreecommitdiff
path: root/libs/assimp/code/Common/Assimp.cpp
blob: 71e312cee29b288dbe4669c9667e729c438cae0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------

Copyright (c) 2006-2022, assimp team



All rights reserved.

Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:

* Redistributions of source code must retain the above
  copyright notice, this list of conditions and the
  following disclaimer.

* Redistributions in binary form must reproduce the above
  copyright notice, this list of conditions and the
  following disclaimer in the documentation and/or other
  materials provided with the distribution.

* Neither the name of the assimp team, nor the names of its
  contributors may be used to endorse or promote products
  derived from this software without specific prior
  written permission of the assimp team.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
/** @file  Assimp.cpp
 *  @brief Implementation of the Plain-C API
 */

#include <assimp/BaseImporter.h>
#include <assimp/Exceptional.h>
#include <assimp/GenericProperty.h>
#include <assimp/cimport.h>
#include <assimp/importerdesc.h>
#include <assimp/scene.h>
#include <assimp/DefaultLogger.hpp>
#include <assimp/Importer.hpp>
#include <assimp/LogStream.hpp>

#include "CApi/CInterfaceIOWrapper.h"
#include "Importer.h"
#include "ScenePrivate.h"

#include <list>

// ------------------------------------------------------------------------------------------------
#ifndef ASSIMP_BUILD_SINGLETHREADED
#include <mutex>
#include <thread>
#endif
// ------------------------------------------------------------------------------------------------
using namespace Assimp;

namespace Assimp {
// underlying structure for aiPropertyStore
typedef BatchLoader::PropertyMap PropertyMap;

#if defined(__has_warning)
#if __has_warning("-Wordered-compare-function-pointers")
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wordered-compare-function-pointers"
#endif
#endif

/** Stores the LogStream objects for all active C log streams */
struct mpred {
    bool operator()(const aiLogStream &s0, const aiLogStream &s1) const {
        return s0.callback < s1.callback && s0.user < s1.user;
    }
};

#if defined(__has_warning)
#if __has_warning("-Wordered-compare-function-pointers")
#pragma GCC diagnostic pop
#endif
#endif
typedef std::map<aiLogStream, Assimp::LogStream *, mpred> LogStreamMap;

/** Stores the LogStream objects allocated by #aiGetPredefinedLogStream */
typedef std::list<Assimp::LogStream *> PredefLogStreamMap;

/** Local storage of all active log streams */
static LogStreamMap gActiveLogStreams;

/** Local storage of LogStreams allocated by #aiGetPredefinedLogStream */
static PredefLogStreamMap gPredefinedStreams;

/** Error message of the last failed import process */
static std::string gLastErrorString;

/** Verbose logging active or not? */
static aiBool gVerboseLogging = false;

/** will return all registered importers. */
void GetImporterInstanceList(std::vector<BaseImporter *> &out);

/** will delete all registered importers. */
void DeleteImporterInstanceList(std::vector<BaseImporter *> &out);
} // namespace Assimp

#ifndef ASSIMP_BUILD_SINGLETHREADED
/** Global mutex to manage the access to the log-stream map */
static std::mutex gLogStreamMutex;
#endif

// ------------------------------------------------------------------------------------------------
// Custom LogStream implementation for the C-API
class LogToCallbackRedirector : public LogStream {
public:
    explicit LogToCallbackRedirector(const aiLogStream &s) :
            stream(s) {
        ai_assert(nullptr != s.callback);
    }

    ~LogToCallbackRedirector() {
#ifndef ASSIMP_BUILD_SINGLETHREADED
        std::lock_guard<std::mutex> lock(gLogStreamMutex);
#endif
        // (HACK) Check whether the 'stream.user' pointer points to a
        // custom LogStream allocated by #aiGetPredefinedLogStream.
        // In this case, we need to delete it, too. Of course, this
        // might cause strange problems, but the chance is quite low.

        PredefLogStreamMap::iterator it = std::find(gPredefinedStreams.begin(),
                gPredefinedStreams.end(), (Assimp::LogStream *)stream.user);

        if (it != gPredefinedStreams.end()) {
            delete *it;
            gPredefinedStreams.erase(it);
        }
    }

    /** @copydoc LogStream::write */
    void write(const char *message) {
        stream.callback(message, stream.user);
    }

private:
    aiLogStream stream;
};

// ------------------------------------------------------------------------------------------------
void ReportSceneNotFoundError() {
    ASSIMP_LOG_ERROR("Unable to find the Assimp::Importer for this aiScene. "
                     "The C-API does not accept scenes produced by the C++ API and vice versa");

    ai_assert(false);
}

// ------------------------------------------------------------------------------------------------
// Reads the given file and returns its content.
const aiScene *aiImportFile(const char *pFile, unsigned int pFlags) {
    return aiImportFileEx(pFile, pFlags, nullptr);
}

// ------------------------------------------------------------------------------------------------
const aiScene *aiImportFileEx(const char *pFile, unsigned int pFlags, aiFileIO *pFS) {
    return aiImportFileExWithProperties(pFile, pFlags, pFS, nullptr);
}

// ------------------------------------------------------------------------------------------------
const aiScene *aiImportFileExWithProperties(const char *pFile, unsigned int pFlags,
        aiFileIO *pFS, const aiPropertyStore *props) {
    ai_assert(nullptr != pFile);

    const aiScene *scene = nullptr;
    ASSIMP_BEGIN_EXCEPTION_REGION();

    // create an Importer for this file
    Assimp::Importer *imp = new Assimp::Importer();

    // copy properties
    if (props) {
        const PropertyMap *pp = reinterpret_cast<const PropertyMap *>(props);
        ImporterPimpl *pimpl = imp->Pimpl();
        pimpl->mIntProperties = pp->ints;
        pimpl->mFloatProperties = pp->floats;
        pimpl->mStringProperties = pp->strings;
        pimpl->mMatrixProperties = pp->matrices;
    }
    // setup a custom IO system if necessary
    if (pFS) {
        imp->SetIOHandler(new CIOSystemWrapper(pFS));
    }

    // and have it read the file
    scene = imp->ReadFile(pFile, pFlags);

    // if succeeded, store the importer in the scene and keep it alive
    if (scene) {
        ScenePrivateData *priv = const_cast<ScenePrivateData *>(ScenePriv(scene));
        priv->mOrigImporter = imp;
    } else {
        // if failed, extract error code and destroy the import
        gLastErrorString = imp->GetErrorString();
        delete imp;
    }

    // return imported data. If the import failed the pointer is nullptr anyways
    ASSIMP_END_EXCEPTION_REGION(const aiScene *);

    return scene;
}

// ------------------------------------------------------------------------------------------------
const aiScene *aiImportFileFromMemory(
        const char *pBuffer,
        unsigned int pLength,
        unsigned int pFlags,
        const char *pHint) {
    return aiImportFileFromMemoryWithProperties(pBuffer, pLength, pFlags, pHint, nullptr);
}

// ------------------------------------------------------------------------------------------------
const aiScene *aiImportFileFromMemoryWithProperties(
        const char *pBuffer,
        unsigned int pLength,
        unsigned int pFlags,
        const char *pHint,
        const aiPropertyStore *props) {
    ai_assert(nullptr != pBuffer);
    ai_assert(0 != pLength);

    const aiScene *scene = nullptr;
    ASSIMP_BEGIN_EXCEPTION_REGION();

    // create an Importer for this file
    Assimp::Importer *imp = new Assimp::Importer();

    // copy properties
    if (props) {
        const PropertyMap *pp = reinterpret_cast<const PropertyMap *>(props);
        ImporterPimpl *pimpl = imp->Pimpl();
        pimpl->mIntProperties = pp->ints;
        pimpl->mFloatProperties = pp->floats;
        pimpl->mStringProperties = pp->strings;
        pimpl->mMatrixProperties = pp->matrices;
    }

    // and have it read the file from the memory buffer
    scene = imp->ReadFileFromMemory(pBuffer, pLength, pFlags, pHint);

    // if succeeded, store the importer in the scene and keep it alive
    if (scene) {
        ScenePrivateData *priv = const_cast<ScenePrivateData *>(ScenePriv(scene));
        priv->mOrigImporter = imp;
    } else {
        // if failed, extract error code and destroy the import
        gLastErrorString = imp->GetErrorString();
        delete imp;
    }
    // return imported data. If the import failed the pointer is nullptr anyways
    ASSIMP_END_EXCEPTION_REGION(const aiScene *);
    return scene;
}

// ------------------------------------------------------------------------------------------------
// Releases all resources associated with the given import process.
void aiReleaseImport(const aiScene *pScene) {
    if (!pScene) {
        return;
    }

    ASSIMP_BEGIN_EXCEPTION_REGION();

    // find the importer associated with this data
    const ScenePrivateData *priv = ScenePriv(pScene);
    if (!priv || !priv->mOrigImporter) {
        delete pScene;
    } else {
        // deleting the Importer also deletes the scene
        // Note: the reason that this is not written as 'delete priv->mOrigImporter'
        // is a suspected bug in gcc 4.4+ (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52339)
        Importer *importer = priv->mOrigImporter;
        delete importer;
    }

    ASSIMP_END_EXCEPTION_REGION(void);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API const aiScene *aiApplyPostProcessing(const aiScene *pScene,
        unsigned int pFlags) {
    const aiScene *sc = nullptr;

    ASSIMP_BEGIN_EXCEPTION_REGION();

    // find the importer associated with this data
    const ScenePrivateData *priv = ScenePriv(pScene);
    if (!priv || !priv->mOrigImporter) {
        ReportSceneNotFoundError();
        return nullptr;
    }

    sc = priv->mOrigImporter->ApplyPostProcessing(pFlags);

    if (!sc) {
        aiReleaseImport(pScene);
        return nullptr;
    }

    ASSIMP_END_EXCEPTION_REGION(const aiScene *);
    return sc;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API const aiScene *aiApplyCustomizedPostProcessing(const aiScene *scene,
        BaseProcess *process,
        bool requestValidation) {
    const aiScene *sc(nullptr);

    ASSIMP_BEGIN_EXCEPTION_REGION();

    // find the importer associated with this data
    const ScenePrivateData *priv = ScenePriv(scene);
    if (nullptr == priv || nullptr == priv->mOrigImporter) {
        ReportSceneNotFoundError();
        return nullptr;
    }

    sc = priv->mOrigImporter->ApplyCustomizedPostProcessing(process, requestValidation);

    if (!sc) {
        aiReleaseImport(scene);
        return nullptr;
    }

    ASSIMP_END_EXCEPTION_REGION(const aiScene *);

    return sc;
}

// ------------------------------------------------------------------------------------------------
void CallbackToLogRedirector(const char *msg, char *dt) {
    ai_assert(nullptr != msg);
    ai_assert(nullptr != dt);
    LogStream *s = (LogStream *)dt;

    s->write(msg);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream, const char *file) {
    aiLogStream sout;

    ASSIMP_BEGIN_EXCEPTION_REGION();
    LogStream *stream = LogStream::createDefaultStream(pStream, file);
    if (!stream) {
        sout.callback = nullptr;
        sout.user = nullptr;
    } else {
        sout.callback = &CallbackToLogRedirector;
        sout.user = (char *)stream;
    }
    gPredefinedStreams.push_back(stream);
    ASSIMP_END_EXCEPTION_REGION(aiLogStream);
    return sout;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiAttachLogStream(const aiLogStream *stream) {
    ASSIMP_BEGIN_EXCEPTION_REGION();

#ifndef ASSIMP_BUILD_SINGLETHREADED
    std::lock_guard<std::mutex> lock(gLogStreamMutex);
#endif

    LogStream *lg = new LogToCallbackRedirector(*stream);
    gActiveLogStreams[*stream] = lg;

    if (DefaultLogger::isNullLogger()) {
        DefaultLogger::create(nullptr, (gVerboseLogging == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
    }
    DefaultLogger::get()->attachStream(lg);
    ASSIMP_END_EXCEPTION_REGION(void);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API aiReturn aiDetachLogStream(const aiLogStream *stream) {
    ASSIMP_BEGIN_EXCEPTION_REGION();

#ifndef ASSIMP_BUILD_SINGLETHREADED
    std::lock_guard<std::mutex> lock(gLogStreamMutex);
#endif
    // find the log-stream associated with this data
    LogStreamMap::iterator it = gActiveLogStreams.find(*stream);
    // it should be there... else the user is playing fools with us
    if (it == gActiveLogStreams.end()) {
        return AI_FAILURE;
    }
    DefaultLogger::get()->detachStream(it->second);
    delete it->second;

    gActiveLogStreams.erase(it);

    if (gActiveLogStreams.empty()) {
        DefaultLogger::kill();
    }
    ASSIMP_END_EXCEPTION_REGION(aiReturn);
    return AI_SUCCESS;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiDetachAllLogStreams(void) {
    ASSIMP_BEGIN_EXCEPTION_REGION();
#ifndef ASSIMP_BUILD_SINGLETHREADED
    std::lock_guard<std::mutex> lock(gLogStreamMutex);
#endif
    Logger *logger(DefaultLogger::get());
    if (nullptr == logger) {
        return;
    }

    for (LogStreamMap::iterator it = gActiveLogStreams.begin(); it != gActiveLogStreams.end(); ++it) {
        logger->detachStream(it->second);
        delete it->second;
    }
    gActiveLogStreams.clear();
    DefaultLogger::kill();

    ASSIMP_END_EXCEPTION_REGION(void);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiEnableVerboseLogging(aiBool d) {
    if (!DefaultLogger::isNullLogger()) {
        DefaultLogger::get()->setLogSeverity((d == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
    }
    gVerboseLogging = d;
}

// ------------------------------------------------------------------------------------------------
// Returns the error text of the last failed import process.
const char *aiGetErrorString() {
    return gLastErrorString.c_str();
}

// -----------------------------------------------------------------------------------------------
// Return the description of a importer given its index
const aiImporterDesc *aiGetImportFormatDescription(size_t pIndex) {
    return Importer().GetImporterInfo(pIndex);
}

// -----------------------------------------------------------------------------------------------
// Return the number of importers
size_t aiGetImportFormatCount(void) {
    return Importer().GetImporterCount();
}

// ------------------------------------------------------------------------------------------------
// Returns the error text of the last failed import process.
aiBool aiIsExtensionSupported(const char *szExtension) {
    ai_assert(nullptr != szExtension);
    aiBool candoit = AI_FALSE;
    ASSIMP_BEGIN_EXCEPTION_REGION();

    // FIXME: no need to create a temporary Importer instance just for that ..
    Assimp::Importer tmp;
    candoit = tmp.IsExtensionSupported(std::string(szExtension)) ? AI_TRUE : AI_FALSE;

    ASSIMP_END_EXCEPTION_REGION(aiBool);
    return candoit;
}

// ------------------------------------------------------------------------------------------------
// Get a list of all file extensions supported by ASSIMP
void aiGetExtensionList(aiString *szOut) {
    ai_assert(nullptr != szOut);
    ASSIMP_BEGIN_EXCEPTION_REGION();

    // FIXME: no need to create a temporary Importer instance just for that ..
    Assimp::Importer tmp;
    tmp.GetExtensionList(*szOut);

    ASSIMP_END_EXCEPTION_REGION(void);
}

// ------------------------------------------------------------------------------------------------
// Get the memory requirements for a particular import.
void aiGetMemoryRequirements(const C_STRUCT aiScene *pIn,
        C_STRUCT aiMemoryInfo *in) {
    ASSIMP_BEGIN_EXCEPTION_REGION();

    // find the importer associated with this data
    const ScenePrivateData *priv = ScenePriv(pIn);
    if (!priv || !priv->mOrigImporter) {
        ReportSceneNotFoundError();
        return;
    }

    return priv->mOrigImporter->GetMemoryRequirements(*in);
    ASSIMP_END_EXCEPTION_REGION(void);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API aiPropertyStore *aiCreatePropertyStore(void) {
    return reinterpret_cast<aiPropertyStore *>(new PropertyMap());
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiReleasePropertyStore(aiPropertyStore *p) {
    delete reinterpret_cast<PropertyMap *>(p);
}

// ------------------------------------------------------------------------------------------------
// Importer::SetPropertyInteger
ASSIMP_API void aiSetImportPropertyInteger(aiPropertyStore *p, const char *szName, int value) {
    ASSIMP_BEGIN_EXCEPTION_REGION();
    PropertyMap *pp = reinterpret_cast<PropertyMap *>(p);
    SetGenericProperty<int>(pp->ints, szName, value);
    ASSIMP_END_EXCEPTION_REGION(void);
}

// ------------------------------------------------------------------------------------------------
// Importer::SetPropertyFloat
ASSIMP_API void aiSetImportPropertyFloat(aiPropertyStore *p, const char *szName, ai_real value) {
    ASSIMP_BEGIN_EXCEPTION_REGION();
    PropertyMap *pp = reinterpret_cast<PropertyMap *>(p);
    SetGenericProperty<ai_real>(pp->floats, szName, value);
    ASSIMP_END_EXCEPTION_REGION(void);
}

// ------------------------------------------------------------------------------------------------
// Importer::SetPropertyString
ASSIMP_API void aiSetImportPropertyString(aiPropertyStore *p, const char *szName,
        const C_STRUCT aiString *st) {
    if (!st) {
        return;
    }
    ASSIMP_BEGIN_EXCEPTION_REGION();
    PropertyMap *pp = reinterpret_cast<PropertyMap *>(p);
    SetGenericProperty<std::string>(pp->strings, szName, std::string(st->C_Str()));
    ASSIMP_END_EXCEPTION_REGION(void);
}

// ------------------------------------------------------------------------------------------------
// Importer::SetPropertyMatrix
ASSIMP_API void aiSetImportPropertyMatrix(aiPropertyStore *p, const char *szName,
        const C_STRUCT aiMatrix4x4 *mat) {
    if (!mat) {
        return;
    }
    ASSIMP_BEGIN_EXCEPTION_REGION();
    PropertyMap *pp = reinterpret_cast<PropertyMap *>(p);
    SetGenericProperty<aiMatrix4x4>(pp->matrices, szName, *mat);
    ASSIMP_END_EXCEPTION_REGION(void);
}

// ------------------------------------------------------------------------------------------------
// Rotation matrix to quaternion
ASSIMP_API void aiCreateQuaternionFromMatrix(aiQuaternion *quat, const aiMatrix3x3 *mat) {
    ai_assert(nullptr != quat);
    ai_assert(nullptr != mat);
    *quat = aiQuaternion(*mat);
}

// ------------------------------------------------------------------------------------------------
// Matrix decomposition
ASSIMP_API void aiDecomposeMatrix(const aiMatrix4x4 *mat, aiVector3D *scaling,
        aiQuaternion *rotation,
        aiVector3D *position) {
    ai_assert(nullptr != rotation);
    ai_assert(nullptr != position);
    ai_assert(nullptr != scaling);
    ai_assert(nullptr != mat);
    mat->Decompose(*scaling, *rotation, *position);
}

// ------------------------------------------------------------------------------------------------
// Matrix transpose
ASSIMP_API void aiTransposeMatrix3(aiMatrix3x3 *mat) {
    ai_assert(nullptr != mat);
    mat->Transpose();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiTransposeMatrix4(aiMatrix4x4 *mat) {
    ai_assert(nullptr != mat);
    mat->Transpose();
}

// ------------------------------------------------------------------------------------------------
// Vector transformation
ASSIMP_API void aiTransformVecByMatrix3(aiVector3D *vec,
        const aiMatrix3x3 *mat) {
    ai_assert(nullptr != mat);
    ai_assert(nullptr != vec);
    *vec *= (*mat);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiTransformVecByMatrix4(aiVector3D *vec,
        const aiMatrix4x4 *mat) {
    ai_assert(nullptr != mat);
    ai_assert(nullptr != vec);

    *vec *= (*mat);
}

// ------------------------------------------------------------------------------------------------
// Matrix multiplication
ASSIMP_API void aiMultiplyMatrix4(
        aiMatrix4x4 *dst,
        const aiMatrix4x4 *src) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != src);
    *dst = (*dst) * (*src);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMultiplyMatrix3(
        aiMatrix3x3 *dst,
        const aiMatrix3x3 *src) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != src);
    *dst = (*dst) * (*src);
}

// ------------------------------------------------------------------------------------------------
// Matrix identity
ASSIMP_API void aiIdentityMatrix3(
        aiMatrix3x3 *mat) {
    ai_assert(nullptr != mat);
    *mat = aiMatrix3x3();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiIdentityMatrix4(
        aiMatrix4x4 *mat) {
    ai_assert(nullptr != mat);
    *mat = aiMatrix4x4();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API C_STRUCT const aiImporterDesc *aiGetImporterDesc(const char *extension) {
    if (nullptr == extension) {
        return nullptr;
    }
    const aiImporterDesc *desc(nullptr);
    std::vector<BaseImporter *> out;
    GetImporterInstanceList(out);
    for (size_t i = 0; i < out.size(); ++i) {
        if (0 == strncmp(out[i]->GetInfo()->mFileExtensions, extension, strlen(extension))) {
            desc = out[i]->GetInfo();
            break;
        }
    }

    DeleteImporterInstanceList(out);

    return desc;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API int aiVector2AreEqual(
        const C_STRUCT aiVector2D *a,
        const C_STRUCT aiVector2D *b) {
    ai_assert(nullptr != a);
    ai_assert(nullptr != b);
    return *a == *b;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API int aiVector2AreEqualEpsilon(
        const C_STRUCT aiVector2D *a,
        const C_STRUCT aiVector2D *b,
        const float epsilon) {
    ai_assert(nullptr != a);
    ai_assert(nullptr != b);
    return a->Equal(*b, epsilon);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector2Add(
        C_STRUCT aiVector2D *dst,
        const C_STRUCT aiVector2D *src) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != src);
    *dst = *dst + *src;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector2Subtract(
        C_STRUCT aiVector2D *dst,
        const C_STRUCT aiVector2D *src) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != src);
    *dst = *dst - *src;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector2Scale(
        C_STRUCT aiVector2D *dst,
        const float s) {
    ai_assert(nullptr != dst);
    *dst *= s;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector2SymMul(
        C_STRUCT aiVector2D *dst,
        const C_STRUCT aiVector2D *other) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != other);
    *dst = dst->SymMul(*other);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector2DivideByScalar(
        C_STRUCT aiVector2D *dst,
        const float s) {
    ai_assert(nullptr != dst);
    *dst /= s;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector2DivideByVector(
        C_STRUCT aiVector2D *dst,
        C_STRUCT aiVector2D *v) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != v);
    *dst = *dst / *v;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiVector2Length(
        const C_STRUCT aiVector2D *v) {
    ai_assert(nullptr != v);
    return v->Length();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiVector2SquareLength(
        const C_STRUCT aiVector2D *v) {
    ai_assert(nullptr != v);
    return v->SquareLength();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector2Negate(
        C_STRUCT aiVector2D *dst) {
    ai_assert(nullptr != dst);
    *dst = -(*dst);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiVector2DotProduct(
        const C_STRUCT aiVector2D *a,
        const C_STRUCT aiVector2D *b) {
    ai_assert(nullptr != a);
    ai_assert(nullptr != b);
    return (*a) * (*b);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector2Normalize(
        C_STRUCT aiVector2D *v) {
    ai_assert(nullptr != v);
    v->Normalize();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API int aiVector3AreEqual(
        const C_STRUCT aiVector3D *a,
        const C_STRUCT aiVector3D *b) {
    ai_assert(nullptr != a);
    ai_assert(nullptr != b);
    return *a == *b;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API int aiVector3AreEqualEpsilon(
        const C_STRUCT aiVector3D *a,
        const C_STRUCT aiVector3D *b,
        const float epsilon) {
    ai_assert(nullptr != a);
    ai_assert(nullptr != b);
    return a->Equal(*b, epsilon);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API int aiVector3LessThan(
        const C_STRUCT aiVector3D *a,
        const C_STRUCT aiVector3D *b) {
    ai_assert(nullptr != a);
    ai_assert(nullptr != b);
    return *a < *b;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector3Add(
        C_STRUCT aiVector3D *dst,
        const C_STRUCT aiVector3D *src) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != src);
    *dst = *dst + *src;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector3Subtract(
        C_STRUCT aiVector3D *dst,
        const C_STRUCT aiVector3D *src) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != src);
    *dst = *dst - *src;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector3Scale(
        C_STRUCT aiVector3D *dst,
        const float s) {
    ai_assert(nullptr != dst);
    *dst *= s;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector3SymMul(
        C_STRUCT aiVector3D *dst,
        const C_STRUCT aiVector3D *other) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != other);
    *dst = dst->SymMul(*other);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector3DivideByScalar(
        C_STRUCT aiVector3D *dst, const float s) {
    ai_assert(nullptr != dst);
    *dst /= s;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector3DivideByVector(
        C_STRUCT aiVector3D *dst,
        C_STRUCT aiVector3D *v) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != v);
    *dst = *dst / *v;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiVector3Length(
        const C_STRUCT aiVector3D *v) {
    ai_assert(nullptr != v);
    return v->Length();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiVector3SquareLength(
        const C_STRUCT aiVector3D *v) {
    ai_assert(nullptr != v);
    return v->SquareLength();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector3Negate(
        C_STRUCT aiVector3D *dst) {
    ai_assert(nullptr != dst);
    *dst = -(*dst);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiVector3DotProduct(
        const C_STRUCT aiVector3D *a,
        const C_STRUCT aiVector3D *b) {
    ai_assert(nullptr != a);
    ai_assert(nullptr != b);
    return (*a) * (*b);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector3CrossProduct(
        C_STRUCT aiVector3D *dst,
        const C_STRUCT aiVector3D *a,
        const C_STRUCT aiVector3D *b) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != a);
    ai_assert(nullptr != b);
    *dst = *a ^ *b;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector3Normalize(
        C_STRUCT aiVector3D *v) {
    ai_assert(nullptr != v);
    v->Normalize();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector3NormalizeSafe(
        C_STRUCT aiVector3D *v) {
    ai_assert(nullptr != v);
    v->NormalizeSafe();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiVector3RotateByQuaternion(
        C_STRUCT aiVector3D *v,
        const C_STRUCT aiQuaternion *q) {
    ai_assert(nullptr != v);
    ai_assert(nullptr != q);
    *v = q->Rotate(*v);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix3FromMatrix4(
        C_STRUCT aiMatrix3x3 *dst,
        const C_STRUCT aiMatrix4x4 *mat) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != mat);
    *dst = aiMatrix3x3(*mat);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix3FromQuaternion(
        C_STRUCT aiMatrix3x3 *mat,
        const C_STRUCT aiQuaternion *q) {
    ai_assert(nullptr != mat);
    ai_assert(nullptr != q);
    *mat = q->GetMatrix();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API int aiMatrix3AreEqual(
        const C_STRUCT aiMatrix3x3 *a,
        const C_STRUCT aiMatrix3x3 *b) {
    ai_assert(nullptr != a);
    ai_assert(nullptr != b);
    return *a == *b;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API int aiMatrix3AreEqualEpsilon(
        const C_STRUCT aiMatrix3x3 *a,
        const C_STRUCT aiMatrix3x3 *b,
        const float epsilon) {
    ai_assert(nullptr != a);
    ai_assert(nullptr != b);
    return a->Equal(*b, epsilon);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix3Inverse(C_STRUCT aiMatrix3x3 *mat) {
    ai_assert(nullptr != mat);
    mat->Inverse();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiMatrix3Determinant(const C_STRUCT aiMatrix3x3 *mat) {
    ai_assert(nullptr != mat);
    return mat->Determinant();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix3RotationZ(
        C_STRUCT aiMatrix3x3 *mat,
        const float angle) {
    ai_assert(nullptr != mat);
    aiMatrix3x3::RotationZ(angle, *mat);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix3FromRotationAroundAxis(
        C_STRUCT aiMatrix3x3 *mat,
        const C_STRUCT aiVector3D *axis,
        const float angle) {
    ai_assert(nullptr != mat);
    ai_assert(nullptr != axis);
    aiMatrix3x3::Rotation(angle, *axis, *mat);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix3Translation(
        C_STRUCT aiMatrix3x3 *mat,
        const C_STRUCT aiVector2D *translation) {
    ai_assert(nullptr != mat);
    ai_assert(nullptr != translation);
    aiMatrix3x3::Translation(*translation, *mat);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix3FromTo(
        C_STRUCT aiMatrix3x3 *mat,
        const C_STRUCT aiVector3D *from,
        const C_STRUCT aiVector3D *to) {
    ai_assert(nullptr != mat);
    ai_assert(nullptr != from);
    ai_assert(nullptr != to);
    aiMatrix3x3::FromToMatrix(*from, *to, *mat);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix4FromMatrix3(
        C_STRUCT aiMatrix4x4 *dst,
        const C_STRUCT aiMatrix3x3 *mat) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != mat);
    *dst = aiMatrix4x4(*mat);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix4FromScalingQuaternionPosition(
        C_STRUCT aiMatrix4x4 *mat,
        const C_STRUCT aiVector3D *scaling,
        const C_STRUCT aiQuaternion *rotation,
        const C_STRUCT aiVector3D *position) {
    ai_assert(nullptr != mat);
    ai_assert(nullptr != scaling);
    ai_assert(nullptr != rotation);
    ai_assert(nullptr != position);
    *mat = aiMatrix4x4(*scaling, *rotation, *position);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix4Add(
        C_STRUCT aiMatrix4x4 *dst,
        const C_STRUCT aiMatrix4x4 *src) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != src);
    *dst = *dst + *src;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API int aiMatrix4AreEqual(
        const C_STRUCT aiMatrix4x4 *a,
        const C_STRUCT aiMatrix4x4 *b) {
    ai_assert(nullptr != a);
    ai_assert(nullptr != b);
    return *a == *b;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API int aiMatrix4AreEqualEpsilon(
        const C_STRUCT aiMatrix4x4 *a,
        const C_STRUCT aiMatrix4x4 *b,
        const float epsilon) {
    ai_assert(nullptr != a);
    ai_assert(nullptr != b);
    return a->Equal(*b, epsilon);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix4Inverse(C_STRUCT aiMatrix4x4 *mat) {
    ai_assert(nullptr != mat);
    mat->Inverse();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiMatrix4Determinant(const C_STRUCT aiMatrix4x4 *mat) {
    ai_assert(nullptr != mat);
    return mat->Determinant();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API int aiMatrix4IsIdentity(const C_STRUCT aiMatrix4x4 *mat) {
    ai_assert(nullptr != mat);
    return mat->IsIdentity();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix4DecomposeIntoScalingEulerAnglesPosition(
        const C_STRUCT aiMatrix4x4 *mat,
        C_STRUCT aiVector3D *scaling,
        C_STRUCT aiVector3D *rotation,
        C_STRUCT aiVector3D *position) {
    ai_assert(nullptr != mat);
    ai_assert(nullptr != scaling);
    ai_assert(nullptr != rotation);
    ai_assert(nullptr != position);
    mat->Decompose(*scaling, *rotation, *position);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix4DecomposeIntoScalingAxisAnglePosition(
        const C_STRUCT aiMatrix4x4 *mat,
        C_STRUCT aiVector3D *scaling,
        C_STRUCT aiVector3D *axis,
        ai_real *angle,
        C_STRUCT aiVector3D *position) {
    ai_assert(nullptr != mat);
    ai_assert(nullptr != scaling);
    ai_assert(nullptr != axis);
    ai_assert(nullptr != angle);
    ai_assert(nullptr != position);
    mat->Decompose(*scaling, *axis, *angle, *position);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix4DecomposeNoScaling(
        const C_STRUCT aiMatrix4x4 *mat,
        C_STRUCT aiQuaternion *rotation,
        C_STRUCT aiVector3D *position) {
    ai_assert(nullptr != mat);
    ai_assert(nullptr != rotation);
    ai_assert(nullptr != position);
    mat->DecomposeNoScaling(*rotation, *position);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix4FromEulerAngles(
        C_STRUCT aiMatrix4x4 *mat,
        float x, float y, float z) {
    ai_assert(nullptr != mat);
    mat->FromEulerAnglesXYZ(x, y, z);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix4RotationX(
        C_STRUCT aiMatrix4x4 *mat,
        const float angle) {
    ai_assert(nullptr != mat);
    aiMatrix4x4::RotationX(angle, *mat);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix4RotationY(
        C_STRUCT aiMatrix4x4 *mat,
        const float angle) {
    ai_assert(NULL != mat);
    aiMatrix4x4::RotationY(angle, *mat);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix4RotationZ(
        C_STRUCT aiMatrix4x4 *mat,
        const float angle) {
    ai_assert(nullptr != mat);
    aiMatrix4x4::RotationZ(angle, *mat);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix4FromRotationAroundAxis(
        C_STRUCT aiMatrix4x4 *mat,
        const C_STRUCT aiVector3D *axis,
        const float angle) {
    ai_assert(nullptr != mat);
    ai_assert(nullptr != axis);
    aiMatrix4x4::Rotation(angle, *axis, *mat);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix4Translation(
        C_STRUCT aiMatrix4x4 *mat,
        const C_STRUCT aiVector3D *translation) {
    ai_assert(nullptr != mat);
    ai_assert(nullptr != translation);
    aiMatrix4x4::Translation(*translation, *mat);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix4Scaling(
        C_STRUCT aiMatrix4x4 *mat,
        const C_STRUCT aiVector3D *scaling) {
    ai_assert(nullptr != mat);
    ai_assert(nullptr != scaling);
    aiMatrix4x4::Scaling(*scaling, *mat);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMatrix4FromTo(
        C_STRUCT aiMatrix4x4 *mat,
        const C_STRUCT aiVector3D *from,
        const C_STRUCT aiVector3D *to) {
    ai_assert(nullptr != mat);
    ai_assert(nullptr != from);
    ai_assert(nullptr != to);
    aiMatrix4x4::FromToMatrix(*from, *to, *mat);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiQuaternionFromEulerAngles(
        C_STRUCT aiQuaternion *q,
        float x, float y, float z) {
    ai_assert(nullptr != q);
    *q = aiQuaternion(x, y, z);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiQuaternionFromAxisAngle(
        C_STRUCT aiQuaternion *q,
        const C_STRUCT aiVector3D *axis,
        const float angle) {
    ai_assert(nullptr != q);
    ai_assert(nullptr != axis);
    *q = aiQuaternion(*axis, angle);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiQuaternionFromNormalizedQuaternion(
        C_STRUCT aiQuaternion *q,
        const C_STRUCT aiVector3D *normalized) {
    ai_assert(nullptr != q);
    ai_assert(nullptr != normalized);
    *q = aiQuaternion(*normalized);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API int aiQuaternionAreEqual(
        const C_STRUCT aiQuaternion *a,
        const C_STRUCT aiQuaternion *b) {
    ai_assert(nullptr != a);
    ai_assert(nullptr != b);
    return *a == *b;
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API int aiQuaternionAreEqualEpsilon(
        const C_STRUCT aiQuaternion *a,
        const C_STRUCT aiQuaternion *b,
        const float epsilon) {
    ai_assert(nullptr != a);
    ai_assert(nullptr != b);
    return a->Equal(*b, epsilon);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiQuaternionNormalize(
        C_STRUCT aiQuaternion *q) {
    ai_assert(nullptr != q);
    q->Normalize();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiQuaternionConjugate(
        C_STRUCT aiQuaternion *q) {
    ai_assert(nullptr != q);
    q->Conjugate();
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiQuaternionMultiply(
        C_STRUCT aiQuaternion *dst,
        const C_STRUCT aiQuaternion *q) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != q);
    *dst = (*dst) * (*q);
}

// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiQuaternionInterpolate(
        C_STRUCT aiQuaternion *dst,
        const C_STRUCT aiQuaternion *start,
        const C_STRUCT aiQuaternion *end,
        const float factor) {
    ai_assert(nullptr != dst);
    ai_assert(nullptr != start);
    ai_assert(nullptr != end);
    aiQuaternion::Interpolate(*dst, *start, *end, factor);
}


// stb_image is a lightweight image loader. It is shared by:
//  - M3D import
//  - PBRT export
// Since it's a header-only library, its implementation must be instantiated in some cpp file.
// Don't scatter this task over multiple importers/exporters. Maintain it in a central place (here!).

#define ASSIMP_HAS_PBRT_EXPORT (!ASSIMP_BUILD_NO_EXPORT && !ASSIMP_BUILD_NO_PBRT_EXPORTER)
#define ASSIMP_HAS_M3D ((!ASSIMP_BUILD_NO_EXPORT && !ASSIMP_BUILD_NO_M3D_EXPORTER) || !ASSIMP_BUILD_NO_M3D_IMPORTER)

#if ASSIMP_HAS_PBRT_EXPORT
#   define ASSIMP_NEEDS_STB_IMAGE 1
#elif ASSIMP_HAS_M3D
#   define ASSIMP_NEEDS_STB_IMAGE 1
#   define STBI_ONLY_PNG
#endif

#if ASSIMP_NEEDS_STB_IMAGE

#   if _MSC_VER // "unreferenced function has been removed" (SSE2 detection routine in x64 builds)
#       pragma warning(push)
#       pragma warning(disable: 4505)
#   endif

#   define STB_IMAGE_IMPLEMENTATION
#   include "stb/stb_image.h"

#   if _MSC_VER
#       pragma warning(pop)
#   endif

#endif