I'd like to move a piece of my code in which i build a THREE.Geometry object to a HTML5 Web Worker.
Since i don't want to serialize it to a string (for obvious performance purposes), i'd like to convert it to a Transferable Object like ArrayBuffer, File or Blob so i can pass it "by reference".
Do you know a efficient way to convert a THREE.Geometry to one of those objects ?
The most efficient way is to use the existing geometry buffers such as:
They are created in
WebGLRenderer.initMeshBuffers
.How it works:
Create a Worker and import three.js using
importScripts("/js/lib/mrdoob-three.js-35db421/build/three.js");
In the worker you create another instance of the geometry you want to process.
Trigger one initial rendering in the main thred
renderer.render(scene, camera);
now the buffers are available...Send the required buffers from the main thread to the worker
Do the hard work on the geometry at the worker thread
Manually (there is no support for that in threejs) fill the required buffers (see
WebGLRenderer.setMeshBuffers)
e.g.:send the buffers back to the main thread and update the geometry there:
If you are doing complex operations on geometries this works well. Understanding how the buffers are created and used by
WebGLRenderer
is important.