瀏覽代碼

Merge pull request #1617 from sebavan/Development

Development
David Catuhe 8 年之前
父節點
當前提交
49bde9f671

+ 1 - 0
Tools/Gulp/config.json

@@ -206,6 +206,7 @@
       "../../src/PostProcess/babylon.lensRenderingPipeline.js",
       "../../src/PostProcess/babylon.colorCorrectionPostProcess.js",
       "../../src/Cameras/babylon.stereoscopicCameras.js",
+      "../../src/Cameras/Holographic/babylon.holographicCamera.js",
       "../../src/PostProcess/babylon.hdrRenderingPipeline.js",
       "../../src/Rendering/babylon.edgesRenderer.js",
       "../../src/PostProcess/babylon.tonemapPostProcess.js",

+ 1 - 0
dist/preview release/what's new.md

@@ -4,6 +4,7 @@
  - New Unity 5 Editor Toolkit. Complete pipeline integration [Doc](TODO) - ([MackeyK24](https://github.com/MackeyK24))
  - New DebugLayer. [Doc](TODO) - ([temechon](https://github.com/temechon))
  - New `VideoTexture.CreateFromWebCam` to generate video texture using WebRTC. [Demo](https://www.babylonjs-playground.com#1R77YT#2) - (Sebastien Vandenberghe)(https://github.com/sebavanmicrosoft) / ([deltakosh](https://github.com/deltakosh))
+ - New `HolographicCamera` to support rendering on Windows Holographic. - ([sebavan](https://github.com/sebavan))
 
 ### Updates
  - `Effect.getVertexShaderSource()` and `Effect.getFragmentShaderSource()` now returns the effective shader code (including evaluation of #define) ([deltakosh](https://github.com/deltakosh))

+ 111 - 0
src/Cameras/Holographic/babylon.holographicCamera.ts

@@ -0,0 +1,111 @@
+interface Window { 
+    holographicViewMatrix: boolean;
+    getViewMatrix(): Float32Array;
+    getCameraPositionVector(): Float32Array;
+} 
+
+module BABYLON {
+    export class HolographicCamera extends Camera {
+        
+        private _identityProjection: Matrix;
+
+        private _scriptProjection: Matrix;
+        private _scriptViewProjection: Matrix;
+
+        private _holographicViewMatrix: Matrix;
+
+        private _onBeforeRenderObserver: Observer<Scene>;
+        private _onBeforeCameraRenderObserver: Observer<Camera>;
+
+        constructor(name: string, scene: Scene) {            
+            super(name, BABYLON.Vector3.Zero(), scene);
+
+            scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);
+            
+            this._holographicViewMatrix = new Matrix();            
+            this._identityProjection = BABYLON.Matrix.Identity();
+            this._scriptProjection = BABYLON.Matrix.Transpose(BABYLON.Matrix.PerspectiveFovLH(30, window.innerWidth / window.innerHeight, 1, 20));
+            this._scriptViewProjection = BABYLON.Matrix.Identity();
+
+            this.fov = 30;
+            this.minZ = 1.0;
+            this.maxZ = 20;
+            this.mode = BABYLON.Camera.PERSPECTIVE_CAMERA;
+            this.isIntermediate = false;
+            this.viewport = new BABYLON.Viewport(0, 0, 1.0, 1.0);
+            this.layerMask = 0x0FFFFFFF;
+            this.fovMode = BABYLON.Camera.FOVMODE_VERTICAL_FIXED;
+            this.cameraRigMode = BABYLON.Camera.RIG_MODE_NONE;
+
+            var self = this;
+            this._onBeforeRenderObserver = scene.onBeforeRenderObservable.add(function (scene) {
+                self._holographicViewMatrix.m = window.getViewMatrix();
+                self.setViewMatrix(self._holographicViewMatrix);
+
+                var position = window.getCameraPositionVector();
+                self.position.copyFromFloats(-position[0], position[1], -position[2]);
+            })
+            this._onBeforeCameraRenderObserver = scene.onBeforeCameraRenderObservable.add(function() {
+                if (scene.frustumPlanes) {
+                    self.getFrustumPlanesToRef(scene.frustumPlanes);
+                }
+            })
+
+            scene.addCamera(this);
+            if (!scene.activeCamera) {
+                scene.activeCamera = this;
+            }
+        }
+
+        public getTypeName(): string {
+            return "HolographicCamera";
+        };        
+
+
+        public getProjectionMatrix(): Matrix {
+            return this._identityProjection;
+        };
+        
+        public getViewMatrix(): Matrix {
+            return this._holographicViewMatrix;
+        };
+
+        public setViewMatrix(view: Matrix) : void {
+            this._holographicViewMatrix = view;
+
+            view.m[0] = -view.m[0];
+            view.m[1] = -view.m[1];
+            view.m[2] = -view.m[2];
+            view.m[3] = -view.m[3];
+
+            view.m[8] = -view.m[8];
+            view.m[9] = -view.m[9];
+            view.m[10] = -view.m[10];
+            view.m[11] = -view.m[11];
+        };
+        
+        public _initCache(): void { };
+        public _updateCache(): void { };
+        public _updateFromScene(): void { };
+
+        // Synchronized
+        public _isSynchronizedViewMatrix() : boolean {
+            return true;
+        };
+        public _isSynchronizedProjectionMatrix() : boolean {
+            return true;
+        };
+
+        private getFrustumPlanesToRef(result: Plane[]): Plane[] {
+            this._holographicViewMatrix.multiplyToRef(this._scriptProjection, this._scriptViewProjection);
+            BABYLON.Frustum.GetPlanesToRef(this._scriptViewProjection, result);
+            return result;
+        };
+
+        public dispose(): void {
+            this.getScene().onBeforeRenderObservable.remove(this._onBeforeRenderObserver);
+            this.getScene().onBeforeCameraRenderObservable.remove(this._onBeforeCameraRenderObserver);
+            super.dispose();
+        }
+    }
+}

+ 13 - 3
src/babylon.engine.ts

@@ -3132,11 +3132,21 @@
         }
 
         private _canRenderToFloatTexture(): boolean {
-            return this._canRenderToTextureOfType(BABYLON.Engine.TEXTURETYPE_FLOAT, 'OES_texture_float');
+            try {
+                return this._canRenderToTextureOfType(BABYLON.Engine.TEXTURETYPE_FLOAT, 'OES_texture_float');
+            }
+            catch (e) {
+                return false;
+            }
         }
 
-        private _canRenderToHalfFloatTexture(): boolean {
-            return this._canRenderToTextureOfType(BABYLON.Engine.TEXTURETYPE_HALF_FLOAT, 'OES_texture_half_float');
+        private _canRenderToHalfFloatTexture(): boolean {            
+            try {
+                return this._canRenderToTextureOfType(BABYLON.Engine.TEXTURETYPE_HALF_FLOAT, 'OES_texture_half_float');
+            }
+            catch (e) {
+                return false;
+            }
         }
 
         // Thank you : http://stackoverflow.com/questions/28827511/webgl-ios-render-to-floating-point-texture

+ 4 - 1
src/babylon.scene.ts

@@ -543,7 +543,11 @@
 
         private _viewMatrix: Matrix;
         private _projectionMatrix: Matrix;
+        
         private _frustumPlanes: Plane[];
+        public get frustumPlanes(): Plane[] {
+            return this._frustumPlanes;
+        }
 
         private _selectionOctree: Octree<AbstractMesh>;
 
@@ -561,7 +565,6 @@
         private _externalData: StringDictionary<Object>;
         private _uid: string;
 
-
         /**
          * @constructor
          * @param {BABYLON.Engine} engine - the engine to be used to render this scene.