multiplyBlock.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 multiply 2 values
  7. */
  8. export class MultiplyBlock extends NodeMaterialBlock {
  9. /**
  10. * Creates a new MultiplyBlock
  11. * @param name defines the block name
  12. */
  13. public constructor(name: string) {
  14. super(name);
  15. this.registerInput("left", NodeMaterialBlockConnectionPointTypes.AutoDetect);
  16. this.registerInput("right", NodeMaterialBlockConnectionPointTypes.AutoDetect);
  17. this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.BasedOnInput);
  18. this._outputs[0]._typeConnectionSource = this._inputs[0];
  19. }
  20. /**
  21. * Gets the current class name
  22. * @returns the class name
  23. */
  24. public getClassName() {
  25. return "MultiplyBlock";
  26. }
  27. /**
  28. * Gets the left operand input component
  29. */
  30. public get left(): NodeMaterialConnectionPoint {
  31. return this._inputs[0];
  32. }
  33. /**
  34. * Gets the right operand input component
  35. */
  36. public get right(): NodeMaterialConnectionPoint {
  37. return this._inputs[1];
  38. }
  39. /**
  40. * Gets the output component
  41. */
  42. public get output(): NodeMaterialConnectionPoint {
  43. return this._outputs[0];
  44. }
  45. protected _buildBlock(state: NodeMaterialBuildState) {
  46. super._buildBlock(state);
  47. let output = this._outputs[0];
  48. state.compilationString += this._declareOutput(output, state) + ` = ${this.left.associatedVariableName} * ${this.right.associatedVariableName};\r\n`;
  49. return this;
  50. }
  51. }