sebavan 6 年之前
父節點
當前提交
91d94753d3

+ 2 - 2
.vscode/tasks.json

@@ -35,8 +35,8 @@
                 },
                 "background": {
                     "activeOnStart": true,
-                    "beginsPattern": "Starting \\'run\\'",
-                    "endsPattern": "Entrypoint babylonjs-gui"
+                    "beginsPattern": "Starting \\'watch\\'",
+                    "endsPattern": "Entrypoint babylonjs-inspector"
                 }
             }
         },

File diff suppressed because it is too large
+ 9966 - 9961
Playground/babylon.d.txt


File diff suppressed because it is too large
+ 9968 - 9963
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 1 - 1
dist/preview release/babylon.js


+ 37 - 19
dist/preview release/babylon.max.js

@@ -100098,6 +100098,10 @@ var BABYLON;
                     body.setCollisionFlags(body.getCollisionFlags() | AmmoJSPlugin.KINEMATIC_FLAG);
                     body.setActivationState(AmmoJSPlugin.DISABLE_DEACTIVATION_FLAG);
                 }
+                // Disable collision if NoImpostor, but keep collision if shape is btCompoundShape
+                if (impostor.type == BABYLON.PhysicsImpostor.NoImpostor && !colShape.getChildShape) {
+                    body.setCollisionFlags(body.getCollisionFlags() | AmmoJSPlugin.DISABLE_COLLISION_FLAG);
+                }
                 body.setRestitution(impostor.getParam("restitution"));
                 this.world.addRigidBody(body);
                 impostor.physicsBody = body;
@@ -100212,7 +100216,11 @@ var BABYLON;
                         var childImpostor = childMesh.getPhysicsImpostor();
                         if (childImpostor) {
                             var shape = _this._createShape(childImpostor);
-                            _this._tmpAmmoTransform.getOrigin().setValue(childMesh.position.x, childMesh.position.y, childMesh.position.z);
+                            // Position needs to be scaled based on parent's scaling
+                            var parentMat = childMesh.parent.getWorldMatrix().clone();
+                            var s = new BABYLON.Vector3();
+                            parentMat.decompose(s);
+                            _this._tmpAmmoTransform.getOrigin().setValue(childMesh.position.x * s.x, childMesh.position.y * s.y, childMesh.position.z * s.z);
                             _this._tmpAmmoQuaternion.setValue(childMesh.rotationQuaternion.x, childMesh.rotationQuaternion.y, childMesh.rotationQuaternion.z, childMesh.rotationQuaternion.w);
                             _this._tmpAmmoTransform.setRotation(_this._tmpAmmoQuaternion);
                             returnValue.addChildShape(_this._tmpAmmoTransform, shape);
@@ -100223,7 +100231,6 @@ var BABYLON;
                     var shape = this._createShape(impostor, true);
                     if (shape) {
                         this._tmpAmmoTransform.getOrigin().setValue(0, 0, 0);
-                        //this._tmpAmmoQuaternion = new this.BJSAMMO.btQuaternion(0,0,0,1);
                         this._tmpAmmoQuaternion.setValue(0, 0, 0, 1);
                         this._tmpAmmoTransform.setRotation(this._tmpAmmoQuaternion);
                         returnValue.addChildShape(this._tmpAmmoTransform, shape);
@@ -100255,6 +100262,10 @@ var BABYLON;
                         returnValue = new Ammo.btBvhTriangleMeshShape(tetraMesh);
                     }
                     break;
+                case BABYLON.PhysicsImpostor.NoImpostor:
+                    // Fill with sphere but collision is disabled on the rigid body in generatePhysicsBody, using an empty shape caused unexpected movement with joints
+                    returnValue = new Ammo.btSphereShape(extendSize.x / 2);
+                    break;
             }
             return returnValue;
         };
@@ -100505,6 +100516,7 @@ var BABYLON;
             Ammo.destroy(this._tmpAmmoConcreteContactResultCallback);
             this.world = null;
         };
+        AmmoJSPlugin.DISABLE_COLLISION_FLAG = 4;
         AmmoJSPlugin.KINEMATIC_FLAG = 2;
         AmmoJSPlugin.DISABLE_DEACTIVATION_FLAG = 4;
         return AmmoJSPlugin;
@@ -103645,6 +103657,10 @@ var BABYLON;
              */
             this.zDragFactor = 3;
             /**
+             * If the object should rotate to face the drag origin
+             */
+            this.rotateDraggedObject = true;
+            /**
              * If the behavior is currently in a dragging state
              */
             this.dragging = false;
