Skip to content

Commit a6e4ab3

Browse files
committed
lel, maybe I should fix the dimensions and clone 😂
1 parent 124c9d5 commit a6e4ab3

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

src/client/scripts/Entities.js

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import * as THREE from "three";
22

3-
class Entities {
3+
export class Entities {
44
constructor(game) {
5+
this.players = [];
6+
57
this.game = game;
68
this.mobMaterial = new THREE.MeshStandardMaterial({
79
color: new THREE.Color("red"),
@@ -14,19 +16,12 @@ class Entities {
1416
this.mobMaxCount
1517
);
1618
this.mobMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
19+
1720
this.game.scene.add(this.mobMesh);
18-
this.playerMaterial = new THREE.MeshStandardMaterial({
19-
color: new THREE.Color("blue"),
20-
});
21-
this.playerGeometry = new THREE.BoxGeometry(1, 1, 1);
22-
this.playerMaxCount = 200;
23-
this.playerMesh = new THREE.InstancedMesh(
24-
this.playerGeometry,
25-
this.playerMaterial,
26-
this.playerMaxCount
27-
);
28-
this.playerMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
29-
this.game.scene.add(this.playerMesh);
21+
this.playerGeometry = this.game.al.get("player");
22+
this.playerGeometry.children[0].material.map = this.game.al.get("playerTex");
23+
24+
3025
this.dummy = new THREE.Object3D();
3126
}
3227

@@ -45,27 +40,26 @@ class Entities {
4540
this.mobMesh.setMatrixAt(num_mobs++, this.dummy.matrix);
4641
}
4742
this.mobMesh.instanceMatrix.needsUpdate = true;
48-
var num_players = 0;
49-
for (let i in entities.players) {
50-
if (entities.players[i][0] !== this.game.nick) {
51-
num_players++;
52-
}
53-
}
54-
this.playerMesh.count = num_players;
55-
num_players = 0;
56-
for (let i in entities.players) {
57-
if (entities.players[i][0] !== this.game.nick) {
58-
this.dummy.position.set(
59-
entities.players[i][1] + offset[0],
60-
entities.players[i][2] + offset[1],
61-
entities.players[i][3] + offset[2]
62-
);
63-
this.dummy.updateMatrix();
64-
this.playerMesh.setMatrixAt(num_players++, this.dummy.matrix);
43+
44+
45+
for (let i = 0; i < entities.players.length; i++) {
46+
const playerData = entities.players[i];
47+
if (playerData[0] === this.game.nick)
48+
continue;
49+
50+
let player = this.players[i];
51+
if (playerData[0] !== this.game.nick) {
52+
if (!player) {
53+
player = this.game.al.get("player");
54+
player.children[0].material.map = this.game.al.get("playerTex");
55+
this.game.scene.add(player);
56+
}
6557
}
58+
player.position.set(
59+
playerData[1] + offset[0],
60+
playerData[2] + offset[1],
61+
playerData[3] + offset[2]
62+
);
6663
}
67-
this.playerMesh.instanceMatrix.needsUpdate = true;
6864
}
69-
}
70-
71-
export { Entities };
65+
};

0 commit comments

Comments
 (0)