UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

47 lines (46 loc) 1.84 kB
"use strict"; import { TypedJsNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { JsConnectionPoint, JsConnectionPointType, JS_CONNECTION_POINT_IN_NODE_DEF } from "../utils/io/connections/Js"; import { Sphere } from "three"; import { Poly } from "../../Poly"; const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF; class SphereJsParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param sphere center */ this.center = ParamConfig.VECTOR3([0, 0, 0]); /** @param sphere radius */ this.radius = ParamConfig.FLOAT(1, { range: [0, 10], rangeLocked: [true, false] }); } } const ParamsConfig = new SphereJsParamsConfig(); export class SphereJsNode extends TypedJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "sphere"; } initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(JsConnectionPointType.SPHERE, JsConnectionPointType.SPHERE, CONNECTION_OPTIONS) ]); } setLines(shadersCollectionController) { const center = this.variableForInputParam(shadersCollectionController, this.p.center); const radius = this.variableForInputParam(shadersCollectionController, this.p.radius); const out = this.jsVarName(JsConnectionPointType.SPHERE); const tmpVarName = shadersCollectionController.addVariable(this, new Sphere()); const func = Poly.namedFunctionsRegister.getFunction("sphereSet", this, shadersCollectionController); const bodyLine = func.asString(center, radius, tmpVarName); shadersCollectionController.addBodyOrComputed(this, [ { dataType: JsConnectionPointType.SPHERE, varName: out, value: bodyLine } ]); } }