rgbSplitterBlock.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { NodeMaterialBlock } from '../../nodeMaterialBlock';
  2. import { NodeMaterialBlockConnectionPointTypes } from '../../nodeMaterialBlockConnectionPointTypes';
  3. import { NodeMaterialBuildState } from '../../nodeMaterialBuildState';
  4. import { NodeMaterialBlockTargets } from '../../nodeMaterialBlockTargets';
  5. import { NodeMaterialConnectionPoint } from '../../nodeMaterialBlockConnectionPoint';
  6. /**
  7. * Block used to expand a Color3 or a Vector3 into 3 outputs (one for each component)
  8. */
  9. export class RGBSplitterBlock extends NodeMaterialBlock {
  10. /**
  11. * Create a new RGBSplitterBlock
  12. * @param name defines the block name
  13. */
  14. public constructor(name: string) {
  15. super(name, NodeMaterialBlockTargets.Fragment);
  16. this.registerInput("input", NodeMaterialBlockConnectionPointTypes.Vector3OrColor3);
  17. this.registerOutput("r", NodeMaterialBlockConnectionPointTypes.Float);
  18. this.registerOutput("g", NodeMaterialBlockConnectionPointTypes.Float);
  19. this.registerOutput("b", NodeMaterialBlockConnectionPointTypes.Float);
  20. }
  21. /**
  22. * Gets the current class name
  23. * @returns the class name
  24. */
  25. public getClassName() {
  26. return "RGBSplitterBlock";
  27. }
  28. /**
  29. * Gets the input component
  30. */
  31. public get input(): NodeMaterialConnectionPoint {
  32. return this._inputs[0];
  33. }
  34. protected _buildBlock(state: NodeMaterialBuildState) {
  35. super._buildBlock(state);
  36. let input = this.input;
  37. let rOutput = this._outputs[0];
  38. let gOutput = this._outputs[1];
  39. let bOutput = this._outputs[2];
  40. if (rOutput.connectedBlocks.length > 0) {
  41. state.compilationString += this._declareOutput(rOutput, state) + ` = ${input.associatedVariableName}.r;\r\n`;
  42. }
  43. if (gOutput.connectedBlocks.length > 0) {
  44. state.compilationString += this._declareOutput(gOutput, state) + ` = ${input.associatedVariableName}.g;\r\n`;
  45. }
  46. if (bOutput.connectedBlocks.length > 0) {
  47. state.compilationString += this._declareOutput(bOutput, state) + ` = ${input.associatedVariableName}.b;\r\n`;
  48. }
  49. return this;
  50. }
  51. }