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
46 lines (41 loc) · 1.22 KB
/
Entities.js
File metadata and controls
46 lines (41 loc) · 1.22 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
// Generated by CoffeeScript 2.5.1
var Entities;
import * as THREE from './build/three.module.js';
Entities = class Entities {
constructor(game) {
this.game = game;
this.mobMaterial = new THREE.MeshBasicMaterial({
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.dummy = new THREE.Object3D();
return;
}
update(entities) {
var i, mobs, offset;
offset = [-0.5, 16, -0.5];
mobs = 0;
for (i in entities) {
if (entities[i].type === "mob") {
mobs++;
}
}
this.mobMesh.count = mobs;
mobs = 0;
for (i in entities) {
if (entities[i].type === "mob") {
this.dummy.position.set(entities[i].position.x + offset[0], entities[i].position.y + offset[1], entities[i].position.z + offset[2]);
this.dummy.updateMatrix();
this.mobMesh.setMatrixAt(mobs++, this.dummy.matrix);
}
}
this.mobMesh.instanceMatrix.needsUpdate = true;
}
};
export {
Entities
};