@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
57 lines (56 loc) • 2.06 kB
JavaScript
"use strict";
import {
JsConnectionPointType,
ARRAY_JS_CONNECTION_TYPES_SET
} from "../utils/io/connections/Js";
import { TypedJsNode } from "./_Base";
import { NodeParamsConfig } from "../utils/params/ParamsConfig";
import { Poly } from "../../Poly";
const ALLOWED_INPUT_TYPES = ARRAY_JS_CONNECTION_TYPES_SET;
class ArrayLengthJsParamsConfig extends NodeParamsConfig {
}
const ParamsConfig = new ArrayLengthJsParamsConfig();
export class ArrayLengthJsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "arrayLength";
}
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));
this.io.connection_points.set_output_name_function(this._expectedOutputName.bind(this));
}
_expectedInputTypes() {
const firstType = this.io.connection_points.first_input_connection_type();
const type = firstType != null && ALLOWED_INPUT_TYPES.has(firstType) ? firstType : JsConnectionPointType.FLOAT_ARRAY;
return [type];
}
_expectedInputName(index) {
const type = this._expectedInputTypes()[0];
return `${type}`;
}
_expectedOutputName(index) {
return `length`;
}
_expectedOutputTypes() {
return [JsConnectionPointType.INT];
}
setLines(shadersCollectionController) {
const array = this.variableForInput(shadersCollectionController, this._expectedInputName(0));
const dataType = this._expectedInputTypes()[0];
const varName = this.jsVarName(this._expectedOutputName(0));
const func = Poly.namedFunctionsRegister.getFunction("arrayLength", this, shadersCollectionController);
shadersCollectionController.addBodyOrComputed(this, [
{
dataType,
varName,
value: func.asString(array)
}
]);
}
}