11import * as THREE from 'three' ;
2- import * as dat from 'lil-gui' ;
32import { config , assets , palette } from '../config' ;
43import gsap from 'gsap' ;
54import { 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