-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ghostModal): add experimental ghost explorer (#358)
* feat(ghostModal): add experimental ghost explorer * chore: update package.json * chore: update zeepkist gtr client --------- Signed-off-by: James Harris <[email protected]>
- Loading branch information
Showing
12 changed files
with
506 additions
and
57 deletions.
There are no files selected for viewing
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,149 @@ | ||
<script setup lang="ts"> | ||
import { onMounted, onUnmounted, ref } from 'vue' | ||
import { | ||
createGhosts, | ||
createGhostScene, | ||
createSphere, | ||
formatResultTime | ||
} from '~/utils' | ||
export interface Position { | ||
x: number | ||
y: number | ||
z: number | ||
} | ||
export interface Quaternion { | ||
x: number | ||
y: number | ||
z: number | ||
w: number | ||
} | ||
const { ghostUrls = [] } = defineProps<{ | ||
ghostUrls: string[] | ||
}>() | ||
const containerRef = ref() | ||
const { camera, clock, controls, renderer, scene } = createGhostScene() | ||
const { ghosts, totalDuration } = await createGhosts(scene, ghostUrls) | ||
let longestGhost = ghosts[0] | ||
for (const ghost of ghosts) { | ||
if (ghost.ghost.frameCount > longestGhost.ghost.frameCount) { | ||
longestGhost = ghost | ||
} | ||
} | ||
const allPoints = ghosts.flatMap(({ points }) => points) | ||
const { center } = createSphere(scene, allPoints) | ||
const cameraOffsets = { | ||
x: 1.1, | ||
y: 1.5, | ||
z: 1.5 | ||
} | ||
let currentFrame = 0 | ||
let currentTime = ref(0) | ||
onMounted(() => { | ||
containerRef.value.append(renderer.domElement) | ||
renderer.setSize( | ||
containerRef.value.clientWidth, | ||
containerRef.value.clientHeight | ||
) | ||
// Calculate the aspect ratio of the renderer | ||
const aspectRatio = | ||
containerRef.value.clientWidth / containerRef.value.clientHeight | ||
camera.aspect = aspectRatio | ||
animate() | ||
}) | ||
onUnmounted(() => { | ||
renderer.domElement.remove() | ||
}) | ||
const animateDrawing = () => { | ||
const elapsedTime = clock.getElapsedTime() | ||
currentTime.value = | ||
longestGhost.ghost.frames[0].time + | ||
(elapsedTime / totalDuration) * totalDuration | ||
while ( | ||
currentFrame < longestGhost.ghost.frames.length - 1 && | ||
longestGhost.ghost.frames[currentFrame + 1].time < currentTime.value | ||
) { | ||
currentFrame++ | ||
} | ||
const leadingPosition = ghosts[0].points[currentFrame] | ||
if (leadingPosition) { | ||
camera.position.set( | ||
leadingPosition.x * cameraOffsets.x, | ||
leadingPosition.y * cameraOffsets.y, | ||
leadingPosition.z * cameraOffsets.z | ||
) | ||
//camera.lookAt(leadingPosition) | ||
} else { | ||
const position = ghosts[0].points.at(-1) ?? center | ||
camera.position.set( | ||
position.x * cameraOffsets.x, | ||
position.y * cameraOffsets.y, | ||
position.z * cameraOffsets.z | ||
) | ||
//camera.lookAt(position) | ||
} | ||
for (const { geometry, material, ghost } of ghosts) { | ||
const visiblePoints = Math.floor( | ||
(ghost.frameCount / totalDuration) * totalDuration | ||
) | ||
const drawRange = Math.min(visiblePoints, currentFrame + 1) | ||
material.visible = true | ||
geometry.setDrawRange(0, drawRange) | ||
} | ||
} | ||
function animate() { | ||
const hasNextFrame = currentFrame < longestGhost.ghost.frames.length - 1 | ||
if (hasNextFrame) animateDrawing() | ||
controls.enableZoom = true | ||
controls.enableRotate = true | ||
controls.enablePan = true | ||
camera.updateProjectionMatrix() | ||
controls.update() | ||
renderer.render(scene, camera) | ||
requestAnimationFrame(animate) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div>{{ formatResultTime(currentTime) }}</div> | ||
<div ref="containerRef" :class="$style.container"></div> | ||
</template> | ||
|
||
<style module lang="less"> | ||
.container { | ||
z-index: -1; | ||
width: 100%; | ||
height: 100%; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
} | ||
</style> |
Oops, something went wrong.