cityjson / ninja

A web viewer for CityJSON files
https://ninja.cityjson.org
Apache License 2.0
39 stars 13 forks source link

Move CityJSON parsing to web workers #39

Closed liberostelios closed 2 years ago

liberostelios commented 3 years ago

This could be done to minimise the freezing time when CityJSON is parsed/triangulated etc.

Resources:

fdahle commented 3 years ago

I have done it in my current CityJSON-worker. If you want I can share my code with you.

It's unfortunately not that easy, as it is not possible to transfer Meshes/geometries over an web-worker. However I find a solution that works using BufferGeometry.

liberostelios commented 3 years ago

Thanks @fdahle, that's sounds really interesting! I've been thinking about decoupling the parsing of CityJSON from the viewer anyway, so I would be interested to see how you implemented it.

fdahle commented 3 years ago

As already mentioned the most important part is that Webworkers cannot work with meshes/geometries, as these are not simple objects. So currently I'm converting my normal geometries into a BufferGeometry (Later I want to create BufferGeometries directly):

var bufferGeom = new THREE.BufferGeometry().fromGeometry(geom);

In order to not have such a high communication between the Worker and the MainThread I'm currently storing multiple BufferGeometries in a List and return this List to the Worker.

In my main thread I can directly use this bufferGeometry to create a mesh:

var mesh = new THREE.Mesh(bufferGeom, material);

This has furthermore the advantage of making the whole scene smaller, because as far I understood also the regular geometries use bufferGeometries internally.

If you have any questions or need the whole code example just write :)

liberostelios commented 2 years ago

Fixed with latest release (v0.4.0).