local module = {} setmetatable(module, {__index=_G}) setfenv(1, module) --===== transform cascading =====-- system = function(params) return { db = params.db, priority = 2, update = function(self, dt) local nodes = self.db:queryComponent("node") -- prepare nodes for id, node in pairs(nodes) do node._visited = false end -- helper function local function recursiveTransform(node) if node._visited then return node._matrix end if not node.parent then node._matrix = node.matrix else local parentTransform = self.db:getComponent(node.parent, "node") local parentMatrix = recursiveTransform(parentTransform) node._matrix = parentMatrix * node.matrix end node._visited = true return node._matrix end -- compute nodes for id, node in pairs(nodes) do recursiveTransform(node) end end, } end return module