I'm developing a personal website to combine Three.js and ScrollMagic with OO Javascript. As the user scrolls the 3d Objects transform. This all works well but there is a slight performance issue. To improve this I want to move some loop/for functions that calculate positions to a web worker (whenever I call a loop function the scrolling lags).
The problem is I'm trying to pass an array (512) of class instances (THREE.PointCloud) to the web worker. I can't seem to get any meaning full properties from these instances in the web worker.
Firstly, I just tried to pass the array to the worker and got this error 'Uncaught DataCloneError: Failed to execute 'postMessage' on 'Worker': An object could not be cloned.'
Then I realised I couldn't do this so then I used JSON.stringify() and JSON.Parse(). I could get the length of the array. However, I couldn't get the properties for each instance.
I think I need to use an ArrayBuffer? But I have no idea how to convert my array of instances to an ArrayBuffer. Anyone? or is there an easier way to improve the performance?
Help would be really appreciated.
Thanks.