Load gltf model from contents, not URL

Viewed 243

I am currently downloading a gltf from Google drive using the Google Drive API. I can print in the console the gltf file as text but I can't seem to be able to parse it and actually visualize it in three.js. I have used GLTFLoader.parse and GLTFLoader.load but both give errors about the json. Is there a workflow for reading files from their content without loading them from a URL?

the response I am getting back from google-drive looks like that:

response body image

enter image description here

1 Answers

Is there a workflow for reading files from their content without loading them from a URL?

Yes. The idea is to directly call the parse() method with the respective content. The three.js editor is using this approach during file import. The normal approach for this is:

const loader = new GLTFLoader();

loader.parse( contents, '', ( gltf ) => {

    const model = gltf.scene;
    scene.add( model );

} );

contents can be of type string or ArrayBuffer.

Related