2
Copyright (c) 2008-2009 NetAllied Systems GmbH
4
This file is part of COLLADAMaya.
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.
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
15
#ifndef __COLLADA_MAYA_GEOMETRY_POLYGON_EXPORTER_H__
16
#define __COLLADA_MAYA_GEOMETRY_POLYGON_EXPORTER_H__
18
#include "COLLADAMayaStableHeaders.h"
19
#include "COLLADAMayaDocumentExporter.h"
20
#include "COLLADAMayaSceneElement.h"
21
#include "COLLADAMayaGeometryExporter.h"
22
#include "COLLADAMayaPolygonSource.h"
25
#include <maya/MFnMesh.h>
26
#include <maya/MDagPath.h>
27
#include <maya/MItMeshPolygon.h>
28
#include <maya/MVector.h>
29
#include <maya/MItMeshPolygon.h>
31
#include "COLLADASWStreamWriter.h"
32
#include "COLLADASWElementWriter.h"
33
#include "COLLADASWLibraryGeometries.h"
34
#include "COLLADASWInputList.h"
35
#include "COLLADASWPrimitves.h"
37
class DocumentExporter;
45
/************************************************************************/
46
/* This class writes the <polylist> elements in the <library_geometries>. */
47
/************************************************************************/
49
class GeometryPolygonExporter : public COLLADASW::LibraryGeometries
54
/** The unique id of the mesh object */
57
/** The array with the uvs */
58
MStringArray mUvSetNames;
60
/** Flag, if face vertex normals exist */
61
bool mHasFaceVertexNormals;
63
/** The shaders of the current mesh. */
64
MObjectArray mShaders;
66
/** The shader indices of the current mesh. */
67
MIntArray mShaderIndices;
69
/** The position of the current shader. */
72
/** The list with the color sets */
73
MStringArray mColorSetNames;
75
/** true, if triangles should be exported. */
78
/** Number of holes in the current mesh */
82
* Array of integer triples, one for each hole in the mesh.
83
* The first element in each triple represents the index of the holed face.
84
* The next two elements represent the number of vertexes in the hole and the
85
* hole's start index in list of hole vertexes in holeVertexArray, respectively.
86
* For example, if holeInfoArray = [ 0, 3, 0, 1, 4, 3 ], then this means that
87
* face 0 contains a 3-vertex hole whose vertex indices are stored in elements
88
* 0, 1, 2 of holeVertexArray, and face 1 contains a 4-vertex hole whose vertex
89
* indices are stored in elements 3, 4, 5, 6 of holeVertexArray.
91
MIntArray mHoleInfoArray;
94
* An array consisting of the vertex indices of every hole in the mesh.
95
* The third element of each triple in holeInfoArray is the index of the
96
* start of a particular hole's vertex list in this array.
98
MIntArray mHoleVertexArray;
100
/** Pointer to the document exporter */
101
DocumentExporter* mDocumentExporter;
103
/** A pointer to the geometry sources input list, which is filled from geometry exporter. */
104
Sources* mPolygonSources;
106
/** A pointer to the vertexes list, which is filled from geometry exporter. */
107
Sources* mVertexSources;
109
/** Vector with the indices of faces which are holes. */
110
std::vector<uint> mHoleFaces;
115
/* @param streamWriter The stream the output will be written to */
116
GeometryPolygonExporter ( COLLADASW::StreamWriter* _streamWriter,
117
DocumentExporter* _documentExporter );
118
virtual ~GeometryPolygonExporter ( void );
121
* Exports the data of all polygons from the shaders in the mesh.
123
void exportPolygonSources (
125
const String& meshId,
126
MStringArray& uvSetNames,
127
MStringArray& colorSetNames,
128
Sources* geometrySourcesList,
130
const bool hasFaceVertexNorms );
135
* Exports the data of all polygons of the current shader.
136
* @param fnMesh The current mesh object.
138
void exportShaderPolygons ( MFnMesh &fnMesh );
141
* Verify the polygons of the meshes shader for holes.
142
* @param fnMesh The current mesh object.
143
* @return bool True, if the shader has a holed polygon.
145
bool verifyPolygonsForHoles( const MFnMesh &fnMesh );
148
* Prepares the polylist in the collada file to add the list values.
149
* @param fnMesh The current mesh object.
150
* @param numPolygons Number of polygons.
151
* @param currentShapeIsHoled True, if we have to implement a polygon instead of a polylist element.
152
* @return COLLADASW::PrimitivesBase* Pointer to the created Template object.
154
COLLADASW::PrimitivesBase* preparePrimitivesBase(
155
const MFnMesh& fnMesh,
156
const uint numPolygons,
157
const uint currentShapeIsHoled );
160
* Retrieve the shader polygon vertices and write them directly into the collada file.
161
* @param primitivesBasePoly The collada object to export.
162
* @param exportType The type of the polygon source.
164
void writeShaderPolygons(
165
COLLADASW::PrimitivesBase* primitivesBasePoly,
166
const uint baseExportType,
170
* Retrieve the vertex indices and establish the number of polygons (in case of
171
* triangulation more than one is possible) and the number of vertexes in the polygon.
172
* @param fnMesh The mesh object.
173
* @param meshPolygonsIter Iterator of the mesh's polygons.
174
* @param polygon The collada source to hold the polygon data.
175
* @param vertexIndices List of the vertex indices of the current polygon.
176
* @param numPolygons Number of polygons in the current mesh.
177
* @param numVertices Number of vertices in the current mesh.
179
void initializePolygonSource(
180
const MFnMesh &fnMesh,
181
MItMeshPolygon &meshPolygonsIter,
182
PolygonSource &polygon,
183
MIntArray &vertexIndices,
188
* Writes the vertex indices into the collada file.
189
* @param primitivesBasePoly The collada file element (polylist, polygons or triangles).
190
* @param polygon Data of the current polygon (for the face vertices).
191
* @param fnMesh The current mesh object.
192
* @param meshPolygonsIter Iterator of the mesh's polygons.
193
* @param baseExportType The type of the primitivesBasePoly.
194
* @param vertexIndices List of the vertex indices of the current polygon.
195
* @param numPolygons Number of polygons in the current mesh.
196
* @param numVertices Number of vertices in the current mesh.
198
void writeElementVertexIndices(
199
COLLADASW::PrimitivesBase* primitivesBasePoly,
200
PolygonSource* polygon,
202
MItMeshPolygon &meshPolygonsIter,
203
const uint baseExportType,
204
const MIntArray &vertexIndices,
205
const uint numPolygons,
206
const uint numVertices );
209
* Determines the export type of the current primitives base.
210
* @param isHoledShape True, if the current shape is holed.
211
* @return uint The export Type (polylist, polygons or triangles)
213
uint determinePrimitivesBaseExportType ( const bool isHoledShape );
216
* If we should export a polylist and all polygons of the current mesh
217
* are triangles, we will export triangles instead of polygons!
218
* @param fnMesh The current mesh object.
219
* @return bool True, if all polygons in the mesh are triangles.
221
bool verifyTriangulation ( MFnMesh &fnMesh );
224
* Create the real Polylist/Polygons/Triangles element.
226
COLLADASW::PrimitivesBase* createPrimitivesBase ( const uint baseExportType );
229
* Check if the current face is a normal polygon or a hole and open the corresponding tag.
231
void openPolygonOrHoleElement ( COLLADASW::PrimitivesBase* polylist,
233
const uint currentFaceIndex );
236
* Check if the current face is a normal polygon or a hole.
238
bool checkForHole ( const PolygonSource* polygon, const uint currentFaceIndex );
241
* Retrieve the vertex indices and establish the number of polygons (in case of
242
* triangulation more than one is possible) and the number of vertexes in the polygon.
244
void retrieveVertexIndices (
245
MIntArray &vertexIndices,
246
MItMeshPolygon &meshPolygonsIter,
251
* Determines the vertex indices and writes them into the collada file.
252
* @param primitivesBasePoly The collada element to write the vertex indices.
253
* @param polygon The polygon with the face vertex data.
254
* @param vertexIndex The list of the vertex indices.
255
* @param normalIndices The normal indices.
256
* @param iteratorVertexIndex The current vertex index.
257
* @param meshPolygonsIter The current mesh polygon to write.
258
* @param fnMesh The current mesh object.
259
* @param polyIndex The current polygon index.
261
void writeVertexIndices(
262
COLLADASW::PrimitivesBase* primitivesBasePoly,
263
PolygonSource *polygon,
264
const int vertexIndex,
265
const MIntArray &normalIndices,
266
const int iteratorVertexIndex,
267
MItMeshPolygon &meshPolygonsIter,
269
const int polyIndex );
272
* Handles the data of a holed polygon element.
273
* @param polygon The polygon to hold the data.
274
* @param polyIndex Index of the current polygon.
275
* @param vertexIndex Index of the current vertex.
276
* @param numVertices Number of vertices in the polygon.
277
* @param iteratorVertexIndex Vertex iterator index.
279
void handleHoledPolygon(
280
PolygonSource &polygon,
284
int iteratorVertexIndex );
287
* Generate the list of the polygon set inputs.
289
void getPolygonInputAttributes ( COLLADASW::InputList& inputList );
291
/** Retrieve the list of vertex attributes.
292
That's the input list of vertexes in the collada document. */
293
void getVerticesInputAttributes( Sources& vertexAttributes );
295
/** Adds a new hole identifier.
296
The face-vertex count entry should already exist and the identifier will be place
297
in increasing order within the current list of entries within the face-vertex count list.
298
@param index The index of the hole within the face-vertex count list. */
299
void addHole ( uint index );
302
* Retrieves the number of polygons and the vertex count list to export.
303
* @param primitivesBase The collada element to write.
304
* @param fnMesh The mesh object.
306
void writeVertexCountList(
307
COLLADASW::PrimitivesBase* primitivesBase,
308
const MFnMesh &fnMesh );
311
* Counts the number of polygons in the current shape.
312
* @param fnMesh The mesh object.
313
* @return uint Number of polygons in the current shape.
315
uint getShaderPolygonsCount( const MFnMesh &fnMesh );
318
* Establish the number of vertexes in the polygon.
319
* @param meshPolygonsIter The current shapes mesh polygons itertator.
320
* @param numVertices The current vertex count.
321
* return True, if the vertex count should be added to the list.
323
bool getPolygonVertexCount(
324
MItMeshPolygon& meshPolygonsIter,
325
unsigned long& numVertices );
329
#endif //__COLLADA_MAYA_GEOMETRY_POLYGON_EXPORTER_H__