Bläddra i källkod

Minor Tweaks.

Sebastien Vandenberghe 8 år sedan
förälder
incheckning
c6388f8528

+ 4 - 4
src/Audio/babylon.sound.ts

@@ -289,14 +289,14 @@ module BABYLON {
                     this._soundPanner.maxDistance = Number.MAX_VALUE;
                     this._soundPanner.maxDistance = Number.MAX_VALUE;
                     this._soundPanner.refDistance = 1;
                     this._soundPanner.refDistance = 1;
                     this._soundPanner.rolloffFactor = 1;
                     this._soundPanner.rolloffFactor = 1;
-                    this._soundPanner.panningModel = this._panningModel;
+                    this._soundPanner.panningModel = this._panningModel as any;
                 }
                 }
                 else {
                 else {
-                    this._soundPanner.distanceModel = this.distanceModel;
+                    this._soundPanner.distanceModel = this.distanceModel as any;
                     this._soundPanner.maxDistance = this.maxDistance;
                     this._soundPanner.maxDistance = this.maxDistance;
                     this._soundPanner.refDistance = this.refDistance;
                     this._soundPanner.refDistance = this.refDistance;
                     this._soundPanner.rolloffFactor = this.rolloffFactor;
                     this._soundPanner.rolloffFactor = this.rolloffFactor;
-                    this._soundPanner.panningModel = this._panningModel;
+                    this._soundPanner.panningModel = this._panningModel as any;
                 }
                 }
             }
             }
         }
         }
