lerpBlock.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { NodeMaterialBlock } from '../nodeMaterialBlock';
  2. import { NodeMaterialBlockConnectionPointTypes } from '../Enums/nodeMaterialBlockConnectionPointTypes';
  3. import { NodeMaterialBuildState } from '../nodeMaterialBuildState';
  4. import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
  5. import { NodeMaterialBlockTargets } from '../Enums/nodeMaterialBlockTargets';
  6. import { _TypeStore } from '../../../Misc/typeStore';
  7. /**
  8. * Block used to lerp between 2 values
  9. */
  10. export class LerpBlock extends NodeMaterialBlock {
  11. /**
  12. * Creates a new LerpBlock
  13. * @param name defines the block name
  14. */
  15. public constructor(name: string) {
  16. super(name, NodeMaterialBlockTargets.Neutral);
  17. this.registerInput("left", NodeMaterialBlockConnectionPointTypes.AutoDetect);
  18. this.registerInput("right", NodeMaterialBlockConnectionPointTypes.AutoDetect);
  19. this.registerInput("gradient", NodeMaterialBlockConnectionPointTypes.Float);
  20. this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.BasedOnInput);
  21. this._outputs[0]._typeConnectionSource = this._inputs[0];
  22. this._linkConnectionTypes(0, 1);
  23. }
  24. /**
  25. * Gets the current class name
  26. * @returns the class name
  27. */
  28. public getClassName() {
  29. return "LerpBlock";
  30. }
  31. /**
  32. * Gets the left operand input component
  33. */
  34. public get left(): NodeMaterialConnectionPoint {
  35. return this._inputs[0];
  36. }
  37. /**
  38. * Gets the right operand input component
  39. */
  40. public get right(): NodeMaterialConnectionPoint {
  41. return this._inputs[1];
  42. }
  43. /**
  44. * Gets the gradient operand input component
  45. */
  46. public get gradient(): NodeMaterialConnectionPoint {
  47. return this._inputs[2];
  48. }
  49. /**
  50. * Gets the output component
  51. */
  52. public get output(): NodeMaterialConnectionPoint {
  53. return this._outputs[0];
  54. }
  55. protected _buildBlock(state: NodeMaterialBuildState) {
  56. super._buildBlock(state);
  57. let output = this._outputs[0];
  58. state.compilationString += this._declareOutput(output, state) + ` = mix(${this.left.associatedVariableName} , ${this.right.associatedVariableName}, ${this.gradient.associatedVariableName});\r\n`;
  59. return this;
  60. }
  61. }
  62. _TypeStore.RegisteredTypes["BABYLON.LerpBlock"] = LerpBlock;