1 | /*
|
---|
2 | ============================================================================
|
---|
3 | This source file is part of the Ogre-Maya Tools.
|
---|
4 | Distributed as part of Ogre (Object-oriented Graphics Rendering Engine).
|
---|
5 | Copyright (C) 2003 Fifty1 Software Inc., Bytelords
|
---|
6 |
|
---|
7 | This program is free software; you can redistribute it and/or
|
---|
8 | modify it under the terms of the GNU General Public License
|
---|
9 | as published by the Free Software Foundation; either version 2
|
---|
10 | of the License, or (at your option) any later version.
|
---|
11 |
|
---|
12 | This program is distributed in the hope that it will be useful,
|
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | GNU General Public License for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with this program; if not, write to the Free Software
|
---|
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
20 | or go to http://www.gnu.org/licenses/gpl.txt
|
---|
21 | ============================================================================
|
---|
22 | */
|
---|
23 | #ifndef _OGREMAYA_MESH_H_
|
---|
24 | #define _OGREMAYA_MESH_H_
|
---|
25 |
|
---|
26 | #include "OgreMayaCommon.h"
|
---|
27 |
|
---|
28 | #include <maya/MGlobal.h>
|
---|
29 | #include <maya/MFloatArray.h>
|
---|
30 | #include <maya/MPointArray.h>
|
---|
31 | #include <maya/MFloatVectorArray.h>
|
---|
32 | #include <maya/MColorArray.h>
|
---|
33 | #include <maya/MObjectArray.h>
|
---|
34 | #include <maya/MFnMesh.h>
|
---|
35 | #include <maya/MStatus.h>
|
---|
36 | #include <maya/MItMeshPolygon.h>
|
---|
37 |
|
---|
38 | #include <fstream>
|
---|
39 |
|
---|
40 | #include <string>
|
---|
41 | #include <list>
|
---|
42 | #include <vector>
|
---|
43 |
|
---|
44 | namespace OgreMaya {
|
---|
45 |
|
---|
46 | using std::ofstream;
|
---|
47 | using std::list;
|
---|
48 | using std::string;
|
---|
49 | using std::vector;
|
---|
50 |
|
---|
51 | // ===========================================================================
|
---|
52 | /** \struct MeshUV
|
---|
53 | Simple structure with single set of UV coordinates for a single vertex.
|
---|
54 | */
|
---|
55 | // ===========================================================================
|
---|
56 | struct MeshVertexUV {
|
---|
57 | Real u;
|
---|
58 | Real v;
|
---|
59 |
|
---|
60 | MeshVertexUV() {
|
---|
61 | u = (Real)0.0;
|
---|
62 | v = (Real)0.0;
|
---|
63 | }
|
---|
64 |
|
---|
65 | bool operator ==(const MeshVertexUV& other) const {
|
---|
66 | return u==other.u && v==other.v;
|
---|
67 | }
|
---|
68 | };
|
---|
69 | typedef list<MeshVertexUV> MeshVertexUVList;
|
---|
70 |
|
---|
71 |
|
---|
72 | // ===========================================================================
|
---|
73 | /** \struct MeshMayaUVSet
|
---|
74 | Structure that holds UVs for all vertex-faces for a single UV set.
|
---|
75 | */
|
---|
76 | // ===========================================================================
|
---|
77 | struct MeshMayaUVSet {
|
---|
78 | MFloatArray uArray;
|
---|
79 | MFloatArray vArray;
|
---|
80 | MString sName;
|
---|
81 | };
|
---|
82 | typedef list<MeshMayaUVSet> MeshMayaUVSetList;
|
---|
83 |
|
---|
84 |
|
---|
85 | // ===========================================================================
|
---|
86 | /** \struct MeshMayaUVSet
|
---|
87 | Structure that holds UVs for all vertex-faces for a single UV set.
|
---|
88 | */
|
---|
89 | // ===========================================================================
|
---|
90 | struct VertexBoneAssigment {
|
---|
91 | int boneId;
|
---|
92 | float weight;
|
---|
93 | };
|
---|
94 | typedef list<VertexBoneAssigment> VertexBoneAssigmentList;
|
---|
95 |
|
---|
96 |
|
---|
97 | // ===========================================================================
|
---|
98 | /** \struct MeshMayaGeometry
|
---|
99 | Structure that holds all data for a single Maya mesh.
|
---|
100 | */
|
---|
101 | // ===========================================================================
|
---|
102 | struct MeshMayaGeometry {
|
---|
103 | MString Name;
|
---|
104 | MString MaterialName;
|
---|
105 | MPointArray Vertices;
|
---|
106 | MFloatVectorArray FaceVertexNormals; // face-vertex normals
|
---|
107 | MColorArray FaceVertexColours;
|
---|
108 | MIntArray TriangleVertexIds; // face-relative ids
|
---|
109 | MIntArray TrianglePolygonIds; // polygon number for each triangle
|
---|
110 | MeshMayaUVSetList UVSets;
|
---|
111 | vector<MFloatArray> Weights;
|
---|
112 | };
|
---|
113 |
|
---|
114 | // ===========================================================================
|
---|
115 | /** \struct MeshFaceVertex
|
---|
116 | Structure that defines a face-vertex.
|
---|
117 | */
|
---|
118 | // ===========================================================================
|
---|
119 | struct MeshFaceVertex {
|
---|
120 | Vector3 vecPosition;
|
---|
121 | Vector3 vecNormal;
|
---|
122 | ColourValue colour;
|
---|
123 | MeshVertexUVList listUV;
|
---|
124 |
|
---|
125 | VertexBoneAssigmentList boneAssigments;
|
---|
126 |
|
---|
127 | bool operator==(const MeshFaceVertex& other) const {
|
---|
128 | // that's enough for equality (boneAssigment is not neccessery)
|
---|
129 | return
|
---|
130 | colour == other.colour
|
---|
131 | && vecPosition == other.vecPosition
|
---|
132 | && vecNormal == other.vecNormal
|
---|
133 | && listEqual(
|
---|
134 | listUV.begin(), other.listUV.begin(),
|
---|
135 | listUV.end(), other.listUV.end()
|
---|
136 | );
|
---|
137 | }
|
---|
138 | };
|
---|
139 | typedef vector<MeshFaceVertex> MeshFaceVertexVector;
|
---|
140 |
|
---|
141 |
|
---|
142 | // ===========================================================================
|
---|
143 | /** \struct MeshTriFace
|
---|
144 | Structure that defines a triangular face as a set of 3 indices into an
|
---|
145 | arrray of MeshFaceVertex'es.
|
---|
146 | */
|
---|
147 | // ===========================================================================
|
---|
148 | struct MeshTriFace {
|
---|
149 | unsigned long index0;
|
---|
150 | unsigned long index1;
|
---|
151 | unsigned long index2;
|
---|
152 | };
|
---|
153 | typedef list<MeshTriFace> MeshTriFaceList;
|
---|
154 |
|
---|
155 |
|
---|
156 | // ===========================================================================
|
---|
157 | /** \class MeshGenerator
|
---|
158 | \author John Van Vliet, Fifty1 Software Inc.
|
---|
159 | \version 1.0
|
---|
160 | \date June 2003
|
---|
161 |
|
---|
162 | Generates an Ogre mesh from a Maya scene. The complete Maya scene is
|
---|
163 | represented by a single Ogre Mesh, and Maya meshes are represented by
|
---|
164 | Ogre SubMeshes.
|
---|
165 | */
|
---|
166 | // ===========================================================================
|
---|
167 | class MeshGenerator {
|
---|
168 | public:
|
---|
169 |
|
---|
170 | /// Standard constructor.
|
---|
171 | MeshGenerator();
|
---|
172 |
|
---|
173 | /// Destructor.
|
---|
174 | virtual ~MeshGenerator();
|
---|
175 |
|
---|
176 | /// Export the complete Maya scene (called by OgreMaya.mll or OgreMaya.exe).
|
---|
177 | bool exportAll();
|
---|
178 |
|
---|
179 | /// Export selected parts of the Maya scene (called by OgreMaya.mll).
|
---|
180 | bool exportSelection();
|
---|
181 |
|
---|
182 | protected:
|
---|
183 | /// Required for OptionParser interface.
|
---|
184 | //bool _validateOptions();
|
---|
185 |
|
---|
186 | /// Return visibility of a DAG node.
|
---|
187 | bool _isVisible(MFnDagNode &fnDag, MStatus &status);
|
---|
188 |
|
---|
189 | /// Process a Maya polyMesh.
|
---|
190 | MStatus _processPolyMesh(ofstream& out, const MDagPath dagPath);
|
---|
191 | MStatus _queryMayaGeometry(MFnMesh &fnMesh, MeshMayaGeometry &rGeom);
|
---|
192 | MStatus _parseMayaGeometry(MFnMesh &fnMesh,
|
---|
193 | MeshMayaGeometry &MayaGeometry,
|
---|
194 | MeshFaceVertexVector &FaceVertices,
|
---|
195 | MeshTriFaceList &TriFaces);
|
---|
196 |
|
---|
197 | void _convertObjectToFace(MItMeshPolygon &iterPoly, MIntArray &objIndices, MIntArray &faceIndices);
|
---|
198 |
|
---|
199 | MString getMaterialName(MFnMesh &fnMesh);
|
---|
200 |
|
---|
201 | };
|
---|
202 |
|
---|
203 | } // namespace OgreMaya
|
---|
204 |
|
---|
205 | #endif
|
---|