Skip to content

Commit

Permalink
Merge pull request #711 from RaananW/remove-mesh-in-worker
Browse files Browse the repository at this point in the history
Remove from collision cache
  • Loading branch information
RaananW committed Sep 29, 2015
2 parents 0f082e3 + f1f4d19 commit 6a48c36
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 23 deletions.
38 changes: 27 additions & 11 deletions src/Collisions/babylon.collisionWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ var BABYLON;
CollisionCache.prototype.addMesh = function (mesh) {
this._meshes[mesh.uniqueId] = mesh;
};
CollisionCache.prototype.removeMesh = function (uniqueId) {
delete this._meshes[uniqueId];
};
CollisionCache.prototype.getGeometry = function (id) {
return this._geometries[id];
};
CollisionCache.prototype.addGeometry = function (geometry) {
this._geometries[geometry.id] = geometry;
};
CollisionCache.prototype.removeGeometry = function (id) {
delete this._geometries[id];
};
return CollisionCache;
})();
BABYLON.CollisionCache = CollisionCache;
Expand Down Expand Up @@ -156,20 +162,31 @@ var BABYLON;
postMessage(reply, undefined);
};
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 = {
error: BABYLON.WorkerReplyType.SUCCESS,
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);
};
CollisionDetectorTransferable.prototype.onCollision = function (payload) {
Expand Down Expand Up @@ -227,4 +244,3 @@ var BABYLON;
console.log("single worker init");
}
})(BABYLON || (BABYLON = {}));
//# sourceMappingURL=babylon.collisionWorker.js.map
47 changes: 35 additions & 12 deletions src/Collisions/babylon.collisionWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ module BABYLON {
public addMesh(mesh: SerializedMesh) {
this._meshes[mesh.uniqueId] = mesh;
}

public removeMesh(uniqueId: number) {
delete this._meshes[uniqueId];
}

public getGeometry(id: string): SerializedGeometry {
return this._geometries[id];
}

public addGeometry(geometry: SerializedGeometry) {
this._geometries[geometry.id] = geometry;
}

public removeGeometry(id: string) {
delete this._geometries[id];
}
}

Expand Down Expand Up @@ -192,21 +200,36 @@ module BABYLON {
}

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,
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);
}

Expand Down

0 comments on commit 6a48c36

Please sign in to comment.