UNPKG

@polygonjs/polygonjs

Version:

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

48 lines (47 loc) 1.78 kB
"use strict"; import { TypedJsNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { JsConnectionPoint, JsConnectionPointType } from "../utils/io/connections/Js"; import { Vector3 } from "three"; import { Poly } from "../../Poly"; const OUTPUT_NAME = "position"; class Vector3ProjectOnPlaneJsParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param vector3 */ this.Vector3 = ParamConfig.VECTOR3([1, 0, 0]); /** @param planeNormal */ this.planeNormal = ParamConfig.VECTOR3([0, 1, 0]); } } const ParamsConfig = new Vector3ProjectOnPlaneJsParamsConfig(); export class Vector3ProjectOnPlaneJsNode extends TypedJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "vector3ProjectOnPlane"; } initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.VECTOR3) ]); } setLines(shadersCollectionController) { const vector3 = this.variableForInputParam(shadersCollectionController, this.p.Vector3); const planeNormal = this.variableForInputParam(shadersCollectionController, this.p.planeNormal); const out = this.jsVarName(OUTPUT_NAME); const tmpVarName = shadersCollectionController.addVariable(this, new Vector3()); const func = Poly.namedFunctionsRegister.getFunction( "vector3ProjectOnPlane", this, shadersCollectionController ); const bodyLine = func.asString(vector3, planeNormal, tmpVarName); shadersCollectionController.addBodyOrComputed(this, [ { dataType: JsConnectionPointType.VECTOR3, varName: out, value: bodyLine } ]); } }