Explorar o código

New ```mesh.moveWithCollisions``` function. Used with ```mesh.ellipsoid``` this function can be used to move a mesh and use an ellipsoid around it to check collisions

David Catuhe %!s(int64=11) %!d(string=hai) anos
pai
achega
b81fdcf8ad

+ 21 - 0
Babylon/Mesh/babylon.abstractMesh.js

@@ -31,6 +31,12 @@ var BABYLON;
             this.layerMask = 0xFFFFFFFF;
             // Physics
             this._physicImpostor = BABYLON.PhysicsEngine.NoImpostor;
+            // Collisions
+            this.ellipsoid = new BABYLON.Vector3(0.5, 1, 0.5);
+            this._collider = new BABYLON.Collider();
+            this._oldPositionForCollisions = new BABYLON.Vector3(0, 0, 0);
+            this._diffPositionForCollisions = new BABYLON.Vector3(0, 0, 0);
+            this._newPositionForCollisions = new BABYLON.Vector3(0, 0, 0);
             // Cache
             this._localScaling = BABYLON.Matrix.Zero();
             this._localRotation = BABYLON.Matrix.Zero();
@@ -523,6 +529,21 @@ var BABYLON;
             this.getScene().getPhysicsEngine()._createLink(this, otherMesh, pivot1, pivot2);
         };
 
+        // Collisions
+        AbstractMesh.prototype.moveWithCollisions = function (velocity) {
+            var globalPosition = this.getAbsolutePosition();
+
+            globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPositionForCollisions);
+            this._collider.radius = this.ellipsoid;
+
+            this.getScene()._getNewPosition(this._oldPositionForCollisions, velocity, this._collider, 3, this._newPositionForCollisions);
+            this._newPositionForCollisions.subtractToRef(this._oldPositionForCollisions, this._diffPositionForCollisions);
+
+            if (this._diffPositionForCollisions.length() > BABYLON.Engine.CollisionsEpsilon) {
+                this.position.addInPlace(this._diffPositionForCollisions);
+            }
+        };
+
         // Submeshes octree
         /**
         * This function will create an octree to help select the right submeshes for rendering, picking and collisions

+ 22 - 0
Babylon/Mesh/babylon.abstractMesh.ts

@@ -59,6 +59,13 @@
         public _physicsFriction: number;
         public _physicRestitution: number;
 
+        // Collisions
+        public ellipsoid = new BABYLON.Vector3(0.5, 1, 0.5);
+        private _collider = new Collider();
+        private _oldPositionForCollisions = new BABYLON.Vector3(0, 0, 0);
+        private _diffPositionForCollisions = new BABYLON.Vector3(0, 0, 0);
+        private _newPositionForCollisions = new BABYLON.Vector3(0, 0, 0);
+
         // Cache
         private _localScaling = BABYLON.Matrix.Zero();
         private _localRotation = BABYLON.Matrix.Zero();
@@ -518,6 +525,21 @@
             this.getScene().getPhysicsEngine()._createLink(this, otherMesh, pivot1, pivot2);
         }
 
+        // Collisions
+        public moveWithCollisions(velocity: Vector3): void {
+            var globalPosition = this.getAbsolutePosition();
+
+            globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPositionForCollisions);
+            this._collider.radius = this.ellipsoid;
+
+            this.getScene()._getNewPosition(this._oldPositionForCollisions, velocity, this._collider, 3, this._newPositionForCollisions);
+            this._newPositionForCollisions.subtractToRef(this._oldPositionForCollisions, this._diffPositionForCollisions);
+
+            if (this._diffPositionForCollisions.length() > Engine.CollisionsEpsilon) {
+                this.position.addInPlace(this._diffPositionForCollisions);
+            }
+        }
+
         // Submeshes octree
 
         /**

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1 - 1
babylon.1.13-beta-debug.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 3 - 3
babylon.1.13-beta.js