Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basketball Demo WebSG APIs #600

Open
robertlong opened this issue May 3, 2023 · 0 comments
Open

Basketball Demo WebSG APIs #600

robertlong opened this issue May 3, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@robertlong
Copy link
Contributor

robertlong commented May 3, 2023

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.

@robertlong robertlong added the enhancement New feature or request label May 3, 2023
This was referenced May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant