| 1 | /* | 
|---|
| 2 |  | 
|---|
| 3 | Lightwave Object Loader | 
|---|
| 4 | (LWOB, LWLO, LWO2) | 
|---|
| 5 |  | 
|---|
| 6 | converted by Dennis Verbeek (dennis.verbeek@chello.nl) | 
|---|
| 7 |  | 
|---|
| 8 | These files were originally coded by Ernie Wright and were included in the  | 
|---|
| 9 | Lightwave SDK. | 
|---|
| 10 | */ | 
|---|
| 11 |  | 
|---|
| 12 | #ifndef _LWO_H_ | 
|---|
| 13 | #define _LWO_H_ | 
|---|
| 14 |  | 
|---|
| 15 | #include <iostream> | 
|---|
| 16 | #include <fstream> | 
|---|
| 17 | #include <vector> | 
|---|
| 18 | #include <algorithm> | 
|---|
| 19 | #include "Point.h" | 
|---|
| 20 |  | 
|---|
| 21 | //using namespace std; | 
|---|
| 22 |  | 
|---|
| 23 | /* chunk and subchunk IDs */ | 
|---|
| 24 |  | 
|---|
| 25 | #define LWID_(a,b,c,d) (((a)<<24)|((b)<<16)|((c)<<8)|(d)) | 
|---|
| 26 |  | 
|---|
| 27 | #define ID_FORM LWID_('F','O','R','M') | 
|---|
| 28 | #define ID_LWO2 LWID_('L','W','O','2') | 
|---|
| 29 | #define ID_LWOB LWID_('L','W','O','B') | 
|---|
| 30 | #define ID_LWLO LWID_('L','W','L','O') | 
|---|
| 31 |  | 
|---|
| 32 | /* top-level chunks */ | 
|---|
| 33 | #define ID_LAYR LWID_('L','A','Y','R') | 
|---|
| 34 | #define ID_TAGS LWID_('T','A','G','S') | 
|---|
| 35 | #define ID_PNTS LWID_('P','N','T','S') | 
|---|
| 36 | #define ID_BBOX LWID_('B','B','O','X') | 
|---|
| 37 | #define ID_VMAP LWID_('V','M','A','P') | 
|---|
| 38 | #define ID_VMAD LWID_('V','M','A','D') | 
|---|
| 39 | #define ID_POLS LWID_('P','O','L','S') | 
|---|
| 40 | #define ID_PTAG LWID_('P','T','A','G') | 
|---|
| 41 | #define ID_ENVL LWID_('E','N','V','L') | 
|---|
| 42 | #define ID_CLIP LWID_('C','L','I','P') | 
|---|
| 43 | #define ID_SURF LWID_('S','U','R','F') | 
|---|
| 44 | #define ID_DESC LWID_('D','E','S','C') | 
|---|
| 45 | #define ID_TEXT LWID_('T','E','X','T') | 
|---|
| 46 | #define ID_ICON LWID_('I','C','O','N') | 
|---|
| 47 |  | 
|---|
| 48 | /* polygon types */ | 
|---|
| 49 | #define ID_FACE LWID_('F','A','C','E') | 
|---|
| 50 | #define ID_CURV LWID_('C','U','R','V') | 
|---|
| 51 | #define ID_PTCH LWID_('P','T','C','H') | 
|---|
| 52 | #define ID_MBAL LWID_('M','B','A','L') | 
|---|
| 53 | #define ID_BONE LWID_('B','O','N','E') | 
|---|
| 54 |  | 
|---|
| 55 | /* polygon tags */ | 
|---|
| 56 | #define ID_SURF LWID_('S','U','R','F') | 
|---|
| 57 | #define ID_PART LWID_('P','A','R','T') | 
|---|
| 58 | #define ID_SMGP LWID_('S','M','G','P') | 
|---|
| 59 |  | 
|---|
| 60 | /* envelopes */ | 
|---|
| 61 | #define ID_PRE  LWID_('P','R','E',' ') | 
|---|
| 62 | #define ID_POST LWID_('P','O','S','T') | 
|---|
| 63 | #define ID_KEY  LWID_('K','E','Y',' ') | 
|---|
| 64 | #define ID_SPAN LWID_('S','P','A','N') | 
|---|
| 65 | #define ID_TCB  LWID_('T','C','B',' ') | 
|---|
| 66 | #define ID_HERM LWID_('H','E','R','M') | 
|---|
| 67 | #define ID_BEZI LWID_('B','E','Z','I') | 
|---|
| 68 | #define ID_BEZ2 LWID_('B','E','Z','2') | 
|---|
| 69 | #define ID_LINE LWID_('L','I','N','E') | 
|---|
| 70 | #define ID_STEP LWID_('S','T','E','P') | 
|---|
| 71 |  | 
|---|
| 72 | /* clips */ | 
|---|
| 73 | #define ID_STIL LWID_('S','T','I','L') | 
|---|
| 74 | #define ID_ISEQ LWID_('I','S','E','Q') | 
|---|
| 75 | #define ID_ANIM LWID_('A','N','I','M') | 
|---|
| 76 | #define ID_XREF LWID_('X','R','E','F') | 
|---|
| 77 | #define ID_STCC LWID_('S','T','C','C') | 
|---|
| 78 | #define ID_TIME LWID_('T','I','M','E') | 
|---|
| 79 | #define ID_CONT LWID_('C','O','N','T') | 
|---|
| 80 | #define ID_BRIT LWID_('B','R','I','T') | 
|---|
| 81 | #define ID_SATR LWID_('S','A','T','R') | 
|---|
| 82 | #define ID_HUE  LWID_('H','U','E',' ') | 
|---|
| 83 | #define ID_GAMM LWID_('G','A','M','M') | 
|---|
| 84 | #define ID_NEGA LWID_('N','E','G','A') | 
|---|
| 85 | #define ID_IFLT LWID_('I','F','L','T') | 
|---|
| 86 | #define ID_PFLT LWID_('P','F','L','T') | 
|---|
| 87 |  | 
|---|
| 88 | /* surfaces */ | 
|---|
| 89 | #define ID_COLR LWID_('C','O','L','R') | 
|---|
| 90 | #define ID_LUMI LWID_('L','U','M','I') | 
|---|
| 91 | #define ID_DIFF LWID_('D','I','F','F') | 
|---|
| 92 | #define ID_SPEC LWID_('S','P','E','C') | 
|---|
| 93 | #define ID_GLOS LWID_('G','L','O','S') | 
|---|
| 94 | #define ID_REFL LWID_('R','E','F','L') | 
|---|
| 95 | #define ID_RFOP LWID_('R','F','O','P') | 
|---|
| 96 | #define ID_RIMG LWID_('R','I','M','G') | 
|---|
| 97 | #define ID_RSAN LWID_('R','S','A','N') | 
|---|
| 98 | #define ID_TRAN LWID_('T','R','A','N') | 
|---|
| 99 | #define ID_TROP LWID_('T','R','O','P') | 
|---|
| 100 | #define ID_TIMG LWID_('T','I','M','G') | 
|---|
| 101 | #define ID_RIND LWID_('R','I','N','D') | 
|---|
| 102 | #define ID_TRNL LWID_('T','R','N','L') | 
|---|
| 103 | #define ID_BUMP LWID_('B','U','M','P') | 
|---|
| 104 | #define ID_SMAN LWID_('S','M','A','N') | 
|---|
| 105 | #define ID_SIDE LWID_('S','I','D','E') | 
|---|
| 106 | #define ID_CLRH LWID_('C','L','R','H') | 
|---|
| 107 | #define ID_CLRF LWID_('C','L','R','F') | 
|---|
| 108 | #define ID_ADTR LWID_('A','D','T','R') | 
|---|
| 109 | #define ID_SHRP LWID_('S','H','R','P') | 
|---|
| 110 | #define ID_LINE LWID_('L','I','N','E') | 
|---|
| 111 | #define ID_LSIZ LWID_('L','S','I','Z') | 
|---|
| 112 | #define ID_ALPH LWID_('A','L','P','H') | 
|---|
| 113 | #define ID_AVAL LWID_('A','V','A','L') | 
|---|
| 114 | #define ID_GVAL LWID_('G','V','A','L') | 
|---|
| 115 | #define ID_BLOK LWID_('B','L','O','K') | 
|---|
| 116 |  | 
|---|
| 117 | /* texture layer */ | 
|---|
| 118 | #define ID_TYPE LWID_('T','Y','P','E') | 
|---|
| 119 | #define ID_CHAN LWID_('C','H','A','N') | 
|---|
| 120 | #define ID_NAME LWID_('N','A','M','E') | 
|---|
| 121 | #define ID_ENAB LWID_('E','N','A','B') | 
|---|
| 122 | #define ID_OPAC LWID_('O','P','A','C') | 
|---|
| 123 | #define ID_FLAG LWID_('F','L','A','G') | 
|---|
| 124 | #define ID_PROJ LWID_('P','R','O','J') | 
|---|
| 125 | #define ID_STCK LWID_('S','T','C','K') | 
|---|
| 126 | #define ID_TAMP LWID_('T','A','M','P') | 
|---|
| 127 |  | 
|---|
| 128 | /* texture coordinates */ | 
|---|
| 129 | #define ID_TMAP LWID_('T','M','A','P') | 
|---|
| 130 | #define ID_AXIS LWID_('A','X','I','S') | 
|---|
| 131 | #define ID_CNTR LWID_('C','N','T','R') | 
|---|
| 132 | #define ID_SIZE LWID_('S','I','Z','E') | 
|---|
| 133 | #define ID_ROTA LWID_('R','O','T','A') | 
|---|
| 134 | #define ID_OREF LWID_('O','R','E','F') | 
|---|
| 135 | #define ID_FALL LWID_('F','A','L','L') | 
|---|
| 136 | #define ID_CSYS LWID_('C','S','Y','S') | 
|---|
| 137 |  | 
|---|
| 138 | /* image map */ | 
|---|
| 139 | #define ID_IMAP LWID_('I','M','A','P') | 
|---|
| 140 | #define ID_IMAG LWID_('I','M','A','G') | 
|---|
| 141 | #define ID_WRAP LWID_('W','R','A','P') | 
|---|
| 142 | #define ID_WRPW LWID_('W','R','P','W') | 
|---|
| 143 | #define ID_WRPH LWID_('W','R','P','H') | 
|---|
| 144 | #define ID_VMAP LWID_('V','M','A','P') | 
|---|
| 145 | #define ID_AAST LWID_('A','A','S','T') | 
|---|
| 146 | #define ID_PIXB LWID_('P','I','X','B') | 
|---|
| 147 |  | 
|---|
| 148 | /* procedural */ | 
|---|
| 149 | #define ID_PROC LWID_('P','R','O','C') | 
|---|
| 150 | #define ID_COLR LWID_('C','O','L','R') | 
|---|
| 151 | #define ID_VALU LWID_('V','A','L','U') | 
|---|
| 152 | #define ID_FUNC LWID_('F','U','N','C') | 
|---|
| 153 | #define ID_FTPS LWID_('F','T','P','S') | 
|---|
| 154 | #define ID_ITPS LWID_('I','T','P','S') | 
|---|
| 155 | #define ID_ETPS LWID_('E','T','P','S') | 
|---|
| 156 |  | 
|---|
| 157 | /* gradient */ | 
|---|
| 158 | #define ID_GRAD LWID_('G','R','A','D') | 
|---|
| 159 | #define ID_GRST LWID_('G','R','S','T') | 
|---|
| 160 | #define ID_GREN LWID_('G','R','E','N') | 
|---|
| 161 | #define ID_PNAM LWID_('P','N','A','M') | 
|---|
| 162 | #define ID_INAM LWID_('I','N','A','M') | 
|---|
| 163 | #define ID_GRPT LWID_('G','R','P','T') | 
|---|
| 164 | #define ID_FKEY LWID_('F','K','E','Y') | 
|---|
| 165 | #define ID_IKEY LWID_('I','K','E','Y') | 
|---|
| 166 |  | 
|---|
| 167 | /* shader */ | 
|---|
| 168 | #define ID_SHDR LWID_('S','H','D','R') | 
|---|
| 169 | #define ID_DATA LWID_('D','A','T','A') | 
|---|
| 170 |  | 
|---|
| 171 | /* IDs specific to LWOB */ | 
|---|
| 172 | #define ID_SRFS LWID_('S','R','F','S') | 
|---|
| 173 | #define ID_FLAG LWID_('F','L','A','G') | 
|---|
| 174 | #define ID_VLUM LWID_('V','L','U','M') | 
|---|
| 175 | #define ID_VDIF LWID_('V','D','I','F') | 
|---|
| 176 | #define ID_VSPC LWID_('V','S','P','C') | 
|---|
| 177 | #define ID_RFLT LWID_('R','F','L','T') | 
|---|
| 178 | #define ID_BTEX LWID_('B','T','E','X') | 
|---|
| 179 | #define ID_CTEX LWID_('C','T','E','X') | 
|---|
| 180 | #define ID_DTEX LWID_('D','T','E','X') | 
|---|
| 181 | #define ID_LTEX LWID_('L','T','E','X') | 
|---|
| 182 | #define ID_RTEX LWID_('R','T','E','X') | 
|---|
| 183 | #define ID_STEX LWID_('S','T','E','X') | 
|---|
| 184 | #define ID_TTEX LWID_('T','T','E','X') | 
|---|
| 185 | #define ID_TFLG LWID_('T','F','L','G') | 
|---|
| 186 | #define ID_TSIZ LWID_('T','S','I','Z') | 
|---|
| 187 | #define ID_TCTR LWID_('T','C','T','R') | 
|---|
| 188 | #define ID_TFAL LWID_('T','F','A','L') | 
|---|
| 189 | #define ID_TVEL LWID_('T','V','E','L') | 
|---|
| 190 | #define ID_TCLR LWID_('T','C','L','R') | 
|---|
| 191 | #define ID_TVAL LWID_('T','V','A','L') | 
|---|
| 192 | #define ID_TAMP LWID_('T','A','M','P') | 
|---|
| 193 | #define ID_TIMG LWID_('T','I','M','G') | 
|---|
| 194 | #define ID_TAAS LWID_('T','A','A','S') | 
|---|
| 195 | #define ID_TREF LWID_('T','R','E','F') | 
|---|
| 196 | #define ID_TOPC LWID_('T','O','P','C') | 
|---|
| 197 | #define ID_SDAT LWID_('S','D','A','T') | 
|---|
| 198 | #define ID_TFP0 LWID_('T','F','P','0') | 
|---|
| 199 | #define ID_TFP1 LWID_('T','F','P','1') | 
|---|
| 200 |  | 
|---|
| 201 | /* Unknown tags */ | 
|---|
| 202 |  | 
|---|
| 203 | #define ID_TFP2 LWID_('T','F','P','2') | 
|---|
| 204 | #define ID_TFP3 LWID_('T','F','P','3') | 
|---|
| 205 | #define ID_SHCP LWID_('S','H','C','P') | 
|---|
| 206 | #define ID_CRVS LWID_('C','R','V','S') | 
|---|
| 207 |  | 
|---|
| 208 | /* plug-in reference */ | 
|---|
| 209 |  | 
|---|
| 210 | class lwPlugin | 
|---|
| 211 | { | 
|---|
| 212 | public: | 
|---|
| 213 |         lwPlugin() | 
|---|
| 214 |         { | 
|---|
| 215 |                 ord = 0; | 
|---|
| 216 |                 name = 0; | 
|---|
| 217 |                 data = 0; | 
|---|
| 218 |         } | 
|---|
| 219 |  | 
|---|
| 220 |         ~lwPlugin() | 
|---|
| 221 |         { | 
|---|
| 222 |                 if (ord) free(ord); | 
|---|
| 223 |                 if (name) free(name); | 
|---|
| 224 |                 if (data) free(data); | 
|---|
| 225 |         } | 
|---|
| 226 |  | 
|---|
| 227 |         char          *ord; | 
|---|
| 228 |         char          *name; | 
|---|
| 229 |         int            flags; | 
|---|
| 230 |         void          *data; | 
|---|
| 231 | }; | 
|---|
| 232 |  | 
|---|
| 233 | typedef vector<lwPlugin*> vplugins; | 
|---|
| 234 |  | 
|---|
| 235 | inline bool operator < (const lwPlugin &p1, const lwPlugin &p2 ) | 
|---|
| 236 | { | 
|---|
| 237 |         return strcmp( p1.ord, p2.ord ) < 0; | 
|---|
| 238 | } | 
|---|
| 239 |  | 
|---|
| 240 | class lwEParam | 
|---|
| 241 | { | 
|---|
| 242 | public: | 
|---|
| 243 |         lwEParam() | 
|---|
| 244 |         { | 
|---|
| 245 |                 val = 0.0f; | 
|---|
| 246 |                 eindex = 0; | 
|---|
| 247 |         } | 
|---|
| 248 |         float val; | 
|---|
| 249 |         int   eindex; | 
|---|
| 250 | }; | 
|---|
| 251 |  | 
|---|
| 252 | class lwVParam | 
|---|
| 253 | { | 
|---|
| 254 | public: | 
|---|
| 255 |         lwVParam() | 
|---|
| 256 |         { | 
|---|
| 257 |                 val[0] = val[1] = val[2] = 0.0f; | 
|---|
| 258 |                 eindex = 0; | 
|---|
| 259 |         } | 
|---|
| 260 |         float val[ 3 ]; | 
|---|
| 261 |         int   eindex; | 
|---|
| 262 | }; | 
|---|
| 263 |  | 
|---|
| 264 |  | 
|---|
| 265 | /* clips */ | 
|---|
| 266 |  | 
|---|
| 267 | /* textures */ | 
|---|
| 268 |  | 
|---|
| 269 | class lwTMap { | 
|---|
| 270 | public: | 
|---|
| 271 |         lwTMap() | 
|---|
| 272 |         { | 
|---|
| 273 |                 ref_object = 0; | 
|---|
| 274 |         } | 
|---|
| 275 |  | 
|---|
| 276 |         ~lwTMap() | 
|---|
| 277 |         { | 
|---|
| 278 |                 if (ref_object) free(ref_object); | 
|---|
| 279 |         } | 
|---|
| 280 |         lwVParam       size; | 
|---|
| 281 |         lwVParam       center; | 
|---|
| 282 |         lwVParam       rotate; | 
|---|
| 283 |         lwVParam       falloff; | 
|---|
| 284 |         int            fall_type; | 
|---|
| 285 |         char          *ref_object; | 
|---|
| 286 |         int            coord_sys; | 
|---|
| 287 | }; | 
|---|
| 288 |  | 
|---|
| 289 | class lwImageMap { | 
|---|
| 290 | public: | 
|---|
| 291 |         lwImageMap() | 
|---|
| 292 |         { | 
|---|
| 293 |                 vmap_name = 0; | 
|---|
| 294 |         } | 
|---|
| 295 |  | 
|---|
| 296 |         ~lwImageMap() | 
|---|
| 297 |         { | 
|---|
| 298 |                 if (vmap_name) free(vmap_name); | 
|---|
| 299 |         } | 
|---|
| 300 |  | 
|---|
| 301 |         int            cindex; | 
|---|
| 302 |         int            projection; | 
|---|
| 303 |         char          *vmap_name; | 
|---|
| 304 |         int            axis; | 
|---|
| 305 |         int            wrapw_type; | 
|---|
| 306 |         int            wraph_type; | 
|---|
| 307 |         lwEParam       wrapw; | 
|---|
| 308 |         lwEParam       wraph; | 
|---|
| 309 |         float          aa_strength; | 
|---|
| 310 |         int            aas_flags; | 
|---|
| 311 |         int            pblend; | 
|---|
| 312 |         lwEParam       stck; | 
|---|
| 313 |         lwEParam       amplitude; | 
|---|
| 314 | }; | 
|---|
| 315 |  | 
|---|
| 316 | #define PROJ_PLANAR       0 | 
|---|
| 317 | #define PROJ_CYLINDRICAL  1 | 
|---|
| 318 | #define PROJ_SPHERICAL    2 | 
|---|
| 319 | #define PROJ_CUBIC        3 | 
|---|
| 320 | #define PROJ_FRONT        4 | 
|---|
| 321 |  | 
|---|
| 322 | #define WRAP_NONE    0 | 
|---|
| 323 | #define WRAP_EDGE    1 | 
|---|
| 324 | #define WRAP_REPEAT  2 | 
|---|
| 325 | #define WRAP_MIRROR  3 | 
|---|
| 326 |  | 
|---|
| 327 | class lwProcedural { | 
|---|
| 328 | public: | 
|---|
| 329 |         lwProcedural() | 
|---|
| 330 |         { | 
|---|
| 331 |                 name = 0; | 
|---|
| 332 |                 data = 0; | 
|---|
| 333 |         } | 
|---|
| 334 |  | 
|---|
| 335 |         ~lwProcedural() | 
|---|
| 336 |         { | 
|---|
| 337 |                 if (name) free(name); | 
|---|
| 338 |                 if (data) free(data); | 
|---|
| 339 |         } | 
|---|
| 340 |  | 
|---|
| 341 |         int            axis; | 
|---|
| 342 |         float          value[ 3 ]; | 
|---|
| 343 |         char          *name; | 
|---|
| 344 |         void          *data; | 
|---|
| 345 | }; | 
|---|
| 346 |  | 
|---|
| 347 | class lwGradKey { | 
|---|
| 348 | public: | 
|---|
| 349 |         float          value; | 
|---|
| 350 |         float          rgba[ 4 ]; | 
|---|
| 351 | }; | 
|---|
| 352 |  | 
|---|
| 353 | class lwGradient { | 
|---|
| 354 | public: | 
|---|
| 355 |         lwGradient() | 
|---|
| 356 |         { | 
|---|
| 357 |                 paramname = 0; | 
|---|
| 358 |                 itemname = 0; | 
|---|
| 359 |                 key = 0; | 
|---|
| 360 |                 ikey = 0; | 
|---|
| 361 |         } | 
|---|
| 362 |  | 
|---|
| 363 |         ~lwGradient() | 
|---|
| 364 |         { | 
|---|
| 365 |                 if (paramname) free(paramname); | 
|---|
| 366 |                 if (itemname) free(itemname); | 
|---|
| 367 |                 if (key) free(key); | 
|---|
| 368 |                 if (ikey) free(ikey); | 
|---|
| 369 |         } | 
|---|
| 370 |  | 
|---|
| 371 |         char          *paramname; | 
|---|
| 372 |         char          *itemname; | 
|---|
| 373 |         float          start; | 
|---|
| 374 |         float          end; | 
|---|
| 375 |         int            repeat; | 
|---|
| 376 |         lwGradKey     *key;                 /* array of gradient keys */ | 
|---|
| 377 |         short         *ikey;                /* array of interpolation codes */ | 
|---|
| 378 | } ; | 
|---|
| 379 |  | 
|---|
| 380 | class lwTexture | 
|---|
| 381 | { | 
|---|
| 382 | public: | 
|---|
| 383 |         lwTexture() | 
|---|
| 384 |         { | 
|---|
| 385 |                 ord = 0; | 
|---|
| 386 |                 param.imap = 0; | 
|---|
| 387 |                  | 
|---|
| 388 |                 tmap.size.val[ 0 ] = | 
|---|
| 389 |                         tmap.size.val[ 1 ] = | 
|---|
| 390 |                         tmap.size.val[ 2 ] = 1.0f; | 
|---|
| 391 |                 opacity.val = 1.0f; | 
|---|
| 392 |                 enabled = 1;             | 
|---|
| 393 |         } | 
|---|
| 394 |  | 
|---|
| 395 |         ~lwTexture() | 
|---|
| 396 |         { | 
|---|
| 397 |                 if (ord) free(ord); | 
|---|
| 398 |                 if(param.imap) | 
|---|
| 399 |                 { | 
|---|
| 400 |                         switch (type) | 
|---|
| 401 |                         { | 
|---|
| 402 |                         case ID_IMAP: | 
|---|
| 403 |                                 delete param.imap; | 
|---|
| 404 |                                 break; | 
|---|
| 405 |                         case ID_PROC: | 
|---|
| 406 |                                 delete param.proc; | 
|---|
| 407 |                                 break; | 
|---|
| 408 |                         case ID_GRAD: | 
|---|
| 409 |                                 delete param.grad; | 
|---|
| 410 |                                 break; | 
|---|
| 411 |                         default: | 
|---|
| 412 |                                 ; | 
|---|
| 413 |                         } | 
|---|
| 414 |                 } | 
|---|
| 415 |         } | 
|---|
| 416 |         char          *ord; | 
|---|
| 417 |         unsigned int   type; | 
|---|
| 418 |         unsigned int   chan; | 
|---|
| 419 |         lwEParam       opacity; | 
|---|
| 420 |         short          opac_type; | 
|---|
| 421 |         short          enabled; | 
|---|
| 422 |         short          negative; | 
|---|
| 423 |         short          axis; | 
|---|
| 424 |         union | 
|---|
| 425 |         { | 
|---|
| 426 |                 lwImageMap     *imap; | 
|---|
| 427 |                 lwProcedural   *proc; | 
|---|
| 428 |                 lwGradient     *grad; | 
|---|
| 429 |         }              param; | 
|---|
| 430 |         lwTMap         tmap; | 
|---|
| 431 | }; | 
|---|
| 432 |  | 
|---|
| 433 | typedef vector<lwTexture*> vtextures; | 
|---|
| 434 |  | 
|---|
| 435 | /* values that can be textured */ | 
|---|
| 436 |  | 
|---|
| 437 | class lwTParam | 
|---|
| 438 | { | 
|---|
| 439 | public: | 
|---|
| 440 |         lwTParam() | 
|---|
| 441 |         { | 
|---|
| 442 |                 val = 0; | 
|---|
| 443 |                 eindex = 0; | 
|---|
| 444 |         } | 
|---|
| 445 |  | 
|---|
| 446 |         ~lwTParam() | 
|---|
| 447 |         { | 
|---|
| 448 |                 for (unsigned int i=0; i < textures.size(); delete textures[i++]); | 
|---|
| 449 |         } | 
|---|
| 450 |  | 
|---|
| 451 |         void addTexture( lwTexture *tex ) | 
|---|
| 452 |         { | 
|---|
| 453 |                 textures.insert(lower_bound(textures.begin(), textures.end(), tex), tex); | 
|---|
| 454 |         } | 
|---|
| 455 |          | 
|---|
| 456 |         float     val; | 
|---|
| 457 |         int       eindex; | 
|---|
| 458 |         vtextures textures;    /* linked list of texture layers */ | 
|---|
| 459 | }; | 
|---|
| 460 |  | 
|---|
| 461 | class lwCParam | 
|---|
| 462 | { | 
|---|
| 463 | public: | 
|---|
| 464 |         lwCParam() | 
|---|
| 465 |         { | 
|---|
| 466 |                 rgb[0] = 0.78431f; | 
|---|
| 467 |                 rgb[1] = 0.78431f; | 
|---|
| 468 |                 rgb[2] = 0.78431f; | 
|---|
| 469 |                 eindex = 0; | 
|---|
| 470 |         } | 
|---|
| 471 |  | 
|---|
| 472 |         ~lwCParam() | 
|---|
| 473 |         { | 
|---|
| 474 |                 for (unsigned int i=0; i < textures.size(); delete textures[i++]); | 
|---|
| 475 |         } | 
|---|
| 476 |  | 
|---|
| 477 |         void addTexture( lwTexture *tex ) | 
|---|
| 478 |         { | 
|---|
| 479 |                 textures.insert(lower_bound(textures.begin(), textures.end(), tex), tex); | 
|---|
| 480 |         } | 
|---|
| 481 |  | 
|---|
| 482 |         float     rgb[ 3 ]; | 
|---|
| 483 |         int       eindex; | 
|---|
| 484 |         vtextures textures;    /* linked list of texture layers */ | 
|---|
| 485 | }; | 
|---|
| 486 |  | 
|---|
| 487 |  | 
|---|
| 488 | /* surfaces */ | 
|---|
| 489 |  | 
|---|
| 490 | class lwGlow | 
|---|
| 491 | { | 
|---|
| 492 | public: | 
|---|
| 493 |         short          enabled; | 
|---|
| 494 |         short          type; | 
|---|
| 495 |         lwEParam       intensity; | 
|---|
| 496 |         lwEParam       size; | 
|---|
| 497 | }; | 
|---|
| 498 |  | 
|---|
| 499 | class lwRMap | 
|---|
| 500 | { | 
|---|
| 501 | public: | 
|---|
| 502 |         lwRMap() | 
|---|
| 503 |         { | 
|---|
| 504 |                 options = 0; | 
|---|
| 505 |                 cindex = 0; | 
|---|
| 506 |                 seam_angle = 0.0f; | 
|---|
| 507 |         } | 
|---|
| 508 |         lwTParam       val; | 
|---|
| 509 |         int            options; | 
|---|
| 510 |         int            cindex; | 
|---|
| 511 |         float          seam_angle; | 
|---|
| 512 | }; | 
|---|
| 513 |  | 
|---|
| 514 | class lwLine | 
|---|
| 515 | { | 
|---|
| 516 | public: | 
|---|
| 517 |         short          enabled; | 
|---|
| 518 |         unsigned short flags; | 
|---|
| 519 |         lwEParam       size; | 
|---|
| 520 | }; | 
|---|
| 521 |  | 
|---|
| 522 | class lwSurface | 
|---|
| 523 | { | 
|---|
| 524 | public: | 
|---|
| 525 |         lwSurface() | 
|---|
| 526 |         { | 
|---|
| 527 |                 name = 0; | 
|---|
| 528 |                 srcname = 0; | 
|---|
| 529 |                 diffuse.val        = 1.0f; | 
|---|
| 530 |                 glossiness.val = 0.4f; | 
|---|
| 531 |                 bump.val       = 1.0f; | 
|---|
| 532 |                 eta.val        = 1.0f; | 
|---|
| 533 |                 sideflags      = 1; | 
|---|
| 534 |         } | 
|---|
| 535 |          | 
|---|
| 536 |         ~lwSurface() | 
|---|
| 537 |         { | 
|---|
| 538 |                 if (name) free(name); | 
|---|
| 539 |                 if (srcname) free(srcname); | 
|---|
| 540 |                 for (unsigned int i=0; i < shaders.size(); delete shaders[i++]); | 
|---|
| 541 |         } | 
|---|
| 542 |          | 
|---|
| 543 |         int addTexture( lwTexture *tex ) | 
|---|
| 544 |         { | 
|---|
| 545 |                 switch ( tex->chan ) | 
|---|
| 546 |                 { | 
|---|
| 547 |                 case ID_COLR: | 
|---|
| 548 |                         color.addTexture(tex); | 
|---|
| 549 |                         break; | 
|---|
| 550 |                 case ID_LUMI: | 
|---|
| 551 |                         luminosity.addTexture(tex); | 
|---|
| 552 |                         break; | 
|---|
| 553 |                 case ID_DIFF: | 
|---|
| 554 |                         diffuse.addTexture(tex); | 
|---|
| 555 |                         break; | 
|---|
| 556 |                 case ID_SPEC: | 
|---|
| 557 |                         specularity.addTexture(tex); | 
|---|
| 558 |                         break; | 
|---|
| 559 |                 case ID_GLOS: | 
|---|
| 560 |                         glossiness.addTexture(tex); | 
|---|
| 561 |                         break; | 
|---|
| 562 |                 case ID_REFL: | 
|---|
| 563 |                         reflection.val.addTexture(tex); | 
|---|
| 564 |                         break; | 
|---|
| 565 |                 case ID_TRAN: | 
|---|
| 566 |                         transparency.val.addTexture(tex); | 
|---|
| 567 |                         break; | 
|---|
| 568 |                 case ID_RIND: | 
|---|
| 569 |                         eta.addTexture(tex); | 
|---|
| 570 |                         break; | 
|---|
| 571 |                 case ID_TRNL: | 
|---|
| 572 |                         translucency.addTexture(tex); | 
|---|
| 573 |                         break; | 
|---|
| 574 |                 case ID_BUMP: | 
|---|
| 575 |                         bump.addTexture(tex); | 
|---|
| 576 |                         break; | 
|---|
| 577 |                 default: | 
|---|
| 578 |                         return 0; | 
|---|
| 579 |                 } | 
|---|
| 580 |                 return 1; | 
|---|
| 581 |         } | 
|---|
| 582 |          | 
|---|
| 583 |         static lwSurface *lwDefaultSurface( void ) | 
|---|
| 584 |         { | 
|---|
| 585 |                 return new lwSurface; | 
|---|
| 586 |         } | 
|---|
| 587 |  | 
|---|
| 588 |         char *setname(const char *newname) | 
|---|
| 589 |         { | 
|---|
| 590 |                 unsigned int slength = strlen(newname); | 
|---|
| 591 |  | 
|---|
| 592 |                 if (name && slength > strlen(name)) | 
|---|
| 593 |                 { | 
|---|
| 594 |                         free(name); | 
|---|
| 595 |                         name = 0;                        | 
|---|
| 596 |                 } | 
|---|
| 597 |                 if (!name) name = (char *)malloc(slength+1); | 
|---|
| 598 |  | 
|---|
| 599 |                 return strcpy(name, newname); | 
|---|
| 600 |         } | 
|---|
| 601 |          | 
|---|
| 602 |         char             *name; | 
|---|
| 603 |         char             *srcname; | 
|---|
| 604 |         lwCParam          color; | 
|---|
| 605 |         lwTParam          luminosity; | 
|---|
| 606 |         lwTParam          diffuse; | 
|---|
| 607 |         lwTParam          specularity; | 
|---|
| 608 |         lwTParam          glossiness; | 
|---|
| 609 |         lwRMap            reflection; | 
|---|
| 610 |         lwRMap            transparency; | 
|---|
| 611 |         lwTParam          eta; | 
|---|
| 612 |         lwTParam          translucency; | 
|---|
| 613 |         lwTParam          bump; | 
|---|
| 614 |         float             smooth; | 
|---|
| 615 |         int               sideflags; | 
|---|
| 616 |         float             alpha; | 
|---|
| 617 |         int               alpha_mode; | 
|---|
| 618 |         lwEParam          color_hilite; | 
|---|
| 619 |         lwEParam          color_filter; | 
|---|
| 620 |         lwEParam          add_trans; | 
|---|
| 621 |         lwEParam          dif_sharp; | 
|---|
| 622 |         lwEParam          glow; | 
|---|
| 623 |         lwLine            line; | 
|---|
| 624 |         vplugins shaders;              /* linked list of shaders */ | 
|---|
| 625 | }; | 
|---|
| 626 |  | 
|---|
| 627 | typedef vector<lwSurface*> vsurfaces; | 
|---|
| 628 |  | 
|---|
| 629 | /* vertex maps */ | 
|---|
| 630 |  | 
|---|
| 631 | class lwVMap | 
|---|
| 632 | { | 
|---|
| 633 | public: | 
|---|
| 634 |         lwVMap() | 
|---|
| 635 |         { | 
|---|
| 636 |                 name = 0; | 
|---|
| 637 |                 vindex = 0; | 
|---|
| 638 |                 pindex = 0; | 
|---|
| 639 |                 val = 0; | 
|---|
| 640 |         } | 
|---|
| 641 |  | 
|---|
| 642 |         ~lwVMap() | 
|---|
| 643 |         { | 
|---|
| 644 |                 if (name) free(name); | 
|---|
| 645 |                 if (vindex) free(vindex); | 
|---|
| 646 |                 if (pindex) free(pindex); | 
|---|
| 647 |                  | 
|---|
| 648 |                 if (val)  | 
|---|
| 649 |                 { | 
|---|
| 650 |                         for (unsigned int i = 0; i < nverts; free(val[i++])); | 
|---|
| 651 |                         free (val); | 
|---|
| 652 |                 } | 
|---|
| 653 |         } | 
|---|
| 654 |          | 
|---|
| 655 |         char          *name; | 
|---|
| 656 |         unsigned int   type; | 
|---|
| 657 |         unsigned int   dim; | 
|---|
| 658 |         unsigned int   nverts; | 
|---|
| 659 |         int            perpoly; | 
|---|
| 660 |         int           *vindex;              /* array of point indexes */ | 
|---|
| 661 |         int           *pindex;              /* array of polygon indexes */ | 
|---|
| 662 |         float        **val; | 
|---|
| 663 | }; | 
|---|
| 664 |  | 
|---|
| 665 | typedef vector<lwVMap*> vvmaps; | 
|---|
| 666 |  | 
|---|
| 667 | class lwVMapPt | 
|---|
| 668 | { | 
|---|
| 669 |         lwVMapPt(); | 
|---|
| 670 | public: | 
|---|
| 671 |         lwVMapPt(lwVMap *nvmap, int nindex) : vmap(nvmap), index(nindex) {}; | 
|---|
| 672 |  | 
|---|
| 673 |         lwVMap        *vmap; | 
|---|
| 674 |         int            index;               /* vindex or pindex element */ | 
|---|
| 675 | }; | 
|---|
| 676 |  | 
|---|
| 677 | typedef vector<lwVMapPt> vvmapptrs; | 
|---|
| 678 |  | 
|---|
| 679 | /* points and polygons */ | 
|---|
| 680 | class lwPolygon; | 
|---|
| 681 |  | 
|---|
| 682 | typedef vector<lwPolygon*> vpolygons; | 
|---|
| 683 |  | 
|---|
| 684 | class lwPoint: public Point3 | 
|---|
| 685 | { | 
|---|
| 686 |         lwPoint(); | 
|---|
| 687 | public: | 
|---|
| 688 |         lwPoint(float r, float s, float t) : Point3(r, s, t) {}; | 
|---|
| 689 |  | 
|---|
| 690 |         vvmapptrs      vmaps;               /* array of vmap references */ | 
|---|
| 691 |         vpolygons      polygons;            /* array of polygon indexes */ | 
|---|
| 692 |         unsigned short index; | 
|---|
| 693 | }; | 
|---|
| 694 |  | 
|---|
| 695 | typedef vector<lwPoint*> vpoints; | 
|---|
| 696 |  | 
|---|
| 697 | class lwVertex | 
|---|
| 698 | { | 
|---|
| 699 |         lwVertex(); | 
|---|
| 700 |  | 
|---|
| 701 | public: | 
|---|
| 702 |         lwVertex(int nindex) : index(nindex) {} | 
|---|
| 703 |          | 
|---|
| 704 |         lwVertex(const lwVertex &v) | 
|---|
| 705 |         { | 
|---|
| 706 |                 index = v.index; | 
|---|
| 707 |                 point = v.point; | 
|---|
| 708 |                 normal = v.normal; | 
|---|
| 709 |                 vmaps = v.vmaps; | 
|---|
| 710 |         } | 
|---|
| 711 |          | 
|---|
| 712 |         int        index;      /* index into the point array */ | 
|---|
| 713 |         lwPoint   *point; | 
|---|
| 714 |         Vector3    normal; | 
|---|
| 715 |         vvmapptrs  vmaps;      /* array of vmap references */ | 
|---|
| 716 | }; | 
|---|
| 717 |  | 
|---|
| 718 | typedef vector<lwVertex*> vvertices; | 
|---|
| 719 |  | 
|---|
| 720 | typedef vector<char *> vtags; | 
|---|
| 721 |  | 
|---|
| 722 | inline bool operator < (const lwTexture &t1, const lwTexture &t2 ) | 
|---|
| 723 | { | 
|---|
| 724 |         return strcmp( t1.ord, t2.ord ) < 0; | 
|---|
| 725 | } | 
|---|
| 726 |  | 
|---|
| 727 | #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 | 
|---|
| 728 | void revbytes( void *bp, int elsize, int elcount ); | 
|---|
| 729 | #else | 
|---|
| 730 | #define revbytes( b, s, c ) | 
|---|
| 731 | #endif | 
|---|
| 732 |  | 
|---|
| 733 | #endif // _LWO_H_ | 
|---|
| 734 |  | 
|---|