2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
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.
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.
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/>.
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.
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.
26 ===========================================================================
33 ======================================================================
35 LWO2 loader. (LightWave Object)
37 Ernie Wright 17 Sep 00
39 ======================================================================
42 /* chunk and subchunk IDs */
44 #define LWID_(a,b,c,d) (((a)<<24)|((b)<<16)|((c)<<8)|(d))
46 #define ID_FORM LWID_('F','O','R','M')
47 #define ID_LWO2 LWID_('L','W','O','2')
48 #define ID_LWOB LWID_('L','W','O','B')
50 /* top-level chunks */
51 #define ID_LAYR LWID_('L','A','Y','R')
52 #define ID_TAGS LWID_('T','A','G','S')
53 #define ID_PNTS LWID_('P','N','T','S')
54 #define ID_BBOX LWID_('B','B','O','X')
55 #define ID_VMAP LWID_('V','M','A','P')
56 #define ID_VMAD LWID_('V','M','A','D')
57 #define ID_POLS LWID_('P','O','L','S')
58 #define ID_PTAG LWID_('P','T','A','G')
59 #define ID_ENVL LWID_('E','N','V','L')
60 #define ID_CLIP LWID_('C','L','I','P')
61 #define ID_SURF LWID_('S','U','R','F')
62 #define ID_DESC LWID_('D','E','S','C')
63 #define ID_TEXT LWID_('T','E','X','T')
64 #define ID_ICON LWID_('I','C','O','N')
67 #define ID_FACE LWID_('F','A','C','E')
68 #define ID_CURV LWID_('C','U','R','V')
69 #define ID_PTCH LWID_('P','T','C','H')
70 #define ID_MBAL LWID_('M','B','A','L')
71 #define ID_BONE LWID_('B','O','N','E')
74 #define ID_SURF LWID_('S','U','R','F')
75 #define ID_PART LWID_('P','A','R','T')
76 #define ID_SMGP LWID_('S','M','G','P')
79 #define ID_PRE LWID_('P','R','E',' ')
80 #define ID_POST LWID_('P','O','S','T')
81 #define ID_KEY LWID_('K','E','Y',' ')
82 #define ID_SPAN LWID_('S','P','A','N')
83 #define ID_TCB LWID_('T','C','B',' ')
84 #define ID_HERM LWID_('H','E','R','M')
85 #define ID_BEZI LWID_('B','E','Z','I')
86 #define ID_BEZ2 LWID_('B','E','Z','2')
87 #define ID_LINE LWID_('L','I','N','E')
88 #define ID_STEP LWID_('S','T','E','P')
91 #define ID_STIL LWID_('S','T','I','L')
92 #define ID_ISEQ LWID_('I','S','E','Q')
93 #define ID_ANIM LWID_('A','N','I','M')
94 #define ID_XREF LWID_('X','R','E','F')
95 #define ID_STCC LWID_('S','T','C','C')
96 #define ID_TIME LWID_('T','I','M','E')
97 #define ID_CONT LWID_('C','O','N','T')
98 #define ID_BRIT LWID_('B','R','I','T')
99 #define ID_SATR LWID_('S','A','T','R')
100 #define ID_HUE LWID_('H','U','E',' ')
101 #define ID_GAMM LWID_('G','A','M','M')
102 #define ID_NEGA LWID_('N','E','G','A')
103 #define ID_IFLT LWID_('I','F','L','T')
104 #define ID_PFLT LWID_('P','F','L','T')
107 #define ID_COLR LWID_('C','O','L','R')
108 #define ID_LUMI LWID_('L','U','M','I')
109 #define ID_DIFF LWID_('D','I','F','F')
110 #define ID_SPEC LWID_('S','P','E','C')
111 #define ID_GLOS LWID_('G','L','O','S')
112 #define ID_REFL LWID_('R','E','F','L')
113 #define ID_RFOP LWID_('R','F','O','P')
114 #define ID_RIMG LWID_('R','I','M','G')
115 #define ID_RSAN LWID_('R','S','A','N')
116 #define ID_TRAN LWID_('T','R','A','N')
117 #define ID_TROP LWID_('T','R','O','P')
118 #define ID_TIMG LWID_('T','I','M','G')
119 #define ID_RIND LWID_('R','I','N','D')
120 #define ID_TRNL LWID_('T','R','N','L')
121 #define ID_BUMP LWID_('B','U','M','P')
122 #define ID_SMAN LWID_('S','M','A','N')
123 #define ID_SIDE LWID_('S','I','D','E')
124 #define ID_CLRH LWID_('C','L','R','H')
125 #define ID_CLRF LWID_('C','L','R','F')
126 #define ID_ADTR LWID_('A','D','T','R')
127 #define ID_SHRP LWID_('S','H','R','P')
128 #define ID_LINE LWID_('L','I','N','E')
129 #define ID_LSIZ LWID_('L','S','I','Z')
130 #define ID_ALPH LWID_('A','L','P','H')
131 #define ID_AVAL LWID_('A','V','A','L')
132 #define ID_GVAL LWID_('G','V','A','L')
133 #define ID_BLOK LWID_('B','L','O','K')
136 #define ID_TYPE LWID_('T','Y','P','E')
137 #define ID_CHAN LWID_('C','H','A','N')
138 #define ID_NAME LWID_('N','A','M','E')
139 #define ID_ENAB LWID_('E','N','A','B')
140 #define ID_OPAC LWID_('O','P','A','C')
141 #define ID_FLAG LWID_('F','L','A','G')
142 #define ID_PROJ LWID_('P','R','O','J')
143 #define ID_STCK LWID_('S','T','C','K')
144 #define ID_TAMP LWID_('T','A','M','P')
146 /* texture coordinates */
147 #define ID_TMAP LWID_('T','M','A','P')
148 #define ID_AXIS LWID_('A','X','I','S')
149 #define ID_CNTR LWID_('C','N','T','R')
150 #define ID_SIZE LWID_('S','I','Z','E')
151 #define ID_ROTA LWID_('R','O','T','A')
152 #define ID_OREF LWID_('O','R','E','F')
153 #define ID_FALL LWID_('F','A','L','L')
154 #define ID_CSYS LWID_('C','S','Y','S')
157 #define ID_IMAP LWID_('I','M','A','P')
158 #define ID_IMAG LWID_('I','M','A','G')
159 #define ID_WRAP LWID_('W','R','A','P')
160 #define ID_WRPW LWID_('W','R','P','W')
161 #define ID_WRPH LWID_('W','R','P','H')
162 #define ID_VMAP LWID_('V','M','A','P')
163 #define ID_AAST LWID_('A','A','S','T')
164 #define ID_PIXB LWID_('P','I','X','B')
167 #define ID_PROC LWID_('P','R','O','C')
168 #define ID_COLR LWID_('C','O','L','R')
169 #define ID_VALU LWID_('V','A','L','U')
170 #define ID_FUNC LWID_('F','U','N','C')
171 #define ID_FTPS LWID_('F','T','P','S')
172 #define ID_ITPS LWID_('I','T','P','S')
173 #define ID_ETPS LWID_('E','T','P','S')
176 #define ID_GRAD LWID_('G','R','A','D')
177 #define ID_GRST LWID_('G','R','S','T')
178 #define ID_GREN LWID_('G','R','E','N')
179 #define ID_PNAM LWID_('P','N','A','M')
180 #define ID_INAM LWID_('I','N','A','M')
181 #define ID_GRPT LWID_('G','R','P','T')
182 #define ID_FKEY LWID_('F','K','E','Y')
183 #define ID_IKEY LWID_('I','K','E','Y')
186 #define ID_SHDR LWID_('S','H','D','R')
187 #define ID_DATA LWID_('D','A','T','A')
190 /* generic linked list */
192 typedef struct st_lwNode {
193 struct st_lwNode *next, *prev;
198 /* plug-in reference */
200 typedef struct st_lwPlugin {
201 struct st_lwPlugin *next, *prev;
211 typedef struct st_lwKey {
212 struct st_lwKey *next, *prev;
215 unsigned int shape; /* ID_TCB, ID_BEZ2, etc. */
222 typedef struct st_lwEnvelope {
223 struct st_lwEnvelope *next, *prev;
227 lwKey *key; /* linked list of keys */
229 int behavior[ 2 ]; /* pre and post (extrapolation) */
230 lwPlugin *cfilter; /* linked list of channel filters */
235 #define BEH_CONSTANT 1
237 #define BEH_OSCILLATE 3
242 /* values that can be enveloped */
244 typedef struct st_lwEParam {
249 typedef struct st_lwVParam {
257 typedef struct st_lwClipStill {
261 typedef struct st_lwClipSeq {
262 char *prefix; /* filename before sequence digits */
263 char *suffix; /* after digits, e.g. extensions */
271 typedef struct st_lwClipAnim {
273 char *server; /* anim loader plug-in */
277 typedef struct st_lwClipXRef {
280 struct st_lwClip *clip;
283 typedef struct st_lwClipCycle {
289 typedef struct st_lwClip {
290 struct st_lwClip *next, *prev;
292 unsigned int type; /* ID_STIL, ID_ISEQ, etc. */
309 lwPlugin *ifilter; /* linked list of image filters */
311 lwPlugin *pfilter; /* linked list of pixel filters */
318 typedef struct st_lwTMap {
328 typedef struct st_lwImageMap {
344 #define PROJ_PLANAR 0
345 #define PROJ_CYLINDRICAL 1
346 #define PROJ_SPHERICAL 2
352 #define WRAP_REPEAT 2
353 #define WRAP_MIRROR 3
355 typedef struct st_lwProcedural {
362 typedef struct st_lwGradKey {
363 struct st_lwGradKey *next, *prev;
368 typedef struct st_lwGradient {
374 lwGradKey *key; /* array of gradient keys */
375 short *ikey; /* array of interpolation codes */
378 typedef struct st_lwTexture {
379 struct st_lwTexture *next, *prev;
397 /* values that can be textured */
399 typedef struct st_lwTParam {
402 lwTexture *tex; /* linked list of texture layers */
405 typedef struct st_lwCParam {
408 lwTexture *tex; /* linked list of texture layers */
414 typedef struct st_lwGlow {
421 typedef struct st_lwRMap {
428 typedef struct st_lwLine {
430 unsigned short flags;
434 typedef struct st_lwSurface {
435 struct st_lwSurface *next, *prev;
441 lwTParam specularity;
446 lwTParam translucency;
452 lwEParam color_hilite;
453 lwEParam color_filter;
458 lwPlugin *shader; /* linked list of shaders */
465 typedef struct st_lwVMap {
466 struct st_lwVMap *next, *prev;
472 int *vindex; /* array of point indexes */
473 int *pindex; /* array of polygon indexes */
480 typedef struct st_lwVMapPt {
482 int index; /* vindex or pindex element */
486 /* points and polygons */
488 typedef struct st_lwPoint {
490 int npols; /* number of polygons sharing the point */
491 int *pol; /* array of polygon indexes */
493 lwVMapPt *vm; /* array of vmap references */
496 typedef struct st_lwPolVert {
497 int index; /* index into the point array */
500 lwVMapPt *vm; /* array of vmap references */
503 typedef struct st_lwPolygon {
505 int part; /* part index */
506 int smoothgrp; /* smoothing group */
511 lwPolVert *v; /* array of vertex records */
514 typedef struct st_lwPointList {
516 int offset; /* only used during reading */
517 lwPoint *pt; /* array of points */
520 typedef struct st_lwPolygonList {
522 int offset; /* only used during reading */
523 int vcount; /* total number of vertices */
524 int voffset; /* only used during reading */
525 lwPolygon *pol; /* array of polygons */
529 /* geometry layers */
531 typedef struct st_lwLayer {
532 struct st_lwLayer *next, *prev;
540 lwPolygonList polygon;
542 lwVMap *vmap; /* linked list of vmaps */
548 typedef struct st_lwTagList {
550 int offset; /* only used during reading */
551 char **tag; /* array of strings */
557 typedef struct st_lwObject {
559 lwLayer * layer; /* linked list of layers */
560 lwEnvelope * env; /* linked list of envelopes */
561 lwClip * clip; /* linked list of clips */
562 lwSurface * surf; /* linked list of surfaces */
573 lwObject *lwGetObject( const char *filename, unsigned int *failID, int *failpos );
574 void lwFreeObject( lwObject *object );
575 void lwFreeLayer( lwLayer *layer );
579 void lwFreePoints( lwPointList *point );
580 void lwFreePolygons( lwPolygonList *plist );
581 int lwGetPoints( idFile *fp, int cksize, lwPointList *point );
582 void lwGetBoundingBox( lwPointList *point, float bbox[] );
583 int lwAllocPolygons( lwPolygonList *plist, int npols, int nverts );
584 int lwGetPolygons( idFile *fp, int cksize, lwPolygonList *plist, int ptoffset );
585 void lwGetPolyNormals( lwPointList *point, lwPolygonList *polygon );
586 int lwGetPointPolygons( lwPointList *point, lwPolygonList *polygon );
587 int lwResolvePolySurfaces( lwPolygonList *polygon, lwTagList *tlist,
588 lwSurface **surf, int *nsurfs );
589 void lwGetVertNormals( lwPointList *point, lwPolygonList *polygon );
590 void lwFreeTags( lwTagList *tlist );
591 int lwGetTags( idFile *fp, int cksize, lwTagList *tlist );
592 int lwGetPolygonTags( idFile *fp, int cksize, lwTagList *tlist,
593 lwPolygonList *plist );
597 void lwFreeVMap( lwVMap *vmap );
598 lwVMap *lwGetVMap( idFile *fp, int cksize, int ptoffset, int poloffset,
600 int lwGetPointVMaps( lwPointList *point, lwVMap *vmap );
601 int lwGetPolyVMaps( lwPolygonList *polygon, lwVMap *vmap );
605 void lwFreeClip( lwClip *clip );
606 lwClip *lwGetClip( idFile *fp, int cksize );
607 lwClip *lwFindClip( lwClip *list, int index );
611 void lwFreeEnvelope( lwEnvelope *env );
612 lwEnvelope *lwGetEnvelope( idFile *fp, int cksize );
613 lwEnvelope *lwFindEnvelope( lwEnvelope *list, int index );
614 float lwEvalEnvelope( lwEnvelope *env, float time );
618 void lwFreePlugin( lwPlugin *p );
619 void lwFreeTexture( lwTexture *t );
620 void lwFreeSurface( lwSurface *surf );
621 int lwGetTHeader( idFile *fp, int hsz, lwTexture *tex );
622 int lwGetTMap( idFile *fp, int tmapsz, lwTMap *tmap );
623 int lwGetImageMap( idFile *fp, int rsz, lwTexture *tex );
624 int lwGetProcedural( idFile *fp, int rsz, lwTexture *tex );
625 int lwGetGradient( idFile *fp, int rsz, lwTexture *tex );
626 lwTexture *lwGetTexture( idFile *fp, int bloksz, unsigned int type );
627 lwPlugin *lwGetShader( idFile *fp, int bloksz );
628 lwSurface *lwGetSurface( idFile *fp, int cksize );
629 lwSurface *lwDefaultSurface( void );
633 lwSurface *lwGetSurface5( idFile *fp, int cksize, lwObject *obj );
634 int lwGetPolygons5( idFile *fp, int cksize, lwPolygonList *plist, int ptoffset );
635 lwObject *lwGetObject5( const char *filename, unsigned int *failID, int *failpos );
639 void lwListFree( void *list, void ( *freeNode )( void * ));
640 void lwListAdd( void **list, void *node );
641 void lwListInsert( void **vlist, void *vitem,
642 int ( *compare )( void *, void * ));
646 float dot( float a[], float b[] );
647 void cross( float a[], float b[], float c[] );
648 void normalize( float v[] );
649 #define vecangle( a, b ) ( float ) idMath::ACos( dot( a, b ) )
653 void set_flen( int i );
654 int get_flen( void );
655 void *getbytes( idFile *fp, int size );
656 void skipbytes( idFile *fp, int n );
657 int getI1( idFile *fp );
658 short getI2( idFile *fp );
659 int getI4( idFile *fp );
660 unsigned char getU1( idFile *fp );
661 unsigned short getU2( idFile *fp );
662 unsigned int getU4( idFile *fp );
663 int getVX( idFile *fp );
664 float getF4( idFile *fp );
665 char *getS0( idFile *fp );
666 int sgetI1( unsigned char **bp );
667 short sgetI2( unsigned char **bp );
668 int sgetI4( unsigned char **bp );
669 unsigned char sgetU1( unsigned char **bp );
670 unsigned short sgetU2( unsigned char **bp );
671 unsigned int sgetU4( unsigned char **bp );
672 int sgetVX( unsigned char **bp );
673 float sgetF4( unsigned char **bp );
674 char *sgetS0( unsigned char **bp );
676 #endif /* !__LWO2_H__ */