浏览代码

Adding transparent bounding

DESKTOP-QJU4N0L\mityh 8 年之前
父节点
当前提交
e86455e386

文件差异内容过多而无法显示
+ 5112 - 5102
dist/preview release/babylon.d.ts


文件差异内容过多而无法显示
+ 37 - 37
dist/preview release/babylon.js


+ 95 - 24
dist/preview release/babylon.max.js

@@ -11785,6 +11785,7 @@ var BABYLON;
             _this.isOccluded = false;
             _this.occlusionQuery = _this._gl.createQuery();
             _this.isOcclusionQueryInProgress = false;
+            _this.occlusionQueryAlgorithmType = AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE;
             _this._rotation = BABYLON.Vector3.Zero();
             _this._scaling = BABYLON.Vector3.One();
             _this.billboardMode = AbstractMesh.BILLBOARDMODE_NONE;
@@ -13816,6 +13817,8 @@ var BABYLON;
         AbstractMesh.OCCLUSION_TYPE_NO_VALUE = 0;
         AbstractMesh.OCCLUSION_TYPE_OPTIMISITC = 1;
         AbstractMesh.OCCLUSION_TYPE_STRICT = 2;
+        AbstractMesh.OCCLUSION_ALGORITHM_TYPE_ACCURATE = 0;
+        AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE = 1;
         AbstractMesh._rotationAxisCache = new BABYLON.Quaternion();
         AbstractMesh._lookAtVectorCache = new BABYLON.Vector3(0, 0, 0);
         return AbstractMesh;
@@ -20448,6 +20451,72 @@ var BABYLON;
         return _InstancesBatch;
     }());
     BABYLON._InstancesBatch = _InstancesBatch;
