From 6db1e839c237f000634a5666cf24f68c98136dbd Mon Sep 17 00:00:00 2001 From: NullBite Date: Fri, 25 Mar 2022 02:42:47 -0400 Subject: [PATCH] Add UVManager --- script.lua | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/script.lua b/script.lua index 4b30dd0..312a75c 100644 --- a/script.lua +++ b/script.lua @@ -358,11 +358,34 @@ end -- UVManager {{{ do local mt={} - mt.__index=UVManager UVManager = { step=vectors.of{u=0, v=0}, - offset=vectors.of{u=0, v=0} + offset=vectors.of{u=0, v=0}, + positions={} } + mt.__index=UVManager + function UVManager.new(self, step, offset, positions) + local t={} + if step ~= nil then t.step=vectors.of(step) end + if offset ~= nil then t.offset=vectors.of(offset) end + if positions ~= nil then t.positions=positions end + t=setmetatable(t, mt) + return t + end + function UVManager.getUV(self, input) + local vec={} + local stp=self.step + local offset=self.offset + if type(input) == "string" then + if self.positions[input] == nil then return nil end + vec=vectors.of(self.positions[input]) + else + vec=vectors.of(input) + end + local u=offset.u+(vec.u*stp.u) + local v=offset.v+(vec.v*stp.v) + return UV{u, v} + end end -- }}}