PageRenderTime 25ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/COLLADAMax/include/COLLADAMaxDocumentExporter.h

https://bitbucket.org/ZhangJingGuo/opencollada
C Header | 248 lines | 100 code | 70 blank | 78 comment | 0 complexity | e49639347a69ba8c049e62184f90a764 MD5 | raw file
  1. /*
  2. Copyright (c) 2008-2009 NetAllied Systems GmbH
  3. This file is part of COLLADAMax.
  4. Portions of the code are:
  5. Copyright (c) 2005-2007 Feeling Software Inc.
  6. Copyright (c) 2005-2007 Sony Computer Entertainment America
  7. Based on the 3dsMax COLLADASW Tools:
  8. Copyright (c) 2005-2006 Autodesk Media Entertainment
  9. Licensed under the MIT Open Source License,
  10. for details please see LICENSE file or the website
  11. http://www.opensource.org/licenses/mit-license.php
  12. */
  13. #ifndef __COLLADAMAX_DOCUMENT_EXPORTER_H__
  14. #define __COLLADAMAX_DOCUMENT_EXPORTER_H__
  15. #include "COLLADAMaxPrerequisites.h"
  16. #include "COLLADASWStreamWriter.h"
  17. #include "COLLADAMaxExportSceneGraph.h"
  18. #include "COLLADAMaxOptions.h"
  19. class Interface;
  20. namespace COLLADAMax
  21. {
  22. class EffectExporter;
  23. class MaterialExporter;
  24. class AnimationExporter;
  25. typedef std::map<String, String> StringToStringMap;
  26. /** Class that uniquely identifies object.*/
  27. class ObjectIdentifier
  28. {
  29. private:
  30. /** Pointer to the object.*/
  31. void* mObject;
  32. /** Additional number to identify multiple objects with same pointer, e.g. objects in a modifier stack.
  33. The mIdentificationNumber can serve as the number in the stack.*/
  34. int mIdentificationNumber;
  35. public:
  36. ObjectIdentifier(void* object) : mObject(object),mIdentificationNumber(0){}
  37. ObjectIdentifier(void* object, int identificationNumber) :mObject(object),mIdentificationNumber(identificationNumber){}
  38. bool operator<(const ObjectIdentifier& other)const;
  39. };
  40. class DocumentExporter
  41. {
  42. private:
  43. typedef std::map<ObjectIdentifier, ExportNode*> ObjectExportNodeMap;
  44. private:
  45. /** The effect exporter used by the document exporter.*/
  46. EffectExporter * mEffectExporter;
  47. /** The material exporter used by the document exporter.*/
  48. MaterialExporter * mMaterialExporter;
  49. /** The Animation exporter used by the document exporter.*/
  50. AnimationExporter * mAnimationExporter;
  51. /** The options used by the exporter.*/
  52. Options mOptions;
  53. /** The options used by the exporter.*/
  54. bool mExportOnlySelected;
  55. Interface* mMaxInterface;
  56. /** The stream writer used to write the COLLADASW file.*/
  57. COLLADASW::StreamWriter mStreamWriter;
  58. /** The uri of the main output file.*/
  59. COLLADASW::URI mOutputFileUri;
  60. /** The scene graph which nodes will be exported.*/
  61. ExportSceneGraph* mExportSceneGraph;
  62. /** Indicates, if the ExportSceneGraph should be deleted on destruction or not.*/
  63. bool mDeleteExportSceneGraph;
  64. /** The id of the @a \<scene\> element.*/
  65. static const String SCENE_ID;
  66. static const String AUTHORING_TOOL;
  67. /** A map, that hold all already exported objects with their ids*/
  68. ObjectExportNodeMap mExportedObjects;
  69. public:
  70. /** Constructor
  71. @param i the max interface
  72. @param filepath The file path the COLLADASW document should be written to*/
  73. DocumentExporter ( Interface* i, const NativeString &filepath, COLLADABU::IDList& xRefExportFileNames, bool exportOnlySelected );
  74. /** Constructor.
  75. @param i the max interface.
  76. @param exportSceneGraph The scene graph to export.
  77. @param filepath The file path the COLLADASW document should be written to
  78. @param options The options to use during export.*/
  79. DocumentExporter ( Interface * i, ExportSceneGraph* exportSceneGraph, const NativeString &filepath, const Options& options, bool exportOnlySelected );
  80. ~DocumentExporter();
  81. /** Returns the path of the COLLADASW file created for the max file with URi @a sourceFile.*/
  82. String getXRefOutputPath(const ExportSceneGraph::XRefSceneGraph& xRefSceneGraph) const;
  83. /** Returns the URI of the COLLADASW file created for the max file with URi @a sourceFile relative
  84. to the main COLLADASW file.*/
  85. COLLADASW::URI DocumentExporter::getXRefOutputURI( const ExportSceneGraph::XRefSceneGraph& xRefSceneGraph ) const;
  86. /** Returns a pointer to the max interface.*/
  87. inline Interface* getMaxInterface()
  88. {
  89. return mMaxInterface;
  90. }
  91. /** Exports the scene currently loaded in max and all its XRef scenes. Before export, it creates an
  92. ExportSceneGraph of the scene and all XRef scenes.*/
  93. void exportRootMaxScene();
  94. /** Exports the scene currently loaded in max and all its XRef scenes. Expects that the ExportSceneGraph has
  95. already been created.*/
  96. void exportMaxScene();
  97. /** Returns a pointer to the effect exporter used by the document exporter.*/
  98. const EffectExporter * const getEffectExporter() const
  99. {
  100. return mEffectExporter;
  101. }
  102. /** Returns a pointer to the effect exporter used by the document exporter.*/
  103. EffectExporter * const getEffectExporter()
  104. {
  105. return mEffectExporter;
  106. }
  107. /** Returns a pointer to the material exporter used by the document exporter.*/
  108. MaterialExporter * getMaterialExporter()
  109. {
  110. return mMaterialExporter;
  111. }
  112. /** Returns a pointer to the animation exporter used by the document exporter.*/
  113. AnimationExporter * getAnimationExporter()
  114. {
  115. return mAnimationExporter;
  116. }
  117. /** Returns the options.*/
  118. const Options & getOptions() const
  119. {
  120. return mOptions;
  121. }
  122. /**
  123. * Returns a pointer to the collada stream writer.
  124. * @return StreamWriter* Pointer to the collada stream writer
  125. */
  126. COLLADASW::StreamWriter & getStreamWriter() { return mStreamWriter; };
  127. /** The uri of the main output file.*/
  128. const COLLADASW::URI& getOutputFileUri()const { return mOutputFileUri; }
  129. /** Shows the export options dialog.
  130. @param suppressPrompts If set to true, no dialog is shows (for scripting).*/
  131. bool showExportOptions(bool suppressPrompts);
  132. /** Returns if @a object has already been exported*/
  133. bool isExportedObject(ObjectIdentifier& object);
  134. /** Inserts @a object with id @a objectId to the list of exported objects*/
  135. void insertExportedObject(ObjectIdentifier& object, ExportNode* objectExportNode);
  136. /** Returns the id of the the already exported object @a object.
  137. If @a object has not been exported, an empty string is returned*/
  138. ExportNode* getExportedObjectExportNode(ObjectIdentifier& object);
  139. private:
  140. DocumentExporter ( const DocumentExporter & documentExporter );
  141. DocumentExporter & operator= ( const DocumentExporter & documentExporter );
  142. /** Creates the scene graph of the nodes, that should be exported.*/
  143. bool createExportSceneGraph();
  144. /** Creates all the importers that are reused by other exporters.*/
  145. void createExporters();
  146. /** Exports the asset.*/
  147. void exportAsset();
  148. /** Exports all the geometries contained in the export scene graph.*/
  149. void exportGeometries();
  150. /** Exports all the controllers contained in the export scene graph.*/
  151. void exportControllers();
  152. /** Exports all the cameras contained in the export scene graph.*/
  153. void exportCameras();
  154. /** Exports all the lights contained in the export scene graph.*/
  155. void exportLights();
  156. /** Exports all the effects used by the nodes in the export scene graph.*/
  157. void exportEffects();
  158. /** Exports all the materials used by the nodes in the export scene graph.*/
  159. void exportMaterials();
  160. /** Exports all the images used by the exported textures.*/
  161. void exportImages();
  162. /** Exports all the nodes contained in the export scene graph.*/
  163. void exportVisualScenes();
  164. /** Exports all animations contained in all animatable elements.*/
  165. void exportAnimations();
  166. /** Exports the scene.*/
  167. void exportScene();
  168. /** Deletes all exporters created by createExporters().*/
  169. void deleteExporters();
  170. /** Returns the value of the environment variable @a variableName.*/
  171. String getEnvironmentVariable ( const String & variableName );
  172. };
  173. }
  174. #endif // __COLLADAMAX_DOCUMENT_EXPORTER_H__