Spaces:
Running
Running
File size: 10,137 Bytes
a28eca3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
class LWO2Parser {
constructor( IFFParser ) {
this.IFF = IFFParser;
}
parseBlock() {
this.IFF.debugger.offset = this.IFF.reader.offset;
this.IFF.debugger.closeForms();
const blockID = this.IFF.reader.getIDTag();
let length = this.IFF.reader.getUint32(); // size of data in bytes
if ( length > this.IFF.reader.dv.byteLength - this.IFF.reader.offset ) {
this.IFF.reader.offset -= 4;
length = this.IFF.reader.getUint16();
}
this.IFF.debugger.dataOffset = this.IFF.reader.offset;
this.IFF.debugger.length = length;
// Data types may be found in either LWO2 OR LWO3 spec
switch ( blockID ) {
case 'FORM': // form blocks may consist of sub -chunks or sub-forms
this.IFF.parseForm( length );
break;
// SKIPPED CHUNKS
// if break; is called directly, the position in the lwoTree is not created
// any sub chunks and forms are added to the parent form instead
// MISC skipped
case 'ICON': // Thumbnail Icon Image
case 'VMPA': // Vertex Map Parameter
case 'BBOX': // bounding box
// case 'VMMD':
// case 'VTYP':
// normal maps can be specified, normally on models imported from other applications. Currently ignored
case 'NORM':
// ENVL FORM skipped
case 'PRE ':
case 'POST':
case 'KEY ':
case 'SPAN':
// CLIP FORM skipped
case 'TIME':
case 'CLRS':
case 'CLRA':
case 'FILT':
case 'DITH':
case 'CONT':
case 'BRIT':
case 'SATR':
case 'HUE ':
case 'GAMM':
case 'NEGA':
case 'IFLT':
case 'PFLT':
// Image Map Layer skipped
case 'PROJ':
case 'AXIS':
case 'AAST':
case 'PIXB':
case 'AUVO':
case 'STCK':
// Procedural Textures skipped
case 'PROC':
case 'VALU':
case 'FUNC':
// Gradient Textures skipped
case 'PNAM':
case 'INAM':
case 'GRST':
case 'GREN':
case 'GRPT':
case 'FKEY':
case 'IKEY':
// Texture Mapping Form skipped
case 'CSYS':
// Surface CHUNKs skipped
case 'OPAQ': // top level 'opacity' checkbox
case 'CMAP': // clip map
// Surface node CHUNKS skipped
// These mainly specify the node editor setup in LW
case 'NLOC':
case 'NZOM':
case 'NVER':
case 'NSRV':
case 'NVSK': // unknown
case 'NCRD':
case 'WRPW': // image wrap w ( for cylindrical and spherical projections)
case 'WRPH': // image wrap h
case 'NMOD':
case 'NSEL':
case 'NPRW':
case 'NPLA':
case 'NODS':
case 'VERS':
case 'ENUM':
case 'TAG ':
case 'OPAC':
// Car Material CHUNKS
case 'CGMD':
case 'CGTY':
case 'CGST':
case 'CGEN':
case 'CGTS':
case 'CGTE':
case 'OSMP':
case 'OMDE':
case 'OUTR':
case 'FLAG':
case 'TRNL':
case 'GLOW':
case 'GVAL': // glow intensity
case 'SHRP':
case 'RFOP':
case 'RSAN':
case 'TROP':
case 'RBLR':
case 'TBLR':
case 'CLRH':
case 'CLRF':
case 'ADTR':
case 'LINE':
case 'ALPH':
case 'VCOL':
case 'ENAB':
this.IFF.debugger.skipped = true;
this.IFF.reader.skip( length );
break;
case 'SURF':
this.IFF.parseSurfaceLwo2( length );
break;
case 'CLIP':
this.IFF.parseClipLwo2( length );
break;
// Texture node chunks (not in spec)
case 'IPIX': // usePixelBlending
case 'IMIP': // useMipMaps
case 'IMOD': // imageBlendingMode
case 'AMOD': // unknown
case 'IINV': // imageInvertAlpha
case 'INCR': // imageInvertColor
case 'IAXS': // imageAxis ( for non-UV maps)
case 'IFOT': // imageFallofType
case 'ITIM': // timing for animated textures
case 'IWRL':
case 'IUTI':
case 'IINX':
case 'IINY':
case 'IINZ':
case 'IREF': // possibly a VX for reused texture nodes
if ( length === 4 ) this.IFF.currentNode[ blockID ] = this.IFF.reader.getInt32();
else this.IFF.reader.skip( length );
break;
case 'OTAG':
this.IFF.parseObjectTag();
break;
case 'LAYR':
this.IFF.parseLayer( length );
break;
case 'PNTS':
this.IFF.parsePoints( length );
break;
case 'VMAP':
this.IFF.parseVertexMapping( length );
break;
case 'AUVU':
case 'AUVN':
this.IFF.reader.skip( length - 1 );
this.IFF.reader.getVariableLengthIndex(); // VX
break;
case 'POLS':
this.IFF.parsePolygonList( length );
break;
case 'TAGS':
this.IFF.parseTagStrings( length );
break;
case 'PTAG':
this.IFF.parsePolygonTagMapping( length );
break;
case 'VMAD':
this.IFF.parseVertexMapping( length, true );
break;
// Misc CHUNKS
case 'DESC': // Description Line
this.IFF.currentForm.description = this.IFF.reader.getString();
break;
case 'TEXT':
case 'CMNT':
case 'NCOM':
this.IFF.currentForm.comment = this.IFF.reader.getString();
break;
// Envelope Form
case 'NAME':
this.IFF.currentForm.channelName = this.IFF.reader.getString();
break;
// Image Map Layer
case 'WRAP':
this.IFF.currentForm.wrap = { w: this.IFF.reader.getUint16(), h: this.IFF.reader.getUint16() };
break;
case 'IMAG':
const index = this.IFF.reader.getVariableLengthIndex();
this.IFF.currentForm.imageIndex = index;
break;
// Texture Mapping Form
case 'OREF':
this.IFF.currentForm.referenceObject = this.IFF.reader.getString();
break;
case 'ROID':
this.IFF.currentForm.referenceObjectID = this.IFF.reader.getUint32();
break;
// Surface Blocks
case 'SSHN':
this.IFF.currentSurface.surfaceShaderName = this.IFF.reader.getString();
break;
case 'AOVN':
this.IFF.currentSurface.surfaceCustomAOVName = this.IFF.reader.getString();
break;
// Nodal Blocks
case 'NSTA':
this.IFF.currentForm.disabled = this.IFF.reader.getUint16();
break;
case 'NRNM':
this.IFF.currentForm.realName = this.IFF.reader.getString();
break;
case 'NNME':
this.IFF.currentForm.refName = this.IFF.reader.getString();
this.IFF.currentSurface.nodes[ this.IFF.currentForm.refName ] = this.IFF.currentForm;
break;
// Nodal Blocks : connections
case 'INME':
if ( ! this.IFF.currentForm.nodeName ) this.IFF.currentForm.nodeName = [];
this.IFF.currentForm.nodeName.push( this.IFF.reader.getString() );
break;
case 'IINN':
if ( ! this.IFF.currentForm.inputNodeName ) this.IFF.currentForm.inputNodeName = [];
this.IFF.currentForm.inputNodeName.push( this.IFF.reader.getString() );
break;
case 'IINM':
if ( ! this.IFF.currentForm.inputName ) this.IFF.currentForm.inputName = [];
this.IFF.currentForm.inputName.push( this.IFF.reader.getString() );
break;
case 'IONM':
if ( ! this.IFF.currentForm.inputOutputName ) this.IFF.currentForm.inputOutputName = [];
this.IFF.currentForm.inputOutputName.push( this.IFF.reader.getString() );
break;
case 'FNAM':
this.IFF.currentForm.fileName = this.IFF.reader.getString();
break;
case 'CHAN': // NOTE: ENVL Forms may also have CHAN chunk, however ENVL is currently ignored
if ( length === 4 ) this.IFF.currentForm.textureChannel = this.IFF.reader.getIDTag();
else this.IFF.reader.skip( length );
break;
// LWO2 Spec chunks: these are needed since the SURF FORMs are often in LWO2 format
case 'SMAN':
const maxSmoothingAngle = this.IFF.reader.getFloat32();
this.IFF.currentSurface.attributes.smooth = ( maxSmoothingAngle < 0 ) ? false : true;
break;
// LWO2: Basic Surface Parameters
case 'COLR':
this.IFF.currentSurface.attributes.Color = { value: this.IFF.reader.getFloat32Array( 3 ) };
this.IFF.reader.skip( 2 ); // VX: envelope
break;
case 'LUMI':
this.IFF.currentSurface.attributes.Luminosity = { value: this.IFF.reader.getFloat32() };
this.IFF.reader.skip( 2 );
break;
case 'SPEC':
this.IFF.currentSurface.attributes.Specular = { value: this.IFF.reader.getFloat32() };
this.IFF.reader.skip( 2 );
break;
case 'DIFF':
this.IFF.currentSurface.attributes.Diffuse = { value: this.IFF.reader.getFloat32() };
this.IFF.reader.skip( 2 );
break;
case 'REFL':
this.IFF.currentSurface.attributes.Reflection = { value: this.IFF.reader.getFloat32() };
this.IFF.reader.skip( 2 );
break;
case 'GLOS':
this.IFF.currentSurface.attributes.Glossiness = { value: this.IFF.reader.getFloat32() };
this.IFF.reader.skip( 2 );
break;
case 'TRAN':
this.IFF.currentSurface.attributes.opacity = this.IFF.reader.getFloat32();
this.IFF.reader.skip( 2 );
break;
case 'BUMP':
this.IFF.currentSurface.attributes.bumpStrength = this.IFF.reader.getFloat32();
this.IFF.reader.skip( 2 );
break;
case 'SIDE':
this.IFF.currentSurface.attributes.side = this.IFF.reader.getUint16();
break;
case 'RIMG':
this.IFF.currentSurface.attributes.reflectionMap = this.IFF.reader.getVariableLengthIndex();
break;
case 'RIND':
this.IFF.currentSurface.attributes.refractiveIndex = this.IFF.reader.getFloat32();
this.IFF.reader.skip( 2 );
break;
case 'TIMG':
this.IFF.currentSurface.attributes.refractionMap = this.IFF.reader.getVariableLengthIndex();
break;
case 'IMAP':
this.IFF.reader.skip( 2 );
break;
case 'TMAP':
this.IFF.debugger.skipped = true;
this.IFF.reader.skip( length ); // needs implementing
break;
case 'IUVI': // uv channel name
this.IFF.currentNode.UVChannel = this.IFF.reader.getString( length );
break;
case 'IUTL': // widthWrappingMode: 0 = Reset, 1 = Repeat, 2 = Mirror, 3 = Edge
this.IFF.currentNode.widthWrappingMode = this.IFF.reader.getUint32();
break;
case 'IVTL': // heightWrappingMode
this.IFF.currentNode.heightWrappingMode = this.IFF.reader.getUint32();
break;
// LWO2 USE
case 'BLOK':
// skip
break;
default:
this.IFF.parseUnknownCHUNK( blockID, length );
}
if ( blockID != 'FORM' ) {
this.IFF.debugger.node = 1;
this.IFF.debugger.nodeID = blockID;
this.IFF.debugger.log();
}
if ( this.IFF.reader.offset >= this.IFF.currentFormEnd ) {
this.IFF.currentForm = this.IFF.parentForm;
}
}
}
export { LWO2Parser };
|