@@ -20,6 +20,8 @@ let renderer,
2020 scene ,
2121 controls ;
2222
23+ const lights = { key : undefined , fill : undefined , rim : undefined } ;
24+
2325function frameObject ( object , camera , controls , fitOffset = 1.2 ) {
2426 const box = new THREE . Box3 ( ) . setFromObject ( object ) ;
2527 const size = box . getSize ( new THREE . Vector3 ( ) ) ;
@@ -96,15 +98,6 @@ function setupPostProcessing({ strength, radius, threshold }) {
9698 // composer.addPass(outputPass);
9799}
98100
99- /**
100- * Setup initial camera position & orbit controls.
101- *
102- * @param {Object } options - Configuration object for the initial camera position.
103- * @param {number } options.x - The x-coordinate of the camera position.
104- * @param {number } options.y - The y-coordinate of the camera position.
105- * @param {number } options.z - The z-coordinate of the camera position.
106- * @param {number } options.fov - The field of view of the camera
107- */
108101function setupCameraAndControls ( ) {
109102 const aspect = container . clientWidth / container . clientHeight ;
110103 const frustumSize = 100 ;
@@ -126,31 +119,23 @@ function setupCameraAndControls() {
126119 // controls.enableDamping = true;
127120}
128121
129- /**
130- * Setup the initial spotlight position.
131- *
132- * @param {Object } options - Configuration object for the initial spotlight position.
133- * @param {number } options.x - The x-coordinate of the spotlight position.
134- * @param {number } options.y - The y-coordinate of the spotlight position.
135- * @param {number } options.z - The z-coordinate of the spotlight position.
136- */
137- function setupScene ( { x, y, z } ) {
122+ function setupScene ( ) {
138123 scene = new THREE . Scene ( ) ;
139124
140125 // Slight ambient so shadows aren’t pure black
141126 scene . add ( new THREE . AmbientLight ( 0xffffff , 0.25 ) ) ;
142127
143- const key = new THREE . DirectionalLight ( 0xffffff , 1.2 ) ;
144- key . position . set ( 2 , 3 , 4 ) ;
145- scene . add ( key ) ;
128+ lights . key = new THREE . DirectionalLight ( 0xffffff , 1.2 ) ;
129+ lights . key . position . set ( 2 , 3 , 4 ) ;
130+ scene . add ( lights . key ) ;
146131
147- const fill = new THREE . DirectionalLight ( 0xffffff , 0.6 ) ;
148- fill . position . set ( - 3 , 1 , 2 ) ;
149- scene . add ( fill ) ;
132+ lights . fill = new THREE . DirectionalLight ( 0xffffff , 0.6 ) ;
133+ lights . fill . position . set ( - 3 , 1 , 2 ) ;
134+ scene . add ( lights . fill ) ;
150135
151- const rim = new THREE . DirectionalLight ( 0xffffff , 0.9 ) ;
152- rim . position . set ( 0 , 3 , - 4 ) ;
153- scene . add ( rim ) ;
136+ lights . rim = new THREE . DirectionalLight ( 0xffffff , 0.9 ) ;
137+ lights . rim . position . set ( 0 , 3 , - 4 ) ;
138+ scene . add ( lights . rim ) ;
154139}
155140
156141/**
@@ -212,45 +197,34 @@ function animate() {
212197
213198function setupGUI ( initialState ) {
214199 const gui = new GUI ( ) ;
215- // const cameraFolder = gui.addFolder("Camera");
216- // const lightingFolder = gui.addFolder("Lighting");
217- // const meshFolder = gui.addFolder("Mesh");
218200 const bloomFolder = gui . addFolder ( "Bloom" ) ;
219- const { lightPos, bloomPass } = initialState ;
220- const set = ( target , key ) => ( value ) => { target [ key ] = Number ( value ) ; } ;
201+ const { bloomPass } = initialState ;
221202
222203 // gui.onChange((event) => {
223204 // console.log("Saving: %O", gui.save());
224205 // });
225206
226- // meshFolder.addColor(initialState.mesh, "color").onChange(console.log);
227- // lightingFolder.add(lightPos, "x", -500, 500, 1).onChange(set(spotLight.position, "x"));
228- // lightingFolder.add(lightPos, "y", -500, 500, 1).onChange(set(spotLight.position, "y"));
229- // lightingFolder.add(lightPos, "z", -500, 500, 1).onChange(set(spotLight.position, "z"));
230-
231- bloomFolder . add ( bloomPass , "radius" , 0 , 1 , 0.1 ) . onChange ( set ( bloomPass , "radius" ) ) ;
232- bloomFolder . add ( bloomPass , "strength" , 0 , 3 , 0.1 ) . onChange ( set ( bloomPass , "strength" ) ) ;
233- bloomFolder . add ( bloomPass , "threshold" , 0 , 1 , 0.1 ) . onChange ( set ( bloomPass , "threshold" ) ) ;
207+ bloomFolder . add ( bloomPass , "radius" , 0 , 1 , 0.1 ) . onChange ( v => {
208+ bloomPass . radius = Number ( v ) ;
209+ } ) ;
210+ bloomFolder . add ( bloomPass , "strength" , 0 , 3 , 0.1 ) . onChange ( v => {
211+ bloomPass . strength = Number ( v ) ;
212+ } ) ;
213+ bloomFolder . add ( bloomPass , "threshold" , 0 , 1 , 0.1 ) . onChange ( v => {
214+ bloomPass . threshold = Number ( v ) ;
215+ } ) ;
234216}
235217
236218function init ( ) {
237219 const initialState = {
238- // mesh: {
239- // color: "#ab98fc"
240- // },
241- lightPos : {
242- x : 20 ,
243- y : 50 ,
244- z : 200
245- } ,
246220 bloomPass : {
247221 strength : 1 ,
248222 radius : .5 ,
249223 threshold : .5
250224 }
251225 } ;
252226 setupRenderer ( ) ;
253- setupScene ( initialState . lightPos ) ;
227+ setupScene ( ) ;
254228 setupCameraAndControls ( ) ;
255229 setupPostProcessing ( initialState . bloomPass ) ;
256230 setupGUI ( initialState ) ;
0 commit comments