瀏覽代碼

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

sebavan 5 年之前
父節點
當前提交
99e931acea

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

@@ -46,6 +46,9 @@
 ### WebXR
 - Added optional ray and mesh selection predicates to `WebXRControllerPointerSelection` ([Exolun](https://github.com/Exolun))
 
+### Collisions
+- Added an option to optimize collision detection performance ([jsdream](https://github.com/jsdream)) - [PR](https://github.com/BabylonJS/Babylon.js/pull/7810)
+
 ## Bugs
 
 - Fix infinite loop in `GlowLayer.unReferenceMeshFromUsingItsOwnMaterial` ([Popov72](https://github.com/Popov72)
@@ -58,5 +61,6 @@
 - Fix improper baking of transformed textures in `KHR_texture_transform` serializer. ([drigax](https://github.com/Drigax))
 - Fixed NME codegen: missing common properties for float-value input block. ([ycw](https://github.com/ycw))
 - Fixed missing options for MeshBuilder.CreateBox. ([ycw](https://github.com/ycw))
+- Fix bug in `Plane.transform` when matrix passed in is not a pure rotation ([Popov72](https://github.com/Popov72)
 
 ## Breaking changes

+ 6 - 3
src/Collisions/collisionCoordinator.ts

@@ -57,9 +57,12 @@ export class DefaultCollisionCoordinator implements ICollisionCoordinator {
 
         collider._initialize(position, velocity, closeDistance);
 
-        // Check all meshes
-        for (var index = 0; index < this._scene.meshes.length; index++) {
-            var mesh = this._scene.meshes[index];
+        // Check if collision detection should happen against specified list of meshes or,
+        // if not specified, against all meshes in the scene
+        var meshes = (excludedMesh && excludedMesh.surroundingMeshes) || this._scene.meshes;
+
+        for (var index = 0; index < meshes.length; index++) {
+            var mesh = meshes[index];
             if (mesh.isEnabled() && mesh.checkCollisions && mesh.subMeshes && mesh !== excludedMesh && ((collisionMask & mesh.collisionGroup) !== 0)) {
                 mesh._checkCollision(collider);
             }

+ 1 - 0
src/Collisions/meshCollisionData.ts

@@ -12,6 +12,7 @@ export class _MeshCollisionData {
     public _checkCollisions = false;
     public _collisionMask = -1;
     public _collisionGroup = -1;
+    public _surroundingMeshes: Nullable<AbstractMesh[]> = null;
     public _collider: Nullable<Collider> = null;
     public _oldPositionForCollisions = new Vector3(0, 0, 0);
     public _diffPositionForCollisions = new Vector3(0, 0, 0);

+ 3 - 3
src/Maths/math.plane.ts

@@ -78,9 +78,9 @@ export class Plane {
      * @returns a new Plane as the result of the transformation of the current Plane by the given matrix.
      */
     public transform(transformation: DeepImmutable<Matrix>): Plane {
-        const transposedMatrix = Plane._TmpMatrix;
-        Matrix.TransposeToRef(transformation, transposedMatrix);
-        const m = transposedMatrix.m;
+        const invertedMatrix = Plane._TmpMatrix;
+        transformation.invertToRef(invertedMatrix);
+        const m = invertedMatrix.m;
         var x = this.normal.x;
         var y = this.normal.y;
         var z = this.normal.z;

+ 17 - 0
src/Meshes/abstractMesh.ts

@@ -559,6 +559,23 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
         this._meshCollisionData._collisionGroup = !isNaN(mask) ? mask : -1;
     }
 
+    /**
+     * Gets or sets current surrounding meshes (null by default).
+     *
+     * By default collision detection is tested against every mesh in the scene.
+     * It is possible to set surroundingMeshes to a defined list of meshes and then only these specified
+     * meshes will be tested for the collision.
+     *
+     * Note: if set to an empty array no collision will happen when this mesh is moved.
+     */
+    public get surroundingMeshes(): Nullable<AbstractMesh[]> {
+        return this._meshCollisionData._surroundingMeshes;
+    }
+
+    public set surroundingMeshes(meshes: Nullable<AbstractMesh[]>) {
+        this._meshCollisionData._surroundingMeshes = meshes;
+    }
+
     // Edges
     /**
      * Defines edge width used when edgesRenderer is enabled

+ 2 - 2
src/Meshes/transformNode.ts

@@ -1238,7 +1238,7 @@ export class TransformNode extends Node {
             camera = (<Camera>this.getScene().activeCamera);
         }
 
-        return Vector3.TransformCoordinates(this.absolutePosition, camera.getViewMatrix());
+        return Vector3.TransformCoordinates(this.getAbsolutePosition(), camera.getViewMatrix());
     }
 
     /**
@@ -1250,7 +1250,7 @@ export class TransformNode extends Node {
         if (!camera) {
             camera = (<Camera>this.getScene().activeCamera);
         }
-        return this.absolutePosition.subtract(camera.globalPosition).length();
+        return this.getAbsolutePosition().subtract(camera.globalPosition).length();
     }
 
     /**