Skip to content

Commit 0b097b1

Browse files
committed
camera frustrum test
1 parent b5fd082 commit 0b097b1

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

src/scripts/Setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Stats from 'three/examples/jsm/libs/stats.module.js'
22
import * as dat from 'three/examples/jsm/libs/dat.gui.module.js'
3-
import { WebGLRenderer, Scene, PerspectiveCamera, AmbientLight } from 'three'
3+
import { WebGLRenderer, Scene, PerspectiveCamera, AmbientLight, Mesh, BoxGeometry, MeshBasicMaterial } from 'three'
44
import { DistanceBasedFog } from './rendering/DistanceBasedFog.js'
55
import { UrlParams } from './UrlParams.js'
66
import { gpuInfo } from './additional/gpuInfo.js'

src/scripts/index.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Color } from 'three'
1+
import { Color, Mesh, Matrix4, Frustum } from 'three'
22
import { TWEEN } from 'three/examples/jsm/libs/tween.module.min.js'
33
import swal from 'sweetalert'
44
import { AssetLoader } from './AssetLoader.js'
@@ -13,7 +13,7 @@ class Game {
1313
console.log('Running in development mode')
1414
}
1515
this.fov = {
16-
normal: 60,
16+
normal: 70,
1717
sprint: 80
1818
}
1919
this.al = new AssetLoader()
@@ -122,6 +122,25 @@ class Game {
122122
this.socket.on('digTime', (time) => {
123123
this.bb.startDigging(time)
124124
})
125+
setInterval(() => {
126+
const frustum = new Frustum()
127+
const cameraViewProjectionMatrix = new Matrix4()
128+
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)
133+
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
140+
}
141+
}
142+
})
143+
}, 1000)
125144
return this.animate()
126145
}
127146

@@ -167,6 +186,7 @@ class Game {
167186
if (this.eh.gameState === 'inventory') {
168187
this.pii.render()
169188
}
189+
170190
this.renderer.render(this.scene, this.camera)
171191
}
172192
}

src/scripts/rendering/DistanceBasedFog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class DistanceBasedFog {
4343
'float dist = length(u_viewPos - vViewPosition);',
4444
'float fogFactor = smoothstep(u_farnear.x, u_farnear.y, dist);',
4545
'gl_FragColor = vec4(outgoingLight, diffuseColor.a );',
46-
'gl_FragColor = mix(gl_FragColor, u_fogColor, max(0.05, fogFactor));'
46+
'gl_FragColor = mix(gl_FragColor, u_fogColor, fogFactor);'
4747
].join('\n')
4848
)
4949
}

src/scripts/world/chunk.worker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +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)
8990
const dist = this.distance(chunkId)
9091
if (
9192
(nearestDistance === -1 || nearestDistance > dist) &&

src/webpack.common.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
55
const webpack = require('webpack')
66

77
const config1 = {
8-
optimization: {
9-
runtimeChunk: 'single'
10-
},
118
entry: {
129
main: path.join(__dirname, 'scripts/index.js'),
1310
bootstrap: [path.join(__dirname, 'styles/style.scss'), 'bootstrap']

0 commit comments

Comments
 (0)