Assimp.cpp 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2024, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file Assimp.cpp
  35. * @brief Implementation of the Plain-C API
  36. */
  37. #include <assimp/BaseImporter.h>
  38. #include <assimp/Exceptional.h>
  39. #include <assimp/GenericProperty.h>
  40. #include <assimp/cimport.h>
  41. #include <assimp/importerdesc.h>
  42. #include <assimp/scene.h>
  43. #include <assimp/DefaultLogger.hpp>
  44. #include <assimp/Importer.hpp>
  45. #include <assimp/LogStream.hpp>
  46. #include "CApi/CInterfaceIOWrapper.h"
  47. #include "Importer.h"
  48. #include "ScenePrivate.h"
  49. #include <list>
  50. // ------------------------------------------------------------------------------------------------
  51. #ifndef ASSIMP_BUILD_SINGLETHREADED
  52. #include <mutex>
  53. #include <thread>
  54. #endif
  55. // ------------------------------------------------------------------------------------------------
  56. using namespace Assimp;
  57. namespace Assimp {
  58. // underlying structure for aiPropertyStore
  59. typedef BatchLoader::PropertyMap PropertyMap;
  60. #if defined(__has_warning)
  61. #if __has_warning("-Wordered-compare-function-pointers")
  62. #pragma GCC diagnostic push
  63. #pragma GCC diagnostic ignored "-Wordered-compare-function-pointers"
  64. #endif
  65. #endif
  66. /** Stores the LogStream objects for all active C log streams */
  67. struct mpred {
  68. bool operator()(const aiLogStream &s0, const aiLogStream &s1) const {
  69. return s0.callback < s1.callback && s0.user < s1.user;
  70. }
  71. };
  72. #if defined(__has_warning)
  73. #if __has_warning("-Wordered-compare-function-pointers")
  74. #pragma GCC diagnostic pop
  75. #endif
  76. #endif
  77. typedef std::map<aiLogStream, Assimp::LogStream *, mpred> LogStreamMap;
  78. /** Stores the LogStream objects allocated by #aiGetPredefinedLogStream */
  79. typedef std::list<Assimp::LogStream *> PredefLogStreamMap;
  80. /** Local storage of all active log streams */
  81. static LogStreamMap gActiveLogStreams;
  82. /** Local storage of LogStreams allocated by #aiGetPredefinedLogStream */
  83. static PredefLogStreamMap gPredefinedStreams;
  84. /** Error message of the last failed import process */
  85. static std::string gLastErrorString;
  86. /** Verbose logging active or not? */
  87. static aiBool gVerboseLogging = false;
  88. /** will return all registered importers. */
  89. void GetImporterInstanceList(std::vector<BaseImporter *> &out);
  90. /** will delete all registered importers. */
  91. void DeleteImporterInstanceList(std::vector<BaseImporter *> &out);
  92. } // namespace Assimp
  93. #ifndef ASSIMP_BUILD_SINGLETHREADED
  94. /** Global mutex to manage the access to the log-stream map */
  95. static std::mutex gLogStreamMutex;
  96. #endif
  97. // ------------------------------------------------------------------------------------------------
  98. // Custom LogStream implementation for the C-API
  99. class LogToCallbackRedirector : public LogStream {
  100. public:
  101. explicit LogToCallbackRedirector(const aiLogStream &s) :
  102. stream(s) {
  103. ai_assert(nullptr != s.callback);
  104. }
  105. ~LogToCallbackRedirector() {
  106. #ifndef ASSIMP_BUILD_SINGLETHREADED
  107. std::lock_guard<std::mutex> lock(gLogStreamMutex);
  108. #endif
  109. // (HACK) Check whether the 'stream.user' pointer points to a
  110. // custom LogStream allocated by #aiGetPredefinedLogStream.
  111. // In this case, we need to delete it, too. Of course, this
  112. // might cause strange problems, but the chance is quite low.
  113. PredefLogStreamMap::iterator it = std::find(gPredefinedStreams.begin(),
  114. gPredefinedStreams.end(), (Assimp::LogStream *)stream.user);
  115. if (it != gPredefinedStreams.end()) {
  116. delete *it;
  117. gPredefinedStreams.erase(it);
  118. }
  119. }
  120. /** @copydoc LogStream::write */
  121. void write(const char *message) {
  122. stream.callback(message, stream.user);
  123. }
  124. private:
  125. aiLogStream stream;
  126. };
  127. // ------------------------------------------------------------------------------------------------
  128. void ReportSceneNotFoundError() {
  129. ASSIMP_LOG_ERROR("Unable to find the Assimp::Importer for this aiScene. "
  130. "The C-API does not accept scenes produced by the C++ API and vice versa");
  131. ai_assert(false);
  132. }
  133. // ------------------------------------------------------------------------------------------------
  134. // Reads the given file and returns its content.
  135. const aiScene *aiImportFile(const char *pFile, unsigned int pFlags) {
  136. return aiImportFileEx(pFile, pFlags, nullptr);
  137. }
  138. // ------------------------------------------------------------------------------------------------
  139. const aiScene *aiImportFileEx(const char *pFile, unsigned int pFlags, aiFileIO *pFS) {
  140. return aiImportFileExWithProperties(pFile, pFlags, pFS, nullptr);
  141. }
  142. // ------------------------------------------------------------------------------------------------
  143. const aiScene *aiImportFileExWithProperties(const char *pFile, unsigned int pFlags,
  144. aiFileIO *pFS, const aiPropertyStore *props) {
  145. ai_assert(nullptr != pFile);
  146. const aiScene *scene = nullptr;
  147. ASSIMP_BEGIN_EXCEPTION_REGION();
  148. // create an Importer for this file
  149. Assimp::Importer *imp = new Assimp::Importer();
  150. // copy properties
  151. if (props) {
  152. const PropertyMap *pp = reinterpret_cast<const PropertyMap *>(props);
  153. ImporterPimpl *pimpl = imp->Pimpl();
  154. pimpl->mIntProperties = pp->ints;
  155. pimpl->mFloatProperties = pp->floats;
  156. pimpl->mStringProperties = pp->strings;
  157. pimpl->mMatrixProperties = pp->matrices;
  158. }
  159. // setup a custom IO system if necessary
  160. if (pFS) {
  161. imp->SetIOHandler(new CIOSystemWrapper(pFS));
  162. }
  163. // and have it read the file
  164. scene = imp->ReadFile(pFile, pFlags);
  165. // if succeeded, store the importer in the scene and keep it alive
  166. if (scene) {
  167. ScenePrivateData *priv = const_cast<ScenePrivateData *>(ScenePriv(scene));
  168. priv->mOrigImporter = imp;
  169. } else {
  170. // if failed, extract error code and destroy the import
  171. gLastErrorString = imp->GetErrorString();
  172. delete imp;
  173. }
  174. // return imported data. If the import failed the pointer is nullptr anyways
  175. ASSIMP_END_EXCEPTION_REGION(const aiScene *);
  176. return scene;
  177. }
  178. // ------------------------------------------------------------------------------------------------
  179. const aiScene *aiImportFileFromMemory(
  180. const char *pBuffer,
  181. unsigned int pLength,
  182. unsigned int pFlags,
  183. const char *pHint) {
  184. return aiImportFileFromMemoryWithProperties(pBuffer, pLength, pFlags, pHint, nullptr);
  185. }
  186. // ------------------------------------------------------------------------------------------------
  187. const aiScene *aiImportFileFromMemoryWithProperties(
  188. const char *pBuffer,
  189. unsigned int pLength,
  190. unsigned int pFlags,
  191. const char *pHint,
  192. const aiPropertyStore *props) {
  193. if (pBuffer == nullptr) {
  194. return nullptr;
  195. }
  196. if (pLength == 0u) {
  197. return nullptr;
  198. }
  199. const aiScene *scene = nullptr;
  200. ASSIMP_BEGIN_EXCEPTION_REGION();
  201. // create an Importer for this file
  202. Assimp::Importer *imp = new Assimp::Importer();
  203. // copy properties
  204. if (props) {
  205. const PropertyMap *pp = reinterpret_cast<const PropertyMap *>(props);
  206. ImporterPimpl *pimpl = imp->Pimpl();
  207. pimpl->mIntProperties = pp->ints;
  208. pimpl->mFloatProperties = pp->floats;
  209. pimpl->mStringProperties = pp->strings;
  210. pimpl->mMatrixProperties = pp->matrices;
  211. }
  212. // and have it read the file from the memory buffer
  213. scene = imp->ReadFileFromMemory(pBuffer, pLength, pFlags, pHint);
  214. // if succeeded, store the importer in the scene and keep it alive
  215. if (scene) {
  216. ScenePrivateData *priv = const_cast<ScenePrivateData *>(ScenePriv(scene));
  217. priv->mOrigImporter = imp;
  218. } else {
  219. // if failed, extract error code and destroy the import
  220. gLastErrorString = imp->GetErrorString();
  221. delete imp;
  222. }
  223. // return imported data. If the import failed the pointer is nullptr anyways
  224. ASSIMP_END_EXCEPTION_REGION(const aiScene *);
  225. return scene;
  226. }
  227. // ------------------------------------------------------------------------------------------------
  228. // Releases all resources associated with the given import process.
  229. void aiReleaseImport(const aiScene *pScene) {
  230. if (!pScene) {
  231. return;
  232. }
  233. ASSIMP_BEGIN_EXCEPTION_REGION();
  234. // find the importer associated with this data
  235. const ScenePrivateData *priv = ScenePriv(pScene);
  236. if (!priv || !priv->mOrigImporter) {
  237. delete pScene;
  238. } else {
  239. // deleting the Importer also deletes the scene
  240. // Note: the reason that this is not written as 'delete priv->mOrigImporter'
  241. // is a suspected bug in gcc 4.4+ (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52339)
  242. Importer *importer = priv->mOrigImporter;
  243. delete importer;
  244. }
  245. ASSIMP_END_EXCEPTION_REGION(void);
  246. }
  247. // ------------------------------------------------------------------------------------------------
  248. ASSIMP_API const aiScene *aiApplyPostProcessing(const aiScene *pScene,
  249. unsigned int pFlags) {
  250. const aiScene *sc = nullptr;
  251. ASSIMP_BEGIN_EXCEPTION_REGION();
  252. // find the importer associated with this data
  253. const ScenePrivateData *priv = ScenePriv(pScene);
  254. if (!priv || !priv->mOrigImporter) {
  255. ReportSceneNotFoundError();
  256. return nullptr;
  257. }
  258. sc = priv->mOrigImporter->ApplyPostProcessing(pFlags);
  259. if (!sc) {
  260. aiReleaseImport(pScene);
  261. return nullptr;
  262. }
  263. ASSIMP_END_EXCEPTION_REGION(const aiScene *);
  264. return sc;
  265. }
  266. // ------------------------------------------------------------------------------------------------
  267. ASSIMP_API const aiScene *aiApplyCustomizedPostProcessing(const aiScene *scene,
  268. BaseProcess *process,
  269. bool requestValidation) {
  270. const aiScene *sc(nullptr);
  271. ASSIMP_BEGIN_EXCEPTION_REGION();
  272. // find the importer associated with this data
  273. const ScenePrivateData *priv = ScenePriv(scene);
  274. if (nullptr == priv || nullptr == priv->mOrigImporter) {
  275. ReportSceneNotFoundError();
  276. return nullptr;
  277. }
  278. sc = priv->mOrigImporter->ApplyCustomizedPostProcessing(process, requestValidation);
  279. if (!sc) {
  280. aiReleaseImport(scene);
  281. return nullptr;
  282. }
  283. ASSIMP_END_EXCEPTION_REGION(const aiScene *);
  284. return sc;
  285. }
  286. // ------------------------------------------------------------------------------------------------
  287. void CallbackToLogRedirector(const char *msg, char *dt) {
  288. ai_assert(nullptr != msg);
  289. ai_assert(nullptr != dt);
  290. LogStream *s = (LogStream *)dt;
  291. s->write(msg);
  292. }
  293. // ------------------------------------------------------------------------------------------------
  294. ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream, const char *file) {
  295. aiLogStream sout;
  296. ASSIMP_BEGIN_EXCEPTION_REGION();
  297. LogStream *stream = LogStream::createDefaultStream(pStream, file);
  298. if (!stream) {
  299. sout.callback = nullptr;
  300. sout.user = nullptr;
  301. } else {
  302. sout.callback = &CallbackToLogRedirector;
  303. sout.user = (char *)stream;
  304. }
  305. gPredefinedStreams.push_back(stream);
  306. ASSIMP_END_EXCEPTION_REGION(aiLogStream);
  307. return sout;
  308. }
  309. // ------------------------------------------------------------------------------------------------
  310. ASSIMP_API void aiAttachLogStream(const aiLogStream *stream) {
  311. ASSIMP_BEGIN_EXCEPTION_REGION();
  312. #ifndef ASSIMP_BUILD_SINGLETHREADED
  313. std::lock_guard<std::mutex> lock(gLogStreamMutex);
  314. #endif
  315. LogStream *lg = new LogToCallbackRedirector(*stream);
  316. gActiveLogStreams[*stream] = lg;
  317. if (DefaultLogger::isNullLogger()) {
  318. DefaultLogger::create(nullptr, (gVerboseLogging == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
  319. }
  320. DefaultLogger::get()->attachStream(lg);
  321. ASSIMP_END_EXCEPTION_REGION(void);
  322. }
  323. // ------------------------------------------------------------------------------------------------
  324. ASSIMP_API aiReturn aiDetachLogStream(const aiLogStream *stream) {
  325. ASSIMP_BEGIN_EXCEPTION_REGION();
  326. #ifndef ASSIMP_BUILD_SINGLETHREADED
  327. std::lock_guard<std::mutex> lock(gLogStreamMutex);
  328. #endif
  329. // find the log-stream associated with this data
  330. LogStreamMap::iterator it = gActiveLogStreams.find(*stream);
  331. // it should be there... else the user is playing fools with us
  332. if (it == gActiveLogStreams.end()) {
  333. return AI_FAILURE;
  334. }
  335. DefaultLogger::get()->detachStream(it->second);
  336. delete it->second;
  337. gActiveLogStreams.erase(it);
  338. if (gActiveLogStreams.empty()) {
  339. DefaultLogger::kill();
  340. }
  341. ASSIMP_END_EXCEPTION_REGION(aiReturn);
  342. return AI_SUCCESS;
  343. }
  344. // ------------------------------------------------------------------------------------------------
  345. ASSIMP_API void aiDetachAllLogStreams(void) {
  346. ASSIMP_BEGIN_EXCEPTION_REGION();
  347. #ifndef ASSIMP_BUILD_SINGLETHREADED
  348. std::lock_guard<std::mutex> lock(gLogStreamMutex);
  349. #endif
  350. Logger *logger(DefaultLogger::get());
  351. if (nullptr == logger) {
  352. return;
  353. }
  354. for (LogStreamMap::iterator it = gActiveLogStreams.begin(); it != gActiveLogStreams.end(); ++it) {
  355. logger->detachStream(it->second);
  356. delete it->second;
  357. }
  358. gActiveLogStreams.clear();
  359. DefaultLogger::kill();
  360. ASSIMP_END_EXCEPTION_REGION(void);
  361. }
  362. // ------------------------------------------------------------------------------------------------
  363. ASSIMP_API void aiEnableVerboseLogging(aiBool d) {
  364. if (!DefaultLogger::isNullLogger()) {
  365. DefaultLogger::get()->setLogSeverity((d == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
  366. }
  367. gVerboseLogging = d;
  368. }
  369. // ------------------------------------------------------------------------------------------------
  370. // Returns the error text of the last failed import process.
  371. const char *aiGetErrorString() {
  372. return gLastErrorString.c_str();
  373. }
  374. // -----------------------------------------------------------------------------------------------
  375. // Return the description of a importer given its index
  376. const aiImporterDesc *aiGetImportFormatDescription(size_t pIndex) {
  377. return Importer().GetImporterInfo(pIndex);
  378. }
  379. // -----------------------------------------------------------------------------------------------
  380. // Return the number of importers
  381. size_t aiGetImportFormatCount(void) {
  382. return Importer().GetImporterCount();
  383. }
  384. // ------------------------------------------------------------------------------------------------
  385. // Returns the error text of the last failed import process.
  386. aiBool aiIsExtensionSupported(const char *szExtension) {
  387. ai_assert(nullptr != szExtension);
  388. aiBool candoit = AI_FALSE;
  389. ASSIMP_BEGIN_EXCEPTION_REGION();
  390. // FIXME: no need to create a temporary Importer instance just for that ..
  391. Assimp::Importer tmp;
  392. candoit = tmp.IsExtensionSupported(std::string(szExtension)) ? AI_TRUE : AI_FALSE;
  393. ASSIMP_END_EXCEPTION_REGION(aiBool);
  394. return candoit;
  395. }
  396. // ------------------------------------------------------------------------------------------------
  397. // Get a list of all file extensions supported by ASSIMP
  398. void aiGetExtensionList(aiString *szOut) {
  399. ai_assert(nullptr != szOut);
  400. ASSIMP_BEGIN_EXCEPTION_REGION();
  401. // FIXME: no need to create a temporary Importer instance just for that ..
  402. Assimp::Importer tmp;
  403. tmp.GetExtensionList(*szOut);
  404. ASSIMP_END_EXCEPTION_REGION(void);
  405. }
  406. // ------------------------------------------------------------------------------------------------
  407. // Get the memory requirements for a particular import.
  408. void aiGetMemoryRequirements(const C_STRUCT aiScene *pIn,
  409. C_STRUCT aiMemoryInfo *in) {
  410. ASSIMP_BEGIN_EXCEPTION_REGION();
  411. // find the importer associated with this data
  412. const ScenePrivateData *priv = ScenePriv(pIn);
  413. if (!priv || !priv->mOrigImporter) {
  414. ReportSceneNotFoundError();
  415. return;
  416. }
  417. return priv->mOrigImporter->GetMemoryRequirements(*in);
  418. ASSIMP_END_EXCEPTION_REGION(void);
  419. }
  420. // ------------------------------------------------------------------------------------------------
  421. ASSIMP_API aiPropertyStore *aiCreatePropertyStore(void) {
  422. return reinterpret_cast<aiPropertyStore *>(new PropertyMap());
  423. }
  424. // ------------------------------------------------------------------------------------------------
  425. ASSIMP_API void aiReleasePropertyStore(aiPropertyStore *p) {
  426. delete reinterpret_cast<PropertyMap *>(p);
  427. }
  428. // ------------------------------------------------------------------------------------------------
  429. // Importer::SetPropertyInteger
  430. ASSIMP_API void aiSetImportPropertyInteger(aiPropertyStore *p, const char *szName, int value) {
  431. ASSIMP_BEGIN_EXCEPTION_REGION();
  432. PropertyMap *pp = reinterpret_cast<PropertyMap *>(p);
  433. SetGenericProperty<int>(pp->ints, szName, value);
  434. ASSIMP_END_EXCEPTION_REGION(void);
  435. }
  436. // ------------------------------------------------------------------------------------------------
  437. // Importer::SetPropertyFloat
  438. ASSIMP_API void aiSetImportPropertyFloat(aiPropertyStore *p, const char *szName, ai_real value) {
  439. ASSIMP_BEGIN_EXCEPTION_REGION();
  440. PropertyMap *pp = reinterpret_cast<PropertyMap *>(p);
  441. SetGenericProperty<ai_real>(pp->floats, szName, value);
  442. ASSIMP_END_EXCEPTION_REGION(void);
  443. }
  444. // ------------------------------------------------------------------------------------------------
  445. // Importer::SetPropertyString
  446. ASSIMP_API void aiSetImportPropertyString(aiPropertyStore *p, const char *szName,
  447. const C_STRUCT aiString *st) {
  448. if (!st) {
  449. return;
  450. }
  451. ASSIMP_BEGIN_EXCEPTION_REGION();
  452. PropertyMap *pp = reinterpret_cast<PropertyMap *>(p);
  453. SetGenericProperty<std::string>(pp->strings, szName, std::string(st->C_Str()));
  454. ASSIMP_END_EXCEPTION_REGION(void);
  455. }
  456. // ------------------------------------------------------------------------------------------------
  457. // Importer::SetPropertyMatrix
  458. ASSIMP_API void aiSetImportPropertyMatrix(aiPropertyStore *p, const char *szName,
  459. const C_STRUCT aiMatrix4x4 *mat) {
  460. if (!mat) {
  461. return;
  462. }
  463. ASSIMP_BEGIN_EXCEPTION_REGION();
  464. PropertyMap *pp = reinterpret_cast<PropertyMap *>(p);
  465. SetGenericProperty<aiMatrix4x4>(pp->matrices, szName, *mat);
  466. ASSIMP_END_EXCEPTION_REGION(void);
  467. }
  468. // ------------------------------------------------------------------------------------------------
  469. // Rotation matrix to quaternion
  470. ASSIMP_API void aiCreateQuaternionFromMatrix(aiQuaternion *quat, const aiMatrix3x3 *mat) {
  471. ai_assert(nullptr != quat);
  472. ai_assert(nullptr != mat);
  473. *quat = aiQuaternion(*mat);
  474. }
  475. // ------------------------------------------------------------------------------------------------
  476. // Matrix decomposition
  477. ASSIMP_API void aiDecomposeMatrix(const aiMatrix4x4 *mat, aiVector3D *scaling,
  478. aiQuaternion *rotation,
  479. aiVector3D *position) {
  480. ai_assert(nullptr != rotation);
  481. ai_assert(nullptr != position);
  482. ai_assert(nullptr != scaling);
  483. ai_assert(nullptr != mat);
  484. mat->Decompose(*scaling, *rotation, *position);
  485. }
  486. // ------------------------------------------------------------------------------------------------
  487. // Matrix transpose
  488. ASSIMP_API void aiTransposeMatrix3(aiMatrix3x3 *mat) {
  489. ai_assert(nullptr != mat);
  490. mat->Transpose();
  491. }
  492. // ------------------------------------------------------------------------------------------------
  493. ASSIMP_API void aiTransposeMatrix4(aiMatrix4x4 *mat) {
  494. ai_assert(nullptr != mat);
  495. mat->Transpose();
  496. }
  497. // ------------------------------------------------------------------------------------------------
  498. // Vector transformation
  499. ASSIMP_API void aiTransformVecByMatrix3(aiVector3D *vec,
  500. const aiMatrix3x3 *mat) {
  501. ai_assert(nullptr != mat);
  502. ai_assert(nullptr != vec);
  503. *vec *= (*mat);
  504. }
  505. // ------------------------------------------------------------------------------------------------
  506. ASSIMP_API void aiTransformVecByMatrix4(aiVector3D *vec,
  507. const aiMatrix4x4 *mat) {
  508. ai_assert(nullptr != mat);
  509. ai_assert(nullptr != vec);
  510. *vec *= (*mat);
  511. }
  512. // ------------------------------------------------------------------------------------------------
  513. // Matrix multiplication
  514. ASSIMP_API void aiMultiplyMatrix4(
  515. aiMatrix4x4 *dst,
  516. const aiMatrix4x4 *src) {
  517. ai_assert(nullptr != dst);
  518. ai_assert(nullptr != src);
  519. *dst = (*dst) * (*src);
  520. }
  521. // ------------------------------------------------------------------------------------------------
  522. ASSIMP_API void aiMultiplyMatrix3(
  523. aiMatrix3x3 *dst,
  524. const aiMatrix3x3 *src) {
  525. ai_assert(nullptr != dst);
  526. ai_assert(nullptr != src);
  527. *dst = (*dst) * (*src);
  528. }
  529. // ------------------------------------------------------------------------------------------------
  530. // Matrix identity
  531. ASSIMP_API void aiIdentityMatrix3(
  532. aiMatrix3x3 *mat) {
  533. ai_assert(nullptr != mat);
  534. *mat = aiMatrix3x3();
  535. }
  536. // ------------------------------------------------------------------------------------------------
  537. ASSIMP_API void aiIdentityMatrix4(
  538. aiMatrix4x4 *mat) {
  539. ai_assert(nullptr != mat);
  540. *mat = aiMatrix4x4();
  541. }
  542. // ------------------------------------------------------------------------------------------------
  543. ASSIMP_API C_STRUCT const aiImporterDesc *aiGetImporterDesc(const char *extension) {
  544. if (nullptr == extension) {
  545. return nullptr;
  546. }
  547. const aiImporterDesc *desc(nullptr);
  548. std::vector<BaseImporter *> out;
  549. GetImporterInstanceList(out);
  550. for (size_t i = 0; i < out.size(); ++i) {
  551. if (0 == strncmp(out[i]->GetInfo()->mFileExtensions, extension, strlen(extension))) {
  552. desc = out[i]->GetInfo();
  553. break;
  554. }
  555. }
  556. DeleteImporterInstanceList(out);
  557. return desc;
  558. }
  559. // ------------------------------------------------------------------------------------------------
  560. ASSIMP_API int aiVector2AreEqual(
  561. const C_STRUCT aiVector2D *a,
  562. const C_STRUCT aiVector2D *b) {
  563. ai_assert(nullptr != a);
  564. ai_assert(nullptr != b);
  565. return *a == *b;
  566. }
  567. // ------------------------------------------------------------------------------------------------
  568. ASSIMP_API int aiVector2AreEqualEpsilon(
  569. const C_STRUCT aiVector2D *a,
  570. const C_STRUCT aiVector2D *b,
  571. const float epsilon) {
  572. ai_assert(nullptr != a);
  573. ai_assert(nullptr != b);
  574. return a->Equal(*b, epsilon);
  575. }
  576. // ------------------------------------------------------------------------------------------------
  577. ASSIMP_API void aiVector2Add(
  578. C_STRUCT aiVector2D *dst,
  579. const C_STRUCT aiVector2D *src) {
  580. ai_assert(nullptr != dst);
  581. ai_assert(nullptr != src);
  582. *dst = *dst + *src;
  583. }
  584. // ------------------------------------------------------------------------------------------------
  585. ASSIMP_API void aiVector2Subtract(
  586. C_STRUCT aiVector2D *dst,
  587. const C_STRUCT aiVector2D *src) {
  588. ai_assert(nullptr != dst);
  589. ai_assert(nullptr != src);
  590. *dst = *dst - *src;
  591. }
  592. // ------------------------------------------------------------------------------------------------
  593. ASSIMP_API void aiVector2Scale(
  594. C_STRUCT aiVector2D *dst,
  595. const float s) {
  596. ai_assert(nullptr != dst);
  597. *dst *= s;
  598. }
  599. // ------------------------------------------------------------------------------------------------
  600. ASSIMP_API void aiVector2SymMul(
  601. C_STRUCT aiVector2D *dst,
  602. const C_STRUCT aiVector2D *other) {
  603. ai_assert(nullptr != dst);
  604. ai_assert(nullptr != other);
  605. *dst = dst->SymMul(*other);
  606. }
  607. // ------------------------------------------------------------------------------------------------
  608. ASSIMP_API void aiVector2DivideByScalar(
  609. C_STRUCT aiVector2D *dst,
  610. const float s) {
  611. ai_assert(nullptr != dst);
  612. *dst /= s;
  613. }
  614. // ------------------------------------------------------------------------------------------------
  615. ASSIMP_API void aiVector2DivideByVector(
  616. C_STRUCT aiVector2D *dst,
  617. C_STRUCT aiVector2D *v) {
  618. ai_assert(nullptr != dst);
  619. ai_assert(nullptr != v);
  620. *dst = *dst / *v;
  621. }
  622. // ------------------------------------------------------------------------------------------------
  623. ASSIMP_API float aiVector2Length(
  624. const C_STRUCT aiVector2D *v) {
  625. ai_assert(nullptr != v);
  626. return v->Length();
  627. }
  628. // ------------------------------------------------------------------------------------------------
  629. ASSIMP_API float aiVector2SquareLength(
  630. const C_STRUCT aiVector2D *v) {
  631. ai_assert(nullptr != v);
  632. return v->SquareLength();
  633. }
  634. // ------------------------------------------------------------------------------------------------
  635. ASSIMP_API void aiVector2Negate(
  636. C_STRUCT aiVector2D *dst) {
  637. ai_assert(nullptr != dst);
  638. *dst = -(*dst);
  639. }
  640. // ------------------------------------------------------------------------------------------------
  641. ASSIMP_API float aiVector2DotProduct(
  642. const C_STRUCT aiVector2D *a,
  643. const C_STRUCT aiVector2D *b) {
  644. ai_assert(nullptr != a);
  645. ai_assert(nullptr != b);
  646. return (*a) * (*b);
  647. }
  648. // ------------------------------------------------------------------------------------------------
  649. ASSIMP_API void aiVector2Normalize(
  650. C_STRUCT aiVector2D *v) {
  651. ai_assert(nullptr != v);
  652. v->Normalize();
  653. }
  654. // ------------------------------------------------------------------------------------------------
  655. ASSIMP_API int aiVector3AreEqual(
  656. const C_STRUCT aiVector3D *a,
  657. const C_STRUCT aiVector3D *b) {
  658. ai_assert(nullptr != a);
  659. ai_assert(nullptr != b);
  660. return *a == *b;
  661. }
  662. // ------------------------------------------------------------------------------------------------
  663. ASSIMP_API int aiVector3AreEqualEpsilon(
  664. const C_STRUCT aiVector3D *a,
  665. const C_STRUCT aiVector3D *b,
  666. const float epsilon) {
  667. ai_assert(nullptr != a);
  668. ai_assert(nullptr != b);
  669. return a->Equal(*b, epsilon);
  670. }
  671. // ------------------------------------------------------------------------------------------------
  672. ASSIMP_API int aiVector3LessThan(
  673. const C_STRUCT aiVector3D *a,
  674. const C_STRUCT aiVector3D *b) {
  675. ai_assert(nullptr != a);
  676. ai_assert(nullptr != b);
  677. return *a < *b;
  678. }
  679. // ------------------------------------------------------------------------------------------------
  680. ASSIMP_API void aiVector3Add(
  681. C_STRUCT aiVector3D *dst,
  682. const C_STRUCT aiVector3D *src) {
  683. ai_assert(nullptr != dst);
  684. ai_assert(nullptr != src);
  685. *dst = *dst + *src;
  686. }
  687. // ------------------------------------------------------------------------------------------------
  688. ASSIMP_API void aiVector3Subtract(
  689. C_STRUCT aiVector3D *dst,
  690. const C_STRUCT aiVector3D *src) {
  691. ai_assert(nullptr != dst);
  692. ai_assert(nullptr != src);
  693. *dst = *dst - *src;
  694. }
  695. // ------------------------------------------------------------------------------------------------
  696. ASSIMP_API void aiVector3Scale(
  697. C_STRUCT aiVector3D *dst,
  698. const float s) {
  699. ai_assert(nullptr != dst);
  700. *dst *= s;
  701. }
  702. // ------------------------------------------------------------------------------------------------
  703. ASSIMP_API void aiVector3SymMul(
  704. C_STRUCT aiVector3D *dst,
  705. const C_STRUCT aiVector3D *other) {
  706. ai_assert(nullptr != dst);
  707. ai_assert(nullptr != other);
  708. *dst = dst->SymMul(*other);
  709. }
  710. // ------------------------------------------------------------------------------------------------
  711. ASSIMP_API void aiVector3DivideByScalar(
  712. C_STRUCT aiVector3D *dst, const float s) {
  713. ai_assert(nullptr != dst);
  714. *dst /= s;
  715. }
  716. // ------------------------------------------------------------------------------------------------
  717. ASSIMP_API void aiVector3DivideByVector(
  718. C_STRUCT aiVector3D *dst,
  719. C_STRUCT aiVector3D *v) {
  720. ai_assert(nullptr != dst);
  721. ai_assert(nullptr != v);
  722. *dst = *dst / *v;
  723. }
  724. // ------------------------------------------------------------------------------------------------
  725. ASSIMP_API float aiVector3Length(
  726. const C_STRUCT aiVector3D *v) {
  727. ai_assert(nullptr != v);
  728. return v->Length();
  729. }
  730. // ------------------------------------------------------------------------------------------------
  731. ASSIMP_API float aiVector3SquareLength(
  732. const C_STRUCT aiVector3D *v) {
  733. ai_assert(nullptr != v);
  734. return v->SquareLength();
  735. }
  736. // ------------------------------------------------------------------------------------------------
  737. ASSIMP_API void aiVector3Negate(
  738. C_STRUCT aiVector3D *dst) {
  739. ai_assert(nullptr != dst);
  740. *dst = -(*dst);
  741. }
  742. // ------------------------------------------------------------------------------------------------
  743. ASSIMP_API float aiVector3DotProduct(
  744. const C_STRUCT aiVector3D *a,
  745. const C_STRUCT aiVector3D *b) {
  746. ai_assert(nullptr != a);
  747. ai_assert(nullptr != b);
  748. return (*a) * (*b);
  749. }
  750. // ------------------------------------------------------------------------------------------------
  751. ASSIMP_API void aiVector3CrossProduct(
  752. C_STRUCT aiVector3D *dst,
  753. const C_STRUCT aiVector3D *a,
  754. const C_STRUCT aiVector3D *b) {
  755. ai_assert(nullptr != dst);
  756. ai_assert(nullptr != a);
  757. ai_assert(nullptr != b);
  758. *dst = *a ^ *b;
  759. }
  760. // ------------------------------------------------------------------------------------------------
  761. ASSIMP_API void aiVector3Normalize(
  762. C_STRUCT aiVector3D *v) {
  763. ai_assert(nullptr != v);
  764. v->Normalize();
  765. }
  766. // ------------------------------------------------------------------------------------------------
  767. ASSIMP_API void aiVector3NormalizeSafe(
  768. C_STRUCT aiVector3D *v) {
  769. ai_assert(nullptr != v);
  770. v->NormalizeSafe();
  771. }
  772. // ------------------------------------------------------------------------------------------------
  773. ASSIMP_API void aiVector3RotateByQuaternion(
  774. C_STRUCT aiVector3D *v,
  775. const C_STRUCT aiQuaternion *q) {
  776. ai_assert(nullptr != v);
  777. ai_assert(nullptr != q);
  778. *v = q->Rotate(*v);
  779. }
  780. // ------------------------------------------------------------------------------------------------
  781. ASSIMP_API void aiMatrix3FromMatrix4(
  782. C_STRUCT aiMatrix3x3 *dst,
  783. const C_STRUCT aiMatrix4x4 *mat) {
  784. ai_assert(nullptr != dst);
  785. ai_assert(nullptr != mat);
  786. *dst = aiMatrix3x3(*mat);
  787. }
  788. // ------------------------------------------------------------------------------------------------
  789. ASSIMP_API void aiMatrix3FromQuaternion(
  790. C_STRUCT aiMatrix3x3 *mat,
  791. const C_STRUCT aiQuaternion *q) {
  792. ai_assert(nullptr != mat);
  793. ai_assert(nullptr != q);
  794. *mat = q->GetMatrix();
  795. }
  796. // ------------------------------------------------------------------------------------------------
  797. ASSIMP_API int aiMatrix3AreEqual(
  798. const C_STRUCT aiMatrix3x3 *a,
  799. const C_STRUCT aiMatrix3x3 *b) {
  800. ai_assert(nullptr != a);
  801. ai_assert(nullptr != b);
  802. return *a == *b;
  803. }
  804. // ------------------------------------------------------------------------------------------------
  805. ASSIMP_API int aiMatrix3AreEqualEpsilon(
  806. const C_STRUCT aiMatrix3x3 *a,
  807. const C_STRUCT aiMatrix3x3 *b,
  808. const float epsilon) {
  809. ai_assert(nullptr != a);
  810. ai_assert(nullptr != b);
  811. return a->Equal(*b, epsilon);
  812. }
  813. // ------------------------------------------------------------------------------------------------
  814. ASSIMP_API void aiMatrix3Inverse(C_STRUCT aiMatrix3x3 *mat) {
  815. ai_assert(nullptr != mat);
  816. mat->Inverse();
  817. }
  818. // ------------------------------------------------------------------------------------------------
  819. ASSIMP_API float aiMatrix3Determinant(const C_STRUCT aiMatrix3x3 *mat) {
  820. ai_assert(nullptr != mat);
  821. return mat->Determinant();
  822. }
  823. // ------------------------------------------------------------------------------------------------
  824. ASSIMP_API void aiMatrix3RotationZ(
  825. C_STRUCT aiMatrix3x3 *mat,
  826. const float angle) {
  827. ai_assert(nullptr != mat);
  828. aiMatrix3x3::RotationZ(angle, *mat);
  829. }
  830. // ------------------------------------------------------------------------------------------------
  831. ASSIMP_API void aiMatrix3FromRotationAroundAxis(
  832. C_STRUCT aiMatrix3x3 *mat,
  833. const C_STRUCT aiVector3D *axis,
  834. const float angle) {
  835. ai_assert(nullptr != mat);
  836. ai_assert(nullptr != axis);
  837. aiMatrix3x3::Rotation(angle, *axis, *mat);
  838. }
  839. // ------------------------------------------------------------------------------------------------
  840. ASSIMP_API void aiMatrix3Translation(
  841. C_STRUCT aiMatrix3x3 *mat,
  842. const C_STRUCT aiVector2D *translation) {
  843. ai_assert(nullptr != mat);
  844. ai_assert(nullptr != translation);
  845. aiMatrix3x3::Translation(*translation, *mat);
  846. }
  847. // ------------------------------------------------------------------------------------------------
  848. ASSIMP_API void aiMatrix3FromTo(
  849. C_STRUCT aiMatrix3x3 *mat,
  850. const C_STRUCT aiVector3D *from,
  851. const C_STRUCT aiVector3D *to) {
  852. ai_assert(nullptr != mat);
  853. ai_assert(nullptr != from);
  854. ai_assert(nullptr != to);
  855. aiMatrix3x3::FromToMatrix(*from, *to, *mat);
  856. }
  857. // ------------------------------------------------------------------------------------------------
  858. ASSIMP_API void aiMatrix4FromMatrix3(
  859. C_STRUCT aiMatrix4x4 *dst,
  860. const C_STRUCT aiMatrix3x3 *mat) {
  861. ai_assert(nullptr != dst);
  862. ai_assert(nullptr != mat);
  863. *dst = aiMatrix4x4(*mat);
  864. }
  865. // ------------------------------------------------------------------------------------------------
  866. ASSIMP_API void aiMatrix4FromScalingQuaternionPosition(
  867. C_STRUCT aiMatrix4x4 *mat,
  868. const C_STRUCT aiVector3D *scaling,
  869. const C_STRUCT aiQuaternion *rotation,
  870. const C_STRUCT aiVector3D *position) {
  871. ai_assert(nullptr != mat);
  872. ai_assert(nullptr != scaling);
  873. ai_assert(nullptr != rotation);
  874. ai_assert(nullptr != position);
  875. *mat = aiMatrix4x4(*scaling, *rotation, *position);
  876. }
  877. // ------------------------------------------------------------------------------------------------
  878. ASSIMP_API void aiMatrix4Add(
  879. C_STRUCT aiMatrix4x4 *dst,
  880. const C_STRUCT aiMatrix4x4 *src) {
  881. ai_assert(nullptr != dst);
  882. ai_assert(nullptr != src);
  883. *dst = *dst + *src;
  884. }
  885. // ------------------------------------------------------------------------------------------------
  886. ASSIMP_API int aiMatrix4AreEqual(
  887. const C_STRUCT aiMatrix4x4 *a,
  888. const C_STRUCT aiMatrix4x4 *b) {
  889. ai_assert(nullptr != a);
  890. ai_assert(nullptr != b);
  891. return *a == *b;
  892. }
  893. // ------------------------------------------------------------------------------------------------
  894. ASSIMP_API int aiMatrix4AreEqualEpsilon(
  895. const C_STRUCT aiMatrix4x4 *a,
  896. const C_STRUCT aiMatrix4x4 *b,
  897. const float epsilon) {
  898. ai_assert(nullptr != a);
  899. ai_assert(nullptr != b);
  900. return a->Equal(*b, epsilon);
  901. }
  902. // ------------------------------------------------------------------------------------------------
  903. ASSIMP_API void aiMatrix4Inverse(C_STRUCT aiMatrix4x4 *mat) {
  904. ai_assert(nullptr != mat);
  905. mat->Inverse();
  906. }
  907. // ------------------------------------------------------------------------------------------------
  908. ASSIMP_API float aiMatrix4Determinant(const C_STRUCT aiMatrix4x4 *mat) {
  909. ai_assert(nullptr != mat);
  910. return mat->Determinant();
  911. }
  912. // ------------------------------------------------------------------------------------------------
  913. ASSIMP_API int aiMatrix4IsIdentity(const C_STRUCT aiMatrix4x4 *mat) {
  914. ai_assert(nullptr != mat);
  915. return mat->IsIdentity();
  916. }
  917. // ------------------------------------------------------------------------------------------------
  918. ASSIMP_API void aiMatrix4DecomposeIntoScalingEulerAnglesPosition(
  919. const C_STRUCT aiMatrix4x4 *mat,
  920. C_STRUCT aiVector3D *scaling,
  921. C_STRUCT aiVector3D *rotation,
  922. C_STRUCT aiVector3D *position) {
  923. ai_assert(nullptr != mat);
  924. ai_assert(nullptr != scaling);
  925. ai_assert(nullptr != rotation);
  926. ai_assert(nullptr != position);
  927. mat->Decompose(*scaling, *rotation, *position);
  928. }
  929. // ------------------------------------------------------------------------------------------------
  930. ASSIMP_API void aiMatrix4DecomposeIntoScalingAxisAnglePosition(
  931. const C_STRUCT aiMatrix4x4 *mat,
  932. C_STRUCT aiVector3D *scaling,
  933. C_STRUCT aiVector3D *axis,
  934. ai_real *angle,
  935. C_STRUCT aiVector3D *position) {
  936. ai_assert(nullptr != mat);
  937. ai_assert(nullptr != scaling);
  938. ai_assert(nullptr != axis);
  939. ai_assert(nullptr != angle);
  940. ai_assert(nullptr != position);
  941. mat->Decompose(*scaling, *axis, *angle, *position);
  942. }
  943. // ------------------------------------------------------------------------------------------------
  944. ASSIMP_API void aiMatrix4DecomposeNoScaling(
  945. const C_STRUCT aiMatrix4x4 *mat,
  946. C_STRUCT aiQuaternion *rotation,
  947. C_STRUCT aiVector3D *position) {
  948. ai_assert(nullptr != mat);
  949. ai_assert(nullptr != rotation);
  950. ai_assert(nullptr != position);
  951. mat->DecomposeNoScaling(*rotation, *position);
  952. }
  953. // ------------------------------------------------------------------------------------------------
  954. ASSIMP_API void aiMatrix4FromEulerAngles(
  955. C_STRUCT aiMatrix4x4 *mat,
  956. float x, float y, float z) {
  957. ai_assert(nullptr != mat);
  958. mat->FromEulerAnglesXYZ(x, y, z);
  959. }
  960. // ------------------------------------------------------------------------------------------------
  961. ASSIMP_API void aiMatrix4RotationX(
  962. C_STRUCT aiMatrix4x4 *mat,
  963. const float angle) {
  964. ai_assert(nullptr != mat);
  965. aiMatrix4x4::RotationX(angle, *mat);
  966. }
  967. // ------------------------------------------------------------------------------------------------
  968. ASSIMP_API void aiMatrix4RotationY(
  969. C_STRUCT aiMatrix4x4 *mat,
  970. const float angle) {
  971. ai_assert(nullptr != mat);
  972. aiMatrix4x4::RotationY(angle, *mat);
  973. }
  974. // ------------------------------------------------------------------------------------------------
  975. ASSIMP_API void aiMatrix4RotationZ(
  976. C_STRUCT aiMatrix4x4 *mat,
  977. const float angle) {
  978. ai_assert(nullptr != mat);
  979. aiMatrix4x4::RotationZ(angle, *mat);
  980. }
  981. // ------------------------------------------------------------------------------------------------
  982. ASSIMP_API void aiMatrix4FromRotationAroundAxis(
  983. C_STRUCT aiMatrix4x4 *mat,
  984. const C_STRUCT aiVector3D *axis,
  985. const float angle) {
  986. ai_assert(nullptr != mat);
  987. ai_assert(nullptr != axis);
  988. aiMatrix4x4::Rotation(angle, *axis, *mat);
  989. }
  990. // ------------------------------------------------------------------------------------------------
  991. ASSIMP_API void aiMatrix4Translation(
  992. C_STRUCT aiMatrix4x4 *mat,
  993. const C_STRUCT aiVector3D *translation) {
  994. ai_assert(nullptr != mat);
  995. ai_assert(nullptr != translation);
  996. aiMatrix4x4::Translation(*translation, *mat);
  997. }
  998. // ------------------------------------------------------------------------------------------------
  999. ASSIMP_API void aiMatrix4Scaling(
  1000. C_STRUCT aiMatrix4x4 *mat,
  1001. const C_STRUCT aiVector3D *scaling) {
  1002. ai_assert(nullptr != mat);
  1003. ai_assert(nullptr != scaling);
  1004. aiMatrix4x4::Scaling(*scaling, *mat);
  1005. }
  1006. // ------------------------------------------------------------------------------------------------
  1007. ASSIMP_API void aiMatrix4FromTo(
  1008. C_STRUCT aiMatrix4x4 *mat,
  1009. const C_STRUCT aiVector3D *from,
  1010. const C_STRUCT aiVector3D *to) {
  1011. ai_assert(nullptr != mat);
  1012. ai_assert(nullptr != from);
  1013. ai_assert(nullptr != to);
  1014. aiMatrix4x4::FromToMatrix(*from, *to, *mat);
  1015. }
  1016. // ------------------------------------------------------------------------------------------------
  1017. ASSIMP_API void aiQuaternionFromEulerAngles(
  1018. C_STRUCT aiQuaternion *q,
  1019. float x, float y, float z) {
  1020. ai_assert(nullptr != q);
  1021. *q = aiQuaternion(x, y, z);
  1022. }
  1023. // ------------------------------------------------------------------------------------------------
  1024. ASSIMP_API void aiQuaternionFromAxisAngle(
  1025. C_STRUCT aiQuaternion *q,
  1026. const C_STRUCT aiVector3D *axis,
  1027. const float angle) {
  1028. ai_assert(nullptr != q);
  1029. ai_assert(nullptr != axis);
  1030. *q = aiQuaternion(*axis, angle);
  1031. }
  1032. // ------------------------------------------------------------------------------------------------
  1033. ASSIMP_API void aiQuaternionFromNormalizedQuaternion(
  1034. C_STRUCT aiQuaternion *q,
  1035. const C_STRUCT aiVector3D *normalized) {
  1036. ai_assert(nullptr != q);
  1037. ai_assert(nullptr != normalized);
  1038. *q = aiQuaternion(*normalized);
  1039. }
  1040. // ------------------------------------------------------------------------------------------------
  1041. ASSIMP_API int aiQuaternionAreEqual(
  1042. const C_STRUCT aiQuaternion *a,
  1043. const C_STRUCT aiQuaternion *b) {
  1044. ai_assert(nullptr != a);
  1045. ai_assert(nullptr != b);
  1046. return *a == *b;
  1047. }
  1048. // ------------------------------------------------------------------------------------------------
  1049. ASSIMP_API int aiQuaternionAreEqualEpsilon(
  1050. const C_STRUCT aiQuaternion *a,
  1051. const C_STRUCT aiQuaternion *b,
  1052. const float epsilon) {
  1053. ai_assert(nullptr != a);
  1054. ai_assert(nullptr != b);
  1055. return a->Equal(*b, epsilon);
  1056. }
  1057. // ------------------------------------------------------------------------------------------------
  1058. ASSIMP_API void aiQuaternionNormalize(
  1059. C_STRUCT aiQuaternion *q) {
  1060. ai_assert(nullptr != q);
  1061. q->Normalize();
  1062. }
  1063. // ------------------------------------------------------------------------------------------------
  1064. ASSIMP_API void aiQuaternionConjugate(
  1065. C_STRUCT aiQuaternion *q) {
  1066. ai_assert(nullptr != q);
  1067. q->Conjugate();
  1068. }
  1069. // ------------------------------------------------------------------------------------------------
  1070. ASSIMP_API void aiQuaternionMultiply(
  1071. C_STRUCT aiQuaternion *dst,
  1072. const C_STRUCT aiQuaternion *q) {
  1073. ai_assert(nullptr != dst);
  1074. ai_assert(nullptr != q);
  1075. *dst = (*dst) * (*q);
  1076. }
  1077. // ------------------------------------------------------------------------------------------------
  1078. ASSIMP_API void aiQuaternionInterpolate(
  1079. C_STRUCT aiQuaternion *dst,
  1080. const C_STRUCT aiQuaternion *start,
  1081. const C_STRUCT aiQuaternion *end,
  1082. const float factor) {
  1083. ai_assert(nullptr != dst);
  1084. ai_assert(nullptr != start);
  1085. ai_assert(nullptr != end);
  1086. aiQuaternion::Interpolate(*dst, *start, *end, factor);
  1087. }
  1088. // stb_image is a lightweight image loader. It is shared by:
  1089. // - M3D import
  1090. // - PBRT export
  1091. // Since it's a header-only library, its implementation must be instantiated in some cpp file.
  1092. // Don't scatter this task over multiple importers/exporters. Maintain it in a central place (here!).
  1093. #define ASSIMP_HAS_PBRT_EXPORT (!ASSIMP_BUILD_NO_EXPORT && !ASSIMP_BUILD_NO_PBRT_EXPORTER)
  1094. #define ASSIMP_HAS_M3D ((!ASSIMP_BUILD_NO_EXPORT && !ASSIMP_BUILD_NO_M3D_EXPORTER) || !ASSIMP_BUILD_NO_M3D_IMPORTER)
  1095. #ifndef STB_USE_HUNTER
  1096. # if ASSIMP_HAS_PBRT_EXPORT
  1097. # define ASSIMP_NEEDS_STB_IMAGE 1
  1098. # elif ASSIMP_HAS_M3D
  1099. # define ASSIMP_NEEDS_STB_IMAGE 1
  1100. # define STBI_ONLY_PNG
  1101. # endif
  1102. #endif
  1103. // Ensure all symbols are linked correctly
  1104. #if ASSIMP_NEEDS_STB_IMAGE
  1105. // Share stb_image's PNG loader with other importers/exporters instead of bringing our own copy.
  1106. # define STBI_ONLY_PNG
  1107. # ifdef ASSIMP_USE_STB_IMAGE_STATIC
  1108. # define STB_IMAGE_STATIC
  1109. # endif
  1110. # define STB_IMAGE_IMPLEMENTATION
  1111. # include "Common/StbCommon.h"
  1112. #endif