powBlock.ts 2.0 KB

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