How can I offload Object3d.toJSON() operation to a web worker?

别来无恙 提交于 2019-12-24 19:04:15

问题


I need to convert the active scene in threejs to json object. But as the models become bigger, the process takes more and more time. I can't even show a progress bar for the same. I tried to send the threejs scene to a web worker and convert it to json at the worker. But I wasn't able to send the scene object to the worker. Is it possible to send the threejs scene to web worker? Or is there any promise based implementation for the Object3d.toJSON()?


回答1:


Is it possible to send the threejs scene to web worker?

not really. Data-Exchange with the worker is limited to ArrayBuffers and anything that can be copied over using the structured clone algorithm. It's very likely, that it won't even work for something like a THREE.Scene object. But, whatever you try, something in the same complexity order as toJSON() needs to take place to get everything into the Worker.

Or is there any promise based implementation for the Object3d.toJSON()?

unfortunately nothing that could make it behave in a way that doesn't block the UI thread for however long it takes.

But you can have a look at what exactly consumes most of the time (do you have huge texture-images maybe?) and find a way to spot-optimize these things by just overwriting THREE.Whatever.prototype.toJSON() with an alternative version.



来源:https://stackoverflow.com/questions/46432201/how-can-i-offload-object3d-tojson-operation-to-a-web-worker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!