Przeglądaj źródła

Merge pull request #5603 from TrevorDev/ammoMotor

ammo motor
David Catuhe 6 lat temu
rodzic
commit
1f70229da5

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

@@ -74,7 +74,7 @@
 - Added support for overriding the mesh used for the world matrix for a mesh with a skeleton ([bghgary](https://github.com/bghgary))
 - Added support for linking a bone to a transform node ([bghgary](https://github.com/bghgary))
 - Factored out `setDirection` function from `lookAt` for transform node ([bghgary](https://github.com/bghgary))
-- Added support for AmmoJS as a physics plugin ([TrevorDev](https://github.com/TrevorDev))
+- Added support for AmmoJS as a physics plugin (Composite objects, joints, motors) ([TrevorDev](https://github.com/TrevorDev))
 - Add support for setting renderingGroupId and creating instances to `AxesViewer` ([bghgary](https://github.com/bghgary))
 - Invert vScale of compressed ktx textures as they are inverted in the file and UNPACK_FLIP_Y_WEBGL is not supported by ktx ([TrevorDev](https://github.com/TrevorDev))
 

+ 20 - 1
src/Physics/Plugins/babylon.ammoJSPlugin.ts

@@ -306,6 +306,25 @@ module BABYLON {
 
             var joint: any;
             switch (impostorJoint.joint.type) {
+                case PhysicsJoint.DistanceJoint:
+                    var distance = (<DistanceJointData>jointData).maxDistance;
+                    if (distance) {
+                        jointData.mainPivot = new Vector3(0, -distance / 2, 0);
+                        jointData.connectedPivot = new Vector3(0, distance / 2, 0);
+                    }
+                    joint = new Ammo.btPoint2PointConstraint(mainBody, connectedBody, new Ammo.btVector3(jointData.mainPivot.x, jointData.mainPivot.y, jointData.mainPivot.z), new Ammo.btVector3(jointData.connectedPivot.x, jointData.connectedPivot.y, jointData.connectedPivot.z));
+                    break;
+                case PhysicsJoint.HingeJoint:
+                    if (!jointData.mainAxis) {
+                        jointData.mainAxis = new Vector3(0, 0, 0);
+                    }
+                    if (!jointData.connectedAxis) {
+                        jointData.connectedAxis = new Vector3(0, 0, 0);
+                    }
+                    var mainAxis = new Ammo.btVector3(jointData.mainAxis.x, jointData.mainAxis.y, jointData.mainAxis.z);
+                    var connectedAxis = new Ammo.btVector3(jointData.connectedAxis.x, jointData.connectedAxis.y, jointData.connectedAxis.z);
+                    joint = new Ammo.btHingeConstraint(mainBody, connectedBody, new Ammo.btVector3(jointData.mainPivot.x, jointData.mainPivot.y, jointData.mainPivot.z), new Ammo.btVector3(jointData.connectedPivot.x, jointData.connectedPivot.y, jointData.connectedPivot.z), mainAxis, connectedAxis);
+                    break;
                 case PhysicsJoint.BallAndSocketJoint:
                     joint = new Ammo.btPoint2PointConstraint(mainBody, connectedBody, new Ammo.btVector3(jointData.mainPivot.x, jointData.mainPivot.y, jointData.mainPivot.z), new Ammo.btVector3(jointData.connectedPivot.x, jointData.connectedPivot.y, jointData.connectedPivot.z));
                     break;
@@ -656,7 +675,7 @@ module BABYLON {
          * @param motorIndex index of the motor
          */
         public setMotor(joint: IMotorEnabledJoint, speed?: number, maxForce?: number, motorIndex?: number) {
-            Tools.Warn("setMotor is not currently supported by the Ammo physics plugin");
+            joint.physicsJoint.enableAngularMotor(true, speed, maxForce);
         }
 
         /**