Przeglądaj źródła

Extend size and position should be in local space for the physics engine(s)

Raanan Weber 5 lat temu
rodzic
commit
63dec6ae14

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

@@ -290,6 +290,7 @@
 - Fix shadow bound calculation in CSM shadow technique ([Popov72](https://github.com/Popov72))
 - Disposing of the depthReducer used in CSM ([Popov72](https://github.com/Popov72))
 - Fixed an issue with teleportation detach and attach ([#7419](https://github.com/BabylonJS/Babylon.js/issues/7419)) ([RaananW](https://github.com/RaananW/))
+- Physics compound calculations were incorrect ([#7407](https://github.com/BabylonJS/Babylon.js/issues/7407)) ([RaananW](https://github.com/RaananW/))
 
 ## Breaking changes
 

+ 1 - 13
src/Physics/Plugins/cannonJSPlugin.ts

@@ -155,7 +155,7 @@ export class CannonJSPlugin implements IPhysicsEnginePlugin {
                 if (childImpostor) {
                     var parent = childImpostor.parent;
                     if (parent !== mainImpostor) {
-                        var pPosition = mesh.getAbsolutePosition().subtract(mainImpostor.object.getAbsolutePosition());
+                        var pPosition = mesh.position.clone();
                         let localRotation = mesh.rotationQuaternion.multiply(Quaternion.Inverse(currentRotation));
                         if (childImpostor.physicsBody) {
                             this.removePhysicsBody(childImpostor);
@@ -599,18 +599,6 @@ export class CannonJSPlugin implements IPhysicsEnginePlugin {
         joint.physicsJoint.distance = maxDistance;
     }
 
-    // private enableMotor(joint: IMotorEnabledJoint, motorIndex?: number) {
-    //     if (!motorIndex) {
-    //         joint.physicsJoint.enableMotor();
-    //     }
-    // }
-
-    // private disableMotor(joint: IMotorEnabledJoint, motorIndex?: number) {
-    //     if (!motorIndex) {
-    //         joint.physicsJoint.disableMotor();
-    //     }
-    // }
-
     public setMotor(joint: IMotorEnabledJoint, speed?: number, maxForce?: number, motorIndex?: number) {
         if (!motorIndex) {
             joint.physicsJoint.enableMotor();

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

@@ -162,11 +162,11 @@ export class OimoJSPlugin implements IPhysicsEnginePlugin {
 
                     bodyConfig.rotShape.push(0, 0, 0);
                 } else {
-                    let localPosition = i.object.getAbsolutePosition().subtract(impostor.object.getAbsolutePosition());
+                    let localPosition = i.object.position.clone();
                     bodyConfig.posShape.push(localPosition.x);
                     bodyConfig.posShape.push(localPosition.y);
                     bodyConfig.posShape.push(localPosition.z);
-                    bodyConfig.pos.push(0, 0, 0);
+                    // bodyConfig.pos.push(0, 0, 0);
 
                     bodyConfig.rotShape.push(rot.x * radToDeg);
                     bodyConfig.rotShape.push(rot.y * radToDeg);

+ 2 - 2
src/Physics/physicsImpostor.ts

@@ -610,7 +610,7 @@ export class PhysicsImpostor {
             //calculate the world matrix with no rotation
             this.object.computeWorldMatrix && this.object.computeWorldMatrix(true);
             let boundingInfo = this.object.getBoundingInfo();
-            let size = boundingInfo.boundingBox.extendSizeWorld.scale(2);
+            let size = boundingInfo.boundingBox.extendSize.scale(2);
 
             //bring back the rotation
             this.object.rotationQuaternion = q;
@@ -636,7 +636,7 @@ export class PhysicsImpostor {
     }
 
     /**
-     * Get a specific parametes from the options parameter
+     * Get a specific parameter from the options parameters
      * @param paramName The object parameter name
      * @returns The object parameter
      */