Bläddra i källkod

Fixing a bug with getAspectRatio

David Catuhe 11 år sedan
förälder
incheckning
03912d42ba

+ 3 - 3
Babylon/Cameras/babylon.camera.js

@@ -93,7 +93,7 @@ var BABYLON = BABYLON || {};
         this._cache.maxZ = this.maxZ;
 
         this._cache.fov = this.fov;
-        this._cache.aspectRatio = engine.getAspectRatio();
+        this._cache.aspectRatio = engine.getAspectRatio(this);
 
         this._cache.orthoLeft = this.orthoLeft;
         this._cache.orthoRight = this.orthoRight;
@@ -135,7 +135,7 @@ var BABYLON = BABYLON || {};
 
         if (this.mode === BABYLON.Camera.PERSPECTIVE_CAMERA) {
             check = this._cache.fov === this.fov
-                 && this._cache.aspectRatio === engine.getAspectRatio();
+                 && this._cache.aspectRatio === engine.getAspectRatio(this);
         }
         else {
             check = this._cache.orthoLeft === this.orthoLeft
@@ -304,7 +304,7 @@ var BABYLON = BABYLON || {};
 
         var engine = this._scene.getEngine();
         if (this.mode === BABYLON.Camera.PERSPECTIVE_CAMERA) {
-            BABYLON.Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(), this.minZ, this.maxZ, this._projectionMatrix);
+            BABYLON.Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(this), this.minZ, this.maxZ, this._projectionMatrix);
             return this._projectionMatrix;
         }
 

+ 71 - 0
Babylon/Tools/babylon.sceneSerializer.js

@@ -0,0 +1,71 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+
+    var serializeLight = function (light, serializationObject) {
+        serializationObject.name = light.name;
+
+        if (light instanceof BABYLON.PointLight) {
+            serializationObject.type = 0;
+            serializationObject.position = light.position.asArray();
+        }
+        //switch (light.type) {
+        //    case 1:
+        //        light = new BABYLON.DirectionalLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.direction), scene);
+        //        light.position = BABYLON.Vector3.FromArray(parsedLight.position);
+        //        break;
+        //    case 2:
+        //        light = new BABYLON.SpotLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.position), BABYLON.Vector3.FromArray(parsedLight.direction), parsedLight.angle, parsedLight.exponent, scene);
+        //        break;
+        //    case 3:
+        //        light = new BABYLON.HemisphericLight(parsedLight.name, BABYLON.Vector3.FromArray(parsedLight.direction), scene);
+        //        light.groundColor = BABYLON.Color3.FromArray(parsedLight.groundColor);
+        //        break;
+        //}
+
+        serializationObject.id = light.id;
+
+        if (light.intensity) {
+            serializationObject.intensity = light.intensity;
+        }
+        serializationObject.diffuse = light.diffuse.asArray();
+        serializationObject.specular = light.specular.asArray();
+    };
+
+    BABYLON.SceneSerializer = {
+        Serialize: function (scene) {
+            var serializationObject = {};
+
+            // Scene
+            serializationObject.useDelayedTextureLoading = scene.useDelayedTextureLoading;
+            serializationObject.autoClear = scene.autoClear;
+            serializationObject.clearColor = scene.clearColor.asArray();
+            serializationObject.ambientColor = scene.ambientColor.asArray();
+            serializationObject.gravity = scene.gravity.asArray();
+
+            // Fog
+            if (scene.fogMode && scene.fogMode !== 0) {
+                serializationObject.fogMode = scene.fogMode;
+                serializationObject.fogColor = scene.fogColor.asArray();
+                serializationObject.fogStart = scene.fogStart;
+                serializationObject.fogEnd = scene.fogEnd;
+                serializationObject.fogDensity = scene.fogDensity;
+            }
+
+            // Lights
+            serializationObject.lights = [];
+            for (var index = 0; index < scene.lights.length; index++) {
+                var light = scene.lights[index];
+                
+                var serializedLight = {};
+                serializationObject.lights.push(serializedLight);
+
+                serializeLight(light, serializedLight);
+            }
+
+            return JSON.stringify(serializationObject);
+        }
+    };
+})();

+ 4 - 6
Babylon/babylon.engine.js

@@ -109,8 +109,9 @@ var BABYLON = BABYLON || {};
     };
 
     // Properties
-    BABYLON.Engine.prototype.getAspectRatio = function () {
-        return this._aspectRatio;
+    BABYLON.Engine.prototype.getAspectRatio = function (camera) {
+        var viewport = camera.viewport;
+        return (this._renderingCanvas.width * viewport.width) / (this._renderingCanvas.height * viewport.height);;
     };
 
     BABYLON.Engine.prototype.getRenderWidth = function () {
@@ -210,15 +211,13 @@ var BABYLON = BABYLON || {};
         
         this._cachedViewport = viewport;
         
-        this._gl.viewport(x * width, y * height, width * viewport.width, height * viewport.height);
-        this._aspectRatio = (width * viewport.width) / (height * viewport.height);
+        this._gl.viewport(x * width, y * height, width * viewport.width, height * viewport.height);        
     };
     
     BABYLON.Engine.prototype.setDirectViewport = function (x, y, width, height) {
         this._cachedViewport = null;
 
         this._gl.viewport(x, y, width, height);
-        this._aspectRatio = width / height;
     };
 
     BABYLON.Engine.prototype.beginFrame = function () {
@@ -238,7 +237,6 @@ var BABYLON = BABYLON || {};
         var gl = this._gl;
         gl.bindFramebuffer(gl.FRAMEBUFFER, texture._framebuffer);
         this._gl.viewport(0, 0, texture._width, texture._height);
-        this._aspectRatio = texture._width / texture._height;
 
         this.wipeCaches();
     };

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
babylon.1.8.5.js