Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix node decomposing at drop time #12698

Merged
merged 2 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class FrameNodePort extends NodePort {
framePortId: number,
parentFrameId: number
) {
super(portContainer, portData.data, node, stateManager);
super(portContainer, portData, node, stateManager);

this._parentFrameId = parentFrameId;
this._isInput = isInput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,13 @@ export class GraphCanvasComponent extends React.Component<IGraphCanvasComponentP
return this.nodes.filter((n) => n.content.data === nodeData.data)[0];
}

this._nodeDataContentList.push(nodeData.data);

onNodeCreated(nodeData.data);

// Connections
if (nodeData.inputs.length) {
for (const input of nodeData.inputs) {
if (input.connectedPort && recursion) {
this.createNodeFromObject(TypeLedger.NodeDataBuilder(input.connectedPort, this), onNodeCreated);
this.createNodeFromObject(TypeLedger.NodeDataBuilder(input.connectedPort.ownerData, this), onNodeCreated);
}
}
}
Expand Down Expand Up @@ -440,12 +438,13 @@ export class GraphCanvasComponent extends React.Component<IGraphCanvasComponentP
link.dispose();
}

appendNode(data: INodeData) {
const newNode = new GraphNode(data, this.props.stateManager);
appendNode(nodeData: INodeData) {
const newNode = new GraphNode(nodeData, this.props.stateManager);

newNode.appendVisual(this._graphCanvas, this);

this._nodes.push(newNode);
this._nodeDataContentList.push(nodeData.data);

return newNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,13 @@ export class GraphFrame {
for (let i = 0; i < this._exposedOutPorts.length; ) {
// Output
const port = this._exposedOutPorts[i];
if (port.node === null || port.node.enclosingFrameId != this.id) {
if (this._removePortFromExposedWithNode(port, this._exposedOutPorts)) continue;
} else {
if (!this._createOutputPorts(port, port.node) && this._removePortFromExposedWithNode(port, this._exposedOutPorts)) {
continue;
if (port) {
if (port.node === null || port.node.enclosingFrameId != this.id) {
if (this._removePortFromExposedWithNode(port, this._exposedOutPorts)) continue;
} else {
if (!this._createOutputPorts(port, port.node) && this._removePortFromExposedWithNode(port, this._exposedOutPorts)) {
continue;
}
}
}
++i;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { GraphNode } from "../graphNode";
import type { INodeData } from "./nodeData";

export interface INodeContainer {
nodes: GraphNode[];
appendNode(data: INodeData): GraphNode;
}
16 changes: 10 additions & 6 deletions packages/tools/nodeEditor/src/graphSystem/blockNodeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,16 @@ export class BlockNodeData implements INodeData {
}

public constructor(public data: NodeMaterialBlock, nodeContainer: INodeContainer) {
this.data.inputs.forEach((input) => {
this._inputs.push(new ConnectionPointPortData(input, nodeContainer));
});
if (data.inputs) {
this.data.inputs.forEach((input) => {
this._inputs.push(new ConnectionPointPortData(input, nodeContainer));
});
}

this.data.outputs.forEach((output) => {
this._outputs.push(new ConnectionPointPortData(output, nodeContainer));
});
if (data.outputs) {
this.data.outputs.forEach((output) => {
this._outputs.push(new ConnectionPointPortData(output, nodeContainer));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { GraphNode } from "shared-ui-components/nodeGraphSystem/graphNode";
import type { INodeContainer } from "shared-ui-components/nodeGraphSystem/interfaces/nodeContainer";
import type { IPortData } from "shared-ui-components/nodeGraphSystem/interfaces/portData";
import { PortDataDirection } from "shared-ui-components/nodeGraphSystem/interfaces/portData";
import { TypeLedger } from "shared-ui-components/nodeGraphSystem/typeLedger";

export class ConnectionPointPortData implements IPortData {
private _connectedPort: Nullable<IPortData> = null;
Expand Down Expand Up @@ -53,11 +54,13 @@ export class ConnectionPointPortData implements IPortData {
}
if (!this._connectedPort) {
const otherBlock = this.data.connectedPoint!.ownerBlock;
const otherNode = this._nodeContainer.nodes.find((n) => n.content.data === otherBlock);
let otherNode = this._nodeContainer.nodes.find((n) => n.content.data === otherBlock);

if (otherNode) {
this._connectedPort = otherNode.getPortDataForPortDataContent(this.data.connectedPoint!);
if (!otherNode) {
otherNode = this._nodeContainer.appendNode(TypeLedger.NodeDataBuilder(otherBlock, this._nodeContainer));
}

this._connectedPort = otherNode.getPortDataForPortDataContent(this.data.connectedPoint!);
}

return this._connectedPort;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { NodeMaterialConnectionPoint } from "core/Materials/Node/nodeMaterialBlockConnectionPoint";
import type { INodeContainer } from "shared-ui-components/nodeGraphSystem/interfaces/nodeContainer";
import { TypeLedger } from "shared-ui-components/nodeGraphSystem/typeLedger";
import { BlockNodeData } from "./blockNodeData";
import { ConnectionPointPortData } from "./connectionPointPortData";
Expand All @@ -9,7 +8,7 @@ export const RegisterTypeLedger = () => {
return new ConnectionPointPortData(data.portData.data as NodeMaterialConnectionPoint, nodeContainer);
};

TypeLedger.NodeDataBuilder = (data, nodeContainer: INodeContainer) => {
TypeLedger.NodeDataBuilder = (data, nodeContainer) => {
return new BlockNodeData(data, nodeContainer);
};
};