Skip to content

Commit b1b5222

Browse files
committed
add objects as green cubes
1 parent 03f3a46 commit b1b5222

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

src/scripts/Setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ async function Setup (game) {
5252
game.distanceBasedFog.addShaderToMaterial(game.world.material)
5353
game.distanceBasedFog.addShaderToMaterial(game.ent.mobMaterial)
5454
game.distanceBasedFog.addShaderToMaterial(game.ent.playerMaterial)
55+
game.distanceBasedFog.addShaderToMaterial(game.ent.objectMaterial)
5556
const gui = new dat.GUI()
5657
game.params = {
5758
chunkdist: 3

src/scripts/proxy/Proxy.worker.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ addEventListener('message', function (e) {
9999
}
100100
const entities = {
101101
mobs: [],
102-
players: []
102+
players: [],
103+
objects: []
103104
}
104105
for (const k in bot.entities) {
105106
const v = bot.entities[k]
@@ -109,18 +110,23 @@ addEventListener('message', function (e) {
109110
v.position.y,
110111
v.position.z
111112
])
112-
}
113-
if (v.type === 'player') {
113+
} else if (v.type === 'player') {
114114
entities.players.push([
115115
v.username,
116116
v.position.x,
117117
v.position.y,
118118
v.position.z
119119
])
120+
} else if (v.type === 'object') {
121+
entities.objects.push([
122+
v.position.x,
123+
v.position.y,
124+
v.position.z
125+
])
120126
}
121127
}
122128
emit('entities', entities)
123-
}, 100)
129+
}, 10)
124130
break
125131
case 'move':
126132
state = data[0]

src/scripts/rendering/Entities.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,53 @@ import {
1010
class Entities {
1111
constructor (game) {
1212
this.game = game
13+
1314
this.mobMaterial = new MeshStandardMaterial({
1415
color: new Color('red')
1516
})
1617
this.mobGeometry = new BoxGeometry(1, 1, 1)
17-
this.mobMaxCount = 200
18+
this.mobMaxCount = 1000
1819
this.mobMesh = new InstancedMesh(
1920
this.mobGeometry,
2021
this.mobMaterial,
2122
this.mobMaxCount
2223
)
2324
this.mobMesh.instanceMatrix.setUsage(DynamicDrawUsage)
2425
this.game.scene.add(this.mobMesh)
26+
2527
this.playerMaterial = new MeshStandardMaterial({
2628
color: new Color('blue')
2729
})
2830
this.playerGeometry = new BoxGeometry(1, 1, 1)
29-
this.playerMaxCount = 200
31+
this.playerMaxCount = 1000
3032
this.playerMesh = new InstancedMesh(
3133
this.playerGeometry,
3234
this.playerMaterial,
3335
this.playerMaxCount
3436
)
3537
this.playerMesh.instanceMatrix.setUsage(DynamicDrawUsage)
3638
this.game.scene.add(this.playerMesh)
39+
40+
this.objectMaterial = new MeshStandardMaterial({
41+
color: new Color('green')
42+
})
43+
this.objectGeometry = new BoxGeometry(0.25, 0.25, 0.25)
44+
this.objectMaxCount = 1000
45+
this.objectMesh = new InstancedMesh(
46+
this.objectGeometry,
47+
this.objectMaterial,
48+
this.objectMaxCount
49+
)
50+
this.objectMesh.instanceMatrix.setUsage(DynamicDrawUsage)
51+
this.game.scene.add(this.objectMesh)
52+
3753
this.dummy = new Object3D()
3854
}
3955

4056
update (entities) {
4157
const offset = [-0.5, 16, -0.5]
4258
let numMobs = 0
4359
this.mobMesh.count = entities.mobs.length
44-
numMobs = 0
4560
for (const i in entities.mobs) {
4661
this.dummy.position.set(
4762
entities.mobs[i][0] + offset[0],
@@ -52,6 +67,20 @@ class Entities {
5267
this.mobMesh.setMatrixAt(numMobs++, this.dummy.matrix)
5368
}
5469
this.mobMesh.instanceMatrix.needsUpdate = true
70+
71+
let numObjects = 0
72+
this.objectMesh.count = entities.objects.length
73+
for (const i in entities.objects) {
74+
this.dummy.position.set(
75+
entities.objects[i][0] + offset[0],
76+
entities.objects[i][1] + offset[1],
77+
entities.objects[i][2] + offset[2]
78+
)
79+
this.dummy.updateMatrix()
80+
this.objectMesh.setMatrixAt(numObjects++, this.dummy.matrix)
81+
}
82+
this.objectMesh.instanceMatrix.needsUpdate = true
83+
5584
let numPlayers = 0
5685
for (const i in entities.players) {
5786
if (entities.players[i][0] !== this.game.nick) {

0 commit comments

Comments
 (0)