UNPKG

@polygonjs/polygonjs

Version:

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

48 lines (47 loc) 1.72 kB
"use strict"; import { BaseSDFJsNode } from "./_BaseSDF"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { JsConnectionPointType, JsConnectionPoint } from "../utils/io/connections/Js"; import { JsType } from "../../poly/registers/nodes/types/Js"; import { Poly } from "../../Poly"; import { Vector3 } from "three"; const OUTPUT_NAME = "p"; class SDFTransformJsParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.position = ParamConfig.VECTOR3([0, 0, 0], { hidden: true }); this.t = ParamConfig.VECTOR3([0, 0, 0]); this.r = ParamConfig.VECTOR3([0, 0, 0]); } } const ParamsConfig = new SDFTransformJsParamsConfig(); export class SDFTransformJsNode extends BaseSDFJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return JsType.SDF_TRANSFORM; } initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.VECTOR3) ]); } setLines(linesController) { const position = this.position(linesController); const t = this.variableForInputParam(linesController, this.p.t); const r = this.variableForInputParam(linesController, this.p.r); const out = this.jsVarName(OUTPUT_NAME); const tmpVarName = linesController.addVariable(this, new Vector3()); const func = Poly.namedFunctionsRegister.getFunction("SDFTransform", this, linesController); linesController.addBodyOrComputed(this, [ { dataType: JsConnectionPointType.FLOAT, varName: out, value: func.asString(position, t, r, tmpVarName) } ]); } }