Skip to content

Commit 239eae3

Browse files
committed
chore: dynamic import lil-gui
1 parent 4e13df7 commit 239eae3

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
"svelte": "^5.35.5",
1818
"svelte-check": "^4.2.2",
1919
"typescript": "~5.8.3",
20-
"vite": "^7.0.4"
20+
"vite": "^7.0.4",
21+
"lil-gui": "^0.20.0"
2122
},
2223
"dependencies": {
2324
"@tailwindcss/vite": "^4.1.11",
2425
"gsap": "^3.13.0",
25-
"lil-gui": "^0.20.0",
2626
"tailwindcss": "^4.1.11",
2727
"three": "^0.179.1"
2828
}

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/VideoOverlay.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<button
1313
class="
1414
close-button
15-
absolute top-2 right-2 w-6 h-6 rounded-full bg-white text-[var(--bgColor)]
15+
absolute top-2 right-2 w-6 h-6 rounded-full bg-white text-[var(--textColor)]
1616
flex items-center justify-center
1717
text-xl font-bold cursor-pointer shadow-lg
1818
transition-transform duration-200 ease-in-out hover:scale-110

src/lib/BookScene.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as THREE from 'three';
2-
import * as dat from 'lil-gui';
32
import { config, assets, palette } from '../config';
43
import gsap from 'gsap';
54
import { IconManager } from './IconManager';
@@ -25,7 +24,6 @@ export class BookScene {
2524
private decorationPairs: DecorationPair[][] = [];
2625
private ambientLight: THREE.AmbientLight = new THREE.AmbientLight(0xffffff, 1.8);
2726
private directionalLights: THREE.DirectionalLight[] = [];
28-
private gui: dat.GUI;
2927

3028
private videoOverlayManager: VideoOverlayManager;
3129
private iconManager: IconManager;
@@ -76,7 +74,7 @@ export class BookScene {
7674
this.container.appendChild(this.renderer.domElement);
7775

7876
this.setUpLight();
79-
// this.setupLightControls();
77+
this.setupLightControls();
8078

8179
this.handleResize(); //FIXME: 现在这个 handleResize 不可以放在后面执行
8280
window.addEventListener('resize', () => this.handleResize());
@@ -107,26 +105,31 @@ export class BookScene {
107105
}
108106

109107
private setupLightControls() {
110-
this.gui = new dat.GUI({ autoPlace: true });
111-
const lightFolder = this.gui.addFolder('Lighting');
108+
if (!isDev()) return;
112109

113-
const ambientFolder = lightFolder.addFolder('Ambient Light');
114-
ambientFolder.addColor({ color: '#ffffff' }, 'color').onChange((value) => {
115-
this.ambientLight.color.set(value);
116-
});
117-
ambientFolder.add(this.ambientLight, 'intensity', 0, 4, 0.01);
110+
import('lil-gui').then((dat) => {
111+
const gui = new dat.GUI({ autoPlace: true });
112+
const lightFolder = gui.addFolder('Lighting');
118113

119-
const directionalFolder = lightFolder.addFolder('Directional Lights');
120-
this.directionalLights.forEach((light, index) => {
121-
const folder = directionalFolder.addFolder(`Light ${ index + 1 }`);
122-
folder.addColor({ color: '#ffffff' }, 'color').onChange((value) => {
123-
light.color.set(value);
114+
const ambientFolder = lightFolder.addFolder('Ambient Light');
115+
ambientFolder.addColor({ color: '#ffffff' }, 'color').onChange((value) => {
116+
this.ambientLight.color.set(value);
117+
});
118+
ambientFolder.add(this.ambientLight, 'intensity', 0, 4, 0.01);
119+
120+
const directionalFolder = lightFolder.addFolder('Directional Lights');
121+
this.directionalLights.forEach((light, index) => {
122+
const folder = directionalFolder.addFolder(`Light ${ index + 1 }`);
123+
folder.addColor({ color: '#ffffff' }, 'color').onChange((value) => {
124+
light.color.set(value);
125+
});
126+
folder.add(light, 'intensity', 0, 4, 0.01);
127+
folder.add(light.position, 'x', -10, 50, 0.1);
128+
folder.add(light.position, 'y', -10, 50, 0.1);
129+
folder.add(light.position, 'z', -10, 50, 0.1);
124130
});
125-
folder.add(light, 'intensity', 0, 4, 0.01);
126-
folder.add(light.position, 'x', -10, 50, 0.1);
127-
folder.add(light.position, 'y', -10, 50, 0.1);
128-
folder.add(light.position, 'z', -10, 50, 0.1);
129131
});
132+
130133
}
131134

132135

@@ -355,8 +358,6 @@ export class BookScene {
355358
this.container.removeChild(this.renderer.domElement);
356359
}
357360

358-
this.gui?.destroy();
359-
360361
(this.scene as any) = null;
361362
(this.camera as any) = null;
362363
}

0 commit comments

Comments
 (0)