| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import { NodeMaterialBlock } from '../../nodeMaterialBlock';
- import { NodeMaterialBlockConnectionPointTypes } from '../../nodeMaterialBlockConnectionPointTypes';
- import { NodeMaterialBuildState } from '../../nodeMaterialBuildState';
- import { NodeMaterialBlockTargets } from '../../nodeMaterialBlockTargets';
- import { NodeMaterialConnectionPoint } from '../../nodeMaterialBlockConnectionPoint';
- /**
- * Block used to expand a Color3 or a Vector3 into 3 outputs (one for each component)
- */
- export class RGBSplitterBlock extends NodeMaterialBlock {
- /**
- * Create a new RGBSplitterBlock
- * @param name defines the block name
- */
- public constructor(name: string) {
- super(name, NodeMaterialBlockTargets.Fragment);
- this.registerInput("input", NodeMaterialBlockConnectionPointTypes.Vector3OrColor3);
- this.registerOutput("r", NodeMaterialBlockConnectionPointTypes.Float);
- this.registerOutput("g", NodeMaterialBlockConnectionPointTypes.Float);
- this.registerOutput("b", NodeMaterialBlockConnectionPointTypes.Float);
- }
- /**
- * Gets the current class name
- * @returns the class name
- */
- public getClassName() {
- return "RGBSplitterBlock";
- }
- /**
- * Gets the input component
- */
- public get input(): NodeMaterialConnectionPoint {
- return this._inputs[0];
- }
- protected _buildBlock(state: NodeMaterialBuildState) {
- super._buildBlock(state);
- let input = this.input;
- let rOutput = this._outputs[0];
- let gOutput = this._outputs[1];
- let bOutput = this._outputs[2];
- if (rOutput.connectedBlocks.length > 0) {
- state.compilationString += this._declareOutput(rOutput, state) + ` = ${input.associatedVariableName}.r;\r\n`;
- }
- if (gOutput.connectedBlocks.length > 0) {
- state.compilationString += this._declareOutput(gOutput, state) + ` = ${input.associatedVariableName}.g;\r\n`;
- }
- if (bOutput.connectedBlocks.length > 0) {
- state.compilationString += this._declareOutput(bOutput, state) + ` = ${input.associatedVariableName}.b;\r\n`;
- }
- return this;
- }
- }
|