فهرست منبع

Fixing small issues with ArcRotateCamera and collisions
Cleaning generated JS a bit

David Catuhe 10 سال پیش
والد
کامیت
207da149bd

+ 31 - 9
Babylon/Cameras/babylon.arcRotateCamera.js

@@ -1,4 +1,4 @@
-var __extends = this.__extends || function (d, b) {
+var __extends = (this && this.__extends) || function (d, b) {
     for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
     function __() { this.constructor = d; }
     __.prototype = b.prototype;
@@ -51,8 +51,6 @@ var BABYLON;
                 }
                 if (!collidedMesh) {
                     _this._previousPosition.copyFrom(_this.position);
-                    _this.setPosition(_this._newPosition);
-                    _this.position.copyFrom(_this._newPosition);
                 }
                 else {
                     _this.setPosition(_this.position);
@@ -60,12 +58,20 @@ var BABYLON;
                         _this.onCollide(collidedMesh);
                     }
                 }
+                // Recompute because of constraints
+                var cosa = Math.cos(_this.alpha);
+                var sina = Math.sin(_this.alpha);
+                var cosb = Math.cos(_this.beta);
+                var sinb = Math.sin(_this.beta);
+                var target = _this._getTargetPosition();
+                target.addToRef(new BABYLON.Vector3(_this.radius * cosa * sinb, _this.radius * cosb, _this.radius * sina * sinb), _this._newPosition);
+                _this.position.copyFrom(_this._newPosition);
                 var up = _this.upVector;
                 if (_this.allowUpsideDown && _this.beta < 0) {
                     var up = up.clone();
                     up = up.negate();
                 }
-                BABYLON.Matrix.LookAtLHToRef(_this.position, _this._getTargetPosition(), up, _this._viewMatrix);
+                BABYLON.Matrix.LookAtLHToRef(_this.position, target, up, _this._viewMatrix);
                 _this._viewMatrix.m[12] += _this.targetScreenOffset.x;
                 _this._viewMatrix.m[13] += _this.targetScreenOffset.y;
                 _this._collisionTriggered = false;
