Bläddra i källkod

Merge pull request #6455 from CedricGuillemet/ellipsoidAmmoJS

Update Ammo.js library and AmmoJS plugin to support ellipsoid
Cedric Guillemet 6 år sedan
förälder
incheckning
ee1def0a56
4 ändrade filer med 92 tillägg och 81 borttagningar
  1. 40 40
      dist/ammo.js
  2. 40 40
      dist/preview release/ammo.js
  3. 1 0
      dist/preview release/what's new.md
  4. 11 1
      src/Physics/Plugins/ammoJSPlugin.ts

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 40 - 40
dist/ammo.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 40 - 40
dist/preview release/ammo.js


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

@@ -48,6 +48,7 @@
 ### Physics
 - Update Ammo.js library to support global collision contact callbacks ([MackeyK24](https://github.com/MackeyK24/))
 - Update AmmoJSPlugin to allow your own broadphase overlapping pair cache ([MackeyK24](https://github.com/MackeyK24/))
+- Update Ammo.js library and AmmoJS plugin to support ellipsoid ([CedricGuillemet](https://github.com/CedricGuillemet/)) 
 
 ### Loaders
 - Added support for non-float accessors in animation data for glTF loader. ([bghgary](https://github.com/bghgary))

+ 11 - 1
src/Physics/Plugins/ammoJSPlugin.ts

@@ -12,6 +12,7 @@ import { ShapeBuilder } from "../../Meshes/Builders/shapeBuilder";
 import { LinesBuilder } from "../../Meshes/Builders/linesBuilder";
 import { LinesMesh } from '../../Meshes/linesMesh';
 import { PhysicsRaycastResult } from "../physicsRaycastResult";
+import { Scalar } from "../../Maths/math.scalar";
 
 declare var Ammo: any;
 
@@ -900,7 +901,16 @@ export class AmmoJSPlugin implements IPhysicsEnginePlugin {
 
         switch (impostor.type) {
             case PhysicsImpostor.SphereImpostor:
-                returnValue = new Ammo.btSphereShape(extendSize.x / 2);
+                // Is there a better way to compare floats number? With an epsylon or with a Math function
+                if (Scalar.WithinEpsilon(extendSize.x, extendSize.y, 0.0001) && Scalar.WithinEpsilon(extendSize.x, extendSize.z, 0.0001)) {
+                    returnValue = new Ammo.btSphereShape(extendSize.x / 2);
+                } else {
+                    // create a btMultiSphereShape because it's not possible to set a local scaling on a btSphereShape
+                    var positions = [new Ammo.btVector3(0, 0, 0)];
+                    var radii = [1];
+                    returnValue = new Ammo.btMultiSphereShape(positions, radii, 1);
+                    returnValue.setLocalScaling(new Ammo.btVector3(extendSize.x / 2, extendSize.y / 2, extendSize.z / 2));
+                }
                 break;
             case PhysicsImpostor.CylinderImpostor:
                 this._tmpAmmoVectorA.setValue(extendSize.x / 2, extendSize.y / 2, extendSize.z / 2);