@@ -42,6 +42,7 @@ export class BookScene {
4242 private maxPixelRatio : number = / i P h o n e | i P a d | i P o d / i. test ( navigator . userAgent ) ? 3 : 2 ;
4343 private normalCameraZ : number = 6 ;
4444 private closedCameraZ : number = 4 ;
45+ private initialCameraOffset = new THREE . Vector3 ( - 1 , - 6 , - 2 ) ;
4546
4647 constructor ( container : HTMLDivElement ) {
4748 this . container = container ;
@@ -51,10 +52,9 @@ export class BookScene {
5152 this . scene . add ( this . book ) ;
5253
5354 this . camera = new THREE . PerspectiveCamera ( 45 , container . clientWidth / container . clientHeight , 0.1 , 1000 ) ;
54- // this.camera.position.set(0, 0, 6);
5555 this . camera . lookAt ( 0 , 0 , 0 ) ;
5656
57- this . renderer = new THREE . WebGLRenderer ( { antialias : true , alpha : true , logarithmicDepthBuffer : false } ) ;
57+ this . renderer = new THREE . WebGLRenderer ( { antialias : ! this . isMobile , alpha : true , logarithmicDepthBuffer : false } ) ;
5858 this . renderer . setPixelRatio ( Math . min ( window . devicePixelRatio , this . maxPixelRatio ) ) ;
5959
6060
@@ -90,13 +90,13 @@ export class BookScene {
9090 private setUpLight ( ) {
9191 this . scene . add ( this . ambientLight ) ;
9292
93- const lLight = new THREE . DirectionalLight ( 0xffffff , 0.5 ) ;
94- lLight . position . set ( - 5 , 0 , 8 ) ;
95- this . scene . add ( lLight ) ;
96- this . directionalLights . push ( lLight ) ;
93+ // const lLight = new THREE.DirectionalLight(0xffffff, 0.5);
94+ // lLight.position.set(-5, 0, 8);
95+ // this.scene.add(lLight);
96+ // this.directionalLights.push(lLight);
9797
9898 const rLight = new THREE . DirectionalLight ( 0xffffff , 0.5 ) ;
99- rLight . position . set ( 5 , 0 , 8 ) ;
99+ rLight . position . set ( 0 , 0 , 8 ) ;
100100 this . scene . add ( rLight ) ;
101101 this . directionalLights . push ( rLight ) ;
102102 }
@@ -131,6 +131,8 @@ export class BookScene {
131131
132132 for ( let i = 0 ; i < config . numPages ; i ++ ) {
133133 const page = this . _createPage ( i , textureLoader ) ;
134+ page . position . z = ( config . numPages - i ) * config . pageDepth ;
135+
134136 this . book . add ( page ) ;
135137 this . pages . push ( page ) ;
136138 }
@@ -151,28 +153,53 @@ export class BookScene {
151153 const pageRotations : number [ ] = [ ] ;
152154 const pProgress = progress / perSegment ;
153155
156+
154157 if ( progress < perSegment ) {
155158 this . camera . position . x = THREE . MathUtils . lerp ( config . pageWidth / 2 , 0 , pProgress ) ;
156159
157160 if ( this . isMobile ) {
158161 this . camera . position . z = THREE . MathUtils . lerp ( this . closedCameraZ , this . normalCameraZ , pProgress ) ;
159162 }
160163 }
164+ // if (progress < perSegment) {
165+ // const endPosition = {
166+ // x: 0,
167+ // y: this.isMobile ? this.camera.position.y : 0,
168+ // z: this.normalCameraZ
169+ // };
170+ // const startPosition = {
171+ // x: endPosition.x + this.initialCameraOffset.x,
172+ // y: endPosition.y + this.initialCameraOffset.y,
173+ // z: endPosition.z + this.initialCameraOffset.z
174+ // };
175+
176+ // this.camera.position.x = THREE.MathUtils.lerp(startPosition.x, startPosition.x, pProgress);
177+ // this.camera.position.y = THREE.MathUtils.lerp(startPosition.y, startPosition.y, pProgress);
178+ // this.camera.position.z = THREE.MathUtils.lerp(startPosition.z, startPosition.z, pProgress);
179+ // }
180+ // this.camera.lookAt(0, 0, 0);
161181
162182 this . currentPage = Math . round ( pProgress ) ;
163183
164184 for ( let i = 0 ; i < config . numPages ; i ++ ) {
165185 const page = this . pages [ i ] ;
186+
166187 const segmentStartProgress = i * perSegment ;
167188 const flipProgress = Math . max ( 0 , Math . min ( 1 , pProgress - ( segmentStartProgress ) / perSegment ) ) ;
168189 const flipRotation = - flipProgress * Math . PI ;
169-
170- page . rotation . y = i * config . rotationStep + flipRotation ;
171190 pageRotations . push ( flipRotation ) ;
172191
192+ page . rotation . y = flipRotation ;
193+ page . position . z = i < pProgress ? ( i - pProgress + 1 ) * config . pageDepth * flipProgress : ( pProgress - i ) * config . pageDepth * ( 1 - flipProgress ) ;
194+
173195 const pageStartProgress = ( i - 2 ) * perSegment ;
174196 const pageEndProgress = ( i + 2 ) * perSegment ;
175- page . visible = progress > pageStartProgress && progress < pageEndProgress ;
197+
198+ if ( progress < pageStartProgress || progress > pageEndProgress ) {
199+ page . visible = false ;
200+ continue ;
201+ }
202+ page . visible = true ;
176203
177204 const decs = this . decorationPairs [ i ] ;
178205 if ( ! decs || decs . length === 0 ) continue ;
@@ -201,6 +228,7 @@ export class BookScene {
201228
202229 this . updateIcons ( ) ;
203230
231+
204232 }
205233 private updateBgColor ( progress : number ) {
206234 const now = performance . now ( ) ;
@@ -270,6 +298,8 @@ export class BookScene {
270298
271299 private _createPage ( i : number , textureLoader : THREE . TextureLoader ) : THREE . Group {
272300 const pivot = new THREE . Group ( ) ;
301+
302+ // TODO: replace bg texture for better rounded corner
273303 const geometry = this . _createRoundedBoxGeometry ( config . pageWidth , config . pageHeight , config . pageDepth , 0.12 , 64 ) ;
274304
275305 const frontTexture = textureLoader . load ( assets . pages [ i ] ) ;
@@ -292,8 +322,8 @@ export class BookScene {
292322 bNormalTexture . repeat . set ( 0.5 , 1 ) ;
293323
294324 const fMaterialConfig = {
295- roughness : 0.35 ,
296- metalness : 0.05 ,
325+ roughness : 0.4 ,
326+ metalness : 0 ,
297327 normalMap : fNormalTexture ,
298328 normalScale : new THREE . Vector2 ( 1 , 3 )
299329 } ;
@@ -349,7 +379,7 @@ export class BookScene {
349379 transparent : true ,
350380 clippingPlanes : [
351381 new THREE . Plane ( new THREE . Vector3 ( - 1 , 0 , 0 ) , config . pageWidth - 0.015 ) ,
352- new THREE . Plane ( new THREE . Vector3 ( 1 , 0 , 0 ) , - 0.025 ) ,
382+ new THREE . Plane ( new THREE . Vector3 ( 1 , 0 , 0 ) , 0.01 ) ,
353383 new THREE . Plane ( new THREE . Vector3 ( 0 , - 1 , 0 ) , config . pageHeight / 2 ) ,
354384 new THREE . Plane ( new THREE . Vector3 ( 0 , 1 , 0 ) , config . pageHeight / 2 )
355385 ] . map ( p => p . clone ( ) )
@@ -361,7 +391,7 @@ export class BookScene {
361391 alphaTest : 0.01 ,
362392 transparent : true ,
363393 clippingPlanes : [
364- new THREE . Plane ( new THREE . Vector3 ( - 1 , 0 , 0 ) , - 0.025 ) ,
394+ new THREE . Plane ( new THREE . Vector3 ( - 1 , 0 , 0 ) , 0.01 ) ,
365395 new THREE . Plane ( new THREE . Vector3 ( 1 , 0 , 0 ) , config . pageWidth - 0.015 ) ,
366396 new THREE . Plane ( new THREE . Vector3 ( 0 , - 1 , 0 ) , config . pageHeight / 2 ) ,
367397 new THREE . Plane ( new THREE . Vector3 ( 0 , 1 , 0 ) , config . pageHeight / 2 )
0 commit comments