@@ -101,7 +107,11 @@ var BABYLON;
         ArcRotateCamera.prototype._isSynchronizedViewMatrix = function () {
             if (!_super.prototype._isSynchronizedViewMatrix.call(this))
                 return false;
-            return this._cache.target.equals(this._getTargetPosition()) && this._cache.alpha === this.alpha && this._cache.beta === this.beta && this._cache.radius === this.radius && this._cache.targetScreenOffset.equals(this.targetScreenOffset);
+            return this._cache.target.equals(this._getTargetPosition())
+                && this._cache.alpha === this.alpha
+                && this._cache.beta === this.beta
+                && this._cache.radius === this.radius
+                && this._cache.targetScreenOffset.equals(this.targetScreenOffset);
         };
         // Methods
         ArcRotateCamera.prototype.attachControl = function (element, noPreventDefault) {
@@ -196,7 +206,10 @@ var BABYLON;
                     }
                 };
                 this._onKeyDown = function (evt) {
-                    if (_this.keysUp.indexOf(evt.keyCode) !== -1 || _this.keysDown.indexOf(evt.keyCode) !== -1 || _this.keysLeft.indexOf(evt.keyCode) !== -1 || _this.keysRight.indexOf(evt.keyCode) !== -1) {
+                    if (_this.keysUp.indexOf(evt.keyCode) !== -1 ||
+                        _this.keysDown.indexOf(evt.keyCode) !== -1 ||
+                        _this.keysLeft.indexOf(evt.keyCode) !== -1 ||
+                        _this.keysRight.indexOf(evt.keyCode) !== -1) {
                         var index = _this._keys.indexOf(evt.keyCode);
                         if (index === -1) {
                             _this._keys.push(evt.keyCode);
@@ -209,7 +222,10 @@ var BABYLON;
                     }
                 };
                 this._onKeyUp = function (evt) {
-                    if (_this.keysUp.indexOf(evt.keyCode) !== -1 || _this.keysDown.indexOf(evt.keyCode) !== -1 || _this.keysLeft.indexOf(evt.keyCode) !== -1 || _this.keysRight.indexOf(evt.keyCode) !== -1) {
+                    if (_this.keysUp.indexOf(evt.keyCode) !== -1 ||
+                        _this.keysDown.indexOf(evt.keyCode) !== -1 ||
+                        _this.keysLeft.indexOf(evt.keyCode) !== -1 ||
+                        _this.keysRight.indexOf(evt.keyCode) !== -1) {
                         var index = _this._keys.indexOf(evt.keyCode);
                         if (index >= 0) {
                             _this._keys.splice(index, 1);
@@ -300,6 +316,7 @@ var BABYLON;
             if (this._collisionTriggered) {
                 return;
             }
+            // Keyboard
             for (var index = 0; index < this._keys.length; index++) {
                 var keyCode = this._keys[index];
                 if (this.keysLeft.indexOf(keyCode) !== -1) {
@@ -331,6 +348,10 @@ var BABYLON;
                     this.inertialRadiusOffset = 0;
             }
             // Limits
+            this._checkLimits();
+            _super.prototype._checkInputs.call(this);
+        };
+        ArcRotateCamera.prototype._checkLimits = function () {
             if (this.lowerBetaLimit === null || this.lowerBetaLimit === undefined) {
                 if (this.allowUpsideDown && this.beta > Math.PI) {
                     this.beta = this.beta - (2 * Math.PI);
@@ -363,7 +384,6 @@ var BABYLON;
             if (this.upperRadiusLimit && this.radius > this.upperRadiusLimit) {
                 this.radius = this.upperRadiusLimit;
             }
-            _super.prototype._checkInputs.call(this);
         };
         ArcRotateCamera.prototype.setPosition = function (position) {
             var radiusv3 = position.subtract(this._getTargetPosition());
@@ -375,6 +395,7 @@ var BABYLON;
             }
             // Beta
             this.beta = Math.acos(radiusv3.y / this.radius);
+            this._checkLimits();
         };
         ArcRotateCamera.prototype._getViewMatrix = function () {
             // Compute
@@ -397,7 +418,7 @@ var BABYLON;
                     var up = up.clone();
                     up = up.negate();
                 }
-                BABYLON.Matrix.LookAtLHToRef(this.position, target, this.upVector, this._viewMatrix);
+                BABYLON.Matrix.LookAtLHToRef(this.position, target, up, this._viewMatrix);
                 this._viewMatrix.m[12] += this.targetScreenOffset.x;
                 this._viewMatrix.m[13] += this.targetScreenOffset.y;
             }
@@ -450,3 +471,4 @@ var BABYLON;
     })(BABYLON.Camera);
     BABYLON.ArcRotateCamera = ArcRotateCamera;
 })(BABYLON || (BABYLON = {}));
+//# sourceMappingURL=babylon.arcRotateCamera.js.map

+ 33 - 20
Babylon/Cameras/babylon.arcRotateCamera.ts

@@ -375,6 +375,12 @@
             }
 
             // Limits
+            this._checkLimits();
+
+            super._checkInputs();
+        }
+
+        private _checkLimits() {
             if (this.lowerBetaLimit === null || this.lowerBetaLimit === undefined) {
                 if (this.allowUpsideDown && this.beta > Math.PI) {
                     this.beta = this.beta - (2 * Math.PI);
@@ -408,8 +414,6 @@
             if (this.upperRadiusLimit && this.radius > this.upperRadiusLimit) {
                 this.radius = this.upperRadiusLimit;
             }
-
-            super._checkInputs();
         }
 
         public setPosition(position: Vector3): void {
@@ -425,6 +429,8 @@
 
             // Beta
             this.beta = Math.acos(radiusv3.y / this.radius);
+
+            this._checkLimits();
         }
 
         public _getViewMatrix(): Matrix {
@@ -443,14 +449,14 @@
                 this.getScene().collisionCoordinator.getNewPosition(this.position, this._collisionVelocity, this._collider, 3, null, this._onCollisionPositionChange, this.uniqueId);
             } else {
                 this.position.copyFrom(this._newPosition);
-				
-				var up = this.upVector;
-				if (this.allowUpsideDown && this.beta < 0) {
-					var up = up.clone();
-					up = up.negate();
-				}
-				
-                BABYLON.Matrix.LookAtLHToRef(this.position, target, this.upVector, this._viewMatrix);
+
+                var up = this.upVector;
+                if (this.allowUpsideDown && this.beta < 0) {
+                    var up = up.clone();
+                    up = up.negate();
+                }
+
+                BABYLON.Matrix.LookAtLHToRef(this.position, target, up, this._viewMatrix);
                 this._viewMatrix.m[12] += this.targetScreenOffset.x;
                 this._viewMatrix.m[13] += this.targetScreenOffset.y;
             }
@@ -465,8 +471,6 @@
 
             if (!collidedMesh) {
                 this._previousPosition.copyFrom(this.position);
-                this.setPosition(this._newPosition);
-                this.position.copyFrom(this._newPosition);
             } else {
                 this.setPosition(this.position);
 
@@ -475,13 +479,22 @@
                 }
             }
 
-			var up = this.upVector;
-			if (this.allowUpsideDown && this.beta < 0) {
-				var up = up.clone();
-				up = up.negate();
-			}
-			
-            Matrix.LookAtLHToRef(this.position, this._getTargetPosition(), up, this._viewMatrix);
+            // Recompute because of constraints
+            var cosa = Math.cos(this.alpha);
+            var sina = Math.sin(this.alpha);
+            var cosb = Math.cos(this.beta);
+            var sinb = Math.sin(this.beta);
+            var target = this._getTargetPosition();
+            target.addToRef(new Vector3(this.radius * cosa * sinb, this.radius * cosb, this.radius * sina * sinb), this._newPosition);
+            this.position.copyFrom(this._newPosition);
+
+            var up = this.upVector;
+            if (this.allowUpsideDown && this.beta < 0) {
+                var up = up.clone();
+                up = up.negate();
+            }
+
+            Matrix.LookAtLHToRef(this.position, target, up, this._viewMatrix);
             this._viewMatrix.m[12] += this.targetScreenOffset.x;
             this._viewMatrix.m[13] += this.targetScreenOffset.y;
 
@@ -543,4 +556,4 @@
             super._updateSubCameras();
         }
     }
