Appearance
@tmrw-realityos/world • Docs
@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
Defined in
Properties
assetsPath
assetsPath:
string
=""
Defined in
camera
camera:
Camera
Defined in
canvas?
optional
canvas:HTMLCanvasElement
Defined in
device?
optional
device:GPUDevice
Defined in
hover?
optional
hover:iTestResult
Defined in
input
input:
Input
Defined in
lastTime
lastTime:
number
Defined in
meshPicker?
optional
meshPicker:WebGPUMeshPicker
Defined in
onUpdate()?
optional
onUpdate: (dt
) =>void
Parameters
• dt: number
Returns
void
Defined in
renderer?
optional
renderer:WebGPURenderer
Defined in
showGizmos
showGizmos:
boolean
=false
Defined in
videoManager?
optional
videoManager:VideoManager
Defined in
world
world:
World
Defined in
Methods
destroy()
destroy():
void
Destroys the renderer and removes input events.
Returns
void
Defined in
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
getBoundComponents()
getBoundComponents(
node
,class_name
?):BaseComponent
[]
Parameters
• node: Node
• class_name?: string
Returns
Defined in
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
loopStep()
loopStep():
void
Returns
void
Defined in
onRenderGizmos()
onRenderGizmos(
renderer
):void
Parameters
• renderer: WebGPURenderer
Returns
void
Defined in
resetHover()
resetHover():
void
Returns
void
Defined in
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
start()
start():
void
Start the main loop. Must be called after init.
Returns
void
Defined in
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
>