Browse Source

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe 7 years ago
parent
commit
36a1241735
2 changed files with 10 additions and 11 deletions
  1. 9 11
      src/Physics/babylon.physicsHelper.ts
  2. 1 0
      what's new.md

+ 9 - 11
src/Physics/babylon.physicsHelper.ts

@@ -197,18 +197,17 @@ module BABYLON {
             if (!this._intersectsWithSphere(impostor, origin, radius)) {
                 return null;
             }
-            
-            if (impostor.object.getClassName() !== 'Mesh') {
+  
+            if (impostor.object.getClassName() !== 'Mesh' && impostor.object.getClassName() !== 'InstancedMesh') {
                 return null;
             }
 
-            var impostorObject = <Mesh>impostor.object;
             var impostorObjectCenter = impostor.getObjectCenter();
             var direction = impostorObjectCenter.subtract(origin);
 
             var ray = new Ray(origin, direction, radius);
             this._rays.push(ray);
-            var hit = ray.intersectsMesh(impostorObject);
+            var hit = ray.intersectsMesh(<AbstractMesh>impostor.object);
 
             var contactPoint = hit.pickedPoint;
             if (!contactPoint) {
@@ -255,7 +254,7 @@ module BABYLON {
         }
 
         private _intersectsWithSphere(impostor: PhysicsImpostor, origin: Vector3, radius: number): boolean {
-            var impostorObject = <Mesh>impostor.object;
+            var impostorObject = <AbstractMesh>impostor.object;
 
             this._prepareSphere();
 
@@ -468,7 +467,7 @@ module BABYLON {
         }
 
         private _intersectsWithCylinder(impostor: PhysicsImpostor): boolean {
-            var impostorObject = <Mesh>impostor.object;
+            var impostorObject = <AbstractMesh>impostor.object;
 
             this._prepareCylinder();
 
@@ -553,18 +552,17 @@ module BABYLON {
             if (!this._intersectsWithCylinder(impostor)) {
                 return null;
             }
-            
-            if (impostor.object.getClassName() !== 'Mesh') {
+
+            if (impostor.object.getClassName() !== 'Mesh' && impostor.object.getClassName() !== 'InstancedMesh') {
                 return null;
             }
 
-            var impostorObject = <Mesh>impostor.object;
             var impostorObjectCenter = impostor.getObjectCenter();
             var originOnPlane = new Vector3(this._origin.x, impostorObjectCenter.y, this._origin.z); // the distance to the origin as if both objects were on a plane (Y-axis)
             var originToImpostorDirection = impostorObjectCenter.subtract(originOnPlane);
 
             var ray = new Ray(originOnPlane, originToImpostorDirection, this._radius);
-            var hit = ray.intersectsMesh(impostorObject);
+            var hit = ray.intersectsMesh(<AbstractMesh>impostor.object);
             var contactPoint = hit.pickedPoint;
             if (!contactPoint) {
                 return null;
@@ -618,7 +616,7 @@ module BABYLON {
         }
 
         private _intersectsWithCylinder(impostor: PhysicsImpostor): boolean {
-            var impostorObject = <Mesh>impostor.object;
+            var impostorObject = <AbstractMesh>impostor.object;
 
             this._prepareCylinder();
 

+ 1 - 0
what's new.md

@@ -81,6 +81,7 @@
 - Fixed a bug with impostor jitter when in VR. ([RaananW](https://github.com/RaananW))
 - Fixed a bug with GUI Slider not working correctly when rotated ([adam](https://github.com/abow))
 - Fixed IE11 "spacebar" bug with GUI InputText ([adam](https://github.com/abow))
+- Fixed a bug where instanced meshes did not work with physics helper effects ([bobalazek](https://github.com/bobalazek))
 
 ## Breaking changes