Explorar el Código

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 hace 10 años
padre
commit
6050d66577

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 21 - 8
Babylon/Collisions/babylon.collisionCoordinator.js


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 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();
         }
         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;
             //is initializing here correct? A quick look - looks like it is fine.
             if (this.collider.retry >= maximumRetry) {
@@ -60,7 +60,6 @@ var BABYLON;
                 this.collider._getResponse(position, velocity);
             }
             if (velocity.length() <= closeDistance) {
-                //console.log("webworker collision with " + this.collider.collidedMesh);
                 this.finalPosition.copyFrom(position);
                 return;
             }
@@ -134,7 +133,7 @@ var BABYLON;
         };
         //TODO - this! :-)
         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;
     })();
@@ -145,8 +144,8 @@ var BABYLON;
         CollisionDetectorTransferable.prototype.onInit = function (payload) {
             this._collisionCache = new CollisionCache();
             var reply = {
-                error: BABYLON.WorkerReplyType.SUCCESS,
-                taskType: BABYLON.WorkerTaskType.INIT
+                error: 0 /* SUCCESS */,
+                taskType: 0 /* INIT */
             };
             postMessage(reply, undefined);
         };
@@ -162,10 +161,9 @@ var BABYLON;
                 }
             }
             var replay = {
-                error: BABYLON.WorkerReplyType.SUCCESS,
-                taskType: BABYLON.WorkerTaskType.UPDATE
+                error: 0 /* SUCCESS */,
+                taskType: 1 /* UPDATE */
             };
-            console.log("updated");
             postMessage(replay, undefined);
         };
         CollisionDetectorTransferable.prototype.onCollision = function (payload) {
@@ -181,8 +179,8 @@ var BABYLON;
                 newPosition: finalPosition.asArray()
             };
             var reply = {
-                error: BABYLON.WorkerReplyType.SUCCESS,
-                taskType: BABYLON.WorkerTaskType.COLLIDE,
+                error: 0 /* SUCCESS */,
+                taskType: 2 /* COLLIDE */,
                 payload: replyPayload
             };
             postMessage(reply, undefined);
@@ -191,19 +189,20 @@ var BABYLON;
     })();
     BABYLON.CollisionDetectorTransferable = CollisionDetectorTransferable;
     //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 onNewMessage = function (event) {
             var message = event.data;
             switch (message.taskType) {
-                case BABYLON.WorkerTaskType.INIT:
+                case 0 /* INIT */:
                     collisionDetector.onInit(message.payload);
                     break;
-                case BABYLON.WorkerTaskType.COLLIDE:
+                case 2 /* COLLIDE */:
                     collisionDetector.onCollision(message.payload);
                     break;
-                case BABYLON.WorkerTaskType.UPDATE:
+                case 1 /* UPDATE */:
                     collisionDetector.onUpdate(message.payload);
                     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) {
 
-            //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;
             //is initializing here correct? A quick look - looks like it is fine.
             
@@ -50,7 +50,6 @@ module BABYLON {
             }
 
             this.collider._initialize(position, velocity, closeDistance);
-        
 
             // Check all meshes
             var meshes = this._collisionCache.getMeshes();
@@ -72,7 +71,6 @@ module BABYLON {
             }
 
             if (velocity.length() <= closeDistance) {
-                //console.log("webworker collision with " + this.collider.collidedMesh);
                 this.finalPosition.copyFrom(position);
                 return;
             }
@@ -160,8 +158,8 @@ module BABYLON {
         }
 
         //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,
                 taskType: WorkerTaskType.UPDATE
             }
-            console.log("updated");
             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
-    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();