UNPKG

@polygonjs/polygonjs

Version:

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

60 lines (59 loc) 2.55 kB
"use strict"; import { ParamlessTypedJsNode } from "./_Base"; import { JsConnectionPoint, JsConnectionPointType, JS_CONNECTION_POINT_IN_NODE_DEF } from "../utils/io/connections/Js"; import { Vector3 } from "three"; import { Poly } from "../../Poly"; const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF; var GetSpherePropertyJsNodeInputName = /* @__PURE__ */ ((GetSpherePropertyJsNodeInputName2) => { GetSpherePropertyJsNodeInputName2["center"] = "center"; GetSpherePropertyJsNodeInputName2["radius"] = "radius"; return GetSpherePropertyJsNodeInputName2; })(GetSpherePropertyJsNodeInputName || {}); export class GetSpherePropertyJsNode extends ParamlessTypedJsNode { static type() { return "getSphereProperty"; } initializeNode() { this.io.inputs.setNamedInputConnectionPoints([ new JsConnectionPoint(JsConnectionPointType.SPHERE, JsConnectionPointType.SPHERE, CONNECTION_OPTIONS) ]); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint("center" /* center */, JsConnectionPointType.VECTOR3), new JsConnectionPoint("radius" /* radius */, JsConnectionPointType.FLOAT) ]); } setLines(shadersCollectionController) { const usedOutputNames = this.io.outputs.used_output_names(); const sphere = this.variableForInput(shadersCollectionController, JsConnectionPointType.SPHERE); const _v3 = (propertyName, functionName, type) => { if (!usedOutputNames.includes(propertyName)) { return; } const varName = this.jsVarName(propertyName); const tmpVarName = shadersCollectionController.addVariable(this, new Vector3()); const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController); shadersCollectionController.addBodyOrComputed(this, [ { dataType: type, varName, value: func.asString(sphere, tmpVarName) } ]); }; const _f = (propertyName, functionName, type) => { if (!usedOutputNames.includes(propertyName)) { return; } const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController); shadersCollectionController.addBodyOrComputed(this, [ { dataType: type, varName: this.jsVarName(propertyName), value: func.asString(sphere) } ]); }; _v3("center" /* center */, "getSphereCenter", JsConnectionPointType.VECTOR3); _f("radius" /* radius */, "getSphereRadius", JsConnectionPointType.FLOAT); } }