Cannot import a GLTF when exported using GLTFExporter.parse

Hi,

I’m obviously missing something.

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?

Cheers

Paul

What does the code look like you’re using for GLTFExporter.Parse? What sort of file size is the saved file?

1 Like
  • 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:

loader.load(data, ‘‘, (gltf) => console.log(gltf), (e) => console.error(e));

As you mention, ObjectLoader’s input format isn’t related to the other two so I don’t think that will help you here.

1 Like

Hi,

To create the data, I use

  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.

dd6f5a5c-50f4-4d23-baac-f8b6b19df4be.gltf (303.6 KB)

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.

I will keep playing.

Arggghh!!! Found the issue.

exporter.parse(result, function () {}, function() {}, { binary: true}

I was missing the callback for onError, so parse never got the binary setting.

Thanks for your help.

2 Likes