Sfoglia il codice sorgente

IE compatibility, Cleanup, functionality

IE 11 is now supported. Tested on Chrome, Firefox, IE, Android chrome.
Cleanup of unneeded comments
Bug fixes
Added update-counter to prevent overflowing the worker with updates.
SubMeshes now get the bounding info serialized so the intersects
function can work correctly.
Raanan Weber 10 anni fa
parent
commit
6050d66577

File diff suppressed because it is too large
+ 21 - 8
Babylon/Collisions/babylon.collisionCoordinator.js


File diff suppressed because it is too large
+ 29 - 8
Babylon/Collisions/babylon.collisionCoordinator.ts


+ 14 - 15
Babylon/Collisions/babylon.collisionWorker.js

@@ -35,7 +35,7 @@ var BABYLON;
             this.collisionTranformationMatrix = BABYLON.Matrix.Zero();
             this.collisionTranformationMatrix = BABYLON.Matrix.Zero();
         }
         }
         CollideWorker.prototype.collideWithWorld = function (position, velocity, maximumRetry, excludedMeshUniqueId) {
         CollideWorker.prototype.collideWithWorld = function (position, velocity, maximumRetry, excludedMeshUniqueId) {
-            //TODO might be a redundant calculation!
+            //TODO CollisionsEpsilon should be defined here and not in the engine.
             var closeDistance = 0.01;
             var closeDistance = 0.01;
             //is initializing here correct? A quick look - looks like it is fine.
             //is initializing here correct? A quick look - looks like it is fine.
             if (this.collider.retry >= maximumRetry) {
             if (this.collider.retry >= maximumRetry) {
@@ -60,7 +60,6 @@ var BABYLON;
                 this.collider._getResponse(position, velocity);
                 this.collider._getResponse(position, velocity);
             }
             }
             if (velocity.length() <= closeDistance) {
             if (velocity.length() <= closeDistance) {
-                //console.log("webworker collision with " + this.collider.collidedMesh);
                 this.finalPosition.copyFrom(position);
                 this.finalPosition.copyFrom(position);
                 return;
                 return;
             }
             }
@@ -134,7 +133,7 @@ var BABYLON;
         };
         };
         //TODO - this! :-)
         //TODO - this! :-)
         CollideWorker.prototype.checkSubmeshCollision = function (subMesh) {
         CollideWorker.prototype.checkSubmeshCollision = function (subMesh) {
-            return true;
+            return this.collider._canDoCollision(BABYLON.Vector3.FromArray(subMesh.sphereCenter), subMesh.sphereRadius, BABYLON.Vector3.FromArray(subMesh.boxMinimum), BABYLON.Vector3.FromArray(subMesh.boxMaximum));
         };
         };
         return CollideWorker;
         return CollideWorker;
     })();
     })();
@@ -145,8 +144,8 @@ var BABYLON;
         CollisionDetectorTransferable.prototype.onInit = function (payload) {
         CollisionDetectorTransferable.prototype.onInit = function (payload) {
             this._collisionCache = new CollisionCache();
             this._collisionCache = new CollisionCache();
             var reply = {
             var reply = {
-                error: BABYLON.WorkerReplyType.SUCCESS,
-                taskType: BABYLON.WorkerTaskType.INIT
+                error: 0 /* SUCCESS */,
+                taskType: 0 /* INIT */
             };
             };
             postMessage(reply, undefined);
             postMessage(reply, undefined);
         };
         };
@@ -162,10 +161,9 @@ var BABYLON;
                 }
                 }
             }
             }
             var replay = {
             var replay = {
-                error: BABYLON.WorkerReplyType.SUCCESS,
-                taskType: BABYLON.WorkerTaskType.UPDATE
+                error: 0 /* SUCCESS */,
+                taskType: 1 /* UPDATE */
             };
             };
-            console.log("updated");
             postMessage(replay, undefined);
             postMessage(replay, undefined);
         };
         };
         CollisionDetectorTransferable.prototype.onCollision = function (payload) {
         CollisionDetectorTransferable.prototype.onCollision = function (payload) {
@@ -181,8 +179,8 @@ var BABYLON;
                 newPosition: finalPosition.asArray()
                 newPosition: finalPosition.asArray()
             };
             };
             var reply = {
             var reply = {
-                error: BABYLON.WorkerReplyType.SUCCESS,
-                taskType: BABYLON.WorkerTaskType.COLLIDE,
+                error: 0 /* SUCCESS */,
+                taskType: 2 /* COLLIDE */,
                 payload: replyPayload
                 payload: replyPayload
             };
             };
             postMessage(reply, undefined);
             postMessage(reply, undefined);
@@ -191,19 +189,20 @@ var BABYLON;
     })();
     })();
     BABYLON.CollisionDetectorTransferable = CollisionDetectorTransferable;
     BABYLON.CollisionDetectorTransferable = CollisionDetectorTransferable;
     //check if we are in a web worker, as this code should NOT run on the main UI thread
     //check if we are in a web worker, as this code should NOT run on the main UI thread