@@ -103711,7 +103727,7 @@ var BABYLON;
                 if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERDOWN) {
                     if (!_this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.hit && pointerInfo.pickInfo.pickedMesh && pointerInfo.pickInfo.ray && pickPredicate(pointerInfo.pickInfo.pickedMesh)) {
                         if (_this._scene.activeCamera && _this._scene.activeCamera.cameraRigMode == BABYLON.Camera.RIG_MODE_NONE) {
-                            pointerInfo.pickInfo.ray.origin.copyFrom(_this._scene.activeCamera.position);
+                            pointerInfo.pickInfo.ray.origin.copyFrom(_this._scene.activeCamera.globalPosition);
                         }
                         pickedMesh = _this._ownerNode;
                         BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(pickedMesh);
@@ -103767,7 +103783,7 @@ var BABYLON;
                     if (_this.currentDraggingPointerID == pointerInfo.event.pointerId && _this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.ray && pickedMesh) {
                         var zDragFactor = _this.zDragFactor;
                         if (_this._scene.activeCamera && _this._scene.activeCamera.cameraRigMode == BABYLON.Camera.RIG_MODE_NONE) {
-                            pointerInfo.pickInfo.ray.origin.copyFrom(_this._scene.activeCamera.position);
+                            pointerInfo.pickInfo.ray.origin.copyFrom(_this._scene.activeCamera.globalPosition);
                             zDragFactor = 0;
                         }
                         // Calculate controller drag distance in controller space
@@ -103803,21 +103819,23 @@ var BABYLON;
                     BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(pickedMesh);
                     // Slowly move mesh to avoid jitter
                     pickedMesh.position.addInPlace(_this._targetPosition.subtract(pickedMesh.position).scale(_this.dragDeltaRatio));
-                    // Get change in rotation
-                    tmpQuaternion.copyFrom(_this._startingOrientation);
-                    tmpQuaternion.x = -tmpQuaternion.x;
-                    tmpQuaternion.y = -tmpQuaternion.y;
-                    tmpQuaternion.z = -tmpQuaternion.z;
-                    _this._virtualDragMesh.rotationQuaternion.multiplyToRef(tmpQuaternion, tmpQuaternion);
-                    // Convert change in rotation to only y axis rotation
-                    BABYLON.Quaternion.RotationYawPitchRollToRef(tmpQuaternion.toEulerAngles("xyz").y, 0, 0, tmpQuaternion);
-                    tmpQuaternion.multiplyToRef(_this._startingOrientation, tmpQuaternion);
-                    // Slowly move mesh to avoid jitter
-                    var oldParent = pickedMesh.parent;
-                    pickedMesh.setParent(null);
-                    BABYLON.Quaternion.SlerpToRef(pickedMesh.rotationQuaternion, tmpQuaternion, _this.dragDeltaRatio, pickedMesh.rotationQuaternion);
-                    pickedMesh.setParent(oldParent);
-                    BABYLON.BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
+                    if (_this.rotateDraggedObject) {
+                        // Get change in rotation
+                        tmpQuaternion.copyFrom(_this._startingOrientation);
+                        tmpQuaternion.x = -tmpQuaternion.x;
+                        tmpQuaternion.y = -tmpQuaternion.y;
+                        tmpQuaternion.z = -tmpQuaternion.z;
+                        _this._virtualDragMesh.rotationQuaternion.multiplyToRef(tmpQuaternion, tmpQuaternion);
+                        // Convert change in rotation to only y axis rotation
+                        BABYLON.Quaternion.RotationYawPitchRollToRef(tmpQuaternion.toEulerAngles("xyz").y, 0, 0, tmpQuaternion);
+                        tmpQuaternion.multiplyToRef(_this._startingOrientation, tmpQuaternion);
+                        // Slowly move mesh to avoid jitter
+                        var oldParent = pickedMesh.parent;
+                        pickedMesh.setParent(null);
+                        BABYLON.Quaternion.SlerpToRef(pickedMesh.rotationQuaternion, tmpQuaternion, _this.dragDeltaRatio, pickedMesh.rotationQuaternion);
+                        pickedMesh.setParent(oldParent);
+                        BABYLON.BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
+                    }
                 }
             });
         };

+ 37 - 19
dist/preview release/babylon.no-module.max.js

@@ -100065,6 +100065,10 @@ var BABYLON;
                     body.setCollisionFlags(body.getCollisionFlags() | AmmoJSPlugin.KINEMATIC_FLAG);
                     body.setActivationState(AmmoJSPlugin.DISABLE_DEACTIVATION_FLAG);
                 }
+                // Disable collision if NoImpostor, but keep collision if shape is btCompoundShape
+                if (impostor.type == BABYLON.PhysicsImpostor.NoImpostor && !colShape.getChildShape) {
+                    body.setCollisionFlags(body.getCollisionFlags() | AmmoJSPlugin.DISABLE_COLLISION_FLAG);
+                }
                 body.setRestitution(impostor.getParam("restitution"));
                 this.world.addRigidBody(body);
                 impostor.physicsBody = body;
@@ -100179,7 +100183,11 @@ var BABYLON;
                         var childImpostor = childMesh.getPhysicsImpostor();
                         if (childImpostor) {
                             var shape = _this._createShape(childImpostor);
-                            _this._tmpAmmoTransform.getOrigin().setValue(childMesh.position.x, childMesh.position.y, childMesh.position.z);
+                            // Position needs to be scaled based on parent's scaling
+                            var parentMat = childMesh.parent.getWorldMatrix().clone();
+                            var s = new BABYLON.Vector3();
+                            parentMat.decompose(s);
+                            _this._tmpAmmoTransform.getOrigin().setValue(childMesh.position.x * s.x, childMesh.position.y * s.y, childMesh.position.z * s.z);
                             _this._tmpAmmoQuaternion.setValue(childMesh.rotationQuaternion.x, childMesh.rotationQuaternion.y, childMesh.rotationQuaternion.z, childMesh.rotationQuaternion.w);
                             _this._tmpAmmoTransform.setRotation(_this._tmpAmmoQuaternion);
                             returnValue.addChildShape(_this._tmpAmmoTransform, shape);
@@ -100190,7 +100198,6 @@ var BABYLON;
                     var shape = this._createShape(impostor, true);
                     if (shape) {
                         this._tmpAmmoTransform.getOrigin().setValue(0, 0, 0);
-                        //this._tmpAmmoQuaternion = new this.BJSAMMO.btQuaternion(0,0,0,1);
                         this._tmpAmmoQuaternion.setValue(0, 0, 0, 1);
                         this._tmpAmmoTransform.setRotation(this._tmpAmmoQuaternion);
                         returnValue.addChildShape(this._tmpAmmoTransform, shape);
@@ -100222,6 +100229,10 @@ var BABYLON;
                         returnValue = new Ammo.btBvhTriangleMeshShape(tetraMesh);
                     }
                     break;
+                case BABYLON.PhysicsImpostor.NoImpostor:
+                    // Fill with sphere but collision is disabled on the rigid body in generatePhysicsBody, using an empty shape caused unexpected movement with joints
+                    returnValue = new Ammo.btSphereShape(extendSize.x / 2);
+                    break;
             }
             return returnValue;
         };
