clampBlock.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { NodeMaterialBlock } from '../nodeMaterialBlock';
  2. import { NodeMaterialBlockConnectionPointTypes } from '../nodeMaterialBlockConnectionPointTypes';
  3. import { NodeMaterialBuildState } from '../nodeMaterialBuildState';
  4. import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
  5. /**
  6. * Block used to clamp a float
  7. */
  8. export class ClampBlock extends NodeMaterialBlock {
  9. /** Gets or sets the minimum range */
  10. public minimum = 0.0;
  11. /** Gets or sets the maximum range */
  12. public maximum = 1.0;
  13. /**
  14. * Creates a new ClampBlock
  15. * @param name defines the block name
  16. */
  17. public constructor(name: string) {
  18. super(name);
  19. this.registerInput("value", NodeMaterialBlockConnectionPointTypes.Float);
  20. this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Float);
  21. }
  22. /**
  23. * Gets the current class name
  24. * @returns the class name
  25. */
  26. public getClassName() {
  27. return "ClampBlock";
  28. }
  29. /**
  30. * Gets the value input component
  31. */
  32. public get value(): NodeMaterialConnectionPoint {
  33. return this._inputs[0];
  34. }
  35. protected _buildBlock(state: NodeMaterialBuildState) {
  36. super._buildBlock(state);
  37. let output = this._outputs[0];
  38. state.compilationString += this._declareOutput(output, state) + ` = clamp(${this.value.associatedVariableName}, ${this._writeFloat(this.minimum)}, ${this._writeFloat(this.maximum)});\r\n`;
  39. return this;
  40. }
  41. }