| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import { NodeMaterialBlock } from '../nodeMaterialBlock';
- import { NodeMaterialBlockConnectionPointTypes } from '../nodeMaterialBlockConnectionPointTypes';
- import { NodeMaterialBuildState } from '../nodeMaterialBuildState';
- import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
- /**
- * Block used to clamp a float
- */
- export class ClampBlock extends NodeMaterialBlock {
- /** Gets or sets the minimum range */
- public minimum = 0.0;
- /** Gets or sets the maximum range */
- public maximum = 1.0;
- /**
- * Creates a new ClampBlock
- * @param name defines the block name
- */
- public constructor(name: string) {
- super(name);
- this.registerInput("value", NodeMaterialBlockConnectionPointTypes.Float);
- this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Float);
- }
- /**
- * Gets the current class name
- * @returns the class name
- */
- public getClassName() {
- return "ClampBlock";
- }
- /**
- * Gets the value input component
- */
- public get value(): NodeMaterialConnectionPoint {
- return this._inputs[0];
- }
- protected _buildBlock(state: NodeMaterialBuildState) {
- super._buildBlock(state);
- let output = this._outputs[0];
- state.compilationString += this._declareOutput(output, state) + ` = clamp(${this.value.associatedVariableName}, ${this._writeFloat(this.minimum)}, ${this._writeFloat(this.maximum)});\r\n`;
- return this;
- }
- }
|