lerpBlock.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.AutoDetect);
  20. this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.BasedOnInput);
  21. this._outputs[0]._typeConnectionSource = this._inputs[0];
  22. this._linkConnectionTypes(0, 1);
  23. this._linkConnectionTypes(1, 2, true);
  24. this._inputs[2].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Float);
  25. }
  26. /**
  27. * Gets the current class name
  28. * @returns the class name
  29. */
  30. public getClassName() {
  31. return "LerpBlock";
  32. }
  33. /**
  34. * Gets the left operand input component
  35. */
  36. public get left(): NodeMaterialConnectionPoint {
  37. return this._inputs[0];
  38. }
  39. /**
  40. * Gets the right operand input component
  41. */
  42. public get right(): NodeMaterialConnectionPoint {
  43. return this._inputs[1];
  44. }
  45. /**
  46. * Gets the gradient operand input component
  47. */
  48. public get gradient(): NodeMaterialConnectionPoint {
  49. return this._inputs[2];
  50. }
  51. /**
  52. * Gets the output component
  53. */
  54. public get output(): NodeMaterialConnectionPoint {
  55. return this._outputs[0];
  56. }
  57. protected _buildBlock(state: NodeMaterialBuildState) {
  58. super._buildBlock(state);
  59. let output = this._outputs[0];
  60. state.compilationString += this._declareOutput(output, state) + ` = mix(${this.left.associatedVariableName} , ${this.right.associatedVariableName}, ${this.gradient.associatedVariableName});\r\n`;
  61. return this;
  62. }
  63. }
  64. _TypeStore.RegisteredTypes["BABYLON.LerpBlock"] = LerpBlock;