reflectBlock.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 get the reflected vector from a direction and a normal
  9. */
  10. export class ReflectBlock extends NodeMaterialBlock {
  11. /**
  12. * Creates a new ReflectBlock
  13. * @param name defines the block name
  14. */
  15. public constructor(name: string) {
  16. super(name, NodeMaterialBlockTargets.Neutral);
  17. this.registerInput("incident", NodeMaterialBlockConnectionPointTypes.Vector3);
  18. this.registerInput("normal", NodeMaterialBlockConnectionPointTypes.Vector3);
  19. this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Vector3);
  20. this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector4);
  21. this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Color3);
  22. this._inputs[0].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Color4);
  23. this._inputs[1].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Vector4);
  24. this._inputs[1].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Color3);
  25. this._inputs[1].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Color4);
  26. }
  27. /**
  28. * Gets the current class name
  29. * @returns the class name
  30. */
  31. public getClassName() {
  32. return "ReflectBlock";
  33. }
  34. /**
  35. * Gets the incident component
  36. */
  37. public get incident(): NodeMaterialConnectionPoint {
  38. return this._inputs[0];
  39. }
  40. /**
  41. * Gets the normal component
  42. */
  43. public get normal(): NodeMaterialConnectionPoint {
  44. return this._inputs[1];
  45. }
  46. /**
  47. * Gets the output component
  48. */
  49. public get output(): NodeMaterialConnectionPoint {
  50. return this._outputs[0];
  51. }
  52. protected _buildBlock(state: NodeMaterialBuildState) {
  53. super._buildBlock(state);
  54. let output = this._outputs[0];
  55. state.compilationString += this._declareOutput(output, state) + ` = reflect(${this.incident.associatedVariableName}.xyz, ${this.normal.associatedVariableName}.xyz);\r\n`;
  56. return this;
  57. }
  58. }
  59. _TypeStore.RegisteredTypes["BABYLON.ReflectBlock"] = ReflectBlock;