genericPortModel.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { LinkModel, PortModel, DefaultLinkModel } from "storm-react-diagrams";
  2. import { Nullable } from 'babylonjs/types';
  3. import { NodeMaterialConnectionPoint } from 'babylonjs/Materials/Node/nodeMaterialBlockConnectionPoint';
  4. import { GenericNodeModel } from './genericNodeModel';
  5. /**
  6. * Port model for the generic node
  7. */
  8. export class GenericPortModel extends PortModel {
  9. /**
  10. * If the port is input or output
  11. */
  12. public position: string | "input" | "output";
  13. /**
  14. * What the port is connected to
  15. */
  16. public connection: Nullable<NodeMaterialConnectionPoint> = null;
  17. static idCounter = 0;
  18. constructor(name:string, type: string = "input") {
  19. super(name, "generic");
  20. this.position = type;
  21. GenericPortModel.idCounter++;
  22. }
  23. syncWithNodeMaterialConnectionPoint(connection:NodeMaterialConnectionPoint){
  24. this.connection = connection;
  25. this.name = connection.name;
  26. }
  27. getNodeModel(){
  28. return this.parent as GenericNodeModel
  29. }
  30. link(outPort:GenericPortModel){
  31. var link = this.createLinkModel()
  32. link.setSourcePort(this)
  33. link.setTargetPort(outPort)
  34. return link;
  35. }
  36. getInputFromBlock(){
  37. }
  38. createLinkModel(): LinkModel {
  39. return new DefaultLinkModel();
  40. }
  41. getValue:Function = ()=>{
  42. return null;
  43. }
  44. static SortInputOutput(a:Nullable<GenericPortModel>, b:Nullable<GenericPortModel>){
  45. if(!a || !b){
  46. return null;
  47. }else if(a.position == "output" && b.position == "input"){
  48. return {
  49. input: b,
  50. output: a
  51. }
  52. }else if(b.position == "output" && a.position == "input"){
  53. return {
  54. input: a,
  55. output: b
  56. }
  57. }else{
  58. return null;
  59. }
  60. }
  61. }