scaleBlock.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 scale a vector by a float
  9. */
  10. export class ScaleBlock extends NodeMaterialBlock {
  11. /**
  12. * Creates a new ScaleBlock
  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.registerInput("factor", NodeMaterialBlockConnectionPointTypes.Float);
  19. this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.BasedOnInput);
  20. this._outputs[0]._typeConnectionSource = this._inputs[0];
  21. }
  22. /**
  23. * Gets the current class name
  24. * @returns the class name
  25. */
  26. public getClassName() {
  27. return "ScaleBlock";
  28. }
  29. /**
  30. * Gets the input component
  31. */
  32. public get input(): NodeMaterialConnectionPoint {
  33. return this._inputs[0];
  34. }
  35. /**
  36. * Gets the factor input component
  37. */
  38. public get factor(): NodeMaterialConnectionPoint {
  39. return this._inputs[1];
  40. }
  41. /**
  42. * Gets the output component
  43. */
  44. public get output(): NodeMaterialConnectionPoint {
  45. return this._outputs[0];
  46. }
  47. protected _buildBlock(state: NodeMaterialBuildState) {
  48. super._buildBlock(state);
  49. let output = this._outputs[0];
  50. state.compilationString += this._declareOutput(output, state) + ` = ${this.input.associatedVariableName} * ${this.factor.associatedVariableName};\r\n`;
  51. return this;
  52. }
  53. }
  54. _TypeStore.RegisteredTypes["BABYLON.ScaleBlock"] = ScaleBlock;