Pārlūkot izejas kodu

Vug fixed with oimo and parenting.

Raanan Weber 9 gadi atpakaļ
vecāks
revīzija
5549681450

+ 2 - 2
src/Mesh/babylon.abstractMesh.js

@@ -683,9 +683,9 @@ var BABYLON;
          * */
         AbstractMesh.prototype.setPhysicsState = function (impostor, options) {
             //legacy support
-            if (impostor.type) {
+            if (impostor.impostor) {
                 options = impostor;
-                impostor = impostor.type;
+                impostor = impostor.impostor;
             }
             this.physicsImpostor = new BABYLON.PhysicsImpostor(this, impostor, options);
             return this.physicsImpostor.physicsBody;

+ 2 - 2
src/Mesh/babylon.abstractMesh.ts

@@ -773,9 +773,9 @@
          * */
         public setPhysicsState(impostor?: any, options?: PhysicsImpostorParameters): any {
             //legacy support
-            if (impostor.type) {
+            if (impostor.impostor) {
                 options = impostor;
-                impostor = impostor.type;
+                impostor = impostor.impostor;
             }
             this.physicsImpostor = new PhysicsImpostor(this, impostor, options);
             return this.physicsImpostor.physicsBody;

+ 1 - 1
src/Physics/Plugins/babylon.oimoJSPlugin.js

@@ -92,10 +92,10 @@ var BABYLON;
                 impostors.forEach(function (i) {
                     //get the correct bounding box
                     var oldQuaternion = i.mesh.rotationQuaternion;
+                    var rot = new OIMO.Euler().setFromQuaternion({ x: impostor.mesh.rotationQuaternion.x, y: impostor.mesh.rotationQuaternion.y, z: impostor.mesh.rotationQuaternion.z, s: impostor.mesh.rotationQuaternion.w });
                     i.mesh.rotationQuaternion = new BABYLON.Quaternion(0, 0, 0, 1);
                     i.mesh.computeWorldMatrix(true);
                     var bbox = i.mesh.getBoundingInfo().boundingBox;
-                    var rot = new OIMO.Euler().setFromQuaternion({ x: impostor.mesh.rotationQuaternion.x, y: impostor.mesh.rotationQuaternion.y, z: impostor.mesh.rotationQuaternion.z, s: impostor.mesh.rotationQuaternion.w });
                     if (i === impostor) {
                         //Can also use Array.prototype.push.apply
                         bodyConfig.pos.push(bbox.center.x);

+ 3 - 2
src/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -114,12 +114,13 @@ module BABYLON {
                     
                     //get the correct bounding box
                     var oldQuaternion = i.mesh.rotationQuaternion;
+                    var rot = new OIMO.Euler().setFromQuaternion({ x: impostor.mesh.rotationQuaternion.x, y: impostor.mesh.rotationQuaternion.y, z: impostor.mesh.rotationQuaternion.z, s: impostor.mesh.rotationQuaternion.w });
+
                     i.mesh.rotationQuaternion = new Quaternion(0, 0, 0, 1);
                     i.mesh.computeWorldMatrix(true);
 
                     var bbox = i.mesh.getBoundingInfo().boundingBox;
-                    var rot = new OIMO.Euler().setFromQuaternion({ x: impostor.mesh.rotationQuaternion.x, y: impostor.mesh.rotationQuaternion.y, z: impostor.mesh.rotationQuaternion.z, s: impostor.mesh.rotationQuaternion.w });
-
+                    
                     if (i === impostor) {
                         //Can also use Array.prototype.push.apply
                         bodyConfig.pos.push(bbox.center.x);

+ 1 - 0
src/Physics/babylon.physicsEngine.ts

@@ -73,6 +73,7 @@
                 //Is it needed?
                 if(removed.length) {
                     this._physicsPlugin.removePhysicsBody(removed[0]);
+                    removed[0].physicsBody = null;
                 }
             }
         }

+ 4 - 0
src/Physics/babylon.physicsImpostor.js

@@ -52,10 +52,14 @@ var BABYLON;
         }
         PhysicsImpostor.prototype._init = function () {
             this._physicsEngine.removeImpostor(this);
+            this.physicsBody = null;
             this._parent = this._parent || this._getPhysicsParent();
             if (!this.parent) {
                 this._physicsEngine.addImpostor(this);
             }
+            else {
+                this.parent.forceUpdate();
+            }
         };
         PhysicsImpostor.prototype._getPhysicsParent = function () {
             if (this.mesh.parent instanceof BABYLON.AbstractMesh) {

+ 3 - 0
src/Physics/babylon.physicsImpostor.ts

@@ -41,9 +41,12 @@ module BABYLON {
 
         private _init() {
             this._physicsEngine.removeImpostor(this);
+            this.physicsBody = null;
             this._parent = this._parent || this._getPhysicsParent();
             if (!this.parent) {
                 this._physicsEngine.addImpostor(this);
+            } else {
+                this.parent.forceUpdate();
             }
         }
 

+ 1 - 1
src/babylon.scene.js

@@ -2028,7 +2028,7 @@ var BABYLON;
          * @Deprecated
          */
         Scene.prototype.createCompoundImpostor = function (parts, options) {
-            BABYLON.Tools.Warn("This function is deprecated. Please use PhysicsImpostor parent/child");
+            BABYLON.Tools.Warn("Scene.createCompoundImpostor is deprecated. Please use PhysicsImpostor parent/child");
             if (parts.parts) {
                 options = parts;
                 parts = parts.parts;

+ 3 - 1
src/babylon.scene.ts

@@ -2533,7 +2533,7 @@
          * @Deprecated
          */
         public createCompoundImpostor(parts: any, options: PhysicsImpostorParameters): any {
-            Tools.Warn("This function is deprecated. Please use PhysicsImpostor parent/child")
+            Tools.Warn("Scene.createCompoundImpostor is deprecated. Please use PhysicsImpostor parent/child")
 
             if (parts.parts) { // Old API
                 options = parts;
@@ -2549,7 +2549,9 @@
                     mesh.parent = mainMesh;
                 }
                 mesh.physicsImpostor = new PhysicsImpostor(mesh, parts[index].impostor, options)
+
             }
+            mainMesh.physicsImpostor.forceUpdate();
         }
 
         public deleteCompoundImpostor(compound: any): void {