I’ve been attempting to parse the response from the stable-fast-3d response.
I have not been able to successfully load the glb file or the gltf assets.
I am unsure of the methods I should be using to convert the string response into a readable glb or gltf file.
Per the StabilityAI docs: ‘The output is a binary blob that includes a glTF asset, including JSON, buffers, and images. See the GLB File Format Specification for more details.’
I am using threejs library to read the response.
There are four methods that I used that have all led to errors; they are detailed below.
- Blob using type ‘model/gltf-binary’ then parsing the Array buffer from the blob
Using the response from the API, create blob instance with ‘model/gltf-binary’
var blob = new Blob([response], {type: ‘model/gltf-binary’});
Get array buffer from blob
const buffer = await blob.arrayBuffer();
Using GLTFLoader from three.js library, parse the buffer.
const loader = new GLTFLoader();
loader.parse(buffer, ‘’, (gltf) => {console.log(gltf);}, (error) => {console.log(‘error’, error); });
This parse method leads to the error below:
RangeError: Offset is outside the bounds of the DataView
at DataView.prototype.getUint32
-
Blob using type 'application/octet-stream then parsing the Array buffer from the blob
Using the response from the API, create blob instance with ‘application/octet-stream’
var blob = new Blob([response], {type: ‘application/octet-stream’});
Same as Step 2 in 1.2.
Same as Step 3 in 1.3.
Parse method leads to the error below:
Error: THREE.GLTFLoader: JSON content not found.
at new GLTFBinaryExtension -
Loading file from blob with type ‘model/gltf-binary’
Using the response from the API, create blob instance with ‘model/gltf-binary’
var blob = new Blob([response], {type: ‘model/gltf-binary’});
Download the file.
Pass this file to the GLTFLoader .load method.
loader.load( // resource URL ‘/dist/response_3d_gltf-binary.glb’, // called when the resource is loaded function ( gltf ) { console.log(gltf); }, // called while loading is progressing function ( xhr ) { console.log( ( xhr.loaded / xhr.total * 100 ) + ‘% loaded’ ); }, // called when loading has errors function ( error ) { console.log(error); console.log( ‘An error happened’ );
});
Error below occurs when attempting to load file
Error: THREE.GLTFLoader: JSON content not found.
at new GLTFBinaryExtension (GLTFLoader.js:1320:13)at GLTFLoader.parse
-
Loading file from blob with type ‘application/octet-stream’
Using the response from the API, create blob instance with ‘application/octet-stream’
var blob = new Blob([response], {type: ‘application/octet-stream’});
Download the file.
Pass this file to the GLTFLoader .load method.
Error below occurs when attempting to load file
RangeError: Offset is outside the bounds of the DataView
at DataView.prototype.getUint32 ()at new GLTFBinaryExtension (GLTFLoader.js:1302:37)
at GLTFLoader.parse
I also passed these files from the API response to a GLTF validator. Pics of the validation errors are attached.