Exporter.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2018, 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 Exporter.cpp
  35. Assimp export interface. While it's public interface bears many similarities
  36. to the import interface (in fact, it is largely symmetric), the internal
  37. implementations differs a lot. Exporters are considered stateless and are
  38. simple callbacks which we maintain in a global list along with their
  39. description strings.
  40. Here we implement only the C++ interface (Assimp::Exporter).
  41. */
  42. #ifndef ASSIMP_BUILD_NO_EXPORT
  43. #include <assimp/BlobIOSystem.h>
  44. #include <assimp/SceneCombiner.h>
  45. #include "BaseProcess.h"
  46. #include "Importer.h" // need this for GetPostProcessingStepInstanceList()
  47. #include "JoinVerticesProcess.h"
  48. #include "MakeVerboseFormat.h"
  49. #include "ConvertToLHProcess.h"
  50. #include "PretransformVertices.h"
  51. #include <assimp/Exceptional.h>
  52. #include "ScenePrivate.h"
  53. #include <memory>
  54. #include <assimp/DefaultIOSystem.h>
  55. #include <assimp/Exporter.hpp>
  56. #include <assimp/mesh.h>
  57. #include <assimp/postprocess.h>
  58. #include <assimp/scene.h>
  59. namespace Assimp {
  60. // PostStepRegistry.cpp
  61. void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out);
  62. // ------------------------------------------------------------------------------------------------
  63. // Exporter worker function prototypes. Should not be necessary to #ifndef them, it's just a prototype
  64. // do not use const, because some exporter need to convert the scene temporary
  65. void ExportSceneCollada(const char*,IOSystem*, const aiScene*, const ExportProperties*);
  66. void ExportSceneXFile(const char*,IOSystem*, const aiScene*, const ExportProperties*);
  67. void ExportSceneStep(const char*,IOSystem*, const aiScene*, const ExportProperties*);
  68. void ExportSceneObj(const char*,IOSystem*, const aiScene*, const ExportProperties*);
  69. void ExportSceneObjNoMtl(const char*,IOSystem*, const aiScene*, const ExportProperties*);
  70. void ExportSceneSTL(const char*,IOSystem*, const aiScene*, const ExportProperties*);
  71. void ExportSceneSTLBinary(const char*,IOSystem*, const aiScene*, const ExportProperties*);
  72. void ExportScenePly(const char*,IOSystem*, const aiScene*, const ExportProperties*);
  73. void ExportScenePlyBinary(const char*, IOSystem*, const aiScene*, const ExportProperties*);
  74. void ExportScene3DS(const char*, IOSystem*, const aiScene*, const ExportProperties*);
  75. void ExportSceneGLTF(const char*, IOSystem*, const aiScene*, const ExportProperties*);
  76. void ExportSceneGLB(const char*, IOSystem*, const aiScene*, const ExportProperties*);
  77. void ExportSceneGLTF2(const char*, IOSystem*, const aiScene*, const ExportProperties*);
  78. void ExportSceneGLB2(const char*, IOSystem*, const aiScene*, const ExportProperties*);
  79. void ExportSceneAssbin(const char*, IOSystem*, const aiScene*, const ExportProperties*);
  80. void ExportSceneAssxml(const char*, IOSystem*, const aiScene*, const ExportProperties*);
  81. void ExportSceneX3D(const char*, IOSystem*, const aiScene*, const ExportProperties*);
  82. void ExportSceneFBX(const char*, IOSystem*, const aiScene*, const ExportProperties*);
  83. void ExportSceneFBXA(const char*, IOSystem*, const aiScene*, const ExportProperties*);
  84. void ExportScene3MF( const char*, IOSystem*, const aiScene*, const ExportProperties* );
  85. // ------------------------------------------------------------------------------------------------
  86. // global array of all export formats which Assimp supports in its current build
  87. Exporter::ExportFormatEntry gExporters[] =
  88. {
  89. #ifndef ASSIMP_BUILD_NO_COLLADA_EXPORTER
  90. Exporter::ExportFormatEntry( "collada", "COLLADA - Digital Asset Exchange Schema", "dae", &ExportSceneCollada ),
  91. #endif
  92. #ifndef ASSIMP_BUILD_NO_X_EXPORTER
  93. Exporter::ExportFormatEntry( "x", "X Files", "x", &ExportSceneXFile,
  94. aiProcess_MakeLeftHanded | aiProcess_FlipWindingOrder | aiProcess_FlipUVs ),
  95. #endif
  96. #ifndef ASSIMP_BUILD_NO_STEP_EXPORTER
  97. Exporter::ExportFormatEntry( "stp", "Step Files", "stp", &ExportSceneStep, 0 ),
  98. #endif
  99. #ifndef ASSIMP_BUILD_NO_OBJ_EXPORTER
  100. Exporter::ExportFormatEntry( "obj", "Wavefront OBJ format", "obj", &ExportSceneObj,
  101. aiProcess_GenSmoothNormals /*| aiProcess_PreTransformVertices */ ),
  102. Exporter::ExportFormatEntry( "objnomtl", "Wavefront OBJ format without material file", "obj", &ExportSceneObjNoMtl,
  103. aiProcess_GenSmoothNormals /*| aiProcess_PreTransformVertices */ ),
  104. #endif
  105. #ifndef ASSIMP_BUILD_NO_STL_EXPORTER
  106. Exporter::ExportFormatEntry( "stl", "Stereolithography", "stl" , &ExportSceneSTL,
  107. aiProcess_Triangulate | aiProcess_GenNormals | aiProcess_PreTransformVertices
  108. ),
  109. Exporter::ExportFormatEntry( "stlb", "Stereolithography (binary)", "stl" , &ExportSceneSTLBinary,
  110. aiProcess_Triangulate | aiProcess_GenNormals | aiProcess_PreTransformVertices
  111. ),
  112. #endif
  113. #ifndef ASSIMP_BUILD_NO_PLY_EXPORTER
  114. Exporter::ExportFormatEntry( "ply", "Stanford Polygon Library", "ply" , &ExportScenePly,
  115. aiProcess_PreTransformVertices
  116. ),
  117. Exporter::ExportFormatEntry( "plyb", "Stanford Polygon Library (binary)", "ply", &ExportScenePlyBinary,
  118. aiProcess_PreTransformVertices
  119. ),
  120. #endif
  121. #ifndef ASSIMP_BUILD_NO_3DS_EXPORTER
  122. Exporter::ExportFormatEntry( "3ds", "Autodesk 3DS (legacy)", "3ds" , &ExportScene3DS,
  123. aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_JoinIdenticalVertices ),
  124. #endif
  125. #ifndef ASSIMP_BUILD_NO_GLTF_EXPORTER
  126. Exporter::ExportFormatEntry( "gltf", "GL Transmission Format", "gltf", &ExportSceneGLTF,
  127. aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ),
  128. Exporter::ExportFormatEntry( "glb", "GL Transmission Format (binary)", "glb", &ExportSceneGLB,
  129. aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ),
  130. Exporter::ExportFormatEntry( "gltf2", "GL Transmission Format v. 2", "gltf", &ExportSceneGLTF2,
  131. aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ),
  132. Exporter::ExportFormatEntry( "glb2", "GL Transmission Format v. 2 (binary)", "glb", &ExportSceneGLB2,
  133. aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ),
  134. #endif
  135. #ifndef ASSIMP_BUILD_NO_ASSBIN_EXPORTER
  136. Exporter::ExportFormatEntry( "assbin", "Assimp Binary", "assbin" , &ExportSceneAssbin, 0 ),
  137. #endif
  138. #ifndef ASSIMP_BUILD_NO_ASSXML_EXPORTER
  139. Exporter::ExportFormatEntry( "assxml", "Assxml Document", "assxml" , &ExportSceneAssxml, 0 ),
  140. #endif
  141. #ifndef ASSIMP_BUILD_NO_X3D_EXPORTER
  142. Exporter::ExportFormatEntry( "x3d", "Extensible 3D", "x3d" , &ExportSceneX3D, 0 ),
  143. #endif
  144. #ifndef ASSIMP_BUILD_NO_FBX_EXPORTER
  145. Exporter::ExportFormatEntry( "fbx", "Autodesk FBX (binary)", "fbx", &ExportSceneFBX, 0 ),
  146. Exporter::ExportFormatEntry( "fbxa", "Autodesk FBX (ascii)", "fbx", &ExportSceneFBXA, 0 ),
  147. #endif
  148. #ifndef ASSIMP_BUILD_NO_3MF_EXPORTER
  149. Exporter::ExportFormatEntry( "3mf", "The 3MF-File-Format", "3mf", &ExportScene3MF, 0 )
  150. #endif
  151. };
  152. #define ASSIMP_NUM_EXPORTERS (sizeof(gExporters)/sizeof(gExporters[0]))
  153. class ExporterPimpl {
  154. public:
  155. ExporterPimpl()
  156. : blob()
  157. , mIOSystem(new Assimp::DefaultIOSystem())
  158. , mIsDefaultIOHandler(true)
  159. {
  160. GetPostProcessingStepInstanceList(mPostProcessingSteps);
  161. // grab all built-in exporters
  162. if ( 0 != ( ASSIMP_NUM_EXPORTERS ) ) {
  163. mExporters.resize( ASSIMP_NUM_EXPORTERS );
  164. std::copy( gExporters, gExporters + ASSIMP_NUM_EXPORTERS, mExporters.begin() );
  165. }
  166. }
  167. ~ExporterPimpl()
  168. {
  169. delete blob;
  170. // Delete all post-processing plug-ins
  171. for( unsigned int a = 0; a < mPostProcessingSteps.size(); a++) {
  172. delete mPostProcessingSteps[a];
  173. }
  174. }
  175. public:
  176. aiExportDataBlob* blob;
  177. std::shared_ptr< Assimp::IOSystem > mIOSystem;
  178. bool mIsDefaultIOHandler;
  179. /** Post processing steps we can apply at the imported data. */
  180. std::vector< BaseProcess* > mPostProcessingSteps;
  181. /** Last fatal export error */
  182. std::string mError;
  183. /** Exporters, this includes those registered using #Assimp::Exporter::RegisterExporter */
  184. std::vector<Exporter::ExportFormatEntry> mExporters;
  185. };
  186. } // end of namespace Assimp
  187. using namespace Assimp;
  188. // ------------------------------------------------------------------------------------------------
  189. Exporter :: Exporter()
  190. : pimpl(new ExporterPimpl()) {
  191. // empty
  192. }
  193. // ------------------------------------------------------------------------------------------------
  194. Exporter::~Exporter() {
  195. FreeBlob();
  196. delete pimpl;
  197. }
  198. // ------------------------------------------------------------------------------------------------
  199. void Exporter::SetIOHandler( IOSystem* pIOHandler) {
  200. pimpl->mIsDefaultIOHandler = !pIOHandler;
  201. pimpl->mIOSystem.reset(pIOHandler);
  202. }
  203. // ------------------------------------------------------------------------------------------------
  204. IOSystem* Exporter::GetIOHandler() const {
  205. return pimpl->mIOSystem.get();
  206. }
  207. // ------------------------------------------------------------------------------------------------
  208. bool Exporter::IsDefaultIOHandler() const {
  209. return pimpl->mIsDefaultIOHandler;
  210. }
  211. // ------------------------------------------------------------------------------------------------
  212. const aiExportDataBlob* Exporter::ExportToBlob( const aiScene* pScene, const char* pFormatId,
  213. unsigned int, const ExportProperties* /*pProperties*/ ) {
  214. if (pimpl->blob) {
  215. delete pimpl->blob;
  216. pimpl->blob = NULL;
  217. }
  218. std::shared_ptr<IOSystem> old = pimpl->mIOSystem;
  219. BlobIOSystem* blobio = new BlobIOSystem();
  220. pimpl->mIOSystem = std::shared_ptr<IOSystem>( blobio );
  221. if (AI_SUCCESS != Export(pScene,pFormatId,blobio->GetMagicFileName())) {
  222. pimpl->mIOSystem = old;
  223. return NULL;
  224. }
  225. pimpl->blob = blobio->GetBlobChain();
  226. pimpl->mIOSystem = old;
  227. return pimpl->blob;
  228. }
  229. // ------------------------------------------------------------------------------------------------
  230. bool IsVerboseFormat(const aiMesh* mesh) {
  231. // avoid slow vector<bool> specialization
  232. std::vector<unsigned int> seen(mesh->mNumVertices,0);
  233. for(unsigned int i = 0; i < mesh->mNumFaces; ++i) {
  234. const aiFace& f = mesh->mFaces[i];
  235. for(unsigned int j = 0; j < f.mNumIndices; ++j) {
  236. if(++seen[f.mIndices[j]] == 2) {
  237. // found a duplicate index
  238. return false;
  239. }
  240. }
  241. }
  242. return true;
  243. }
  244. // ------------------------------------------------------------------------------------------------
  245. bool IsVerboseFormat(const aiScene* pScene) {
  246. for(unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
  247. if(!IsVerboseFormat(pScene->mMeshes[i])) {
  248. return false;
  249. }
  250. }
  251. return true;
  252. }
  253. // ------------------------------------------------------------------------------------------------
  254. aiReturn Exporter::Export( const aiScene* pScene, const char* pFormatId, const char* pPath,
  255. unsigned int pPreprocessing, const ExportProperties* pProperties) {
  256. ASSIMP_BEGIN_EXCEPTION_REGION();
  257. // when they create scenes from scratch, users will likely create them not in verbose
  258. // format. They will likely not be aware that there is a flag in the scene to indicate
  259. // this, however. To avoid surprises and bug reports, we check for duplicates in
  260. // meshes upfront.
  261. const bool is_verbose_format = !(pScene->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT) || IsVerboseFormat(pScene);
  262. pimpl->mError = "";
  263. for (size_t i = 0; i < pimpl->mExporters.size(); ++i) {
  264. const Exporter::ExportFormatEntry& exp = pimpl->mExporters[i];
  265. if (!strcmp(exp.mDescription.id,pFormatId)) {
  266. try {
  267. // Always create a full copy of the scene. We might optimize this one day,
  268. // but for now it is the most pragmatic way.
  269. aiScene* scenecopy_tmp = NULL;
  270. SceneCombiner::CopyScene(&scenecopy_tmp,pScene);
  271. std::unique_ptr<aiScene> scenecopy(scenecopy_tmp);
  272. const ScenePrivateData* const priv = ScenePriv(pScene);
  273. // steps that are not idempotent, i.e. we might need to run them again, usually to get back to the
  274. // original state before the step was applied first. When checking which steps we don't need
  275. // to run, those are excluded.
  276. const unsigned int nonIdempotentSteps = aiProcess_FlipWindingOrder | aiProcess_FlipUVs | aiProcess_MakeLeftHanded;
  277. // Erase all pp steps that were already applied to this scene
  278. const unsigned int pp = (exp.mEnforcePP | pPreprocessing) & ~(priv && !priv->mIsCopy
  279. ? (priv->mPPStepsApplied & ~nonIdempotentSteps)
  280. : 0u);
  281. // If no extra post-processing was specified, and we obtained this scene from an
  282. // Assimp importer, apply the reverse steps automatically.
  283. // TODO: either drop this, or document it. Otherwise it is just a bad surprise.
  284. //if (!pPreprocessing && priv) {
  285. // pp |= (nonIdempotentSteps & priv->mPPStepsApplied);
  286. //}
  287. // If the input scene is not in verbose format, but there is at least post-processing step that relies on it,
  288. // we need to run the MakeVerboseFormat step first.
  289. bool must_join_again = false;
  290. if (!is_verbose_format) {
  291. bool verbosify = false;
  292. for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++) {
  293. BaseProcess* const p = pimpl->mPostProcessingSteps[a];
  294. if (p->IsActive(pp) && p->RequireVerboseFormat()) {
  295. verbosify = true;
  296. break;
  297. }
  298. }
  299. if (verbosify || (exp.mEnforcePP & aiProcess_JoinIdenticalVertices)) {
  300. ASSIMP_LOG_DEBUG("export: Scene data not in verbose format, applying MakeVerboseFormat step first");
  301. MakeVerboseFormatProcess proc;
  302. proc.Execute(scenecopy.get());
  303. if(!(exp.mEnforcePP & aiProcess_JoinIdenticalVertices)) {
  304. must_join_again = true;
  305. }
  306. }
  307. }
  308. if (pp) {
  309. // the three 'conversion' steps need to be executed first because all other steps rely on the standard data layout
  310. {
  311. FlipWindingOrderProcess step;
  312. if (step.IsActive(pp)) {
  313. step.Execute(scenecopy.get());
  314. }
  315. }
  316. {
  317. FlipUVsProcess step;
  318. if (step.IsActive(pp)) {
  319. step.Execute(scenecopy.get());
  320. }
  321. }
  322. {
  323. MakeLeftHandedProcess step;
  324. if (step.IsActive(pp)) {
  325. step.Execute(scenecopy.get());
  326. }
  327. }
  328. bool exportPointCloud(false);
  329. if (nullptr != pProperties) {
  330. exportPointCloud = pProperties->GetPropertyBool(AI_CONFIG_EXPORT_POINT_CLOUDS);
  331. }
  332. // dispatch other processes
  333. for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++) {
  334. BaseProcess* const p = pimpl->mPostProcessingSteps[a];
  335. if (p->IsActive(pp)
  336. && !dynamic_cast<FlipUVsProcess*>(p)
  337. && !dynamic_cast<FlipWindingOrderProcess*>(p)
  338. && !dynamic_cast<MakeLeftHandedProcess*>(p)) {
  339. if (dynamic_cast<PretransformVertices*>(p) && exportPointCloud) {
  340. continue;
  341. }
  342. p->Execute(scenecopy.get());
  343. }
  344. }
  345. ScenePrivateData* const privOut = ScenePriv(scenecopy.get());
  346. ai_assert(privOut);
  347. privOut->mPPStepsApplied |= pp;
  348. }
  349. if(must_join_again) {
  350. JoinVerticesProcess proc;
  351. proc.Execute(scenecopy.get());
  352. }
  353. ExportProperties emptyProperties; // Never pass NULL ExportProperties so Exporters don't have to worry.
  354. exp.mExportFunction(pPath,pimpl->mIOSystem.get(),scenecopy.get(), pProperties ? pProperties : &emptyProperties);
  355. } catch (DeadlyExportError& err) {
  356. pimpl->mError = err.what();
  357. return AI_FAILURE;
  358. }
  359. return AI_SUCCESS;
  360. }
  361. }
  362. pimpl->mError = std::string("Found no exporter to handle this file format: ") + pFormatId;
  363. ASSIMP_END_EXCEPTION_REGION(aiReturn);
  364. return AI_FAILURE;
  365. }
  366. // ------------------------------------------------------------------------------------------------
  367. const char* Exporter::GetErrorString() const {
  368. return pimpl->mError.c_str();
  369. }
  370. // ------------------------------------------------------------------------------------------------
  371. void Exporter::FreeBlob() {
  372. delete pimpl->blob;
  373. pimpl->blob = NULL;
  374. pimpl->mError = "";
  375. }
  376. // ------------------------------------------------------------------------------------------------
  377. const aiExportDataBlob* Exporter::GetBlob() const {
  378. return pimpl->blob;
  379. }
  380. // ------------------------------------------------------------------------------------------------
  381. const aiExportDataBlob* Exporter::GetOrphanedBlob() const {
  382. const aiExportDataBlob* tmp = pimpl->blob;
  383. pimpl->blob = NULL;
  384. return tmp;
  385. }
  386. // ------------------------------------------------------------------------------------------------
  387. size_t Exporter::GetExportFormatCount() const {
  388. return pimpl->mExporters.size();
  389. }
  390. // ------------------------------------------------------------------------------------------------
  391. const aiExportFormatDesc* Exporter::GetExportFormatDescription( size_t index ) const {
  392. if (index >= GetExportFormatCount()) {
  393. return nullptr;
  394. }
  395. // Return from static storage if the requested index is built-in.
  396. if (index < sizeof(gExporters) / sizeof(gExporters[0])) {
  397. return &gExporters[index].mDescription;
  398. }
  399. return &pimpl->mExporters[index].mDescription;
  400. }
  401. // ------------------------------------------------------------------------------------------------
  402. aiReturn Exporter::RegisterExporter(const ExportFormatEntry& desc) {
  403. for(const ExportFormatEntry& e : pimpl->mExporters) {
  404. if (!strcmp(e.mDescription.id,desc.mDescription.id)) {
  405. return aiReturn_FAILURE;
  406. }
  407. }
  408. pimpl->mExporters.push_back(desc);
  409. return aiReturn_SUCCESS;
  410. }
  411. // ------------------------------------------------------------------------------------------------
  412. void Exporter::UnregisterExporter(const char* id) {
  413. for(std::vector<ExportFormatEntry>::iterator it = pimpl->mExporters.begin();
  414. it != pimpl->mExporters.end(); ++it) {
  415. if (!strcmp((*it).mDescription.id,id)) {
  416. pimpl->mExporters.erase(it);
  417. break;
  418. }
  419. }
  420. }
  421. // ------------------------------------------------------------------------------------------------
  422. ExportProperties::ExportProperties() {
  423. // empty
  424. }
  425. // ------------------------------------------------------------------------------------------------
  426. ExportProperties::ExportProperties(const ExportProperties &other)
  427. : mIntProperties(other.mIntProperties)
  428. , mFloatProperties(other.mFloatProperties)
  429. , mStringProperties(other.mStringProperties)
  430. , mMatrixProperties(other.mMatrixProperties) {
  431. // empty
  432. }
  433. // ------------------------------------------------------------------------------------------------
  434. // Set a configuration property
  435. bool ExportProperties::SetPropertyInteger(const char* szName, int iValue) {
  436. return SetGenericProperty<int>(mIntProperties, szName,iValue);
  437. }
  438. // ------------------------------------------------------------------------------------------------
  439. // Set a configuration property
  440. bool ExportProperties::SetPropertyFloat(const char* szName, ai_real iValue) {
  441. return SetGenericProperty<ai_real>(mFloatProperties, szName,iValue);
  442. }
  443. // ------------------------------------------------------------------------------------------------
  444. // Set a configuration property
  445. bool ExportProperties::SetPropertyString(const char* szName, const std::string& value) {
  446. return SetGenericProperty<std::string>(mStringProperties, szName,value);
  447. }
  448. // ------------------------------------------------------------------------------------------------
  449. // Set a configuration property
  450. bool ExportProperties :: SetPropertyMatrix(const char* szName, const aiMatrix4x4& value)
  451. {
  452. return SetGenericProperty<aiMatrix4x4>(mMatrixProperties, szName,value);
  453. }
  454. // ------------------------------------------------------------------------------------------------
  455. // Get a configuration property
  456. int ExportProperties :: GetPropertyInteger(const char* szName,
  457. int iErrorReturn /*= 0xffffffff*/) const
  458. {
  459. return GetGenericProperty<int>(mIntProperties,szName,iErrorReturn);
  460. }
  461. // ------------------------------------------------------------------------------------------------
  462. // Get a configuration property
  463. ai_real ExportProperties :: GetPropertyFloat(const char* szName,
  464. ai_real iErrorReturn /*= 10e10*/) const
  465. {
  466. return GetGenericProperty<ai_real>(mFloatProperties,szName,iErrorReturn);
  467. }
  468. // ------------------------------------------------------------------------------------------------
  469. // Get a configuration property
  470. const std::string ExportProperties :: GetPropertyString(const char* szName,
  471. const std::string& iErrorReturn /*= ""*/) const
  472. {
  473. return GetGenericProperty<std::string>(mStringProperties,szName,iErrorReturn);
  474. }
  475. // ------------------------------------------------------------------------------------------------
  476. // Has a configuration property
  477. const aiMatrix4x4 ExportProperties :: GetPropertyMatrix(const char* szName,
  478. const aiMatrix4x4& iErrorReturn /*= aiMatrix4x4()*/) const
  479. {
  480. return GetGenericProperty<aiMatrix4x4>(mMatrixProperties,szName,iErrorReturn);
  481. }
  482. // ------------------------------------------------------------------------------------------------
  483. // Has a configuration property
  484. bool ExportProperties :: HasPropertyInteger(const char* szName) const
  485. {
  486. return HasGenericProperty<int>(mIntProperties, szName);
  487. }
  488. // ------------------------------------------------------------------------------------------------
  489. // Has a configuration property
  490. bool ExportProperties :: HasPropertyBool(const char* szName) const
  491. {
  492. return HasGenericProperty<int>(mIntProperties, szName);
  493. }
  494. // ------------------------------------------------------------------------------------------------
  495. // Has a configuration property
  496. bool ExportProperties :: HasPropertyFloat(const char* szName) const
  497. {
  498. return HasGenericProperty<ai_real>(mFloatProperties, szName);
  499. }
  500. // ------------------------------------------------------------------------------------------------
  501. // Has a configuration property
  502. bool ExportProperties :: HasPropertyString(const char* szName) const
  503. {
  504. return HasGenericProperty<std::string>(mStringProperties, szName);
  505. }
  506. // ------------------------------------------------------------------------------------------------
  507. // Has a configuration property
  508. bool ExportProperties :: HasPropertyMatrix(const char* szName) const
  509. {
  510. return HasGenericProperty<aiMatrix4x4>(mMatrixProperties, szName);
  511. }
  512. #endif // !ASSIMP_BUILD_NO_EXPORT