-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
120 lines (102 loc) · 4.39 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Superquadrics - Demo</title>
<link type="text/css" rel="stylesheet" href="./styles/main.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<div class="nav-bar">
<span class="title">Extending Three.js - Superquadrics</span>
<span class="space-fill"></span>
<span id="home-button" class="nav-item" onclick="changeView('home')" style="display: none;">Back to Overview</span>
<a href="https://hpicgs.github.io/seminar-extending-threejs-2023/" class="nav-item">About this Project</a>
<span class="nav-item" id="theme-switch"><input type="checkbox" id="theme-switch-checkbox"><label for="theme-switch-checkbox" class="theme-switch-label"><i id="theme-switch-icon" class="fas fa-moon"></i></label></span>
<a href="https://github.com/MatteoVoges/extending-three.js" class="nav-item"><i class="fa-brands fa-github"></i></a>
</div>
<div class="content">
<div class="space-fill"></div>
<div id="examples"></div>
<iframe id="viewer-frame" name="viewer-frame" src="" style="display: none;"></iframe>
<div class="space-fill"></div>
</div>
<div class="footer">© 2024 Matteo Voges</footer>
</body>
<script>
const viewerFrame = document.getElementById("viewer-frame");
const homeButton = document.getElementById("home-button");
const examplesContainer = document.getElementById("examples");
const themeSwitch = document.getElementById("theme-switch");
const themeSwitchIcon = document.getElementById("theme-switch-icon");
const themeSwitchCheckbox = document.getElementById("theme-switch-checkbox");
function applyPrimaryColor() {
const primaryColor = "rgb(" + getComputedStyle(document.documentElement).getPropertyValue("--primary-color") + ")";
for (const e of document.getElementsByClassName("lil-gui")) {
e.style.setProperty("--number-color", primaryColor);
}
}
function applyColorTheme() {
let theme;
if (themeSwitchCheckbox.checked) {
// dark theme
themeSwitchIcon.classList.remove("fa-moon");
themeSwitchIcon.classList.add("fa-sun");
theme = {"background-color": "30, 30, 30", "dark-background-color": "11, 23, 32", "text-color": "255, 255, 255", "dark-text-color": "136, 136, 136"};
themeSwitchCheckbox.checked = false;
} else {
// light theme
themeSwitchIcon.classList.remove("fa-sun");
themeSwitchIcon.classList.add("fa-moon");
theme = {"background-color": "255, 250, 240", "dark-background-color": "210, 210, 220", "text-color": "0, 0, 0", "dark-text-color": "100, 100, 100"};
themeSwitchCheckbox.checked = true;
}
// apply theme
for (const [key, value] of Object.entries(theme)) {
document.documentElement.style.setProperty("--" + key, value);
}
// change background color of renderer
if (viewerFrame.contentWindow.setBackgroundColorCallback) viewerFrame.contentWindow.setBackgroundColorCallback();
}
viewerFrame.addEventListener("load", applyPrimaryColor);
themeSwitch.addEventListener("click", applyColorTheme);
// apply theme on load
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
themeSwitchCheckbox.checked = true;
applyColorTheme();
}
function changeView(path) {
if (path === "home") {
viewerFrame.src = "";
viewerFrame.style.display = "none";
homeButton.style.display = "none";
examplesContainer.style.display = "grid";
} else {
examplesContainer.style.display = "none";
viewerFrame.src = path;
homeButton.style.display = "flex";
viewerFrame.style.display = "unset";
}
window.location.hash = path;
}
const exampleSources = {
"Playground": "playground",
"PBR - Interactive": "pbr-interactive",
"PBR - Materials": "pbr-materials",
"Vertex Shader": "vertex-shader",
"Visualization": "visualization"
}
// autogenerate examples
for (const [name, src] of Object.entries(exampleSources)) {
const example = document.createElement("div");
example.className = "example";
example.onclick = function() {changeView("examples/" + src + "/index.html")};
example.innerHTML = `
<img src="examples/${src}/preview.png" alt="${name}">
<div>${name}</div>
`;
examplesContainer.appendChild(example);
}
</script>
</html>