@@ -88,7 +88,7 @@ export class WorldRendererThree extends WorldRendererCommon {
88
88
89
89
this . renderer = renderer
90
90
displayOptions . rendererState . renderer = WorldRendererThree . getRendererInfo ( renderer ) ?? '...'
91
- this . starField = new StarField ( this . scene )
91
+ this . starField = new StarField ( this )
92
92
this . cursorBlock = new CursorBlock ( this )
93
93
this . holdingBlock = new HoldingBlock ( this )
94
94
this . holdingBlockLeft = new HoldingBlock ( this , true )
@@ -318,10 +318,11 @@ export class WorldRendererThree extends WorldRendererCommon {
318
318
section . renderOrder = 500 - chunkDistance
319
319
}
320
320
321
- updateViewerPosition ( pos : Vec3 ) : void {
322
- this . viewerPosition = pos
323
- const cameraPos = this . cameraObject . position . toArray ( ) . map ( x => Math . floor ( x / 16 ) ) as [ number , number , number ]
324
- this . cameraSectionPos = new Vec3 ( ...cameraPos )
321
+ override updateViewerPosition ( pos : Vec3 ) : void {
322
+ this . viewerChunkPosition = pos
323
+ }
324
+
325
+ cameraSectionPositionUpdate ( ) {
325
326
// eslint-disable-next-line guard-for-in
326
327
for ( const key in this . sectionObjects ) {
327
328
const value = this . sectionObjects [ key ]
@@ -447,11 +448,35 @@ export class WorldRendererThree extends WorldRendererCommon {
447
448
return tex
448
449
}
449
450
451
+ getCameraPosition ( ) {
452
+ const worldPos = new THREE . Vector3 ( )
453
+ this . camera . getWorldPosition ( worldPos )
454
+ return worldPos
455
+ }
456
+
457
+ getWorldCameraPosition ( ) {
458
+ const pos = this . getCameraPosition ( )
459
+ return new Vec3 (
460
+ Math . floor ( pos . x / 16 ) ,
461
+ Math . floor ( pos . y / 16 ) ,
462
+ Math . floor ( pos . z / 16 )
463
+ )
464
+ }
465
+
466
+ updateCameraSectionPos ( ) {
467
+ const newSectionPos = this . getWorldCameraPosition ( )
468
+ if ( ! this . cameraSectionPos . equals ( newSectionPos ) ) {
469
+ this . cameraSectionPos = newSectionPos
470
+ this . cameraSectionPositionUpdate ( )
471
+ }
472
+ }
473
+
450
474
setFirstPersonCamera ( pos : Vec3 | null , yaw : number , pitch : number ) {
451
475
const yOffset = this . playerStateReactive . eyeHeight
452
476
453
477
this . updateCamera ( pos ?. offset ( 0 , yOffset , 0 ) ?? null , yaw , pitch )
454
478
this . media . tryIntersectMedia ( )
479
+ this . updateCameraSectionPos ( )
455
480
}
456
481
457
482
getThirdPersonCamera ( pos : THREE . Vector3 | null , yaw : number , pitch : number ) {
@@ -636,6 +661,8 @@ export class WorldRendererThree extends WorldRendererCommon {
636
661
}
637
662
}
638
663
}
664
+
665
+ this . updateCameraSectionPos ( )
639
666
}
640
667
641
668
debugChunksVisibilityOverride ( ) {
@@ -988,7 +1015,9 @@ class StarField {
988
1015
}
989
1016
}
990
1017
991
- constructor ( private readonly scene : THREE . Scene ) {
1018
+ constructor (
1019
+ private readonly worldRenderer : WorldRendererThree
1020
+ ) {
992
1021
}
993
1022
994
1023
addToScene ( ) {
@@ -1030,11 +1059,11 @@ class StarField {
1030
1059
1031
1060
// Create points and add them to the scene
1032
1061
this . points = new THREE . Points ( geometry , material )
1033
- this . scene . add ( this . points )
1062
+ this . worldRenderer . scene . add ( this . points )
1034
1063
1035
1064
const clock = new THREE . Clock ( )
1036
1065
this . points . onBeforeRender = ( renderer , scene , camera ) => {
1037
- this . points ?. position . copy ?.( camera . position )
1066
+ this . points ?. position . copy ?.( this . worldRenderer . getCameraPosition ( ) )
1038
1067
material . uniforms . time . value = clock . getElapsedTime ( ) * speed
1039
1068
}
1040
1069
this . points . renderOrder = - 1
@@ -1044,7 +1073,7 @@ class StarField {
1044
1073
if ( this . points ) {
1045
1074
this . points . geometry . dispose ( ) ;
1046
1075
( this . points . material as THREE . Material ) . dispose ( )
1047
- this . scene . remove ( this . points )
1076
+ this . worldRenderer . scene . remove ( this . points )
1048
1077
1049
1078
this . points = undefined
1050
1079
}
0 commit comments