|
@@ -10975,6 +10975,23 @@ var BABYLON;
|
|
|
return this._gl.RGBA;
|
|
|
};
|
|
|
;
|
|
|
+ Engine.prototype.createQuery = function () {
|
|
|
+ return this._gl.createQuery();
|
|
|
+ };
|
|
|
+ Engine.prototype.isQueryResultAvailable = function (query) {
|
|
|
+ return this._gl.getQueryParameter(query, this._gl.QUERY_RESULT_AVAILABLE);
|
|
|
+ };
|
|
|
+ Engine.prototype.getQueryResult = function (query) {
|
|
|
+ return this._gl.getQueryParameter(query, this._gl.QUERY_RESULT);
|
|
|
+ };
|
|
|
+ Engine.prototype.beginQuery = function (algorithmType, query) {
|
|
|
+ var glAlgorithm = algorithmType === BABYLON.AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE ? this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE : this._gl.ANY_SAMPLES_PASSED;
|
|
|
+ this._gl.beginQuery(glAlgorithm, query);
|
|
|
+ };
|
|
|
+ Engine.prototype.endQuery = function (algorithmType) {
|
|
|
+ var glAlgorithm = algorithmType === BABYLON.AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE ? this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE : this._gl.ANY_SAMPLES_PASSED;
|
|
|
+ this._gl.endQuery(glAlgorithm);
|
|
|
+ };
|
|
|
// Statics
|
|
|
Engine.isSupported = function () {
|
|
|
try {
|
|
@@ -11790,15 +11807,14 @@ var BABYLON;
|
|
|
// Properties
|
|
|
_this.definedFacingForward = true; // orientation for POV movement & rotation
|
|
|
_this.position = BABYLON.Vector3.Zero();
|
|
|
- _this._gl = _this.getEngine()._gl;
|
|
|
_this._webGLVersion = _this.getEngine().webGLVersion;
|
|
|
_this._occlusionInternalRetryCounter = 0;
|
|
|
_this.occlusionType = AbstractMesh.OCCLUSION_TYPE_NO_VALUE;
|
|
|
_this.occlusionRetryCount = -1;
|
|
|
_this._isOccluded = false;
|
|
|
- _this.occlusionQuery = _this._gl.createQuery();
|
|
|
+ _this.occlusionQuery = _this.getEngine().createQuery();
|
|
|
_this.isOcclusionQueryInProgress = false;
|
|
|
- _this._occlusionQueryAlgorithmType = _this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE;
|
|
|
+ _this.occlusionQueryAlgorithmType = AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE;
|
|
|
_this._rotation = BABYLON.Vector3.Zero();
|
|
|
_this._scaling = BABYLON.Vector3.One();
|
|
|
_this.billboardMode = AbstractMesh.BILLBOARDMODE_NONE;
|
|
@@ -11989,16 +12005,6 @@ var BABYLON;
|
|
|
enumerable: true,
|
|
|
configurable: true
|
|
|
});
|
|
|
- Object.defineProperty(AbstractMesh.prototype, "occlusionQueryAlgorithmType", {
|
|
|
- get: function () {
|
|
|
- return this._occlusionQueryAlgorithmType === this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE ? AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE : AbstractMesh.OCCLUSION_ALGORITHM_TYPE_ACCURATE;
|
|
|
- },
|
|
|
- set: function (alogrithmType) {
|
|
|
- this._occlusionQueryAlgorithmType = alogrithmType === AbstractMesh.OCCLUSION_ALGORITHM_TYPE_CONSERVATIVE ? this._gl.ANY_SAMPLES_PASSED_CONSERVATIVE : this._gl.ANY_SAMPLES_PASSED;
|
|
|
- },
|
|
|
- enumerable: true,
|
|
|
- configurable: true
|
|
|
- });
|
|
|
Object.defineProperty(AbstractMesh.prototype, "material", {
|
|
|
get: function () {
|
|
|
return this._material;
|
|
@@ -13433,9 +13439,6 @@ var BABYLON;
|
|
|
this.onAfterWorldMatrixUpdateObservable.clear();
|
|
|
this.onCollideObservable.clear();
|
|
|
this.onCollisionPositionChangeObservable.clear();
|
|
|
- if (this._occlusionBoundingBoxRenderer) {
|
|
|
- this._occlusionBoundingBoxRenderer.dispose();
|
|
|
- }
|
|
|
this._isDisposed = true;
|
|
|
_super.prototype.dispose.call(this);
|
|
|
};
|
|
@@ -13849,14 +13852,11 @@ var BABYLON;
|
|
|
this._isOccluded = false;
|
|
|
return;
|
|
|
}
|
|
|
- if (!this._occlusionBoundingBoxRenderer) {
|
|
|
- var scene = this.getScene();
|
|
|
- this._occlusionBoundingBoxRenderer = new BABYLON.OcclusionBoundingBoxRenderer(scene);
|
|
|
- }
|
|
|
+ var engine = this.getEngine();
|
|
|
if (this.isOcclusionQueryInProgress) {
|
|
|
- var isOcclusionQueryAvailable = this._gl.getQueryParameter(this.occlusionQuery, this._gl.QUERY_RESULT_AVAILABLE);
|
|
|
+ var isOcclusionQueryAvailable = engine.isQueryResultAvailable(this.occlusionQuery);
|
|
|
if (isOcclusionQueryAvailable) {
|
|
|
- var occlusionQueryResult = this._gl.getQueryParameter(this.occlusionQuery, this._gl.QUERY_RESULT);
|
|
|
+ var occlusionQueryResult = engine.getQueryResult(this.occlusionQuery);
|
|
|
this.isOcclusionQueryInProgress = false;
|
|
|
this._occlusionInternalRetryCounter = 0;
|
|
|
this._isOccluded = occlusionQueryResult === 1 ? false : true;
|
|
@@ -13876,9 +13876,11 @@ var BABYLON;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- this._gl.beginQuery(this._occlusionQueryAlgorithmType, this.occlusionQuery);
|
|
|
- this._occlusionBoundingBoxRenderer.render(this);
|
|
|
- this._gl.endQuery(this._occlusionQueryAlgorithmType);
|
|
|
+ var scene = this.getScene();
|
|
|
+ var occlusionBoundingBoxRenderer = scene.getBoundingBoxRenderer();
|
|
|
+ engine.beginQuery(this.occlusionQueryAlgorithmType, this.occlusionQuery);
|
|
|
+ occlusionBoundingBoxRenderer.renderOcclusionBoundingBox(this);
|
|
|
+ engine.endQuery(this.occlusionQueryAlgorithmType);
|
|
|
this.isOcclusionQueryInProgress = true;
|
|
|
};
|
|
|
// Statics
|
|
@@ -29668,72 +29670,6 @@ var BABYLON;
|
|
|
|
|
|
var BABYLON;
|
|
|
(function (BABYLON) {
|
|
|
- var OcclusionBoundingBoxRenderer = (function () {
|
|
|
- function OcclusionBoundingBoxRenderer(scene) {
|
|
|
- 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());
|
|
|
- engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());
|
|
|
- engine.setDepthFunctionToLess();
|
|
|
- this._scene.resetCachedMaterial();
|
|
|
- this._colorShader.bind(worldMatrix);
|
|
|
- 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;
|
|
|
-})(BABYLON || (BABYLON = {}));
|
|
|
-
|
|
|
-//# sourceMappingURL=babylon.occlusionBoundingBoxRenderer.js.map
|
|
|
-
|
|
|
-var BABYLON;
|
|
|
-(function (BABYLON) {
|
|
|
var AnimationRange = (function () {
|
|
|
function AnimationRange(name, from, to) {
|
|
|
this.name = name;
|
|
@@ -47528,6 +47464,33 @@ var BABYLON;
|
|
|
engine.setDepthFunctionToLessOrEqual();
|
|
|
engine.setDepthWrite(true);
|
|
|
};
|
|
|
+ BoundingBoxRenderer.prototype.renderOcclusionBoundingBox = 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());
|
|
|
+ engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());
|
|
|
+ engine.setDepthFunctionToLess();
|
|
|
+ this._scene.resetCachedMaterial();
|
|
|
+ this._colorShader.bind(worldMatrix);
|
|
|
+ engine.draw(false, 0, 24);
|
|
|
+ this._colorShader.unbind();
|
|
|
+ engine.setDepthFunctionToLessOrEqual();
|
|
|
+ engine.setDepthWrite(true);
|
|
|
+ engine.setColorWrite(true);
|
|
|
+ };
|
|
|
BoundingBoxRenderer.prototype.dispose = function () {
|
|
|
if (!this._colorShader) {
|
|
|
return;
|