@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
60 lines (59 loc) • 2.12 kB
JavaScript
;
import { JsConnectionPoint, JsConnectionPointType, JS_CONNECTION_POINT_IN_NODE_DEF } from "../utils/io/connections/Js";
import { Vector3 } from "three";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { TypedJsNode } from "./_Base";
import { Poly } from "../../Poly";
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
const T_NAME = "t";
const OUTPUT_NAME = "position";
class CatmullRomCurve3GetPointJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.t = ParamConfig.FLOAT(0, {
range: [0, 1],
rangeLocked: [true, true]
});
}
}
const ParamsConfig = new CatmullRomCurve3GetPointJsParamsConfig();
export class CatmullRomCurve3GetPointJsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "catmullRomCurve3GetPoint";
}
initializeNode() {
this.io.inputs.setNamedInputConnectionPoints([
new JsConnectionPoint(
JsConnectionPointType.CATMULL_ROM_CURVE3,
JsConnectionPointType.CATMULL_ROM_CURVE3,
CONNECTION_OPTIONS
),
new JsConnectionPoint(T_NAME, JsConnectionPointType.FLOAT, CONNECTION_OPTIONS)
]);
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.VECTOR3)
]);
}
setLines(shadersCollectionController) {
const inputCurve = this.variableForInput(shadersCollectionController, JsConnectionPointType.CATMULL_ROM_CURVE3);
const t = this.variableForInputParam(shadersCollectionController, this.p.t);
const varName = this.jsVarName(OUTPUT_NAME);
const tmpVarName = shadersCollectionController.addVariable(this, new Vector3());
const func = Poly.namedFunctionsRegister.getFunction(
"catmullRomCurve3GetPoint",
this,
shadersCollectionController
);
shadersCollectionController.addBodyOrComputed(this, [
{
dataType: JsConnectionPointType.VECTOR3,
varName,
value: func.asString(inputCurve, t, tmpVarName)
}
]);
}
}