@@ -69,6 +69,9 @@ export class WorldRendererThree extends WorldRendererCommon {
6969 }
7070 fountains : Fountain [ ] = [ ]
7171
72+ private currentPosTween ?: tweenJs . Tween < THREE . Vector3 >
73+ private currentRotTween ?: tweenJs . Tween < { pitch : number , yaw : number } >
74+
7275 get tilesRendered ( ) {
7376 return Object . values ( this . sectionObjects ) . reduce ( ( acc , obj ) => acc + ( obj as any ) . tilesCount , 0 )
7477 }
@@ -150,7 +153,7 @@ export class WorldRendererThree extends WorldRendererCommon {
150153 override watchReactivePlayerState ( ) {
151154 super . watchReactivePlayerState ( )
152155 this . onReactivePlayerStateUpdated ( 'inWater' , ( value ) => {
153- this . scene . fog = value ? new THREE . Fog ( 0x00_00_ff , 0.1 , this . displayOptions . playerState . reactive . waterBreathing ? 100 : 20 ) : null
156+ this . scene . fog = value ? new THREE . Fog ( 0x00_00_ff , 0.1 , this . playerStateReactive . waterBreathing ? 100 : 20 ) : null
154157 } )
155158 this . onReactivePlayerStateUpdated ( 'ambientLight' , ( value ) => {
156159 if ( ! value ) return
@@ -238,7 +241,7 @@ export class WorldRendererThree extends WorldRendererCommon {
238241 }
239242
240243 getItemRenderData ( item : Record < string , any > , specificProps : ItemSpecificContextProperties ) {
241- return getItemUv ( item , specificProps , this . resourcesManager , this . playerState )
244+ return getItemUv ( item , specificProps , this . resourcesManager , this . playerStateReactive )
242245 }
243246
244247 async demoModel ( ) {
@@ -430,7 +433,7 @@ export class WorldRendererThree extends WorldRendererCommon {
430433 }
431434
432435 setFirstPersonCamera ( pos : Vec3 | null , yaw : number , pitch : number ) {
433- const yOffset = this . displayOptions . playerState . reactive . eyeHeight
436+ const yOffset = this . playerStateReactive . eyeHeight
434437
435438 this . updateCamera ( pos ?. offset ( 0 , yOffset , 0 ) ?? null , yaw , pitch )
436439 this . media . tryIntersectMedia ( )
@@ -448,10 +451,28 @@ export class WorldRendererThree extends WorldRendererCommon {
448451 pos . y -= this . camera . position . y // Fix Y position of camera in world
449452 }
450453
451- new tweenJs . Tween ( this . cameraObject . position ) . to ( { x : pos . x , y : pos . y , z : pos . z } , 50 ) . start ( )
454+ this . currentPosTween ?. stop ( )
455+ this . currentPosTween = new tweenJs . Tween ( this . cameraObject . position ) . to ( { x : pos . x , y : pos . y , z : pos . z } , this . playerStateUtils . isSpectatingEntity ( ) ? 150 : 50 ) . start ( )
452456 // this.freeFlyState.position = pos
453457 }
454- this . cameraShake . setBaseRotation ( pitch , yaw )
458+
459+ if ( this . playerStateUtils . isSpectatingEntity ( ) ) {
460+ const rotation = this . cameraShake . getBaseRotation ( )
461+ // wrap in the correct direction
462+ let yawOffset = 0
463+ const halfPi = Math . PI / 2
464+ if ( rotation . yaw < halfPi && yaw > Math . PI + halfPi ) {
465+ yawOffset = - Math . PI * 2
466+ } else if ( yaw < halfPi && rotation . yaw > Math . PI + halfPi ) {
467+ yawOffset = Math . PI * 2
468+ }
469+ this . currentRotTween ?. stop ( )
470+ this . currentRotTween = new tweenJs . Tween ( rotation ) . to ( { pitch, yaw : yaw + yawOffset } , 100 )
471+ . onUpdate ( params => this . cameraShake . setBaseRotation ( params . pitch , params . yaw - yawOffset ) ) . start ( )
472+ } else {
473+ this . currentRotTween ?. stop ( )
474+ this . cameraShake . setBaseRotation ( pitch , yaw )
475+ }
455476 }
456477
457478 debugChunksVisibilityOverride ( ) {
@@ -508,7 +529,7 @@ export class WorldRendererThree extends WorldRendererCommon {
508529 const cam = this . cameraGroupVr instanceof THREE . Group ? this . cameraGroupVr . children . find ( child => child instanceof THREE . PerspectiveCamera ) as THREE . PerspectiveCamera : this . camera
509530 this . renderer . render ( this . scene , cam )
510531
511- if ( this . displayOptions . inWorldRenderingConfig . showHand && this . playerState . reactive . gameMode !== 'spectator' /* && !this.freeFlyMode */ && ! this . renderer . xr . isPresenting ) {
532+ if ( this . displayOptions . inWorldRenderingConfig . showHand && this . playerStateReactive . gameMode !== 'spectator' /* && !this.freeFlyMode */ && ! this . renderer . xr . isPresenting ) {
512533 this . holdingBlock . render ( this . camera , this . renderer , this . ambientLight , this . directionalLight )
513534 this . holdingBlockLeft . render ( this . camera , this . renderer , this . ambientLight , this . directionalLight )
514535 }
0 commit comments