Browse Source

Exposing Collider on mesh

David Catuhe 7 years ago
parent
commit
366b5b9cb2

File diff suppressed because it is too large
+ 6083 - 6068
dist/preview release/babylon.d.ts


+ 1 - 0
dist/preview release/what's new.md

@@ -30,6 +30,7 @@
 ## Updates
 
 - Introduced `TransformNode` class as a parent of `AbstractMesh`. This class was extensively asked by the community to hold only tranformation for a node ([deltakosh](https://github.com/deltakosh))
+- Collider object is now exposed on meshes. It can be used to get precise information about mesh to mesh collisions (used with mesh.moveWithCollisions function) ([deltakosh](https://github.com/deltakosh))
 - Added `boundingInfo.centerOn` to recreate the bounding info to be centered around a specific point given a specific extend ([deltakosh](https://github.com/deltakosh))
 - Added `mesh.normalizeToUnitCube` to uniformly scales the mesh to fit inside of a unit cube (1 X 1 X 1 units) ([deltakosh](https://github.com/deltakosh))
 - Added `scene.onDataLoadedObservable` which is raised when SceneLoader.Append or SceneLoader.Load or SceneLoader.ImportMesh were successfully executed ([deltakosh](https://github.com/deltakosh))

+ 2 - 2
src/Cameras/babylon.arcRotateCamera.ts

@@ -657,7 +657,7 @@
                 if (!this._collider) {
                     this._collider = new Collider();
                 }
-                this._collider.radius = this.collisionRadius;
+                this._collider._radius = this.collisionRadius;
                 this._newPosition.subtractToRef(this.position, this._collisionVelocity);
                 this._collisionTriggered = true;
                 this.getScene().collisionCoordinator.getNewPosition(this.position, this._collisionVelocity, this._collider, 3, null, this._onCollisionPositionChange, this.uniqueId);
@@ -685,7 +685,7 @@
         protected _onCollisionPositionChange = (collisionId: number, newPosition: Vector3, collidedMesh: Nullable<AbstractMesh> = null) => {
 
             if (this.getScene().workerCollisions && this.checkCollisions) {
-                newPosition.multiplyInPlace(this._collider.radius);
+                newPosition.multiplyInPlace(this._collider._radius);
             }
 
             if (!collidedMesh) {

+ 31 - 31
src/Cameras/babylon.freeCamera.ts

@@ -1,5 +1,5 @@
 module BABYLON {
-    export class FreeCamera extends TargetCamera {        
+    export class FreeCamera extends TargetCamera {
         @serializeAsVector3()
         public ellipsoid = new Vector3(0.5, 1, 0.5);
 
@@ -8,9 +8,9 @@
 
         @serialize()
         public applyGravity = false;
-                
-        public inputs : FreeCameraInputsManager;
-        
+
+        public inputs: FreeCameraInputsManager;
+
         //-- begin properties for backward compatibility for inputs
         public get angularSensibility(): number {
             var mouse = <FreeCameraMouseInput>this.inputs.attached["mouse"];
@@ -19,13 +19,13 @@
 
             return 0;
         }
-        
+
         public set angularSensibility(value: number) {
             var mouse = <FreeCameraMouseInput>this.inputs.attached["mouse"];
             if (mouse)
                 mouse.angularSensibility = value;
         }
-        
+
         public get keysUp(): number[] {
             var keyboard = <FreeCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
             if (keyboard)
@@ -33,13 +33,13 @@
 
             return [];
         }
-        
+
         public set keysUp(value: number[]) {
             var keyboard = <FreeCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
             if (keyboard)
                 keyboard.keysUp = value;
         }
-        
+
         public get keysDown(): number[] {
             var keyboard = <FreeCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
             if (keyboard)
@@ -47,13 +47,13 @@
 
             return [];
         }
-        
+
         public set keysDown(value: number[]) {
             var keyboard = <FreeCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
             if (keyboard)
                 keyboard.keysDown = value;
         }
-        
+
         public get keysLeft(): number[] {
             var keyboard = <FreeCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
             if (keyboard)
@@ -61,13 +61,13 @@
 
             return [];
         }
-        
+
         public set keysLeft(value: number[]) {
             var keyboard = <FreeCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
             if (keyboard)
                 keyboard.keysLeft = value;
         }
-        
+
         public get keysRight(): number[] {
             var keyboard = <FreeCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
             if (keyboard)
@@ -75,55 +75,55 @@
 
             return [];
         }
-        
+
         public set keysRight(value: number[]) {
             var keyboard = <FreeCameraKeyboardMoveInput>this.inputs.attached["keyboard"];
             if (keyboard)
                 keyboard.keysRight = value;
         }
-        
+
         //-- end properties for backward compatibility for inputs
-        
+
         public onCollide: (collidedMesh: AbstractMesh) => void;
-        
+
         private _collider: Collider;
         private _needMoveForGravity = false;
         private _oldPosition = Vector3.Zero();
         private _diffPosition = Vector3.Zero();
         private _newPosition = Vector3.Zero();
-        
+
         public _localDirection: Vector3;
-        public _transformedDirection: Vector3;        
-        
+        public _transformedDirection: Vector3;
+
         constructor(name: string, position: Vector3, scene: Scene) {
             super(name, position, scene);
             this.inputs = new FreeCameraInputsManager(this);
             this.inputs.addKeyboard().addMouse();
-        }     
+        }
 
         // Controls
         public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
             this.inputs.attachElement(element, noPreventDefault);
-        }        
+        }
 
         public detachControl(element: HTMLElement): void {
             this.inputs.detachElement(element);
-            
+
             this.cameraDirection = new Vector3(0, 0, 0);
             this.cameraRotation = new Vector2(0, 0);
         }
 
         // Collisions
         private _collisionMask = -1;
-        
+
         public get collisionMask(): number {
             return this._collisionMask;
         }
-        
+
         public set collisionMask(mask: number) {
             this._collisionMask = !isNaN(mask) ? mask : -1;
         }
-	 
+
         public _collideWithWorld(displacement: Vector3): void {
             var globalPosition: Vector3;
 
@@ -139,12 +139,12 @@
                 this._collider = new Collider();
             }
 
-            this._collider.radius = this.ellipsoid;
+            this._collider._radius = this.ellipsoid;
             this._collider.collisionMask = this._collisionMask;
-		
+
             //no need for clone, as long as gravity is not on.
             var actualDisplacement = displacement;
-			
+
             //add gravity to the direction to prevent the dual-collision checking
             if (this.applyGravity) {
                 //this prevents mending with cameraDirection, a global variable of the free camera class.
@@ -158,7 +158,7 @@
         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.multiplyInPlace(this._collider._radius);
 
             var updatePosition = (newPos: Vector3) => {
                 this._newPosition.copyFrom(newPos);
@@ -203,9 +203,9 @@
             this.inputs.clear();
             super.dispose();
         }
-        
+
         public getClassName(): string {
             return "FreeCamera";
         }
-    }    
+    }
 } 

+ 70 - 53
src/Collisions/babylon.collider.ts

@@ -55,23 +55,20 @@
                 return result;
             }
         }
-    )();
+        )();
 
     export class Collider {
-        public radius = Vector3.One();
-        public retry = 0;
-        public velocity: Vector3;
-        public basePoint: Vector3;
-        public epsilon: number;
+        /** Define if a collision was found */
         public collisionFound: boolean;
-        public velocityWorldLength: number;
-        public basePointWorld = Vector3.Zero();
-        public velocityWorld = Vector3.Zero();
-        public normalizedVelocity = Vector3.Zero();
-        public initialVelocity: Vector3;
-        public initialPosition: Vector3;
-        public nearestDistance: number;
+
+        /**
+         * Define last intersection point in local space
+         */
         public intersectionPoint: Vector3;
+
+        /**
+         * Define last collided mesh
+         */
         public collidedMesh: Nullable<AbstractMesh>;
 
         private _collisionPoint = Vector3.Zero();
@@ -86,28 +83,48 @@
         private _slidePlaneNormal = Vector3.Zero();
         private _displacementVector = Vector3.Zero();
 
+        public _radius = Vector3.One();
+        public _retry = 0;
+        private _velocity: Vector3;
+        private _basePoint: Vector3;
+        private _epsilon: number;
+        public _velocityWorldLength: number;
+        public _basePointWorld = Vector3.Zero();
+        private _velocityWorld = Vector3.Zero();
+        private _normalizedVelocity = Vector3.Zero();
+        public _initialVelocity: Vector3;
+        public _initialPosition: Vector3;
+        private _nearestDistance: number;
+
         private _collisionMask = -1;
-        
+
         public get collisionMask(): number {
             return this._collisionMask;
         }
-        
+
         public set collisionMask(mask: number) {
             this._collisionMask = !isNaN(mask) ? mask : -1;
         }
 
+        /**
+         * Gets the plane normal used to compute the sliding response (in local space)
+         */
+        public get slidePlaneNormal(): Vector3 {
+            return this._slidePlaneNormal;
+        }
+
         // Methods
         public _initialize(source: Vector3, dir: Vector3, e: number): void {
-            this.velocity = dir;
-            Vector3.NormalizeToRef(dir, this.normalizedVelocity);
-            this.basePoint = source;
+            this._velocity = dir;
+            Vector3.NormalizeToRef(dir, this._normalizedVelocity);
+            this._basePoint = source;
 
-            source.multiplyToRef(this.radius, this.basePointWorld);
-            dir.multiplyToRef(this.radius, this.velocityWorld);
+            source.multiplyToRef(this._radius, this._basePointWorld);
+            dir.multiplyToRef(this._radius, this._velocityWorld);
 
-            this.velocityWorldLength = this.velocityWorld.length();
+            this._velocityWorldLength = this._velocityWorld.length();
 
-            this.epsilon = e;
+            this._epsilon = e;
             this.collisionFound = false;
         }
 
@@ -132,15 +149,15 @@
         }
 
         public _canDoCollision(sphereCenter: Vector3, sphereRadius: number, vecMin: Vector3, vecMax: Vector3): boolean {
-            var distance = Vector3.Distance(this.basePointWorld, sphereCenter);
+            var distance = Vector3.Distance(this._basePointWorld, sphereCenter);
 
-            var max = Math.max(this.radius.x, this.radius.y, this.radius.z);
+            var max = Math.max(this._radius.x, this._radius.y, this._radius.z);
 
-            if (distance > this.velocityWorldLength + max + sphereRadius) {
+            if (distance > this._velocityWorldLength + max + sphereRadius) {
                 return false;
             }
 
-            if (!intersectBoxAASphere(vecMin, vecMax, this.basePointWorld, this.velocityWorldLength + max))
+            if (!intersectBoxAASphere(vecMin, vecMax, this._basePointWorld, this._velocityWorldLength + max))
                 return false;
 
             return true;
@@ -162,11 +179,11 @@
 
             var trianglePlane = trianglePlaneArray[faceIndex];
 
-            if ((!hasMaterial) && !trianglePlane.isFrontFacingTo(this.normalizedVelocity, 0))
+            if ((!hasMaterial) && !trianglePlane.isFrontFacingTo(this._normalizedVelocity, 0))
                 return;
 
-            var signedDistToTrianglePlane = trianglePlane.signedDistanceTo(this.basePoint);
-            var normalDotVelocity = Vector3.Dot(trianglePlane.normal, this.velocity);
+            var signedDistToTrianglePlane = trianglePlane.signedDistanceTo(this._basePoint);
+            var normalDotVelocity = Vector3.Dot(trianglePlane.normal, this._velocity);
 
             if (normalDotVelocity == 0) {
                 if (Math.abs(signedDistToTrianglePlane) >= 1.0)
@@ -199,8 +216,8 @@
             var t = 1.0;
 
             if (!embeddedInPlane) {
-                this.basePoint.subtractToRef(trianglePlane.normal, this._planeIntersectionPoint);
-                this.velocity.scaleToRef(t0, this._tempVector);
+                this._basePoint.subtractToRef(trianglePlane.normal, this._planeIntersectionPoint);
+                this._velocity.scaleToRef(t0, this._tempVector);
                 this._planeIntersectionPoint.addInPlace(this._tempVector);
 
                 if (this._checkPointInTriangle(this._planeIntersectionPoint, p1, p2, p3, trianglePlane.normal)) {
@@ -211,12 +228,12 @@
             }
 
             if (!found) {
-                var velocitySquaredLength = this.velocity.lengthSquared();
+                var velocitySquaredLength = this._velocity.lengthSquared();
 
                 var a = velocitySquaredLength;
 
-                this.basePoint.subtractToRef(p1, this._tempVector);
-                var b = 2.0 * (Vector3.Dot(this.velocity, this._tempVector));
+                this._basePoint.subtractToRef(p1, this._tempVector);
+                var b = 2.0 * (Vector3.Dot(this._velocity, this._tempVector));
                 var c = this._tempVector.lengthSquared() - 1.0;
 
                 var lowestRoot = getLowestRoot(a, b, c, t);
@@ -226,8 +243,8 @@
                     this._collisionPoint.copyFrom(p1);
                 }
 
-                this.basePoint.subtractToRef(p2, this._tempVector);
-                b = 2.0 * (Vector3.Dot(this.velocity, this._tempVector));
+                this._basePoint.subtractToRef(p2, this._tempVector);
+                b = 2.0 * (Vector3.Dot(this._velocity, this._tempVector));
                 c = this._tempVector.lengthSquared() - 1.0;
 
                 lowestRoot = getLowestRoot(a, b, c, t);
@@ -237,8 +254,8 @@
                     this._collisionPoint.copyFrom(p2);
                 }
 
-                this.basePoint.subtractToRef(p3, this._tempVector);
-                b = 2.0 * (Vector3.Dot(this.velocity, this._tempVector));
+                this._basePoint.subtractToRef(p3, this._tempVector);
+                b = 2.0 * (Vector3.Dot(this._velocity, this._tempVector));
                 c = this._tempVector.lengthSquared() - 1.0;
 
                 lowestRoot = getLowestRoot(a, b, c, t);
@@ -249,13 +266,13 @@
                 }
 
                 p2.subtractToRef(p1, this._edge);
-                p1.subtractToRef(this.basePoint, this._baseToVertex);
+                p1.subtractToRef(this._basePoint, this._baseToVertex);
                 var edgeSquaredLength = this._edge.lengthSquared();
-                var edgeDotVelocity = Vector3.Dot(this._edge, this.velocity);
+                var edgeDotVelocity = Vector3.Dot(this._edge, this._velocity);
                 var edgeDotBaseToVertex = Vector3.Dot(this._edge, this._baseToVertex);
 
                 a = edgeSquaredLength * (-velocitySquaredLength) + edgeDotVelocity * edgeDotVelocity;
-                b = edgeSquaredLength * (2.0 * Vector3.Dot(this.velocity, this._baseToVertex)) - 2.0 * edgeDotVelocity * edgeDotBaseToVertex;
+                b = edgeSquaredLength * (2.0 * Vector3.Dot(this._velocity, this._baseToVertex)) - 2.0 * edgeDotVelocity * edgeDotBaseToVertex;
                 c = edgeSquaredLength * (1.0 - this._baseToVertex.lengthSquared()) + edgeDotBaseToVertex * edgeDotBaseToVertex;
 
                 lowestRoot = getLowestRoot(a, b, c, t);
@@ -271,13 +288,13 @@
                 }
 
                 p3.subtractToRef(p2, this._edge);
-                p2.subtractToRef(this.basePoint, this._baseToVertex);
+                p2.subtractToRef(this._basePoint, this._baseToVertex);
                 edgeSquaredLength = this._edge.lengthSquared();
-                edgeDotVelocity = Vector3.Dot(this._edge, this.velocity);
+                edgeDotVelocity = Vector3.Dot(this._edge, this._velocity);
                 edgeDotBaseToVertex = Vector3.Dot(this._edge, this._baseToVertex);
 
                 a = edgeSquaredLength * (-velocitySquaredLength) + edgeDotVelocity * edgeDotVelocity;
-                b = edgeSquaredLength * (2.0 * Vector3.Dot(this.velocity, this._baseToVertex)) - 2.0 * edgeDotVelocity * edgeDotBaseToVertex;
+                b = edgeSquaredLength * (2.0 * Vector3.Dot(this._velocity, this._baseToVertex)) - 2.0 * edgeDotVelocity * edgeDotBaseToVertex;
                 c = edgeSquaredLength * (1.0 - this._baseToVertex.lengthSquared()) + edgeDotBaseToVertex * edgeDotBaseToVertex;
                 lowestRoot = getLowestRoot(a, b, c, t);
                 if (lowestRoot.found) {
@@ -292,13 +309,13 @@
                 }
 
                 p1.subtractToRef(p3, this._edge);
-                p3.subtractToRef(this.basePoint, this._baseToVertex);
+                p3.subtractToRef(this._basePoint, this._baseToVertex);
                 edgeSquaredLength = this._edge.lengthSquared();
-                edgeDotVelocity = Vector3.Dot(this._edge, this.velocity);
+                edgeDotVelocity = Vector3.Dot(this._edge, this._velocity);
                 edgeDotBaseToVertex = Vector3.Dot(this._edge, this._baseToVertex);
 
                 a = edgeSquaredLength * (-velocitySquaredLength) + edgeDotVelocity * edgeDotVelocity;
-                b = edgeSquaredLength * (2.0 * Vector3.Dot(this.velocity, this._baseToVertex)) - 2.0 * edgeDotVelocity * edgeDotBaseToVertex;
+                b = edgeSquaredLength * (2.0 * Vector3.Dot(this._velocity, this._baseToVertex)) - 2.0 * edgeDotVelocity * edgeDotBaseToVertex;
                 c = edgeSquaredLength * (1.0 - this._baseToVertex.lengthSquared()) + edgeDotBaseToVertex * edgeDotBaseToVertex;
 
                 lowestRoot = getLowestRoot(a, b, c, t);
@@ -315,15 +332,15 @@
             }
 
             if (found) {
-                var distToCollision = t * this.velocity.length();
+                var distToCollision = t * this._velocity.length();
 
-                if (!this.collisionFound || distToCollision < this.nearestDistance) {
+                if (!this.collisionFound || distToCollision < this._nearestDistance) {
                     if (!this.intersectionPoint) {
                         this.intersectionPoint = this._collisionPoint.clone();
                     } else {
                         this.intersectionPoint.copyFrom(this._collisionPoint);
                     }
-                    this.nearestDistance = distToCollision;
+                    this._nearestDistance = distToCollision;
                     this.collisionFound = true;
                 }
             }
@@ -341,12 +358,12 @@
 
         public _getResponse(pos: Vector3, vel: Vector3): void {
             pos.addToRef(vel, this._destinationPoint);
-            vel.scaleInPlace((this.nearestDistance / vel.length()));
+            vel.scaleInPlace((this._nearestDistance / vel.length()));
 
-            this.basePoint.addToRef(vel, pos);
+            this._basePoint.addToRef(vel, pos);
             pos.subtractToRef(this.intersectionPoint, this._slidePlaneNormal);
             this._slidePlaneNormal.normalize();
-            this._slidePlaneNormal.scaleToRef(this.epsilon, this._displacementVector);
+            this._slidePlaneNormal.scaleToRef(this._epsilon, this._displacementVector);
 
             pos.addInPlace(this._displacementVector);
             this.intersectionPoint.addInPlace(this._displacementVector);

+ 11 - 11
src/Collisions/babylon.collisionCoordinator.ts

@@ -194,8 +194,8 @@ module BABYLON {
             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);
+            position.divideToRef(collider._radius, this._scaledPosition);
+            displacement.divideToRef(collider._radius, this._scaledVelocity);
 
             this._collisionsCallbackArray[collisionIndex] = onNewPosition;
 
@@ -203,7 +203,7 @@ module BABYLON {
                 collider: {
                     position: this._scaledPosition.asArray(),
                     velocity: this._scaledVelocity.asArray(),
-                    radius: collider.radius.asArray()
+                    radius: collider._radius.asArray()
                 },
                 collisionId: collisionIndex,
                 excludedMeshUniqueId: excludedMesh ? excludedMesh.uniqueId : null,
@@ -360,15 +360,15 @@ module BABYLON {
         private _finalPosition = Vector3.Zero();
 
         public getNewPosition(position: Vector3, displacement: Vector3, collider: Collider, maximumRetry: number, excludedMesh: AbstractMesh, onNewPosition: (collisionIndex: number, newPosition: Vector3, collidedMesh: Nullable<AbstractMesh>) => void, collisionIndex: number): void {
-            position.divideToRef(collider.radius, this._scaledPosition);
-            displacement.divideToRef(collider.radius, this._scaledVelocity);
+            position.divideToRef(collider._radius, this._scaledPosition);
+            displacement.divideToRef(collider._radius, this._scaledVelocity);
             collider.collidedMesh = null;
-            collider.retry = 0;
-            collider.initialVelocity = this._scaledVelocity;
-            collider.initialPosition = this._scaledPosition;
+            collider._retry = 0;
+            collider._initialVelocity = this._scaledVelocity;
+            collider._initialPosition = this._scaledPosition;
             this._collideWithWorld(this._scaledPosition, this._scaledVelocity, collider, maximumRetry, this._finalPosition, excludedMesh);
 
-            this._finalPosition.multiplyInPlace(collider.radius);
+            this._finalPosition.multiplyInPlace(collider._radius);
             //run the callback
             onNewPosition(collisionIndex, this._finalPosition, collider.collidedMesh);
         }
@@ -392,7 +392,7 @@ module BABYLON {
         private _collideWithWorld(position: Vector3, velocity: Vector3, collider: Collider, maximumRetry: number, finalPosition: Vector3, excludedMesh: Nullable<AbstractMesh> = null): void {
             var closeDistance = Engine.CollisionsEpsilon * 10.0;
 
-            if (collider.retry >= maximumRetry) {
+            if (collider._retry >= maximumRetry) {
                 finalPosition.copyFrom(position);
                 return;
             }
@@ -424,7 +424,7 @@ module BABYLON {
                 return;
             }
 
-            collider.retry++;
+            collider._retry++;
             this._collideWithWorld(position, velocity, collider, maximumRetry, finalPosition, excludedMesh);
         }
     }

+ 14 - 14
src/Collisions/babylon.collisionWorker.ts

@@ -55,7 +55,7 @@ module BABYLON {
 
             //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) {
+            if (this.collider._retry >= maximumRetry) {
                 this.finalPosition.copyFrom(position);
                 return;
             }
@@ -91,7 +91,7 @@ module BABYLON {
                 return;
             }
 
-            this.collider.retry++;
+            this.collider._retry++;
             this.collideWithWorld(position, velocity, maximumRetry, excludedMeshUniqueId);
         }
 
@@ -102,7 +102,7 @@ module BABYLON {
             };
 
             // Transformation matrix
-            Matrix.ScalingToRef(1.0 / this.collider.radius.x, 1.0 / this.collider.radius.y, 1.0 / this.collider.radius.z, this.collisionsScalingMatrix);
+            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);
 
@@ -165,7 +165,7 @@ module BABYLON {
                 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);
@@ -233,7 +233,7 @@ module BABYLON {
             var finalPosition = Vector3.Zero();
             //create a new collider
             var collider = new Collider();
-            collider.radius = Vector3.FromArray(payload.collider.radius);
+            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);
@@ -273,15 +273,15 @@ module BABYLON {
             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;
+                    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;
                 }
             }
 

+ 26 - 19
src/Mesh/babylon.abstractMesh.ts

@@ -42,12 +42,12 @@
             Y: 1,
             Z: 1
         };
-      
+
         private _facetDepthSort: boolean = false;                           // is the facet depth sort to be computed
         private _facetDepthSortEnabled: boolean = false;                    // is the facet depth sort initialized
         private _depthSortedIndices: IndicesArray;                          // copy of the indices array to store them once sorted
-        private _depthSortedFacets: {ind: number, sqDistance: number}[];    // array of depth sorted facets
-        private _facetDepthSortFunction: (f1: {ind: number, sqDistance: number}, f2: {ind: number, sqDistance: number}) => number;  // facet depth sort function
+        private _depthSortedFacets: { ind: number, sqDistance: number }[];    // array of depth sorted facets
+        private _facetDepthSortFunction: (f1: { ind: number, sqDistance: number }, f2: { ind: number, sqDistance: number }) => number;  // facet depth sort function
         private _facetDepthSortFrom: Vector3;                               // location where to depth sort from
         private _facetDepthSortOrigin: Vector3;                             // same as facetDepthSortFrom but expressed in the mesh local space
         private _invertedMatrix: Matrix;                                    // Mesh inverted World Matrix
@@ -1064,6 +1064,13 @@
             }
         }
 
+        /**
+         * Gets Collider object used to compute collisions (not physics)
+         */
+        public get collider(): Collider {
+            return this._collider;
+        }
+
         public moveWithCollisions(displacement: Vector3): AbstractMesh {
             var globalPosition = this.getAbsolutePosition();
 
@@ -1074,7 +1081,7 @@
                 this._collider = new Collider();
             }
 
-            this._collider.radius = this.ellipsoid;
+            this._collider._radius = this.ellipsoid;
 
             this.getScene().collisionCoordinator.getNewPosition(this._oldPositionForCollisions, displacement, this._collider, 3, this, this._onCollisionPositionChange, this.uniqueId);
             return this;
@@ -1083,7 +1090,7 @@
         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.multiplyInPlace(this._collider._radius);
 
             newPosition.subtractToRef(this._oldPositionForCollisions, this._diffPositionForCollisions);
 
@@ -1154,8 +1161,8 @@
 
             // Octrees
             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);
+                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;
@@ -1182,7 +1189,7 @@
                 return this;
 
             // Transformation matrix
-            Matrix.ScalingToRef(1.0 / collider.radius.x, 1.0 / collider.radius.y, 1.0 / collider.radius.z, this._collisionsScalingMatrix);
+            Matrix.ScalingToRef(1.0 / collider._radius.x, 1.0 / collider._radius.y, 1.0 / collider._radius.z, this._collisionsScalingMatrix);
             this.worldMatrixFromCache.multiplyToRef(this._collisionsScalingMatrix, this._collisionsTransformMatrix);
             this._processCollisionsForSubMeshes(collider, this._collisionsTransformMatrix);
             return this;
@@ -1489,7 +1496,7 @@
                 }
                 else if (indices instanceof Uint32Array) {
                     this._depthSortedIndices = new Uint32Array(indices!);
-                } 
+                }
                 else {
                     var needs32bits = false;
                     for (var i = 0; i < indices!.length; i++) {
@@ -1500,12 +1507,12 @@
                     }
                     if (needs32bits) {
                         this._depthSortedIndices = new Uint32Array(indices!);
-                    } 
+                    }
                     else {
                         this._depthSortedIndices = new Uint16Array(indices!);
                     }
-                }               
-                this._facetDepthSortFunction = function(f1, f2) {
+                }
+                this._facetDepthSortFunction = function (f1, f2) {
                     return (f2.sqDistance - f1.sqDistance);
                 };
                 if (!this._facetDepthSortFrom) {
@@ -1553,7 +1560,7 @@
 
             if (this._facetDepthSort && this._facetDepthSortEnabled) {
                 this._depthSortedFacets.sort(this._facetDepthSortFunction);
-                var l = (this._depthSortedIndices.length / 3)|0;
+                var l = (this._depthSortedIndices.length / 3) | 0;
                 for (var f = 0; f < l; f++) {
                     var sind = this._depthSortedFacets[f].ind;
                     this._depthSortedIndices[f * 3] = indices![sind];
@@ -1782,19 +1789,19 @@
          * Align the mesh with a normal.
          * Returns the mesh.  
          */
-        public alignWithNormal(normal:BABYLON.Vector3, upDirection?:BABYLON.Vector3):AbstractMesh{       
-            if(!upDirection){
+        public alignWithNormal(normal: BABYLON.Vector3, upDirection?: BABYLON.Vector3): AbstractMesh {
+            if (!upDirection) {
                 upDirection = BABYLON.Axis.Y;
             }
-            
+
             var axisX = Tmp.Vector3[0];
             var axisZ = Tmp.Vector3[1];
             Vector3.CrossToRef(upDirection, normal, axisZ);
             Vector3.CrossToRef(normal, axisZ, axisX);
-            
-            if(this.rotationQuaternion){
+
+            if (this.rotationQuaternion) {
                 Quaternion.RotationQuaternionFromAxisToRef(axisX, normal, axisZ, this.rotationQuaternion);
-            }else{
+            } else {
                 Vector3.RotationFromAxisToRef(axisX, normal, axisZ, this.rotation);
             }
             return this;