-    if (self && !self.document) {
-        var window = {};
+    if (self && self instanceof WorkerGlobalScope) {
+        //Window hack to allow including babylonjs native code. the <any> is for typescript.
+        window = {};
         var collisionDetector = new CollisionDetectorTransferable();
         var collisionDetector = new CollisionDetectorTransferable();
         var onNewMessage = function (event) {
         var onNewMessage = function (event) {
             var message = event.data;
             var message = event.data;
             switch (message.taskType) {
             switch (message.taskType) {
-                case BABYLON.WorkerTaskType.INIT:
+                case 0 /* INIT */:
                     collisionDetector.onInit(message.payload);
                     collisionDetector.onInit(message.payload);
                     break;
                     break;
-                case BABYLON.WorkerTaskType.COLLIDE:
+                case 2 /* COLLIDE */:
                     collisionDetector.onCollision(message.payload);
                     collisionDetector.onCollision(message.payload);
                     break;
                     break;
-                case BABYLON.WorkerTaskType.UPDATE:
+                case 1 /* UPDATE */:
                     collisionDetector.onUpdate(message.payload);
                     collisionDetector.onUpdate(message.payload);
                     break;
                     break;
             }
             }

+ 9 - 8
Babylon/Collisions/babylon.collisionWorker.ts

@@ -40,7 +40,7 @@ module BABYLON {
 
 
         public collideWithWorld(position: BABYLON.Vector3, velocity: BABYLON.Vector3, maximumRetry: number, excludedMeshUniqueId?: number) {
         public collideWithWorld(position: BABYLON.Vector3, velocity: BABYLON.Vector3, maximumRetry: number, excludedMeshUniqueId?: number) {
 
 
-            //TODO might be a redundant calculation!
+            //TODO CollisionsEpsilon should be defined here and not in the engine.
             var closeDistance = /*BABYLON.Engine.CollisionsEpsilon * 10.0*/ 0.01;
             var closeDistance = /*BABYLON.Engine.CollisionsEpsilon * 10.0*/ 0.01;
             //is initializing here correct? A quick look - looks like it is fine.
             //is initializing here correct? A quick look - looks like it is fine.
             
             
@@ -50,7 +50,6 @@ module BABYLON {
             }
             }
 
 
             this.collider._initialize(position, velocity, closeDistance);
             this.collider._initialize(position, velocity, closeDistance);
-        
 
 
             // Check all meshes
             // Check all meshes
             var meshes = this._collisionCache.getMeshes();
             var meshes = this._collisionCache.getMeshes();
@@ -72,7 +71,6 @@ module BABYLON {
             }
             }
 
 
             if (velocity.length() <= closeDistance) {
             if (velocity.length() <= closeDistance) {
-                //console.log("webworker collision with " + this.collider.collidedMesh);
                 this.finalPosition.copyFrom(position);
                 this.finalPosition.copyFrom(position);
                 return;
                 return;
             }
             }
@@ -160,8 +158,8 @@ module BABYLON {
         }
         }
 
 
         //TODO - this! :-)
         //TODO - this! :-)
-        private checkSubmeshCollision(subMesh: SerializedSubMesh) {
-            return true;
+        private checkSubmeshCollision(subMesh: SerializedSubMesh) : boolean {
+            return this.collider._canDoCollision(BABYLON.Vector3.FromArray(subMesh.sphereCenter), subMesh.sphereRadius, BABYLON.Vector3.FromArray(subMesh.boxMinimum), BABYLON.Vector3.FromArray(subMesh.boxMaximum));
         }
         }
 
 
 
 
@@ -201,7 +199,6 @@ module BABYLON {
                 error: WorkerReplyType.SUCCESS,
                 error: WorkerReplyType.SUCCESS,
                 taskType: WorkerTaskType.UPDATE
                 taskType: WorkerTaskType.UPDATE
             }
             }
-            console.log("updated");
             postMessage(replay, undefined);
             postMessage(replay, undefined);
         }
         }
 
 
@@ -227,10 +224,14 @@ module BABYLON {
         }
         }
     }
     }
 
 
+    //TypeScript doesn't know WorkerGlobalScope
+    declare class WorkerGlobalScope { }
+
     //check if we are in a web worker, as this code should NOT run on the main UI thread
     //check if we are in a web worker, as this code should NOT run on the main UI thread
-    if (self && !self.document) {
+    if (self && self instanceof WorkerGlobalScope) {
 
 
-        var window = {};
+        //Window hack to allow including babylonjs native code. the <any> is for typescript.
+        window = <any> {};
 
 
         var collisionDetector: ICollisionDetector = new CollisionDetectorTransferable();
         var collisionDetector: ICollisionDetector = new CollisionDetectorTransferable();