UNPKG

@polygonjs/polygonjs

Version:

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

49 lines (48 loc) 1.7 kB
"use strict"; import { TypedJsNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { JsConnectionPoint, JsConnectionPointType } from "../utils/io/connections/Js"; import { Quaternion } from "three"; import { Poly } from "../../Poly"; class QuaternionJsParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param axis */ this.axis = ParamConfig.VECTOR3([0, 1, 0]); /** @param rotation order */ this.angle = ParamConfig.FLOAT(0, { range: [-Math.PI, Math.PI], rangeLocked: [false, false] }); } } const ParamsConfig = new QuaternionJsParamsConfig(); export class QuaternionJsNode extends TypedJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "quaternion"; } initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(JsConnectionPointType.QUATERNION, JsConnectionPointType.QUATERNION) ]); } setLines(linesController) { const axis = this.variableForInputParam(linesController, this.p.axis); const angle = this.variableForInputParam(linesController, this.p.angle); const varName = this.jsVarName(JsConnectionPointType.QUATERNION); const tmpVarName = linesController.addVariable(this, new Quaternion()); const func = Poly.namedFunctionsRegister.getFunction("quaternionSetFromAxisAngle", this, linesController); linesController.addBodyOrComputed(this, [ { dataType: JsConnectionPointType.EULER, varName, value: func.asString(axis, angle, tmpVarName) } ]); } }