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