@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
99 lines (98 loc) • 4.01 kB
JavaScript
"use strict";
import { TypedJsNode } from "./_Base";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { JsConnectionPointType } from "../utils/io/connections/Js";
import { inputObject3D, setObject3DOutputLine } from "./_BaseObject3D";
import { Poly } from "../../Poly";
export const SetGeometryPositionsInputName = {
[JsConnectionPointType.TRIGGER]: JsConnectionPointType.TRIGGER,
[JsConnectionPointType.OBJECT_3D]: JsConnectionPointType.OBJECT_3D,
values: "values",
lerp: "lerp",
attributeNeedsUpdate: "attributeNeedsUpdate",
computeNormals: "computeNormals",
computeTangents: "computeTangents"
};
const INPUT_NAMES = [
SetGeometryPositionsInputName.trigger,
SetGeometryPositionsInputName.Object3D,
SetGeometryPositionsInputName.values,
SetGeometryPositionsInputName.lerp,
SetGeometryPositionsInputName.attributeNeedsUpdate,
SetGeometryPositionsInputName.computeNormals,
SetGeometryPositionsInputName.computeTangents
];
const DefaultValues = {
[SetGeometryPositionsInputName.lerp]: 1,
[SetGeometryPositionsInputName.attributeNeedsUpdate]: true,
[SetGeometryPositionsInputName.computeNormals]: true,
[SetGeometryPositionsInputName.computeTangents]: true
};
class SetGeometryPositionsJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.lerp = ParamConfig.FLOAT(1, {
range: [0, 1]
});
this.attributeNeedsUpdate = ParamConfig.BOOLEAN(1);
this.computeNormals = ParamConfig.BOOLEAN(1);
this.computeTangents = ParamConfig.BOOLEAN(1);
}
}
const ParamsConfig = new SetGeometryPositionsJsParamsConfig();
export class SetGeometryPositionsJsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "setGeometryPositions";
}
initializeNode() {
super.initializeNode();
this.io.connection_points.set_expected_input_types_function(this.expectedInputTypes.bind(this));
this.io.connection_points.set_input_name_function(this._expectedInputName.bind(this));
this.io.connection_points.set_expected_output_types_function(this._expectedOutputTypes.bind(this));
this.io.connection_points.set_output_name_function(this._expectedOutputNames.bind(this));
}
paramDefaultValue(name) {
return DefaultValues[name];
}
expectedInputTypes() {
return [
JsConnectionPointType.TRIGGER,
JsConnectionPointType.OBJECT_3D,
JsConnectionPointType.VECTOR3_ARRAY,
JsConnectionPointType.FLOAT,
JsConnectionPointType.BOOLEAN,
JsConnectionPointType.BOOLEAN,
JsConnectionPointType.BOOLEAN
];
}
_expectedInputName(index) {
return INPUT_NAMES[index];
}
_expectedOutputTypes() {
return [JsConnectionPointType.TRIGGER, JsConnectionPointType.OBJECT_3D];
}
_expectedOutputNames(i) {
return [JsConnectionPointType.TRIGGER, JsConnectionPointType.OBJECT_3D][i];
}
setLines(linesController) {
setObject3DOutputLine(this, linesController);
}
setTriggerableLines(shadersCollectionController) {
const object3D = inputObject3D(this, shadersCollectionController);
const values = this.variableForInput(shadersCollectionController, SetGeometryPositionsInputName.values);
const lerp = this.variableForInputParam(shadersCollectionController, this.p.lerp);
const attributeNeedsUpdate = this.variableForInputParam(
shadersCollectionController,
this.p.attributeNeedsUpdate
);
const computeNormals = this.variableForInputParam(shadersCollectionController, this.p.computeNormals);
const computeTangents = this.variableForInputParam(shadersCollectionController, this.p.computeTangents);
const func = Poly.namedFunctionsRegister.getFunction("setGeometryPositions", this, shadersCollectionController);
const bodyLine = func.asString(object3D, values, lerp, attributeNeedsUpdate, computeNormals, computeTangents);
shadersCollectionController.addTriggerableLines(this, [bodyLine]);
}
}