-} 
+} 

+ 1 - 1
Babylon/babylon.engine.js

@@ -585,7 +585,7 @@ var BABYLON;
         });
         Object.defineProperty(Engine, "Version", {
             get: function () {
-                return "2.1.0 beta";
+                return "2.1.0";
             },
             enumerable: true,
             configurable: true

+ 1 - 1
Babylon/babylon.engine.ts

@@ -461,7 +461,7 @@
         }
 
         public static get Version(): string {
-            return "2.1.0 beta";
+            return "2.1.0";
         }
 
         // Updatable statics so stick with vars here

+ 10 - 2
Tools/Gulp/gulp-addModuleExports.js

@@ -5,9 +5,17 @@ module.exports = function (varName) {
   return through.obj(function (file, enc, cb) {
 
     var moduleExportsAddition = 
-      '\nif (module && module.exports) {\n' +
+      '\nif (window.module && module.exports) {\n' +
       '    module.exports = ' + varName + ';\n' +
       '};\n';
+      
+      var extendsAddition = 
+      'var __extends = (this && this.__extends) || function (d, b) {\n' +
+        'for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n' +
+        'function __() { this.constructor = d; }\n' +
+        '__.prototype = b.prototype;\n' +
+        'd.prototype = new __();\n' +
+      '};\n';
 
     if (file.isNull()) {
       cb(null, file);
@@ -20,7 +28,7 @@ module.exports = function (varName) {
     }
 
     try {
-      file.contents = new Buffer(String(file.contents).concat(moduleExportsAddition));
+      file.contents = new Buffer(extendsAddition.concat(String(file.contents)).concat(moduleExportsAddition));
       this.push(file);
 
     } catch (err) {

+ 5 - 0
Tools/Gulp/gulpfile.js

@@ -10,12 +10,15 @@ var rename = require("gulp-rename");
 var cleants = require('gulp-clean-ts-extends');
 var changed = require('gulp-changed');
 var runSequence = require('run-sequence');
+var replace = require("gulp-replace")
 
 var config = require("./config.json");
 
 var shadersStream;
 var workersStream;
 
+var extendsSearchRegex = /var\s__extends[\s\S]+?\};/g
+
 //function to convert the shaders' filenames to variable names.
 function shadersName(filename) {
     return filename.replace('.fragment', 'Pixel')
@@ -78,6 +81,7 @@ gulp.task("buildNoWorker", ["shaders"], function () {
     )
     .pipe(concat(config.build.minNoWorkerFilename))
     .pipe(cleants())
+    .pipe(replace(extendsSearchRegex, ""))
     .pipe(addModuleExports("BABYLON"))
     .pipe(uglify())
     .pipe(gulp.dest(config.build.outputDirectory))
@@ -91,6 +95,7 @@ gulp.task("build", ["workers", "shaders"], function () {
     )
     .pipe(concat(config.build.filename))
     .pipe(cleants())
+    .pipe(replace(extendsSearchRegex, ""))
     .pipe(addModuleExports("BABYLON"))
     .pipe(gulp.dest(config.build.outputDirectory))
     .pipe(rename(config.build.minFilename))

+ 2 - 1
Tools/Gulp/package.json

@@ -16,6 +16,7 @@
     "gulp-rename": "~1.2.2",
     "gulp-clean-ts-extends": "~0.1.1",
     "gulp-changed": "~1.2.1",
-    "run-sequence": "~1.1.0"
+    "run-sequence": "~1.1.0",
+    "gulp-replace": "~0.5.3"
   }
 }

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 106 - 379
babylon.2.1-rc.debug.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 27 - 30
babylon.2.1-rc.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 26 - 30
babylon.2.1-rc.noworker.js