@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
108 lines (107 loc) • 4.33 kB
JavaScript
;
import { TRIGGER_CONNECTION_NAME, TypedJsNode } from "./_Base";
import {
JsConnectionPoint,
JsConnectionPointType,
JS_CONNECTION_POINT_IN_NODE_DEF,
PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES
} from "../utils/io/connections/Js";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { inputObject3D, setObject3DOutputLine } from "./_BaseObject3D";
import { Poly } from "../../Poly";
import { JsType } from "../../poly/registers/nodes/types/Js";
export var SetObjectAttributeInputName = /* @__PURE__ */ ((SetObjectAttributeInputName2) => {
SetObjectAttributeInputName2["attribName"] = "attribName";
SetObjectAttributeInputName2["lerp"] = "lerp";
SetObjectAttributeInputName2["val"] = "val";
return SetObjectAttributeInputName2;
})(SetObjectAttributeInputName || {});
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
class SetObjectAttributeJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param attribute type */
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 SetObjectAttributeJsParamsConfig();
export class SetObjectAttributeJsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
this._nextAttribName = "";
}
static type() {
return JsType.SET_OBJECT_ATTRIBUTE;
}
initializeNode() {
this.io.inputs.setNamedInputConnectionPoints([
new JsConnectionPoint(TRIGGER_CONNECTION_NAME, JsConnectionPointType.TRIGGER, CONNECTION_OPTIONS),
new JsConnectionPoint(JsConnectionPointType.OBJECT_3D, JsConnectionPointType.OBJECT_3D, CONNECTION_OPTIONS),
new JsConnectionPoint(
"attribName" /* attribName */,
JsConnectionPointType.STRING,
CONNECTION_OPTIONS
),
new JsConnectionPoint("lerp", JsConnectionPointType.FLOAT, {
...CONNECTION_OPTIONS,
init_value: 1
})
]);
this.io.connection_points.set_input_name_function(() => "val" /* val */);
this.io.connection_points.set_expected_input_types_function(() => [this._currentConnectionType()]);
this.io.connection_points.set_output_name_function(
(i) => [TRIGGER_CONNECTION_NAME, JsConnectionPointType.OBJECT_3D][i]
);
this.io.connection_points.set_expected_output_types_function(() => [
JsConnectionPointType.TRIGGER,
JsConnectionPointType.OBJECT_3D
]);
}
_currentConnectionType() {
if (this.pv.type == null) {
console.warn(`${this.type()} js node type not valid`);
}
const connectionType = PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES[this.pv.type];
if (connectionType == null) {
console.warn(`${this.type()} js node type not valid`);
}
return connectionType || JsConnectionPointType.FLOAT;
}
paramDefaultValue(name) {
return {
["attribName" /* attribName */]: this._nextAttribName,
["lerp" /* lerp */]: 1,
["val" /* val */]: 0
}[name];
}
setAttribType(type) {
this.p.type.set(PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES.indexOf(type));
}
setAttribName(attribName) {
const param = this.params.get("attribName" /* attribName */);
if (param) {
param.set(attribName);
} else {
this._nextAttribName = attribName;
}
}
setLines(linesController) {
setObject3DOutputLine(this, linesController);
}
setTriggerableLines(shadersCollectionController) {
const object3D = inputObject3D(this, shadersCollectionController);
const attribName = this.variableForInput(shadersCollectionController, "attribName" /* attribName */);
const lerp = this.variableForInput(shadersCollectionController, "lerp" /* lerp */);
const newValue = this.variableForInput(shadersCollectionController, "val" /* val */);
const func = Poly.namedFunctionsRegister.getFunction("setObjectAttribute", this, shadersCollectionController);
const bodyLine = func.asString(object3D, attribName, lerp, newValue, `'${this._currentConnectionType()}'`);
shadersCollectionController.addTriggerableLines(this, [bodyLine]);
}
}