Search code examples
javascriptthree.jsjszip

Reading GLB files in JSZip


How would I read a glb file using JSZip

The only thing Ican think of is using this method.

 zip.file("hello.txt").async("string");

Maybe converting the string into Base64 But I don't know.


Solution

  • Here's a full example for you:

    const JSZip = require("jszip");
    const zip = new JSZip();
    
    zip.loadAsync(glbFilePath)
      .then(() => {
        return zip.file("yourmodel.glb").async("blob");
      })
      .then((fileData) => {
        var loader = new THREE.GLTFLoader();
    
        // load the GLB file
        loader.load(fileData, function (gltf) {
            var model = gltf.scene;
            
            // add the model to your scene
        });
      });