浏览代码

fixing two issues with physics and playground

The first is an Oimo bug. Used a different method.
The second should make things a bit faster.
Raanan Weber 9 年之前
父节点
当前提交
f3be1271e3
共有 2 个文件被更改,包括 11 次插入2 次删除
  1. 10 2
      src/Physics/Plugins/babylon.oimoJSPlugin.ts
  2. 1 0
      src/Physics/babylon.physicsImpostor.ts

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

@@ -277,8 +277,16 @@ module BABYLON {
             impostorJoint.joint.physicsJoint = new OIMO.Link(nativeJointData).joint//this.world.add(nativeJointData);
         }
 
-        public removeJoint(joint: PhysicsImpostorJoint) {
-            joint.joint.physicsJoint.dispose();
+        public removeJoint(impostorJoint: PhysicsImpostorJoint) {
+            //Bug in Oimo prevents us from disposing a joint in the playground
+            //joint.joint.physicsJoint.dispose();
+            //So we will bruteforce it!
+            try {
+                this.world.removeJoint(impostorJoint.joint.physicsJoint);
+            } catch(e) {
+                Tools.Warn(e);
+            }
+            
         }
 
         public isSupported(): boolean {

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

@@ -328,6 +328,7 @@ module BABYLON {
 
         //event and body object due to cannon's event-based architecture.
         public onCollide = (e: { body: any }) => {
+            if(!this._onPhysicsCollideCallbacks.length) return;
             var otherImpostor = this._physicsEngine.getImpostorWithPhysicsBody(e.body);
             if (otherImpostor) {
                 this._onPhysicsCollideCallbacks.filter((obj) => {