Jelajahi Sumber

Remove from collision cache

The remove function was missing, meshes and geometries would not have
been removed from the collision cache of the worker.
Raanan Weber 10 tahun lalu
induk
melakukan
c5b145d486

File diff ditekan karena terlalu besar
+ 33 - 0
dist/babylon.js


+ 27 - 11
src/Collisions/babylon.collisionWorker.js

@@ -19,12 +19,18 @@ var BABYLON;
         CollisionCache.prototype.addMesh = function (mesh) {
         CollisionCache.prototype.addMesh = function (mesh) {
             this._meshes[mesh.uniqueId] = mesh;
             this._meshes[mesh.uniqueId] = mesh;
         };
         };
+        CollisionCache.prototype.removeMesh = function (uniqueId) {
+            delete this._meshes[uniqueId];
+        };
         CollisionCache.prototype.getGeometry = function (id) {
         CollisionCache.prototype.getGeometry = function (id) {
             return this._geometries[id];
             return this._geometries[id];
         };
         };
         CollisionCache.prototype.addGeometry = function (geometry) {
         CollisionCache.prototype.addGeometry = function (geometry) {
             this._geometries[geometry.id] = geometry;
             this._geometries[geometry.id] = geometry;
         };
         };
+        CollisionCache.prototype.removeGeometry = function (id) {
+            delete this._geometries[id];
+        };
         return CollisionCache;
         return CollisionCache;
     })();
     })();
     BABYLON.CollisionCache = CollisionCache;
     BABYLON.CollisionCache = CollisionCache;
@@ -156,20 +162,31 @@ var BABYLON;
             postMessage(reply, undefined);
             postMessage(reply, undefined);
         };
         };
         CollisionDetectorTransferable.prototype.onUpdate = function (payload) {
         CollisionDetectorTransferable.prototype.onUpdate = function (payload) {
-            for (var id in payload.updatedGeometries) {
-                if (payload.updatedGeometries.hasOwnProperty(id)) {
-                    this._collisionCache.addGeometry(payload.updatedGeometries[id]);
-                }
-            }
-            for (var uniqueId in payload.updatedMeshes) {
-                if (payload.updatedMeshes.hasOwnProperty(uniqueId)) {
-                    this._collisionCache.addMesh(payload.updatedMeshes[uniqueId]);
-                }
-            }
             var replay = {
             var replay = {
                 error: BABYLON.WorkerReplyType.SUCCESS,
                 error: BABYLON.WorkerReplyType.SUCCESS,
                 taskType: BABYLON.WorkerTaskType.UPDATE
                 taskType: BABYLON.WorkerTaskType.UPDATE
             };
             };
+            try {
+                for (var id in payload.updatedGeometries) {
+                    if (payload.updatedGeometries.hasOwnProperty(id)) {
+                        this._collisionCache.addGeometry(payload.updatedGeometries[id]);
+                    }
+                }
+                for (var uniqueId in payload.updatedMeshes) {
+                    if (payload.updatedMeshes.hasOwnProperty(uniqueId)) {
+                        this._collisionCache.addMesh(payload.updatedMeshes[uniqueId]);
+                    }
+                }
+                payload.removedGeometries.forEach(function (id) {
+                    this._collisionCache.removeGeometry(id);
+                });
+                payload.removedMeshes.forEach(function (uniqueId) {
+                    this._collisionCache.removeMesh(uniqueId);
+                });
+            }
+            catch (x) {
+                replay.error = BABYLON.WorkerReplyType.UNKNOWN_ERROR;
+            }
             postMessage(replay, undefined);
             postMessage(replay, undefined);
         };
         };
         CollisionDetectorTransferable.prototype.onCollision = function (payload) {
         CollisionDetectorTransferable.prototype.onCollision = function (payload) {
@@ -227,4 +244,3 @@ var BABYLON;
         console.log("single worker init");
         console.log("single worker init");
     }
     }
 })(BABYLON || (BABYLON = {}));
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.collisionWorker.js.map

+ 35 - 12
src/Collisions/babylon.collisionWorker.ts

@@ -22,6 +22,10 @@ module BABYLON {
         public addMesh(mesh: SerializedMesh) {
         public addMesh(mesh: SerializedMesh) {
             this._meshes[mesh.uniqueId] = mesh;
             this._meshes[mesh.uniqueId] = mesh;
         }
         }
+		
+		public removeMesh(uniqueId: number) {
+            delete this._meshes[uniqueId];
+        }
 
 
         public getGeometry(id: string): SerializedGeometry {
         public getGeometry(id: string): SerializedGeometry {
             return this._geometries[id];
             return this._geometries[id];
@@ -30,6 +34,10 @@ module BABYLON {
         public addGeometry(geometry: SerializedGeometry) {
         public addGeometry(geometry: SerializedGeometry) {
             this._geometries[geometry.id] = geometry;
             this._geometries[geometry.id] = geometry;
         }
         }
+		
+		public removeGeometry(id: string) {
+            delete this._geometries[id];
+        }
     }
     }
 
 
     export class CollideWorker {
     export class CollideWorker {
@@ -192,21 +200,36 @@ module BABYLON {
         }
         }
 
 
         public onUpdate(payload: UpdatePayload) {
         public onUpdate(payload: UpdatePayload) {
-            for (var id in payload.updatedGeometries) {
-                if (payload.updatedGeometries.hasOwnProperty(id)) {
-                    this._collisionCache.addGeometry(payload.updatedGeometries[id]);
-                }
-            }
-            for (var uniqueId in payload.updatedMeshes) {
-                if (payload.updatedMeshes.hasOwnProperty(uniqueId)) {
-                    this._collisionCache.addMesh(payload.updatedMeshes[uniqueId]);
-                }
-            }
-
-            var replay: WorkerReply = {
+			var replay: WorkerReply = {
                 error: WorkerReplyType.SUCCESS,
                 error: WorkerReplyType.SUCCESS,
                 taskType: WorkerTaskType.UPDATE
                 taskType: WorkerTaskType.UPDATE
             }
             }
+			
+			try {
+				for (var id in payload.updatedGeometries) {
+					if (payload.updatedGeometries.hasOwnProperty(id)) {
+						this._collisionCache.addGeometry(payload.updatedGeometries[id]);
+					}
+				}
+				for (var uniqueId in payload.updatedMeshes) {
+					if (payload.updatedMeshes.hasOwnProperty(uniqueId)) {
+						this._collisionCache.addMesh(payload.updatedMeshes[uniqueId]);
+					}
+				}
+				
+				payload.removedGeometries.forEach(function(id) {
+					this._collisionCache.removeGeometry(id);
+				});
+				
+				payload.removedMeshes.forEach(function(uniqueId) {
+					this._collisionCache.removeMesh(uniqueId);
+				});
+				
+			} catch(x) {
+				replay.error = WorkerReplyType.UNKNOWN_ERROR;
+			}
+
+            
             postMessage(replay, undefined);
             postMessage(replay, undefined);
         }
         }