@@ -313,7 +313,7 @@ module BABYLON {
 
 
         private _switchPanningModel() {
         private _switchPanningModel() {
             if (Engine.audioEngine.canUseWebAudio && this.spatialSound) {
             if (Engine.audioEngine.canUseWebAudio && this.spatialSound) {
-                this._soundPanner.panningModel = this._panningModel;
+                this._soundPanner.panningModel = this._panningModel as any;
             }
             }
         }
         }
 
 

+ 3 - 1
src/Materials/Textures/babylon.baseTexture.ts

@@ -1,5 +1,7 @@
 module BABYLON {
 module BABYLON {
     export class BaseTexture {
     export class BaseTexture {
+        public static DEFAULT_ANISOTROPIC_FILTERING_LEVEL = 4;
+
         @serialize()
         @serialize()
         public name: string;
         public name: string;
 
 
@@ -45,7 +47,7 @@
         public wrapV = Texture.WRAP_ADDRESSMODE;
         public wrapV = Texture.WRAP_ADDRESSMODE;
 
 
         @serialize()
         @serialize()
-        public anisotropicFilteringLevel = 4;
+        public anisotropicFilteringLevel = BaseTexture.DEFAULT_ANISOTROPIC_FILTERING_LEVEL;
 
 
         @serialize()
         @serialize()
         public isCube = false;
         public isCube = false;

+ 12 - 7
src/Materials/Textures/babylon.renderTargetTexture.ts

@@ -1,4 +1,12 @@
 module BABYLON {
 module BABYLON {
+    export interface IRenderTargetOptions {
+        generateMipMaps: boolean,
+        type: number,
+        samplingMode: number,
+        generateDepthBuffer: boolean,
+        generateStencilBuffer: boolean
+    }
+
     export class RenderTargetTexture extends Texture {
     export class RenderTargetTexture extends Texture {
         public static _REFRESHRATE_RENDER_ONCE: number = 0;
         public static _REFRESHRATE_RENDER_ONCE: number = 0;
         public static _REFRESHRATE_RENDER_ONEVERYFRAME: number = 1;
         public static _REFRESHRATE_RENDER_ONEVERYFRAME: number = 1;
@@ -100,13 +108,10 @@
         private _refreshRate = 1;
         private _refreshRate = 1;
         private _textureMatrix: Matrix;
         private _textureMatrix: Matrix;
         private _samples = 1;
         private _samples = 1;
-        protected _renderTargetOptions: {
-            generateMipMaps: boolean,
-            type: number,
-            samplingMode: number,
-            generateDepthBuffer: boolean,
-            generateStencilBuffer: boolean
-        };
+        protected _renderTargetOptions: IRenderTargetOptions;
+        public get renderTargetOptions(): IRenderTargetOptions {
+            return this._renderTargetOptions;
+        }
 
 
         constructor(name: string, size: any, scene: Scene, generateMipMaps?: boolean, doNotChangeAspectRatio: boolean = true, type: number = Engine.TEXTURETYPE_UNSIGNED_INT, public isCube = false, samplingMode = Texture.TRILINEAR_SAMPLINGMODE, generateDepthBuffer = true, generateStencilBuffer = false) {
         constructor(name: string, size: any, scene: Scene, generateMipMaps?: boolean, doNotChangeAspectRatio: boolean = true, type: number = Engine.TEXTURETYPE_UNSIGNED_INT, public isCube = false, samplingMode = Texture.TRILINEAR_SAMPLINGMODE, generateDepthBuffer = true, generateStencilBuffer = false) {
             super(null, scene, !generateMipMaps);
             super(null, scene, !generateMipMaps);

+ 4 - 2
src/PostProcess/babylon.postProcess.ts

@@ -27,6 +27,7 @@
         private _effect: Effect;
         private _effect: Effect;
         private _samplers: string[];
         private _samplers: string[];
         private _fragmentUrl: string;
         private _fragmentUrl: string;
+        private _vertexUrl: string;
         private _parameters: string[];
         private _parameters: string[];
         private _scaleRatio = new Vector2(1, 1);
         private _scaleRatio = new Vector2(1, 1);
 
 
@@ -102,7 +103,7 @@
             this._onAfterRenderObserver = this.onAfterRenderObservable.add(callback);
             this._onAfterRenderObserver = this.onAfterRenderObservable.add(callback);
         }
         }
 
 
-        constructor(public name: string, fragmentUrl: string, parameters: string[], samplers: string[], options: number | PostProcessOptions, camera: Camera, samplingMode: number = Texture.NEAREST_SAMPLINGMODE, engine?: Engine, reusable?: boolean, defines?: string, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
+        constructor(public name: string, fragmentUrl: string, parameters: string[], samplers: string[], options: number | PostProcessOptions, camera: Camera, samplingMode: number = Texture.NEAREST_SAMPLINGMODE, engine?: Engine, reusable?: boolean, defines?: string, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT, vertexUrl: string = 'postprocess') {
             if (camera != null) {
             if (camera != null) {
                 this._camera = camera;
                 this._camera = camera;
                 this._scene = camera.getScene();
                 this._scene = camera.getScene();
@@ -122,6 +123,7 @@
             this._samplers.push("textureSampler");
             this._samplers.push("textureSampler");
 
 
             this._fragmentUrl = fragmentUrl;
             this._fragmentUrl = fragmentUrl;
+            this._vertexUrl = vertexUrl;
             this._parameters = parameters || [];
             this._parameters = parameters || [];
 
 
             this._parameters.push("scale");
             this._parameters.push("scale");
@@ -130,7 +132,7 @@
         }
         }
         
         
         public updateEffect(defines?: string) {
         public updateEffect(defines?: string) {
-            this._effect = this._engine.createEffect({ vertex: "postprocess", fragment: this._fragmentUrl },
+            this._effect = this._engine.createEffect({ vertex: this._vertexUrl, fragment: this._fragmentUrl },
                 ["position"],
                 ["position"],
                 this._parameters,
                 this._parameters,
                 this._samplers, defines !== undefined ? defines : "");
                 this._samplers, defines !== undefined ? defines : "");

+ 10 - 3
src/Rendering/babylon.renderingManager.ts

@@ -21,6 +21,11 @@
          */
          */
         public static MIN_RENDERINGGROUPS = 0;
         public static MIN_RENDERINGGROUPS = 0;
 
 
+        /**
+         * Used to globally prevent autoclearing scenes.
+         */
+        public static AUTOCLEAR = true;
+
         private _scene: Scene;
         private _scene: Scene;
         private _renderingGroups = new Array<RenderingGroup>();
         private _renderingGroups = new Array<RenderingGroup>();
         private _depthStencilBufferAlreadyCleaned: boolean;
         private _depthStencilBufferAlreadyCleaned: boolean;
@@ -93,9 +98,11 @@
                 }
                 }
 
 
                 // Clear depth/stencil if needed
                 // Clear depth/stencil if needed
-                let autoClear = this._autoClearDepthStencil[index];
-                if (autoClear && autoClear.autoClear) {
-                    this._clearDepthStencilBuffer(autoClear.depth, autoClear.stencil);
+                if (RenderingManager.AUTOCLEAR) {
+                    let autoClear = this._autoClearDepthStencil[index];
+                    if (autoClear && autoClear.autoClear) {
+                        this._clearDepthStencilBuffer(autoClear.depth, autoClear.stencil);
+                    }
                 }
                 }
 
 
                 if (observable) {
                 if (observable) {

+ 6 - 5
src/Tools/babylon.tools.ts

@@ -395,7 +395,7 @@
         }
         }
 
 
         //ANY
         //ANY
-        public static LoadFile(url: string, callback: (data: any) => void, progressCallBack?: () => void, database?, useArrayBuffer?: boolean, onError?: () => void): void {
+        public static LoadFile(url: string, callback: (data: any) => void, progressCallBack?: (data: any) => void, database?, useArrayBuffer?: boolean, onError?: (request: XMLHttpRequest) => void): void {
             url = Tools.CleanUrl(url);
             url = Tools.CleanUrl(url);
 
 
             var noIndexedDB = () => {
             var noIndexedDB = () => {
@@ -410,14 +410,15 @@
                 request.onprogress = progressCallBack;
                 request.onprogress = progressCallBack;
 
 
                 request.onreadystatechange = () => {
                 request.onreadystatechange = () => {
-                    if (request.readyState === 4) {
+                    // In case of undefined state in some browsers.
+                    if (request.readyState === (XMLHttpRequest.DONE || 4)) {
                         request.onreadystatechange = null;//some browsers have issues where onreadystatechange can be called multiple times with the same value
                         request.onreadystatechange = null;//some browsers have issues where onreadystatechange can be called multiple times with the same value
 
 
                         if (request.status >= 200 && request.status < 300 || (navigator.isCocoonJS && (request.status === 0))) {
                         if (request.status >= 200 && request.status < 300 || (navigator.isCocoonJS && (request.status === 0))) {
                             callback(!useArrayBuffer ? request.responseText : request.response);
                             callback(!useArrayBuffer ? request.responseText : request.response);
                         } else { // Failed
                         } else { // Failed
                             if (onError) {
                             if (onError) {
-                                onError();
+                                onError(request);
                             } else {
                             } else {
 
 
                                 throw new Error("Error status: " + request.status + " - Unable to load " + loadUrl);
                                 throw new Error("Error status: " + request.status + " - Unable to load " + loadUrl);
@@ -436,10 +437,10 @@
             if (url.indexOf("file:") !== -1) {
             if (url.indexOf("file:") !== -1) {
                 var fileName = url.substring(5).toLowerCase();
                 var fileName = url.substring(5).toLowerCase();
                 if (FilesInput.FilesToLoad[fileName]) {
                 if (FilesInput.FilesToLoad[fileName]) {
-                    Tools.ReadFile(FilesInput.FilesToLoad[fileName], callback, progressCallBack, useArrayBuffer); 
+                    Tools.ReadFile(FilesInput.FilesToLoad[fileName], callback, progressCallBack, useArrayBuffer);
                 }
                 }
                 else {
                 else {
-                    Tools.Error("File: " + fileName + " not found. Did you forget to provide it?");  
+                    Tools.Error("File: " + fileName + " not found. Did you forget to provide it?");
                 }
                 }
             }
             }
             else {
             else {

+ 1 - 1
src/babylon.engine.ts

@@ -1205,7 +1205,7 @@
             });
             });
         }
         }
 
 
-        public getVRDevice(name: string, callback: (device) => void) {
+        public getVRDevice(name: string, callback: (device: any) => void) {
             if (!this.vrDisplaysPromise) {
             if (!this.vrDisplaysPromise) {
                 callback(null);
                 callback(null);
                 return;
                 return;

+ 28 - 10
src/babylon.scene.ts

@@ -512,9 +512,9 @@
 
 
         public materials = new Array<Material>();
         public materials = new Array<Material>();
         public multiMaterials = new Array<MultiMaterial>();
         public multiMaterials = new Array<MultiMaterial>();
-        private _defaultMaterial: StandardMaterial;
+        private _defaultMaterial: Material;
 
 
-        public get defaultMaterial(): StandardMaterial {
+        public get defaultMaterial(): Material {
             if (!this._defaultMaterial) {
             if (!this._defaultMaterial) {
                 this._defaultMaterial = new StandardMaterial("default material", this);
                 this._defaultMaterial = new StandardMaterial("default material", this);
             }
             }
@@ -522,6 +522,10 @@
             return this._defaultMaterial;
             return this._defaultMaterial;
         }
         }
 
 
+        public set defaultMaterial(value: Material) {
+            this._defaultMaterial = value;
+        }
+
         // Textures
         // Textures
         private _texturesEnabled = true;
         private _texturesEnabled = true;
         public set texturesEnabled(value : boolean) {
         public set texturesEnabled(value : boolean) {
@@ -716,6 +720,8 @@
         private _externalData: StringDictionary<Object>;
         private _externalData: StringDictionary<Object>;
         private _uid: string;
         private _uid: string;
 
 
+        public offscreenRenderTarget: RenderTargetTexture = null;
+
         /**
         /**
          * @constructor
          * @constructor
          * @param {BABYLON.Engine} engine - the engine to be used to render this scene.
          * @param {BABYLON.Engine} engine - the engine to be used to render this scene.
@@ -2602,7 +2608,7 @@
                 this._intermediateRendering = true;
                 this._intermediateRendering = true;
                 Tools.StartPerformanceCounter("Render targets", this._renderTargets.length > 0);
                 Tools.StartPerformanceCounter("Render targets", this._renderTargets.length > 0);
                 for (var renderIndex = 0; renderIndex < this._renderTargets.length; renderIndex++) {
                 for (var renderIndex = 0; renderIndex < this._renderTargets.length; renderIndex++) {
-                    var renderTarget = this._renderTargets.data[renderIndex];
+                    let renderTarget = this._renderTargets.data[renderIndex];
                     if (renderTarget._shouldRender()) {
                     if (renderTarget._shouldRender()) {
                         this._renderId++;
                         this._renderId++;
                         var hasSpecialRenderTargetCamera = renderTarget.activeCamera && renderTarget.activeCamera !== this.activeCamera;
                         var hasSpecialRenderTargetCamera = renderTarget.activeCamera && renderTarget.activeCamera !== this.activeCamera;
@@ -2632,7 +2638,7 @@
 
 
                         renderhighlights = true;
                         renderhighlights = true;
 
 
-                        var renderTarget = (<RenderTargetTexture>(<any>highlightLayer)._mainTexture);
+                        let renderTarget = (<RenderTargetTexture>(<any>highlightLayer)._mainTexture);
                         if (renderTarget._shouldRender()) {
                         if (renderTarget._shouldRender()) {
                             this._renderId++;
                             this._renderId++;
                             renderTarget.render(false, false);
                             renderTarget.render(false, false);
@@ -2646,7 +2652,12 @@
             }
             }
 
 
             if (needsRestoreFrameBuffer) {
             if (needsRestoreFrameBuffer) {
-                engine.restoreDefaultFramebuffer();
+                if (this.offscreenRenderTarget) {
+                    engine.bindFramebuffer(this.offscreenRenderTarget._texture);
+                }
+                else {
+                    engine.restoreDefaultFramebuffer(); // Restore back buffer
+                }
             }
             }
 
 
             this._renderTargetsDuration.endMonitoring(false);
             this._renderTargetsDuration.endMonitoring(false);
@@ -2844,9 +2855,9 @@
 
 
             // Physics
             // Physics
             if (this._physicsEngine) {
             if (this._physicsEngine) {
-                Tools.StartPerformanceCounter("Physics");
-                this._physicsEngine._step(deltaTime / 1000.0);
-                Tools.EndPerformanceCounter("Physics");
+               Tools.StartPerformanceCounter("Physics");
+               this._physicsEngine._step(deltaTime / 1000.0);
+               Tools.EndPerformanceCounter("Physics");
             }
             }
 
 
             // Before render
             // Before render
@@ -2883,9 +2894,16 @@
                 this._renderId++;
                 this._renderId++;
             }
             }
 
 
-            if (this.customRenderTargets.length > 0) { // Restore back buffer
-                engine.restoreDefaultFramebuffer();
+            if (this.offscreenRenderTarget) {
+                engine.bindFramebuffer(this.offscreenRenderTarget._texture);
+            }
+            else {
+                // Restore back buffer
+                if (this.customRenderTargets.length > 0) {
+                    engine.restoreDefaultFramebuffer();
+                }
             }
             }
+
             this._renderTargetsDuration.endMonitoring();
             this._renderTargetsDuration.endMonitoring();
             this.activeCamera = currentActiveCamera;
             this.activeCamera = currentActiveCamera;