I use GLTFExporter.parse with a GLB mesh I loaded with GLTFLoader. I save the results of parse and then try and reload with both GLTFLoader which doesn’t work.
I also read I should use the parse function of ObjectLoader, but this fails too. I look at the code in ObjectLoader and it expects json.geometries but all I see returned from GLTFLoader.parse is buffers so I am assuming the two don’t work together.
How do I load the output from GLTFExporter.parse or do you recommend using another method?
GLTFLoader: Decodes .gltf/.glb files to create THREE.Object3D subtree
GLTFExporter: Encodes THREE.Object3D subtree to .gltf/.glb files
ObjectLoader: Decodes internal three.js JSON format to various three.js objects
Output of GLTFExporter.parse should be compatible with GLTFLoader.parse. I might suggest using the {binary: true} option to ensure that’s a single buffer. Then on the loading side:
const exporter = new GLTFExporter();
exporter.parse(result, function (parsedData) {
let jsonString = JSON.stringify(parsedData);
// At this point I upload to the server to create a GLB file. I get the same structire whatever I set binary to
.....
.....
}, { binary: true });
I can open the GLB on the server on a 3D Model Viewer.
Later, I use
const gltfModelLoader = new GLTFLoader()
// Here is where the error occurs.
gltfModelLoader.load(filename, function (gltf) {
I get
An error happened Error: THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported in the console.
Binary data should not be JSON.stringify’d, you’ll need to either upload it as binary data to your server, or encode it as a base64 string, or stick to the non-binary output. Any of these are fine but I’d suggest double-checking that the data is identical after the client-server-client round trip. Or check that things work without the server round trip first.
Hmmm. Now it’s started working after playing around.
I did try uploading using this (i.e. not using JSON.stringify) but still got the same data at the other end. But I still don’t see what I think is binary.
new Blob([jsonString], { type: ‘application/octet-stream’ });
Certainly, the uploaded file looks very different to a GLB generating using 3D MAX or Blender.