doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
exporter.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 #define MAYA_DEFAULT_CAMERA "camera1"
29 
30 #define ANIM_TX BIT( 0 )
31 #define ANIM_TY BIT( 1 )
32 #define ANIM_TZ BIT( 2 )
33 #define ANIM_QX BIT( 3 )
34 #define ANIM_QY BIT( 4 )
35 #define ANIM_QZ BIT( 5 )
36 
37 typedef enum {
41 } exportType_t;
42 
43 typedef struct {
46 } jointFrame_t;
47 
48 typedef struct {
49  idCQuat q;
50  idVec3 t;
51  float fov;
53 
54 /*
55 ==============================================================================================
56 
57  idTokenizer
58 
59 ==============================================================================================
60 */
61 
62 class idTokenizer {
63 private:
66 
67 public:
68  idTokenizer() { Clear(); };
69  void Clear( void ) { currentToken = 0; tokens.Clear(); };
70 
71  int SetTokens( const char *buffer );
72  const char *NextToken( const char *errorstring = NULL );
73 
74  bool TokenAvailable( void ) { return currentToken < tokens.Num(); };
75  int Num( void ) { return tokens.Num(); };
76  void UnGetToken( void ) { if ( currentToken > 0 ) { currentToken--; } };
77  const char *GetToken( int index ) { if ( ( index >= 0 ) && ( index < tokens.Num() ) ) { return tokens[ index ]; } else { return NULL; } };
78  const char *CurrentToken( void ) { return GetToken( currentToken ); };
79 };
80 
81 /*
82 ==============================================================================================
83 
84  idExportOptions
85 
86 ==============================================================================================
87 */
88 
89 class idNamePair {
90 public:
93 };
94 
95 class idAnimGroup {
96 public:
99 };
100 
102 private:
104 
105  void Reset( const char *commandline );
106 
107 public:
113  float scale;
120  int endframe;
132  float rotate;
135 
136  idExportOptions( const char *commandline, const char *ospath );
137 
138  bool jointInExportGroup( const char *jointname );
139 };
140 
141 /*
142 ==============================================================================
143 
144 idExportJoint
145 
146 ==============================================================================
147 */
148 
150 public:
154  int index;
156  bool keep;
157 
158  float scale;
159  float invscale;
160 
161  MFnDagNode *dagnode;
162 
165 
168 
171 
174 
175  int animBits;
178  int depth;
179 
180  idExportJoint();
181  idExportJoint &operator=( const idExportJoint &other );
182 };
183 
184 /*
185 ==============================================================================
186 
187 misc structures
188 
189 ==============================================================================
190 */
191 
192 typedef struct {
194  float jointWeight;
197 
198 typedef struct {
204 
205 typedef struct {
206  int indexes[ 3 ];
208 
209 typedef struct {
210  idVec2 uv[ 3 ];
211 } exportUV_t;
212 
214  if ( a.pos != b.pos ) {
215  return false;
216  }
217 
218  if ( ( a.texCoords[ 0 ] != b.texCoords[ 0 ] ) || ( a.texCoords[ 1 ] != b.texCoords[ 1 ] ) ) {
219  return false;
220  }
221 
222  if ( ( a.startweight != b.startweight ) || ( a.numWeights != b.numWeights ) ) {
223  return false;
224  }
225 
226  return true;
227 }
228 
229 /*
230 ========================================================================
231 
232 .MD3 triangle model file format
233 
234 ========================================================================
235 */
236 
237 #define MD3_IDENT (('3'<<24)+('P'<<16)+('D'<<8)+'I')
238 #define MD3_VERSION 15
239 
240 // limits
241 #define MD3_MAX_LODS 4
242 #define MD3_MAX_TRIANGLES 8192 // per surface
243 #define MD3_MAX_VERTS 4096 // per surface
244 #define MD3_MAX_SHADERS 256 // per surface
245 #define MD3_MAX_FRAMES 1024 // per model
246 #define MD3_MAX_SURFACES 32 // per model
247 #define MD3_MAX_TAGS 16 // per frame
248 
249 // vertex scales
250 #define MD3_XYZ_SCALE (1.0/64)
251 
252 // surface geometry should not exceed these limits
253 #define SHADER_MAX_VERTEXES 1000
254 #define SHADER_MAX_INDEXES (6*SHADER_MAX_VERTEXES)
255 
256 
257 // the maximum size of game reletive pathnames
258 #define MAX_Q3PATH 64
259 
260 typedef struct md3Frame_s {
263  float radius;
264  char name[16];
265 } md3Frame_t;
266 
267 typedef struct md3Tag_s {
268  char name[MAX_Q3PATH]; // tag name
271 } md3Tag_t;
272 
273 /*
274 ** md3Surface_t
275 **
276 ** CHUNK SIZE
277 ** header sizeof( md3Surface_t )
278 ** shaders sizeof( md3Shader_t ) * numShaders
279 ** triangles[0] sizeof( md3Triangle_t ) * numTriangles
280 ** st sizeof( md3St_t ) * numVerts
281 ** XyzNormals sizeof( md3XyzNormal_t ) * numVerts * numFrames
282 */
283 typedef struct {
284  int ident; //
285 
286  char name[MAX_Q3PATH]; // polyset name
287 
288  int flags;
289  int numFrames; // all surfaces in a model should have the same
290 
291  int numShaders; // all surfaces in a model should have the same
292  int numVerts;
293 
296 
297  int ofsShaders; // offset from start of md3Surface_t
298  int ofsSt; // texture coords are common for all frames
299  int ofsXyzNormals; // numVerts * numFrames
300 
301  int ofsEnd; // next surface follows
302 } md3Surface_t;
303 
304 typedef struct {
306  int shaderIndex; // for in-game use
307 } md3Shader_t;
308 
309 typedef struct {
310  int indexes[3];
311 } md3Triangle_t;
312 
313 typedef struct {
314  float st[2];
315 } md3St_t;
316 
317 typedef struct {
318  short xyz[3];
319  short normal;
321 
322 typedef struct {
323  int ident;
324  int version;
325 
326  char name[MAX_Q3PATH]; // model name
327 
328  int flags;
329 
331  int numTags;
333 
334  int numSkins;
335 
336  int ofsFrames; // offset for first frame
337  int ofsTags; // numFrames * numTags
338  int ofsSurfaces; // first surface, others follow
339 
340  int ofsEnd; // end of file
341 } md3Header_t;
342 
343 /*
344 ==============================================================================
345 
346 idExportMesh
347 
348 ==============================================================================
349 */
350 
352 public:
353 
356 
357  bool keep;
358 
363 
364  idExportMesh() { keep = true; };
365  void ShareVerts( void );
366  void GetBounds( idBounds &bounds ) const;
367  void Merge( idExportMesh *mesh );
368 };
369 
370 /*
371 ==============================================================================
372 
373 idExportModel
374 
375 ==============================================================================
376 */
377 
379 public:
394 
395  idExportModel();
396  ~idExportModel();
397  idExportJoint *FindJointReal( const char *name );
398  idExportJoint *FindJoint( const char *name );
399  bool WriteMesh( const char *filename, idExportOptions &options );
400  bool WriteAnim( const char *filename, idExportOptions &options );
401  bool WriteCamera( const char *filename, idExportOptions &options );
402 };
403 
404 /*
405 ==============================================================================
406 
407 Maya
408 
409 ==============================================================================
410 */
411 
413 private:
416 
417  void FreeDagNodes( void );
418 
419  float TimeForFrame( int num ) const;
420  int GetMayaFrameNum( int num ) const;
421  void SetFrame( int num );
422 
423 
424  void GetBindPose( MObject &jointNode, idExportJoint *joint, float scale );
425  void GetLocalTransform( idExportJoint *joint, idVec3 &pos, idMat3 &mat );
426  void GetWorldTransform( idExportJoint *joint, idVec3 &pos, idMat3 &mat, float scale );
427 
428  void CreateJoints( float scale );
429  void PruneJoints( idStrList &keepjoints, idStr &prefix );
430  void RenameJoints( idList<idNamePair> &renamejoints, idStr &prefix );
431  bool RemapParents( idList<idNamePair> &remapjoints );
432 
433  MObject FindShader( MObject& setNode );
434  void GetTextureForMesh( idExportMesh *mesh, MFnDagNode &dagNode );
435 
436  idExportMesh *CopyMesh( MFnSkinCluster &skinCluster, float scale );
437  void CreateMesh( float scale );
438  void CombineMeshes( void );
439 
440  void GetAlignment( idStr &alignName, idMat3 &align, float rotate, int startframe );
441 
442  const char *GetObjectType( MObject object );
443 
444  float GetCameraFov( idExportJoint *joint );
445  void GetCameraFrame( idExportJoint *camera, idMat3 &align, cameraFrame_t *cam );
446  void CreateCameraAnim( idMat3 &align );
447 
448  void GetDefaultPose( idMat3 &align );
449  void CreateAnimation( idMat3 &align );
450 
451 public:
452  idMayaExport( idExportOptions &exportOptions ) : options( exportOptions ) { };
453  ~idMayaExport();
454 
455  void ConvertModel( void );
456  void ConvertToMD3( void );
457 };
GLdouble GLdouble GLdouble GLdouble q
Definition: glext.h:2959
idStr from
Definition: exporter.h:91
bool RemapParents(idList< idNamePair > &remapjoints)
Definition: maya_main.cpp:1722
bool TokenAvailable(void)
Definition: exporter.h:74
int SetTokens(const char *buffer)
Definition: maya_main.cpp:395
idList< idExportJoint > joints
Definition: exporter.h:381
idList< idAnimGroup > groups
Definition: exporter.h:131
int version
Definition: exporter.h:324
int numTriangles
Definition: exporter.h:294
void ConvertModel(void)
Definition: maya_main.cpp:2794
void GetBindPose(MObject &jointNode, idExportJoint *joint, float scale)
Definition: maya_main.cpp:1475
Definition: Quat.h:306
idExportJoint * FindJointReal(const char *name)
Definition: maya_main.cpp:933
idList< int > cameraCuts
Definition: exporter.h:384
idExportJoint & operator=(const idExportJoint &other)
Definition: maya_main.cpp:760
void CreateMesh(float scale)
Definition: maya_main.cpp:2077
void GetLocalTransform(idExportJoint *joint, idVec3 &pos, idMat3 &mat)
Definition: maya_main.cpp:1541
void ConvertToMD3(void)
Definition: maya_main.cpp:2904
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:4804
idStr to
Definition: exporter.h:92
int ofsSurfaces
Definition: exporter.h:338
exportType_t
Definition: exporter.h:37
struct md3Surface_s md3Surface_t
struct md3Frame_s md3Frame_t
idList< idAnimGroup * > exportgroups
Definition: exporter.h:130
void GetAlignment(idStr &alignName, idMat3 &align, float rotate, int startframe)
Definition: maya_main.cpp:2281
int ofsXyzNormals
Definition: exporter.h:299
#define MAX_Q3PATH
Definition: exporter.h:258
float scale
Definition: exporter.h:158
bool WriteAnim(const char *filename, idExportOptions &options)
Definition: maya_main.cpp:1074
float jointWeight
Definition: exporter.h:194
const char * CurrentToken(void)
Definition: exporter.h:78
Definition: Vector.h:316
idList< idBounds > bounds
Definition: exporter.h:386
idExportModel model
Definition: exporter.h:414
void CombineMeshes(void)
Definition: maya_main.cpp:2233
short normal
Definition: exporter.h:319
idMat3 wm
Definition: exporter.h:167
void Clear(void)
Definition: exporter.h:69
int numFrames
Definition: exporter.h:289
idExportOptions(const char *commandline, const char *ospath)
Definition: maya_main.cpp:490
bool ignoreMeshes
Definition: exporter.h:115
idExportMesh * CopyMesh(MFnSkinCluster &skinCluster, float scale)
Definition: maya_main.cpp:1921
idVec3 offset
Definition: exporter.h:195
idStr name
Definition: exporter.h:151
idVec3 bindpos
Definition: exporter.h:172
bool WriteCamera(const char *filename, idExportOptions &options)
Definition: maya_main.cpp:1238
idStr realname
Definition: exporter.h:152
void GetDefaultPose(idMat3 &align)
Definition: maya_main.cpp:2536
GLuint GLuint num
Definition: glext.h:5390
const char * GetObjectType(MObject object)
Definition: maya_main.cpp:2328
int numShaders
Definition: exporter.h:291
idExportJoint * FindJoint(const char *name)
Definition: maya_main.cpp:947
int Num(void)
Definition: exporter.h:75
idVec3 bounds[2]
Definition: exporter.h:261
int ofsEnd
Definition: exporter.h:340
idList< cameraFrame_t > camera
Definition: exporter.h:385
idList< idNamePair > remapjoints
Definition: exporter.h:126
int ofsFrames
Definition: exporter.h:336
bool jointInExportGroup(const char *jointname)
Definition: maya_main.cpp:707
int shaderIndex
Definition: exporter.h:306
idList< exportWeight_t > weights
Definition: exporter.h:361
bool ignoreScale
Definition: exporter.h:118
int numSkins
Definition: exporter.h:334
idVec3 idt
Definition: exporter.h:169
jointFrame_t baseFrame
Definition: exporter.h:177
void UnGetToken(void)
Definition: exporter.h:76
idVec3 origin
Definition: exporter.h:269
idExportOptions & options
Definition: exporter.h:415
Definition: Vector.h:52
void GetTextureForMesh(idExportMesh *mesh, MFnDagNode &dagNode)
Definition: maya_main.cpp:1816
GLuint index
Definition: glext.h:3476
void Merge(idExportMesh *mesh)
Definition: maya_main.cpp:840
exportType_t type
Definition: exporter.h:114
void RenameJoints(idList< idNamePair > &renamejoints, idStr &prefix)
Definition: maya_main.cpp:1693
bool clearOriginAxis
Definition: exporter.h:117
idStr longname
Definition: exporter.h:153
idList< exportTriangle_t > tris
Definition: exporter.h:360
idList< exportVertex_t > verts
Definition: exporter.h:359
idStr name
Definition: exporter.h:354
idVec3 pos
Definition: exporter.h:199
float radius
Definition: exporter.h:263
#define NULL
Definition: Lib.h:88
idList< exportUV_t > uv
Definition: exporter.h:362
GLuint buffer
Definition: glext.h:3108
int firstComponent
Definition: exporter.h:176
const char * NextToken(const char *errorstring=NULL)
Definition: maya_main.cpp:427
idStr name
Definition: exporter.h:97
float GetCameraFov(idExportJoint *joint)
Definition: maya_main.cpp:2352
idList< idNamePair > renamejoints
Definition: exporter.h:125
idMat3 idwm
Definition: exporter.h:170
idVec3 t
Definition: exporter.h:166
idStrList keepmeshes
Definition: exporter.h:129
idList< idExportMesh * > meshes
Definition: exporter.h:393
idMat3 bindmat
Definition: exporter.h:173
int numFrames
Definition: exporter.h:330
MObject FindShader(MObject &setNode)
Definition: maya_main.cpp:1786
float jointThreshold
Definition: exporter.h:133
void ShareVerts(void)
Definition: maya_main.cpp:801
idStrList keepjoints
Definition: exporter.h:127
void CreateCameraAnim(idMat3 &align)
Definition: maya_main.cpp:2417
bool WriteMesh(const char *filename, idExportOptions &options)
Definition: maya_main.cpp:961
float TimeForFrame(int num) const
Definition: maya_main.cpp:1301
int numSurfaces
Definition: exporter.h:332
idVec2 texCoords
Definition: exporter.h:200
int ofsTags
Definition: exporter.h:337
idMayaExport(idExportOptions &exportOptions)
Definition: exporter.h:452
GLubyte GLubyte GLubyte a
Definition: glext.h:4662
MFnDagNode * dagnode
Definition: exporter.h:161
void PruneJoints(idStrList &keepjoints, idStr &prefix)
Definition: maya_main.cpp:1363
void CreateAnimation(idMat3 &align)
Definition: maya_main.cpp:2626
float invscale
Definition: exporter.h:159
struct md3Tag_s md3Tag_t
idList< jointFrame_t > jointFrames
Definition: exporter.h:387
GLubyte GLubyte b
Definition: glext.h:4662
idHierarchy< idExportJoint > mayaNode
Definition: exporter.h:163
int numTags
Definition: exporter.h:331
int skipjoints
Definition: exporter.h:391
idExportJoint * exportOrigin
Definition: exporter.h:380
void GetBounds(idBounds &bounds) const
Definition: maya_main.cpp:882
int GetMayaFrameNum(int num) const
Definition: maya_main.cpp:1315
Definition: Matrix.h:333
idList< jointFrame_t * > frames
Definition: exporter.h:388
void GetCameraFrame(idExportJoint *camera, idMat3 &align, cameraFrame_t *cam)
Definition: maya_main.cpp:2390
idHierarchy< idExportJoint > exportHead
Definition: exporter.h:383
ID_INLINE int operator==(exportVertex_t a, exportVertex_t b)
Definition: exporter.h:213
idStrList joints
Definition: exporter.h:98
void Reset(const char *commandline)
Definition: maya_main.cpp:452
idHierarchy< idExportJoint > mayaHead
Definition: exporter.h:382
int Num(void) const
Definition: List.h:265
void GetWorldTransform(idExportJoint *joint, idVec3 &pos, idMat3 &mat, float scale)
Definition: maya_main.cpp:1576
idHierarchy< idExportJoint > exportNode
Definition: exporter.h:164
const GLcharARB * name
Definition: glext.h:3629
GLfloat * st
Definition: qgl.h:89
Definition: Str.h:116
float xyzPrecision
Definition: exporter.h:122
bool clearOrigin
Definition: exporter.h:116
idVec3 localOrigin
Definition: exporter.h:262
idStr commandLine
Definition: exporter.h:108
idStr shader
Definition: exporter.h:355
struct md3Header_s md3Header_t
idTokenizer()
Definition: exporter.h:68
void SetFrame(int num)
Definition: maya_main.cpp:1346
float quatPrecision
Definition: exporter.h:123
int ofsTriangles
Definition: exporter.h:295
void CreateJoints(float scale)
Definition: maya_main.cpp:1600
int ofsShaders
Definition: exporter.h:297
void FreeDagNodes(void)
Definition: maya_main.cpp:1461
int export_joints
Definition: exporter.h:392
idExportJoint * joint
Definition: exporter.h:193
idStrList tokens
Definition: exporter.h:65
idCQuat q
Definition: exporter.h:44
int currentToken
Definition: exporter.h:64
idVec3 t
Definition: exporter.h:45
idStrList skipmeshes
Definition: exporter.h:128
const char * GetToken(int index)
Definition: exporter.h:77
idTokenizer tokens
Definition: exporter.h:103
idVec3 axis[3]
Definition: exporter.h:270
GLdouble GLdouble t
Definition: glext.h:2943
int numVerts
Definition: exporter.h:292
void Clear(void)
Definition: List.h:184