@@ -100472,6 +100483,7 @@ var BABYLON;
             Ammo.destroy(this._tmpAmmoConcreteContactResultCallback);
             this.world = null;
         };
+        AmmoJSPlugin.DISABLE_COLLISION_FLAG = 4;
         AmmoJSPlugin.KINEMATIC_FLAG = 2;
         AmmoJSPlugin.DISABLE_DEACTIVATION_FLAG = 4;
         return AmmoJSPlugin;
@@ -103612,6 +103624,10 @@ var BABYLON;
              */
             this.zDragFactor = 3;
             /**
+             * If the object should rotate to face the drag origin
+             */
+            this.rotateDraggedObject = true;
+            /**
              * If the behavior is currently in a dragging state
              */
             this.dragging = false;
@@ -103678,7 +103694,7 @@ var BABYLON;
                 if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERDOWN) {
                     if (!_this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.hit && pointerInfo.pickInfo.pickedMesh && pointerInfo.pickInfo.ray && pickPredicate(pointerInfo.pickInfo.pickedMesh)) {
                         if (_this._scene.activeCamera && _this._scene.activeCamera.cameraRigMode == BABYLON.Camera.RIG_MODE_NONE) {
-                            pointerInfo.pickInfo.ray.origin.copyFrom(_this._scene.activeCamera.position);
+                            pointerInfo.pickInfo.ray.origin.copyFrom(_this._scene.activeCamera.globalPosition);
                         }
                         pickedMesh = _this._ownerNode;
                         BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(pickedMesh);
@@ -103734,7 +103750,7 @@ var BABYLON;
                     if (_this.currentDraggingPointerID == pointerInfo.event.pointerId && _this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.ray && pickedMesh) {
                         var zDragFactor = _this.zDragFactor;
                         if (_this._scene.activeCamera && _this._scene.activeCamera.cameraRigMode == BABYLON.Camera.RIG_MODE_NONE) {
-                            pointerInfo.pickInfo.ray.origin.copyFrom(_this._scene.activeCamera.position);
+                            pointerInfo.pickInfo.ray.origin.copyFrom(_this._scene.activeCamera.globalPosition);
                             zDragFactor = 0;
                         }
                         // Calculate controller drag distance in controller space
@@ -103770,21 +103786,23 @@ var BABYLON;
                     BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(pickedMesh);
                     // Slowly move mesh to avoid jitter
                     pickedMesh.position.addInPlace(_this._targetPosition.subtract(pickedMesh.position).scale(_this.dragDeltaRatio));
-                    // Get change in rotation
-                    tmpQuaternion.copyFrom(_this._startingOrientation);
-                    tmpQuaternion.x = -tmpQuaternion.x;
-                    tmpQuaternion.y = -tmpQuaternion.y;
-                    tmpQuaternion.z = -tmpQuaternion.z;
-                    _this._virtualDragMesh.rotationQuaternion.multiplyToRef(tmpQuaternion, tmpQuaternion);
-                    // Convert change in rotation to only y axis rotation
-                    BABYLON.Quaternion.RotationYawPitchRollToRef(tmpQuaternion.toEulerAngles("xyz").y, 0, 0, tmpQuaternion);
-                    tmpQuaternion.multiplyToRef(_this._startingOrientation, tmpQuaternion);
-                    // Slowly move mesh to avoid jitter
-                    var oldParent = pickedMesh.parent;
-                    pickedMesh.setParent(null);
-                    BABYLON.Quaternion.SlerpToRef(pickedMesh.rotationQuaternion, tmpQuaternion, _this.dragDeltaRatio, pickedMesh.rotationQuaternion);
-                    pickedMesh.setParent(oldParent);
-                    BABYLON.BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
+                    if (_this.rotateDraggedObject) {
+                        // Get change in rotation
+                        tmpQuaternion.copyFrom(_this._startingOrientation);
+                        tmpQuaternion.x = -tmpQuaternion.x;
+                        tmpQuaternion.y = -tmpQuaternion.y;
+                        tmpQuaternion.z = -tmpQuaternion.z;
+                        _this._virtualDragMesh.rotationQuaternion.multiplyToRef(tmpQuaternion, tmpQuaternion);
+                        // Convert change in rotation to only y axis rotation
+                        BABYLON.Quaternion.RotationYawPitchRollToRef(tmpQuaternion.toEulerAngles("xyz").y, 0, 0, tmpQuaternion);
+                        tmpQuaternion.multiplyToRef(_this._startingOrientation, tmpQuaternion);
+                        // Slowly move mesh to avoid jitter
+                        var oldParent = pickedMesh.parent;
+                        pickedMesh.setParent(null);
+                        BABYLON.Quaternion.SlerpToRef(pickedMesh.rotationQuaternion, tmpQuaternion, _this.dragDeltaRatio, pickedMesh.rotationQuaternion);
+                        pickedMesh.setParent(oldParent);
+                        BABYLON.BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
+                    }
                 }
             });
         };

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/babylon.worker.js


