问题
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