Exporter.cpp 28 KB

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