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
60 lines (55 loc) · 1.73 KB
/
Entities.js
File metadata and controls
60 lines (55 loc) · 1.73 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
// Generated by CoffeeScript 2.5.1
var Entities;
import * as THREE from './build/three.module.js';
Entities = class Entities {
constructor(options) {
this.scene = options.scene;
this.saved = {};
this.nick = options.nick;
this.TWEEN = options.TWEEN;
}
update(entities) {
var cube, geometry, i, material, offset, pos, results;
offset = [-0.5, 16, -0.5];
for (i in entities) {
if (entities[i].username !== this.nick) {
pos = [entities[i].position.x + offset[0], entities[i].position.y + offset[1], entities[i].position.z + offset[2]];
if (this.saved[entities[i].uuid] === void 0) {
if (entities[i].name === "item") {
material = new THREE.MeshBasicMaterial({
color: new THREE.Color("blue")
});
geometry = new THREE.BoxGeometry(0.5, 0.5, 0.5);
} else {
material = new THREE.MeshBasicMaterial({
color: new THREE.Color("red")
});
geometry = new THREE.BoxGeometry(1, 1, 1);
}
cube = new THREE.Mesh(geometry, material);
this.scene.add(cube);
this.saved[entities[i].uuid] = cube;
this.saved[entities[i].uuid].position.set(...pos);
this.saved[entities[i].uuid].active = true;
} else {
this.saved[entities[i].uuid].position.set(...pos);
this.saved[entities[i].uuid].active = true;
}
}
}
for (i in this.saved) {
if (this.saved[i].active === false) {
this.scene.remove(this.saved[i]);
delete this.saved[i];
}
}
results = [];
for (i in this.saved) {
results.push(this.saved[i].active = false);
}
return results;
}
};
export {
Entities
};