浏览代码

Allow creating a custom input block when not connecting an input to an output block

Popov72 5 年之前
父节点
当前提交
5d3bb90752
共有 2 个文件被更改,包括 17 次插入2 次删除
  1. 8 2
      nodeEditor/src/diagram/graphCanvas.tsx
  2. 9 0
      src/Materials/Node/nodeMaterialBlockConnectionPoint.ts

+ 8 - 2
nodeEditor/src/diagram/graphCanvas.tsx

@@ -735,9 +735,15 @@ export class GraphCanvasComponent extends React.Component<IGraphCanvasComponentP
             }
 
             // No destination so let's spin a new input block
-            let inputBlock = new InputBlock(NodeMaterialBlockConnectionPointTypes[this._candidateLink!.portA.connectionPoint.type], undefined, this._candidateLink!.portA.connectionPoint.type);
+            let pointName = "output", inputBlock;
+            let customInputBlock = this._candidateLink!.portA.connectionPoint.createCustomInputBlock();
+            if (!customInputBlock) {
+                inputBlock = new InputBlock(NodeMaterialBlockConnectionPointTypes[this._candidateLink!.portA.connectionPoint.type], undefined, this._candidateLink!.portA.connectionPoint.type);
+            } else {
+                [inputBlock, pointName] = customInputBlock;
+            }
             this.props.globalState.nodeMaterial.attachedBlocks.push(inputBlock);
-            pointA = inputBlock.output;
+            pointA = inputBlock[pointName];
             nodeA = this.appendBlock(inputBlock);
             
             nodeA.x = this._dropPointX - 200;

+ 9 - 0
src/Materials/Node/nodeMaterialBlockConnectionPoint.ts

@@ -287,6 +287,15 @@ export class NodeMaterialConnectionPoint {
     }
 
     /**
+     * Creates a block suitable to be used as an input for this input point.
+     * If null is returned, a block based on the point type will be created.
+     * @returns The returned string parameter is the name of the output point of NodeMaterialBlock (first parameter of the returned array) that can be connected to the input
+     */
+    public createCustomInputBlock(): Nullable<[NodeMaterialBlock, string]> {
+        return null;
+    }
+
+    /**
      * Creates a new connection point
      * @param name defines the connection point name
      * @param ownerBlock defines the block hosting this connection point