@babylonjs/core
Version:
Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.
209 lines (208 loc) • 10.7 kB
JavaScript
import { __decorate } from "../../../../tslib.es6.js";
import { NodeRenderGraphBlock } from "../../nodeRenderGraphBlock.js";
import { RegisterClass } from "../../../../Misc/typeStore.js";
import { NodeRenderGraphBlockConnectionPointTypes } from "../../Types/nodeRenderGraphTypes.js";
import { editableInPropertyPage } from "../../../../Decorators/nodeDecorator.js";
import { FrameGraphSelectionOutlineLayerTask } from "../../../Tasks/Layers/selectionOutlineTask.js";
import { NodeRenderGraphConnectionPointCustomObject } from "../../nodeRenderGraphConnectionPointCustomObject.js";
import { NodeRenderGraphBaseObjectRendererBlock } from "../Rendering/baseObjectRendererBlock.js";
import { Color3 } from "../../../../Maths/math.color.js";
/**
* Block that implements the selection outline layer
*/
export class NodeRenderGraphSelectionOutlineLayerBlock extends NodeRenderGraphBlock {
/**
* Gets the frame graph task associated with this block
*/
get task() {
return this._frameGraphTask;
}
/**
* Create a new NodeRenderGraphSelectionOutlineLayerBlock
* @param name defines the block name
* @param frameGraph defines the hosting frame graph
* @param scene defines the hosting scene
* @param layerTextureRatio multiplication factor applied to the main texture size to compute the size of the layer render target texture (default: 1.0)
* @param layerTextureFixedSize defines the fixed size of the layer render target texture. Takes precedence over layerTextureRatio if provided (default: undefined)
* @param layerTextureType defines the type of the layer texture (default: 2)
*/
constructor(name, frameGraph, scene, layerTextureRatio = 1.0, layerTextureFixedSize, layerTextureType = 2) {
super(name, frameGraph, scene);
this._additionalConstructionParameters = [layerTextureRatio, layerTextureFixedSize, layerTextureType];
this.registerInput("target", NodeRenderGraphBlockConnectionPointTypes.AutoDetect);
this.registerInput("layer", NodeRenderGraphBlockConnectionPointTypes.AutoDetect, true);
this.registerInput("objectRenderer", NodeRenderGraphBlockConnectionPointTypes.Object, false, new NodeRenderGraphConnectionPointCustomObject("objectRenderer", this, 0 /* NodeRenderGraphConnectionPointDirection.Input */, NodeRenderGraphBaseObjectRendererBlock, "NodeRenderGraphBaseObjectRendererBlock"));
this.registerInput("depth", NodeRenderGraphBlockConnectionPointTypes.AutoDetect);
this.depth.addExcludedConnectionPointFromAllowedTypes(NodeRenderGraphBlockConnectionPointTypes.TextureViewDepth | NodeRenderGraphBlockConnectionPointTypes.TextureNormalizedViewDepth);
this._addDependenciesInput();
this.registerOutput("output", NodeRenderGraphBlockConnectionPointTypes.BasedOnInput);
this.target.addExcludedConnectionPointFromAllowedTypes(NodeRenderGraphBlockConnectionPointTypes.TextureAllButBackBufferDepthStencil);
this.layer.addExcludedConnectionPointFromAllowedTypes(NodeRenderGraphBlockConnectionPointTypes.TextureAllButBackBuffer);
this.output._typeConnectionSource = this.target;
this._frameGraphTask = new FrameGraphSelectionOutlineLayerTask(this.name, this._frameGraph, this._scene, {
mainTextureRatio: layerTextureRatio,
mainTextureFixedSize: layerTextureFixedSize,
mainTextureType: layerTextureType,
});
}
_createTask(layerTextureRatio, layerTextureFixedSize, layerTextureType) {
const outlineColor = this.outlineColor;
const outlineThickness = this.outlineThickness;
const occlusionStrength = this.occlusionStrength;
const occlusionThreshold = this.occlusionThreshold;
this._frameGraphTask?.dispose();
this._frameGraphTask = new FrameGraphSelectionOutlineLayerTask(this.name, this._frameGraph, this._scene, {
mainTextureRatio: layerTextureRatio,
mainTextureFixedSize: layerTextureFixedSize,
mainTextureType: layerTextureType,
});
this.outlineColor = outlineColor;
this.outlineThickness = outlineThickness;
this.occlusionStrength = occlusionStrength;
this.occlusionThreshold = occlusionThreshold;
this._additionalConstructionParameters = [layerTextureRatio, layerTextureFixedSize, layerTextureType];
}
/** Multiplication factor applied to the main texture size to compute the size of the layer render target texture */
get layerTextureRatio() {
return this._frameGraphTask.layer._options.mainTextureRatio;
}
set layerTextureRatio(value) {
const options = this._frameGraphTask.layer._options;
this._createTask(value, options.mainTextureFixedSize, options.mainTextureType);
}
/** Defines the fixed size of the layer render target texture. Takes precedence over layerTextureRatio if provided */
get layerTextureFixedSize() {
return this._frameGraphTask.layer._options.mainTextureFixedSize;
}
set layerTextureFixedSize(value) {
const options = this._frameGraphTask.layer._options;
this._createTask(options.mainTextureRatio, value, options.mainTextureType);
}
/** Defines the type of the layer texture */
get layerTextureType() {
return this._frameGraphTask.layer._options.mainTextureType;
}
set layerTextureType(value) {
const options = this._frameGraphTask.layer._options;
this._createTask(options.mainTextureRatio, options.mainTextureFixedSize, value);
}
/** The outline color */
get outlineColor() {
return this._frameGraphTask.layer.outlineColor;
}
set outlineColor(value) {
this._frameGraphTask.layer.outlineColor = value;
}
/** The thickness of the edges */
get outlineThickness() {
return this._frameGraphTask.layer.outlineThickness;
}
set outlineThickness(value) {
this._frameGraphTask.layer.outlineThickness = value;
}
/** The strength of the occlusion effect */
get occlusionStrength() {
return this._frameGraphTask.layer.occlusionStrength;
}
set occlusionStrength(value) {
this._frameGraphTask.layer.occlusionStrength = value;
}
/** The occlusion threshold */
get occlusionThreshold() {
return this._frameGraphTask.layer.occlusionThreshold;
}
set occlusionThreshold(value) {
this._frameGraphTask.layer.occlusionThreshold = value;
}
/**
* Gets the current class name
* @returns the class name
*/
getClassName() {
return "NodeRenderGraphSelectionOutlineLayerBlock";
}
/**
* Gets the target texture input component
*/
get target() {
return this._inputs[0];
}
/**
* Gets the layer texture input component
*/
get layer() {
return this._inputs[1];
}
/**
* Gets the objectRenderer input component
*/
get objectRenderer() {
return this._inputs[2];
}
/**
* Gets the depth input component
*/
get depth() {
return this._inputs[3];
}
/**
* Gets the output component
*/
get output() {
return this._outputs[0];
}
_buildBlock(state) {
super._buildBlock(state);
this.output.value = this._frameGraphTask.outputTexture;
this._frameGraphTask.targetTexture = this.target.connectedPoint?.value;
this._frameGraphTask.layerTexture = this.layer.connectedPoint?.value;
this._frameGraphTask.objectRendererTask = this.objectRenderer.connectedPoint?.value;
this._frameGraphTask.depthTexture = this.depth.connectedPoint?.value;
}
_dumpPropertiesCode() {
const codes = [];
codes.push(`${this._codeVariableName}.outlineColor = new BABYLON.Color3(${this.outlineColor.r}, ${this.outlineColor.g}, ${this.outlineColor.b});`);
codes.push(`${this._codeVariableName}.outlineThickness = ${this.outlineThickness};`);
codes.push(`${this._codeVariableName}.occlusionStrength = ${this.occlusionStrength};`);
codes.push(`${this._codeVariableName}.occlusionThreshold = ${this.occlusionThreshold};`);
return super._dumpPropertiesCode() + codes.join("\n");
}
serialize() {
const serializationObject = super.serialize();
serializationObject.outlineColor = this.outlineColor.asArray();
serializationObject.outlineThickness = this.outlineThickness;
serializationObject.occlusionStrength = this.occlusionStrength;
serializationObject.occlusionThreshold = this.occlusionThreshold;
return serializationObject;
}
_deserialize(serializationObject) {
super._deserialize(serializationObject);
this.outlineColor = Color3.FromArray(serializationObject.outlineColor);
this.outlineThickness = serializationObject.outlineThickness;
this.occlusionStrength = serializationObject.occlusionStrength;
this.occlusionThreshold = serializationObject.occlusionThreshold;
}
}
__decorate([
editableInPropertyPage("Layer texture ratio", 1 /* PropertyTypeForEdition.Float */, "PROPERTIES")
], NodeRenderGraphSelectionOutlineLayerBlock.prototype, "layerTextureRatio", null);
__decorate([
editableInPropertyPage("Layer texture fixed size", 1 /* PropertyTypeForEdition.Float */, "PROPERTIES")
], NodeRenderGraphSelectionOutlineLayerBlock.prototype, "layerTextureFixedSize", null);
__decorate([
editableInPropertyPage("Layer texture type", 10 /* PropertyTypeForEdition.TextureType */, "PROPERTIES")
], NodeRenderGraphSelectionOutlineLayerBlock.prototype, "layerTextureType", null);
__decorate([
editableInPropertyPage("Outline color", 6 /* PropertyTypeForEdition.Color3 */, "PROPERTIES")
], NodeRenderGraphSelectionOutlineLayerBlock.prototype, "outlineColor", null);
__decorate([
editableInPropertyPage("Outline thickness", 1 /* PropertyTypeForEdition.Float */, "PROPERTIES", { min: 0, max: 30 })
], NodeRenderGraphSelectionOutlineLayerBlock.prototype, "outlineThickness", null);
__decorate([
editableInPropertyPage("Occlusion strength", 1 /* PropertyTypeForEdition.Float */, "PROPERTIES", { min: 0, max: 1 })
], NodeRenderGraphSelectionOutlineLayerBlock.prototype, "occlusionStrength", null);
__decorate([
editableInPropertyPage("Occlusion threshold", 1 /* PropertyTypeForEdition.Float */, "PROPERTIES", { min: 0, max: 1 })
], NodeRenderGraphSelectionOutlineLayerBlock.prototype, "occlusionThreshold", null);
RegisterClass("BABYLON.NodeRenderGraphSelectionOutlineLayerBlock", NodeRenderGraphSelectionOutlineLayerBlock);
//# sourceMappingURL=selectionOutlineLayerBlock.js.map