Skip to content

Basketball Demo WebSG APIs #600

@robertlong

Description

@robertlong

Basketball Demo WebSG APIs

Network Replication

network.defineReplicator(factoryFn: () => WebSG.Node): Replicator

Should define a new replicator id with the runtime. Creates a new Replicator instance and sets its opaque data to include the replicator id and factory function. Also registers a prefab.

Replicator ids should be stored on the WASM Script Context and unregistered when the script unloads.

Replicators should be defined before the script is loaded. We may be able to register additional replicators at runtime with coordination on id allocation though so we shouldn't limit it yet but should document that the order that defineReplicator is called matters.

interface ReplicatorSpawnMessage {
  node: WebSG.Node;
  data: string | ArrayBuffer;
}

replicator.spawned(): Iterator<ReplicatorSpawnMessage>

replicator.despawned(): NodeIterator

replicator.spawn(message: string | ArrayBuffer): undefined

Uses the factory function to create a new node. Internally adds the Prefab component, marking the node as an instance of the replicator's prefab. Also adds the Networked and Owned components.

interface NetworkMessage {
  peer: Peer;
  data: string | ArrayBuffer;
}

network.host: Peer

network.local: Peer

network.isHost(): boolean

network.isLocal(): boolean

network.send(peer: Peer, message: string | ArrayBuffer): undefined

network.receive(buffer?: ArrayBuffer): Iterator<NetworkMessage>

Replaces receive and receiveInto and combines into a single API.

Network Peers

peer.id: string

peer.translation: Vector3

peer.rotation: Quaternion

ThirdRoom ActionBar

thirdroom.setActionBarItems(items: ActionBarItems[])

interface ActionBarItems {
  action: string;
  label: string;
  thumbnail: WebSG.Image; // Must not be a compressed texture
}

Input

world.input.get(action: string): ButtonState | Vector2 | Vector3

Physics Body

physicsBody.applyImpulse(impulse: ArrayLike<number>): void

Future Considerations

The platformer example will need network synchronized platform positions. We'd like to be able to define these platforms as replicated or synced in editor and then have them automatically synchronize their positions based on who is the host. The host would be the only one running the systems for moving the platforms. The clients would just be receiving the updates and applying them to the platform nodes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions