فهرست منبع

Merge pull request #3928 from RaananW/oimo-1.0.9

Oimo 1.0.9
Raanan Weber 7 سال پیش
والد
کامیت
b06eb6b9e8
4فایلهای تغییر یافته به همراه12011 افزوده شده و 12216 حذف شده
  1. 11 11
      dist/Oimo.js
  2. 11954 12166
      dist/preview release/Oimo.js
  3. 1 0
      dist/preview release/what's new.md
  4. 45 39
      src/Physics/Plugins/babylon.oimoJSPlugin.ts

+ 11 - 11
dist/Oimo.js

@@ -7390,31 +7390,31 @@ OIMO.BoxBoxCollisionDetector.prototype.constructor = OIMO.BoxBoxCollisionDetecto
 
 OIMO.BoxBoxCollisionDetector.prototype.detectCollision = function (shape1, shape2, manifold) {
     // What you are doing 
-    // · I to prepare a separate axis of the fifteen 
+    // · I to prepare a separate axis of the fifteen 
     //-Six in each of three normal vectors of the xyz direction of the box both 
-    // · Remaining nine 3x3 a vector perpendicular to the side of the box 2 and the side of the box 1 
-    // · Calculate the depth to the separation axis 
+    // · Remaining nine 3x3 a vector perpendicular to the side of the box 2 and the side of the box 1 
+    // · Calculate the depth to the separation axis 
 
     // Calculates the distance using the inner product and put the amount of embedment 
-    // · However a vertical separation axis and side to weight a little to avoid vibration 
+    // · However a vertical separation axis and side to weight a little to avoid vibration 
     // And end when there is a separate axis that is remote even one 
-    // · I look for separation axis with little to dent most 
+    // · I look for separation axis with little to dent most 
     // Men and if separation axis of the first six - end collision 
     // Heng If it separate axis of nine other - side collision 
     // Heng - case of a side collision 
-    // · Find points of two sides on which you made ​​the separation axis 
+    // · Find points of two sides on which you made ​​the separation axis 
 
     // Calculates the point of closest approach of a straight line consisting of separate axis points obtained, and the collision point 
     //-Surface - the case of the plane crash 
-    //-Box A, box B and the other a box of better made ​​a separate axis 
-    //  The surface A and the plane that made the separation axis of the box A, and B to the surface the face of the box B close in the opposite direction to the most isolated axis 
+    //-Box A, box B and the other a box of better made ​​a separate axis 
+    // • The surface A and the plane that made the separation axis of the box A, and B to the surface the face of the box B close in the opposite direction to the most isolated axis 
 
     // When viewed from the front surface A, and the cut part exceeding the area of the surface A is a surface B 
     //-Plane B becomes the 3-8 triangle, I a candidate for the collision point the vertex of surface B 
-    //  If more than one candidate 5 exists, scraping up to four 
+    // • If more than one candidate 5 exists, scraping up to four 
 
     // For potential collision points of all, to examine the distance between the surface A 
-    //  If you were on the inside surface of A, and the collision point
+    // • If you were on the inside surface of A, and the collision point
 
     var b1;
     var b2;
@@ -12526,4 +12526,4 @@ if (!root['OIMO']) {
     else {
         root["OIMO"] = OIMO;
     }
-}
+}

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 11954 - 12166
dist/preview release/Oimo.js


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

@@ -19,6 +19,7 @@
 - New [Babylon.js](http://doc.babylonjs.com/resources/maya) and [glTF](http://doc.babylonjs.com/resources/maya_to_gltf) exporter for Autodesk Maya ([Noalak](https://github.com/Noalak))
 - New glTF [serializer](https://github.com/BabylonJS/Babylon.js/tree/master/serializers/src/glTF/2.0). You can now export glTF or glb files directly from a Babylon scene ([kcoley](https://github.com/kcoley))
 - New [glTF exporter](http://doc.babylonjs.com/resources/3dsmax_to_gltf) for Autodesk 3dsmax ([Noalak](https://github.com/Noalak))
+- Physics - Latest production version of Oimo.js is being used - 1.0.9 ([RaananW](https://github.com/RaananW))
 
 ## Updates
 

+ 45 - 39
src/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -11,11 +11,10 @@ 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.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,40 +321,35 @@ 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();
         }
 
-        private _getLastShape(body: any): any {
+        /*private _getLastShape(body: any): any {
             var lastShape = body.shapes;
             while (lastShape.next) {
                 lastShape = lastShape.next;
             }
             return lastShape;
-        }
+        }*/
 
         public setLinearVelocity(impostor: PhysicsImpostor, velocity: Vector3) {
             impostor.physicsBody.linearVelocity.init(velocity.x, velocity.y, velocity.z);