Bladeren bron

NME: Import frame (#8651)

* Propagate the type of a connected input to the output(s) / other connected blocks

* Restore connections when importing a frame

* Make sure we don't loose data in the locations array when merging
Popov72 5 jaren geleden
bovenliggende
commit
80d58b405f
2 gewijzigde bestanden met toevoegingen van 53 en 12 verwijderingen
  1. 39 1
      nodeEditor/src/diagram/graphCanvas.tsx
  2. 14 11
      src/Materials/Node/nodeMaterial.ts

+ 39 - 1
nodeEditor/src/diagram/graphCanvas.tsx

@@ -836,7 +836,45 @@ export class GraphCanvasComponent extends React.Component<IGraphCanvasComponentP
         pointA.connectTo(pointB);
         this.connectPorts(pointA, pointB);
 
-        nodeB.refresh();
+        if (pointB.innerType === NodeMaterialBlockConnectionPointTypes.AutoDetect) {
+            // need to potentially propagate the type of pointA to other ports of blocks connected to owner of pointB
+
+            const refreshNode = (node: GraphNode) => {
+                node.refresh();
+
+                const links = node.links;
+
+                // refresh first the nodes so that the right types are assigned to the auto-detect ports
+                links.forEach((link) => {
+                    const nodeA = link.nodeA, nodeB = link.nodeB;
+
+                    if (!visitedNodes.has(nodeA)) {
+                        visitedNodes.add(nodeA);
+                        refreshNode(nodeA);
+                    }
+
+                    if (nodeB && !visitedNodes.has(nodeB)) {
+                        visitedNodes.add(nodeB);
+                        refreshNode(nodeB);
+                    }
+                });
+
+                // then refresh the links to display the right color between ports
+                links.forEach((link) => {
+                    if (!visitedLinks.has(link)) {
+                        visitedLinks.add(link);
+                        link.update();
+                    }
+                });
+            };
+
+            const visitedNodes = new Set<GraphNode>([nodeA]);
+            const visitedLinks = new Set<NodeLink>([nodeB.links[nodeB.links.length - 1]]);
+
+            refreshNode(nodeB);
+        } else {
+            nodeB.refresh();
+        }
 
         this.props.globalState.onRebuildRequiredObservable.notifyObservers();
     }

+ 14 - 11
src/Materials/Node/nodeMaterial.ts

@@ -1627,20 +1627,19 @@ export class NodeMaterial extends PushMaterial {
             }
         }
 
-        // Connections
-        if (!merge) {
-            // Starts with input blocks only
-            for (var blockIndex = 0; blockIndex < source.blocks.length; blockIndex++) {
-                let parsedBlock = source.blocks[blockIndex];
-                let block = map[parsedBlock.id];
+        // Connections - Starts with input blocks only (except if in "merge" mode where we scan all blocks)
+        for (var blockIndex = 0; blockIndex < source.blocks.length; blockIndex++) {
+            let parsedBlock = source.blocks[blockIndex];
+            let block = map[parsedBlock.id];
 
-                if (block.inputs.length) {
-                    continue;
-                }
-                this._restoreConnections(block, source, map);
+            if (block.inputs.length && !merge) {
+                continue;
             }
+            this._restoreConnections(block, source, map);
+        }
 
-            // Outputs
+        // Outputs
+        if (source.outputNodes) {
             for (var outputNodeId of source.outputNodes) {
                 this.addOutputNode(map[outputNodeId]);
             }
@@ -1660,6 +1659,10 @@ export class NodeMaterial extends PushMaterial {
                 }
             }
 
+            if (merge && this.editorData && this.editorData.locations) {
+                locations.concat(this.editorData.locations);
+            }
+
             if (source.locations) {
                 this.editorData = {
                     locations: locations