dotBlock.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 apply a dot product between 2 vectors
  9. */
  10. export class DotBlock extends NodeMaterialBlock {
  11. /**
  12. * Creates a new DotBlock
  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.Float);
  20. this._linkConnectionTypes(0, 1);
  21. this._inputs[0].excludedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Float);
  22. this._inputs[0].excludedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Matrix);
  23. this._inputs[1].excludedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Float);
  24. this._inputs[1].excludedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Matrix);
  25. }
  26. /**
  27. * Gets the current class name
  28. * @returns the class name
  29. */
  30. public getClassName() {
  31. return "DotBlock";
  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 output component
  47. */
  48. public get output(): NodeMaterialConnectionPoint {
  49. return this._outputs[0];
  50. }
  51. protected _buildBlock(state: NodeMaterialBuildState) {
  52. super._buildBlock(state);
  53. let output = this._outputs[0];
  54. state.compilationString += this._declareOutput(output, state) + ` = dot(${this.left.associatedVariableName}, ${this.right.associatedVariableName});\r\n`;
  55. return this;
  56. }
  57. }
  58. _TypeStore.RegisteredTypes["BABYLON.DotBlock"] = DotBlock;