Mesh Building in Web Workers

Hello once again!

I’d like to be able to construct ground tiles with “MeshBuilder.CreateGroundFromHeightMap()”, serialize the mesh upon completion and send it back to the main thread. However, I’ve only had success with simple objects such as planes, spheres or boxes (including materials and textures too), but I haven’t even been able to see my console logs inside the “onReady” callbacks with “CreateGroundFromHeightMap”, as if it’s not being built at all.

Could this be a limitation of NullEngine?

Thanks for your time.

Yes I think so because NullEngine cannot create texture and that function requires to read a file :frowning:
Can you somehow reproduce it in the playground>? or in jsfiddle?

I’m away from my computer at the moment, but I’ll see what I can do on on jsfiddle early next week. I’ve been able send texture data as a blob to the worker, build a texture in the second thread, apply it to a plane and send it back successfully. But even using the subdivide method seems to make it act weird…

I’ll try sending the worker a canvas and use the regular engine; hopefully that won’t interfere with my React component.

1 Like

Hello again! So I think I have it figured out – it’s just a matter of avoiding operations related to the DOM like you said (no image processing). I was able to convert the height-map to a Uint8Array, send it over to the worker and apply mesh.applyDisplacementMapFromBuffer() along with a myriad of other things, then send the mesh back over to the main thread for integration into the scene.

Thanks for your help!

1 Like