cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
104 lines (103 loc) • 2.73 kB
JavaScript
import Base from "../core/Base.mjs";
import CompositorNode from "./CompositorNode.mjs";
var Graph = Base.extend(
function() {
return {
nodes: []
};
},
{
dirty: function() {
this._dirty = true;
},
addNode: function(node) {
if (this.nodes.indexOf(node) >= 0) {
return;
}
this.nodes.push(node);
this._dirty = true;
},
removeNode: function(node) {
if (typeof node === "string") {
node = this.getNodeByName(node);
}
var idx = this.nodes.indexOf(node);
if (idx >= 0) {
this.nodes.splice(idx, 1);
this._dirty = true;
}
},
getNodeByName: function(name) {
for (var i = 0; i < this.nodes.length; i++) {
if (this.nodes[i].name === name) {
return this.nodes[i];
}
}
},
update: function() {
for (var i = 0; i < this.nodes.length; i++) {
this.nodes[i].clear();
}
for (var i = 0; i < this.nodes.length; i++) {
var node = this.nodes[i];
if (!node.inputs) {
continue;
}
for (var inputName in node.inputs) {
if (!node.inputs[inputName]) {
continue;
}
if (node.pass && !node.pass.material.isUniformEnabled(inputName)) {
console.warn("Pin " + node.name + "." + inputName + " not used.");
continue;
}
var fromPinInfo = node.inputs[inputName];
var fromPin = this.findPin(fromPinInfo);
if (fromPin) {
node.link(inputName, fromPin.node, fromPin.pin);
} else {
if (typeof fromPinInfo === "string") {
console.warn("Node " + fromPinInfo + " not exist");
} else {
console.warn("Pin of " + fromPinInfo.node + "." + fromPinInfo.pin + " not exist");
}
}
}
}
},
findPin: function(input) {
var node;
if (typeof input === "string" || input instanceof CompositorNode) {
input = {
node: input
};
}
if (typeof input.node === "string") {
for (var i = 0; i < this.nodes.length; i++) {
var tmp = this.nodes[i];
if (tmp.name === input.node) {
node = tmp;
}
}
} else {
node = input.node;
}
if (node) {
var inputPin = input.pin;
if (!inputPin) {
if (node.outputs) {
inputPin = Object.keys(node.outputs)[0];
}
}
if (node.outputs[inputPin]) {
return {
node,
pin: inputPin
};
}
}
}
}
);
var Graph$1 = Graph;
export { Graph$1 as default };