@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
52 lines (51 loc) • 1.54 kB
JavaScript
;
import { SopType } from "./../../poly/registers/nodes/types/Sop";
import { BaseMethod } from "./_Base";
import { CoreWalker } from "../../../core/Walker";
import { AnimType } from "../../poly/registers/nodes/types/Anim";
function isCopyNode(node) {
return node && node.type() == SopType.COPY && node.type() == AnimType.COPY;
}
export class CopyExpression extends BaseMethod {
static requiredArguments() {
return [
["string", "path to copy"],
["integer", "default value"]
];
}
static optionalArguments() {
return [["string", "attribute name (optional)"]];
}
findDependency(args) {
if (args.indexOrPath == null) {
return null;
}
const node = this.findReferencedGraphNode(args.indexOrPath);
if (isCopyNode(node)) {
const stampNode = node.stampNode();
return this.createDependency(stampNode, { indexOrPath: args.indexOrPath });
}
return null;
}
processArguments(args) {
return new Promise((resolve, reject) => {
if (args.length >= 1) {
const path = args[0];
const defaultValue = args[1] || 0;
const attributeName = args[2];
const currentNode = this.node();
const node = currentNode ? CoreWalker.findNode(currentNode, path) : null;
let value;
if (isCopyNode(node)) {
value = node.stampValue(attributeName);
}
if (value == null) {
value = defaultValue;
}
resolve(value);
} else {
resolve(0);
}
});
}
}