浏览代码

Merge pull request #5754 from TrevorDev/physicsConsistency

Physics consistency
David Catuhe 6 年之前
父节点
当前提交
e926354dfe
共有 3 个文件被更改,包括 23 次插入2 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 15 2
      src/Physics/Plugins/cannonJSPlugin.ts
  3. 7 0
      src/Physics/Plugins/oimoJSPlugin.ts

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

@@ -149,6 +149,7 @@
 - Fix more case sensitive paths ([mrdunk](https://github.com))
 - Attaching a BoundingBoxGizmo on a child should not remove its parent ([TrevorDev](https://github.com/TrevorDev)))
 - AmmoJS fix include issue caused after modules update and use world contact point to be consistent with oimo and cannon ([TrevorDev](https://github.com/TrevorDev)))
+- Oimo disable motor maxForce, cannonJS support no impostor, cannonJS cylinder axis ([TrevorDev](https://github.com/TrevorDev)))
 - Utility layer should render on last active camera ([TrevorDev](https://github.com/TrevorDev))
 
 ### Core Engine

+ 15 - 2
src/Physics/Plugins/cannonJSPlugin.ts

@@ -271,11 +271,20 @@ export class CannonJSPlugin implements IPhysicsEnginePlugin {
             //TMP also for cylinder - TODO Cannon supports cylinder natively.
             case PhysicsImpostor.CylinderImpostor:
                 let nativeParams = impostor.getParam("nativeOptions");
+                if (!nativeParams) {
+                    nativeParams = {};
+                }
                 let radiusTop = nativeParams.radiusTop !== undefined ? nativeParams.radiusTop : this._checkWithEpsilon(extendSize.x) / 2;
                 let radiusBottom = nativeParams.radiusBottom !== undefined ? nativeParams.radiusBottom : this._checkWithEpsilon(extendSize.x) / 2;
-                let height = nativeParams.height !== undefined ? nativeParams.height : this._checkWithEpsilon(extendSize.y) / 2;
+                let height = nativeParams.height !== undefined ? nativeParams.height : this._checkWithEpsilon(extendSize.y);
                 let numSegments = nativeParams.numSegments !== undefined ? nativeParams.numSegments : 16;
                 returnValue = new this.BJSCANNON.Cylinder(radiusTop, radiusBottom, height, numSegments);
+
+                // Rotate 90 degrees as this shape is horizontal in cannon
+                var quat = new this.BJSCANNON.Quaternion();
+                quat.setFromAxisAngle(new this.BJSCANNON.Vec3(1, 0, 0), -Math.PI / 2);
+                var translation = new this.BJSCANNON.Vec3(0, 0, 0);
+                returnValue.transformAllPoints(translation, quat);
                 break;
             case PhysicsImpostor.BoxImpostor:
                 var box = extendSize.scale(0.5);
@@ -334,6 +343,9 @@ export class CannonJSPlugin implements IPhysicsEnginePlugin {
             case PhysicsImpostor.ParticleImpostor:
                 returnValue = new this.BJSCANNON.Particle();
                 break;
+            case PhysicsImpostor.NoImpostor:
+                returnValue = new this.BJSCANNON.Box(new this.BJSCANNON.Vec3(0, 0, 0));
+                break;
         }
 
         return returnValue;
@@ -430,7 +442,8 @@ export class CannonJSPlugin implements IPhysicsEnginePlugin {
         }
 
         //is shape is a plane or a heightmap, it must be rotated 90 degs in the X axis.
-        if (impostor.type === PhysicsImpostor.PlaneImpostor || impostor.type === PhysicsImpostor.HeightmapImpostor || impostor.type === PhysicsImpostor.CylinderImpostor) {
+        //ideally these would be rotated at time of creation like cylinder but they dont extend ConvexPolyhedron
+        if (impostor.type === PhysicsImpostor.PlaneImpostor || impostor.type === PhysicsImpostor.HeightmapImpostor) {
             //-90 DEG in X, precalculated
             quaternion = quaternion.multiply(this._minus90X);
             //Invert! (Precalculated, 90 deg in X)

+ 7 - 0
src/Physics/Plugins/oimoJSPlugin.ts

@@ -423,6 +423,13 @@ export class OimoJSPlugin implements IPhysicsEnginePlugin {
     }
 
     public setMotor(joint: IMotorEnabledJoint, speed: number, maxForce?: number, motorIndex?: number) {
+        // Keep defaults consistant with other physics plugins
+        if (maxForce !== undefined) {
+            Logger.Warn("OimoJS plugin does not support setMotor with maxForce");
+        }
+        maxForce = 1e6;
+        speed *= -1;
+
         //TODO separate rotational and transational motors.
         var motor = motorIndex ? joint.physicsJoint.rotationalLimitMotor2 : joint.physicsJoint.rotationalLimitMotor1 || joint.physicsJoint.rotationalLimitMotor || joint.physicsJoint.limitMotor;
         if (motor) {