UNPKG

@polygonjs/polygonjs

Version:

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

123 lines (122 loc) 4.85 kB
"use strict"; import { TRIGGER_CONNECTION_NAME } from "./_Base"; import { JsConnectionPoint, JsConnectionPointType, JS_CONNECTION_POINT_IN_NODE_DEF } from "../utils/io/connections/Js"; import { JsType } from "../../poly/registers/nodes/types/Js"; import { OnObjectPointerEventGPUJsNodeInputName, OnObjectPointerEventGPUJsNodeOutputName, CPUOnObjectPointerEventJsParamsConfig, ExtendableOnObjectPointerEventJsNode, PointerEventConfigParamConfig, pointerButtonConfig } from "./_BaseOnObjectPointerEvent"; import { PointerEventType } from "../../../core/event/PointerEventType"; import { inputObject3D } from "./_BaseObject3D"; import { Poly } from "../../Poly"; import { InitFunctionJsDefinition, RefJsDefinition } from "./utils/JsDefinition"; import { nodeMethodName } from "./code/assemblers/actor/ActorAssemblerUtils"; import { SwipeParamConfig } from "../../scene/utils/actors/rayObjectIntersection/RayObjectIntersectionsSwipeController"; const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF; export class OnObjectSwipeGPUJsParamsConfig extends PointerEventConfigParamConfig( SwipeParamConfig(CPUOnObjectPointerEventJsParamsConfig) ) { } const ParamsConfig = new OnObjectSwipeGPUJsParamsConfig(); export class OnObjectSwipeGPUJsNode extends ExtendableOnObjectPointerEventJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return JsType.ON_OBJECT_SWIPE_GPU; } isTriggering() { return true; } eventData() { return [ { type: PointerEventType.pointerdown, emitter: this.eventEmitter(), jsType: JsType.ON_OBJECT_POINTERDOWN }, // pointerup is currently needed to update the pointerEventsController cursor { type: PointerEventType.pointerup, emitter: this.eventEmitter(), jsType: JsType.ON_OBJECT_POINTERUP } ]; } initializeNode() { super.initializeNode(); this.io.inputs.setNamedInputConnectionPoints([ new JsConnectionPoint(JsConnectionPointType.OBJECT_3D, JsConnectionPointType.OBJECT_3D, CONNECTION_OPTIONS), new JsConnectionPoint( OnObjectPointerEventGPUJsNodeInputName.worldPosMaterial, JsConnectionPointType.MATERIAL, CONNECTION_OPTIONS ) ]); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(TRIGGER_CONNECTION_NAME, JsConnectionPointType.TRIGGER, CONNECTION_OPTIONS), new JsConnectionPoint( OnObjectPointerEventGPUJsNodeOutputName.distance, JsConnectionPointType.FLOAT, CONNECTION_OPTIONS ) ]); } setLines(linesController) { const usedOutputNames = this.io.outputs.used_output_names(); if (usedOutputNames.includes(OnObjectPointerEventGPUJsNodeOutputName.distance)) { this._addDistanceRef(linesController); } } setTriggeringLines(linesController, triggeredMethods) { const object3D = inputObject3D(this, linesController); const blockObjectsBehind = this.variableForInputParam(linesController, this.p.blockObjectsBehind); const skipIfObjectsInFront = this.variableForInputParam(linesController, this.p.skipIfObjectsInFront); const worldPosMaterial = this.variableForInput( linesController, OnObjectPointerEventGPUJsNodeInputName.worldPosMaterial ); const distanceRef = this._addDistanceRef(linesController); const angle = this.variableForInputParam(linesController, this.p.angle); const angleMargin = this.variableForInputParam(linesController, this.p.angleMargin); const minDistance = this.variableForInputParam(linesController, this.p.minDistance); const func = Poly.namedFunctionsRegister.getFunction("addObjectToObjectSwipeCheck", this, linesController); const options = { priority: { blockObjectsBehind, skipIfObjectsInFront }, gpu: { worldPosMaterial, distanceRef: `this.${distanceRef}` }, swipe: { angle, angleMargin, minDistance, callback: `this.${nodeMethodName(this)}.bind(this)` }, config: pointerButtonConfig(this, linesController) }; const jsonOptions = JSON.stringify(options).replace(/"/g, ""); const bodyLine = func.asString(object3D, `this`, jsonOptions); linesController.addDefinitions(this, [ new InitFunctionJsDefinition(this, linesController, JsConnectionPointType.OBJECT_3D, this.path(), bodyLine) ]); linesController.addTriggeringLines(this, [triggeredMethods], { gatherable: true }); } _addDistanceRef(linesController) { const outDistance = this.jsVarName(OnObjectPointerEventGPUJsNodeOutputName.distance); linesController.addDefinitions(this, [ new RefJsDefinition(this, linesController, JsConnectionPointType.FLOAT, outDistance, `-1`) ]); return outDistance; } }