Skip to content

Commit 4910fa2

Browse files
Merge pull request #273 from COS301-SE-2024/stable
Stable
2 parents c884bf5 + 8d7ac67 commit 4910fa2

File tree

3 files changed

+54
-157
lines changed

3 files changed

+54
-157
lines changed

src/src/lib/components/common/SideBar.svelte

Lines changed: 0 additions & 156 deletions
This file was deleted.

src/src/lib/components/lessons/lesson/Environment.svelte

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import { Canvas } from '@threlte/core';
33
import Scene from './Scene.svelte';
44
import { onMount } from 'svelte';
5+
import { useProgress } from '@threlte/extras';
6+
import { derived } from 'svelte/store';
57
68
let selectedObject = '';
7-
89
export let role: string;
910
export let materials: { type: boolean; file_path: string; title: string }[] = [];
1011
@@ -17,6 +18,12 @@
1718
selectedObject = materials.find((material) => material.type === true)?.file_path || '';
1819
}
1920
});
21+
22+
// Use the `useProgress` hook to track loading state
23+
const { progress } = useProgress();
24+
25+
// A derived store to track if the loading is complete
26+
const isLoading = derived(progress, ($progress) => $progress < 1);
2027
</script>
2128

2229
<div
@@ -33,6 +40,12 @@
3340
</select>
3441
</div>
3542

43+
{#if $isLoading}
44+
<div class="loading-overlay">
45+
Loading 3D model... {$progress * 100}%
46+
</div>
47+
{/if}
48+
3649
<Canvas>
3750
<Scene {selectedObject} {role} />
3851
</Canvas>
@@ -48,4 +61,19 @@
4861
padding: 10px;
4962
border-radius: 5px;
5063
}
64+
65+
.loading-overlay {
66+
position: absolute;
67+
top: 0;
68+
left: 0;
69+
width: 100%;
70+
height: 100%;
71+
display: flex;
72+
justify-content: center;
73+
align-items: center;
74+
background-color: rgba(0, 0, 0, 0.5);
75+
color: white;
76+
font-size: 1.5rem;
77+
z-index: 2000;
78+
}
5179
</style>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
let speechSynthesis: SpeechSynthesis;
2+
let speechRate = 1.8;
3+
4+
if (typeof window !== 'undefined') {
5+
speechSynthesis = window.speechSynthesis;
6+
}
7+
8+
export function speak(text: string): void {
9+
if (!speechSynthesis) return;
10+
speechSynthesis.cancel();
11+
12+
const utterance = new SpeechSynthesisUtterance(text);
13+
utterance.rate = speechRate;
14+
speechSynthesis.speak(utterance);
15+
}
16+
17+
export function setRate(rate: number): void {
18+
speechRate = rate;
19+
}
20+
21+
export function cancel(): void {
22+
if (speechSynthesis) {
23+
speechSynthesis.cancel();
24+
}
25+
}

0 commit comments

Comments
 (0)