ThreeInput

A scene's pointer input: the canvas's pointer events, hit-tested by a raycast, as core's InputSource, so a mesh is hovered and pressed as an element is. hover(subject, onStart) and press(subject, onStart) are Motion's functions on a scene's objects: onStart runs as the gesture starts, and what it returns runs as it ends, press's told whether it ended on the object. Each returns its cancel.

  • What a pointer hits: the nearest object under it that's drawn: on the camera's layers, and visible, with every parent. An object with no gesture still blocks what's behind it. A hit on a child is a hit on each object above it. hitTest replaces the raycast, for a BVH or GPU picking.
  • When: once a frame per pointer over the canvas, at the start of frame(t), against what was last drawn, so hover follows what moves under a still pointer; a down and a release at once, where they happen. With no gesture watched, nothing is cast.
  • A raycast that throws (the camera's, hitTest's, an object's raycast) is reported once until one succeeds: a pointer keeps what it was over, a down or a release hits nothing, and Wardic's writes run on.
  • A Batch: hover(swarm, onStart) watches each member, an InstancedMesh's instance by the hit's instanceId, and tells which as the event's member; hover(swarm.at(i), onStart) member i alone.
import * as WardicThree from "@wardic/three/WardicThree"

const wardic = WardicThree.make({ canvas: renderer.domElement, camera, scene })
wardic.hover(crate, () => {
  wardic.animate(crate, { scale: 1.1 })
  return () => wardic.animate(crate, { scale: 1 })
})
wardic.press(swarm, (event) => (end, { success }) => {
  if (success) select(event.member)
})

Interfaces

CanvasLike

A canvas, as the input reads one: its pointer events, and where it is on the page.

Extends

  • EventTarget

Properties

getBoundingClientRect
readonly getBoundingClientRect: () => object;
Returns

object

height
readonly height: number;
left
readonly left: number;
top
readonly top: number;
width
readonly width: number;
ownerDocument?
readonly ownerDocument?: 
  | {
  defaultView: EventTarget | null;
}
  | null;

Options

The scene's input: its canvas, its camera (or the one active now), and the scene a pointer hits.

Properties

camera
readonly camera: Camera | (() => Camera);
canvas
readonly canvas: CanvasLike;
hitTest?
readonly hitTest?: HitTest;

What a pointer hits, in the raycast's place: a BVH's, or a GPU pick's. three's raycast over scene when left out.

scene
readonly scene: Object3D;
window?
readonly window?: EventTarget;

Where a held pointer's events are heard once it leaves the canvas: the canvas's window when left out.


SceneInput

A scene's input, made by make: core's InputSource for its gestures, and its raycast, once a frame.

Properties

dispose
readonly dispose: () => void;

Ends every gesture, and stops listening.

Returns

void

frame
readonly frame: () => void;

The frame's raycast, each pointer's over the canvas: before Wardic's writes, against what was last drawn.

Returns

void

hover
readonly hover: (subject, onStart) => () => void;

hover, on this input.

Parameters
subject

unknown

onStart

HoverStart

Returns

() => void

press
readonly press: (subject, onStart) => () => void;

press, on this input.

Parameters
subject

unknown

onStart

PressStart

Returns

() => void

source
readonly source: InputSource;
wantsFrame
readonly wantsFrame: () => boolean;

Whether a pointer moved since the last frame while a gesture is watched: a loop that draws on demand draws one.

Returns

boolean


ScenePointerEvent

A pointer's event on a scene, as a gesture's callbacks get it: where it is on the page, and what's under it.

Properties

distance
readonly distance: number | undefined;

How far that is from the camera.

instanceId
readonly instanceId: number | undefined;

The instance of an InstancedMesh it's over.

member
readonly member: number | undefined;

The Batch member a gesture on a Batch is told of, by its index.

nativeEvent
readonly nativeEvent: Event | undefined;

The platform's event, undefined for a hover a frame found under a still pointer.

object
readonly object: Object3D<Object3DEventMap> | undefined;

The nearest object under it, undefined over nothing.

point
readonly point: Vector3 | undefined;

Where the pointer's ray meets object, in world space.

x
readonly x: number;

Where the pointer is across the page, in CSS pixels.

y
readonly y: number;

Where the pointer is down the page, in CSS pixels.

Type Aliases

HitTest

type HitTest = (raycaster, scene) => ReadonlyArray<Intersection>;

What hits a scene: the intersections along the raycaster's ray, nearest first.

Parameters

raycaster

Raycaster

scene

Object3D

Returns

ReadonlyArray<Intersection>


HoverStart

type HoverStart = (event) => void | ((event) => void);

hover's start: what to run as the pointer comes over, and what it returns, as it goes off.

Parameters

event

ScenePointerEvent

Returns

void | ((event) => void)


PressStart

type PressStart = (event) => void | ((event, info) => void);

press's start: what to run as a press starts, and what it returns, as it ends, success when it ended on the object.

Parameters

event

ScenePointerEvent

Returns

void | ((event, info) => void)

Functions

make()

function make(options): SceneInput;

A scene's input on options' canvas, listening from now until dispose.

Parameters

options

Options

Returns

SceneInput