Skip to content

Commit 719ac60

Browse files
authored
Fix volume rendering sample (#506)
The files were changed from `.bin-gz` to `.gz` and then left to the browser to decompress. But that only happened to work because the local dev server served `.gz` files with `content-encoding: gzip` headers. Github didn't do this. Revert to using `.bin-gz` and manually decompressing with `DecompressionStream`
1 parent c803763 commit 719ac60

5 files changed

+16
-7
lines changed

public/assets/img/volume/t1_icbm_normal_1mm_pn0_rf0.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def load_byte_array_from_file(file_path):
5656
with open("t1_icbm_normal_1mm_pn0_rf0_180x216x180_uint8_1x1.bin", "rb") as f:
5757
bytes_data = f.read()
5858

59-
gzip_filename = "t1_icbm_normal_1mm_pn0_rf0_180x216x180_uint8_1x1.bin.gz"
59+
gzip_filename = "t1_icbm_normal_1mm_pn0_rf0_180x216x180_uint8_1x1.bin-gz"
6060

6161
with gzip.open(gzip_filename, "wb", compresslevel=9) as f:
6262
f.write(bytes_data)

sample/volumeRenderingTexture3D/main.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ const brainImages = {
1414
blockLength: 1,
1515
feature: undefined,
1616
dataPath:
17-
'../../assets/img/volume/t1_icbm_normal_1mm_pn0_rf0_180x216x180_uint8_1x1.bin.gz',
17+
'../../assets/img/volume/t1_icbm_normal_1mm_pn0_rf0_180x216x180_uint8_1x1.bin-gz',
1818
},
1919
'bc4-r-unorm': {
2020
bytesPerBlock: 8,
2121
blockLength: 4,
2222
feature: 'texture-compression-bc-sliced-3d',
2323
dataPath:
24-
'../../assets/img/volume/t1_icbm_normal_1mm_pn0_rf0_180x216x180_bc4_4x4.bin.gz',
24+
'../../assets/img/volume/t1_icbm_normal_1mm_pn0_rf0_180x216x180_bc4_4x4.bin-gz',
2525
// Generated with texconv from https://github.com/microsoft/DirectXTex/releases
2626
},
2727
'astc-12x12-unorm': {
2828
bytesPerBlock: 16,
2929
blockLength: 12,
3030
feature: 'texture-compression-astc-sliced-3d',
3131
dataPath:
32-
'../../assets/img/volume/t1_icbm_normal_1mm_pn0_rf0_180x216x180_astc_12x12.bin.gz',
32+
'../../assets/img/volume/t1_icbm_normal_1mm_pn0_rf0_180x216x180_astc_12x12.bin-gz',
3333
// Generated with astcenc from https://github.com/ARM-software/astc-encoder/releases
3434
},
3535
};
@@ -158,11 +158,20 @@ async function createVolumeTexture(format: GPUTextureFormat) {
158158
});
159159

160160
const response = await fetch(dataPath);
161-
const buffer = await response.arrayBuffer();
162-
161+
const compressedBlob = await response.blob();
162+
163+
// Decompress the data using DecompressionStream for gzip format
164+
const decompressionStream = new DecompressionStream('gzip');
165+
const decompressedStream = compressedBlob
166+
.stream()
167+
.pipeThrough(decompressionStream);
168+
const decompressedArrayBuffer = await new Response(
169+
decompressedStream
170+
).arrayBuffer();
171+
const byteArray = new Uint8Array(decompressedArrayBuffer);
163172
device.queue.writeTexture(
164173
{ texture: volumeTexture },
165-
buffer,
174+
byteArray,
166175
{ bytesPerRow: bytesPerRow, rowsPerImage: blocksHigh },
167176
[width, height, depth]
168177
);

0 commit comments

Comments
 (0)