@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
27 lines (26 loc) • 917 B
JavaScript
;
import * as THREE from "three";
export class BaseCodeProcessor {
constructor(node) {
this.node = node;
}
}
export function buildCodeNodeFunction(options) {
const { BaseCodeProcessor: BaseCodeProcessor2, BaseCodeProcessorName, node, functionBody, otherVariables } = options;
const availableVariables = {
[BaseCodeProcessorName]: BaseCodeProcessor2,
...THREE,
states: node.states
};
const variableNames = Object.keys(availableVariables).concat(Object.keys(otherVariables || {}));
const sortedVariables = variableNames.map((varName) => {
let varValue = availableVariables[varName];
if (varValue == null) {
varValue = (otherVariables || {})[varName];
}
return varValue;
});
const processorCreatorFunction = new Function(...variableNames, functionBody);
const ProcessorClass = processorCreatorFunction(...sortedVariables);
return ProcessorClass;
}