I’m trying to parse glb files from zip as arraybuffer and got undefined. When trying to decode arraybuffer then got not valid json. Take a look at the samples and screenshot
LittlestTokyo.draco.glb.zip (3.5 MB)
LittlestTokyo.glb.zip (5.4 MB)
DragonAttenuation.glb.zip (4.1 MB)
The loader example:
export const parseGLBFromZipArchive = async (zip: JSZip): Promise<THREE.Object3D | THREE.Group> => {
const glbFile = getFileNamesByExt(zip, /\.glb$/i)[0];
if (glbFile) {
const glbLoader = new GLTFLoader();
const response = await zip.file(glbFile).async('arraybuffer');
console.log('response', response);
// const content = await response.arrayBuffer();
try {
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath('3rd-Party/three/draco/');
const ktx2Loader = new KTX2Loader();
ktx2Loader.setTranscoderPath('3rd-Party/three/basis/');
glbLoader.setDRACOLoader(dracoLoader);
glbLoader.setKTX2Loader(ktx2Loader);
glbLoader.setMeshoptDecoder(MeshoptDecoder);
// const object3d = glbLoader.parse(content);
// const object3d = glbLoader.parse(new TextDecoder().decode(response));
const object3d = glbLoader.parse(response);
console.log('obj3d ', object3d);
return object3d; // undefined or not valid json with new TextDecoder().decode
} catch (e) {
console.error('can`t parse .GLB file', e);
}
} else {
console.error('.GLB file not found in the zip archive');
}
};
Could someone point out what is wrong?