Appearance
@bendyline/molen-client/navigation
Molen rendering client: three.js wrapper, snapshot sync, interpolation.
ts
import { /* … */ } from '@bendyline/molen-client/navigation';Classes
CollisionTree
Keep Three's collision queries, but partition triangles without duplicating them. Rendered roads, walls and portal covers can overlap. An octree copies each triangle into every intersecting cell and repeatedly splits those copies, causing long rebuild stalls. A balanced bounding-volume tree stores each triangle once, even for coincident surfaces.
Extends
Octree
Constructors
Constructor
ts
new CollisionTree(box?): CollisionTree;Parameters
box?
Box3
Returns
Inherited from
ts
Octree.constructorMethods
build()
ts
build(): this;Returns
this
Overrides
ts
Octree.buildFlyController
Constructors
Constructor
ts
new FlyController(
position,
orientation,
options?
): FlyController;Parameters
position
orientation
pitch
number
yaw
number
options?
Returns
Properties
pitch
ts
pitch: number;Radians above the horizon (negative looks down).
position
ts
readonly position: NavigationVector;yaw
ts
yaw: number;Engine yaw: 0 faces +X (east), -PI/2 faces north.
Methods
update()
ts
update(
dt,
input,
environment
): NavigationPose;Parameters
dt
number
input
environment
Returns
FollowController
Constructors
Constructor
ts
new FollowController(options?): FollowController;Parameters
options?
Returns
Methods
reset()
ts
reset(): void;Snap next frame instead of easing (after a teleport or a subject change).
Returns
void
update()
ts
update(
dt,
subject,
input,
environment
): NavigationPose;Parameters
dt
number
subject
input
environment
Returns
NavigationInputSource
Combines an InputMap (keys, gamepad, software controls) with pointer gestures into one NavigationInput per frame. Switch profiles with setProfile(mode) when navigation changes.
Constructors
Constructor
ts
new NavigationInputSource(options): NavigationInputSource;Parameters
options
Returns
Properties
map
ts
readonly map: InputMap;pointer
ts
readonly pointer: NavigationPointer;Methods
dispose()
ts
dispose(): void;Returns
void
read()
ts
read(dt): NavigationInput;Poll devices and drain this frame's gestures and presses. dt is in seconds.
Parameters
dt
number
Returns
setProfile()
ts
setProfile(profile): void;Parameters
profile
Returns
void
NavigationPointer
Tracks pointer gestures on a surface. One mouse button or finger drags to look; the secondary or middle button, shift-drag, or two fingers pan; the wheel or a two-finger pinch zooms; two fingers rotating twist. Enable pointer lock for mouse-look (walk mode) with setPointerLock.
Constructors
Constructor
ts
new NavigationPointer(surface, options?): NavigationPointer;Parameters
surface
options?
Returns
Methods
consume()
ts
consume(): NavigationGestures;Drop the accumulated gestures and return them. Call once per frame.
Returns
dispose()
ts
dispose(): void;Returns
void
reset()
ts
reset(): void;Forget held pointers and pending gestures (e.g. on blur or a mode change).
Returns
void
setPointerLock()
ts
setPointerLock(enabled): void;Request pointer lock on the next press (mouse-look); releasing unlocks immediately.
Parameters
enabled
boolean
Returns
void
OrbitController
Constructors
Constructor
ts
new OrbitController(initial, options?): OrbitController;Parameters
initial
options?
Returns
Accessors
flying
Get Signature
ts
get flying(): boolean;Whether a fly-to animation is running.
Returns
boolean
rangeLimits
Get Signature
ts
get rangeLimits(): object;The current camera distance limits, meters.
Returns
object
maxRange
ts
maxRange: number;minRange
ts
minRange: number;state
Get Signature
ts
get state(): OrbitState;The state the camera is currently showing.
Returns
Methods
flyTo()
ts
flyTo(state, options?): void;Animate to a framing; direct input during the flight cancels it.
Parameters
state
Partial<OrbitState>
options?
Returns
void
set()
ts
set(state): void;Jump to a framing immediately (fields omitted keep their values).
Parameters
state
Partial<OrbitState>
Returns
void
setRangeLimits()
ts
setRangeLimits(limits): void;Change the camera distance limits (omitted fields keep their values), for example when the distance a scene can draw changes. A camera beyond the new limits eases back inside them.
Parameters
limits
maxRange?
number
minRange?
number
Returns
void
update()
ts
update(
dt,
input,
environment
): NavigationPose;Advance by dt seconds under input and return the pose to render. The target settles onto the ground as terrain streams in, and the camera never dips below minClearance.
Parameters
dt
number
input
environment
Returns
TouchStick
Stick geometry without a DOM: feed it pointer positions, read axes.
Constructors
Constructor
ts
new TouchStick(options?): TouchStick;Parameters
options?
Returns
Properties
radius
ts
readonly radius: number;Accessors
active
Get Signature
ts
get active(): boolean;Returns
boolean
knob
Get Signature
ts
get knob(): object;Knob displacement from the center in CSS pixels, clamped to the radius.
Returns
object
x
ts
x: number;y
ts
y: number;Methods
axes()
ts
axes(): object;Movement intent: forward is up the screen, both in -1..1 after the dead zone.
Returns
object
forward
ts
forward: number;right
ts
right: number;drag()
ts
drag(x, y): void;Parameters
x
number
y
number
Returns
void
press()
ts
press(x, y): void;Parameters
x
number
y
number
Returns
void
release()
ts
release(): void;Returns
void
WalkCollision
A small collision neighborhood in metric coordinates, independent of floating-origin shifts. Only visible, resident geometry under root participates; evicted tiles and hidden layers disappear on the next scan, and instance transforms are expanded only inside the neighborhood. Large geometries (terrain tiles, building cells) are walked through a per-geometry spatial index, so a rebuild costs the triangles near the subject rather than the whole tile. Meshes opt out with userData.walkIgnore, and water materials (userData.terrainWaterMaterial) and semantic:landcover overlays are never solid.
Constructors
Constructor
ts
new WalkCollision(options?): WalkCollision;Parameters
options?
boolean | WalkCollisionOptions
Returns
Properties
octree
ts
readonly octree: CollisionTree;origin
ts
readonly origin: Vector3;Methods
clear()
ts
clear(): void;Returns
void
invalidate()
ts
invalidate(): void;Scan the scene on the next update regardless of the rescan interval: call it before a query that must see geometry published this frame, such as placing a walker.
Returns
void
update()
ts
update(
root,
x,
z,
y?
): void;Track the subject at (x, z). With a verticalRadius, y bounds the neighborhood vertically. Scans the visible scene when the subject leaves the neighborhood, when the rescan interval has passed, or after invalidate(); rebuilds the tree only when nearby geometry changed.
Parameters
root
Object3D
x
number
z
number
y?
number
Returns
void
WalkController
First-person walking over streamed geometry: a 1.8 m capsule with gravity, jumping, wall sliding and a 50° walkable-slope limit, integrated at a fixed 120 Hz so results agree across frame rates. feet is the world position; put the camera WALK_EYE_HEIGHT above it. Missing terrain pauses movement (it is never a bottomless pit) until coverage arrives.
Constructors
Constructor
ts
new WalkController(): WalkController;Returns
Properties
feet
ts
readonly feet: Vector3;grounded
ts
grounded: boolean;ready
ts
ready: boolean;velocity
ts
readonly velocity: Vector3;waitingForTerrain
ts
waitingForTerrain: boolean;Methods
place()
ts
place(collision, sampleHeight): boolean;Find open ground near the fly camera, rather than dropping through a building's roof.
Parameters
collision
sampleHeight
(x, z) => number | undefined
Returns
boolean
reset()
ts
reset(x, z): void;Parameters
x
number
z
number
Returns
void
update()
ts
update(
dt,
input,
collision,
sampleHeight
): void;Parameters
dt
number
input
collision
sampleHeight
(x, z) => number | undefined
Returns
void
Interfaces
CameraOrientation
Properties
pitch
ts
pitch: number;yaw
ts
yaw: number;FlyControllerOptions
Properties
lookSensitivity?
ts
optional lookSensitivity?: number;Radians per CSS pixel of look (default 0.003).
minClearance?
ts
optional minClearance?: number;Minimum height above the ground under the camera, meters (default 2).
minSpeed?
ts
optional minSpeed?: number;Slowest speed in m/s, used near the ground (default 12).
speedPerMeter?
ts
optional speedPerMeter?: number;Speed per meter of height above ground, in 1/s (default 1.2).
sprintFactor?
ts
optional sprintFactor?: number;Multiplier while sprinting (default 4).
FollowControllerOptions
Properties
distance?
ts
optional distance?: number;Horizontal distance behind the subject, meters (default 6).
height?
ts
optional height?: number;Camera height above the subject, meters (default 2.2).
lookHeight?
ts
optional lookHeight?: number;Height above the subject's origin the camera looks at, meters (default 1.2).
minClearance?
ts
optional minClearance?: number;Minimum height above the ground under the camera, meters (default 0.6).
recenter?
ts
optional recenter?: number;Seconds for look offsets to return behind the subject (default 1.5).
smoothing?
ts
optional smoothing?: number;Seconds to close ~63% of the gap to the ideal placement (default 0.18).
FollowSubject
Where the followed subject is and which way it faces.
Properties
heading
ts
heading: number;Compass bearing in radians the subject faces: 0 north, PI/2 east.
position
ts
position: NavigationVector;NavigationEnvironment
World facts a controller may query.
Methods
groundHeight()
ts
groundHeight(x, z): number | undefined;Ground height at world X/Z, or undefined while that terrain is not loaded.
Parameters
x
number
z
number
Returns
number | undefined
NavigationGestures
Gestures accumulated since the previous consume().
Properties
look
ts
look: [number, number];Drag or pointer-lock movement, in CSS pixels (right/down positive).
pan
ts
pan: [number, number];Secondary-button, shift-drag or two-finger movement, in CSS pixels.
taps
ts
taps: object[];Clicks/taps that did not become drags, in element-relative CSS pixels.
x
ts
x: number;y
ts
y: number;twist
ts
twist: number;Two-finger rotation in radians, clockwise positive.
zoom
ts
zoom: number;Log-scale zoom: positive zooms in (wheel up, pinch out).
NavigationInput
Everything a navigation controller reads in one frame.
Properties
interact
ts
interact: number;Presses of interact since the previous frame (edge-triggered).
jump
ts
jump: boolean;Held jump / brake.
look
ts
look: [number, number];Look delta in CSS-pixel equivalents (pointer drag plus scaled gamepad stick).
move
ts
move: object;Movement intent, each -1..1 (forward, right, up).
forward
ts
forward: number;right
ts
right: number;up
ts
up: number;pan
ts
pan: [number, number];Pan delta in CSS pixels (secondary-button, shift or two-finger drag).
pilot?
ts
optional pilot?: PilotInput;Flight controls, present while the pilot profile is active.
sprint
ts
sprint: boolean;taps
ts
taps: object[];Clicks/taps in element-relative CSS pixels.
x
ts
x: number;y
ts
y: number;twist
ts
twist: number;Two-finger twist in radians, clockwise positive.
view
ts
view: number;Presses of the view toggle since the previous frame (edge-triggered).
zoom
ts
zoom: number;Log-scale zoom; positive zooms in.
NavigationInputSourceOptions
Extends
Properties
element
ts
element: NavigationPointerSurface;Element receiving pointer gestures, usually the canvas.
gamepadLookSpeed?
ts
optional gamepadLookSpeed?: number;Gamepad look speed, CSS-pixel equivalents per second at full deflection (default 900).
getGamepads?
ts
optional getGamepads?: () => readonly (InputGamepad | null)[];Gamepad source; injectable for tests.
Returns
readonly (InputGamepad | null)[]
keyTarget?
ts
optional keyTarget?: NavigationKeyTarget;Keyboard/focus event target. Defaults to element, which then needs to be focusable (tabindex="0" on a canvas); presses focus it automatically.
now?
ts
optional now?: () => number;Clock for tap timing; injectable for tests (default performance.now).
Returns
number
Inherited from
profile?
ts
optional profile?: NavigationProfileName;Starting profile (default 'orbit').
tapMilliseconds?
ts
optional tapMilliseconds?: number;Longest press (ms) still counted as a tap (default 350).
Inherited from
NavigationPointerOptions.tapMilliseconds
tapSlop?
ts
optional tapSlop?: number;Movement (CSS px) before a press becomes a drag instead of a tap (default 6).
Inherited from
NavigationPointerOptions.tapSlop
wheelScale?
ts
optional wheelScale?: number;Wheel pixels per e-fold of zoom (default 400).
Inherited from
NavigationPointerOptions.wheelScale
NavigationKeyTarget
Structural event target for keyboard and focus events (a canvas, a document, a fake).
Methods
addEventListener()
ts
addEventListener(type, listener): void;Parameters
type
string
listener
(event) => void
Returns
void
removeEventListener()
ts
removeEventListener(type, listener): void;Parameters
type
string
listener
(event) => void
Returns
void
NavigationPointerEvent
The pointer-event fields the tracker reads.
Properties
button?
ts
optional button?: number;buttons?
ts
optional buttons?: number;clientX
ts
clientX: number;clientY
ts
clientY: number;ctrlKey?
ts
optional ctrlKey?: boolean;movementX?
ts
optional movementX?: number;movementY?
ts
optional movementY?: number;pointerId
ts
pointerId: number;pointerType?
ts
optional pointerType?: string;shiftKey?
ts
optional shiftKey?: boolean;Methods
preventDefault()?
ts
optional preventDefault(): void;Returns
void
NavigationPointerOptions
Extended by
Properties
now?
ts
optional now?: () => number;Clock for tap timing; injectable for tests (default performance.now).
Returns
number
tapMilliseconds?
ts
optional tapMilliseconds?: number;Longest press (ms) still counted as a tap (default 350).
tapSlop?
ts
optional tapSlop?: number;Movement (CSS px) before a press becomes a drag instead of a tap (default 6).
wheelScale?
ts
optional wheelScale?: number;Wheel pixels per e-fold of zoom (default 400).
NavigationPointerSurface
The slice of a DOM element the gesture tracker needs; tests pass a fake.
Properties
ownerDocument?
ts
optional ownerDocument?:
| {
pointerLockElement?: unknown;
exitPointerLock?: void;
}
| null;Methods
addEventListener()
ts
addEventListener(
type,
listener,
options?
): void;Parameters
type
string
listener
(event) => void
options?
boolean | AddEventListenerOptions
Returns
void
focus()?
ts
optional focus(options?): void;Parameters
options?
preventScroll?
boolean
Returns
void
getBoundingClientRect()?
ts
optional getBoundingClientRect(): object;Returns
object
height
ts
height: number;left
ts
left: number;top
ts
top: number;width
ts
width: number;hasPointerCapture()?
ts
optional hasPointerCapture(pointerId): boolean;Parameters
pointerId
number
Returns
boolean
releasePointerCapture()?
ts
optional releasePointerCapture(pointerId): void;Parameters
pointerId
number
Returns
void
removeEventListener()
ts
removeEventListener(type, listener): void;Parameters
type
string
listener
(event) => void
Returns
void
requestPointerLock()?
ts
optional requestPointerLock(): unknown;Returns
unknown
setPointerCapture()?
ts
optional setPointerCapture(pointerId): void;Parameters
pointerId
number
Returns
void
NavigationPose
A camera placement: position, the point it looks at, and its unit view direction.
Properties
direction
ts
direction: NavigationVector;lookAt
ts
lookAt: NavigationVector;position
ts
position: NavigationVector;NavigationWheelEvent
Properties
clientX?
ts
optional clientX?: number;clientY?
ts
optional clientY?: number;deltaMode?
ts
optional deltaMode?: number;0 pixels, 1 lines, 2 pages.
deltaY
ts
deltaY: number;Methods
preventDefault()?
ts
optional preventDefault(): void;Returns
void
OrbitControllerOptions
Properties
maxPitch?
ts
optional maxPitch?: number;maxRange?
ts
optional maxRange?: number;minClearance?
ts
optional minClearance?: number;Minimum camera height above the ground under it, meters (default 3).
minPitch?
ts
optional minPitch?: number;minRange?
ts
optional minRange?: number;rotateSensitivity?
ts
optional rotateSensitivity?: number;Radians per CSS pixel of drag (default 0.005).
smoothing?
ts
optional smoothing?: number;Seconds to close ~63% of the gap to the goal (default 0.12; 0 disables smoothing).
OrbitFlyToOptions
Properties
durationMs?
ts
optional durationMs?: number;Animation length (default scales with distance, 0.6-3 s).
OrbitState
The orbit camera's framing.
Properties
heading
ts
heading: number;Compass bearing of the view in radians: 0 looks north, PI/2 east.
pitch
ts
pitch: number;Downward tilt from the horizon in radians: small is oblique, PI/2 looks straight down.
range
ts
range: number;Camera distance from the target in meters.
target
ts
target: NavigationVector;Ground point the camera looks at (world meters).
PilotInput
Flight controls beyond pitch (-move.forward) and roll (move.right), in the pilot profile.
Properties
engine
ts
engine: number;Presses since the previous frame (edge-triggered).
flaps
ts
flaps: number;gear
ts
gear: number;recover
ts
recover: number;throttle
ts
throttle: number;Held throttle or collective change, -1..1 (more power positive).
yaw
ts
yaw: number;Held rudder or pedals, -1..1 (right positive).
TouchJoystick
Properties
element
ts
readonly element: HTMLElement;stick
ts
readonly stick: TouchStick;Methods
dispose()
ts
dispose(): void;Returns
void
setVisible()
ts
setVisible(visible): void;Parameters
visible
boolean
Returns
void
TouchJoystickOptions
Extends
Properties
className?
ts
optional className?: string;Extra class names for styling the root element.
deadZone?
ts
optional deadZone?: number;Fraction of the radius ignored around the center (default 0.12).
Inherited from
radius?
ts
optional radius?: number;Knob travel radius in CSS pixels (default 56).
Inherited from
source?
ts
optional source?: string;Software-device name in the InputMap (default 'touch-joystick').
TouchStickOptions
Extended by
Properties
deadZone?
ts
optional deadZone?: number;Fraction of the radius ignored around the center (default 0.12).
radius?
ts
optional radius?: number;Knob travel radius in CSS pixels (default 56).
WalkCollisionOptions
Properties
ignoreVehicles?
ts
optional ignoreVehicles?: boolean;Skip car and aircraft geometry; the vehicle systems collide with those themselves.
now?
ts
optional now?: () => number;Clock for the rescan interval, ms (default performance.now).
Returns
number
radius?
ts
optional radius?: number;Horizontal half-size of the neighborhood around the tracked point, meters (default 24).
rebuildDistance?
ts
optional rebuildDistance?: number;How far the tracked point moves from the neighborhood's center before the tree is rebuilt around it (default 6). Queries reach at most radius - rebuildDistance from the point.
rescanIntervalMs?
ts
optional rescanIntervalMs?: number;Minimum time between scans of the visible scene for streaming changes while the tracked point stays inside the neighborhood, ms (default 0: every update scans). A scan visits every visible mesh under the root, so a per-frame host should pass something like 200; invalidate() forces the next update to scan.
verticalRadius?
ts
optional verticalRadius?: number;Vertical half-size of the neighborhood, meters, applied when update receives a y. Fast or airborne subjects use it so ground far below (or roofs far above) never enters the tree; leave it unset to include the whole column, which a walker's placement ray needs.
WalkInput
Properties
forward
ts
forward: number;jump
ts
jump: boolean;right
ts
right: number;sprint
ts
sprint: boolean;yaw
ts
yaw: number;Type Aliases
NavigationProfileName
ts
type NavigationProfileName = "orbit" | "fly" | "walk" | "drive" | "pilot";The navigation modes with a default input profile.
NavigationVector
ts
type NavigationVector = [number, number, number];Variables
MAX_LOOK_PITCH
ts
const MAX_LOOK_PITCH: 1.5 = 1.5;Pitch limit shared by look controls: just short of straight up/down.
NAVIGATION_ACTIONS
ts
const NAVIGATION_ACTIONS: object;Named actions the navigation profiles bind; software controls drive the same names.
Type Declaration
back
ts
readonly back: "nav-back";down
ts
readonly down: "nav-down";engine
ts
readonly engine: "nav-engine";flaps
ts
readonly flaps: "nav-flaps";forward
ts
readonly forward: "nav-forward";gear
ts
readonly gear: "nav-gear";interact
ts
readonly interact: "nav-interact";jump
ts
readonly jump: "nav-jump";left
ts
readonly left: "nav-left";lookDown
ts
readonly lookDown: "nav-look-down";lookLeft
ts
readonly lookLeft: "nav-look-left";lookRight
ts
readonly lookRight: "nav-look-right";lookUp
ts
readonly lookUp: "nav-look-up";recover
ts
readonly recover: "nav-recover";right
ts
readonly right: "nav-right";sprint
ts
readonly sprint: "nav-sprint";throttleDown
ts
readonly throttleDown: "nav-throttle-down";throttleUp
ts
readonly throttleUp: "nav-throttle-up";up
ts
readonly up: "nav-up";view
ts
readonly view: "nav-view";yawLeft
ts
readonly yawLeft: "nav-yaw-left";yawRight
ts
readonly yawRight: "nav-yaw-right";RUN_SPEED
ts
const RUN_SPEED: number;WALK_EYE_HEIGHT
ts
const WALK_EYE_HEIGHT: number;WALK_PLACEMENT_RADIUS
ts
const WALK_PLACEMENT_RADIUS: number;How far from the requested spot place may land the body, including its radius: the ground a host should have loaded (terrain and anything built on it) before calling place.
WALK_SPEED
ts
const WALK_SPEED: number;Functions
applyCameraLookDelta()
ts
function applyCameraLookDelta(
yaw,
pitch,
deltaX,
deltaY,
sensitivity?
): CameraOrientation;Apply a pointer delta (pixels) to a yaw/pitch pair; moving right turns right.
Parameters
yaw
number
pitch
number
deltaX
number
deltaY
number
sensitivity?
number
Returns
cameraForward()
ts
function cameraForward(yaw, pitch): NavigationVector;Parameters
yaw
number
pitch
number
Returns
cameraPlanarForward()
ts
function cameraPlanarForward(yaw): NavigationVector;Parameters
yaw
number
Returns
cameraRight()
ts
function cameraRight(yaw): NavigationVector;Parameters
yaw
number
Returns
createTouchJoystick()
ts
function createTouchJoystick(
container,
input,
options?
): TouchJoystick;Add a movement stick to container (bottom-left by default styling). The stick captures its own pointer, so the rest of the canvas keeps handling look/zoom gestures.
Parameters
container
HTMLElement
input
Pick<InputMap, "setVirtual" | "clearVirtual">
options?
Returns
idleNavigationInput()
ts
function idleNavigationInput(): NavigationInput;An input with no intent; controllers treat it as "hold still".
Returns
navigationInputProfiles()
ts
function navigationInputProfiles(): Record<NavigationProfileName, InputProfile>;Default key/gamepad bindings per navigation mode. Orbit and fly use Q/E for down/up; walk and drive use E to interact (board or leave a vehicle), Space to jump or brake, and V to switch the vehicle view. Pilot flies an aircraft: W/S (or ↑/↓) pitch the nose down/up, A/D (or ←/→) bank, Q/Z work the rudder or pedals, Shift/Ctrl (or +/−, Page Up/Down) set throttle or collective, I toggles the engine, G the gear, F the flaps, R recovers after an impact, Space brakes, V switches the view and E leaves. Hosts may replace any profile through InputMap.defineProfile.
Returns
Record<NavigationProfileName, InputProfile>
orientationFromDirection()
ts
function orientationFromDirection(direction): CameraOrientation;Yaw/pitch of a direction vector (the inverse of cameraForward).
Parameters
direction
Returns
viewNeedsImmediateUpdate()
ts
function viewNeedsImmediateUpdate(
previousPosition,
previousDirection,
position,
direction,
movementThreshold,
turnThresholdRadians
): boolean;Detect camera changes that can outrun a throttled terrain-selection update. Terrain selectors have a view guard band, so tiny per-frame changes can wait for their normal cadence; larger turns or translations need coverage replanned before the next render.
Parameters
previousPosition
previousDirection
position
direction
movementThreshold
number
turnThresholdRadians
number
Returns
boolean