GraphicsAPI_2020C
Exporter.hpp
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
5 
6 Copyright (c) 2006-2017, assimp team
7 
8 
9 All rights reserved.
10 
11 Redistribution and use of this software in source and binary forms,
12 with or without modification, are permitted provided that the following
13 conditions are met:
14 
15 * Redistributions of source code must retain the above
16 copyright notice, this list of conditions and the
17 following disclaimer.
18 
19 * Redistributions in binary form must reproduce the above
20 copyright notice, this list of conditions and the
21 following disclaimer in the documentation and/or other
22 materials provided with the distribution.
23 
24 * Neither the name of the assimp team, nor the names of its
25 contributors may be used to endorse or promote products
26 derived from this software without specific prior
27 written permission of the assimp team.
28 
29 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 ---------------------------------------------------------------------------
41 */
42 
46 #pragma once
47 #ifndef AI_EXPORT_HPP_INC
48 #define AI_EXPORT_HPP_INC
49 
50 #ifndef ASSIMP_BUILD_NO_EXPORT
51 
52 #include "cexport.h"
53 #include <map>
54 
55 namespace Assimp {
56 
57 class ExporterPimpl;
58 class IOSystem;
59 
60 // ----------------------------------------------------------------------------------
78 class ASSIMP_API ExportProperties;
79 
80 class ASSIMP_API Exporter {
81 public:
83  typedef void (*fpExportFunc)(const char*, IOSystem*, const aiScene*, const ExportProperties*);
84 
87  {
90 
91  // Worker function to do the actual exporting
92  fpExportFunc mExportFunction;
93 
94  // Post-processing steps to be executed PRIOR to invoking mExportFunction
95  unsigned int mEnforcePP;
96 
97  // Constructor to fill all entries
98  ExportFormatEntry( const char* pId, const char* pDesc, const char* pExtension, fpExportFunc pFunction, unsigned int pEnforcePP = 0u)
99  {
100  mDescription.id = pId;
101  mDescription.description = pDesc;
102  mDescription.fileExtension = pExtension;
103  mExportFunction = pFunction;
104  mEnforcePP = pEnforcePP;
105  }
106 
108  mExportFunction()
109  , mEnforcePP()
110  {
111  mDescription.id = NULL;
112  mDescription.description = NULL;
113  mDescription.fileExtension = NULL;
114  }
115  };
116 
117 
118 public:
119  Exporter();
120  ~Exporter();
121 
122 public:
123  // -------------------------------------------------------------------
138  void SetIOHandler( IOSystem* pIOHandler);
139 
140  // -------------------------------------------------------------------
147  IOSystem* GetIOHandler() const;
148 
149  // -------------------------------------------------------------------
154  bool IsDefaultIOHandler() const;
155 
156  // -------------------------------------------------------------------
174  const aiExportDataBlob* ExportToBlob(const aiScene* pScene, const char* pFormatId, unsigned int pPreprocessing = 0u, const ExportProperties* = NULL);
175  const aiExportDataBlob* ExportToBlob( const aiScene* pScene, const std::string& pFormatId, unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = NULL);
176 
177  // -------------------------------------------------------------------
210  aiReturn Export( const aiScene* pScene, const char* pFormatId, const char* pPath, unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = NULL);
211  aiReturn Export( const aiScene* pScene, const std::string& pFormatId, const std::string& pPath, unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = NULL);
212 
213  // -------------------------------------------------------------------
223  const char* GetErrorString() const;
224 
225  // -------------------------------------------------------------------
227  const aiExportDataBlob* GetBlob() const;
228 
229  // -------------------------------------------------------------------
233  const aiExportDataBlob* GetOrphanedBlob() const;
234 
235  // -------------------------------------------------------------------
243  void FreeBlob( );
244 
245  // -------------------------------------------------------------------
253  size_t GetExportFormatCount() const;
254 
255  // -------------------------------------------------------------------
269  const aiExportFormatDesc* GetExportFormatDescription( size_t pIndex ) const;
270 
271  // -------------------------------------------------------------------
282  aiReturn RegisterExporter(const ExportFormatEntry& desc);
283 
284  // -------------------------------------------------------------------
293  void UnregisterExporter(const char* id);
294 
295 protected:
296  // Just because we don't want you to know how we're hacking around.
297  ExporterPimpl* pimpl;
298 };
299 
300 class ASSIMP_API ExportProperties {
301 public:
302  // Data type to store the key hash
303  typedef unsigned int KeyType;
304 
305  // typedefs for our four configuration maps.
306  // We don't need more, so there is no need for a generic solution
307  typedef std::map<KeyType, int> IntPropertyMap;
308  typedef std::map<KeyType, ai_real> FloatPropertyMap;
309  typedef std::map<KeyType, std::string> StringPropertyMap;
310  typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap;
311 
312 public:
317 
318  // -------------------------------------------------------------------
324  ExportProperties(const ExportProperties& other);
325 
326  // -------------------------------------------------------------------
339  bool SetPropertyInteger(const char* szName, int iValue);
340 
341  // -------------------------------------------------------------------
348  bool SetPropertyBool(const char* szName, bool value) {
349  return SetPropertyInteger(szName,value);
350  }
351 
352  // -------------------------------------------------------------------
356  bool SetPropertyFloat(const char* szName, ai_real fValue);
357 
358  // -------------------------------------------------------------------
362  bool SetPropertyString(const char* szName, const std::string& sValue);
363 
364  // -------------------------------------------------------------------
368  bool SetPropertyMatrix(const char* szName, const aiMatrix4x4& sValue);
369 
370  // -------------------------------------------------------------------
383  int GetPropertyInteger(const char* szName,
384  int iErrorReturn = 0xffffffff) const;
385 
386  // -------------------------------------------------------------------
393  bool GetPropertyBool(const char* szName, bool bErrorReturn = false) const {
394  return GetPropertyInteger(szName,bErrorReturn)!=0;
395  }
396 
397  // -------------------------------------------------------------------
401  ai_real GetPropertyFloat(const char* szName,
402  ai_real fErrorReturn = 10e10f) const;
403 
404  // -------------------------------------------------------------------
410  const std::string GetPropertyString(const char* szName,
411  const std::string& sErrorReturn = "") const;
412 
413  // -------------------------------------------------------------------
419  const aiMatrix4x4 GetPropertyMatrix(const char* szName,
420  const aiMatrix4x4& sErrorReturn = aiMatrix4x4()) const;
421 
422  // -------------------------------------------------------------------
426  bool HasPropertyInteger(const char* szName) const;
427 
431  bool HasPropertyBool(const char* szName) const;
432 
436  bool HasPropertyFloat(const char* szName) const;
437 
441  bool HasPropertyString(const char* szName) const;
442 
446  bool HasPropertyMatrix(const char* szName) const;
447 
448 protected:
449 
451  IntPropertyMap mIntProperties;
452 
454  FloatPropertyMap mFloatProperties;
455 
457  StringPropertyMap mStringProperties;
458 
460  MatrixPropertyMap mMatrixProperties;
461 };
462 
463 // ----------------------------------------------------------------------------------
464 inline
465 const aiExportDataBlob* Exporter::ExportToBlob( const aiScene* pScene, const std::string& pFormatId,
466  unsigned int pPreprocessing, const ExportProperties* pProperties)
467 {
468  return ExportToBlob(pScene,pFormatId.c_str(),pPreprocessing, pProperties);
469 }
470 
471 // ----------------------------------------------------------------------------------
472 inline
473 aiReturn Exporter :: Export( const aiScene* pScene, const std::string& pFormatId,
474  const std::string& pPath, unsigned int pPreprocessing,
475  const ExportProperties* pProperties)
476 {
477  return Export(pScene,pFormatId.c_str(),pPath.c_str(),pPreprocessing, pProperties);
478 }
479 
480 } // namespace Assimp
481 
482 #endif // ASSIMP_BUILD_NO_EXPORT
483 #endif // AI_EXPORT_HPP_INC
Definition: Exporter.hpp:300
Assimp&#39;s CPP-API and all internal APIs.
Definition: DefaultIOStream.h:51
Definition: matrix4x4.h:269
const char * fileExtension
Recommended file extension for the exported file in lower case.
Definition: cexport.h:78
Defines the C-API for the Assimp export interface.
aiReturn
Standard return type for some library functions.
Definition: types.h:375
CPP-API: Interface to the file system.
Definition: IOSystem.hpp:84
MatrixPropertyMap mMatrixProperties
List of Matrix properties.
Definition: Exporter.hpp:460
const aiExportDataBlob * ExportToBlob(const aiScene *pScene, const char *pFormatId, unsigned int pPreprocessing=0u, const ExportProperties *=NULL)
Exports the given scene to a chosen file format.
bool SetPropertyBool(const char *szName, bool value)
Set a boolean configuration property.
Definition: Exporter.hpp:348
The root structure of the imported data.
Definition: scene.h:240
Describes a blob of exported scene data.
Definition: cexport.h:200
IntPropertyMap mIntProperties
List of integer properties.
Definition: Exporter.hpp:451
class ASSIMP_API ExportProperties
CPP-API: The Exporter class forms an C++ interface to the export functionality of the Open Asset Impo...
Definition: Exporter.hpp:78
const char * id
a short string ID to uniquely identify the export format.
Definition: cexport.h:71
bool GetPropertyBool(const char *szName, bool bErrorReturn=false) const
Get a boolean configuration property.
Definition: Exporter.hpp:393
StringPropertyMap mStringProperties
List of string properties.
Definition: Exporter.hpp:457
Definition: Exporter.hpp:80
FloatPropertyMap mFloatProperties
List of floating-point properties.
Definition: Exporter.hpp:454
const char * description
A short description of the file format to present to users.
Definition: cexport.h:75
aiReturn Export(const aiScene *pScene, const char *pFormatId, const char *pPath, unsigned int pPreprocessing=0u, const ExportProperties *pProperties=NULL)
Convenience function to export directly to a file.
Internal description of an Assimp export format option.
Definition: Exporter.hpp:86
Describes an file format which Assimp can export to.
Definition: cexport.h:66
aiExportFormatDesc mDescription
Public description structure to be returned by aiGetExportFormatDescription()
Definition: Exporter.hpp:89