소스 검색

Remove Worker

sebastien 6 년 전
부모
커밋
be67c4929c

+ 0 - 4
src/Cameras/arcRotateCamera.ts

@@ -954,10 +954,6 @@ import { ArcRotateCameraInputsManager } from "Cameras/arcRotateCameraInputsManag
 
         protected _onCollisionPositionChange = (collisionId: number, newPosition: Vector3, collidedMesh: Nullable<AbstractMesh> = null) => {
 
-            if (this.getScene().workerCollisions && this.checkCollisions) {
-                newPosition.multiplyInPlace(this._collider._radius);
-            }
-
             if (!collidedMesh) {
                 this._previousPosition.copyFrom(this.position);
             } else {

+ 0 - 4
src/Cameras/flyCamera.ts

@@ -340,10 +340,6 @@ import { FlyCameraKeyboardInput } from "Cameras/Inputs/flyCameraKeyboardInput";
 
         /** @hidden */
         private _onCollisionPositionChange = (collisionId: number, newPosition: Vector3, collidedMesh: Nullable<AbstractMesh> = null) => {
-            // TODO Move this to the collision coordinator!
-            if (this.getScene().workerCollisions) {
-                newPosition.multiplyInPlace(this._collider._radius);
-            }
 
             var updatePosition = (newPos: Vector3) => {
                 this._newPosition.copyFrom(newPos);

+ 0 - 4
src/Cameras/freeCamera.ts

@@ -257,10 +257,6 @@ import { FreeCameraKeyboardMoveInput } from "Cameras/Inputs/freeCameraKeyboardMo
         }
 
         private _onCollisionPositionChange = (collisionId: number, newPosition: Vector3, collidedMesh: Nullable<AbstractMesh> = null) => {
-            //TODO move this to the collision coordinator!
-            if (this.getScene().workerCollisions) {
-                newPosition.multiplyInPlace(this._collider._radius);
-            }
 
             var updatePosition = (newPos: Vector3) => {
                 this._newPosition.copyFrom(newPos);

+ 0 - 375
src/Collisions/collisionCoordinator.ts

@@ -1,20 +1,10 @@
-import { Tools } from "Tools/tools";
 import { Nullable } from "types";
 import { Scene } from "scene";
 import { Vector3 } from "Math/math";
 import { Engine } from "Engine/engine";
 import { Collider } from "./collider";
-import { WorkerIncluded } from "./collisionWorker";
-import { TransformNode } from "Mesh/transformNode";
 import { Geometry } from "Mesh/geometry";
-import { VertexBuffer } from "Mesh/buffer";
 import { AbstractMesh } from "Mesh/abstractMesh";
-import { InstancedMesh } from "Mesh/instancedMesh";
-import { Mesh } from "Mesh/mesh";
-
-    //WebWorker code will be inserted to this variable.
-    /** @hidden */
-    export var CollisionWorker = "";
 
     /** @hidden */
     export interface ICollisionCoordinator {
@@ -32,371 +22,6 @@ import { Mesh } from "Mesh/mesh";
     }
 
     /** @hidden */
-    export interface SerializedMesh {
-        id: string;
-        name: string;
-        uniqueId: number;
-        geometryId: Nullable<string>;
-        sphereCenter: Array<number>;
-        sphereRadius: number;
-        boxMinimum: Array<number>;
-        boxMaximum: Array<number>;
-        worldMatrixFromCache: any;
-        subMeshes: Array<SerializedSubMesh>;
-        checkCollisions: boolean;
-    }
-
-    /** @hidden */
-    export interface SerializedSubMesh {
-        position: number;
-        verticesStart: number;
-        verticesCount: number;
-        indexStart: number;
-        indexCount: number;
-        hasMaterial: boolean;
-        sphereCenter: Array<number>;
-        sphereRadius: number;
-        boxMinimum: Array<number>;
-        boxMaximum: Array<number>;
-    }
-
-    /**
-     * Interface describing the value associated with a geometry.
-     * @hidden
-     */
-    export interface SerializedGeometry {
-        /**
-         * Defines the unique ID of the geometry
-         */
-        id: string;
-        /**
-         * Defines the array containing the positions
-         */
-        positions: Float32Array;
-        /**
-         * Defines the array containing the indices
-         */
-        indices: Uint32Array;
-        /**
-         * Defines the array containing the normals
-         */
-        normals: Float32Array;
-    }
-
-    /** @hidden */
-    export interface BabylonMessage {
-        taskType: WorkerTaskType;
-        payload: InitPayload | CollidePayload | UpdatePayload /*any for TS under 1.4*/;
-    }
-
-    /** @hidden */
-    export interface SerializedColliderToWorker {
-        position: Array<number>;
-        velocity: Array<number>;
-        radius: Array<number>;
-    }
-
-    /** Defines supported task for worker process */
-    export enum WorkerTaskType {
-        /** Initialization */
-        INIT,
-        /** Update of geometry */
-        UPDATE,
-        /** Evaluate collision */
-        COLLIDE
-    }
-
-    /** @hidden */
-    export interface WorkerReply {
-        error: WorkerReplyType;
-        taskType: WorkerTaskType;
-        payload?: any;
-    }
-
-    /** @hidden */
-    export interface CollisionReplyPayload {
-        newPosition: Array<number>;
-        collisionId: number;
-        collidedMeshUniqueId: number;
-    }
-
-    /** @hidden */
-    export interface InitPayload {
-
-    }
-
-    /** @hidden */
-    export interface CollidePayload {
-        collisionId: number;
-        collider: SerializedColliderToWorker;
-        maximumRetry: number;
-        excludedMeshUniqueId: Nullable<number>;
-    }
-
-    /** @hidden */
-    export interface UpdatePayload {
-        updatedMeshes: { [n: number]: SerializedMesh; };
-        updatedGeometries: { [s: string]: SerializedGeometry; };
-        removedMeshes: Array<number>;
-        removedGeometries: Array<string>;
-    }
-
-    /** Defines kind of replies returned by worker */
-    export enum WorkerReplyType {
-        /** Success */
-        SUCCESS,
-        /** Unkown error */
-        UNKNOWN_ERROR
-    }
-
-    /** @hidden */
-    export class CollisionCoordinatorWorker implements ICollisionCoordinator {
-
-        private _scene: Scene;
-
-        private _scaledPosition = Vector3.Zero();
-        private _scaledVelocity = Vector3.Zero();
-
-        private _collisionsCallbackArray: Array<Nullable<(collisionIndex: number, newPosition: Vector3, collidedMesh: Nullable<AbstractMesh>) => void>>;
-
-        private _init: boolean;
-        private _runningUpdated: number;
-        private _worker: Worker;
-
-        private _addUpdateMeshesList: { [n: number]: SerializedMesh; };
-        private _addUpdateGeometriesList: { [s: string]: SerializedGeometry; };
-        private _toRemoveMeshesArray: Array<number>;
-        private _toRemoveGeometryArray: Array<string>;
-
-        constructor() {
-            this._collisionsCallbackArray = [];
-            this._init = false;
-            this._runningUpdated = 0;
-
-            this._addUpdateMeshesList = {};
-            this._addUpdateGeometriesList = {};
-            this._toRemoveGeometryArray = [];
-            this._toRemoveMeshesArray = [];
-        }
-
-        public static SerializeMesh = function(mesh: AbstractMesh): SerializedMesh {
-            var submeshes: Array<SerializedSubMesh> = [];
-            if (mesh.subMeshes) {
-                submeshes = mesh.subMeshes.map(function(sm, idx) {
-                    let boundingInfo = sm.getBoundingInfo();
-
-                    return {
-                        position: idx,
-                        verticesStart: sm.verticesStart,
-                        verticesCount: sm.verticesCount,
-                        indexStart: sm.indexStart,
-                        indexCount: sm.indexCount,
-                        hasMaterial: !!sm.getMaterial(),
-                        sphereCenter: boundingInfo.boundingSphere.centerWorld.asArray(),
-                        sphereRadius: boundingInfo.boundingSphere.radiusWorld,
-                        boxMinimum: boundingInfo.boundingBox.minimumWorld.asArray(),
-                        boxMaximum: boundingInfo.boundingBox.maximumWorld.asArray()
-                    };
-                });
-            }
-
-            var geometryId: Nullable<string> = null;
-            if (mesh instanceof Mesh) {
-                let geometry = (<Mesh>mesh).geometry;
-                geometryId = geometry ? geometry.id : null;
-            } else if (mesh instanceof InstancedMesh) {
-                let geometry = (<InstancedMesh>mesh).sourceMesh && (<InstancedMesh>mesh).sourceMesh.geometry;
-                geometryId = geometry ? geometry.id : null;
-            }
-
-            let boundingInfo = mesh.getBoundingInfo();
-
-            return {
-                uniqueId: mesh.uniqueId,
-                id: mesh.id,
-                name: mesh.name,
-                geometryId: geometryId,
-                sphereCenter: boundingInfo.boundingSphere.centerWorld.asArray(),
-                sphereRadius: boundingInfo.boundingSphere.radiusWorld,
-                boxMinimum: boundingInfo.boundingBox.minimumWorld.asArray(),
-                boxMaximum: boundingInfo.boundingBox.maximumWorld.asArray(),
-                worldMatrixFromCache: mesh.worldMatrixFromCache.asArray(),
-                subMeshes: submeshes,
-                checkCollisions: mesh.checkCollisions
-            };
-        };
-
-        public static SerializeGeometry = function(geometry: Geometry): SerializedGeometry {
-            return {
-                id: geometry.id,
-                positions: new Float32Array(geometry.getVerticesData(VertexBuffer.PositionKind) || []),
-                normals: new Float32Array(geometry.getVerticesData(VertexBuffer.NormalKind) || []),
-                indices: new Uint32Array(geometry.getIndices() || []),
-                //uvs: new Float32Array(geometry.getVerticesData(VertexBuffer.UVKind) || [])
-            };
-        };
-
-        public getNewPosition(position: Vector3, displacement: Vector3, collider: Collider, maximumRetry: number, excludedMesh: AbstractMesh, onNewPosition: (collisionIndex: number, newPosition: Vector3, collidedMesh: Nullable<AbstractMesh>) => void, collisionIndex: number): void {
-            if (!this._init) { return; }
-            if (this._collisionsCallbackArray[collisionIndex] || this._collisionsCallbackArray[collisionIndex + 100000]) { return; }
-
-            position.divideToRef(collider._radius, this._scaledPosition);
-            displacement.divideToRef(collider._radius, this._scaledVelocity);
-
-            this._collisionsCallbackArray[collisionIndex] = onNewPosition;
-
-            var payload: CollidePayload = {
-                collider: {
-                    position: this._scaledPosition.asArray(),
-                    velocity: this._scaledVelocity.asArray(),
-                    radius: collider._radius.asArray()
-                },
-                collisionId: collisionIndex,
-                excludedMeshUniqueId: excludedMesh ? excludedMesh.uniqueId : null,
-                maximumRetry: maximumRetry
-            };
-            var message: BabylonMessage = {
-                payload: payload,
-                taskType: WorkerTaskType.COLLIDE
-            };
-            this._worker.postMessage(message);
-
-        }
-
-        public init(scene: Scene): void {
-            this._scene = scene;
-            this._scene.registerAfterRender(this._afterRender);
-            var workerUrl = WorkerIncluded ? Engine.CodeRepository + "Collisions/babylon.collisionWorker.js" : URL.createObjectURL(new Blob([CollisionWorker], { type: 'application/javascript' }));
-            this._worker = new Worker(workerUrl);
-            this._worker.onmessage = this._onMessageFromWorker;
-            var message: BabylonMessage = {
-                payload: {},
-                taskType: WorkerTaskType.INIT
-            };
-            this._worker.postMessage(message);
-        }
-
-        public destroy(): void {
-            this._scene.unregisterAfterRender(this._afterRender);
-            this._worker.terminate();
-        }
-
-        public onMeshAdded(mesh: AbstractMesh) {
-            mesh.registerAfterWorldMatrixUpdate(this.onMeshUpdated);
-            this.onMeshUpdated(mesh);
-        }
-
-        public onMeshUpdated = (transformNode: TransformNode) => {
-            this._addUpdateMeshesList[transformNode.uniqueId] = CollisionCoordinatorWorker.SerializeMesh(transformNode as AbstractMesh);
-        }
-
-        public onMeshRemoved(mesh: AbstractMesh) {
-            this._toRemoveMeshesArray.push(mesh.uniqueId);
-        }
-
-        public onGeometryAdded(geometry: Geometry) {
-            //TODO this will break if the user uses his own function. This should be an array of callbacks!
-            geometry.onGeometryUpdated = this.onGeometryUpdated;
-            this.onGeometryUpdated(geometry);
-        }
-
-        public onGeometryUpdated = (geometry: Geometry) => {
-            this._addUpdateGeometriesList[geometry.id] = CollisionCoordinatorWorker.SerializeGeometry(geometry);
-        }
-
-        public onGeometryDeleted(geometry: Geometry) {
-            this._toRemoveGeometryArray.push(geometry.id);
-        }
-
-        private _afterRender = () => {
-
-            if (!this._init) { return; }
-
-            if (this._toRemoveGeometryArray.length == 0 && this._toRemoveMeshesArray.length == 0 && Object.keys(this._addUpdateGeometriesList).length == 0 && Object.keys(this._addUpdateMeshesList).length == 0) {
-                return;
-            }
-
-            //5 concurrent updates were sent to the web worker and were not yet processed. Abort next update.
-            //TODO make sure update runs as fast as possible to be able to update 60 FPS.
-            if (this._runningUpdated > 4) {
-                return;
-            }
-
-            ++this._runningUpdated;
-
-            var payload: UpdatePayload = {
-                updatedMeshes: this._addUpdateMeshesList,
-                updatedGeometries: this._addUpdateGeometriesList,
-                removedGeometries: this._toRemoveGeometryArray,
-                removedMeshes: this._toRemoveMeshesArray
-            };
-            var message: BabylonMessage = {
-                payload: payload,
-                taskType: WorkerTaskType.UPDATE
-            };
-            var serializable = [];
-            for (var id in payload.updatedGeometries) {
-                if (payload.updatedGeometries.hasOwnProperty(id)) {
-                    //prepare transferables
-                    serializable.push((<UpdatePayload>message.payload).updatedGeometries[id].indices.buffer);
-                    serializable.push((<UpdatePayload>message.payload).updatedGeometries[id].normals.buffer);
-                    serializable.push((<UpdatePayload>message.payload).updatedGeometries[id].positions.buffer);
-                }
-            }
-
-            this._worker.postMessage(message, serializable);
-            this._addUpdateMeshesList = {};
-            this._addUpdateGeometriesList = {};
-            this._toRemoveGeometryArray = [];
-            this._toRemoveMeshesArray = [];
-        }
-
-        private _onMessageFromWorker = (e: MessageEvent) => {
-            var returnData = <WorkerReply>e.data;
-            if (returnData.error != WorkerReplyType.SUCCESS) {
-                //TODO what errors can be returned from the worker?
-                Tools.Warn("error returned from worker!");
-                return;
-            }
-
-            switch (returnData.taskType) {
-                case WorkerTaskType.INIT:
-                    this._init = true;
-                    //Update the worked with ALL of the scene's current state
-                    this._scene.meshes.forEach((mesh) => {
-                        this.onMeshAdded(mesh);
-                    });
-
-                    this._scene.getGeometries().forEach((geometry) => {
-                        this.onGeometryAdded(geometry);
-                    });
-
-                    break;
-                case WorkerTaskType.UPDATE:
-                    this._runningUpdated--;
-                    break;
-                case WorkerTaskType.COLLIDE:
-                    var returnPayload: CollisionReplyPayload = returnData.payload;
-                    if (!this._collisionsCallbackArray[returnPayload.collisionId]) { return; }
-
-                    let callback = this._collisionsCallbackArray[returnPayload.collisionId];
-
-                    if (callback) {
-                        let mesh = this._scene.getMeshByUniqueID(returnPayload.collidedMeshUniqueId);
-
-                        if (mesh) {
-                            callback(returnPayload.collisionId, Vector3.FromArray(returnPayload.newPosition), mesh);
-                        }
-                    }
-
-                    //cleanup
-                    this._collisionsCallbackArray[returnPayload.collisionId] = null;
-                    break;
-            }
-        }
-    }
-
-    /** @hidden */
     export class CollisionCoordinatorLegacy implements ICollisionCoordinator {
 
         private _scene: Scene;

+ 0 - 305
src/Collisions/collisionWorker.ts

@@ -1,305 +0,0 @@
-import { Nullable } from "types";
-import { Matrix, Vector3 } from "Math/math";
-import { Collider } from "Collisions/collider";
-import { SerializedMesh, SerializedGeometry, SerializedSubMesh, InitPayload, UpdatePayload, CollidePayload, WorkerReply, WorkerReplyType, WorkerTaskType, CollisionReplyPayload, BabylonMessage } from "Collisions/collisionCoordinator";
-
-declare function importScripts(...urls: string[]): void;
-
-// since typescript doesn't understand the file's execution context, we need to override postMessage's signature for error-free compilation
-const safePostMessage: any = self.postMessage;
-
-    //If this file is included in the main thread, this will be initialized.
-    /** @hidden */
-    export var WorkerIncluded: boolean = true;
-
-    /** @hidden */
-    export class CollisionCache {
-        private _meshes: { [n: string]: SerializedMesh; } = {};
-        private _geometries: { [s: string]: SerializedGeometry; } = {};
-
-        public getMeshes(): { [n: number]: SerializedMesh; } {
-            return this._meshes;
-        }
-
-        public getGeometries(): { [s: number]: SerializedGeometry; } {
-            return this._geometries;
-        }
-
-        public getMesh(id: any): SerializedMesh {
-            return this._meshes[id];
-        }
-
-        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];
-        }
-    }
-
-    /** @hidden */
-    export class CollideWorker {
-
-        private collisionsScalingMatrix = Matrix.Zero();
-        private collisionTranformationMatrix = Matrix.Zero();
-
-        constructor(public collider: Collider, private _collisionCache: CollisionCache, private finalPosition: Vector3) {
-
-        }
-
-        public collideWithWorld(position: Vector3, velocity: Vector3, maximumRetry: number, excludedMeshUniqueId: Nullable<number>) {
-
-            //TODO CollisionsEpsilon should be defined here and not in the engine.
-            const closeDistance = 0.01; //is initializing here correct? A quick look - looks like it is fine.
-            if (this.collider._retry >= maximumRetry) {
-                this.finalPosition.copyFrom(position);
-                return;
-            }
-
-            this.collider._initialize(position, velocity, closeDistance);
-
-            // Check all meshes
-            var meshes = this._collisionCache.getMeshes();
-            var keys = Object.keys(meshes);
-            var len = keys.length;
-            var uniqueId: string;
-
-            for (var i = 0; i < len; ++i) {
-                uniqueId = keys[i];
-                if (parseInt(uniqueId) != excludedMeshUniqueId) {
-                    var mesh: SerializedMesh = (<any>meshes)[uniqueId];
-                    if (mesh.checkCollisions) {
-                        this.checkCollision(mesh);
-                    }
-                }
-            }
-
-            if (!this.collider.collisionFound) {
-                position.addToRef(velocity, this.finalPosition);
-                return;
-            }
-
-            if (velocity.x !== 0 || velocity.y !== 0 || velocity.z !== 0) {
-                this.collider._getResponse(position, velocity);
-            }
-
-            if (velocity.length() <= closeDistance) {
-                this.finalPosition.copyFrom(position);
-                return;
-            }
-
-            this.collider._retry++;
-            this.collideWithWorld(position, velocity, maximumRetry, excludedMeshUniqueId);
-        }
-
-        private checkCollision(mesh: SerializedMesh) {
-
-            if (!this.collider._canDoCollision(Vector3.FromArray(mesh.sphereCenter), mesh.sphereRadius, Vector3.FromArray(mesh.boxMinimum), Vector3.FromArray(mesh.boxMaximum))) {
-                return;
-            }
-
-            // Transformation matrix
-            Matrix.ScalingToRef(1.0 / this.collider._radius.x, 1.0 / this.collider._radius.y, 1.0 / this.collider._radius.z, this.collisionsScalingMatrix);
-            var worldFromCache = Matrix.FromArray(mesh.worldMatrixFromCache);
-            worldFromCache.multiplyToRef(this.collisionsScalingMatrix, this.collisionTranformationMatrix);
-
-            this.processCollisionsForSubMeshes(this.collisionTranformationMatrix, mesh);
-            //return colTransMat;
-        }
-
-        private processCollisionsForSubMeshes(transformMatrix: Matrix, mesh: SerializedMesh): void {
-            // No Octrees for now
-            //if (this._submeshesOctree && this.useOctreeForCollisions) {
-            //    var radius = collider.velocityWorldLength + Math.max(collider.radius.x, collider.radius.y, collider.radius.z);
-            //    var intersections = this._submeshesOctree.intersects(collider.basePointWorld, radius);
-
-            //    len = intersections.length;
-            //    subMeshes = intersections.data;
-            //} else {
-            var subMeshes = mesh.subMeshes;
-            var len = subMeshes.length;
-            //}
-
-            if (!mesh.geometryId) {
-                console.log("no mesh geometry id");
-                return;
-            }
-
-            var meshGeometry = this._collisionCache.getGeometry(mesh.geometryId);
-            if (!meshGeometry) {
-                console.log("couldn't find geometry", mesh.geometryId);
-                return;
-            }
-
-            for (var index = 0; index < len; index++) {
-                var subMesh = subMeshes[index];
-
-                // Bounding test
-                if (len > 1 && !this.checkSubmeshCollision(subMesh)) {
-                    continue;
-                }
-
-                this.collideForSubMesh(subMesh, transformMatrix, meshGeometry);
-                if (this.collider.collisionFound) {
-                    this.collider.collidedMesh = <any>mesh.uniqueId;
-                }
-            }
-        }
-
-        private collideForSubMesh(subMesh: SerializedSubMesh, transformMatrix: Matrix, meshGeometry: SerializedGeometry): void {
-            if (!(<any>meshGeometry)['positionsArray']) {
-                (<any>meshGeometry)['positionsArray'] = [];
-                for (var i = 0, len = meshGeometry.positions.length; i < len; i = i + 3) {
-                    var p = Vector3.FromArray([meshGeometry.positions[i], meshGeometry.positions[i + 1], meshGeometry.positions[i + 2]]);
-                    (<any>meshGeometry)['positionsArray'].push(p);
-                }
-            }
-
-            if (!(<any>subMesh)['_lastColliderWorldVertices'] || !(<any>subMesh)['_lastColliderTransformMatrix'].equals(transformMatrix)) {
-                (<any>subMesh)['_lastColliderTransformMatrix'] = transformMatrix.clone();
-                (<any>subMesh)['_lastColliderWorldVertices'] = [];
-                (<any>subMesh)['_trianglePlanes'] = [];
-                var start = subMesh.verticesStart;
-                var end = (subMesh.verticesStart + subMesh.verticesCount);
-                for (var i = start; i < end; i++) {
-                    (<any>subMesh)['_lastColliderWorldVertices'].push(Vector3.TransformCoordinates((<any>meshGeometry)['positionsArray'][i], transformMatrix));
-                }
-            }
-
-            // Collide
-            this.collider._collide((<any>subMesh)['_trianglePlanes'], (<any>subMesh)['_lastColliderWorldVertices'], <any>meshGeometry.indices, subMesh.indexStart, subMesh.indexStart + subMesh.indexCount, subMesh.verticesStart, subMesh.hasMaterial);
-
-        }
-
-        private checkSubmeshCollision(subMesh: SerializedSubMesh): boolean {
-            return this.collider._canDoCollision(Vector3.FromArray(subMesh.sphereCenter), subMesh.sphereRadius, Vector3.FromArray(subMesh.boxMinimum), Vector3.FromArray(subMesh.boxMaximum));
-        }
-    }
-
-    /** @hidden */
-    export interface ICollisionDetector {
-        onInit(payload: InitPayload): void;
-        onUpdate(payload: UpdatePayload): void;
-        onCollision(payload: CollidePayload): void;
-    }
-
-    /** @hidden */
-    export class CollisionDetectorTransferable implements ICollisionDetector {
-        private _collisionCache: CollisionCache;
-
-        public onInit(payload: InitPayload) {
-            this._collisionCache = new CollisionCache();
-            var reply: WorkerReply = {
-                error: WorkerReplyType.SUCCESS,
-                taskType: WorkerTaskType.INIT
-            };
-            safePostMessage(reply);
-        }
-
-        public onUpdate(payload: UpdatePayload) {
-            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((id) => {
-                    this._collisionCache.removeGeometry(id);
-                });
-
-                payload.removedMeshes.forEach((uniqueId) => {
-                    this._collisionCache.removeMesh(uniqueId);
-                });
-
-            } catch (x) {
-                replay.error = WorkerReplyType.UNKNOWN_ERROR;
-            }
-
-            safePostMessage(replay);
-        }
-
-        public onCollision(payload: CollidePayload) {
-            var finalPosition = Vector3.Zero();
-            //create a new collider
-            var collider = new Collider();
-            collider._radius = Vector3.FromArray(payload.collider.radius);
-
-            var colliderWorker = new CollideWorker(collider, this._collisionCache, finalPosition);
-            colliderWorker.collideWithWorld(Vector3.FromArray(payload.collider.position), Vector3.FromArray(payload.collider.velocity), payload.maximumRetry, payload.excludedMeshUniqueId);
-            var replyPayload: CollisionReplyPayload = {
-                collidedMeshUniqueId: <any>collider.collidedMesh,
-                collisionId: payload.collisionId,
-                newPosition: finalPosition.asArray()
-            };
-            var reply: WorkerReply = {
-                error: WorkerReplyType.SUCCESS,
-                taskType: WorkerTaskType.COLLIDE,
-                payload: replyPayload
-            };
-            safePostMessage(reply);
-        }
-    }
-
-    //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
-    try {
-        if (self && self instanceof WorkerGlobalScope) {
-
-            //Window hack to allow including babylonjs native code. the <any> is for typescript.
-            window = <any>{};
-
-            //scripts were not included, standalone worker
-            if (!Collider) {
-                importScripts("./babylon.collisionCoordinator.js");
-                importScripts("./babylon.collider.js");
-                importScripts("../Math/babylon.math.js");
-            }
-
-            var collisionDetector: ICollisionDetector = new CollisionDetectorTransferable();
-
-            var onNewMessage = (event: MessageEvent) => {
-                var message = <BabylonMessage>event.data;
-                switch (message.taskType) {
-                    case WorkerTaskType.INIT:
-                        collisionDetector.onInit(<InitPayload>message.payload);
-                        break;
-                    case WorkerTaskType.COLLIDE:
-                        collisionDetector.onCollision(<CollidePayload>message.payload);
-                        break;
-                    case WorkerTaskType.UPDATE:
-                        collisionDetector.onUpdate(<UpdatePayload>message.payload);
-                        break;
-                }
-            };
-
-            self.onmessage = onNewMessage;
-        }
-    } catch (e) {
-        console.log("single worker init");
-    }

+ 0 - 1
src/Collisions/index.ts

@@ -1,4 +1,3 @@
 export * from "./collider";
 export * from "./collisionCoordinator";
-export * from "./collisionWorker";
 export * from "./pickingInfo";

+ 0 - 1
src/Loading/Plugins/babylonFileLoader.ts

@@ -641,7 +641,6 @@ import { CannonJSPlugin, OimoJSPlugin } from "Physics";
                 if (parsedData.collisionsEnabled !== undefined && parsedData.collisionsEnabled !== null) {
                     scene.collisionsEnabled = parsedData.collisionsEnabled;
                 }
-                scene.workerCollisions = !!parsedData.workerCollisions;
 
                 var container = loadAssetContainer(scene, data, rootUrl, onError, true);
                 if (!container) {

+ 0 - 8
src/Mesh/abstractMesh.ts

@@ -1263,9 +1263,6 @@ import { Constants } from "Engine/constants";
 
         public set checkCollisions(collisionEnabled: boolean) {
             this._checkCollisions = collisionEnabled;
-            if (this.getScene().workerCollisions) {
-                this.getScene().collisionCoordinator.onMeshUpdated(this);
-            }
         }
 
         /**
@@ -1298,11 +1295,6 @@ import { Constants } from "Engine/constants";
         }
 
         private _onCollisionPositionChange = (collisionId: number, newPosition: Vector3, collidedMesh: Nullable<AbstractMesh> = null) => {
-            //TODO move this to the collision coordinator!
-            if (this.getScene().workerCollisions) {
-                newPosition.multiplyInPlace(this._collider._radius);
-            }
-
             newPosition.subtractToRef(this._oldPositionForCollisions, this._diffPositionForCollisions);
 
             if (this._diffPositionForCollisions.length() > Engine.CollisionsEpsilon) {

+ 0 - 1
src/Tools/sceneSerializer.ts

@@ -152,7 +152,6 @@ import { SerializationHelper } from "./decorators";
             serializationObject.ambientColor = scene.ambientColor.asArray();
             serializationObject.gravity = scene.gravity.asArray();
             serializationObject.collisionsEnabled = scene.collisionsEnabled;
-            serializationObject.workerCollisions = scene.workerCollisions;
 
             // Fog
             if (scene.fogMode && scene.fogMode !== 0) {

+ 6 - 7
src/scene.ts

@@ -33,7 +33,7 @@ import { AnimationPropertiesOverride } from "Animations/animationPropertiesOverr
 import { Light } from "Lights/light";
 import { PickingInfo } from "Collisions/pickingInfo";
 import { Collider } from "Collisions/collider";
-import { ICollisionCoordinator, CollisionWorker, CollisionCoordinatorWorker, CollisionCoordinatorLegacy } from "Collisions/collisionCoordinator";
+import { ICollisionCoordinator, CollisionCoordinatorLegacy } from "Collisions/collisionCoordinator";
 import { PointerEventTypes, PointerInfoPre, PointerInfo } from "Events/pointerEvents";
 import { KeyboardInfoPre, KeyboardInfo, KeyboardEventTypes } from "Events/keyboardEvents";
 import { ActionManager, ActionEvent } from "Actions/actionManager";
@@ -919,7 +919,7 @@ import { Constants } from "Engine/constants";
         * @see http://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity
         */
         public collisionsEnabled = true;
-        private _workerCollisions: boolean;
+
         /** @hidden */
         public collisionCoordinator: ICollisionCoordinator;
         /**
@@ -1369,14 +1369,11 @@ import { Constants } from "Engine/constants";
                 return;
             }
 
-            enabled = (enabled && !!Worker && !!CollisionWorker);
-
-            this._workerCollisions = enabled;
             if (this.collisionCoordinator) {
                 this.collisionCoordinator.destroy();
             }
 
-            this.collisionCoordinator = enabled ? new CollisionCoordinatorWorker() : new CollisionCoordinatorLegacy();
+            this.collisionCoordinator = new CollisionCoordinatorLegacy();
 
             this.collisionCoordinator.init(this);
         }
@@ -1386,7 +1383,9 @@ import { Constants } from "Engine/constants";
          * @see http://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity#web-worker-based-collision-system-since-21
          */
         public get workerCollisions(): boolean {
-            return this._workerCollisions;
+            // Worker has been deprecated.
+            // Keep for back compat.
+            return false;
         }
 
         /**