UNPKG

@polygonjs/polygonjs

Version:

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

81 lines (80 loc) 3.67 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 { inputObject3D } from "./_BaseObject3D"; import { Poly } from "../../Poly"; import { handTrackingVector4Array } from "../../../core/computerVision/hand/Data"; import { VectorArray } from "./code/assemblers/_BaseJsPersistedConfigUtils"; const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF; export var TrackHandJsNodeOutput = /* @__PURE__ */ ((TrackHandJsNodeOutput2) => { TrackHandJsNodeOutput2["NORMALIZED_LANDMARKS"] = "normalizedLandmarks"; TrackHandJsNodeOutput2["WORLD_LANDMARKS"] = "worldLandmarks"; return TrackHandJsNodeOutput2; })(TrackHandJsNodeOutput || {}); class TrackHandJsParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.handIndex = ParamConfig.INTEGER(0, { range: [0, 1], rangeLocked: [true, false] }); } } const ParamsConfig = new TrackHandJsParamsConfig(); export class TrackHandJsNode extends TypedJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "trackHand"; } initializeNode() { this.io.inputs.setNamedInputConnectionPoints([ new JsConnectionPoint(TRIGGER_CONNECTION_NAME, JsConnectionPointType.TRIGGER, CONNECTION_OPTIONS), new JsConnectionPoint(JsConnectionPointType.OBJECT_3D, JsConnectionPointType.OBJECT_3D, CONNECTION_OPTIONS), new JsConnectionPoint(JsConnectionPointType.TEXTURE, JsConnectionPointType.TEXTURE, CONNECTION_OPTIONS) ]); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint("normalizedLandmarks" /* NORMALIZED_LANDMARKS */, JsConnectionPointType.VECTOR4_ARRAY), new JsConnectionPoint("worldLandmarks" /* WORLD_LANDMARKS */, JsConnectionPointType.VECTOR4_ARRAY) ]); } setTriggerableLines(shadersCollectionController) { const object3D = inputObject3D(this, shadersCollectionController); const texture = this.variableForInput(shadersCollectionController, JsConnectionPointType.TEXTURE); const func = Poly.namedFunctionsRegister.getFunction("trackHand", this, shadersCollectionController); const bodyLine = func.asString(object3D, texture); shadersCollectionController.addTriggerableLines(this, [bodyLine]); } setLines(shadersCollectionController) { const object3D = inputObject3D(this, shadersCollectionController); const usedOutputNames = this.io.outputs.used_output_names(); const handIndex = this.variableForInputParam(shadersCollectionController, this.p.handIndex); const _v4 = (propertyName, functionName, type) => { if (!usedOutputNames.includes(propertyName)) { return; } const varName = this.jsVarName(propertyName); const tmpVarName = shadersCollectionController.addVariable( this, new VectorArray(handTrackingVector4Array()) ); const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController); shadersCollectionController.addBodyOrComputed(this, [ { dataType: type, varName, value: func.asString(object3D, handIndex, tmpVarName) } ]); }; _v4( "normalizedLandmarks" /* NORMALIZED_LANDMARKS */, "trackHandGetNormalizedLandmarks", JsConnectionPointType.VECTOR4_ARRAY ); _v4("worldLandmarks" /* WORLD_LANDMARKS */, "trackHandGetWorldLandmarks", JsConnectionPointType.VECTOR4_ARRAY); } }