2
0

Assimp.cpp 43 KB

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