Let me start by saying that I am new to three.js and would like to share my learning journey.
My objective was to convert geometry into a format that can be transferred to another web worker (as not all objects can be transferred between workers, only structured cloneable datatypes). I referred to the documentation and tried using .toJSON along with BufferGeometryLoader, among other approaches.
const box = new BoxBufferGeometry();
const geomJSON = box.toJSON();
const geometriesLoader = new THREE.BufferGeometryLoader();
const parsedGeom = geometriesLoader.parse(geomJSON);
const mesh = new Mesh(parsedGeom);
this.scene.add(mesh);
This resulted in an error message:
https://i.sstatic.net/rqMuU.png
I also experimented with different loaders, such as JSON.stringify
, but found that packaging meshes with geometries in a GLTF file and serializing it with a callback function was the most effective solution (although not very convenient).
Despite reaching out for help online, I couldn't find a satisfactory answer. The documentation simply states:
.toJSON (): Object
Convert the buffer geometry to three.js JSON Object/Scene format.
Three.js version: 0.135.0 and 0.136.0