forked from michaljaz/webmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntities.coffee
More file actions
28 lines (28 loc) · 892 Bytes
/
Entities.coffee
File metadata and controls
28 lines (28 loc) · 892 Bytes
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
import * as THREE from 'three'
class Entities
constructor:(game)->
@game=game
@mobMaterial = new THREE.MeshBasicMaterial {color: new THREE.Color "red" }
@mobGeometry = new THREE.BoxGeometry 1, 1, 1
@mobMaxCount=200
@mobMesh=new THREE.InstancedMesh @mobGeometry,@mobMaterial,@mobMaxCount
@mobMesh.instanceMatrix.setUsage THREE.DynamicDrawUsage
@game.scene.add @mobMesh
@dummy = new THREE.Object3D()
return
update:(entities)->
offset=[-0.5,16,-0.5]
mobs=0
for i of entities
if entities[i].type is "mob"
mobs++
@mobMesh.count=mobs
mobs=0
for i of entities
if entities[i].type is "mob"
@dummy.position.set entities[i].position.x+offset[0],entities[i].position.y+offset[1],entities[i].position.z+offset[2]
@dummy.updateMatrix()
@mobMesh.setMatrixAt mobs++, @dummy.matrix
@mobMesh.instanceMatrix.needsUpdate = true
return
export {Entities}