Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/assets/img/volume/t1_icbm_normal_1mm_pn0_rf0.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def load_byte_array_from_file(file_path):
with open("t1_icbm_normal_1mm_pn0_rf0_180x216x180_uint8_1x1.bin", "rb") as f:
bytes_data = f.read()

gzip_filename = "t1_icbm_normal_1mm_pn0_rf0_180x216x180_uint8_1x1.bin.gz"
gzip_filename = "t1_icbm_normal_1mm_pn0_rf0_180x216x180_uint8_1x1.bin-gz"

with gzip.open(gzip_filename, "wb", compresslevel=9) as f:
f.write(bytes_data)
Expand Down
21 changes: 15 additions & 6 deletions sample/volumeRenderingTexture3D/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ const brainImages = {
blockLength: 1,
feature: undefined,
dataPath:
'../../assets/img/volume/t1_icbm_normal_1mm_pn0_rf0_180x216x180_uint8_1x1.bin.gz',
'../../assets/img/volume/t1_icbm_normal_1mm_pn0_rf0_180x216x180_uint8_1x1.bin-gz',
},
'bc4-r-unorm': {
bytesPerBlock: 8,
blockLength: 4,
feature: 'texture-compression-bc-sliced-3d',
dataPath:
'../../assets/img/volume/t1_icbm_normal_1mm_pn0_rf0_180x216x180_bc4_4x4.bin.gz',
'../../assets/img/volume/t1_icbm_normal_1mm_pn0_rf0_180x216x180_bc4_4x4.bin-gz',
// Generated with texconv from https://github.com/microsoft/DirectXTex/releases
},
'astc-12x12-unorm': {
bytesPerBlock: 16,
blockLength: 12,
feature: 'texture-compression-astc-sliced-3d',
dataPath:
'../../assets/img/volume/t1_icbm_normal_1mm_pn0_rf0_180x216x180_astc_12x12.bin.gz',
'../../assets/img/volume/t1_icbm_normal_1mm_pn0_rf0_180x216x180_astc_12x12.bin-gz',
// Generated with astcenc from https://github.com/ARM-software/astc-encoder/releases
},
};
Expand Down Expand Up @@ -158,11 +158,20 @@ async function createVolumeTexture(format: GPUTextureFormat) {
});

const response = await fetch(dataPath);
const buffer = await response.arrayBuffer();

const compressedBlob = await response.blob();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why blob?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because theoretically it uses less memory? The browser can stream the blob through the decompressor. It can't stream the arrayBuffer as it's required to have loaded the entire thing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! Thanks!


// Decompress the data using DecompressionStream for gzip format
const decompressionStream = new DecompressionStream('gzip');
const decompressedStream = compressedBlob
.stream()
.pipeThrough(decompressionStream);
const decompressedArrayBuffer = await new Response(
decompressedStream
).arrayBuffer();
const byteArray = new Uint8Array(decompressedArrayBuffer);
device.queue.writeTexture(
{ texture: volumeTexture },
buffer,
byteArray,
{ bytesPerRow: bytesPerRow, rowsPerImage: blocksHigh },
[width, height, depth]
);
Expand Down