defaultNodeModel.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { NodeModel, DiagramModel } from "storm-react-diagrams";
  2. import { Nullable } from 'babylonjs/types';
  3. import { NodeMaterialBlock } from 'babylonjs/Materials/Node/nodeMaterialBlock';
  4. import { GraphEditor, NodeCreationOptions } from '../../graphEditor';
  5. import { GlobalState } from '../../globalState';
  6. import { DefaultPortModel } from './port/defaultPortModel';
  7. /**
  8. * Generic node model which stores information about a node editor block
  9. */
  10. export class DefaultNodeModel extends NodeModel {
  11. /**
  12. * The babylon block this node represents
  13. */
  14. public block: Nullable<NodeMaterialBlock> = null;
  15. public ports: { [s: string]: DefaultPortModel };
  16. /**
  17. * Constructs the node model
  18. */
  19. constructor(key: string) {
  20. super(key);
  21. }
  22. prepare(options: NodeCreationOptions, nodes: Array<DefaultNodeModel>, model: DiagramModel, graphEditor: GraphEditor) {
  23. this.block = options.nodeMaterialBlock || null;
  24. if (!options.nodeMaterialBlock) {
  25. return;
  26. }
  27. // Create output ports
  28. options.nodeMaterialBlock._outputs.forEach((connection: any) => {
  29. var outputPort = new DefaultPortModel(connection.name, "output");
  30. outputPort.syncWithNodeMaterialConnectionPoint(connection);
  31. this.addPort(outputPort)
  32. })
  33. // Create input ports and nodes if they exist
  34. options.nodeMaterialBlock._inputs.forEach((connection) => {
  35. var inputPort = new DefaultPortModel(connection.name, "input");
  36. inputPort.connection = connection;
  37. this.addPort(inputPort)
  38. if (connection.connectedPoint) {
  39. // Block is not a leaf node, create node for the given block type
  40. // var connectedNode;
  41. // var existingNodes = nodes.filter((n) => { return n.block === (connection as any)._connectedPoint._ownerBlock });
  42. // if (existingNodes.length == 0) {
  43. // connectedNode = graphEditor.createNodeFromObject({ nodeMaterialBlock: connection.connectedPoint._ownerBlock });
  44. // } else {
  45. // connectedNode = existingNodes[0];
  46. // }
  47. // let link = connectedNode.ports[connection.connectedPoint.name].link(inputPort);
  48. // if (graphEditor._toAdd) {
  49. // graphEditor._toAdd.push(link);
  50. // } else {
  51. // model.addAll(link);
  52. // }
  53. }
  54. });
  55. }
  56. renderProperties(globalState: GlobalState): JSX.Element | null {
  57. return null;
  58. }
  59. }