ObjectLoader does not load the json properly or .toJSON does not export the needed geometry data

Hello guys,

Ive been researching on this topic for 2 weeks now… but I couldn’t figure it out.
What ive been doing is to serialize a given mesh as JSON, with .toJSON method.
I am also using worker-threads, which takes stringified json string and turns it in to a list of meshes.

After the whole parsing stuff has been finished, I try to intersect a random generated ray with those meshes. But the “intersectObjects” function does return an empty array, which means no intersection has been done.

Without using worker-threads, it works and I am able to get intersections.
For debugging purposes only, I converted the meshes with .toJSON to a json formatted string and then loaded it straight away with ObjectLoader… surprisingly, that time, the intersections always failed. So it has to be something with .toJSON method or ObjectLoader.

Does .toJSON or ObjectLoader not deserialize/serialize the given json properly? Or is there a known bug?


There is no known bug. If toJSON and ObjectLoader are not working with your content, I think you may need to create a demo showing the issue.

When you compare a mesh with its exported-and-then-imported version, are there any differences in primary data (like vertices and normals) and in secondary data (like matrices and bounding spheres/boxes)?

I already compared it via jsondiff.com and both of the outputs are exact similar.
Does ObjectLoader parse it wrongly?

Ive looked at it further and it seems that the JSON does not export the given parent.

I meant – compare the JS objects, not the JSON texts.

Still the same result. Both JS objects are identical. Except the parents.
It seems that toJSON method does not export parents

As there is no shared online example to test with, I made my own example that:

  • loads a GLTF model with GLTFLoader
  • exports the model to JSON and loads the JSON with ObjectLoader (lines 73-81)
  • the first intersection point of a raycaster is marked by a small red sphere

Result: both models can be intersected well. Here is a live example:



Calling toJSON() on an object does not export its parents, no. If you’re trying to include the entire scene you will likely want to call toJSON() on the scene itself.

It wasn’t a parenting problem. Yes, toJSON does not export its parents.
It was mainly worldMatrix problem.

Recalculating it after reconverting it to objects from json fixed the problem.
Mainly these 3 functions;

I actually do not know if this is something what THREE.JS wants. But as for programming sake, please change it so that you don’t have to recalculate the matrices again, because the object had the identity matrix, instead of the actual values.