@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
47 lines (46 loc) • 1.69 kB
JavaScript
;
import { TypedJsNode } from "./_Base";
import { JsConnectionPointType } from "../utils/io/connections/Js";
import { NodeParamsConfig } from "../utils/params/ParamsConfig";
import { rangeWithEnd, arrayCompact } from "../../../core/ArrayUtils";
export class BaseJsMathFunctionParamsConfig extends NodeParamsConfig {
}
const ParamsConfig = new BaseJsMathFunctionParamsConfig();
export class BaseMathFunctionJsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
initializeNode() {
super.initializeNode();
this.io.connection_points.set_expected_input_types_function(this._expectedInputTypes.bind(this));
this.io.connection_points.set_expected_output_types_function(this._expectedOutputTypes.bind(this));
this.io.connection_points.set_input_name_function(this._expectedInputName.bind(this));
}
_expectedInputTypes() {
const type = this.io.connection_points.first_input_connection_type() || JsConnectionPointType.FLOAT;
if (this.io.connections.firstInputConnection()) {
const connections = this.io.connections.inputConnections();
if (connections) {
const compactConnections = [];
arrayCompact(connections, compactConnections);
let count = Math.max(compactConnections.length + 1, 2);
return rangeWithEnd(count).map((i) => type);
} else {
return [];
}
} else {
return rangeWithEnd(2).map((i) => type);
}
}
_expectedOutputTypes() {
const type = this._expectedInputTypes()[0];
return [type];
}
_expectedInputName(index) {
return "in";
}
_expectedOutputName(index) {
return "val";
}
}