+ 37 - 19
dist/preview release/es6.js

@@ -100065,6 +100065,10 @@ var BABYLON;
                     body.setCollisionFlags(body.getCollisionFlags() | AmmoJSPlugin.KINEMATIC_FLAG);
                     body.setActivationState(AmmoJSPlugin.DISABLE_DEACTIVATION_FLAG);
                 }
+                // Disable collision if NoImpostor, but keep collision if shape is btCompoundShape
+                if (impostor.type == BABYLON.PhysicsImpostor.NoImpostor && !colShape.getChildShape) {
+                    body.setCollisionFlags(body.getCollisionFlags() | AmmoJSPlugin.DISABLE_COLLISION_FLAG);
+                }
                 body.setRestitution(impostor.getParam("restitution"));
                 this.world.addRigidBody(body);
                 impostor.physicsBody = body;
@@ -100179,7 +100183,11 @@ var BABYLON;
                         var childImpostor = childMesh.getPhysicsImpostor();
                         if (childImpostor) {
                             var shape = _this._createShape(childImpostor);
-                            _this._tmpAmmoTransform.getOrigin().setValue(childMesh.position.x, childMesh.position.y, childMesh.position.z);
+                            // Position needs to be scaled based on parent's scaling
+                            var parentMat = childMesh.parent.getWorldMatrix().clone();
+                            var s = new BABYLON.Vector3();
+                            parentMat.decompose(s);
+                            _this._tmpAmmoTransform.getOrigin().setValue(childMesh.position.x * s.x, childMesh.position.y * s.y, childMesh.position.z * s.z);
                             _this._tmpAmmoQuaternion.setValue(childMesh.rotationQuaternion.x, childMesh.rotationQuaternion.y, childMesh.rotationQuaternion.z, childMesh.rotationQuaternion.w);
                             _this._tmpAmmoTransform.setRotation(_this._tmpAmmoQuaternion);
                             returnValue.addChildShape(_this._tmpAmmoTransform, shape);
@@ -100190,7 +100198,6 @@ var BABYLON;
                     var shape = this._createShape(impostor, true);
                     if (shape) {
                         this._tmpAmmoTransform.getOrigin().setValue(0, 0, 0);
-                        //this._tmpAmmoQuaternion = new this.BJSAMMO.btQuaternion(0,0,0,1);
                         this._tmpAmmoQuaternion.setValue(0, 0, 0, 1);
                         this._tmpAmmoTransform.setRotation(this._tmpAmmoQuaternion);
                         returnValue.addChildShape(this._tmpAmmoTransform, shape);
@@ -100222,6 +100229,10 @@ var BABYLON;
                         returnValue = new Ammo.btBvhTriangleMeshShape(tetraMesh);
                     }
                     break;
+                case BABYLON.PhysicsImpostor.NoImpostor:
+                    // Fill with sphere but collision is disabled on the rigid body in generatePhysicsBody, using an empty shape caused unexpected movement with joints
+                    returnValue = new Ammo.btSphereShape(extendSize.x / 2);
+                    break;
             }
             return returnValue;
         };
@@ -100472,6 +100483,7 @@ var BABYLON;
             Ammo.destroy(this._tmpAmmoConcreteContactResultCallback);
             this.world = null;
         };
+        AmmoJSPlugin.DISABLE_COLLISION_FLAG = 4;
         AmmoJSPlugin.KINEMATIC_FLAG = 2;
         AmmoJSPlugin.DISABLE_DEACTIVATION_FLAG = 4;
         return AmmoJSPlugin;
@@ -103612,6 +103624,10 @@ var BABYLON;
              */
             this.zDragFactor = 3;
             /**
+             * If the object should rotate to face the drag origin
+             */
+            this.rotateDraggedObject = true;
+            /**
              * If the behavior is currently in a dragging state
              */
             this.dragging = false;
