import * as React from "react"; import { DefaultNodeModel } from './defaultNodeModel'; import { DefaultPortModel } from './port/defaultPortModel'; import { Nullable } from 'babylonjs/types'; import { NodeMaterialConnectionPoint } from 'babylonjs/Materials/Node/nodeMaterialBlockConnectionPoint'; import { NodeMaterialBlockConnectionPointTypes } from 'babylonjs/Materials/Node/nodeMaterialBlockConnectionPointTypes'; import { DefaultPortWidget } from './port/defaultPortWidget'; import { BlockTools } from '../../blockTools'; export class PortHelper { private static _GetPortTypeIndicator(connection: NodeMaterialConnectionPoint): Nullable { switch (connection.type) { case NodeMaterialBlockConnectionPointTypes.Float: case NodeMaterialBlockConnectionPointTypes.Int: return ; case NodeMaterialBlockConnectionPointTypes.Vector2: return ; case NodeMaterialBlockConnectionPointTypes.Vector3: case NodeMaterialBlockConnectionPointTypes.Color3: return ; case NodeMaterialBlockConnectionPointTypes.Vector4: case NodeMaterialBlockConnectionPointTypes.Color4: return ; case NodeMaterialBlockConnectionPointTypes.Matrix: return ; } return null; } static _GetPortStyle(type: NodeMaterialBlockConnectionPointTypes) { return { background: BlockTools.GetColorFromConnectionNodeType(type) }; } public static GenerateOutputPorts(node: Nullable, ignoreLabel: boolean) { if (!node) { return new Array(); } let outputPorts = []; for (var key in node.ports) { let port = node.ports[key] as DefaultPortModel; if (port.position === "output") { let typeIndicator = this._GetPortTypeIndicator(port.connection!); let style = this._GetPortStyle(port.connection!.type); let isConnected = port.connection && port.connection.endpoints.length > 0; outputPorts.push(
{ !ignoreLabel &&
{port.name}
}
{ !isConnected &&
}
{ typeIndicator }
); } } return outputPorts; } public static GenerateInputPorts(node: Nullable, includeOnly?: string[]) { if (!node) { return new Array(); } let inputPorts = []; for (var key in node.ports) { let port = node.ports[key] as DefaultPortModel; if (port.position === "input") { let typeIndicator = this._GetPortTypeIndicator(port.connection!); let style = this._GetPortStyle(port.connection!.type); let isConnected = port.connection && port.connection.endpoints.length > 0; if (!includeOnly || includeOnly.indexOf(port.name) !== -1) { inputPorts.push(
{ !isConnected &&
}
{ typeIndicator }
{port.name}
); } } } return inputPorts; } }