~ubuntu-branches/ubuntu/wily/opencollada/wily-proposed

« back to all changes in this revision

Viewing changes to COLLADAMaya/include/COLLADAMayaVisualSceneExporter.h

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2008-2009 NetAllied Systems GmbH
 
3
 
 
4
        This file is part of COLLADAMaya.
 
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
    Copyright (c) 2004-2005 Alias Systems Corp.
 
10
        
 
11
    Licensed under the MIT Open Source License, 
 
12
    for details please see LICENSE file or the website
 
13
    http://www.opensource.org/licenses/mit-license.php
 
14
*/
 
15
 
 
16
#ifndef __COLLADA_MAYA_VISUAL_SCENE_EXPORTER_H__
 
17
#define __COLLADA_MAYA_VISUAL_SCENE_EXPORTER_H__
 
18
 
 
19
#include "COLLADAMayaStableHeaders.h"
 
20
#include "COLLADASWLibraryVisualScenes.h"
 
21
#include "COLLADASWStreamWriter.h"
 
22
#include "COLLADASWNode.h"
 
23
#include "COLLADASWInstanceMaterial.h"
 
24
 
 
25
#include "COLLADAMayaDocumentExporter.h"
 
26
#include "COLLADAMayaSceneElement.h"
 
27
 
 
28
#include "COLLADABUIDList.h"
 
29
 
 
30
#include <maya/MDagPath.h>
 
31
#include <maya/MFnTransform.h>
 
32
#include <maya/MFnMesh.h>
 
33
 
 
34
 
 
35
class DocumentExporter;
 
36
 
 
37
namespace COLLADAMaya
 
