UNPKG

@polygonjs/polygonjs

Version:

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

47 lines (46 loc) 2.01 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 { Vector3 } from "three"; import { Poly } from "../../Poly"; const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF; const OUTPUT_NAME = "position"; class Vector3ProjectJsParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param vector3 */ this.Vector3 = ParamConfig.VECTOR3([0, 0, 0]); } } const ParamsConfig = new Vector3ProjectJsParamsConfig(); export class Vector3ProjectJsNode extends TypedJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "vector3Project"; } initializeNode() { super.initializeNode(); this.io.inputs.setNamedInputConnectionPoints([ new JsConnectionPoint(JsConnectionPointType.VECTOR3, JsConnectionPointType.VECTOR3, CONNECTION_OPTIONS), new JsConnectionPoint(JsConnectionPointType.CAMERA, JsConnectionPointType.CAMERA, CONNECTION_OPTIONS) ]); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.VECTOR3) ]); } setLines(shadersCollectionController) { const vector3 = this.variableForInputParam(shadersCollectionController, this.p.Vector3); const camera = this.variableForInput(shadersCollectionController, JsConnectionPointType.CAMERA); const out = this.jsVarName(OUTPUT_NAME); const tmpVarName = shadersCollectionController.addVariable(this, new Vector3()); const func = Poly.namedFunctionsRegister.getFunction("vector3Project", this, shadersCollectionController); const bodyLine = func.asString(vector3, camera, tmpVarName); shadersCollectionController.addBodyOrComputed(this, [ { dataType: JsConnectionPointType.VECTOR3, varName: out, value: bodyLine } ]); } }