addBlock.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 add 2 vectors
  9. */
  10. export class AddBlock extends NodeMaterialBlock {
  11. /**
  12. * Creates a new AddBlock
  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.registerOutput("output", NodeMaterialBlockConnectionPointTypes.BasedOnInput);
  20. this._outputs[0]._typeConnectionSource = this._inputs[0];
  21. this._linkConnectionTypes(0, 1);
  22. }
  23. /**
  24. * Gets the current class name
  25. * @returns the class name
  26. */
  27. public getClassName() {
  28. return "AddBlock";
  29. }
  30. /**
  31. * Gets the left operand input component
  32. */
  33. public get left(): NodeMaterialConnectionPoint {
  34. return this._inputs[0];
  35. }
  36. /**
  37. * Gets the right operand input component
  38. */
  39. public get right(): NodeMaterialConnectionPoint {
  40. return this._inputs[1];
  41. }
  42. /**
  43. * Gets the output component
  44. */
  45. public get output(): NodeMaterialConnectionPoint {
  46. return this._outputs[0];
  47. }
  48. protected _buildBlock(state: NodeMaterialBuildState) {
  49. super._buildBlock(state);
  50. let output = this._outputs[0];
  51. state.compilationString += this._declareOutput(output, state) + ` = ${this.left.associatedVariableName} + ${this.right.associatedVariableName};\r\n`;
  52. return this;
  53. }
  54. }
  55. _TypeStore.RegisteredTypes["BABYLON.AddBlock"] = AddBlock;