normalizeBlock.ts 2.0 KB

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