crossBlock.ts 2.7 KB

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