+    var OcclusionBoundingBoxRenderer = (function () {
+        function OcclusionBoundingBoxRenderer(scene) {
+            this.frontColor = new BABYLON.Color3(1, 1, 1);
+            this.backColor = new BABYLON.Color3(0.1, 0.1, 0.1);
+            this._vertexBuffers = {};
+            this._scene = scene;
+        }
+        OcclusionBoundingBoxRenderer.prototype._prepareRessources = function () {
+            if (this._colorShader) {
+                return;
+            }
+            this._colorShader = new BABYLON.ShaderMaterial("colorShader", this._scene, "color", {
+                attributes: [BABYLON.VertexBuffer.PositionKind],
+                uniforms: ["world", "viewProjection", "color"]
+            });
+            var engine = this._scene.getEngine();
+            var boxdata = BABYLON.VertexData.CreateBox({ size: 1.0 });
+            this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = new BABYLON.VertexBuffer(engine, boxdata.positions, BABYLON.VertexBuffer.PositionKind, false);
+            this._indexBuffer = engine.createIndexBuffer([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 7, 1, 6, 2, 5, 3, 4]);
+        };
+        OcclusionBoundingBoxRenderer.prototype.render = function (mesh) {
+            this._prepareRessources();
+            if (!this._colorShader.isReady()) {
+                return;
+            }
+            var engine = this._scene.getEngine();
+            engine.setDepthWrite(false);
+            engine.setColorWrite(false);
+            this._colorShader._preBind();
+            var boundingBox = mesh._boundingInfo.boundingBox;
+            var min = boundingBox.minimum;
+            var max = boundingBox.maximum;
+            var diff = max.subtract(min);
+            var median = min.add(diff.scale(0.5));
+            var worldMatrix = BABYLON.Matrix.Scaling(diff.x, diff.y, diff.z)
+                .multiply(BABYLON.Matrix.Translation(median.x, median.y, median.z))
+                .multiply(boundingBox.getWorldMatrix());
+            // VBOs
+            engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());
+            // Front
+            engine.setDepthFunctionToLess();
+            this._scene.resetCachedMaterial();
+            this._colorShader.setColor4("color", this.frontColor.toColor4());
+            this._colorShader.bind(worldMatrix);
+            // Draw order
+            engine.draw(false, 0, 24);
+            this._colorShader.unbind();
+            engine.setDepthFunctionToLessOrEqual();
+            engine.setDepthWrite(true);
+            engine.setColorWrite(true);
+        };
+        OcclusionBoundingBoxRenderer.prototype.dispose = function () {
+            if (!this._colorShader) {
+                return;
+            }
+            this._colorShader.dispose();
+            var buffer = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind];
+            if (buffer) {
+                buffer.dispose();
+                this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = null;
+            }
+            this._scene.getEngine()._releaseBuffer(this._indexBuffer);
+        };
+        return OcclusionBoundingBoxRenderer;
+    }());
+    BABYLON.OcclusionBoundingBoxRenderer = OcclusionBoundingBoxRenderer;
     var Mesh = (function (_super) {
         __extends(Mesh, _super);
         /**
@@ -20493,9 +20562,6 @@ var BABYLON;
             _this._areNormalsFrozen = false; // Will be used by ribbons mainly
             // Will be used to save a source mesh reference, If any
             _this._source = null;
-            _this._vertexBuffers = {};
-            _this.frontColor = new BABYLON.Color3(1, 1, 1);
-            _this.backColor = new BABYLON.Color3(0.1, 0.1, 0.1);
             if (source) {
                 // Source mesh
                 _this._source = source;
@@ -21456,21 +21522,11 @@ var BABYLON;
             }
             return this;
         };
-        Mesh.prototype._prepareRessources = function () {
-            if (this._caaaaolorasaShader) {
-                return;
-            }
-            var scene = this.getScene();
-            this._caaaaolorasaShader = new BABYLON.ShaderMaterial("caaaaolorasaShader", scene, "color", {
-                attributes: ["aaaa"],
-                uniforms: ["world", "viewProjection", "color"]
-            });
-            var engine = scene.getEngine();
-            var boxdata = BABYLON.VertexData.CreateBox({ size: 1.0 });
-            this._vertexBuffers["aaaa"] = new BABYLON.VertexBuffer(engine, boxdata.positions, "aaaa", false);
-            this._indexBuffer = engine.createIndexBuffer([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 7, 1, 6, 2, 5, 3, 4]);
-        };
         Mesh.prototype.renderOcclusionBoundingMesh = function () {
+            var scene = this.getScene();
+            if (!this._occlusionBoundingBoxRenderer) {
+                this._occlusionBoundingBoxRenderer = new OcclusionBoundingBoxRenderer(scene);
+            }
             if (this.isOcclusionQueryInProgress) {
                 console.log("Enter occlusion check");
                 var isOcclusionQueryAvailable = this._gl.getQueryParameter(this.occlusionQuery, this._gl.QUERY_RESULT_AVAILABLE);
@@ -21489,15 +21545,27 @@ var BABYLON;
                     return false;
                 }
             }
-            var scene = this.getScene();
             console.log("Enter Draw Bound");
-            this._gl.beginQuery(this._gl.ANY_SAMPLES_PASSED, this.occlusionQuery);
-            var _boundingBoxRenderer = new BABYLON.BoundingBoxRenderer(scene);
-            _boundingBoxRenderer.showBackLines = false;
-            _boundingBoxRenderer.renderList.push(this._boundingInfo.boundingBox);
-            _boundingBoxRenderer.render();
-            this._gl.endQuery(this._gl.ANY_SAMPLES_PASSED);
+            var occlusionAlgorithmType = this.occlusionQueryAlgorithmType == BABYLON.AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE ? this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE : this._gl.ANY_SAMPLES_PASSED;
+            this._gl.beginQuery(occlusionAlgorithmType, this.occlusionQuery);
+            this._occlusionBoundingBoxRenderer.render(this);
+            this._gl.endQuery(occlusionAlgorithmType);
             this.isOcclusionQueryInProgress = true;
+            var isOcclusionQueryAvailable = this._gl.getQueryParameter(this.occlusionQuery, this._gl.QUERY_RESULT_AVAILABLE);
+            console.log("isOcclusionQueryAvailable " + isOcclusionQueryAvailable);
+            if (isOcclusionQueryAvailable) {
+                var occlusionQueryResult = this._gl.getQueryParameter(this.occlusionQuery, this._gl.QUERY_RESULT);
+                console.log("occlusionQueryResult " + occlusionQueryResult);
+                this.isOccluded = true;
+                this.isOcclusionQueryInProgress = false;
+                if (occlusionQueryResult === 1) {
+                    this.isOccluded = false;
+                    return true;
+                }
+            }
+            else {
+                return false;
+            }
             return false;
         };
         /**
@@ -21825,6 +21893,9 @@ var BABYLON;
                 this._instancesBuffer.dispose();
                 this._instancesBuffer = null;
             }
+            if (this._occlusionBoundingBoxRenderer) {
+                this._occlusionBoundingBoxRenderer.dispose();
+            }
             while (this.instances.length) {
                 this.instances[0].dispose();
             }

文件差异内容过多而无法显示
+ 5112 - 5102
dist/preview release/babylon.module.d.ts


文件差异内容过多而无法显示
+ 37 - 37
dist/preview release/babylon.worker.js


文件差异内容过多而无法显示
+ 1650 - 1640
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


文件差异内容过多而无法显示
+ 21 - 21
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


+ 95 - 24
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -11785,6 +11785,7 @@ var BABYLON;
             _this.isOccluded = false;
             _this.occlusionQuery = _this._gl.createQuery();
             _this.isOcclusionQueryInProgress = false;
+            _this.occlusionQueryAlgorithmType = AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE;
             _this._rotation = BABYLON.Vector3.Zero();
             _this._scaling = BABYLON.Vector3.One();
             _this.billboardMode = AbstractMesh.BILLBOARDMODE_NONE;
@@ -13816,6 +13817,8 @@ var BABYLON;
         AbstractMesh.OCCLUSION_TYPE_NO_VALUE = 0;
         AbstractMesh.OCCLUSION_TYPE_OPTIMISITC = 1;
         AbstractMesh.OCCLUSION_TYPE_STRICT = 2;
+        AbstractMesh.OCCLUSION_ALGORITHM_TYPE_ACCURATE = 0;
+        AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE = 1;
         AbstractMesh._rotationAxisCache = new BABYLON.Quaternion();
         AbstractMesh._lookAtVectorCache = new BABYLON.Vector3(0, 0, 0);
         return AbstractMesh;
@@ -20448,6 +20451,72 @@ var BABYLON;
         return _InstancesBatch;
     }());
     BABYLON._InstancesBatch = _InstancesBatch;
+    var OcclusionBoundingBoxRenderer = (function () {
+        function OcclusionBoundingBoxRenderer(scene) {
+            this.frontColor = new BABYLON.Color3(1, 1, 1);
+            this.backColor = new BABYLON.Color3(0.1, 0.1, 0.1);
+            this._vertexBuffers = {};
+            this._scene = scene;
+        }
+        OcclusionBoundingBoxRenderer.prototype._prepareRessources = function () {
+            if (this._colorShader) {
+                return;
+            }
+            this._colorShader = new BABYLON.ShaderMaterial("colorShader", this._scene, "color", {
+                attributes: [BABYLON.VertexBuffer.PositionKind],
+                uniforms: ["world", "viewProjection", "color"]
+            });
+            var engine = this._scene.getEngine();
+            var boxdata = BABYLON.VertexData.CreateBox({ size: 1.0 });
+            this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = new BABYLON.VertexBuffer(engine, boxdata.positions, BABYLON.VertexBuffer.PositionKind, false);
+            this._indexBuffer = engine.createIndexBuffer([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 7, 1, 6, 2, 5, 3, 4]);
+        };
+        OcclusionBoundingBoxRenderer.prototype.render = function (mesh) {
+            this._prepareRessources();
+            if (!this._colorShader.isReady()) {
+                return;
+            }
+            var engine = this._scene.getEngine();
+            engine.setDepthWrite(false);
+            engine.setColorWrite(false);
+            this._colorShader._preBind();
+            var boundingBox = mesh._boundingInfo.boundingBox;
+            var min = boundingBox.minimum;
+            var max = boundingBox.maximum;
+            var diff = max.subtract(min);
+            var median = min.add(diff.scale(0.5));
+            var worldMatrix = BABYLON.Matrix.Scaling(diff.x, diff.y, diff.z)
+                .multiply(BABYLON.Matrix.Translation(median.x, median.y, median.z))
+                .multiply(boundingBox.getWorldMatrix());
+            // VBOs
+            engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());
+            // Front
+            engine.setDepthFunctionToLess();
+            this._scene.resetCachedMaterial();
+            this._colorShader.setColor4("color", this.frontColor.toColor4());
+            this._colorShader.bind(worldMatrix);
+            // Draw order
+            engine.draw(false, 0, 24);
+            this._colorShader.unbind();
+            engine.setDepthFunctionToLessOrEqual();
+            engine.setDepthWrite(true);
+            engine.setColorWrite(true);
+        };
+        OcclusionBoundingBoxRenderer.prototype.dispose = function () {
+            if (!this._colorShader) {
+                return;
+            }
+            this._colorShader.dispose();
+            var buffer = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind];
+            if (buffer) {
+                buffer.dispose();
+                this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = null;
+            }
+            this._scene.getEngine()._releaseBuffer(this._indexBuffer);
+        };
+        return OcclusionBoundingBoxRenderer;
+    }());
+    BABYLON.OcclusionBoundingBoxRenderer = OcclusionBoundingBoxRenderer;
     var Mesh = (function (_super) {
         __extends(Mesh, _super);
         /**
@@ -20493,9 +20562,6 @@ var BABYLON;
             _this._areNormalsFrozen = false; // Will be used by ribbons mainly
             // Will be used to save a source mesh reference, If any
             _this._source = null;
-            _this._vertexBuffers = {};
-            _this.frontColor = new BABYLON.Color3(1, 1, 1);
-            _this.backColor = new BABYLON.Color3(0.1, 0.1, 0.1);
             if (source) {
                 // Source mesh
                 _this._source = source;
@@ -21456,21 +21522,11 @@ var BABYLON;
             }
             return this;
         };
-        Mesh.prototype._prepareRessources = function () {
-            if (this._caaaaolorasaShader) {
-                return;
-            }
-            var scene = this.getScene();
-            this._caaaaolorasaShader = new BABYLON.ShaderMaterial("caaaaolorasaShader", scene, "color", {
-                attributes: ["aaaa"],
-                uniforms: ["world", "viewProjection", "color"]
-            });
-            var engine = scene.getEngine();
-            var boxdata = BABYLON.VertexData.CreateBox({ size: 1.0 });
-            this._vertexBuffers["aaaa"] = new BABYLON.VertexBuffer(engine, boxdata.positions, "aaaa", false);
-            this._indexBuffer = engine.createIndexBuffer([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 7, 1, 6, 2, 5, 3, 4]);
-        };
         Mesh.prototype.renderOcclusionBoundingMesh = function () {
+            var scene = this.getScene();
+            if (!this._occlusionBoundingBoxRenderer) {
+                this._occlusionBoundingBoxRenderer = new OcclusionBoundingBoxRenderer(scene);
+            }
             if (this.isOcclusionQueryInProgress) {
                 console.log("Enter occlusion check");
                 var isOcclusionQueryAvailable = this._gl.getQueryParameter(this.occlusionQuery, this._gl.QUERY_RESULT_AVAILABLE);
@@ -21489,15 +21545,27 @@ var BABYLON;
                     return false;
                 }
             }
-            var scene = this.getScene();
             console.log("Enter Draw Bound");
-            this._gl.beginQuery(this._gl.ANY_SAMPLES_PASSED, this.occlusionQuery);
-            var _boundingBoxRenderer = new BABYLON.BoundingBoxRenderer(scene);
-            _boundingBoxRenderer.showBackLines = false;
-            _boundingBoxRenderer.renderList.push(this._boundingInfo.boundingBox);
-            _boundingBoxRenderer.render();
-            this._gl.endQuery(this._gl.ANY_SAMPLES_PASSED);
+            var occlusionAlgorithmType = this.occlusionQueryAlgorithmType == BABYLON.AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE ? this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE : this._gl.ANY_SAMPLES_PASSED;
+            this._gl.beginQuery(occlusionAlgorithmType, this.occlusionQuery);
+            this._occlusionBoundingBoxRenderer.render(this);
+            this._gl.endQuery(occlusionAlgorithmType);
             this.isOcclusionQueryInProgress = true;
+            var isOcclusionQueryAvailable = this._gl.getQueryParameter(this.occlusionQuery, this._gl.QUERY_RESULT_AVAILABLE);
+            console.log("isOcclusionQueryAvailable " + isOcclusionQueryAvailable);
+            if (isOcclusionQueryAvailable) {
+                var occlusionQueryResult = this._gl.getQueryParameter(this.occlusionQuery, this._gl.QUERY_RESULT);
+                console.log("occlusionQueryResult " + occlusionQueryResult);
+                this.isOccluded = true;
+                this.isOcclusionQueryInProgress = false;
+                if (occlusionQueryResult === 1) {
+                    this.isOccluded = false;
+                    return true;
+                }
+            }
+            else {
+                return false;
+            }
             return false;
         };
         /**
@@ -21825,6 +21893,9 @@ var BABYLON;
                 this._instancesBuffer.dispose();
                 this._instancesBuffer = null;
             }
+            if (this._occlusionBoundingBoxRenderer) {
+                this._occlusionBoundingBoxRenderer.dispose();
+            }
             while (this.instances.length) {
                 this.instances[0].dispose();
             }

文件差异内容过多而无法显示
+ 1650 - 1640
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts


+ 3 - 0
src/Mesh/babylon.abstractMesh.ts

@@ -10,6 +10,8 @@
         public static OCCLUSION_TYPE_NO_VALUE = 0;
         public static OCCLUSION_TYPE_OPTIMISITC = 1;
         public static OCCLUSION_TYPE_STRICT = 2;
+        public static OCCLUSION_ALGORITHM_TYPE_ACCURATE = 0;
+        public static OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE = 1;
 
         public static get BILLBOARDMODE_NONE(): number {
             return AbstractMesh._BILLBOARDMODE_NONE;
@@ -131,6 +133,7 @@
         public isOccluded = false;
         public occlusionQuery = this._gl.createQuery();
         public isOcclusionQueryInProgress = false;
+        public occlusionQueryAlgorithmType= AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE;
         private _rotation = Vector3.Zero();
         private _rotationQuaternion: Quaternion;
         private _scaling = Vector3.One();

+ 121 - 8
src/Mesh/babylon.mesh.ts

@@ -5,6 +5,94 @@
         public renderSelf = new Array<boolean>();
     }
 
+    export class OcclusionBoundingBoxRenderer {
+        public frontColor = new Color3(1, 1, 1);
+        public backColor = new Color3(0.1, 0.1, 0.1);
+
+        private _scene: Scene;
+        private _colorShader: ShaderMaterial;
+        private _vertexBuffers: { [key: string]: VertexBuffer } = {};
+        private _indexBuffer: WebGLBuffer;
+
+        constructor(scene: Scene) {
+            this._scene = scene;
+        }
+
+        private _prepareRessources(): void {
+            if (this._colorShader) {
+                return;
+            }
+
+            this._colorShader = new ShaderMaterial("colorShader", this._scene, "color",
+                {
+                    attributes: [VertexBuffer.PositionKind],
+                    uniforms: ["world", "viewProjection", "color"]
+                });
+
+
+            var engine = this._scene.getEngine();
+            var boxdata = VertexData.CreateBox({ size: 1.0 });
+            this._vertexBuffers[VertexBuffer.PositionKind] = new VertexBuffer(engine, boxdata.positions, VertexBuffer.PositionKind, false);
+            this._indexBuffer = engine.createIndexBuffer([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 7, 1, 6, 2, 5, 3, 4]);
+        }
+
+        public render(mesh: Mesh): void {
+
+            this._prepareRessources();
+
+            if (!this._colorShader.isReady()) {
+                return;
+            }
+
+            var engine = this._scene.getEngine();
+            engine.setDepthWrite(false);
+            engine.setColorWrite(false);
+            this._colorShader._preBind();
+
+            var boundingBox = mesh._boundingInfo.boundingBox;
+            var min = boundingBox.minimum;
+            var max = boundingBox.maximum;
+            var diff = max.subtract(min);
+            var median = min.add(diff.scale(0.5));
+
+            var worldMatrix = Matrix.Scaling(diff.x, diff.y, diff.z)
+                .multiply(Matrix.Translation(median.x, median.y, median.z))
+                .multiply(boundingBox.getWorldMatrix());
+
+            // VBOs
+            engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());
+
+            // Front
+            engine.setDepthFunctionToLess();
+            this._scene.resetCachedMaterial();
+            this._colorShader.setColor4("color", this.frontColor.toColor4());
+            this._colorShader.bind(worldMatrix);
+
+            // Draw order
+            engine.draw(false, 0, 24);
+
+            this._colorShader.unbind();
+            engine.setDepthFunctionToLessOrEqual();
+            engine.setDepthWrite(true);
+            engine.setColorWrite(true);
+        }
+
+        public dispose(): void {
+            if (!this._colorShader) {
+                return;
+            }
+
+            this._colorShader.dispose();
+
+            var buffer = this._vertexBuffers[VertexBuffer.PositionKind];
+            if (buffer) {
+                buffer.dispose();
+                this._vertexBuffers[VertexBuffer.PositionKind] = null;
+            }
+            this._scene.getEngine()._releaseBuffer(this._indexBuffer);
+        }
+    }
+
     export class Mesh extends AbstractMesh implements IGetSetVerticesData {
         // Consts
         public static _FRONTSIDE: number = 0;
@@ -136,6 +224,8 @@
         private _sourcePositions: Float32Array; // Will be used to save original positions when using software skinning
         private _sourceNormals: Float32Array;   // Will be used to save original normals when using software skinning
 
+        private _occlusionBoundingBoxRenderer: OcclusionBoundingBoxRenderer;
+
         // Will be used to save a source mesh reference, If any
         private _source: BABYLON.Mesh = null;
         public get source(): BABYLON.Mesh {
@@ -1103,6 +1193,10 @@
 
         private renderOcclusionBoundingMesh() {
 
+            var scene = this.getScene();
+            if (!this._occlusionBoundingBoxRenderer) {
+                this._occlusionBoundingBoxRenderer = new OcclusionBoundingBoxRenderer(scene);
+            }
 
             if (this.isOcclusionQueryInProgress) {
 
@@ -1125,18 +1219,33 @@
                 }
             }
 
+            console.log("Enter Draw Bound");
 
-            var scene = this.getScene();
+            var occlusionAlgorithmType = this.occlusionQueryAlgorithmType == AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE ? this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE : this._gl.ANY_SAMPLES_PASSED;
 
-            console.log("Enter Draw Bound");
-            this._gl.beginQuery(this._gl.ANY_SAMPLES_PASSED, this.occlusionQuery);
-            var _boundingBoxRenderer = new BoundingBoxRenderer(scene);
-            _boundingBoxRenderer.showBackLines=false;
-            _boundingBoxRenderer.renderList.push(this._boundingInfo.boundingBox);
-            _boundingBoxRenderer.render();
-            this._gl.endQuery(this._gl.ANY_SAMPLES_PASSED);
+            this._gl.beginQuery(occlusionAlgorithmType, this.occlusionQuery);
+            this._occlusionBoundingBoxRenderer.render(this);
+            this._gl.endQuery(occlusionAlgorithmType);
             this.isOcclusionQueryInProgress = true;
 
+
+            var isOcclusionQueryAvailable = this._gl.getQueryParameter(this.occlusionQuery, this._gl.QUERY_RESULT_AVAILABLE) as boolean;
+            console.log("isOcclusionQueryAvailable " + isOcclusionQueryAvailable);
+            if (isOcclusionQueryAvailable) {
+                var occlusionQueryResult = this._gl.getQueryParameter(this.occlusionQuery, this._gl.QUERY_RESULT) as number;
+                console.log("occlusionQueryResult " + occlusionQueryResult);
+
+                this.isOccluded = true;
+                this.isOcclusionQueryInProgress = false;
+                if (occlusionQueryResult === 1) {
+                    this.isOccluded = false;
+                    return true;
+                }
+            }
+            else {
+                return false;
+            }
+
             return false;
         }
 
@@ -1521,6 +1630,10 @@
                 this._instancesBuffer = null;
             }
 
+            if (this._occlusionBoundingBoxRenderer) {
+                this._occlusionBoundingBoxRenderer.dispose();
+            }
+
             while (this.instances.length) {
                 this.instances[0].dispose();
             }

+ 0 - 87
src/Rendering/babylon.occlusionBoundingBoxRenderer.ts

@@ -1,87 +0,0 @@
-module BABYLON {
-    export class OcclusionBoundingBoxRenderer {
-        public frontColor = new Color3(1, 1, 1);
-        public backColor = new Color3(0.1, 0.1, 0.1);
-
-        private _scene: Scene;
-        private _colorShader: ShaderMaterial;
-        private _vertexBuffers: { [key: string]: VertexBuffer } = {};
-        private _indexBuffer: WebGLBuffer;
-
-        constructor(scene: Scene) {
-            this._scene = scene;
-        }
-
-        private _prepareRessources(): void {
-            if (this._colorShader) {
-                return;
-            }
-
-            this._colorShader = new ShaderMaterial("colorShader", this._scene, "color",
-                {
-                    attributes: [VertexBuffer.PositionKind],
-                    uniforms: ["world", "viewProjection", "color"]
-                });
-
-
-            var engine = this._scene.getEngine();
-            var boxdata = VertexData.CreateBox({ size: 1.0 });
-            this._vertexBuffers[VertexBuffer.PositionKind] = new VertexBuffer(engine, boxdata.positions, VertexBuffer.PositionKind, false);
-            this._indexBuffer = engine.createIndexBuffer([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 7, 1, 6, 2, 5, 3, 4]);
-        }
-
-        public render(mesh: Mesh): void {
-
-            this._prepareRessources();
-
-            if (!this._colorShader.isReady()) {
-                return;
-            }
-
-            var engine = this._scene.getEngine();
-            engine.setDepthWrite(false);
-            this._colorShader._preBind();
-
-            var boundingBox = mesh._boundingInfo.boundingBox;
-            var min = boundingBox.minimum;
-            var max = boundingBox.maximum;
-            var diff = max.subtract(min);
-            var median = min.add(diff.scale(0.5));
-
-            var worldMatrix = Matrix.Scaling(diff.x, diff.y, diff.z)
-                .multiply(Matrix.Translation(median.x, median.y, median.z))
-                .multiply(boundingBox.getWorldMatrix());
-
-            // VBOs
-            engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());
-
-            // Front
-            engine.setDepthFunctionToLess();
-            this._scene.resetCachedMaterial();
-            this._colorShader.setColor4("color", this.frontColor.toColor4());
-            this._colorShader.bind(worldMatrix);
-
-            // Draw order
-            engine.draw(false, 0, 24);
-
-            this._colorShader.unbind();
-            engine.setDepthFunctionToLessOrEqual();
-            engine.setDepthWrite(true);
-        }
-
-        public dispose(): void {
-            if (!this._colorShader) {
-                return;
-            }
-
-            this._colorShader.dispose();
-
-            var buffer = this._vertexBuffers[VertexBuffer.PositionKind];
-            if (buffer) {
-                buffer.dispose();
-                this._vertexBuffers[VertexBuffer.PositionKind] = null;
-            }
-            this._scene.getEngine()._releaseBuffer(this._indexBuffer);
-        }
-    }
-}