oneMinusBlock.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 opposite (1 - x) of a value
  9. */
  10. export class OneMinusBlock extends NodeMaterialBlock {
  11. /**
  12. * Creates a new OneMinusBlock
  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. }
  21. /**
  22. * Gets the current class name
  23. * @returns the class name
  24. */
  25. public getClassName() {
  26. return "OneMinusBlock";
  27. }
  28. /**
  29. * Gets the input component
  30. */
  31. public get input(): NodeMaterialConnectionPoint {
  32. return this._inputs[0];
  33. }
  34. /**
  35. * Gets the output component
  36. */
  37. public get output(): NodeMaterialConnectionPoint {
  38. return this._outputs[0];
  39. }
  40. protected _buildBlock(state: NodeMaterialBuildState) {
  41. super._buildBlock(state);
  42. let output = this._outputs[0];
  43. state.compilationString += this._declareOutput(output, state) + ` = 1. - ${this.input.associatedVariableName};\r\n`;
  44. return this;
  45. }
  46. }
  47. _TypeStore.RegisteredTypes["BABYLON.OneMinusBlock"] = OneMinusBlock;
  48. _TypeStore.RegisteredTypes["BABYLON.OppositeBlock"] = OneMinusBlock; // Backward compatibility