Repository navigation
Expand file tree
/
Copy pathdemo.ts
More file actions
94 lines (80 loc) · 3.06 KB
/
Copy pathdemo.ts
File metadata and controls
94 lines (80 loc) · 3.06 KB
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
import { BlackholeRenderer } from "./src/BlackholeRenderer";
const canvas = document.getElementById("canvas") as HTMLCanvasElement;
const params = new URLSearchParams(window.location.search);
const quality = (params.get("quality") as "low" | "medium" | "high") || "medium";
const renderer = new BlackholeRenderer({
canvas,
quality,
cameraDistance: 10,
fieldOfView: 90,
enableOrbit: true,
enableControls: false, // 默认关闭手动控制
mouseSensitivity: 0.002,
touchSensitivity: 0.003,
enableZoom: true,
minDistance: 2.1,
maxDistance: 50,
showAccretionDisk: true,
useDiskTexture: true,
enableLorentzTransform: true,
enableDopplerShift: true,
enableBeaming: true,
bloomStrength: 0.5,
bloomRadius: 0.3,
bloomThreshold: 0.8,
backgroundTextureUrl: "/assets/milkyway.jpg",
starTextureUrl: "/assets/star_noise.png",
diskTextureUrl: "/assets/accretion_disk.png",
});
renderer.start();
let frames = 0;
let lastTime = performance.now();
const fpsEl = document.getElementById("fps");
function updateFPS() {
frames++;
const now = performance.now();
if (now - lastTime >= 1000) {
if (fpsEl) fpsEl.textContent = `${frames} FPS`;
frames = 0;
lastTime = now;
}
requestAnimationFrame(updateFPS);
}
updateFPS();
const orbitToggle = document.getElementById("orbitToggle") as HTMLInputElement;
const controlsToggle = document.getElementById("controlsToggle") as HTMLInputElement;
const diskCheckbox = document.getElementById("disk") as HTMLInputElement;
const dopplerCheckbox = document.getElementById("doppler") as HTMLInputElement;
const beamingCheckbox = document.getElementById("beaming") as HTMLInputElement;
const lorentzCheckbox = document.getElementById("lorentz") as HTMLInputElement;
const distanceSlider = document.getElementById("distance") as HTMLInputElement;
const mouseSensitivitySlider = document.getElementById("mouseSensitivity") as HTMLInputElement;
orbitToggle.addEventListener("change", () => {
renderer.setConfig({ enableOrbit: orbitToggle.checked });
});
controlsToggle.addEventListener("change", () => {
renderer.setConfig({ enableControls: controlsToggle.checked });
// 当启用手动控制时,自动禁用轨道运动
if (controlsToggle.checked && orbitToggle.checked) {
orbitToggle.checked = false;
renderer.setConfig({ enableOrbit: false });
}
});
diskCheckbox.addEventListener("change", () => {
renderer.setConfig({ showAccretionDisk: diskCheckbox.checked });
});
dopplerCheckbox.addEventListener("change", () => {
renderer.setConfig({ enableDopplerShift: dopplerCheckbox.checked });
});
beamingCheckbox.addEventListener("change", () => {
renderer.setConfig({ enableBeaming: beamingCheckbox.checked });
});
lorentzCheckbox.addEventListener("change", () => {
renderer.setConfig({ enableLorentzTransform: lorentzCheckbox.checked });
});
distanceSlider.addEventListener("input", () => {
renderer.setConfig({ cameraDistance: parseFloat(distanceSlider.value) });
});
mouseSensitivitySlider.addEventListener("input", () => {
renderer.setConfig({ mouseSensitivity: parseFloat(mouseSensitivitySlider.value) });
});