offscreencanvas-worker-picking.js 538 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. /* global importScripts, init, state, pickPosition */
  3. importScripts('resources/threejs/r115/build/three.min.js');
  4. importScripts('shared-picking.js');
  5. function size(data) {
  6. state.width = data.width;
  7. state.height = data.height;
  8. }
  9. function mouse(data) {
  10. pickPosition.x = data.x;
  11. pickPosition.y = data.y;
  12. }
  13. const handlers = {
  14. init,
  15. mouse,
  16. size,
  17. };
  18. self.onmessage = function(e) {
  19. const fn = handlers[e.data.type];
  20. if (!fn) {
  21. throw new Error('no handler for type: ' + e.data.type);
  22. }
  23. fn(e.data);
  24. };