summaryrefslogtreecommitdiff
path: root/demo/MeshInstance.lua
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-11-08 09:46:02 -0600
committersanine-a <sanine.not@pm.me>2020-11-08 09:46:02 -0600
commitc00400ce832f2ab81fdef0ecdf6820a08e596eae (patch)
treec3afc529f43949c800e774b114ebffa10a37d3f2 /demo/MeshInstance.lua
parent94572182ea873d5dadbc8428330d4c00eead2c80 (diff)
fix transform order and add drawing cascade
Diffstat (limited to 'demo/MeshInstance.lua')
-rw-r--r--demo/MeshInstance.lua14
1 files changed, 10 insertions, 4 deletions
diff --git a/demo/MeshInstance.lua b/demo/MeshInstance.lua
index 7164f18..a3e6da2 100644
--- a/demo/MeshInstance.lua
+++ b/demo/MeshInstance.lua
@@ -5,11 +5,17 @@ local MeshInstance = {}
MeshInstance.prototype = {}
setmetatable(MeshInstance.prototype, { __index = Node.prototype})
-MeshInstance.prototype.draw = function(self, shader, camera)
+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
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -19,13 +25,13 @@ MeshInstance.mt.__index = MeshInstance.prototype
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-MeshInstance.new = function(parent, position, rotation, scale, mesh)
+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)
- meshinstance.mesh = mesh
-
return meshinstance
end