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
|
local Node = require('Node')
local MeshInstance = {}
MeshInstance.prototype = {}
setmetatable(MeshInstance.prototype, { __index = Node.prototype})
MeshInstance.prototype.draw = function(self, camera, shader)
local shader = shader or self.shader
honey.shader.set_mat4(shader, 'model', self.transform.array)
honey.shader.set_mat4(shader, 'view', camera.view.array)
honey.shader.set_mat4(shader, 'projection', camera.projection.array)
honey.mesh.draw(self.mesh, shader)
for _, child in ipairs(self.children) do
child:draw(camera)
end
end
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MeshInstance.mt = {}
MeshInstance.mt.__index = MeshInstance.prototype
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MeshInstance.new = function(parent, position, rotation, scale, mesh, shader)
local meshinstance = Node.new(parent, position, rotation, scale)
meshinstance.mesh = mesh
meshinstance.shader = shader
setmetatable(meshinstance, MeshInstance.mt)
return meshinstance
end
return MeshInstance
|