Przeglądaj źródła

New cache system
Better debug version (Fully readable, not minified)

David Catuhe 11 lat temu
rodzic
commit
294e3f4745

+ 23 - 6
Babylon/Physics/Plugins/babylon.cannonJSPlugin.js

@@ -9,7 +9,9 @@
                     var registeredMesh = this._registeredMeshes[index];
                     if (registeredMesh.mesh === mesh || registeredMesh.mesh === mesh.parent) {
                         var body = registeredMesh.body.body;
-                        body.position.set(mesh.position.x, mesh.position.z, mesh.position.y);
+
+                        var center = mesh.getBoundingInfo().boundingBox.center;
+                        body.position.set(center.x, center.z, center.y);
 
                         body.quaternion.x = mesh.rotationQuaternion.x;
                         body.quaternion.z = mesh.rotationQuaternion.y;
@@ -41,9 +43,19 @@
                     continue;
                 }
 
-                registeredMesh.mesh.position.x = registeredMesh.body.position.x;
-                registeredMesh.mesh.position.y = registeredMesh.body.position.z;
-                registeredMesh.mesh.position.z = registeredMesh.body.position.y;
+                // Body position
+                var bodyX = registeredMesh.body.position.x, bodyY = registeredMesh.body.position.y, bodyZ = registeredMesh.body.position.z;
+
+                var deltaPos = registeredMesh.delta;
+                if (deltaPos) {
+                    registeredMesh.mesh.position.x = bodyX + deltaPos.x;
+                    registeredMesh.mesh.position.y = bodyZ + deltaPos.y;
+                    registeredMesh.mesh.position.z = bodyY + deltaPos.z;
+                } else {
+                    registeredMesh.mesh.position.x = bodyX;
+                    registeredMesh.mesh.position.y = bodyZ;
+                    registeredMesh.mesh.position.z = bodyY;
+                }
 
                 if (!registeredMesh.mesh.rotationQuaternion) {
                     registeredMesh.mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
@@ -184,6 +196,10 @@
                 mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
             }
 
+            // The delta between the mesh position and the mesh bounding box center
+            var bbox = mesh.getBoundingInfo().boundingBox;
+            var deltaPosition = mesh.position.subtract(bbox.center);
+
             var material = this._addMaterial(friction, restitution);
             var body = new CANNON.RigidBody(mass, shape, material);
 
@@ -194,10 +210,10 @@
                 body.quaternion.w = -initialRotation.w;
             }
 
-            body.position.set(mesh.position.x, mesh.position.z, mesh.position.y);
+            body.position.set(bbox.center.x, bbox.center.z, bbox.center.y);
             this._world.add(body);
 
-            this._registeredMeshes.push({ mesh: mesh, body: body, material: material });
+            this._registeredMeshes.push({ mesh: mesh, body: body, material: material, delta: deltaPosition });
 
             return body;
         };
@@ -231,6 +247,7 @@
 
                 if (registeredMesh.body === body) {
                     registeredMesh.body = null;
+                    registeredMesh.delta = 0;
                 }
             }
         };

+ 32 - 8
Babylon/Physics/Plugins/babylon.oimoJSPlugin.js

@@ -12,7 +12,9 @@ var BABYLON;
                     var registeredMesh = this._registeredMeshes[index];
                     if (registeredMesh.mesh === mesh || registeredMesh.mesh === mesh.parent) {
                         var body = registeredMesh.body.body;
-                        body.setPosition(mesh.position.x, mesh.position.y, mesh.position.z);
+
+                        var center = mesh.getBoundingInfo().boundingBox.center;
+                        body.setPosition(center.x, center.y, center.z);
                         body.setOrientation(mesh.rotation.x, mesh.rotation.y, mesh.rotation.z);
                         return;
                     }
@@ -59,10 +61,14 @@ var BABYLON;
                     var radiusZ = bbox.maximumWorld.z - bbox.minimumWorld.z;
 
                     var size = Math.max(this._checkWithEpsilon(radiusX), this._checkWithEpsilon(radiusY), this._checkWithEpsilon(radiusZ)) / 2;
