Parcourir la source

moving to oimo 1.0.9

Raanan Weber il y a 7 ans
Parent
commit
d6e99f861d
3 fichiers modifiés avec 23953 ajouts et 24371 suppressions
  1. 11955 12167
      dist/Oimo.js
  2. 11954 12166
      dist/preview release/Oimo.js
  3. 44 38
      src/Physics/Plugins/babylon.oimoJSPlugin.ts

Fichier diff supprimé car celui-ci est trop grand
+ 11955 - 12167
dist/Oimo.js


Fichier diff supprimé car celui-ci est trop grand
+ 11954 - 12166
dist/preview release/Oimo.js


+ 44 - 38
src/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -10,12 +10,11 @@ module BABYLON {
 
 
         constructor(iterations?: number) {
-            this.BJSOIMO = typeof OIMO !== 'undefined' ? OIMO : (typeof require !== 'undefined' ? require('./Oimo') : undefined);
-            this.world = new this.BJSOIMO.World(1 / 60, 2, iterations, true);
-            this.world.worldscale(1);
+            this.BJSOIMO = typeof OIMO !== 'undefined' ? OIMO : (typeof require !== 'undefined' ? require('oimo') : undefined);
+            this.world = new this.BJSOIMO.World({
+                iterations: iterations
+            });
             this.world.clear();
-            //making sure no stats are calculated
-            this.world.isNoStat = true;
         }
 
         public setGravity(gravity: Vector3) {
@@ -71,8 +70,8 @@ module BABYLON {
         }
 
         public applyImpulse(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3) {
-            var mass = impostor.physicsBody.massInfo.mass;
-            impostor.physicsBody.applyImpulse(contactPoint.scale(this.BJSOIMO.INV_SCALE), force.scale(this.BJSOIMO.INV_SCALE * mass));
+            var mass = impostor.physicsBody.mass;
+            impostor.physicsBody.applyImpulse(contactPoint.scale(this.world.invScale), force.scale(this.world.invScale * mass));
         }
         public applyForce(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3) {
             Tools.Warn("Oimo doesn't support applying force. Using impule instead.");
@@ -97,8 +96,13 @@ module BABYLON {
                     size: [],
                     type: [],
                     pos: [],
+                    posShape: [],
                     rot: [],
+                    rotShape: [],
                     move: impostor.getParam("mass") !== 0,
+                    density: impostor.getParam("mass"),
+                    friction: impostor.getParam("friction"),
+                    restitution: impostor.getParam("restitution"),
                     //Supporting older versions of Oimo
                     world: this.world
                 };
@@ -120,21 +124,17 @@ module BABYLON {
                 }
 
                 impostors.forEach((i) => {
-                    if (!impostor.object.rotationQuaternion) {
+                    if (!i.object.rotationQuaternion) {
                         return;
                     }
                     //get the correct bounding box
                     var oldQuaternion = i.object.rotationQuaternion;
-                    var rot = new this.BJSOIMO.Euler().setFromQuaternion({
-                        x: impostor.object.rotationQuaternion.x,
-                        y: impostor.object.rotationQuaternion.y,
-                        z: impostor.object.rotationQuaternion.z,
-                        s: impostor.object.rotationQuaternion.w
-                    });
-
 
+                    var rot = oldQuaternion.toEulerAngles();
                     var extendSize = i.getObjectExtendSize();
 
+                    const radToDeg = 57.295779513082320876;
+
                     if (i === impostor) {
                         var center = impostor.getObjectCenter();
 
@@ -145,27 +145,33 @@ module BABYLON {
                         bodyConfig.pos.push(center.x);
                         bodyConfig.pos.push(center.y);
                         bodyConfig.pos.push(center.z);
+                        bodyConfig.posShape.push(0, 0, 0);
 
                         //tmp solution
-                        bodyConfig.rot.push(rot.x / (this.BJSOIMO.degtorad || this.BJSOIMO.TO_RAD));
-                        bodyConfig.rot.push(rot.y / (this.BJSOIMO.degtorad || this.BJSOIMO.TO_RAD));
-                        bodyConfig.rot.push(rot.z / (this.BJSOIMO.degtorad || this.BJSOIMO.TO_RAD));
+                        bodyConfig.rot.push(rot.x * radToDeg);
+                        bodyConfig.rot.push(rot.y * radToDeg);
+                        bodyConfig.rot.push(rot.z * radToDeg);
+                        bodyConfig.rotShape.push(0, 0, 0);
                     } else {
                         let localPosition = i.object.getAbsolutePosition().subtract(impostor.object.getAbsolutePosition());
-                        bodyConfig.pos.push(localPosition.x);
-                        bodyConfig.pos.push(localPosition.y);
-                        bodyConfig.pos.push(localPosition.z);
+                        bodyConfig.posShape.push(localPosition.x);
+                        bodyConfig.posShape.push(localPosition.y);
+                        bodyConfig.posShape.push(localPosition.z);
+                        bodyConfig.pos.push(0, 0, 0);
 
                         //tmp solution until https://github.com/lo-th/OIMO.js/pull/37 is merged
                         bodyConfig.rot.push(0);
                         bodyConfig.rot.push(0);
                         bodyConfig.rot.push(0);
+                        bodyConfig.rotShape.push(rot.x * radToDeg);
+                        bodyConfig.rotShape.push(rot.y * radToDeg);
+                        bodyConfig.rotShape.push(rot.z * radToDeg);
                     }
 
                     // register mesh
                     switch (i.type) {
                         case PhysicsImpostor.ParticleImpostor:
-                            Tools.Warn("No Particle support in this.BJSOIMO.js. using SphereImpostor instead");
+                            Tools.Warn("No Particle support in OIMO.js. using SphereImpostor instead");
                         case PhysicsImpostor.SphereImpostor:
                             var radiusX = extendSize.x;
                             var radiusY = extendSize.y;
@@ -200,10 +206,15 @@ module BABYLON {
                             var sizeY = checkWithEpsilon(extendSize.y);
                             var sizeZ = checkWithEpsilon(extendSize.z);
 
+
                             bodyConfig.type.push('box');
+                            //if (i === impostor) {
                             bodyConfig.size.push(sizeX);
                             bodyConfig.size.push(sizeY);
                             bodyConfig.size.push(sizeZ);
+                            //} else {
+                            //    bodyConfig.size.push(0,0,0);
+                            //}
                             break;
                     }
 
@@ -211,7 +222,7 @@ module BABYLON {
                     i.object.rotationQuaternion = oldQuaternion;
                 });
 
-                impostor.physicsBody = new this.BJSOIMO.Body(bodyConfig).body//this.world.add(bodyConfig);
+                impostor.physicsBody = this.world.add(bodyConfig);
 
             } else {
                 this._tmpPositionVector.copyFromFloats(0, 0, 0);
@@ -264,7 +275,7 @@ module BABYLON {
                     type = "jointBall";
                     break;
                 case PhysicsJoint.SpringJoint:
-                    Tools.Warn("this.BJSOIMO.js doesn't support Spring Constraint. Simulating using DistanceJoint instead");
+                    Tools.Warn("OIMO.js doesn't support Spring Constraint. Simulating using DistanceJoint instead");
                     var springData = <SpringJointData>jointData;
                     nativeJointData.min = springData.length || nativeJointData.min;
                     //Max should also be set, just make sure it is at least min
@@ -288,7 +299,7 @@ module BABYLON {
                     break;
             }
             nativeJointData.type = type;
-            impostorJoint.joint.physicsJoint = new this.BJSOIMO.Link(nativeJointData).joint//this.world.add(nativeJointData);
+            impostorJoint.joint.physicsJoint = this.world.add(nativeJointData);
         }
 
         public removeJoint(impostorJoint: PhysicsImpostorJoint) {
@@ -310,29 +321,24 @@ module BABYLON {
         public setTransformationFromPhysicsBody(impostor: PhysicsImpostor) {
             if (!impostor.physicsBody.sleeping) {
                 //TODO check that
-                if (impostor.physicsBody.shapes.next) {
+                /*if (impostor.physicsBody.shapes.next) {
                     var parentShape = this._getLastShape(impostor.physicsBody);
-                    impostor.object.position.x = parentShape.position.x * this.BJSOIMO.WORLD_SCALE;
-                    impostor.object.position.y = parentShape.position.y * this.BJSOIMO.WORLD_SCALE;
-                    impostor.object.position.z = parentShape.position.z * this.BJSOIMO.WORLD_SCALE;
-                } else {
-                    impostor.object.position.copyFrom(impostor.physicsBody.getPosition());
-
-                }
+                    impostor.object.position.copyFrom(parentShape.position);
+                    console.log(parentShape.position);
+                } else {*/
+                impostor.object.position.copyFrom(impostor.physicsBody.getPosition());
+                //}
 
                 if (impostor.object.rotationQuaternion) {
                     impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.getQuaternion());
-                    impostor.object.rotationQuaternion.normalize();
                 }
             }
         }
 
         public setPhysicsBodyTransformation(impostor: PhysicsImpostor, newPosition: Vector3, newRotation: Quaternion) {
             var body = impostor.physicsBody;
-
-            body.position.init(newPosition.x * this.BJSOIMO.INV_SCALE, newPosition.y * this.BJSOIMO.INV_SCALE, newPosition.z * this.BJSOIMO.INV_SCALE);
-
-            body.orientation.init(newRotation.w, newRotation.x, newRotation.y, newRotation.z);
+            body.position.copy(newPosition);
+            body.orientation.copy(newRotation);
             body.syncShapes();
             body.awake();
         }