Skip to content

Commit 73b57c6

Browse files
committed
add smooth chunks options
1 parent ead8b58 commit 73b57c6

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

src/scripts/Setup.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ function Setup (game) {
9090
}
9191
})
9292
.listen()
93+
gui
94+
.add(game.world.chunkManager, 'smooth')
95+
.name('Smooth chunks')
96+
.listen()
9397
game.eh = new EventHandler(game)
9498
}
9599

src/scripts/world/ChunkManager.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class ChunkManager {
66
constructor (game) {
77
this.game = game
88
this.cellMesh = new Map()
9+
this.smooth = false
910
}
1011

1112
addChunk (cellId, vert) {
@@ -27,19 +28,20 @@ class ChunkManager {
2728
}
2829
this.cellMesh.set(cellId, newMesh)
2930
this.game.scene.add(newMesh)
30-
newMesh.position.y = -32
31-
32-
const to = {
33-
y: 0
31+
if (this.smooth) {
32+
newMesh.position.y = -32
33+
const to = {
34+
y: 0
35+
}
36+
new TWEEN.Tween(newMesh.position)
37+
.to(to, 1000)
38+
.easing(TWEEN.Easing.Quadratic.Out)
39+
.onComplete(() => {
40+
newMesh.matrixAutoUpdate = true
41+
newMesh.geometry.matrixAutoUpdate = true
42+
})
43+
.start()
3444
}
35-
new TWEEN.Tween(newMesh.position)
36-
.to(to, 1000)
37-
.easing(TWEEN.Easing.Quadratic.Out)
38-
.onComplete(() => {
39-
newMesh.matrixAutoUpdate = true
40-
newMesh.geometry.matrixAutoUpdate = true
41-
})
42-
.start()
4345
if (this.game.world.lastPlayerChunk !== null) {
4446
this.updateRenderOrder(JSON.parse(this.game.world.lastPlayerChunk))
4547
}
@@ -75,7 +77,9 @@ class ChunkManager {
7577
}
7678

7779
update () {
78-
TWEEN.update()
80+
if (this.smooth) {
81+
TWEEN.update()
82+
}
7983
}
8084
}
8185
export { ChunkManager }

0 commit comments

Comments
 (0)