lengthBlock.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { NodeMaterialBlock } from '../nodeMaterialBlock';
  2. import { NodeMaterialBlockConnectionPointTypes } from '../nodeMaterialBlockConnectionPointTypes';
  3. import { NodeMaterialBuildState } from '../nodeMaterialBuildState';
  4. import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
  5. import { NodeMaterialBlockTargets } from '../nodeMaterialBlockTargets';
  6. import { _TypeStore } from '../../../Misc/typeStore';
  7. /**
  8. * Block used to get the length of a vector
  9. */
  10. export class LengthBlock extends NodeMaterialBlock {
  11. /**
  12. * Creates a new LengthBlock
  13. * @param name defines the block name
  14. */
  15. public constructor(name: string) {
  16. super(name, NodeMaterialBlockTargets.Neutral);
  17. this.registerInput("value", NodeMaterialBlockConnectionPointTypes.AutoDetect);
  18. this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Float);
  19. }
  20. /**
  21. * Gets the current class name
  22. * @returns the class name
  23. */
  24. public getClassName() {
  25. return "LengthBlock";
  26. }
  27. /**
  28. * Gets the value input component
  29. */
  30. public get value(): NodeMaterialConnectionPoint {
  31. return this._inputs[0];
  32. }
  33. /**
  34. * Gets the output component
  35. */
  36. public get output(): NodeMaterialConnectionPoint {
  37. return this._outputs[0];
  38. }
  39. protected _buildBlock(state: NodeMaterialBuildState) {
  40. super._buildBlock(state);
  41. let output = this._outputs[0];
  42. state.compilationString += this._declareOutput(output, state) + ` = length(${this.value.associatedVariableName});\r\n`;
  43. return this;
  44. }
  45. }
  46. _TypeStore.RegisteredTypes["BABYLON.LengthBlock"] = LengthBlock;