polygonjs-engine
Version:
node-based webgl 3D engine https://polygonjs.com
43 lines (42 loc) • 1.76 kB
JavaScript
import {TypedGlNode} from "./_Base";
import {ThreeToGl as ThreeToGl2} from "../../../../src/core/ThreeToGl";
import DiskMethods from "./gl/disk.glsl";
import {NodeParamsConfig, ParamConfig} from "../utils/params/ParamsConfig";
import {GlConnectionPointType, GlConnectionPoint} from "../utils/io/connections/Gl";
import {FunctionGLDefinition} from "./utils/GLDefinition";
const OUTPUT_NAME = "float";
class SphereGlParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.position = ParamConfig.VECTOR3([0, 0, 0]);
this.center = ParamConfig.VECTOR3([0, 0, 0]);
this.radius = ParamConfig.FLOAT(1);
this.feather = ParamConfig.FLOAT(0.1);
}
}
const ParamsConfig2 = new SphereGlParamsConfig();
export class SphereGlNode extends TypedGlNode {
constructor() {
super(...arguments);
this.params_config = ParamsConfig2;
}
static type() {
return "sphere";
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.FLOAT)
]);
}
set_lines(shaders_collection_controller) {
const position = ThreeToGl2.vector2(this.variable_for_input("position"));
const center = ThreeToGl2.vector2(this.variable_for_input("center"));
const radius = ThreeToGl2.float(this.variable_for_input("radius"));
const feather = ThreeToGl2.float(this.variable_for_input("feather"));
const float = this.gl_var_name("float");
const body_line = `float ${float} = disk3d(${position}, ${center}, ${radius}, ${feather})`;
shaders_collection_controller.add_body_lines(this, [body_line]);
shaders_collection_controller.add_definitions(this, [new FunctionGLDefinition(this, DiskMethods)]);
}
}