import { PackFileReader } from '../common/packfile-reader' ; import { IFragment } from './schema' ; generator param { Buffer } buffer returns { Iterable < IFragment > } export function * parseFragments ( buffer ) { const pfr = new PackFileReader ( buffer ) ; for ( let i = 0 , len = pfr . numEntries ( ) ; i < len ; i ++ ) { const entryType = pfr . seekEntry ( i ) ; console . assert ( entryType ) ; console . assert ( entryType . version > 4 ) ; const flags = pfr . getUint8 ( ) ; const visible = ( flags & 0x01 ) !== 0 ; const materialID = pfr . getVarint ( ) ; const geometryID = pfr . getVarint ( ) ; const transform = pfr . getTransform ( ) ; let bbox = [ 0 , 0 , 0 , 0 , 0 , 0 ] ; let bboxOffset = [ 0 , 0 , 0 ] ; if ( entryType . version > 3 ) { if ( transform && 't' in transform ) { bboxOffset [ 0 ] = transform . t . x ; bboxOffset [ 1 ] = transform . t . y ; bboxOffset [ 2 ] = transform . t . z ; } } for ( let j = 0 ; j < 6 ; j ++ ) { bbox [ j ] = pfr . getFloat32 ( ) + bboxOffset [ j % 3 ] ; } const dbID = pfr . getVarint ( ) ; yield { visible , materialID , geometryID , dbID , transform , bbox } ; } }