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
26 lines (26 loc) · 800 Bytes
/
Entities.coffee
File metadata and controls
26 lines (26 loc) · 800 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
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
mobs++
@mobMesh.count=mobs
mobs=0
for i of entities
@dummy.position.set entities[i][0]+offset[0],entities[i][1]+offset[1],entities[i][2]+offset[2]
@dummy.updateMatrix()
@mobMesh.setMatrixAt mobs++, @dummy.matrix
@mobMesh.instanceMatrix.needsUpdate = true
return
export {Entities}