33 lines
731 B
JavaScript
33 lines
731 B
JavaScript
import { Mesh, Node } from './index'
|
|
|
|
// Entity is just a Mesh with extra functionality.
|
|
class Entity extends Node {
|
|
constructor (mesh, pos, scale, rotation) {
|
|
super(pos, scale, rotation)
|
|
this.mesh = mesh
|
|
}
|
|
|
|
// Drawing related
|
|
update (dt) {
|
|
// Override this!
|
|
}
|
|
|
|
draw (gl, shader) {
|
|
// Set model transform matrix uniform
|
|
const modelloc = shader.getUniformLocation(gl, 'uModelMatrix')
|
|
gl.uniformMatrix4fv(modelloc, false, this.transform)
|
|
|
|
// Draw the mesh
|
|
this.mesh.draw(gl, shader)
|
|
}
|
|
|
|
// Generators
|
|
static async createEntity (gl, meshName, pos) {
|
|
let mesh = await Mesh.loadFile(gl, meshName)
|
|
let entity = new Entity(mesh, pos)
|
|
return entity
|
|
}
|
|
}
|
|
|
|
export default Entity
|