Skip to content

Commit

Permalink
Loading screen percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleGough committed Jul 28, 2023
1 parent 1468026 commit 2d31acb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
11 changes: 8 additions & 3 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ <h1>Solar System Model</h1>
<span id="createdBy">created by</span>
<span id="name">Kyle Gough</span>
</p>
<div id="loader-progress">
<div id="loader-text">
Loading...
</div>
<div id="loader-percentage">
0%
</div>
</div>
<div id="loader">
<div id="loader-circle">
<svg
Expand All @@ -37,9 +45,6 @@ <h1>Solar System Model</h1>
</svg>
</div>
</div>
<div id="loader-text">
Loading...
</div>
</div>
</div>
<canvas class="webgl"></canvas>
Expand Down
13 changes: 10 additions & 3 deletions src/setup/textures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { onLoaded } from "./loading";
let textureCount = 0;
let texturesLoaded = 0;
const textureLoader = new THREE.TextureLoader();
const textureLoadSet = new Set<string>();

export const loadTexture = (path: string) => {
textureLoadSet.add(path);
return textureLoader.load(path, () => {
textureLoadSet.delete(path);
texturesLoaded++;

const percentageContainer = document.getElementById(
"loader-percentage"
) as HTMLElement;
percentageContainer.textContent = getProgress();

if (texturesLoaded === textureCount) {
onLoaded();
}
Expand All @@ -21,3 +23,8 @@ export const loadTexture = (path: string) => {
export const setTextureCount = (n: number) => {
textureCount = n;
};

const getProgress = (): string => {
const percentage = (100 * texturesLoaded) / textureCount;
return `${percentage.toFixed(0)}%`;
};
17 changes: 10 additions & 7 deletions src/styles/loading-screen.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$loader-size: 50px;
$loader-size: 75px;

#loading {
position: fixed;
Expand Down Expand Up @@ -47,18 +47,21 @@ $loader-size: 50px;
animation: fadeIn 2s ease-in-out 2.75s 1 forwards;

svg {
transform: scale(1.62);
transform: scale(3.5);
animation: loading 2s ease-in-out 4.75s infinite;
}
}
}

#loader-text {
margin-top: 1rem;
#loader-progress {
display: flex;
justify-content: center;
justify-content: space-between;
margin-top: 1rem;
font-weight: 100;
font-size: 0.8rem;
opacity: 0;
animation: fadeIn 2s ease-in-out 3.5s 1 forwards;

div {
opacity: 0;
animation: fadeIn 2s ease-in-out 3.5s 1 forwards;
}
}

0 comments on commit 2d31acb

Please sign in to comment.