@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
47 lines (46 loc) • 1.81 kB
JavaScript
;
import { TypedJsNode } from "./_Base";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { JsConnectionPoint, JsConnectionPointType } from "../utils/io/connections/Js";
import { Plane } from "three";
import { Poly } from "../../Poly";
const OUTPUT_NAME = JsConnectionPointType.PLANE;
class PlaneJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param a unit length vector defining the normal of the plane */
this.normal = ParamConfig.VECTOR3([0, 1, 0]);
/** @param the signed distance from the origin to the plane */
this.constant = ParamConfig.FLOAT(0, {
range: [-1, 1],
rangeLocked: [false, false]
});
}
}
const ParamsConfig = new PlaneJsParamsConfig();
export class PlaneJsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "plane";
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.PLANE)
]);
}
setLines(shadersCollectionController) {
const normal = this.variableForInputParam(shadersCollectionController, this.p.normal);
const constant = this.variableForInputParam(shadersCollectionController, this.p.constant);
const out = this.jsVarName(OUTPUT_NAME);
const tmpVarName = shadersCollectionController.addVariable(this, new Plane());
const func = Poly.namedFunctionsRegister.getFunction("planeSet", this, shadersCollectionController);
const bodyLine = func.asString(normal, constant, tmpVarName);
shadersCollectionController.addBodyOrComputed(this, [
{ dataType: JsConnectionPointType.PLANE, varName: out, value: bodyLine }
]);
}
}