This repository has been archived by the owner on Aug 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from topology-foundation/develop
Merge develop
- Loading branch information
Showing
30 changed files
with
13,762 additions
and
2,509 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<script lang="ts"> | ||
import { onMount, onDestroy } from "svelte"; | ||
import { T, useFrame } from "@threlte/core"; | ||
import { PlayerData, players } from "$lib/store/playersData"; | ||
import type { PlayerID } from "$lib/store/playersData"; | ||
import { addOrUpdatePlayer, removePlayer } from "$lib/store/playersManager"; | ||
import { initializePlayerData, startP2PUpdates } from "$lib/store/fakeP2P"; | ||
import { Vector3, Euler } from "three"; | ||
import Player from "./Player.svelte"; | ||
import { nodeId } from "$lib/topology"; | ||
let playerModels: Map<PlayerID, any> = new Map(); | ||
let playerArray: PlayerData[] = []; | ||
function createPlayerModel() { | ||
return { | ||
position: new Vector3(), | ||
rotation: new Euler(), | ||
}; | ||
} | ||
function updatePlayerState( | ||
model: any, | ||
state: "idle" | "running" | "walking" | "jumping", | ||
): void { | ||
// Do more stuff | ||
} | ||
function updatePlayerModel(player: PlayerData) { | ||
// Find or create the 3D model for the player | ||
let model = playerModels.get(player.id); | ||
if (!model) { | ||
model = createPlayerModel(); | ||
playerModels.set(player.id, model); | ||
} | ||
model.position.copy(player.position); | ||
model.rotation.copy(player.rotation); | ||
updatePlayerState(model, player.state); | ||
} | ||
function updatePlayerArray() { | ||
playerArray = Array.from(players.values()); | ||
} | ||
useFrame(() => { | ||
players.forEach((player) => updatePlayerModel(player)); | ||
updatePlayerArray(); | ||
}); | ||
onMount(async () => { | ||
// //Sets up the mock data of the users | ||
// await initializePlayerData(); | ||
// startP2PUpdates((id, x, y, z, rotationX, rotationY, rotationZ, state) => { | ||
// addOrUpdatePlayer(id, x, y, z, rotationX, rotationY, rotationZ, state); | ||
// updatePlayerArray(); | ||
// }, 60); // 60Hz = 16.17 | ||
}); | ||
onDestroy(() => { | ||
players.clear(); | ||
}); | ||
function stringToColor(str: string): number { | ||
let hash = 0; | ||
for (let i = 0; i < str.length; i++) { | ||
hash = str.charCodeAt(i) + ((hash << 5) - hash); | ||
} | ||
let c = (hash & 0x00ffffff).toString(16).toUpperCase(); | ||
return parseInt("0x" + "00000".substring(0, 6 - c.length) + c); | ||
} | ||
</script> | ||
|
||
{#if playerArray} | ||
{#each playerArray as player (player.id)} | ||
<T.Group | ||
position={[player.position.x, player.position.y, player.position.z]} | ||
> | ||
<T.Mesh> | ||
<T.SphereGeometry args={[0.5, 32, 32]} position={[0, 1, 0]} /> | ||
<T.MeshBasicMaterial color={stringToColor(nodeId)} /> | ||
</T.Mesh> | ||
</T.Group> | ||
{/each} | ||
{/if} |
Oops, something went wrong.