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 29 #ifndef __LWO2_H__ 30 #define __LWO2_H__ 31 32 /* 33 ====================================================================== 34 35 LWO2 loader. (LightWave Object) 36 37 Ernie Wright 17 Sep 00 38 39 ====================================================================== 40 */ 41 42 /* chunk and subchunk IDs */ 43 44 #define LWID_(a,b,c,d) (((a)<<24)|((b)<<16)|((c)<<8)|(d)) 45 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') 49 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') 65 66 /* polygon types */ 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') 72 73 /* polygon tags */ 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') 77 78 /* envelopes */ 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') 89 90 /* clips */ 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') 105 106 /* surfaces */ 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') 134 135 /* texture layer */ 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') 145 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') 155 156 /* image map */ 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') 165 166 /* procedural */ 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') 174 175 /* gradient */ 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') 184 185 /* shader */ 186 #define ID_SHDR LWID_('S','H','D','R') 187 #define ID_DATA LWID_('D','A','T','A') 188 189 190 /* generic linked list */ 191 192 typedef struct st_lwNode { 193 struct st_lwNode *next, *prev; 194 void *data; 195 } lwNode; 196 197 198 /* plug-in reference */ 199 200 typedef struct st_lwPlugin { 201 struct st_lwPlugin *next, *prev; 202 char *ord; 203 char *name; 204 int flags; 205 void *data; 206 } lwPlugin; 207 208 209 /* envelopes */ 210 211 typedef struct st_lwKey { 212 struct st_lwKey *next, *prev; 213 float value; 214 float time; 215 unsigned int shape; /* ID_TCB, ID_BEZ2, etc. */ 216 float tension; 217 float continuity; 218 float bias; 219 float param[ 4 ]; 220 } lwKey; 221 222 typedef struct st_lwEnvelope { 223 struct st_lwEnvelope *next, *prev; 224 int index; 225 int type; 226 char *name; 227 lwKey *key; /* linked list of keys */ 228 int nkeys; 229 int behavior[ 2 ]; /* pre and post (extrapolation) */ 230 lwPlugin *cfilter; /* linked list of channel filters */ 231 int ncfilters; 232 } lwEnvelope; 233 234 #define BEH_RESET 0 235 #define BEH_CONSTANT 1 236 #define BEH_REPEAT 2 237 #define BEH_OSCILLATE 3 238 #define BEH_OFFSET 4 239 #define BEH_LINEAR 5 240 241 242 /* values that can be enveloped */ 243 244 typedef struct st_lwEParam { 245 float val; 246 int eindex; 247 } lwEParam; 248 249 typedef struct st_lwVParam { 250 float val[ 3 ]; 251 int eindex; 252 } lwVParam; 253 254 255 /* clips */ 256 257 typedef struct st_lwClipStill { 258 char *name; 259 } lwClipStill; 260 261 typedef struct st_lwClipSeq { 262 char *prefix; /* filename before sequence digits */ 263 char *suffix; /* after digits, e.g. extensions */ 264 int digits; 265 int flags; 266 int offset; 267 int start; 268 int end; 269 } lwClipSeq; 270 271 typedef struct st_lwClipAnim { 272 char *name; 273 char *server; /* anim loader plug-in */ 274 void *data; 275 } lwClipAnim; 276 277 typedef struct st_lwClipXRef { 278 char *string; 279 int index; 280 struct st_lwClip *clip; 281 } lwClipXRef; 282 283 typedef struct st_lwClipCycle { 284 char *name; 285 int lo; 286 int hi; 287 } lwClipCycle; 288 289 typedef struct st_lwClip { 290 struct st_lwClip *next, *prev; 291 int index; 292 unsigned int type; /* ID_STIL, ID_ISEQ, etc. */ 293 union { 294 lwClipStill still; 295 lwClipSeq seq; 296 lwClipAnim anim; 297 lwClipXRef xref; 298 lwClipCycle cycle; 299 } source; 300 float start_time; 301 float duration; 302 float frame_rate; 303 lwEParam contrast; 304 lwEParam brightness; 305 lwEParam saturation; 306 lwEParam hue; 307 lwEParam gamma; 308 int negative; 309 lwPlugin *ifilter; /* linked list of image filters */ 310 int nifilters; 311 lwPlugin *pfilter; /* linked list of pixel filters */ 312 int npfilters; 313 } lwClip; 314 315 316 /* textures */ 317 318 typedef struct st_lwTMap { 319 lwVParam size; 320 lwVParam center; 321 lwVParam rotate; 322 lwVParam falloff; 323 int fall_type; 324 char *ref_object; 325 int coord_sys; 326 } lwTMap; 327 328 typedef struct st_lwImageMap { 329 int cindex; 330 int projection; 331 char *vmap_name; 332 int axis; 333 int wrapw_type; 334 int wraph_type; 335 lwEParam wrapw; 336 lwEParam wraph; 337 float aa_strength; 338 int aas_flags; 339 int pblend; 340 lwEParam stck; 341 lwEParam amplitude; 342 } lwImageMap; 343 344 #define PROJ_PLANAR 0 345 #define PROJ_CYLINDRICAL 1 346 #define PROJ_SPHERICAL 2 347 #define PROJ_CUBIC 3 348 #define PROJ_FRONT 4 349 350 #define WRAP_NONE 0 351 #define WRAP_EDGE 1 352 #define WRAP_REPEAT 2 353 #define WRAP_MIRROR 3 354 355 typedef struct st_lwProcedural { 356 int axis; 357 float value[ 3 ]; 358 char *name; 359 void *data; 360 } lwProcedural; 361 362 typedef struct st_lwGradKey { 363 struct st_lwGradKey *next, *prev; 364 float value; 365 float rgba[ 4 ]; 366 } lwGradKey; 367 368 typedef struct st_lwGradient { 369 char *paramname; 370 char *itemname; 371 float start; 372 float end; 373 int repeat; 374 lwGradKey *key; /* array of gradient keys */ 375 short *ikey; /* array of interpolation codes */ 376 } lwGradient; 377 378 typedef struct st_lwTexture { 379 struct st_lwTexture *next, *prev; 380 char *ord; 381 unsigned int type; 382 unsigned int chan; 383 lwEParam opacity; 384 short opac_type; 385 short enabled; 386 short negative; 387 short axis; 388 union { 389 lwImageMap imap; 390 lwProcedural proc; 391 lwGradient grad; 392 } param; 393 lwTMap tmap; 394 } lwTexture; 395 396 397 /* values that can be textured */ 398 399 typedef struct st_lwTParam { 400 float val; 401 int eindex; 402 lwTexture *tex; /* linked list of texture layers */ 403 } lwTParam; 404 405 typedef struct st_lwCParam { 406 float rgb[ 3 ]; 407 int eindex; 408 lwTexture *tex; /* linked list of texture layers */ 409 } lwCParam; 410 411 412 /* surfaces */ 413 414 typedef struct st_lwGlow { 415 short enabled; 416 short type; 417 lwEParam intensity; 418 lwEParam size; 419 } Glow; 420 421 typedef struct st_lwRMap { 422 lwTParam val; 423 int options; 424 int cindex; 425 float seam_angle; 426 } lwRMap; 427 428 typedef struct st_lwLine { 429 short enabled; 430 unsigned short flags; 431 lwEParam size; 432 } lwLine; 433 434 typedef struct st_lwSurface { 435 struct st_lwSurface *next, *prev; 436 char *name; 437 char *srcname; 438 lwCParam color; 439 lwTParam luminosity; 440 lwTParam diffuse; 441 lwTParam specularity; 442 lwTParam glossiness; 443 lwRMap reflection; 444 lwRMap transparency; 445 lwTParam eta; 446 lwTParam translucency; 447 lwTParam bump; 448 float smooth; 449 int sideflags; 450 float alpha; 451 int alpha_mode; 452 lwEParam color_hilite; 453 lwEParam color_filter; 454 lwEParam add_trans; 455 lwEParam dif_sharp; 456 lwEParam glow; 457 lwLine line; 458 lwPlugin *shader; /* linked list of shaders */ 459 int nshaders; 460 } lwSurface; 461 462 463 /* vertex maps */ 464 465 typedef struct st_lwVMap { 466 struct st_lwVMap *next, *prev; 467 char *name; 468 unsigned int type; 469 int dim; 470 int nverts; 471 int perpoly; 472 int *vindex; /* array of point indexes */ 473 int *pindex; /* array of polygon indexes */ 474 float **val; 475 476 // added by duffy 477 int offset; 478 } lwVMap; 479 480 typedef struct st_lwVMapPt { 481 lwVMap *vmap; 482 int index; /* vindex or pindex element */ 483 } lwVMapPt; 484 485 486 /* points and polygons */ 487 488 typedef struct st_lwPoint { 489 float pos[ 3 ]; 490 int npols; /* number of polygons sharing the point */ 491 int *pol; /* array of polygon indexes */ 492 int nvmaps; 493 lwVMapPt *vm; /* array of vmap references */ 494 } lwPoint; 495 496 typedef struct st_lwPolVert { 497 int index; /* index into the point array */ 498 float norm[ 3 ]; 499 int nvmaps; 500 lwVMapPt *vm; /* array of vmap references */ 501 } lwPolVert; 502 503 typedef struct st_lwPolygon { 504 lwSurface *surf; 505 int part; /* part index */ 506 int smoothgrp; /* smoothing group */ 507 int flags; 508 unsigned int type; 509 float norm[ 3 ]; 510 int nverts; 511 lwPolVert *v; /* array of vertex records */ 512 } lwPolygon; 513 514 typedef struct st_lwPointList { 515 int count; 516 int offset; /* only used during reading */ 517 lwPoint *pt; /* array of points */ 518 } lwPointList; 519 520 typedef struct st_lwPolygonList { 521 int count; 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 */ 526 } lwPolygonList; 527 528 529 /* geometry layers */ 530 531 typedef struct st_lwLayer { 532 struct st_lwLayer *next, *prev; 533 char *name; 534 int index; 535 int parent; 536 int flags; 537 float pivot[ 3 ]; 538 float bbox[ 6 ]; 539 lwPointList point; 540 lwPolygonList polygon; 541 int nvmaps; 542 lwVMap *vmap; /* linked list of vmaps */ 543 } lwLayer; 544 545 546 /* tag strings */ 547 548 typedef struct st_lwTagList { 549 int count; 550 int offset; /* only used during reading */ 551 char **tag; /* array of strings */ 552 } lwTagList; 553 554 555 /* an object */ 556 557 typedef struct st_lwObject { 558 ID_TIME_T timeStamp; 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 */ 563 lwTagList taglist; 564 int nlayers; 565 int nenvs; 566 int nclips; 567 int nsurfs; 568 } lwObject; 569 570 571 /* lwo2.c */ 572 573 lwObject *lwGetObject( const char *filename, unsigned int *failID, int *failpos ); 574 void lwFreeObject( lwObject *object ); 575 void lwFreeLayer( lwLayer *layer ); 576 577 /* pntspols.c */ 578 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 ); 594 595 /* vmap.c */ 596 597 void lwFreeVMap( lwVMap *vmap ); 598 lwVMap *lwGetVMap( idFile *fp, int cksize, int ptoffset, int poloffset, 599 int perpoly ); 600 int lwGetPointVMaps( lwPointList *point, lwVMap *vmap ); 601 int lwGetPolyVMaps( lwPolygonList *polygon, lwVMap *vmap ); 602 603 /* clip.c */ 604 605 void lwFreeClip( lwClip *clip ); 606 lwClip *lwGetClip( idFile *fp, int cksize ); 607 lwClip *lwFindClip( lwClip *list, int index ); 608 609 /* envelope.c */ 610 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 ); 615 616 /* surface.c */ 617 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 ); 630 631 /* lwob.c */ 632 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 ); 636 637 /* list.c */ 638 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 * )); 643 644 /* vecmath.c */ 645 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 ) ) 650 651 /* lwio.c */ 652 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 ); 675 676 #endif /* !__LWO2_H__ */ 677