UNPKG

@polygonjs/polygonjs

Version:

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

149 lines (148 loc) 5.66 kB
"use strict"; import { TypedJsNode } from "./_Base"; import { JsConnectionPoint, JsConnectionPointType } from "../utils/io/connections/Js"; import { Ray, Vector3 } from "three"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { Poly } from "../../Poly"; import { inputObject3D } from "./_BaseObject3D"; var GetWebXRControllerPropertyJsNodeInputName = /* @__PURE__ */ ((GetWebXRControllerPropertyJsNodeInputName2) => { GetWebXRControllerPropertyJsNodeInputName2["Object3D"] = "Object3D"; GetWebXRControllerPropertyJsNodeInputName2["Ray"] = "Ray"; GetWebXRControllerPropertyJsNodeInputName2["hasLinearVelocity"] = "hasLinearVelocity"; GetWebXRControllerPropertyJsNodeInputName2["linearVelocity"] = "linearVelocity"; GetWebXRControllerPropertyJsNodeInputName2["hasAngularVelocity"] = "hasAngularVelocity"; GetWebXRControllerPropertyJsNodeInputName2["angularVelocity"] = "angularVelocity"; return GetWebXRControllerPropertyJsNodeInputName2; })(GetWebXRControllerPropertyJsNodeInputName || {}); class GetWebXRControllerPropertyJsParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param controller index */ this.controllerIndex = ParamConfig.INTEGER(0, { range: [0, 1], rangeLocked: [true, true] }); } } const ParamsConfig = new GetWebXRControllerPropertyJsParamsConfig(); export class GetWebXRControllerPropertyJsNode extends TypedJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "getWebXRControllerProperty"; } initializeNode() { this.io.inputs.setNamedInputConnectionPoints([]); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint("Object3D" /* Object3D */, JsConnectionPointType.OBJECT_3D), new JsConnectionPoint("Ray" /* Ray */, JsConnectionPointType.RAY), new JsConnectionPoint( "hasLinearVelocity" /* hasLinearVelocity */, JsConnectionPointType.BOOLEAN ), new JsConnectionPoint( "linearVelocity" /* linearVelocity */, JsConnectionPointType.VECTOR3 ), new JsConnectionPoint( "hasAngularVelocity" /* hasAngularVelocity */, JsConnectionPointType.BOOLEAN ), new JsConnectionPoint( "angularVelocity" /* angularVelocity */, JsConnectionPointType.VECTOR3 ) ]); } setLines(shadersCollectionController) { const usedOutputNames = this.io.outputs.used_output_names(); const object3D = inputObject3D(this, shadersCollectionController); const controllerIndex = this.variableForInputParam(shadersCollectionController, this.p.controllerIndex); const _object = (propertyName, functionName, type) => { if (!usedOutputNames.includes(propertyName)) { return; } const varName = this.jsVarName(propertyName); const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController); shadersCollectionController.addBodyOrComputed(this, [ { dataType: type, varName, value: func.asString(object3D, controllerIndex) } ]); }; const _ray = (propertyName, functionName, type) => { if (!usedOutputNames.includes(propertyName)) { return; } const varName = this.jsVarName(propertyName); const tmpVarName = shadersCollectionController.addVariable(this, new Ray()); const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController); shadersCollectionController.addBodyOrComputed(this, [ { dataType: type, varName, value: func.asString(object3D, controllerIndex, tmpVarName) } ]); }; const _b = (propertyName, functionName, type) => { if (!usedOutputNames.includes(propertyName)) { return; } const varName = this.jsVarName(propertyName); const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController); shadersCollectionController.addBodyOrComputed(this, [ { dataType: type, varName, value: func.asString(object3D, controllerIndex) } ]); }; const _v3 = (propertyName, functionName, type) => { if (!usedOutputNames.includes(propertyName)) { return; } const varName = this.jsVarName(propertyName); const tmpVarName = shadersCollectionController.addVariable(this, new Vector3()); const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController); shadersCollectionController.addBodyOrComputed(this, [ { dataType: type, varName, value: func.asString(object3D, controllerIndex, tmpVarName) } ]); }; _object( "Object3D" /* Object3D */, "getWebXRControllerObject", JsConnectionPointType.OBJECT_3D ); _ray("Ray" /* Ray */, "getWebXRControllerRay", JsConnectionPointType.RAY); _b( "hasAngularVelocity" /* hasAngularVelocity */, "getWebXRControllerHasAngularVelocity", JsConnectionPointType.BOOLEAN ); _v3( "angularVelocity" /* angularVelocity */, "getWebXRControllerAngularVelocity", JsConnectionPointType.VECTOR3 ); _b( "hasLinearVelocity" /* hasLinearVelocity */, "getWebXRControllerHasLinearVelocity", JsConnectionPointType.BOOLEAN ); _v3( "linearVelocity" /* linearVelocity */, "getWebXRControllerLinearVelocity", JsConnectionPointType.VECTOR3 ); } }