Skip to content

Commit 98e1792

Browse files
committed
chunk loading like in rlcraft
1 parent d026ac9 commit 98e1792

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/scripts/world/ChunkManager.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { BufferGeometry, BufferAttribute, Mesh } from 'three'
2+
import { TWEEN } from 'three/examples/jsm/libs/tween.module.min.js'
23
import vec3 from 'vec3'
34

45
class ChunkManager {
56
constructor (game) {
67
this.game = game
78
this.cellMesh = new Map()
9+
setInterval(() => {
10+
TWEEN.update()
11+
})
812
}
913

1014
addChunk (cellId, vert) {
@@ -13,19 +17,32 @@ class ChunkManager {
1317
geometry.setAttribute('normal', new BufferAttribute(new Float32Array(vert.normals), 3))
1418
geometry.setAttribute('uv', new BufferAttribute(new Float32Array(vert.uvs), 2))
1519
geometry.setAttribute('color', new BufferAttribute(new Float32Array(vert.colors), 3))
16-
geometry.matrixAutoUpdate = false
20+
geometry.matrixAutoUpdate = true
1721

1822
const mesh = this.cellMesh.get(cellId)
1923
if (mesh === undefined) {
2024
const newMesh = new Mesh(geometry, this.game.world.material)
21-
newMesh.matrixAutoUpdate = false
25+
newMesh.matrixAutoUpdate = true
2226
newMesh.frustumCulled = false
2327
newMesh.onAfterRender = () => {
2428
newMesh.frustumCulled = true
2529
newMesh.onAfterRender = function () {}
2630
}
2731
this.cellMesh.set(cellId, newMesh)
2832
this.game.scene.add(newMesh)
33+
newMesh.position.y = -256
34+
35+
const to = {
36+
y: 0
37+
}
38+
new TWEEN.Tween(newMesh.position)
39+
.to(to, 2000)
40+
.easing(TWEEN.Easing.Quadratic.Out)
41+
.onComplete(() => {
42+
newMesh.matrixAutoUpdate = true
43+
newMesh.geometry.matrixAutoUpdate = true
44+
})
45+
.start()
2946
if (this.game.world.lastPlayerChunk !== null) {
3047
this.updateRenderOrder(JSON.parse(this.game.world.lastPlayerChunk))
3148
}

0 commit comments

Comments
 (0)