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

Stable #273

Merged
merged 6 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 0 additions & 156 deletions src/src/lib/components/common/SideBar.svelte

This file was deleted.

30 changes: 29 additions & 1 deletion src/src/lib/components/lessons/lesson/Environment.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import { Canvas } from '@threlte/core';
import Scene from './Scene.svelte';
import { onMount } from 'svelte';
import { useProgress } from '@threlte/extras';
import { derived } from 'svelte/store';

let selectedObject = '';

export let role: string;
export let materials: { type: boolean; file_path: string; title: string }[] = [];

Expand All @@ -17,6 +18,12 @@
selectedObject = materials.find((material) => material.type === true)?.file_path || '';
}
});

// Use the `useProgress` hook to track loading state
const { progress } = useProgress();

// A derived store to track if the loading is complete
const isLoading = derived(progress, ($progress) => $progress < 1);
</script>

<div
Expand All @@ -33,6 +40,12 @@
</select>
</div>

{#if $isLoading}
<div class="loading-overlay">
Loading 3D model... {$progress * 100}%
</div>
{/if}

<Canvas>
<Scene {selectedObject} {role} />
</Canvas>
Expand All @@ -48,4 +61,19 @@
padding: 10px;
border-radius: 5px;
}

.loading-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: rgba(0, 0, 0, 0.5);
color: white;
font-size: 1.5rem;
z-index: 2000;
}
</style>
25 changes: 25 additions & 0 deletions src/src/lib/components/webspeech/speechSynthesis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
let speechSynthesis: SpeechSynthesis;
let speechRate = 1.8;

if (typeof window !== 'undefined') {
speechSynthesis = window.speechSynthesis;
}

export function speak(text: string): void {
if (!speechSynthesis) return;
speechSynthesis.cancel();

const utterance = new SpeechSynthesisUtterance(text);
utterance.rate = speechRate;
speechSynthesis.speak(utterance);
}

export function setRate(rate: number): void {
speechRate = rate;
}

export function cancel(): void {
if (speechSynthesis) {
speechSynthesis.cancel();
}
}
Loading