forked from michaljaz/webmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntities.js
More file actions
66 lines (61 loc) · 2.14 KB
/
Entities.js
File metadata and controls
66 lines (61 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Generated by CoffeeScript 2.5.1
var Entities;
import * as THREE from 'three';
Entities = class Entities {
constructor(game) {
this.game = game;
this.mobMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color("red")
});
this.mobGeometry = new THREE.BoxGeometry(1, 1, 1);
this.mobMaxCount = 200;
this.mobMesh = new THREE.InstancedMesh(this.mobGeometry, this.mobMaterial, this.mobMaxCount);
this.mobMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
this.game.scene.add(this.mobMesh);
this.playerMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color("blue")
});
this.playerGeometry = new THREE.BoxGeometry(1, 1, 1);
this.playerMaxCount = 200;
this.playerMesh = new THREE.InstancedMesh(this.playerGeometry, this.playerMaterial, this.playerMaxCount);
this.playerMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
this.game.scene.add(this.playerMesh);
this.dummy = new THREE.Object3D();
return;
}
update(entities) {
var i, num_mobs, num_players, offset;
offset = [-0.5, 16, -0.5];
num_mobs = 0;
for (i in entities.mobs) {
num_mobs++;
}
this.mobMesh.count = num_mobs;
num_mobs = 0;
for (i in entities.mobs) {
this.dummy.position.set(entities.mobs[i][0] + offset[0], entities.mobs[i][1] + offset[1], entities.mobs[i][2] + offset[2]);
this.dummy.updateMatrix();
this.mobMesh.setMatrixAt(num_mobs++, this.dummy.matrix);
}
this.mobMesh.instanceMatrix.needsUpdate = true;
num_players = 0;
for (i in entities.players) {
if (entities.players[i][0] !== this.game.nick) {
num_players++;
}
}
this.playerMesh.count = num_players;
num_players = 0;
for (i in entities.players) {
if (entities.players[i][0] !== this.game.nick) {
this.dummy.position.set(entities.players[i][1] + offset[0], entities.players[i][2] + offset[1], entities.players[i][3] + offset[2]);
this.dummy.updateMatrix();
this.playerMesh.setMatrixAt(num_players++, this.dummy.matrix);
}
}
this.playerMesh.instanceMatrix.needsUpdate = true;
}
};
export {
Entities
};