Offscreen canvas and orbit controls

Hi all.

I am trying to use the offscreen canvas in my 3d threejs based viewer.

One of my problems is that I don’t know how to interact with my scene with an orbitControls in the webworker thread.

As far as I know, webworkers cannot interact with dom objects.

Is there any workarraound for this?

Best regards

Only thing you need is the camera in your worker, so use the OrbitControls in your main thread and just snycrhonize the camera quaternion and world position with your thread.

I have found an example:

https://threejsfundamentals.org/threejs/threejs-offscreencanvas-w-orbitcontrols.html

Best regards

1 Like

I wrote an example, you can view:
https://github.com/puxiao/using-orbitcontrols-in-worker

1 Like

What if I have a raycasting, TransformControls and Keyevents?

  • Keep user interactions, event handling (like OrbitControls), and any operations directly related to the DOM or user input in the main thread.
  • Synchronize changes in the camera’s properties (position, rotation, etc.) between the main thread and the worker thread for rendering updates.
  • Handle interactions like raycasting or object transformations in the main thread and communicate the necessary data or results to the worker for rendering updates.

This means it is not necessary to have proxies for the controls like puxiao suggests in his example to pass the events if the controls are camera related?

1 Like