Skip to content

@tmrw-realityos/worldDocs


@tmrw-realityos/world / Player

Class: Player

Class in charge of handling the interaction with a World. It contains the main loop and dispatches actions to render, update, etc

Example

This examples demonstrates how to construct a simple player.

ts
import {registerAllComponents} from "./components/index"
const canvas = document.createElement("canvas");
const player = new Player();
// Register components to be available to the world.
// For simplicity, all supported components are registered here.
registerAllComponents();
// Initialize the renderer and bind input events to a canvas
await player.init(canvas);
// Load a world
player.world.load("worldfile.json");
// Start main loop
player.start();

Constructors

new Player()

new Player(assetsPath): Player

Player constructor creates an empty World.

Parameters

assetsPath: string

Base path for assets referenced by relative filename.

Returns

Player

Defined in

player.ts:60

Properties

assetsPath

assetsPath: string = ""

Defined in

player.ts:47


camera

camera: Camera

Defined in

player.ts:46


canvas?

optional canvas: HTMLCanvasElement

Defined in

player.ts:38


device?

optional device: GPUDevice

Defined in

player.ts:39


hover?

optional hover: iTestResult

Defined in

player.ts:50


input

input: Input

Defined in

player.ts:43


lastTime

lastTime: number

Defined in

player.ts:49


meshPicker?

optional meshPicker: WebGPUMeshPicker

Defined in

player.ts:41


onUpdate()?

optional onUpdate: (dt) => void

Parameters

dt: number

Returns

void

Defined in

player.ts:54


renderer?

optional renderer: WebGPURenderer

Defined in

player.ts:40


showGizmos

showGizmos: boolean = false

Defined in

player.ts:52


videoManager?

optional videoManager: VideoManager

Defined in

player.ts:42


world

world: World

Defined in

player.ts:45

Methods

destroy()

destroy(): void

Destroys the renderer and removes input events.

Returns

void

Defined in

player.ts:71


executeMethodFromNode()

executeMethodFromNode(node, func_name, data): void

calls anything that could be affected by this node

Parameters

node: Node

func_name: string

data: unknown

Returns

void

Defined in

player.ts:253


getBoundComponents()

getBoundComponents(node, class_name?): BaseComponent[]

Parameters

node: Node

class_name?: string

Returns

BaseComponent[]

Defined in

player.ts:237


init()

init(canvas): Promise<void>

Initialize the renderer. Must be async for creating a WebGPU device. Sets up input events on the target element.

Parameters

canvas: HTMLCanvasElement

Target element

Returns

Promise<void>

Defined in

player.ts:82


loopStep()

loopStep(): void

Returns

void

Defined in

player.ts:110


onRenderGizmos()

onRenderGizmos(renderer): void

Parameters

renderer: WebGPURenderer

Returns

void

Defined in

player.ts:158


resetHover()

resetHover(): void

Returns

void

Defined in

player.ts:170


sendMouseInteractionToWorld()

sendMouseInteractionToWorld(e): void

Checks object on top of mouse and sends mouse and ray events to the hovered node.

Parameters

e: PointerEvent

pointer event

Returns

void

Defined in

player.ts:215


start()

start(): void

Start the main loop. Must be called after init.

Returns

void

Defined in

player.ts:166


testMouseHover()

testMouseHover(x, y, layers): Promise<undefined | iTestResult>

check which node is below the mouse and set some flags

Parameters

x: number

y: number

layers: number = 0xff

Returns

Promise<undefined | iTestResult>

Defined in

player.ts:176