1
0

offscreencanvas-worker-picking.js 470 B

12345678910111213141516171819202122232425262728293031323334
  1. import { state, init, pickPosition } from './shared-picking.js';
  2. function size( data ) {
  3. state.width = data.width;
  4. state.height = data.height;
  5. }
  6. function mouse( data ) {
  7. pickPosition.x = data.x;
  8. pickPosition.y = data.y;
  9. }
  10. const handlers = {
  11. init,
  12. mouse,
  13. size,
  14. };
  15. self.onmessage = function ( e ) {
  16. const fn = handlers[ e.data.type ];
  17. if ( typeof fn !== 'function' ) {
  18. throw new Error( 'no handler for type: ' + e.data.type );
  19. }
  20. fn( e.data );
  21. };