38
{
 
39
 
 
40
    /**
 
41
     * Exports the transform data of the visual scene.
 
42
     * 
 
43
     * All transform components with units will be in maya's internal units 
 
44
     * (radians for rotations and centimeters for translations).
 
45
     * We have to translate them into the working units of the current scene!
 
46
     */
 
47
    class VisualSceneExporter : public COLLADASW::LibraryVisualScenes
 
48
    {
 
49
 
 
50
    private:
 
51
 
 
52
        /**
 
53
        * The list of the unique collada ids.
 
54
        */
 
55
        COLLADABU::IDList mNodeIdList;
 
56
 
 
57
        /**
 
58
        * A collada id for every maya id.
 
59
        */
 
60
        StringToStringMap mMayaIdColladaNodeId;
 
61
 
 
62
        /** Flag, if the current node is a joint. */
 
63
        bool mIsJoint;
 
64
 
 
65
        /** Flag, if we handle the first rotation. 
 
66
        Make sure to export the rotation order correctly by always enforcing
 
67
        the elements of the first rotation. */
 
68
        bool mIsFirstRotation;
 
69
 
 
70
        /** The id of the current scene. */
 
71
        String mSceneId;
 
72
 
 
73
        /** Pointer to the document exporter. */
 
74
        DocumentExporter* mDocumentExporter;
 
75
 
 
76
        /** Flag if the visual scene library is already added. */
 
77
        bool mVisualSceneAdded;
 
78
 
 
79
        /** A pointer to the actual visual scene node. */
 
80
        COLLADASW::Node* mVisualSceneNode;
 
81
 
 
82
        /** Pointer to the current scene element. */
 
83
        SceneElement* mSceneElement;
 
84
 
 
85
        /** The path of the current node. */
 
86
        MDagPath mDagPath;
 
87
 
 
88
        /** The current transform object. */
 
89
        MObject mTransformObject;
 
90
 
 
91
        /** The current transform matrix. */
 
92
        MTransformationMatrix mTransformMatrix;
 
93
 
 
94
    public:
 
95
 
 
96
        /**
 
97
         * Constructor
 
98
         * @param streamWriter Pointer to the collada stream writer.
 
99
         * @param documentExporter Pointer to the main document exporter.
 
100
         * @param sceneId Name of the current scene to export. Has an empty string as default value.
 
101
         */
 
102
        VisualSceneExporter ( COLLADASW::StreamWriter* streamWriter,
 
103
                              DocumentExporter* documentExporter,
 
104
                              const String& sceneId = EMPTY_STRING );
 
105
        /**
 
106
         * Destructor.
 
107
         */
 
108
        virtual ~VisualSceneExporter() {};
 
109
 
 
110
        /** 
 
111
         * Exports the visual scene with the transforms of all included elements 
 
112
         */
 
113
        bool exportVisualScenes();
 
114
 
 
115
        /**
 
116
        * A collada id for every maya id.
 
117
        */
 
118
        const String findColladaNodeId ( const String& mayaNodeId );
 
119
 
 
120
        /**
 
121
        * Creates the uri for the scene element. Checks for instances 
 
122
        * and creates the right element.
 
123
        */
 
124
        COLLADASW::URI getSceneElementURI ( const SceneElement* sceneElement, const String& elementId = EMPTY_STRING );
 
125
 
 
126
        /**
 
127
         * Returns the collada id of the current node, if it is a transform node
 
128
         */
 
129
        String getColladaNodeId ( const MDagPath& dagPath );
 
130
 
 
131
    private:
 
132
 
 
133
        /** Returns the tolerance value for double value comparison. */
 
134
        const double getTolerance () const 
 
135
        {
 
136
            return mDocumentExporter->getTolerance ();
 
137
        }
 
138
 
 
139
        /**
 
140
         * Exports all the nodes in a node and all its child nodes recursive.
 
141
         * @param sceneElement The node to export.
 
142
         */
 
143
        bool exportVisualSceneNodes ( SceneElement* sceneElement );
 
144
 
 
145
        /**
 
146
         * Creates and opens a visual scene node of type node and writes the transforms
 
147
         * and the references to the geometries and materials of the current scene element.
 
148
         * @param sceneNode The collada node to write.
 
149
         * @param sceneElement The node to export.
 
150
         */
 
151
        bool exportNodeVisualSceneNode ( COLLADASW::Node* sceneNode, SceneElement* sceneElement );
 
152
 
 
153
        /**
 
154
        * Creates and opens a visual scene node of type joint and writes the transforms
 
155
        * and the references to the geometries and materials of the current scene element.
 
156
        * @param sceneNode The collada node.
 
157
        * @param dagPath The node to export.
 
158
        */
 
159
        bool exportJointVisualSceneNode ( COLLADASW::Node* sceneNode, SceneElement* sceneElement );
 
160
 
 
161
        /**
 
162
        * Creates and opens a visual scene node and writes the transforms
 
163
        * and the references to the geometries and materials of the current scene element.
 
164
        * @param sceneNode The collada node to write.
 
165
        * @param sceneElement The node to export.
 
166
        */
 
167
        bool exportVisualSceneNode ( COLLADASW::Node* sceneNode, SceneElement* sceneElement );
 
168
 
 
169
        /**
 
170
        * Exports a node instance of the current scene element.
 
171
        * @param sceneElement The scene element to instantiate.
 
172
        */
 
173
        void exportInstanceNode ( SceneElement* sceneElement );
 
174
 
 
175
        void exportInstanceChildNodes ( const SceneElement* sceneElement );
 
176
 
 
177
        /**
 
178
         * Exports the geometry instances of the given transform scene element.
 
179
         * @param childElement The transform scene element.
 
180
         */
 
181
        void exportInstanceGeometry ( SceneElement* sceneElement );
 
182
 
 
183
        /**
 
184
        * Exports the skin controller instances of the given transform scene element.
 
185
        * @param childElement The transform scene element.
 
186
         */
 
187
        void exportInstanceController( 
 
188
            SceneElement* childElement, 
 
189
            const bool hasSkinController, 
 
190
            const bool hasMorphController );
 
191
 
 
192
        /**
 
193
        * Exports the light instances of the given transform scene element.
 
194
        * @param childElement The transform scene element.
 
195
         */
 
196
        void exportInstanceLight ( const SceneElement* childElement );
 
197
 
 
198
        /**
 
199
        * Exports the camera instances of the given transform scene element.
 
200
        * @param childElement The transform scene element.
 
201
        */
 
202
        void exportInstanceCamera ( const SceneElement* childElement );
 
203
 
 
204
        /**
 
205
         * Exports the material instances.
 
206
         * @param instanceMaterialList The instance list to fill.
 
207
         * @param childDagPath The path of the current node to export the material instances.
 
208
         * @param instanceNumber The current instance number of the shape.
 
209
         */
 
210
        void exportInstanceMaterial ( 
 
211
            COLLADASW::InstanceMaterialList &instanceMaterialList, 
 
212
            const MDagPath &dagPath );
 
213
 
 
214
        /** 
 
215
         * Check if the current mesh has some polygons for the connected shader.
 
216
         * If not, we don't need to write the current material instance.
 
217
         */
 
218
        const bool meshContainsShaderPolygons ( 
 
219
            const MFnMesh& fnMesh, 
 
220
            const MObjectArray& shaders, 
 
221
            const MIntArray& shaderIndices, 
 
222
            const uint shaderPosition );
 
223
 
 
224
        /**
 
225
         * Initializes the transform objects.
 
226
         * @param dagPath The path to the transform object.
 
227
         * @return bool True, if the initialisation was successfull.
 
228
         */
 
229
        bool initializeTransform ( SceneElement* sceneElement );
 
230
 
 
231
        /**
 
232
         * Prepares a new the visual scene node.
 
233
         * @param sceneElement The scene element of the node.
 
234
         */
 
235
        void openVisualSceneNode ( const SceneElement *sceneElement );
 
236
 
 
237
        /**
 
238
         * Compute local space parameters and export them. These parameters are:
 
239
         * - Eye position
 
240
         * - Interest point
 
241
         * - Up-axis direction
 
242
         */
 
243
        void exportLookatTransform ();
 
244
 
 
245
        /** Exports all transforms */
 
246
        void exportDecomposedTransform ();
 
247
 
 
248
        /** Exports the translation */
 
249
        void exportTranslation ( const String name, const MPoint& translation, bool animation );
 
250
        void exportTranslation ( const String name, const MVector& translation, bool animation );
 
251
 
 
252
        /** Exports the translation in matrix style */
 
253
        void exportMatrixTransform ();
 
254
 
 
255
        /** Exports the Rotation */
 
256
        void exportRotation ( const String name, const MEulerRotation& rotation );
 
257
 
 
258
        /** Exports the scale */
 
259
        void exportScale();
 
260
 
 
261
        /** Exports the skew */
 
262
        void exportSkew ( double* shear );
 
263
 
 
264
        /**
 
265
         * Exports the visibility technique tag and the visibility animation.
 
266
         * A hidden visual scene node will not be rendered but will
 
267
         * still affect the world. This parameter is a floating-point value
 
268
         * because it is animated. It should be intepreted as a Boolean value.
 
269
         * @param sceneNode The collada scene node to export the values.
 
270
         */
 
271
        void exportVisibility ( COLLADASW::Node* sceneNode );
 
272
 
 
273
        /**
 
274
         * @todo documentation
 
275
         * @param sceneElement
 
276
         * @param instantiate
 
277
         * @return bool
 
278
         */
 
279
        bool enterDagNode( const SceneElement* sceneElement, bool instantiate );
 
280
 
 
281
    };
 
282
 
 
283
}
 
284
 
 
285
#endif //__COLLADA_MAYA_VISUAL_SCENE_EXPORTER_H__