matrix-org / matrix-org/thirdroom
Basketball Demo WebSG APIs
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 647
- Forks
- 70
- PR merge metrics
- No merged PRs in 30d
Description
# 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.
```ts
interface ReplicatorSpawnMessage {
node: WebSG.Node;
data: string | ArrayBuffer;
}
```
### `replicator.spawned(): Iterator`
### `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.
```ts
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`
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[])`
```ts
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): 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the WebSG API entry points and the WASM Script Context mentioned in the issue, then trace how scripts currently register and unload resources. Use the Network Replication, Network Peers, ThirdRoom ActionBar, Input, and Physics Body sections as the scope; done means the listed APIs, lifecycle behavior, messages, and component effects are implemented and documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, wasm
- Domain
- api, game-dev, networking
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100