+
+                    // The delta between the mesh position and the mesh bounding box center
+                    var deltaPosition = mesh.position.subtract(bbox.center);
+
                     body = new OIMO.Body({
                         type: 'sphere',
                         size: [size],
-                        pos: [mesh.position.x, mesh.position.y, mesh.position.z],
+                        pos: [bbox.center.x, bbox.center.y, bbox.center.z],
                         rot: [mesh.rotation.x / OIMO.TO_RAD, mesh.rotation.y / OIMO.TO_RAD, mesh.rotation.z / OIMO.TO_RAD],
                         move: options.mass != 0,
                         config: [options.mass, options.friction, options.restitution],
@@ -70,7 +76,8 @@ var BABYLON;
                     });
                     this._registeredMeshes.push({
                         mesh: mesh,
-                        body: body
+                        body: body,
+                        delta: deltaPosition
                     });
                     break;
 
@@ -83,10 +90,14 @@ var BABYLON;
                     var sizeX = this._checkWithEpsilon(box.x);
                     var sizeY = this._checkWithEpsilon(box.y);
                     var sizeZ = this._checkWithEpsilon(box.z);
+
+                    // The delta between the mesh position and the mesh boudning box center
+                    var deltaPosition = mesh.position.subtract(bbox.center);
+
                     body = new OIMO.Body({
                         type: 'box',
                         size: [sizeX, sizeY, sizeZ],
-                        pos: [mesh.position.x, mesh.position.y, mesh.position.z],
+                        pos: [bbox.center.x, bbox.center.y, bbox.center.z],
                         rot: [mesh.rotation.x / OIMO.TO_RAD, mesh.rotation.y / OIMO.TO_RAD, mesh.rotation.z / OIMO.TO_RAD],
                         move: options.mass != 0,
                         config: [options.mass, options.friction, options.restitution],
@@ -95,7 +106,8 @@ var BABYLON;
 
                     this._registeredMeshes.push({
                         mesh: mesh,
-                        body: body
+                        body: body,
+                        delta: deltaPosition
                     });
                     break;
             }
@@ -273,6 +285,8 @@ var BABYLON;
             while (i--) {
                 var body = this._registeredMeshes[i].body.body;
                 var mesh = this._registeredMeshes[i].mesh;
+                var delta = this._registeredMeshes[i].delta;
+
                 if (!body.sleeping) {
                     if (body.shapes.next) {
                         var parentShape = this._getLastShape(body);
@@ -288,9 +302,19 @@ var BABYLON;
                     } else {
                         m = body.getMatrix();
                         mtx = BABYLON.Matrix.FromArray(m);
-                        mesh.position.x = mtx.m[12];
-                        mesh.position.y = mtx.m[13];
-                        mesh.position.z = mtx.m[14];
+
+                        // Body position
+                        var bodyX = mtx.m[12], bodyY = mtx.m[13], bodyZ = mtx.m[14];
+
+                        if (delta) {
+                            mesh.position.x = bodyX;
+                            mesh.position.y = bodyY;
+                            mesh.position.z = bodyZ;
+                        } else {
+                            mesh.position.x = bodyX + delta.x;
+                            mesh.position.y = bodyY + delta.y;
+                            mesh.position.z = bodyZ + delta.z;
+                        }
 
                         if (!mesh.rotationQuaternion) {
                             mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);

+ 1 - 1
Babylon/Tools/babylon.database.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var Database = (function () {
         function Database(urlToScene, callbackManifestChecked) {

+ 4 - 0
Babylon/babylon.scene.js

@@ -1003,6 +1003,10 @@
                     this._processSubCameras(this.activeCameras[cameraIndex]);
                 }
             } else {
+                if (!this.activeCamera) {
+                    throw new Error("No camera defined");
+                }
+
                 this._processSubCameras(this.activeCamera);
             }
 

+ 5 - 1
Babylon/babylon.scene.ts

@@ -161,7 +161,7 @@
 
         private _selectionOctree: Octree<AbstractMesh>;
 
-        private _pointerOverMesh: AbstractMesh;      
+        private _pointerOverMesh: AbstractMesh;
 
         // Constructor
         constructor(engine: Engine) {
@@ -1084,6 +1084,10 @@
                     this._processSubCameras(this.activeCameras[cameraIndex]);
                 }
             } else {
+                if (!this.activeCamera) {
+                    throw new Error("No camera defined");
+                }
+
                 this._processSubCameras(this.activeCamera);
             }
 

BIN
Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJS/executables/JSKompactor.exe


Plik diff jest za duży
+ 25200 - 2
babylon.1.14-beta-debug.js


Plik diff jest za duży
+ 9 - 9
babylon.1.14-beta.js