1 line
41 KiB
Plaintext
1 line
41 KiB
Plaintext
|
|
{"version":3,"file":"IFFParser.cjs","sources":["../../../src/loaders/lwo/IFFParser.js"],"sourcesContent":["/**\n * === IFFParser ===\n * - Parses data from the IFF buffer.\n * - LWO3 files are in IFF format and can contain the following data types, referred to by shorthand codes\n *\n * ATOMIC DATA TYPES\n * ID Tag - 4x 7 bit uppercase ASCII chars: ID4\n * signed integer, 1, 2, or 4 byte length: I1, I2, I4\n * unsigned integer, 1, 2, or 4 byte length: U1, U2, U4\n * float, 4 byte length: F4\n * string, series of ASCII chars followed by null byte (If the length of the string including the null terminating byte is odd, an extra null is added so that the data that follows will begin on an even byte boundary): S0\n *\n * COMPOUND DATA TYPES\n * Variable-length Index (index into an array or collection): U2 or U4 : VX\n * Color (RGB): F4 + F4 + F4: COL12\n * Coordinate (x, y, z): F4 + F4 + F4: VEC12\n * Percentage F4 data type from 0->1 with 1 = 100%: FP4\n * Angle in radian F4: ANG4\n * Filename (string) S0: FNAM0\n * XValue F4 + index (VX) + optional envelope( ENVL ): XVAL\n * XValue vector VEC12 + index (VX) + optional envelope( ENVL ): XVAL3\n *\n * The IFF file is arranged in chunks:\n * CHUNK = ID4 + length (U4) + length X bytes of data + optional 0 pad byte\n * optional 0 pad byte is there to ensure chunk ends on even boundary, not counted in size\n *\n * COMPOUND DATA TYPES\n * - Chunks are combined in Forms (collections of chunks)\n * - FORM = string 'FORM' (ID4) + length (U4) + type (ID4) + optional ( CHUNK | FORM )\n * - CHUNKS and FORMS are collectively referred to as blocks\n * - The entire file is contained in one top level FORM\n *\n **/\n\nimport { LWO2Parser } from './LWO2Parser'\nimport { LWO3Parser } from './LWO3Parser'\n\nclass IFFParser {\n constructor() {\n this.debugger = new Debugger()\n // this.debugger.enable(); // un-comment to log IFF hierarchy.\n }\n\n parse(buffer) {\n this.reader = new DataViewReader(buffer)\n\n this.tree = {\n materials: {},\n layers: [],\n tags: [],\n textures: [],\n }\n\n // start out at the top level to add any data before first layer is encountered\n this.currentLayer = this.tree\n this.currentForm = this.tree\n\n this.parseTopForm()\n\n if (this.tree.format === undefined) return\n\n if (this.tree.format === 'LWO2') {\n this.parser = new LWO2Parser(this)\n while (!this.reader.endOfFile()) this.parser.parseBlock()\n } else if (this.tree.format === 'LWO3') {\n this.parser = new LWO3Parser(this)\n while (!this.reader.endOfFile()) this.parser.parseBlock()\n }\n\n this.debugger.offset = this.reader.offset\n this.debugger.closeForms()\n\n return this.tree\n }\n\n parseTopForm() {\n this.debugger.offset = this.reader.offset\n\n var topForm = this.reader.getIDTag()\n\n if (topForm !== 'FORM') {\n console.warn('LWOLoader: Top-level FORM missing.')\n return\n }\n\n var length = this.reader.getUint32()\n\n this.debugger.dataOffset = this.reader.offset\n this.debugger.length = length\n\n var type = this.reader.getIDTag()\n\n if (type === 'LWO2') {\n this.tree.format = type\n } else if (type === 'LWO3') {\n this.tree.format = type\n }\n\n this.debugger.node = 0\n this.debugger.nodeID = type\n this.debugger.log()\n\n return\n }\n\n ///\n // FORM PARSING METHODS\n ///\n\n // Forms are organisational and can contain any number of sub chunks and sub forms\n // FORM ::= 'FORM'[ID4], length[U4], type[ID4], ( chunk[CHUNK] | form[FORM] ) * }\n parseForm(length) {\n var type = this.reader.getIDTag()\n\n switch (type) {\n // SKIPPED FORMS\n // if skipForm( length ) is called, the entire form and any sub forms and chunks are skipped\n\n case 'ISEQ': // Image sequence\n case 'ANIM': // plug in animation\n case 'STCC': // Color-cycling Still\n case 'VPVL':\n case 'VPRM':\n case 'NROT':\n case 'WRPW': // image wrap w ( for cylindrical and spherical projections)\n case
|