|
@@ -21650,15 +21650,18 @@ var BABYLON;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // Todo. Move into an occlusion query component.
|
|
|
var scene = this.getScene();
|
|
|
- var occlusionBoundingBoxRenderer = scene.getBoundingBoxRenderer();
|
|
|
- if (!this._occlusionQuery) {
|
|
|
- this._occlusionQuery = engine.createQuery();
|
|
|
+ if (scene.getBoundingBoxRenderer) {
|
|
|
+ var occlusionBoundingBoxRenderer = scene.getBoundingBoxRenderer();
|
|
|
+ if (!this._occlusionQuery) {
|
|
|
+ this._occlusionQuery = engine.createQuery();
|
|
|
+ }
|
|
|
+ engine.beginOcclusionQuery(this.occlusionQueryAlgorithmType, this._occlusionQuery);
|
|
|
+ occlusionBoundingBoxRenderer.renderOcclusionBoundingBox(this);
|
|
|
+ engine.endOcclusionQuery(this.occlusionQueryAlgorithmType);
|
|
|
+ this._isOcclusionQueryInProgress = true;
|
|
|
}
|
|
|
- engine.beginOcclusionQuery(this.occlusionQueryAlgorithmType, this._occlusionQuery);
|
|
|
- occlusionBoundingBoxRenderer.renderOcclusionBoundingBox(this);
|
|
|
- engine.endOcclusionQuery(this.occlusionQueryAlgorithmType);
|
|
|
- this._isOcclusionQueryInProgress = true;
|
|
|
};
|
|
|
/** No occlusion */
|
|
|
AbstractMesh.OCCLUSION_TYPE_NONE = 0;
|
|
@@ -23964,15 +23967,20 @@ var BABYLON;
|
|
|
SceneComponentConstants.NAME_EFFECTLAYER = "EffectLayer";
|
|
|
SceneComponentConstants.NAME_LAYER = "Layer";
|
|
|
SceneComponentConstants.NAME_LENSFLARESYSTEM = "LensFlareSystem";
|
|
|
+ SceneComponentConstants.NAME_BOUNDINGBOXRENDERER = "BoundingBoxRenderer";
|
|
|
SceneComponentConstants.STEP_ISREADYFORMESH_EFFECTLAYER = 0;
|
|
|
+ SceneComponentConstants.STEP_BEFOREEVALUATEACTIVEMESH_BOUNDINGBOXRENDERER = 0;
|
|
|
+ SceneComponentConstants.STEP_EVALUATESUBMESH_BOUNDINGBOXRENDERER = 0;
|
|
|
+ SceneComponentConstants.STEP_ACTIVEMESH_BOUNDINGBOXRENDERER = 0;
|
|
|
SceneComponentConstants.STEP_CAMERADRAWRENDERTARGET_EFFECTLAYER = 1;
|
|
|
SceneComponentConstants.STEP_BEFORECAMERADRAW_EFFECTLAYER = 0;
|
|
|
SceneComponentConstants.STEP_BEFORECAMERADRAW_LAYER = 1;
|
|
|
SceneComponentConstants.STEP_AFTERRENDERINGGROUPDRAW_EFFECTLAYER_DRAW = 0;
|
|
|
SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER = 0;
|
|
|
SceneComponentConstants.STEP_AFTERCAMERADRAW_LENSFLARESYSTEM = 1;
|
|
|
- SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW = 2;
|
|
|
- SceneComponentConstants.STEP_AFTERCAMERADRAW_LAYER = 3;
|
|
|
+ SceneComponentConstants.STEP_AFTERCAMERADRAW_BOUNDINGBOXRENDERER = 2;
|
|
|
+ SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW = 3;
|
|
|
+ SceneComponentConstants.STEP_AFTERCAMERADRAW_LAYER = 4;
|
|
|
return SceneComponentConstants;
|
|
|
}());
|
|
|
BABYLON.SceneComponentConstants = SceneComponentConstants;
|
|
@@ -24249,10 +24257,6 @@ var BABYLON;
|
|
|
_this._forceWireframe = false;
|
|
|
_this._forcePointsCloud = false;
|
|
|
/**
|
|
|
- * Gets or sets a boolean indicating if all bounding boxes must be rendered
|
|
|
- */
|
|
|
- _this.forceShowBoundingBoxes = false;
|
|
|
- /**
|
|
|
* Gets or sets a boolean indicating if animations are enabled
|
|
|
*/
|
|
|
_this.animationsEnabled = true;
|
|
@@ -24651,6 +24655,10 @@ var BABYLON;
|
|
|
*/
|
|
|
_this._components = [];
|
|
|
/**
|
|
|
+ * Backing store of defined scene components.
|
|
|
+ */
|
|
|
+ _this._serializableComponents = [];
|
|
|
+ /**
|
|
|
* List of components to register on the next registration step.
|
|
|
*/
|
|
|
_this._transientComponents = [];
|
|
@@ -24659,6 +24667,18 @@ var BABYLON;
|
|
|
*/
|
|
|
_this._isReadyForMeshStage = BABYLON.Stage.Create();
|
|
|
/**
|
|
|
+ * Defines the actions happening before evaluate active mesh checks.
|
|
|
+ */
|
|
|
+ _this._beforeEvaluateActiveMeshStage = BABYLON.Stage.Create();
|
|
|
+ /**
|
|
|
+ * Defines the actions happening during the evaluate sub mesh checks.
|
|
|
+ */
|
|
|
+ _this._evaluateSubMeshStage = BABYLON.Stage.Create();
|
|
|
+ /**
|
|
|
+ * Defines the actions happening during the active mesh stage.
|
|
|
+ */
|
|
|
+ _this._activeMeshStage = BABYLON.Stage.Create();
|
|
|
+ /**
|
|
|
* Defines the actions happening during the per camera render target step.
|
|
|
*/
|
|
|
_this._cameraDrawRenderTargetStage = BABYLON.Stage.Create();
|
|
@@ -25157,6 +25177,10 @@ var BABYLON;
|
|
|
Scene.prototype._addComponent = function (component) {
|
|
|
this._components.push(component);
|
|
|
this._transientComponents.push(component);
|
|
|
+ var serializableComponent = component;
|
|
|
+ if (serializableComponent.addFromContainer) {
|
|
|
+ this._serializableComponents.push(serializableComponent);
|
|
|
+ }
|
|
|
};
|
|
|
/**
|
|
|
* Gets a component from the scene.
|
|
@@ -25283,16 +25307,6 @@ var BABYLON;
|
|
|
return this._cachedEffect !== effect || this._cachedMaterial !== material || this._cachedVisibility !== visibility;
|
|
|
};
|
|
|
/**
|
|
|
- * Gets the bounding box renderer associated with the scene
|
|
|
- * @returns a BoundingBoxRenderer
|
|
|
- */
|
|
|
- Scene.prototype.getBoundingBoxRenderer = function () {
|
|
|
- if (!this._boundingBoxRenderer) {
|
|
|
- this._boundingBoxRenderer = new BABYLON.BoundingBoxRenderer(this);
|
|
|
- }
|
|
|
- return this._boundingBoxRenderer;
|
|
|
- };
|
|
|
- /**
|
|
|
* Gets the outline renderer associated with the scene
|
|
|
* @returns a OutlineRenderer
|
|
|
*/
|
|
@@ -27680,11 +27694,9 @@ var BABYLON;
|
|
|
};
|
|
|
Scene.prototype._evaluateSubMesh = function (subMesh, mesh) {
|
|
|
if (this.dispatchAllSubMeshesOfActiveMeshes || mesh.alwaysSelectAsActiveMesh || mesh.subMeshes.length === 1 || subMesh.isInFrustum(this._frustumPlanes)) {
|
|
|
- if (mesh.showSubMeshesBoundingBox) {
|
|
|
- var boundingInfo = subMesh.getBoundingInfo();
|
|
|
- if (boundingInfo !== null && boundingInfo !== undefined) {
|
|
|
- this.getBoundingBoxRenderer().renderList.push(boundingInfo.boundingBox);
|
|
|
- }
|
|
|
+ for (var _i = 0, _a = this._evaluateSubMeshStage; _i < _a.length; _i++) {
|
|
|
+ var step = _a[_i];
|
|
|
+ step.action(mesh, subMesh);
|
|
|
}
|
|
|
var material = subMesh.getMaterial();
|
|
|
if (material !== null && material !== undefined) {
|
|
@@ -27796,8 +27808,9 @@ var BABYLON;
|
|
|
this._activeParticleSystems.reset();
|
|
|
this._activeSkeletons.reset();
|
|
|
this._softwareSkinnedMeshes.reset();
|
|
|
- if (this._boundingBoxRenderer) {
|
|
|
- this._boundingBoxRenderer.reset();
|
|
|
+ for (var _i = 0, _a = this._beforeEvaluateActiveMeshStage; _i < _a.length; _i++) {
|
|
|
+ var step = _a[_i];
|
|
|
+ step.action();
|
|
|
}
|
|
|
// Meshes
|
|
|
var meshes;
|
|
@@ -27885,9 +27898,9 @@ var BABYLON;
|
|
|
this._softwareSkinnedMeshes.pushNoDuplicate(mesh);
|
|
|
}
|
|
|
}
|
|
|
- if (sourceMesh.showBoundingBox || this.forceShowBoundingBoxes) {
|
|
|
- var boundingInfo = sourceMesh.getBoundingInfo();
|
|
|
- this.getBoundingBoxRenderer().renderList.push(boundingInfo.boundingBox);
|
|
|
+ for (var _i = 0, _a = this._activeMeshStage; _i < _a.length; _i++) {
|
|
|
+ var step = _a[_i];
|
|
|
+ step.action(sourceMesh, mesh);
|
|
|
}
|
|
|
if (mesh !== undefined && mesh !== null
|
|
|
&& mesh.subMeshes !== undefined && mesh.subMeshes !== null && mesh.subMeshes.length > 0) {
|
|
@@ -28001,10 +28014,6 @@ var BABYLON;
|
|
|
var step = _e[_d];
|
|
|
step.action(this.activeCamera);
|
|
|
}
|
|
|
- // Bounding boxes
|
|
|
- if (this._boundingBoxRenderer) {
|
|
|
- this._boundingBoxRenderer.render();
|
|
|
- }
|
|
|
// Finalize frame
|
|
|
if (this.postProcessManager) {
|
|
|
this.postProcessManager._finalizeFrame(camera.isIntermediate);
|
|
@@ -28494,6 +28503,9 @@ var BABYLON;
|
|
|
this.morphTargetManagers = [];
|
|
|
this._transientComponents = [];
|
|
|
this._isReadyForMeshStage.clear();
|
|
|
+ this._beforeEvaluateActiveMeshStage.clear();
|
|
|
+ this._evaluateSubMeshStage.clear();
|
|
|
+ this._activeMeshStage.clear();
|
|
|
this._cameraDrawRenderTargetStage.clear();
|
|
|
this._beforeCameraDrawStage.clear();
|
|
|
this._beforeRenderingGroupDrawStage.clear();
|
|
@@ -28526,9 +28538,6 @@ var BABYLON;
|
|
|
this._softwareSkinnedMeshes.dispose();
|
|
|
this._renderTargets.dispose();
|
|
|
this._registeredForLateAnimationBindings.dispose();
|
|
|
- if (this._boundingBoxRenderer) {
|
|
|
- this._boundingBoxRenderer.dispose();
|
|
|
- }
|
|
|
this._meshesForIntersections.dispose();
|
|
|
this._toBeDisposed.dispose();
|
|
|
// Abort active requests
|
|
@@ -29119,9 +29128,6 @@ var BABYLON;
|
|
|
var component = _e[_d];
|
|
|
component.rebuild();
|
|
|
}
|
|
|
- if (this._boundingBoxRenderer) {
|
|
|
- this._boundingBoxRenderer._rebuild();
|
|
|
- }
|
|
|
for (var _f = 0, _g = this.particleSystems; _f < _g.length; _f++) {
|
|
|
var system = _g[_f];
|
|
|
system.rebuild();
|
|
@@ -29521,7 +29527,7 @@ var BABYLON;
|
|
|
this.textures.forEach(function (o) {
|
|
|
_this.scene.addTexture(o);
|
|
|
});
|
|
|
- for (var _i = 0, _a = this.scene._components; _i < _a.length; _i++) {
|
|
|
+ for (var _i = 0, _a = this.scene._serializableComponents; _i < _a.length; _i++) {
|
|
|
var component = _a[_i];
|
|
|
component.addFromContainer(this.scene);
|
|
|
}
|
|
@@ -29578,7 +29584,7 @@ var BABYLON;
|
|
|
this.textures.forEach(function (o) {
|
|
|
_this.scene.removeTexture(o);
|
|
|
});
|
|
|
- for (var _i = 0, _a = this.scene._components; _i < _a.length; _i++) {
|
|
|
+ for (var _i = 0, _a = this.scene._serializableComponents; _i < _a.length; _i++) {
|
|
|
var component = _a[_i];
|
|
|
component.removeFromContainer(this.scene);
|
|
|
}
|
|
@@ -89284,33 +89290,85 @@ var BABYLON;
|
|
|
|
|
|
var BABYLON;
|
|
|
(function (BABYLON) {
|
|
|
+ Object.defineProperty(BABYLON.Scene.prototype, "forceShowBoundingBoxes", {
|
|
|
+ get: function () {
|
|
|
+ return this._forceShowBoundingBoxes || false;
|
|
|
+ },
|
|
|
+ set: function (value) {
|
|
|
+ this._forceShowBoundingBoxes = value;
|
|
|
+ // Lazyly creates a BB renderer if needed.
|
|
|
+ if (value) {
|
|
|
+ this.getBoundingBoxRenderer();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
+ BABYLON.Scene.prototype.getBoundingBoxRenderer = function () {
|
|
|
+ if (!this._boundingBoxRenderer) {
|
|
|
+ this._boundingBoxRenderer = new BoundingBoxRenderer(this);
|
|
|
+ }
|
|
|
+ return this._boundingBoxRenderer;
|
|
|
+ };
|
|
|
var BoundingBoxRenderer = /** @class */ (function () {
|
|
|
function BoundingBoxRenderer(scene) {
|
|
|
+ /**
|
|
|
+ * The component name helpfull to identify the component in the list of scene components.
|
|
|
+ */
|
|
|
+ this.name = BABYLON.SceneComponentConstants.NAME_BOUNDINGBOXRENDERER;
|
|
|
this.frontColor = new BABYLON.Color3(1, 1, 1);
|
|
|
this.backColor = new BABYLON.Color3(0.1, 0.1, 0.1);
|
|
|
this.showBackLines = true;
|
|
|
this.renderList = new BABYLON.SmartArray(32);
|
|
|
this._vertexBuffers = {};
|
|
|
- this._scene = scene;
|
|
|
+ this.scene = scene;
|
|
|
+ scene._addComponent(this);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * Registers the component in a given scene
|
|
|
+ */
|
|
|
+ BoundingBoxRenderer.prototype.register = function () {
|
|
|
+ this.scene._beforeEvaluateActiveMeshStage.registerStep(BABYLON.SceneComponentConstants.STEP_BEFOREEVALUATEACTIVEMESH_BOUNDINGBOXRENDERER, this, this.reset);
|
|
|
+ this.scene._activeMeshStage.registerStep(BABYLON.SceneComponentConstants.STEP_ACTIVEMESH_BOUNDINGBOXRENDERER, this, this._activeMesh);
|
|
|
+ this.scene._evaluateSubMeshStage.registerStep(BABYLON.SceneComponentConstants.STEP_EVALUATESUBMESH_BOUNDINGBOXRENDERER, this, this._evaluateSubMesh);
|
|
|
+ this.scene._afterCameraDrawStage.registerStep(BABYLON.SceneComponentConstants.STEP_AFTERCAMERADRAW_BOUNDINGBOXRENDERER, this, this.render);
|
|
|
+ };
|
|
|
+ BoundingBoxRenderer.prototype._evaluateSubMesh = function (mesh, subMesh) {
|
|
|
+ if (mesh.showSubMeshesBoundingBox) {
|
|
|
+ var boundingInfo = subMesh.getBoundingInfo();
|
|
|
+ if (boundingInfo !== null && boundingInfo !== undefined) {
|
|
|
+ this.renderList.push(boundingInfo.boundingBox);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ BoundingBoxRenderer.prototype._activeMesh = function (sourceMesh, mesh) {
|
|
|
+ if (sourceMesh.showBoundingBox || this.scene.forceShowBoundingBoxes) {
|
|
|
+ var boundingInfo = sourceMesh.getBoundingInfo();
|
|
|
+ this.renderList.push(boundingInfo.boundingBox);
|
|
|
+ }
|
|
|
+ };
|
|
|
BoundingBoxRenderer.prototype._prepareRessources = function () {
|
|
|
if (this._colorShader) {
|
|
|
return;
|
|
|
}
|
|
|
- this._colorShader = new BABYLON.ShaderMaterial("colorShader", this._scene, "color", {
|
|
|
+ this._colorShader = new BABYLON.ShaderMaterial("colorShader", this.scene, "color", {
|
|
|
attributes: [BABYLON.VertexBuffer.PositionKind],
|
|
|
uniforms: ["world", "viewProjection", "color"]
|
|
|
});
|
|
|
- var engine = this._scene.getEngine();
|
|
|
+ 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._createIndexBuffer();
|
|
|
};
|
|
|
BoundingBoxRenderer.prototype._createIndexBuffer = function () {
|
|
|
- var engine = this._scene.getEngine();
|
|
|
+ var engine = this.scene.getEngine();
|
|
|
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]);
|
|
|
};
|
|
|
- BoundingBoxRenderer.prototype._rebuild = function () {
|
|
|
+ /**
|
|
|
+ * Rebuilds the elements related to this component in case of
|
|
|
+ * context lost for instance.
|
|
|
+ */
|
|
|
+ BoundingBoxRenderer.prototype.rebuild = function () {
|
|
|
var vb = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind];
|
|
|
if (vb) {
|
|
|
vb._rebuild();
|
|
@@ -89328,7 +89386,7 @@ var BABYLON;
|
|
|
if (!this._colorShader.isReady()) {
|
|
|
return;
|
|
|
}
|
|
|
- var engine = this._scene.getEngine();
|
|
|
+ var engine = this.scene.getEngine();
|
|
|
engine.setDepthWrite(false);
|
|
|
this._colorShader._preBind();
|
|
|
for (var boundingBoxIndex = 0; boundingBoxIndex < this.renderList.length; boundingBoxIndex++) {
|
|
@@ -89345,7 +89403,7 @@ var BABYLON;
|
|
|
if (this.showBackLines) {
|
|
|
// Back
|
|
|
engine.setDepthFunctionToGreaterOrEqual();
|
|
|
- this._scene.resetCachedMaterial();
|
|
|
+ this.scene.resetCachedMaterial();
|
|
|
this._colorShader.setColor4("color", this.backColor.toColor4());
|
|
|
this._colorShader.bind(worldMatrix);
|
|
|
// Draw order
|
|
@@ -89353,7 +89411,7 @@ var BABYLON;
|
|
|
}
|
|
|
// Front
|
|
|
engine.setDepthFunctionToLess();
|
|
|
- this._scene.resetCachedMaterial();
|
|
|
+ this.scene.resetCachedMaterial();
|
|
|
this._colorShader.setColor4("color", this.frontColor.toColor4());
|
|
|
this._colorShader.bind(worldMatrix);
|
|
|
// Draw order
|
|
@@ -89368,7 +89426,7 @@ var BABYLON;
|
|
|
if (!this._colorShader.isReady() || !mesh._boundingInfo) {
|
|
|
return;
|
|
|
}
|
|
|
- var engine = this._scene.getEngine();
|
|
|
+ var engine = this.scene.getEngine();
|
|
|
engine.setDepthWrite(false);
|
|
|
engine.setColorWrite(false);
|
|
|
this._colorShader._preBind();
|
|
@@ -89382,7 +89440,7 @@ var BABYLON;
|
|
|
.multiply(boundingBox.getWorldMatrix());
|
|
|
engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());
|
|
|
engine.setDepthFunctionToLess();
|
|
|
- this._scene.resetCachedMaterial();
|
|
|
+ this.scene.resetCachedMaterial();
|
|
|
this._colorShader.bind(worldMatrix);
|
|
|
engine.drawElementsType(BABYLON.Material.LineListDrawMode, 0, 24);
|
|
|
this._colorShader.unbind();
|
|
@@ -89401,7 +89459,7 @@ var BABYLON;
|
|
|
buffer.dispose();
|
|
|
this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = null;
|
|
|
}
|
|
|
- this._scene.getEngine()._releaseBuffer(this._indexBuffer);
|
|
|
+ this.scene.getEngine()._releaseBuffer(this._indexBuffer);
|
|
|
};
|
|
|
return BoundingBoxRenderer;
|
|
|
}());
|
|
@@ -99743,7 +99801,7 @@ var BABYLON;
|
|
|
}
|
|
|
}
|
|
|
// Components
|
|
|
- for (var _b = 0, _c = scene._components; _b < _c.length; _b++) {
|
|
|
+ for (var _b = 0, _c = scene._serializableComponents; _b < _c.length; _b++) {
|
|
|
var component = _c[_b];
|
|
|
component.serialize(serializationObject);
|
|
|
}
|
|
@@ -99940,43 +99998,6 @@ var BABYLON;
|
|
|
}
|
|
|
};
|
|
|
/**
|
|
|
- * Serializes the component data to the specified json object
|
|
|
- * @param serializationObject The object to serialize to
|
|
|
- */
|
|
|
- LayerSceneComponent.prototype.serialize = function (serializationObject) {
|
|
|
- // TODO. Implement layer serialization
|
|
|
- // serializationObject.layers = [];
|
|
|
- // for (let layer of this._layers) {
|
|
|
- // if (layer.serialize) {
|
|
|
- // serializationObject.layers.push(layer.serialize());
|
|
|
- // }
|
|
|
- // }
|
|
|
- };
|
|
|
- /**
|
|
|
- * Adds all the element from the container to the scene
|
|
|
- * @param container the container holding the elements
|
|
|
- */
|
|
|
- LayerSceneComponent.prototype.addFromContainer = function (container) {
|
|
|
- if (!container.layers) {
|
|
|
- return;
|
|
|
- }
|
|
|
- // container.layers.forEach((o) => {
|
|
|
- // this.scene.addLayer(o);
|
|
|
- // });
|
|
|
- };
|
|
|
- /**
|
|
|
- * Removes all the elements in the container from the scene
|
|
|
- * @param container contains the elements to remove
|
|
|
- */
|
|
|
- LayerSceneComponent.prototype.removeFromContainer = function (container) {
|
|
|
- if (!container.layers) {
|
|
|
- return;
|
|
|
- }
|
|
|
- // container.layers.forEach((o) => {
|
|
|
- // this.scene.removeLayer(o);
|
|
|
- // });
|
|
|
- };
|
|
|
- /**
|
|
|
* Disposes the component and the associated ressources.
|
|
|
*/
|
|
|
LayerSceneComponent.prototype.dispose = function () {
|