import reverse from '../../common/stringreverse' ; import BinaryStream from '../../common/binarystream' ; import Md34 from './md34' ; import ModelHeader from './modelheader' ; import Sequence from './sequence' ; import Stc from './stc' ; import Stg from './stg' ; import Sts from './sts' ; import Bone from './bone' ; import Division from './division' ; import Region from './region' ; import Batch from './batch' ; import MaterialReference from './materialreference' ; import StandardMaterial from './standardmaterial' ; import Layer from './layer' ; import Event from './event' ; import BoundingSphere from './boundingsphere' ; import AttachmentPoint from './attachmentpoint' ; import Camera from './camera' ; import Sd from './sd' ; import UnsupportedEntry from './unsupportedentry' ; const tagMapping = { MD34 : [ Md34 , { 11 : 24 } ] , MODL : [ ModelHeader , { 23 : 784 , 25 : 808 , 26 : 820 , 28 : 844 , 29 : 856 } ] , SEQS : [ Sequence , { 1 : 96 , 2 : 92 } ] , STC_ : [ Stc , { 4 : 204 } ] , STG_ : [ Stg , { 0 : 24 } ] , STS_ : [ Sts , { 0 : 28 } ] , BONE : [ Bone , { 1 : 160 } ] , DIV_ : [ Division , { 2 : 52 } ] , REGN : [ Region , { 3 : 36 , 4 : 40 , 5 : 48 } ] , BAT_ : [ Batch , { 1 : 14 } ] , MATM : [ MaterialReference , { 0 : 8 } ] , MAT_ : [ StandardMaterial , { 15 : 268 , 16 : 280 , 17 : 280 , 18 : 280 , 19 : 340 } ] , LAYR : [ Layer , { 22 : 356 , 24 : 436 , 25 : 468 , 26 : 464 } ] , EVNT : [ Event , { 0 : 96 , 1 : 104 , 2 : 108 } ] , BNDS : [ BoundingSphere , { 0 : 28 } ] , ATT_ : [ AttachmentPoint , { 1 : 20 } ] , CAM_ : [ Camera , { 3 : 180 , 5 : 264 } ] , SDEV : [ Sd , { 0 : 32 } ] , SDU6 : [ Sd , { 0 : 32 } ] , SDFG : [ Sd , { 0 : 32 } ] , SDS6 : [ Sd , { 0 : 32 } ] , SDR3 : [ Sd , { 0 : 32 } ] , SD2V : [ Sd , { 0 : 32 } ] , SD3V : [ Sd , { 0 : 32 } ] , SD4Q : [ Sd , { 0 : 32 } ] , SDCC : [ Sd , { 0 : 32 } ] , SDMB : [ Sd , { 0 : 32 } ] , FLAG : [ Sd , { 0 : 32 } ] , MSEC : [ UnsupportedEntry , { 1 : 72 } ] , LITE : [ UnsupportedEntry , { 7 : 212 } ] , ATVL : [ UnsupportedEntry , { 0 : 116 } ] , PATU : [ UnsupportedEntry , { 4 : 152 } ] , TRGD : [ UnsupportedEntry , { 0 : 24 } ] , DIS_ : [ UnsupportedEntry , { 4 : 68 } ] , CMS_ : [ UnsupportedEntry , { 0 : 24 } ] , CMP_ : [ UnsupportedEntry , { 2 : 28 } ] , TER_ : [ UnsupportedEntry , { 0 : 24 , 1 : 28 } ] , VOL_ : [ UnsupportedEntry , { 0 : 84 } ] , VON_ : [ UnsupportedEntry , { 0 : 268 } ] , CREP : [ UnsupportedEntry , { 0 : 24 , 1 : 28 } ] , STBM : [ UnsupportedEntry , { 0 : 48 } ] , LFSB : [ UnsupportedEntry , { 2 : 56 } ] , LFLR : [ UnsupportedEntry , { 2 : 80 , 3 : 152 } ] , PAR_ : [ UnsupportedEntry , { 12 : 1316 , 17 : 1460 , 18 : 1464 , 19 : 1464 , 21 : 1464 , 22 : 1484 , 23 : 1492 , 24 : 1496 } ] , PARC : [ UnsupportedEntry , { 0 : 40 } ] , PROJ : [ UnsupportedEntry , { 4 : 388 , 5 : 382 } ] , PHYJ : [ UnsupportedEntry , { 0 : 180 } ] , PHCC : [ UnsupportedEntry , { 0 : 76 } ] , PHAC : [ UnsupportedEntry , { 0 : 32 } ] , PHCL : [ UnsupportedEntry , { 2 : 128 } ] , FOR_ : [ UnsupportedEntry , { 1 : 104 , 2 : 104 } ] , DMSE : [ UnsupportedEntry , { 0 : 4 } ] , PHSH : [ UnsupportedEntry , { 1 : 132 , 3 : 300 } ] , PHRB : [ UnsupportedEntry , { 2 : 104 , 4 : 80 } ] , SSGS : [ UnsupportedEntry , { 1 : 108 } ] , BBSC : [ UnsupportedEntry , { 0 : 48 } ] , SRIB : [ UnsupportedEntry , { 0 : 272 } ] , RIB_ : [ UnsupportedEntry , { 6 : 748 , 8 : 756 , 9 : 760 } ] , IKJT : [ UnsupportedEntry , { 0 : 32 } ] , SHBX : [ UnsupportedEntry , { 0 : 64 } ] , WRP_ : [ UnsupportedEntry , { 1 : 132 } ] , } ; export type EntryType = Md34 [ ] | ModelHeader [ ] | Sequence [ ] | Stc [ ] | Stg [ ] | Sts [ ] | Bone [ ] | Division [ ] | Region [ ] | Batch [ ] | MaterialReference [ ] | StandardMaterial [ ] | Layer [ ] | Event [ ] | BoundingSphere [ ] | AttachmentPoint [ ] | Camera [ ] | Sd [ ] | UnsupportedEntry [ ] | string | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Float32Array | Float32Array [ ] ; export type SingleEntryType = Md34 | ModelHeader | Sequence | Stc | Stg | Sts | Bone | Division | Region | Batch | MaterialReference | StandardMaterial | Layer | Event | BoundingSphere | AttachmentPoint | Camera | Sd | UnsupportedEntry | string | number | Float32Array ; /**
 * An index entry.
 */ export default class IndexEntry { index : IndexEntry [ ] ; tag : string ; offset : number ; version : number ; entries : EntryType ; constructor ( stream , index ) { const tag = reverse ( stream . readBinary ( 4 ) ) ; const offset = stream . readUint32 ( ) ; const entriesCount = stream . readUint32 ( ) ; const version = stream . readUint32 ( ) ; this . index = index ; this . tag = tag ; this . offset = offset ; this . version = version ; const mapping = tagMapping [ tag ] ; const readerOffset = stream . index ; stream . seek ( offset ) ; if ( mapping ) { const constructor = mapping [ 0 ] ; const entrySize = mapping [ 1 ] [ version ] ; if ( ! entrySize ) { throw new Error ( ': Unsupported object version - tag ' + tag + ' and version ' + version ) ; } this . entries = [ ] ; for ( let i = 0 , l = entriesCount ; i < l ; i ++ ) { if ( constructor === UnsupportedEntry ) { this . entries [ i ] = new UnsupportedEntry ( stream . substream ( entrySize ) , version , index ) ; } else { const entry = new constructor ( ) ; entry . load ( stream . substream ( entrySize ) , version , index ) ; this . entries [ i ] = entry ; } } } else if ( tag === 'CHAR' || tag === 'SCHR' ) { this . entries = stream . read ( entriesCount ) ; } else if ( tag === 'U8__' ) { this . entries = stream . readUint8Array ( entriesCount ) ; } else if ( tag === 'U16_' ) { this . entries = stream . readUint16Array ( entriesCount ) ; } else if ( tag === 'U32_' ) { this . entries = stream . readUint32Array ( entriesCount ) ; } else if ( tag === 'I16_' ) { this . entries = stream . readInt16Array ( entriesCount ) ; } else if ( tag === 'I32_' ) { this . entries = stream . readInt32Array ( entriesCount ) ; } else if ( tag === 'REAL' ) { this . entries = stream . readFloat32Array ( entriesCount ) ; } else if ( tag === 'VEC2' ) { this . entries = [ ] ; for ( let i = 0 ; i < entriesCount ; i ++ ) { this . entries [ i ] = stream . readFloat32Array ( 2 ) ; } } else if ( tag === 'VEC3' || tag === 'SVC3' ) { this . entries = [ ] ; for ( let i = 0 ; i < entriesCount ; i ++ ) { this . entries [ i ] = stream . readFloat32Array ( 3 ) ; } } else if ( tag === 'VEC4' || tag === 'QUAT' ) { this . entries = [ ] ; for ( let i = 0 ; i < entriesCount ; i ++ ) { this . entries [ i ] = stream . readFloat32Array ( 4 ) ; } } else if ( tag === 'IREF' ) { this . entries = [ ] ; for ( let i = 0 ; i < entriesCount ; i ++ ) { this . entries [ i ] = stream . readFloat32Array ( 16 ) ; } } else { this . entries = [ ] ; throw new Error ( ': Unsupported object tag - tag ' + tag + ' and version ' + version ) ; } stream . seek ( readerOffset ) ; } }