@@ -103678,7 +103694,7 @@ var BABYLON;
                 if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERDOWN) {
                     if (!_this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.hit && pointerInfo.pickInfo.pickedMesh && pointerInfo.pickInfo.ray && pickPredicate(pointerInfo.pickInfo.pickedMesh)) {
                         if (_this._scene.activeCamera && _this._scene.activeCamera.cameraRigMode == BABYLON.Camera.RIG_MODE_NONE) {
-                            pointerInfo.pickInfo.ray.origin.copyFrom(_this._scene.activeCamera.position);
+                            pointerInfo.pickInfo.ray.origin.copyFrom(_this._scene.activeCamera.globalPosition);
                         }
                         pickedMesh = _this._ownerNode;
                         BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(pickedMesh);
@@ -103734,7 +103750,7 @@ var BABYLON;
                     if (_this.currentDraggingPointerID == pointerInfo.event.pointerId && _this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.ray && pickedMesh) {
                         var zDragFactor = _this.zDragFactor;
                         if (_this._scene.activeCamera && _this._scene.activeCamera.cameraRigMode == BABYLON.Camera.RIG_MODE_NONE) {
-                            pointerInfo.pickInfo.ray.origin.copyFrom(_this._scene.activeCamera.position);
+                            pointerInfo.pickInfo.ray.origin.copyFrom(_this._scene.activeCamera.globalPosition);
                             zDragFactor = 0;
                         }
                         // Calculate controller drag distance in controller space
@@ -103770,21 +103786,23 @@ var BABYLON;
                     BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(pickedMesh);
                     // Slowly move mesh to avoid jitter
                     pickedMesh.position.addInPlace(_this._targetPosition.subtract(pickedMesh.position).scale(_this.dragDeltaRatio));
-                    // Get change in rotation
-                    tmpQuaternion.copyFrom(_this._startingOrientation);
-                    tmpQuaternion.x = -tmpQuaternion.x;
-                    tmpQuaternion.y = -tmpQuaternion.y;
-                    tmpQuaternion.z = -tmpQuaternion.z;
-                    _this._virtualDragMesh.rotationQuaternion.multiplyToRef(tmpQuaternion, tmpQuaternion);
-                    // Convert change in rotation to only y axis rotation
-                    BABYLON.Quaternion.RotationYawPitchRollToRef(tmpQuaternion.toEulerAngles("xyz").y, 0, 0, tmpQuaternion);
-                    tmpQuaternion.multiplyToRef(_this._startingOrientation, tmpQuaternion);
-                    // Slowly move mesh to avoid jitter
-                    var oldParent = pickedMesh.parent;
-                    pickedMesh.setParent(null);
-                    BABYLON.Quaternion.SlerpToRef(pickedMesh.rotationQuaternion, tmpQuaternion, _this.dragDeltaRatio, pickedMesh.rotationQuaternion);
-                    pickedMesh.setParent(oldParent);
-                    BABYLON.BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
+                    if (_this.rotateDraggedObject) {
+                        // Get change in rotation
+                        tmpQuaternion.copyFrom(_this._startingOrientation);
+                        tmpQuaternion.x = -tmpQuaternion.x;
+                        tmpQuaternion.y = -tmpQuaternion.y;
+                        tmpQuaternion.z = -tmpQuaternion.z;
+                        _this._virtualDragMesh.rotationQuaternion.multiplyToRef(tmpQuaternion, tmpQuaternion);
+                        // Convert change in rotation to only y axis rotation
+                        BABYLON.Quaternion.RotationYawPitchRollToRef(tmpQuaternion.toEulerAngles("xyz").y, 0, 0, tmpQuaternion);
+                        tmpQuaternion.multiplyToRef(_this._startingOrientation, tmpQuaternion);
+                        // Slowly move mesh to avoid jitter
+                        var oldParent = pickedMesh.parent;
+                        pickedMesh.setParent(null);
+                        BABYLON.Quaternion.SlerpToRef(pickedMesh.rotationQuaternion, tmpQuaternion, _this.dragDeltaRatio, pickedMesh.rotationQuaternion);
+                        pickedMesh.setParent(oldParent);
+                        BABYLON.BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
+                    }
                 }
             });
         };

+ 15 - 1
dist/preview release/viewer/babylon.viewer.d.ts

