@relu-interactives/spatial-ecs
@relu-interactives/spatial-ecs / index / World
Class: World ​
Defined in: World.ts:129
Constructors ​
Constructor ​
new World(options): World;Defined in: World.ts:208
Parameters ​
| Parameter | Type | Description |
|---|---|---|
options | { scene: Scene; camera: PerspectiveCamera; renderer: EcsRenderer; backend?: RenderBackend; featureFlags?: WorldFeatureFlags; gameId?: string; } | - |
options.scene | Scene | - |
options.camera | PerspectiveCamera | - |
options.renderer | EcsRenderer | A THREE.WebGLRenderer, or a WebGPURenderer from three/webgpu. A WebGPURenderer must be initialised (await renderer.init()) before the first update(). |
options.backend? | RenderBackend | Renderer-specific behaviour (post-processing, green-screen video, area lights). Defaults to the WebGL backend; pass webgpuBackend from @relu-interactives/spatial-ecs/webgpu with a WebGPURenderer. |
options.featureFlags? | WorldFeatureFlags | - |
options.gameId? | string | Names this game for saved settings (relu-game-settings:<gameId>), so two games on one site keep their own volume and graphics choices. |
Returns ​
World
Accessors ​
settings ​
Get Signature ​
get settings(): GameSettings;Defined in: World.ts:429
The player's settings: graphics, audio, controls and gameplay, saved between visits. The engine applies its own parts; a settings screen reads and writes here.
world.settings.update({ audio: { music: 0.4 } });Returns ​
input ​
Get Signature ​
get input(): InputSystem | null;Defined in: World.ts:436
The input system with actions, gamepads and touch, or null when the host added none.
Returns ​
InputSystem | null
quality ​
Get Signature ​
get quality(): QualitySystem | null;Defined in: World.ts:441
Graphics quality: presets, the device and its recommendation, fps. Null without a QualitySystem.
Returns ​
QualitySystem | null
streaming ​
Get Signature ​
get streaming(): StreamingSystem | null;Defined in: World.ts:1463
World streaming: loads regions of a big world as the player comes near and frees them from memory once they're far (StreamingComponent). Change what distance is measured from with setFocus (the camera by default), the load concurrency and memory budget in settings, and read getStats(world). Null before setup.
this.world.streaming?.setFocus(this.entityId);Returns ​
StreamingSystem | null
lod ​
Get Signature ​
get lod(): LODSystem | null;Defined in: World.ts:1476
Levels of detail (LODComponent): bias multiplies every screen size (null follows the quality preset), switches counts level changes.
Returns ​
LODSystem | null
occlusion ​
Get Signature ​
get occlusion(): OcclusionCullingSystem | null;Defined in: World.ts:1485
Occlusion culling (OccluderComponent): enabled, xr (also in a headset), maxOccluders, getStats(), and addOccluderSource for systems with their own occluders.
Returns ​
OcclusionCullingSystem | null
terrain ​
Get Signature ​
get terrain(): TerrainSystem | null;Defined in: World.ts:1498
Terrains (TerrainComponent): heightAt(world, x, z) and normalAt(world, x, z) read the ground in world space; edit(id) gives a terrain's heightfield to sculpt and paint; save(id) its .terrain file.
const ground = this.world.terrain?.heightAt(this.world, x, z);Returns ​
TerrainSystem | null
foliage ​
Get Signature ​
get foliage(): FoliageSystem | null;Defined in: World.ts:1503
Grass and scattered models on terrains: getStats().
Returns ​
FoliageSystem | null
Methods ​
createEntity() ​
createEntity(): number;Defined in: World.ts:239
Returns ​
number
destroyEntity() ​
destroyEntity(entityId): void;Defined in: World.ts:247
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
Returns ​
void
hasEntity() ​
hasEntity(entityId): boolean;Defined in: World.ts:274
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
Returns ​
boolean
getEntities() ​
getEntities(): number[];Defined in: World.ts:278
Returns ​
number[]
getEntityCount() ​
getEntityCount(): number;Defined in: World.ts:282
Returns ​
number
addComponent() ​
addComponent<T>(entityId, component): void;Defined in: World.ts:286
Type Parameters ​
| Type Parameter |
|---|
T extends Component |
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
component | T |
Returns ​
void
addComponents() ​
addComponents<T>(entityId, components): void;Defined in: World.ts:301
Type Parameters ​
| Type Parameter |
|---|
T extends Component |
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
components | T[] |
Returns ​
void
removeComponent() ​
removeComponent<T>(entityId, componentType): void;Defined in: World.ts:322
Type Parameters ​
| Type Parameter |
|---|
T extends Component |
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
componentType | ComponentClass<T> |
Returns ​
void
getComponent() ​
getComponent<T>(entityId, componentType): T | undefined;Defined in: World.ts:330
Type Parameters ​
| Type Parameter |
|---|
T extends Component |
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
componentType | ComponentClass<T> |
Returns ​
T | undefined
hasComponent() ​
hasComponent<T>(entityId, componentType): boolean;Defined in: World.ts:337
Type Parameters ​
| Type Parameter |
|---|
T extends Component |
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
componentType | ComponentClass<T> |
Returns ​
boolean
query() ​
query(...componentTypes): number[];Defined in: World.ts:344
Parameters ​
| Parameter | Type |
|---|---|
...componentTypes | ComponentClass<Component>[] |
Returns ​
number[]
getStoreVersion() ​
getStoreVersion(): number;Defined in: World.ts:405
A number that changes whenever an entity or component is added or removed. Systems compare it to skip work when nothing came or went.
Returns ​
number
isEntityVisible() ​
isEntityVisible(entityId): boolean;Defined in: World.ts:415
Returns true if the entity is currently visible (its Object3DRef.visibility is true), or if the entity has no Object3DRef component (entities without a scene object are always considered active). Systems use this to skip per-entity updates for hidden objects.
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
Returns ​
boolean
getQualityLimits() ​
getQualityLimits(): QualityLimits | null;Defined in: World.ts:451
What the quality system applies now. Lights and post effects read it.
Returns ​
QualityLimits | null
getInputSystem() ​
getInputSystem(): EcsSystem | null;Defined in: World.ts:460
Returns ​
EcsSystem | null
getKeyDown() ​
getKeyDown(key): boolean;Defined in: World.ts:472
Parameters ​
| Parameter | Type |
|---|---|
key | KeyboardKey |
Returns ​
boolean
getKeyUp() ​
getKeyUp(key): boolean;Defined in: World.ts:481
Parameters ​
| Parameter | Type |
|---|---|
key | KeyboardKey |
Returns ​
boolean
getKey() ​
getKey(key): boolean;Defined in: World.ts:490
Parameters ​
| Parameter | Type |
|---|---|
key | KeyboardKey |
Returns ​
boolean
getMouse() ​
getMouse(button): boolean;Defined in: World.ts:499
Parameters ​
| Parameter | Type |
|---|---|
button | string | number |
Returns ​
boolean
getMouseDown() ​
getMouseDown(button): boolean;Defined in: World.ts:508
Parameters ​
| Parameter | Type |
|---|---|
button | string | number |
Returns ​
boolean
getMouseUp() ​
getMouseUp(button): boolean;Defined in: World.ts:517
Parameters ​
| Parameter | Type |
|---|---|
button | string | number |
Returns ​
boolean
getScrollClick() ​
getScrollClick(): boolean;Defined in: World.ts:526
Returns ​
boolean
getScrollClickDown() ​
getScrollClickDown(): boolean;Defined in: World.ts:535
Returns ​
boolean
getScrollClickUp() ​
getScrollClickUp(): boolean;Defined in: World.ts:544
Returns ​
boolean
getScrollDelta() ​
getScrollDelta(): {
x: number;
y: number;
};Defined in: World.ts:553
Returns ​
{
x: number;
y: number;
}| Name | Type | Defined in |
|---|---|---|
x | number | World.ts:553 |
y | number | World.ts:553 |
consumeScrollDelta() ​
consumeScrollDelta(): {
x: number;
y: number;
};Defined in: World.ts:562
Returns ​
{
x: number;
y: number;
}| Name | Type | Defined in |
|---|---|---|
x | number | World.ts:562 |
y | number | World.ts:562 |
getMousePosition() ​
getMousePosition(): {
x: number;
y: number;
};Defined in: World.ts:571
Returns ​
{
x: number;
y: number;
}| Name | Type | Defined in |
|---|---|---|
x | number | World.ts:571 |
y | number | World.ts:571 |
getMouseDelta() ​
getMouseDelta(): {
x: number;
y: number;
};Defined in: World.ts:580
Returns ​
{
x: number;
y: number;
}| Name | Type | Defined in |
|---|---|---|
x | number | World.ts:580 |
y | number | World.ts:580 |
consumeMouseDelta() ​
consumeMouseDelta(): {
x: number;
y: number;
};Defined in: World.ts:589
Returns ​
{
x: number;
y: number;
}| Name | Type | Defined in |
|---|---|---|
x | number | World.ts:589 |
y | number | World.ts:589 |
getRapierModule() ​
getRapierModule(): Promise<__module>;Defined in: World.ts:598
Returns ​
Promise<__module>
getPhysicsWorld() ​
getPhysicsWorld(): World | null;Defined in: World.ts:616
Returns ​
World | null
setPhysicsWorld() ​
setPhysicsWorld(physicsWorld): void;Defined in: World.ts:620
Parameters ​
| Parameter | Type |
|---|---|
physicsWorld | World | null |
Returns ​
void
createPhysicsWorld() ​
createPhysicsWorld(options?): Promise<World | null>;Defined in: World.ts:624
Parameters ​
| Parameter | Type |
|---|---|
options? | { gravity?: { x?: number; y?: number; z?: number; }; } |
options.gravity? | { x?: number; y?: number; z?: number; } |
options.gravity.x? | number |
options.gravity.y? | number |
options.gravity.z? | number |
Returns ​
Promise<World | null>
lockMousePointer() ​
lockMousePointer(): boolean;Defined in: World.ts:643
Returns ​
boolean
unlockMousePointer() ​
unlockMousePointer(): boolean;Defined in: World.ts:674
Returns ​
boolean
isMousePointerLocked() ​
isMousePointerLocked(): boolean;Defined in: World.ts:695
Returns ​
boolean
onPointerLockChange() ​
onPointerLockChange(listener): () => void;Defined in: World.ts:727
Listen for the pointer lock being gained or lost. Returns an unsubscribe function.
Escape while the pointer is locked is taken by the browser, which drops the lock and may never show the page a keydown. This is how a game hears it.
Parameters ​
| Parameter | Type |
|---|---|
listener | PointerLockListener |
Returns ​
() => void
Example ​
const stop = world.onPointerLockChange((locked) => {
if (!locked) world.pause();
});
// later
stop();getSystem() ​
getSystem<T>(system): T;Defined in: World.ts:759
Type Parameters ​
| Type Parameter |
|---|
T extends EcsSystem |
Parameters ​
| Parameter | Type |
|---|---|
system | T |
Returns ​
T
hasSystem() ​
hasSystem<T>(system): boolean;Defined in: World.ts:776
Type Parameters ​
| Type Parameter |
|---|
T extends EcsSystem |
Parameters ​
| Parameter | Type |
|---|---|
system | T |
Returns ​
boolean
addSystem() ​
addSystem(system): void;Defined in: World.ts:785
Parameters ​
| Parameter | Type |
|---|---|
system | EcsSystem |
Returns ​
void
addSystems() ​
addSystems(systems): void;Defined in: World.ts:789
Parameters ​
| Parameter | Type |
|---|---|
systems | EcsSystem[] |
Returns ​
void
setup() ​
setup(__namedParameters): {
objectManagementSystem: ObjectManagementSystem;
transformSyncSystem: TransformSyncSystem;
renderSystem: RenderSystem;
};Defined in: World.ts:795
Parameters ​
| Parameter | Type |
|---|---|
__namedParameters | { systems: EcsSystem[]; isEditor?: boolean; } |
__namedParameters.systems | EcsSystem[] |
__namedParameters.isEditor? | boolean |
Returns ​
{
objectManagementSystem: ObjectManagementSystem;
transformSyncSystem: TransformSyncSystem;
renderSystem: RenderSystem;
}| Name | Type | Defined in |
|---|---|---|
objectManagementSystem | ObjectManagementSystem | World.ts:796 |
transformSyncSystem | TransformSyncSystem | World.ts:797 |
renderSystem | RenderSystem | World.ts:798 |
isEditorMode() ​
isEditorMode(): boolean;Defined in: World.ts:930
Returns ​
boolean
isXrPresenting() ​
isXrPresenting(): boolean;Defined in: World.ts:947
true while an immersive WebXR session is actively presenting.
While presenting, three's WebXRManager OWNS the render camera: each frame updateUserCamera() writes the headset pose into the camera's position/quaternion/scale and copies the XR projection (including a derived fov) onto it. Systems that also drive the camera must stand down for the duration, or they ping-pong with the headset every frame and defeat their own dirty-checks.
Locomotion therefore moves the camera's PARENT (the XR rig) — three composes the head pose as parent.matrixWorld × headPose.
Returns ​
boolean
isXrPassthrough() ​
isXrPassthrough(): boolean;Defined in: World.ts:964
true while the session is compositing over the real world (passthrough).
Read from the session's environmentBlendMode rather than from what the app ASKED for: a request for immersive-ar can be granted as a plain opaque session, and the blend mode is the only thing that says what the user is actually looking at. additive (optical see-through) and alpha-blend (video passthrough) both mean the real world is visible behind the render.
The load-bearing consequence is that nothing may paint an opaque background: a skybox drawn over the whole framebuffer hides the room completely, which looks exactly like passthrough having failed.
Returns ​
boolean
setXrView() ​
setXrView(view, options?): boolean;Defined in: World.ts:984
What the player is shown in a passthrough session: their room, or a fully virtual world drawn over it, which is VR. Switches live, with no new session and no tap; the sky fades in or out over fade seconds (default 0.6). Everything that depends on the view switches at once: locomotion works only in virtual, and the player's rig snaps back to where it was when they return to the room, so content stays where it belongs in their room.
Answers whether the view can be shown here: virtual always, room only in a passthrough session (Quest, Android XR; never Apple Vision Pro, which gives web pages no passthrough). Each session starts in its rig's startView, whatever was set before it.
Parameters ​
| Parameter | Type |
|---|---|
view | XrView |
options | { fade?: number; } |
options.fade? | number |
Returns ​
boolean
getXrView() ​
getXrView(): XrView;Defined in: World.ts:995
What the player sees now: room only while the real room is showing.
Returns ​
canShowXrRoom() ​
canShowXrRoom(): boolean;Defined in: World.ts:1000
Whether this session could show the room (a passthrough session).
Returns ​
boolean
isXrRoomVisible() ​
isXrRoomVisible(): boolean;Defined in: World.ts:1010
true while the real room is meant to be seen: a passthrough session in the room view. Systems that only make sense over the real room (no artificial locomotion, subtle avatars, depth occlusion) read this rather than the session's blend mode.
Returns ​
boolean
getXrViewFadeSeconds() ​
getXrViewFadeSeconds(): number;Defined in: World.ts:1015
Seconds the last setXrView asked the sky to fade over.
Returns ​
number
pause() ​
pause(options?): void;Defined in: World.ts:1034
Pauses the game: physics, animation, IK, locomotion and every script's onUpdate stop, and playing sounds and videos hold their place. A custom system stops too unless it sets runsWhilePaused.
The world keeps rendering and reading input, so a headset stays tracked and a pause menu works: scripts get onPause, then onPausedUpdate each frame. Later systems in the frame pause() is called from already see it.
Calling it while paused does nothing. In a multiplayer room it pauses this player only: the room carries on.
Parameters ​
| Parameter | Type |
|---|---|
options | PauseOptions |
Returns ​
void
resume() ​
resume(): void;Defined in: World.ts:1057
Resumes the game after pause: sounds and videos that were held pick up where they were, and scripts get onResume. Physics carries on from where it stopped, with no catch-up. Calling it while running does nothing.
Returns ​
void
togglePause() ​
togglePause(options?): boolean;Defined in: World.ts:1072
pause if the game is running, resume if it is paused. Returns whether it is paused now.
Parameters ​
| Parameter | Type |
|---|---|
options? | PauseOptions |
Returns ​
boolean
onPauseChange() ​
onPauseChange(listener): () => void;Defined in: World.ts:1095
Listen for the game pausing and resuming. Called with true on pause and false on resume, after systems and scripts have heard. Returns an unsubscribe function.
Parameters ​
| Parameter | Type |
|---|---|
listener | PauseListener |
Returns ​
() => void
Example ​
const stop = world.onPauseChange((paused) => {
overlay.hidden = !paused;
});
// later
stop();isPaused() ​
isPaused(): boolean;Defined in: World.ts:1140
Returns true if the world is currently paused.
Returns ​
boolean
Example ​
if (this.world.isPaused()) {
this.world.resume();
}getScene() ​
getScene(): Scene;Defined in: World.ts:1144
Returns ​
Scene
getCamera() ​
getCamera(): PerspectiveCamera;Defined in: World.ts:1148
Returns ​
PerspectiveCamera
getRenderer() ​
getRenderer(): EcsRenderer;Defined in: World.ts:1158
The renderer this world draws with: a THREE.WebGLRenderer, or a WebGPURenderer from three/webgpu. Check getRendererKind before using an API only one of them has (for example capabilities exists on WebGL only).
Returns ​
warmUpShaders() ​
warmUpShaders(): Promise<number>;Defined in: World.ts:1175
Compile the shaders of everything in the scene now, hidden objects included, instead of the first time each is drawn.
A material's first draw compiles its shader, which on a Quest was a 100-600 ms freeze per batch, and once 2.6 s when a game mode showed 50 new materials at once (Counters Ball). Call it once loading has finished, behind the loading screen, and again after spawning a batch of new kinds of things. Uses the renderer's compileAsync, so where the browser can compile in parallel (KHR_parallel_shader_compile) the page keeps running. Resolves to the number of new shader programs, or 0 where the renderer can't count them. Never throws.
Returns ​
Promise<number>
getRendererKind() ​
getRendererKind(): RendererKind;Defined in: World.ts:1192
"webgpu" when the world renders with a WebGPURenderer, else "webgl".
Returns ​
getRenderBackend() ​
getRenderBackend(): RenderBackend;Defined in: World.ts:1200
The renderer-specific backend in use (post-processing, green-screen video, area lights). See RenderBackend.
Returns ​
update() ​
update(deltaTime): void;Defined in: World.ts:1204
Parameters ​
| Parameter | Type |
|---|---|
deltaTime | number |
Returns ​
void
dispose() ​
dispose(): void;Defined in: World.ts:1214
Returns ​
void
setSelectedEntity() ​
setSelectedEntity(entityId): void;Defined in: World.ts:1241
Parameters ​
| Parameter | Type |
|---|---|
entityId | number | null |
Returns ​
void
getSelectedEntity() ​
getSelectedEntity(): number | null;Defined in: World.ts:1263
Returns ​
number | null
getEntitiesByComponent() ​
getEntitiesByComponent(component): WorldEntityView[];Defined in: World.ts:1323
Parameters ​
| Parameter | Type |
|---|---|
component | Component |
Returns ​
WorldEntityView[]
getEntitiesByName() ​
getEntitiesByName(name): WorldEntityView[];Defined in: World.ts:1337
Parameters ​
| Parameter | Type |
|---|---|
name | string |
Returns ​
WorldEntityView[]
getEntityByName() ​
getEntityByName(name): WorldEntityView | null;Defined in: World.ts:1355
Parameters ​
| Parameter | Type |
|---|---|
name | string |
Returns ​
WorldEntityView | null
getEntityById() ​
getEntityById(entityId): WorldEntityView | null;Defined in: World.ts:1381
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
Returns ​
WorldEntityView | null
getEntitiesChildren() ​
getEntitiesChildren(entityId): WorldEntityView[];Defined in: World.ts:1389
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
Returns ​
WorldEntityView[]
getEntitiesParent() ​
getEntitiesParent(entityId): WorldEntityView | null;Defined in: World.ts:1403
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
Returns ​
WorldEntityView | null
spawnPrefab() ​
spawnPrefab(source, options?): Promise<number>;Defined in: World.ts:1418
Instantiate a prefab asset into this world at runtime — see spawnPrefab. Convenience wrapper so scripts and embedding apps can spawn without reaching for the object management system.
Parameters ​
| Parameter | Type |
|---|---|
source | SpawnPrefabSource |
options? | SpawnPrefabOptions |
Returns ​
Promise<number>
despawnPrefab() ​
despawnPrefab(rootEntityId): number;Defined in: World.ts:1426
Remove a spawned prefab instance (root + descendants).
Parameters ​
| Parameter | Type |
|---|---|
rootEntityId | number |
Returns ​
number
getNetwork() ​
getNetwork(): NetworkService | null;Defined in: World.ts:1431
The shared-world connection, or null in a single-player run.
Returns ​
NetworkService | null
setNetwork() ​
setNetwork(network): void;Defined in: World.ts:1436
Set by NetworkSystem when it connects and clears.
Parameters ​
| Parameter | Type |
|---|---|
network | NetworkService | null |
Returns ​
void
getAudioSystem() ​
getAudioSystem(): AudioSystem | null;Defined in: World.ts:1441
The audio system (mixer buses, sound banks), or null before setup.
Returns ​
AudioSystem | null
getCameraDirector() ​
getCameraDirector(): CameraDirector;Defined in: World.ts:1447
Cutscenes, camera shake and camera-relative input. See CameraDirector.
Returns ​
getModelLoadGate() ​
getModelLoadGate(): ModelLoadGate | null;Defined in: World.ts:1507
Returns ​
ModelLoadGate | null
getIKSystem() ​
getIKSystem(): IKSystem | null;Defined in: World.ts:1512
Returns ​
IKSystem | null
getFaceTracker() ​
getFaceTracker(): Face | null;Defined in: World.ts:1521
The face tracker of a face-tracking project: expressions, and where things are on the person in front of the camera. null in the editor and in other kinds of project.
Returns ​
Face | null
setFaceTracker() ​
setFaceTracker(tracker): void;Defined in: World.ts:1529
Set by a face-tracking runtime. Attached objects read it to find the person's head, and scripts read gestures through it.
Parameters ​
| Parameter | Type |
|---|---|
tracker | FaceTracker | null |
Returns ​
void
getHandTracker() ​
getHandTracker(): Hands | null;Defined in: World.ts:1538
Hands: which are in view, their poses and gestures. null unless the project has hand tracking on, and in the editor.
Returns ​
Hands | null
setHandTracker() ​
setHandTracker(tracker): void;Defined in: World.ts:1547
Set by a project with hand tracking on, with what createHandTracker makes in @relu-interactives/spatial-ecs/hands. That's its own entry, so a project without hands doesn't carry any of it.
Parameters ​
| Parameter | Type |
|---|---|
tracker | HandTrackerRuntime | null |
Returns ​
void
getUIPanelSystem() ​
getUIPanelSystem(): UIPanelSystem | null;Defined in: World.ts:1556
The spatial-UI system, or null when this world runs without one. Use it to ask what draws a widget tree: getUIPanelSystem()?.rendererOf(world, id).
Returns ​
UIPanelSystem | null
getObjectManagementSystem() ​
getObjectManagementSystem(): ObjectManagementSystem;Defined in: World.ts:1560
Returns ​
getEnvironmentComponent() ​
getEnvironmentComponent(): Environment | undefined;Defined in: World.ts:1588
Returns the singleton Environment component for the scene, or undefined if no environment entity exists yet.
Mutate component.values directly to change skybox, fog, or gravity at runtime — EnvironmentSyncSystem picks up the changes next frame.
Returns ​
Environment | undefined
Example ​
const env = this.world.getEnvironmentComponent();
if (env) {
env.values.fog.type = "exponential";
env.values.fog.exponential.density = 0.01;
}getPostprocessingComponent() ​
getPostprocessingComponent():
| Postprocessing
| undefined;Defined in: World.ts:1611
Returns the singleton Postprocessing component for the scene, or undefined if no postprocessing entity exists yet.
Mutate component.values directly to enable/disable effects or tweak parameters at runtime — PostprocessingSyncSystem picks up the changes next frame.
Returns ​
| Postprocessing | undefined
Example ​
const pp = this.world.getPostprocessingComponent();
if (pp) {
pp.values.bloom.enabled = true;
pp.values.bloom.intensity = 2.0;
}raycast() ​
raycast(
origin,
direction,
near?,
far?,
options?): IntersectionResult[];Defined in: World.ts:1660
Cast a ray from origin along direction and return every intersected entity-bound mesh, sorted by distance. Each result is a standard THREE.Intersection augmented with the owning entityId (or null if the hit object is not part of any tracked entity).
Big static meshes get a bounding volume hierarchy the first time a ray reaches them, so a ray at a 500k-triangle terrain tests a few dozen triangles. Pass options to make a call cheaper still:
firstHitOnly: only the nearest hit; meshes are tried nearest first and the search stops early. Use it whenever you only need "what's in front".visibleOnly: skip hidden objects (three's raycaster tests them).entities: test only these entities (and their children).ignore: never hit these entities.layers: only objects on these three.js layers.
Parameters ​
| Parameter | Type | Default value | Description |
|---|---|---|---|
origin | Vec3 | undefined | World-space origin of the ray (THREE.Vector3 or { x, y, z }). |
direction | Vec3 | undefined | World-space direction of the ray. Will be normalized internally; magnitude is ignored. |
near | number | RaycastOptions | 0 | Minimum hit distance, or the options object. Defaults to 0. |
far | number | Infinity | Maximum hit distance from the origin. Defaults to Infinity. |
options | RaycastOptions | {} | See above. |
Returns ​
Example ​
const hits = world.raycast(
{ x: 0, y: 1, z: 0 },
{ x: 0, y: 0, z: -1 },
);
if (hits[0]?.entityId !== null) {
console.log("hit entity", hits[0].entityId, "at", hits[0].point);
}
// Only what's in front, ignoring hidden objects, within 50 m.
const [ground] = world.raycast(origin, down, {
far: 50,
firstHitOnly: true,
visibleOnly: true,
});raycastWith() ​
raycastWith(raycaster, options?): IntersectionResult[];Defined in: World.ts:1693
Like raycast, with a raycaster you set up yourself (for example with setFromCamera). Its near, far and layers are used; camera is filled in when missing, since three needs it to test sprites.
Parameters ​
| Parameter | Type |
|---|---|
raycaster | Raycaster |
options | RaycastOptions |
Returns ​
raycastFrom() ​
raycastFrom(
entityId,
near?,
far?): IntersectionResult[];Defined in: World.ts:1758
Cast a ray from an entity's world-space position along its forward direction (the +Z axis of its world matrix). Returns intersected entity-bound meshes sorted by distance, with the source entity itself filtered out so the ray does not hit the caster.
Parameters ​
| Parameter | Type | Default value | Description |
|---|---|---|---|
entityId | number | undefined | Entity to cast the ray from. Must have an Object3DRef. |
near | number | RaycastOptions | 0 | Minimum hit distance from the origin, or the options object (see raycast). Defaults to 0. |
far | number | Infinity | Maximum hit distance from the origin. Defaults to Infinity. |
Returns ​
Example ​
const hits = world.raycastFrom(this.entityId, 0, 50);
const closest = hits[0];
if (closest && closest.entityId !== null) {
console.log("looking at", closest.entityId);
}getEntityScript() ​
getEntityScript<T>(entityId): T | null;Defined in: World.ts:1836
Type Parameters ​
| Type Parameter | Default type |
|---|---|
T | unknown |
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
Returns ​
T | null
getScripts() ​
getScripts<T>(className): T[];Defined in: World.ts:1849
Type Parameters ​
| Type Parameter | Default type |
|---|---|
T | unknown |
Parameters ​
| Parameter | Type |
|---|---|
className | string |
Returns ​
T[]
getScript() ​
getScript<T>(className): T | null;Defined in: World.ts:1890
Type Parameters ​
| Type Parameter | Default type |
|---|---|
T | unknown |
Parameters ​
| Parameter | Type |
|---|---|
className | string |
Returns ​
T | null
getAllEntities() ​
getAllEntities(): WorldEntityView[];Defined in: World.ts:1895
Returns ​
WorldEntityView[]
onSelectionChanged() ​
onSelectionChanged(listener): () => void;Defined in: World.ts:1901
Parameters ​
| Parameter | Type |
|---|---|
listener | SelectionListener |
Returns ​
() => void
subscribe() ​
subscribe(listener): () => void;Defined in: World.ts:1909
Parameters ​
| Parameter | Type |
|---|---|
listener | StoreListener |
Returns ​
() => void
onScriptError() ​
onScriptError(listener): () => void;Defined in: World.ts:1935
Listen for script errors from Behaviours and ScriptObjects: load failures, init() / build() / update() exceptions, and exceptions thrown inside Behaviour hooks such as onSelect or onUiPress.
Each DISTINCT error (same script URL, class, phase and message) is delivered once, so a script that throws every frame does not flood the listener. Returns an unsubscribe function.
Parameters ​
| Parameter | Type |
|---|---|
listener | ScriptErrorListener |
Returns ​
() => void
Example ​
const stop = world.onScriptError((event) => {
console.warn(`${event.className} failed in ${event.phase}: ${event.message}`);
});
// later
stop();reportScriptError() ​
reportScriptError(report, error): boolean;Defined in: World.ts:1952
Report a script error. Used by the script systems and by any system that calls into Behaviour hooks; scripts themselves do not need to call it.
The first occurrence of a distinct error (same script URL, class, phase and message) is logged with console.error and delivered to onScriptError listeners; repeats are dropped. Returns true when the error was new.
Parameters ​
| Parameter | Type |
|---|---|
report | ScriptErrorReport |
error | unknown |
Returns ​
boolean
clearScriptErrors() ​
clearScriptErrors(scriptUrl?): void;Defined in: World.ts:2004
Forget which script errors were already reported, so their next occurrence is logged and delivered again. Pass a script URL to forget only that script's errors (for example after hot-reloading it).
Parameters ​
| Parameter | Type |
|---|---|
scriptUrl? | string |
Returns ​
void
getDebugSnapshot() ​
getDebugSnapshot(maxDepth?): unknown;Defined in: World.ts:2016
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
maxDepth | number | 3 |
Returns ​
unknown
getDebugSignature() ​
getDebugSignature(maxDepth?): string;Defined in: World.ts:2066
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
maxDepth | number | 3 |
Returns ​
string
getEntitiesSnapshot() ​
getEntitiesSnapshot(entityIds, maxDepth?): {
entities: number[];
components: {
component: string;
entries: {
entityId: number;
value: unknown;
}[];
}[];
};Defined in: World.ts:2075
Serialize ONLY the given entities into the same columnar {entities, components} shape as getDebugSnapshot (no systems, no selection). Used by prefab/scene subtree serialization.
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
entityIds | number[] | undefined |
maxDepth | number | 10 |
Returns ​
{
entities: number[];
components: {
component: string;
entries: {
entityId: number;
value: unknown;
}[];
}[];
}| Name | Type | Defined in |
|---|---|---|
entities | number[] | World.ts:2079 |
components | { component: string; entries: { entityId: number; value: unknown; }[]; }[] | World.ts:2080 |
createHistorySnapshot() ​
createHistorySnapshot(): WorldHistorySnapshot;Defined in: World.ts:2117
Returns ​
WorldHistorySnapshot
applyHistorySnapshot() ​
applyHistorySnapshot(snapshot): void;Defined in: World.ts:2138
Parameters ​
| Parameter | Type |
|---|---|
snapshot | WorldHistorySnapshot |
Returns ​
void

