Browse Source

Merge pull request #5596 from TrevorDev/ammoThrow

Ammo throw
David Catuhe 6 năm trước cách đây
mục cha
commit
2112d28582

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

@@ -115,6 +115,8 @@
 - In multi-camera scenes the inspector would cause the camera's interaction events to get detached ([TrevorDev](https://github.com/TrevorDev))
 - Fix delete highlighted text after keyboard input, beat delay after double click event in InputText ([Saket Saurabh](https://github.com/ssaket))
 - SixDofDragBehavior will support when the camera is parented ([TrevorDev](https://github.com/TrevorDev))
+- Deactivate webvr lasers when not in vr ([TrevorDev](https://github.com/TrevorDev))
+- Update physics position using absolutePosition instead of pivotPosition ([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))

+ 17 - 1
src/Cameras/VR/babylon.vrExperienceHelper.ts

@@ -938,6 +938,14 @@ module BABYLON {
                 this._scene.registerBeforeRender(this.beforeRender);
             }
 
+            if (this._displayLaserPointer) {
+                [this._leftController, this._rightController].forEach((controller) => {
+                    if (controller) {
+                        controller._activatePointer();
+                    }
+                });
+            }
+
             this._hasEnteredVR = true;
         }
 
@@ -1021,6 +1029,12 @@ module BABYLON {
                 // resize to update width and height when exiting vr exits fullscreen
                 this._scene.getEngine().resize();
 
+                [this._leftController, this._rightController].forEach((controller) => {
+                    if (controller) {
+                        controller._deactivatePointer();
+                    }
+                });
+
                 this._hasEnteredVR = false;
             }
         }
@@ -1268,7 +1282,9 @@ module BABYLON {
             if (controllerMesh) {
 
                 controller._interactionsEnabled = true;
-                controller._activatePointer();
+                if (this.isInVRMode && this._displayLaserPointer) {
+                    controller._activatePointer();
+                }
                 if (this.webVROptions.laserToggle) {
                     controller.webVRController.onMainButtonStateChangedObservable.add((stateObject) => {
                         // Enabling / disabling laserPointer

+ 38 - 28
src/Physics/Plugins/babylon.ammoJSPlugin.ts

@@ -379,39 +379,46 @@ module BABYLON {
 
             if (!ignoreChildren) {
                 var meshChildren = impostor.object.getChildMeshes ? impostor.object.getChildMeshes(true) : [];
-                if (meshChildren.length > 0) {
-                    returnValue = new Ammo.btCompoundShape();
-
-                    // Add shape of all children to the compound shape
-                    meshChildren.forEach((childMesh) => {
-                        var childImpostor = childMesh.getPhysicsImpostor();
-                        if (childImpostor) {
-                            var shape = this._createShape(childImpostor);
-
-                            // 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);
-                            childImpostor.dispose();
-                        }
-                    });
-
-                    // Add parents shape as a child if present
-                    var shape = this._createShape(impostor, true);
-                    if (shape) {
-                        this._tmpAmmoTransform.getOrigin().setValue(0, 0, 0);
-                        this._tmpAmmoQuaternion.setValue(0, 0, 0, 1);
+                returnValue = new Ammo.btCompoundShape();
+
+                // Add shape of all children to the compound shape
+                var childrenAdded = 0;
+                meshChildren.forEach((childMesh) => {
+                    var childImpostor = childMesh.getPhysicsImpostor();
+                    if (childImpostor) {
+                        var shape = this._createShape(childImpostor);
+
+                        // 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);
+                        childImpostor.dispose();
+                        childrenAdded++;
                     }
+                });
+
+                if (childrenAdded > 0) {
+                    // Add parents shape as a child if present
+                    if (impostor.type != PhysicsImpostor.NoImpostor) {
+                        var shape = this._createShape(impostor, true);
+                        if (shape) {
+                            this._tmpAmmoTransform.getOrigin().setValue(0, 0, 0);
+                            this._tmpAmmoQuaternion.setValue(0, 0, 0, 1);
+                            this._tmpAmmoTransform.setRotation(this._tmpAmmoQuaternion);
 
+                            returnValue.addChildShape(this._tmpAmmoTransform, shape);
+                        }
+                    }
                     return returnValue;
+                }else {
+                    // If no children with impostors create the actual shape below instead
+                    Ammo.destroy(returnValue);
+                    returnValue = null;
                 }
             }
 
@@ -442,6 +449,9 @@ module BABYLON {
                     // 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;
+                default:
+                    Tools.Warn("The impostor type is not currently supported by the ammo plugin.");
+                    break;
             }
 
             return returnValue;

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

@@ -638,7 +638,7 @@ module BABYLON {
                 this._tmpQuat.copyFrom(this.object.rotationQuaternion || new Quaternion());
             }
             if (!this._options.disableBidirectionalTransformation) {
-                this.object.rotationQuaternion && this._physicsEngine.getPhysicsPlugin().setPhysicsBodyTransformation(this, /*bInfo.boundingBox.centerWorld*/ this.object.getAbsolutePivotPoint(), this._tmpQuat);
+                this.object.rotationQuaternion && this._physicsEngine.getPhysicsPlugin().setPhysicsBodyTransformation(this, /*bInfo.boundingBox.centerWorld*/ this.object.getAbsolutePosition(), this._tmpQuat);
             }
 
             this._onBeforePhysicsStepCallbacks.forEach((func) => {