Exporter.cpp 27 KB

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