@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
47 lines (46 loc) • 1.79 kB
JavaScript
;
import { BaseSDFGlNode } from "./_BaseSDF";
import { ThreeToGl } from "../../../../src/core/ThreeToGl";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl";
import { GlType } from "../../poly/registers/nodes/types/Gl";
const OUTPUT_NAME = "float";
class SDFConeGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.position = ParamConfig.VECTOR3([0, 0, 0], { hidden: true });
this.center = ParamConfig.VECTOR3([0, 0, 0]);
this.height = ParamConfig.FLOAT(1);
this.angle = ParamConfig.FLOAT(0.25 * Math.PI, {
range: [0, Math.PI],
rangeLocked: [true, false],
step: 1e-5
});
}
}
const ParamsConfig = new SDFConeGlParamsConfig();
export class SDFConeGlNode extends BaseSDFGlNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return GlType.SDF_CONE;
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.FLOAT)
]);
}
setLines(shadersCollectionController) {
const position = this.position();
const center = ThreeToGl.vector3(this.variableForInputParam(this.p.center));
const angle = ThreeToGl.vector2(this.variableForInputParam(this.p.angle));
const height = ThreeToGl.float(this.variableForInputParam(this.p.height));
const float = this.glVarName(OUTPUT_NAME);
const bodyLine = `float ${float} = sdConeWrapped(${position} - ${center}, ${angle}, ${height})`;
shadersCollectionController.addBodyLines(this, [bodyLine]);
this._addSDFMethods(shadersCollectionController);
}
}