Pārlūkot izejas kodu

Getter and Setter for checkCollisions

This will prevent non-updated meshes in the worker's cache, in case a
worker is used as the collision coordinator.
Raanan Weber 10 gadi atpakaļ
vecāks
revīzija
e58bc2d07e

+ 15 - 5
Babylon/Mesh/babylon.abstractMesh.js

@@ -25,7 +25,6 @@ var BABYLON;
             this.showBoundingBox = false;
             this.showSubMeshesBoundingBox = false;
             this.onDispose = null;
-            this.checkCollisions = false;
             this.isBlocker = false;
             this.renderingGroupId = 0;
             this.receiveShadows = false;
@@ -46,6 +45,7 @@ var BABYLON;
             // Physics
             this._physicImpostor = BABYLON.PhysicsEngine.NoImpostor;
             // Collisions
+            this._checkCollisions = false;
             this.ellipsoid = new BABYLON.Vector3(0.5, 1, 0.5);
             this.ellipsoidOffset = new BABYLON.Vector3(0, 0, 0);
             this._collider = new BABYLON.Collider();
@@ -453,7 +453,6 @@ var BABYLON;
             this._updateBoundingInfo();
             // Absolute position
             this._absolutePosition.copyFromFloats(this._worldMatrix.m[12], this._worldMatrix.m[13], this._worldMatrix.m[14]);
-            // Callbacks
             for (var callbackIndex = 0; callbackIndex < this._onAfterWorldMatrixUpdate.length; callbackIndex++) {
                 this._onAfterWorldMatrixUpdate[callbackIndex](this);
             }
@@ -614,7 +613,20 @@ var BABYLON;
             }
             this.getScene().getPhysicsEngine()._updateBodyPosition(this);
         };
-        // Collisions
+        Object.defineProperty(AbstractMesh.prototype, "checkCollisions", {
+            // Collisions
+            get: function () {
+                return this._checkCollisions;
+            },
+            set: function (collisionEnabled) {
+                this._checkCollisions = collisionEnabled;
+                if (this.getScene().workerCollisions) {
+                    this.getScene().collisionCoordinator.onMeshUpdated(this);
+                }
+            },
+            enumerable: true,
+            configurable: true
+        });
         AbstractMesh.prototype.moveWithCollisions = function (velocity) {
             var globalPosition = this.getAbsolutePosition();
             globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPositionForCollisions);
@@ -772,7 +784,6 @@ var BABYLON;
             if (this.getPhysicsImpostor() !== BABYLON.PhysicsEngine.NoImpostor) {
                 this.setPhysicsState(BABYLON.PhysicsEngine.NoImpostor);
             }
-            // Intersections in progress
             for (index = 0; index < this._intersectionsInProgress.length; index++) {
                 var other = this._intersectionsInProgress[index];
                 var pos = other._intersectionsInProgress.indexOf(this);
@@ -784,7 +795,6 @@ var BABYLON;
             // Remove from scene
             this.getScene().removeMesh(this);
             if (!doNotRecurse) {
-                // Particles
                 for (index = 0; index < this.getScene().particleSystems.length; index++) {
                     if (this.getScene().particleSystems[index].emitter === this) {
                         this.getScene().particleSystems[index].dispose();

+ 13 - 1
Babylon/Mesh/babylon.abstractMesh.ts

@@ -42,7 +42,6 @@
         public showBoundingBox = false;
         public showSubMeshesBoundingBox = false;
         public onDispose = null;
-        public checkCollisions = false;
         public isBlocker = false;
         public skeleton: Skeleton;
         public renderingGroupId = 0;
@@ -74,6 +73,7 @@
         public _physicRestitution: number;
 
         // Collisions
+        private _checkCollisions = false;
         public ellipsoid = new Vector3(0.5, 1, 0.5);
         public ellipsoidOffset = new Vector3(0, 0, 0);
         private _collider = new Collider();
@@ -710,6 +710,18 @@
 
 
         // Collisions
+
+        public get checkCollisions() : boolean {
+            return this._checkCollisions;
+        }
+
+        public set checkCollisions(collisionEnabled: boolean) {
+            this._checkCollisions = collisionEnabled;
+            if (this.getScene().workerCollisions) {
+                this.getScene().collisionCoordinator.onMeshUpdated(this);
+            }
+        }
+
         public moveWithCollisions(velocity: Vector3): void {
             var globalPosition = this.getAbsolutePosition();