|
@@ -2,7 +2,8 @@ import {
|
|
DiagramEngine,
|
|
DiagramEngine,
|
|
DiagramModel,
|
|
DiagramModel,
|
|
DiagramWidget,
|
|
DiagramWidget,
|
|
- MoveCanvasAction
|
|
|
|
|
|
+ MoveCanvasAction,
|
|
|
|
+ LinkModel
|
|
} from "storm-react-diagrams";
|
|
} from "storm-react-diagrams";
|
|
|
|
|
|
import * as React from "react";
|
|
import * as React from "react";
|
|
@@ -58,10 +59,13 @@ export class GraphEditor extends React.Component<IGraphEditorProps> {
|
|
|
|
|
|
private _nodes = new Array<DefaultNodeModel>();
|
|
private _nodes = new Array<DefaultNodeModel>();
|
|
|
|
|
|
|
|
+ /** @hidden */
|
|
|
|
+ public _toAdd: LinkModel[] | null = [];
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Current row/column position used when adding new nodes
|
|
* Current row/column position used when adding new nodes
|
|
*/
|
|
*/
|
|
- private _rowPos = new Array<number>()
|
|
|
|
|
|
+ private _rowPos = new Array<number>();
|
|
|
|
|
|
/**
|
|
/**
|
|
* Creates a node and recursivly creates its parent nodes from it's input
|
|
* Creates a node and recursivly creates its parent nodes from it's input
|
|
@@ -76,29 +80,29 @@ export class GraphEditor extends React.Component<IGraphEditorProps> {
|
|
}
|
|
}
|
|
|
|
|
|
// Create new node in the graph
|
|
// Create new node in the graph
|
|
- var outputNode: DefaultNodeModel;
|
|
|
|
|
|
+ var newNode: DefaultNodeModel;
|
|
var filterInputs = [];
|
|
var filterInputs = [];
|
|
|
|
|
|
if (options.nodeMaterialBlock) {
|
|
if (options.nodeMaterialBlock) {
|
|
if (options.nodeMaterialBlock instanceof TextureBlock) {
|
|
if (options.nodeMaterialBlock instanceof TextureBlock) {
|
|
- outputNode = new TextureNodeModel();
|
|
|
|
|
|
+ newNode = new TextureNodeModel();
|
|
filterInputs.push("uv");
|
|
filterInputs.push("uv");
|
|
} else {
|
|
} else {
|
|
- outputNode = new GenericNodeModel();
|
|
|
|
|
|
+ newNode = new GenericNodeModel();
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- outputNode = new InputNodeModel();
|
|
|
|
- (outputNode as InputNodeModel).connection = options.connection;
|
|
|
|
|
|
+ newNode = new InputNodeModel();
|
|
|
|
+ (newNode as InputNodeModel).connection = options.connection;
|
|
}
|
|
}
|
|
- this._nodes.push(outputNode)
|
|
|
|
- outputNode.setPosition(1600 - (300 * options.column), 210 * this._rowPos[options.column])
|
|
|
|
- this._model.addAll(outputNode);
|
|
|
|
|
|
+ this._nodes.push(newNode)
|
|
|
|
+ newNode.setPosition(1600 - (300 * options.column), 210 * this._rowPos[options.column])
|
|
|
|
+ this._model.addAll(newNode);
|
|
|
|
|
|
if (options.nodeMaterialBlock) {
|
|
if (options.nodeMaterialBlock) {
|
|
- outputNode.prepare(options, this._nodes, this._model, this, filterInputs);
|
|
|
|
|
|
+ newNode.prepare(options, this._nodes, this._model, this, filterInputs);
|
|
}
|
|
}
|
|
|
|
|
|
- return outputNode;
|
|
|
|
|
|
+ return newNode;
|
|
}
|
|
}
|
|
|
|
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
@@ -126,6 +130,25 @@ export class GraphEditor extends React.Component<IGraphEditorProps> {
|
|
this._engine.registerNodeFactory(new TextureNodeFactory(this.props.globalState));
|
|
this._engine.registerNodeFactory(new TextureNodeFactory(this.props.globalState));
|
|
this._engine.registerNodeFactory(new InputNodeFactory(this.props.globalState));
|
|
this._engine.registerNodeFactory(new InputNodeFactory(this.props.globalState));
|
|
|
|
|
|
|
|
+ this.props.globalState.onRebuildRequiredObservable.add(() => {
|
|
|
|
+ if (this.props.globalState.nodeMaterial) {
|
|
|
|
+ this.props.globalState.nodeMaterial.build(true);
|
|
|
|
+ }
|
|
|
|
+ this.forceUpdate();
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ this.props.globalState.onResetRequiredObservable.add(() => {
|
|
|
|
+ this._rowPos = [];
|
|
|
|
+ this.build();
|
|
|
|
+ if (this.props.globalState.nodeMaterial) {
|
|
|
|
+ this.props.globalState.nodeMaterial.build(true);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ this.build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ build() {
|
|
// setup the diagram model
|
|
// setup the diagram model
|
|
this._model = new DiagramModel();
|
|
this._model = new DiagramModel();
|
|
|
|
|
|
@@ -134,42 +157,33 @@ export class GraphEditor extends React.Component<IGraphEditorProps> {
|
|
linksUpdated: (e) => {
|
|
linksUpdated: (e) => {
|
|
if (!e.isCreated) {
|
|
if (!e.isCreated) {
|
|
// Link is deleted
|
|
// Link is deleted
|
|
- console.log("link deleted");
|
|
|
|
|
|
+ this.props.globalState.onSelectionChangedObservable.notifyObservers(null);
|
|
var link = DefaultPortModel.SortInputOutput(e.link.sourcePort as DefaultPortModel, e.link.targetPort as DefaultPortModel);
|
|
var link = DefaultPortModel.SortInputOutput(e.link.sourcePort as DefaultPortModel, e.link.targetPort as DefaultPortModel);
|
|
console.log(link)
|
|
console.log(link)
|
|
if (link) {
|
|
if (link) {
|
|
if (link.output.connection && link.input.connection) {
|
|
if (link.output.connection && link.input.connection) {
|
|
// Disconnect standard nodes
|
|
// Disconnect standard nodes
|
|
- console.log("disconnected " + link.output.connection.name + " from " + link.input.connection.name)
|
|
|
|
link.output.connection.disconnectFrom(link.input.connection)
|
|
link.output.connection.disconnectFrom(link.input.connection)
|
|
link.input.syncWithNodeMaterialConnectionPoint(link.input.connection)
|
|
link.input.syncWithNodeMaterialConnectionPoint(link.input.connection)
|
|
link.output.syncWithNodeMaterialConnectionPoint(link.output.connection)
|
|
link.output.syncWithNodeMaterialConnectionPoint(link.output.connection)
|
|
} else if (link.input.connection && link.input.connection.value) {
|
|
} else if (link.input.connection && link.input.connection.value) {
|
|
- console.log("value link removed");
|
|
|
|
link.input.connection.value = null;
|
|
link.input.connection.value = null;
|
|
- } else {
|
|
|
|
- console.log("invalid link error");
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- console.log("link created")
|
|
|
|
- console.log(e.link.sourcePort)
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
e.link.addListener({
|
|
e.link.addListener({
|
|
sourcePortChanged: () => {
|
|
sourcePortChanged: () => {
|
|
console.log("port change")
|
|
console.log("port change")
|
|
},
|
|
},
|
|
targetPortChanged: () => {
|
|
targetPortChanged: () => {
|
|
// Link is created with a target port
|
|
// Link is created with a target port
|
|
- console.log("Link set to target")
|
|
|
|
var link = DefaultPortModel.SortInputOutput(e.link.sourcePort as DefaultPortModel, e.link.targetPort as DefaultPortModel);
|
|
var link = DefaultPortModel.SortInputOutput(e.link.sourcePort as DefaultPortModel, e.link.targetPort as DefaultPortModel);
|
|
|
|
|
|
if (link) {
|
|
if (link) {
|
|
if (link.output.connection && link.input.connection) {
|
|
if (link.output.connection && link.input.connection) {
|
|
- console.log("link standard blocks")
|
|
|
|
link.output.connection.connectTo(link.input.connection)
|
|
link.output.connection.connectTo(link.input.connection)
|
|
} else if (link.input.connection) {
|
|
} else if (link.input.connection) {
|
|
- console.log("link value to standard block")
|
|
|
|
link.input.connection.value = link.output.getValue();
|
|
link.input.connection.value = link.output.getValue();
|
|
|
|
|
|
}
|
|
}
|
|
@@ -178,22 +192,7 @@ export class GraphEditor extends React.Component<IGraphEditorProps> {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
})
|
|
})
|
|
-
|
|
|
|
- },
|
|
|
|
- nodesUpdated: (e) => {
|
|
|
|
- if (e.isCreated) {
|
|
|
|
- console.log("new node")
|
|
|
|
- } else {
|
|
|
|
- console.log("node deleted")
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- this.props.globalState.onRebuildRequiredObservable.add(() => {
|
|
|
|
- if (this.props.globalState.nodeMaterial) {
|
|
|
|
- this.props.globalState.nodeMaterial.build();
|
|
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
@@ -212,11 +211,18 @@ export class GraphEditor extends React.Component<IGraphEditorProps> {
|
|
this._model.setZoomLevel(80)
|
|
this._model.setZoomLevel(80)
|
|
|
|
|
|
// load model into engine
|
|
// load model into engine
|
|
- this._engine.setDiagramModel(this._model);
|
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ if (this._toAdd) {
|
|
|
|
+ this._model.addAll(...this._toAdd);
|
|
|
|
+ }
|
|
|
|
+ this._toAdd = null;
|
|
|
|
+ this._engine.setDiagramModel(this._model);
|
|
|
|
+ this.forceUpdate();
|
|
|
|
+ }, 15);
|
|
}
|
|
}
|
|
|
|
|
|
addNodeFromClass(ObjectClass: typeof NodeMaterialBlock) {
|
|
addNodeFromClass(ObjectClass: typeof NodeMaterialBlock) {
|
|
- var block = new ObjectClass(ObjectClass.prototype.getClassName() + "sdfsdf")
|
|
|
|
|
|
+ var block = new ObjectClass(ObjectClass.prototype.getClassName())
|
|
var localNode = this.createNodeFromObject({ column: 0, nodeMaterialBlock: block })
|
|
var localNode = this.createNodeFromObject({ column: 0, nodeMaterialBlock: block })
|
|
var widget = (this.refs["test"] as DiagramWidget);
|
|
var widget = (this.refs["test"] as DiagramWidget);
|
|
|
|
|