Skip to content

Commit 491b035

Browse files
committed
frustum test checkbox GUI
1 parent 0b097b1 commit 491b035

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

src/scripts/Setup.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ function Setup (game) {
6363
])
6464
const gui = new dat.GUI()
6565
game.params = {
66-
chunkdist: 4
66+
chunkdist: 4,
67+
frustumtest: false
6768
}
6869
game.distanceBasedFog.updateDistance(game.params.chunkdist)
6970
gui
@@ -103,6 +104,10 @@ function Setup (game) {
103104
.add(game.world.material, 'wireframe')
104105
.name('Wireframe')
105106
.listen()
107+
gui
108+
.add(game.params, 'frustumtest')
109+
.name('Frustum test')
110+
.listen()
106111
game.eh = new EventHandler(game)
107112
}
108113

src/scripts/index.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,24 +123,26 @@ class Game {
123123
this.bb.startDigging(time)
124124
})
125125
setInterval(() => {
126-
const frustum = new Frustum()
127-
const cameraViewProjectionMatrix = new Matrix4()
126+
if (this.params.frustumtest) {
127+
const frustum = new Frustum()
128+
const cameraViewProjectionMatrix = new Matrix4()
128129

129-
this.camera.updateMatrixWorld()
130-
this.camera.matrixWorldInverse.copy(this.camera.matrixWorld).invert()
131-
cameraViewProjectionMatrix.multiplyMatrices(this.camera.projectionMatrix, this.camera.matrixWorldInverse)
132-
frustum.setFromProjectionMatrix(cameraViewProjectionMatrix)
130+
this.camera.updateMatrixWorld()
131+
this.camera.matrixWorldInverse.copy(this.camera.matrixWorld).invert()
132+
cameraViewProjectionMatrix.multiplyMatrices(this.camera.projectionMatrix, this.camera.matrixWorldInverse)
133+
frustum.setFromProjectionMatrix(cameraViewProjectionMatrix)
133134

134-
this.scene.traverse((node) => {
135-
if (node instanceof Mesh) {
136-
if (frustum.intersectsObject(node)) {
137-
node.visible = true
138-
} else {
139-
node.visible = false
135+
this.scene.traverse((node) => {
136+
if (node instanceof Mesh) {
137+
if (frustum.intersectsObject(node)) {
138+
node.visible = true
139+
} else {
140+
node.visible = false
141+
}
140142
}
141-
}
142-
})
143-
}, 1000)
143+
})
144+
}
145+
}, 2000)
144146
return this.animate()
145147
}
146148

src/scripts/world/chunk.worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class TerrainManager {
8686
let nearestDistance = -1
8787
let isNearest = false
8888
for (const chunkId in this.chunkNeedsUpdate) {
89-
const pos = chunkTerrain.strToVec(chunkId)
89+
const pos = this.chunkTerrain.strToVec(chunkId)
9090
const dist = this.distance(chunkId)
9191
if (
9292
(nearestDistance === -1 || nearestDistance > dist) &&

0 commit comments

Comments
 (0)