@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
67 lines (66 loc) • 2.28 kB
JavaScript
;
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { JsConnectionPoint, JsConnectionPointType } from "../utils/io/connections/Js";
import { JsType } from "../../poly/registers/nodes/types/Js";
import { BaseUserInputJsNode } from "./_BaseUserInput";
import { CoreEventEmitter, EVENT_EMITTERS, EVENT_EMITTER_PARAM_MENU_OPTIONS } from "../../../core/event/CoreEventEmitter";
import { ComputedValueJsDefinition } from "./utils/JsDefinition";
import { Poly } from "../../Poly";
import { PointerEventType } from "../../../core/event/PointerEventType";
const OUTPUT_NAME = "cursor";
class CursorJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param set which element triggers the event */
this.element = ParamConfig.INTEGER(EVENT_EMITTERS.indexOf(CoreEventEmitter.CANVAS), {
...EVENT_EMITTER_PARAM_MENU_OPTIONS
});
}
/** @param cursor */
// cursor = ParamConfig.VECTOR2([0, 0]);
}
const ParamsConfig = new CursorJsParamsConfig();
export class CursorJsNode extends BaseUserInputJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return JsType.CURSOR;
}
// userInputEventNames() {
// return ['pointermove'];
// }
eventData() {
return {
type: PointerEventType.pointermove,
emitter: this.eventEmitter(),
jsType: JsType.CURSOR
};
}
eventEmitter() {
return EVENT_EMITTERS[this.pv.element];
}
setEventEmitter(emitter) {
this.p.element.set(EVENT_EMITTERS.indexOf(emitter));
}
initializeNode() {
this.io.connection_points.spare_params.setInputlessParamNames(["element"]);
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.VECTOR2)
]);
}
setLines(shadersCollectionController) {
const out = this.jsVarName(OUTPUT_NAME);
const _cursor = Poly.namedFunctionsRegister.getFunction("globalsCursor", this, shadersCollectionController);
shadersCollectionController.addDefinitions(this, [
new ComputedValueJsDefinition(
this,
shadersCollectionController,
JsConnectionPointType.VECTOR2,
out,
_cursor.asString()
)
]);
}
}