UNPKG

@polygonjs/polygonjs

Version:

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

58 lines (57 loc) 2.74 kB
"use strict"; import { TRIGGER_CONNECTION_NAME, 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 { JsType } from "../../poly/registers/nodes/types/Js"; import { Poly } from "../../Poly"; import { inputObject3D, setObject3DOutputLine } from "./_BaseObject3D"; const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF; class SetObjectLookAtJsParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param targetPosition */ this.targetPosition = ParamConfig.VECTOR3([0, 0, 0]); /** @param up */ this.up = ParamConfig.VECTOR3([0, 1, 0]); /** @param lerp factor */ this.lerp = ParamConfig.FLOAT(1); /** @param invertDirection */ this.invertDirection = ParamConfig.BOOLEAN(0); /** @param sets if the matrix should be updated as the animation progresses */ this.updateMatrix = ParamConfig.BOOLEAN(1); } } const ParamsConfig = new SetObjectLookAtJsParamsConfig(); export class SetObjectLookAtJsNode extends TypedJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return JsType.SET_OBJECT_LOOK_AT; } initializeNode() { this.io.inputs.setNamedInputConnectionPoints([ new JsConnectionPoint(TRIGGER_CONNECTION_NAME, JsConnectionPointType.TRIGGER, CONNECTION_OPTIONS), new JsConnectionPoint(JsConnectionPointType.OBJECT_3D, JsConnectionPointType.OBJECT_3D, CONNECTION_OPTIONS) ]); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(TRIGGER_CONNECTION_NAME, JsConnectionPointType.TRIGGER), new JsConnectionPoint(JsConnectionPointType.OBJECT_3D, JsConnectionPointType.OBJECT_3D) ]); } setLines(linesController) { setObject3DOutputLine(this, linesController); } setTriggerableLines(linesController) { const object3D = inputObject3D(this, linesController); const targetPosition = this.variableForInputParam(linesController, this.p.targetPosition); const up = this.variableForInputParam(linesController, this.p.up); const lerp = this.variableForInputParam(linesController, this.p.lerp); const invertDirection = this.variableForInputParam(linesController, this.p.invertDirection); const updateMatrix = this.variableForInputParam(linesController, this.p.updateMatrix); const func = Poly.namedFunctionsRegister.getFunction("setObjectLookAt", this, linesController); const bodyLine = func.asString(object3D, targetPosition, up, lerp, invertDirection, updateMatrix); linesController.addTriggerableLines(this, [bodyLine]); } }