UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

27 lines (26 loc) 726 B
"use strict"; import { BaseMethod } from "./_Base"; export class JsExpression extends BaseMethod { static requiredArguments() { return [["string", "javascript expression"]]; } async processArguments(args) { let val = 0; if (args.length == 1) { const arg = args[0]; this._function = this._function || this._create_function(arg); if (this._function) { try { val = this._function(this.param.scene(), this.param.node, this.param); } catch (e) { console.warn(`expression error`); console.warn(e); } } } return val; } _create_function(content) { return new Function("scene", "node", "param", `return ${content}`); } }