@@ -924,7 +924,7 @@ declare module BabylonViewer {
       * @param name the name of the custom optimizer configuration
       * @param upgrade set to true if you want to upgrade optimizer and false if you want to degrade
       */
-    export function getCustomOptimizerByName(name: string, upgrade?: boolean): (sceneManager: SceneManager) => boolean;
+    export function getCustomOptimizerByName(name: string, upgrade?: boolean): typeof extendedUpgrade;
     export function registerCustomOptimizer(name: string, optimizer: (sceneManager: SceneManager) => boolean): void;
 }
 declare module BabylonViewer {
@@ -1558,6 +1558,20 @@ declare module BabylonViewer {
     export function addLoaderPlugin(name: string, plugin: ILoaderPlugin): void;
 }
 declare module BabylonViewer {
+    /**
+        * A custom upgrade-oriented function configuration for the scene optimizer.
+        *
+        * @param viewer the viewer to optimize
+        */
+    export function extendedUpgrade(sceneManager: SceneManager): boolean;
+    /**
+        * A custom degrade-oriented function configuration for the scene optimizer.
+        *
+        * @param viewer the viewer to optimize
+        */
+    export function extendedDegrade(sceneManager: SceneManager): boolean;
+}
+declare module BabylonViewer {
 }
 declare module BabylonViewer {
     export interface IEnvironmentMapConfiguration {

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/viewer/babylon.viewer.js


File diff suppressed because it is too large
+ 1 - 1
dist/preview release/viewer/babylon.viewer.max.js


+ 18 - 1
dist/preview release/viewer/babylon.viewer.module.d.ts

@@ -986,13 +986,14 @@ declare module 'babylonjs-viewer/templating/viewerTemplatePlugin' {
 }
 
 declare module 'babylonjs-viewer/optimizer/custom' {
+    import { extendedUpgrade } from "babylonjs-viewer/optimizer/custom/extended";
     import { SceneManager } from "babylonjs-viewer/managers/sceneManager";
     /**
       *
       * @param name the name of the custom optimizer configuration
       * @param upgrade set to true if you want to upgrade optimizer and false if you want to degrade
       */
-    export function getCustomOptimizerByName(name: string, upgrade?: boolean): (sceneManager: SceneManager) => boolean;
+    export function getCustomOptimizerByName(name: string, upgrade?: boolean): typeof extendedUpgrade;
     export function registerCustomOptimizer(name: string, optimizer: (sceneManager: SceneManager) => boolean): void;
 }
 
@@ -1663,6 +1664,22 @@ declare module 'babylonjs-viewer/loader/plugins' {
     export function addLoaderPlugin(name: string, plugin: ILoaderPlugin): void;
 }
 
+declare module 'babylonjs-viewer/optimizer/custom/extended' {
+    import { SceneManager } from 'babylonjs-viewer/managers/sceneManager';
+    /**
+        * A custom upgrade-oriented function configuration for the scene optimizer.
+        *
+        * @param viewer the viewer to optimize
+        */
+    export function extendedUpgrade(sceneManager: SceneManager): boolean;
+    /**
+        * A custom degrade-oriented function configuration for the scene optimizer.
+        *
+        * @param viewer the viewer to optimize
+        */
+    export function extendedDegrade(sceneManager: SceneManager): boolean;
+}
+
 declare module 'babylonjs-viewer/configuration/interfaces' {
     export * from 'babylonjs-viewer/configuration/interfaces/cameraConfiguration';
     export * from 'babylonjs-viewer/configuration/interfaces/colorGradingConfiguration';

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

@@ -71,7 +71,7 @@
 - Added support for overriding the mesh used for the world matrix for a mesh with a skeleton ([bghgary](https://github.com/bghgary))
 - Added support for linking a bone to a transform node ([bghgary](https://github.com/bghgary))
 - Factored out `setDirection` function from `lookAt` for transform node ([bghgary](https://github.com/bghgary))
-- Added support for AmmoJS physics plugin ([TrevorDev](https://github.com/TrevorDev))
+- Added support for AmmoJS as a physics plugin ([TrevorDev](https://github.com/TrevorDev))
 - Add support for setting renderingGroupId and creating instances to `AxesViewer` ([bghgary](https://github.com/bghgary))
 - Invert vScale of compressed ktx textures as they are inverted in the file and UNPACK_FLIP_Y_WEBGL is not supported by ktx ([TrevorDev](https://github.com/TrevorDev))
 
@@ -108,6 +108,7 @@
 - MakeNotPickableAndWrapInBoundingBox had unexpected behavior when input had scaling of 0 on an axis ([TrevorDev](https://github.com/TrevorDev))
 - Fixed an issue with loading base64 encoded images in the glTF loader ([bghgary](https://github.com/bghgary))
 - In multi-camera scenes the inspector would cause the camera's interaction events to get detached ([TrevorDev](https://github.com/TrevorDev))
+- SixDofDragBehavior will support when the camera is parented ([TrevorDev](https://github.com/TrevorDev))
 
 ### Core Engine
 - Fixed a bug with `mesh.alwaysSelectAsActiveMesh` preventing layerMask to be taken in account ([Deltakosh](https://github.com/deltakosh))

+ 20 - 15
inspector/src/inspector.ts

@@ -88,7 +88,6 @@ export class Inspector {
             }
 
             if (!options.overlay) {
-                this._SceneExplorerHost.style.gridColumn = "1";
                 this._SceneExplorerHost.style.position = "relative";
             }
         }
@@ -146,7 +145,6 @@ export class Inspector {
             this._ActionTabsHost = host;
 
             if (!options.overlay) {
-                this._ActionTabsHost.style.gridColumn = "3";
                 this._ActionTabsHost.style.position = "relative";
             }
         }
@@ -201,7 +199,6 @@ export class Inspector {
             this._EmbedHost = host;
 
             if (!options.overlay) {
-                this._EmbedHost.style.gridColumn = "2";
                 this._EmbedHost.style.position = "relative";
             }
         }
@@ -342,11 +339,7 @@ export class Inspector {
                 let parentControl = (options.globalRoot ? options.globalRoot : canvas!.parentElement) as HTMLElement;
 
                 if (!options.overlay && !this._NewCanvasContainer) {
-
                     this._CreateCanvasContainer(parentControl);
-                    parentControl.style.gridTemplateColumns = "1fr auto";
-                    this._NewCanvasContainer!.style.gridColumn = "1";
-
                 } else if (!options.overlay && this._NewCanvasContainer && this._NewCanvasContainer.parentElement) {
                     // the root is now the parent of the canvas container
                     parentControl = this._NewCanvasContainer.parentElement;
@@ -381,9 +374,7 @@ export class Inspector {
             let parentControl = (options.globalRoot ? options.globalRoot : canvas!.parentElement) as HTMLElement;
 
             if (!options.overlay && !this._NewCanvasContainer) {
-
                 this._CreateCanvasContainer(parentControl);
-
             } else if (!options.overlay && this._NewCanvasContainer && this._NewCanvasContainer.parentElement) {
                 // the root is now the parent of the canvas container
                 parentControl = this._NewCanvasContainer.parentElement;
@@ -410,11 +401,9 @@ export class Inspector {
 
     private static _CreateCanvasContainer(parentControl: HTMLElement) {
         // Create a container for previous elements
-        parentControl.style.display = "grid";
-        parentControl.style.gridTemplateColumns = "auto 1fr auto";
-        parentControl.style.gridTemplateRows = "100%";
-
         this._NewCanvasContainer = parentControl.ownerDocument!.createElement("div");
+        this._NewCanvasContainer.style.display = parentControl.style.display;
+        parentControl.style.display = "flex";
 
         while (parentControl.childElementCount > 0) {
             var child = parentControl.childNodes[0];
@@ -424,13 +413,29 @@ export class Inspector {
 
         parentControl.appendChild(this._NewCanvasContainer);
 
-        this._NewCanvasContainer.style.gridRow = "1";
-        this._NewCanvasContainer.style.gridColumn = "2";
         this._NewCanvasContainer.style.width = "100%";
         this._NewCanvasContainer.style.height = "100%";
     }
 
+    private static _DestroyCanvasContainer() {
+        const parentControl = this._NewCanvasContainer.parentElement!;
+
+        while (this._NewCanvasContainer.childElementCount > 0) {
+            const child = this._NewCanvasContainer.childNodes[0];
+            this._NewCanvasContainer.removeChild(child);
+            parentControl.appendChild(child);
+        }
+
+        parentControl.removeChild(this._NewCanvasContainer);
+        parentControl.style.display = this._NewCanvasContainer.style.display;
+        delete this._NewCanvasContainer;
+    }
+
     private static _Cleanup() {
+        if (!this._NewCanvasContainer) {
+            this._DestroyCanvasContainer();
+        }
+
         if (Inspector._OpenedPane === 0 && this._OnBeforeRenderObserver && this._Scene) {
             this._Scene.onBeforeRenderObservable.remove(this._OnBeforeRenderObserver);
             this._OnBeforeRenderObserver = null;

+ 24 - 18
src/Behaviors/Meshes/sixDofDragBehavior.ts

@@ -25,7 +25,11 @@ import { Camera } from "Cameras/camera";
         /**
          * How much faster the object should move when the controller is moving towards it. This is useful to bring objects that are far away from the user to them faster. Set this to 0 to avoid any speed increase. (Default: 3)
          */
-         private zDragFactor = 3;
+        private zDragFactor = 3;
+        /**
+         * If the object should rotate to face the drag origin
+         */
+        public rotateDraggedObject = true;
         /**
          * If the behavior is currently in a dragging state
          */
@@ -99,7 +103,7 @@ import { Camera } from "Cameras/camera";
                 if (pointerInfo.type == PointerEventTypes.POINTERDOWN) {
                     if (!this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.hit && pointerInfo.pickInfo.pickedMesh && pointerInfo.pickInfo.ray && pickPredicate(pointerInfo.pickInfo.pickedMesh)) {
                         if (this._scene.activeCamera && this._scene.activeCamera.cameraRigMode == Camera.RIG_MODE_NONE) {
-                            pointerInfo.pickInfo.ray.origin.copyFrom(this._scene.activeCamera!.position);
+                            pointerInfo.pickInfo.ray.origin.copyFrom(this._scene.activeCamera!.globalPosition);
                         }
 
                         pickedMesh = this._ownerNode;
@@ -158,7 +162,7 @@ import { Camera } from "Cameras/camera";
                     if (this.currentDraggingPointerID == (<PointerEvent>pointerInfo.event).pointerId && this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.ray && pickedMesh) {
                         var zDragFactor = this.zDragFactor;
                         if (this._scene.activeCamera && this._scene.activeCamera.cameraRigMode == Camera.RIG_MODE_NONE) {
-                            pointerInfo.pickInfo.ray.origin.copyFrom(this._scene.activeCamera!.position);
+                            pointerInfo.pickInfo.ray.origin.copyFrom(this._scene.activeCamera!.globalPosition);
                             zDragFactor = 0;
                         }
 
@@ -201,21 +205,23 @@ import { Camera } from "Cameras/camera";
                     // Slowly move mesh to avoid jitter
                     pickedMesh.position.addInPlace(this._targetPosition.subtract(pickedMesh.position).scale(this.dragDeltaRatio));
 
-                    // Get change in rotation
-                    tmpQuaternion.copyFrom(this._startingOrientation);
-                    tmpQuaternion.x = -tmpQuaternion.x;
-                    tmpQuaternion.y = -tmpQuaternion.y;
-                    tmpQuaternion.z = -tmpQuaternion.z;
-                    this._virtualDragMesh.rotationQuaternion!.multiplyToRef(tmpQuaternion, tmpQuaternion);
-                    // Convert change in rotation to only y axis rotation
-                    Quaternion.RotationYawPitchRollToRef(tmpQuaternion.toEulerAngles("xyz").y, 0, 0, tmpQuaternion);
-                    tmpQuaternion.multiplyToRef(this._startingOrientation, tmpQuaternion);
-                    // Slowly move mesh to avoid jitter
-                    var oldParent = pickedMesh.parent;
-                    pickedMesh.setParent(null);
-                    Quaternion.SlerpToRef(pickedMesh.rotationQuaternion!, tmpQuaternion, this.dragDeltaRatio, pickedMesh.rotationQuaternion!);
-                    pickedMesh.setParent(oldParent);
-                    BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
+                    if (this.rotateDraggedObject) {
+                        // Get change in rotation
+                        tmpQuaternion.copyFrom(this._startingOrientation);
+                        tmpQuaternion.x = -tmpQuaternion.x;
+                        tmpQuaternion.y = -tmpQuaternion.y;
+                        tmpQuaternion.z = -tmpQuaternion.z;
+                        this._virtualDragMesh.rotationQuaternion!.multiplyToRef(tmpQuaternion, tmpQuaternion);
+                        // Convert change in rotation to only y axis rotation
+                        Quaternion.RotationYawPitchRollToRef(tmpQuaternion.toEulerAngles("xyz").y, 0, 0, tmpQuaternion);
+                        tmpQuaternion.multiplyToRef(this._startingOrientation, tmpQuaternion);
+                        // Slowly move mesh to avoid jitter
+                        var oldParent = pickedMesh.parent;
+                        pickedMesh.setParent(null);
+                        Quaternion.SlerpToRef(pickedMesh.rotationQuaternion!, tmpQuaternion, this.dragDeltaRatio, pickedMesh.rotationQuaternion!);
+                        pickedMesh.setParent(oldParent);
+                        BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
+                    }
                 }
             });
         }

+ 38 - 4
src/Physics/Plugins/ammoJSPlugin.ts

@@ -29,6 +29,7 @@ import { AbstractMesh } from "Meshes/abstractMesh";
         public name: string = "AmmoJSPlugin";
 
         private _timeStep: number = 1 / 60;
+        private _fixedTimeStep: number = 1 / 60;
         private _maxSteps = 5;
         private _tmpQuaternion = new Quaternion();
         private _tmpAmmoTransform: any;
@@ -43,6 +44,7 @@ import { AbstractMesh } from "Meshes/abstractMesh";
         private _tmpAmmoVectorC: any;
         private _tmpContactCallbackResult = false;
 
+        private static readonly DISABLE_COLLISION_FLAG = 4;
         private static readonly KINEMATIC_FLAG = 2;
         private static readonly DISABLE_DEACTIVATION_FLAG = 4;
 
@@ -96,6 +98,22 @@ import { AbstractMesh } from "Meshes/abstractMesh";
         }
 
         /**
+         * Increment to step forward in the physics engine (If timeStep is set to 1/60 and fixedTimeStep is set to 1/120 the physics engine should run 2 steps per frame) (Default: 1/60)
+         * @param fixedTimeStep fixedTimeStep to use in seconds
+         */
+        public setFixedTimeStep(fixedTimeStep: number) {
+            this._fixedTimeStep = fixedTimeStep;
+        }
+
+        /**
+         * Sets the maximum number of steps by the physics engine per frame (Default: 5)
+         * @param maxSteps the maximum number of steps by the physics engine per frame
+         */
+        public setMaxSteps(maxSteps: number) {
+            this._maxSteps = maxSteps;
+        }
+
+        /**
          * Gets the current timestep (only used if useDeltaForWorldStep is false in the constructor)
          * @returns the current timestep in seconds
          */
@@ -154,7 +172,7 @@ import { AbstractMesh } from "Meshes/abstractMesh";
                 impostor.beforeStep();
             }
 
-            this._stepSimulation(this._useDeltaForWorldStep ? delta : this._timeStep, this._maxSteps);
+            this._stepSimulation(this._useDeltaForWorldStep ? delta : this._timeStep, this._maxSteps, this._fixedTimeStep);
 
             for (var mainImpostor of impostors) {
                 // After physics update make babylon world objects match physics world objects
@@ -248,6 +266,11 @@ import { AbstractMesh } from "Meshes/abstractMesh";
                     body.setActivationState(AmmoJSPlugin.DISABLE_DEACTIVATION_FLAG);
                 }
 
+                // Disable collision if NoImpostor, but keep collision if shape is btCompoundShape
+                if (impostor.type == BABYLON.PhysicsImpostor.NoImpostor && !colShape.getChildShape) {
+                    body.setCollisionFlags(body.getCollisionFlags() | AmmoJSPlugin.DISABLE_COLLISION_FLAG);
+                }
+
                 body.setRestitution(impostor.getParam("restitution"));
                 this.world.addRigidBody(body);
                 impostor.physicsBody = body;
@@ -308,7 +331,9 @@ import { AbstractMesh } from "Meshes/abstractMesh";
          * @param impostorJoint the imposter joint to remove the joint from
          */
         public removeJoint(impostorJoint: PhysicsImpostorJoint) {
-            this.world.removeConstraint(impostorJoint.joint.physicsJoint);
+            if (this.world) {
+                this.world.removeConstraint(impostorJoint.joint.physicsJoint);
+            }
         }
 
         // adds all verticies (including child verticies) to the triangle mesh
@@ -370,7 +395,13 @@ import { AbstractMesh } from "Meshes/abstractMesh";
                         var childImpostor = childMesh.getPhysicsImpostor();
                         if (childImpostor) {
                             var shape = this._createShape(childImpostor);
-                            this._tmpAmmoTransform.getOrigin().setValue(childMesh.position.x, childMesh.position.y, childMesh.position.z);
+
+                            // Position needs to be scaled based on parent's scaling
+                            var parentMat = childMesh.parent!.getWorldMatrix().clone();
+                            var s = new BABYLON.Vector3();
+                            parentMat.decompose(s);
+                            this._tmpAmmoTransform.getOrigin().setValue(childMesh.position.x * s.x, childMesh.position.y * s.y, childMesh.position.z * s.z);
+
                             this._tmpAmmoQuaternion.setValue(childMesh.rotationQuaternion!.x, childMesh.rotationQuaternion!.y, childMesh.rotationQuaternion!.z, childMesh.rotationQuaternion!.w);
                             this._tmpAmmoTransform.setRotation(this._tmpAmmoQuaternion);
                             returnValue.addChildShape(this._tmpAmmoTransform, shape);
@@ -382,7 +413,6 @@ import { AbstractMesh } from "Meshes/abstractMesh";
                     var shape = this._createShape(impostor, true);
                     if (shape) {
                         this._tmpAmmoTransform.getOrigin().setValue(0, 0, 0);
-                        //this._tmpAmmoQuaternion = new this.BJSAMMO.btQuaternion(0,0,0,1);
                         this._tmpAmmoQuaternion.setValue(0, 0, 0, 1);
                         this._tmpAmmoTransform.setRotation(this._tmpAmmoQuaternion);
 
@@ -416,6 +446,10 @@ import { AbstractMesh } from "Meshes/abstractMesh";
                         returnValue = new Ammo.btBvhTriangleMeshShape(tetraMesh);
                     }
                     break;
+                case PhysicsImpostor.NoImpostor:
+                    // Fill with sphere but collision is disabled on the rigid body in generatePhysicsBody, using an empty shape caused unexpected movement with joints
+                    returnValue = new Ammo.btSphereShape(extendSize.x / 2);
+                    break;
             }
 
             return returnValue;