@@ -202,6 +202,7 @@ interface ShardInfo {
202202}
203203
204204interface GrapheneMultiscaleManifestChunk extends MultiscaleManifestChunk {
205+ fragments : Array < FragmentId [ ] > | null ;
205206 fragmentIds : FragmentId [ ] | null ;
206207 shardInfo ?: ShardInfo ;
207208}
@@ -217,7 +218,7 @@ function decodeMultiscaleManifestChunk(chunk: GrapheneMultiscaleManifestChunk, r
217218 clipLowerBound : vec3 . clone ( response . clipLowerBound ) ,
218219 clipUpperBound : vec3 . clone ( response . clipUpperBound ) ,
219220 } ;
220- chunk . fragmentIds = response . fragments ;
221+ chunk . fragments = response . fragments ;
221222 chunk . manifest . clipLowerBound . fill ( 0 ) ;
222223 chunk . manifest . clipUpperBound . fill ( 10000000 ) ;
223224 chunk . manifest . octree [ 5 * ( response . fragments . length - 1 ) + 4 ] &= 0x7fffffff ;
@@ -260,6 +261,19 @@ async function decodeMultiscaleFragmentChunk(
260261 ) ;
261262}
262263
264+ function mergeArrayBuffers ( buffers : ArrayBuffer [ ] ) : ArrayBuffer {
265+ const totalLength = buffers . reduce ( ( sum , buf ) => sum + buf . byteLength , 0 ) ;
266+ const mergedBuffer = new ArrayBuffer ( totalLength ) ;
267+ const mergedView = new Uint8Array ( mergedBuffer ) ;
268+
269+ let offset = 0 ;
270+ for ( const buffer of buffers ) {
271+ mergedView . set ( new Uint8Array ( buffer ) , offset ) ;
272+ offset += buffer . byteLength ;
273+ }
274+ return mergedBuffer ;
275+ }
276+
263277@registerSharedObject ( )
264278export class GrapheneMultiscaleMeshSource extends WithParameters (
265279 WithSharedKvStoreContextCounterpart ( MultiscaleMeshSource ) ,
@@ -295,7 +309,7 @@ export class GrapheneMultiscaleMeshSource extends WithParameters(
295309 return decodeManifestChunk ( chunk , { fragments : [ ] } ) ;
296310 }
297311 const { fetchOkImpl, baseUrl } = this . manifestHttpSource ;
298- const manifestPath = `/manifest/multiscale/${ chunk . objectId } ?verify=1&prepend_seg_ids=1 ` ;
312+ const manifestPath = `/manifest/multiscale/${ chunk . objectId } ?verify=1` ;
299313 const response = await (
300314 await fetchOkImpl ( baseUrl + manifestPath , { signal } )
301315 ) . json ( ) ;
@@ -322,21 +336,23 @@ export class GrapheneMultiscaleMeshSource extends WithParameters(
322336 const { parameters } = this ;
323337 const manifestChunk = chunk . manifestChunk ! as GrapheneMultiscaleManifestChunk ;
324338 const chunkIndex = chunk . chunkIndex ;
325- const { fragmentIds } = manifestChunk ;
339+ const { fragments } = manifestChunk ;
326340
327341 try {
328- let fragmentId = null ;
329- if ( fragmentIds !== null ) {
330- fragmentId = fragmentIds [ chunkIndex ] ;
331- fragmentId = fragmentId . substring ( fragmentId . indexOf ( ":" ) + 1 ) ;
342+ if ( fragments !== null ) {
343+ const fragmentsIds = fragments [ chunkIndex ] ;
344+ let result : ArrayBuffer [ ] = new Array ( ) ;
345+ for ( const fragmentId of fragmentsIds ) {
346+ let { response } = await downloadFragment (
347+ this . fragmentKvStore ,
348+ fragmentId ,
349+ parameters ,
350+ signal ,
351+ ) ;
352+ result . push ( await response . arrayBuffer ( ) )
353+ }
354+ await decodeMultiscaleFragmentChunk ( chunk , mergeArrayBuffers ( result ) ) ;
332355 }
333- const { response } = await downloadFragment (
334- this . fragmentKvStore ,
335- fragmentId ,
336- parameters ,
337- signal ,
338- ) ;
339- await decodeMultiscaleFragmentChunk ( chunk , await response . arrayBuffer ( ) ) ;
340356 } catch ( e ) {
341357 if ( isNotFoundError ( e ) ) {
342358 chunk . source ! . removeChunk ( chunk ) ;
0 commit comments