Browse Source

offscreencanvas fixes for r110

Gregg Tavares 5 years ago
parent
commit
18984c8e83

+ 6 - 3
threejs/lessons/threejs-offscreencanvas.md

@@ -1125,7 +1125,8 @@ They also also add `mousemove` and `mouseup` events to the `document`
 to handle mouse capture (when the mouse goes outside the window) but
 to handle mouse capture (when the mouse goes outside the window) but
 like `window` there is no `document` in a worker.
 like `window` there is no `document` in a worker.
 
 
-Finally they look at `document.body`.
+Further the compare `document` to the element we pass into `OrbitControls`
+and expect them to not be equal.
 
 
 We can solve all of these with a few quick hacks. In our worker
 We can solve all of these with a few quick hacks. In our worker
 code we'll re-use our proxy for all 3 problems.
 code we'll re-use our proxy for all 3 problems.
@@ -1133,9 +1134,11 @@ code we'll re-use our proxy for all 3 problems.
 ```js
 ```js
 function start(data) {
 function start(data) {
   const proxy = proxyManager.getProxy(data.canvasId);
   const proxy = proxyManager.getProxy(data.canvasId);
-+  proxy.body = proxy;  // HACK!
 +  self.window = proxy;  // HACK!
 +  self.window = proxy;  // HACK!
-+  self.document = proxy;  // HACK!
++  self.document = {  // HACK!
++    addEventListener: proxy.addEventListener.bind(proxy),
++    removeEventListener: proxy.removeEventListener.bind(proxy),
++  };
   init({
   init({
     canvas: data.canvas,
     canvas: data.canvas,
     inputElement: proxy,
     inputElement: proxy,

+ 4 - 1
threejs/offscreencanvas-worker-orbitcontrols.js

@@ -70,7 +70,10 @@ function start(data) {
   const proxy = proxyManager.getProxy(data.canvasId);
   const proxy = proxyManager.getProxy(data.canvasId);
   proxy.body = proxy;  // HACK!
   proxy.body = proxy;  // HACK!
   self.window = proxy;
   self.window = proxy;
-  self.document = proxy;
+  self.document = {
+    addEventListener: proxy.addEventListener.bind(proxy),
+    removeEventListener: proxy.removeEventListener.bind(proxy),
+  };
   init({
   init({
     canvas: data.canvas,
     canvas: data.canvas,
     inputElement: proxy,
     inputElement: proxy,