UNPKG

@polygonjs/polygonjs

Version:

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

51 lines (50 loc) 2.21 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 { inputObject3D } from "./_BaseObject3D"; import { createVariable } from "./code/assemblers/_BaseJsPersistedConfigUtils"; import { Poly } from "../../Poly"; const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF; const OUTPUT_NAME = "local"; class Object3DWorldToLocalJsParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param vector3 */ this.Vector3 = ParamConfig.VECTOR3([0, 0, 0]); } } const ParamsConfig = new Object3DWorldToLocalJsParamsConfig(); export class Object3DWorldToLocalJsNode extends TypedJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "object3DWorldToLocal"; } initializeNode() { super.initializeNode(); this.io.inputs.setNamedInputConnectionPoints([ new JsConnectionPoint(JsConnectionPointType.OBJECT_3D, JsConnectionPointType.OBJECT_3D, CONNECTION_OPTIONS) // new JsConnectionPoint(JsConnectionPointType.VECTOR3, JsConnectionPointType.VECTOR3, CONNECTION_OPTIONS), ]); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.VECTOR3) ]); } setLines(shadersCollectionController) { const object3D = inputObject3D(this, shadersCollectionController); const position = this.variableForInputParam(shadersCollectionController, this.p.Vector3); 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("object3DWorldToLocal", this, shadersCollectionController); shadersCollectionController.addBodyOrComputed(this, [ { dataType: JsConnectionPointType.PLANE, varName, value: func.asString(object3D, position, tmpVarName) } ]); } }