UNPKG

@polygonjs/polygonjs

Version:

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

54 lines (53 loc) 2.2 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 { createVariable } from "./code/assemblers/_BaseJsPersistedConfigUtils"; import { Poly } from "../../Poly"; const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF; const OUTPUT_NAME = "position"; class NearestPositionJsParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param vector3 */ this.Vector3 = ParamConfig.VECTOR3([0, 0, 0]); } } const ParamsConfig = new NearestPositionJsParamsConfig(); export class NearestPositionJsNode extends TypedJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "nearestPosition"; } initializeNode() { super.initializeNode(); this.io.inputs.setNamedInputConnectionPoints([ new JsConnectionPoint(JsConnectionPointType.VECTOR3, JsConnectionPointType.VECTOR3, CONNECTION_OPTIONS), new JsConnectionPoint( JsConnectionPointType.VECTOR3_ARRAY, JsConnectionPointType.VECTOR3_ARRAY, CONNECTION_OPTIONS ) ]); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.VECTOR3) ]); } setLines(shadersCollectionController) { const v3 = this.variableForInputParam(shadersCollectionController, this.p.Vector3); const positions = this.variableForInput(shadersCollectionController, JsConnectionPointType.VECTOR3_ARRAY); const varName = this.jsVarName(OUTPUT_NAME); const variable = createVariable(JsConnectionPointType.VECTOR3); const tmpVarName = variable ? shadersCollectionController.addVariable(this, variable) : void 0; if (!tmpVarName) { return; } const func = Poly.namedFunctionsRegister.getFunction("nearestPosition", this, shadersCollectionController); shadersCollectionController.addBodyOrComputed(this, [ { dataType: JsConnectionPointType.VECTOR3, varName, value: func.asString(v3, positions, tmpVarName) } ]); } }