@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
83 lines (82 loc) • 3.08 kB
JavaScript
;
import { TypedJsNode } from "./_Base";
import {
PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES,
JsConnectionPointType,
JsConnectionPointInitValueMap,
JsConnectionPointTypeToParamTypeMap
} from "../utils/io/connections/Js";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { ParamConfigsController } from "../utils/code/controllers/ParamConfigsController";
import { JsParamConfig } from "./code/utils/JsParamConfig";
import { Poly } from "../../Poly";
class ParamJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.name = ParamConfig.STRING("");
this.type = ParamConfig.INTEGER(PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES.indexOf(JsConnectionPointType.FLOAT), {
menu: {
entries: PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES.map((name, i) => {
return { name, value: i };
})
}
});
}
}
const ParamsConfig = new ParamJsParamsConfig();
const _ParamJsNode = class extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "param";
}
initializeNode() {
this.addPostDirtyHook("_setFunctionNodeToRecompile", this._setFunctionNodeToRecompile.bind(this));
this.io.connection_points.initializeNode();
this.io.connection_points.set_output_name_function((index) => _ParamJsNode.OUTPUT_NAME);
this.io.connection_points.set_expected_input_types_function(() => []);
this.io.connection_points.set_expected_output_types_function(() => [
PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES[this.pv.type]
]);
}
setLines(shadersCollectionController) {
const out = this.jsVarName(_ParamJsNode.OUTPUT_NAME);
const _func = Poly.namedFunctionsRegister.getFunction(
"getActorNodeParamValue",
this,
shadersCollectionController
);
shadersCollectionController.addBodyOrComputed(this, [
{
dataType: PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES[this.pv.type],
varName: out,
value: _func.asString(`'${this.pv.name}'`)
}
]);
}
setParamConfigs() {
const type = PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES[this.pv.type];
const defaultValue = JsConnectionPointInitValueMap[type];
const paramType = JsConnectionPointTypeToParamTypeMap[type];
this._param_configs_controller = this._param_configs_controller || new ParamConfigsController();
this._param_configs_controller.reset();
const param_config = new JsParamConfig(paramType, this.pv.name, defaultValue, this.uniformName());
this._param_configs_controller.push(param_config);
}
uniformName() {
return this.jsVarName(_ParamJsNode.OUTPUT_NAME);
}
setJsType(type) {
const index = PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES.indexOf(type);
this.p.type.set(index);
}
paramsGenerating() {
return true;
}
};
export let ParamJsNode = _ParamJsNode;
// protected _allow_inputs_created_from_params: boolean = false;
// static readonly UNIFORM_NAME = 'paramVal';
ParamJsNode.OUTPUT_NAME = "val";