From 7cc97b97568ac873fbac27f6a35c7ef2b27d8799 Mon Sep 17 00:00:00 2001 From: NullBite Date: Wed, 21 Jun 2023 19:42:35 -0400 Subject: [PATCH] Split off UVManager --- nulllib | 2 +- script.lua | 69 +++--------------------------------------------------- 2 files changed, 4 insertions(+), 67 deletions(-) diff --git a/nulllib b/nulllib index 2656ab0..e30a49a 160000 --- a/nulllib +++ b/nulllib @@ -1 +1 @@ -Subproject commit 2656ab02e5c0733695428fe68fd1794ffbbf6094 +Subproject commit e30a49af3b84499652d80fcf956e575569dc692f diff --git a/script.lua b/script.lua index 913501e..da5bf61 100644 --- a/script.lua +++ b/script.lua @@ -127,8 +127,9 @@ function ping.syncState(tbl) end -- }}} +-- math functions nmath=require("nulllib.math") -lerp=math.lerp +lerp=math.lerp -- this is implemented in figura now wave=nmath.wave -- Master and local state variables -- {{{ @@ -203,72 +204,8 @@ end PartsManager=require("nulllib.PartsManager") --- UVManager {{{ --- -- TODO: accept model part for built-in UV management, automatic texture size -do - local mt={} - --- @class UVManager - UVManager = { - step=vec(0,0), - offset=vec(0,0), - positions={}, - part=nil, - dimensions=nil - } - mt.__index=UVManager - --- @return UVManager - --- @param step Vector2 A vector representing the distance between UVs - --- @param offset Vector2 A vector represnting the starting point for UVs, or nil - --- @param positions table A dictionary of names and offset vectors - --- @param part ModelPart Model part to manage - function UVManager.new(self, step, offset, positions, part) - local t={} - if step ~= nil then t.step=step end - if offset ~= nil then t.offset=offset end - if positions ~= nil then t.positions=positions end - - if part ~= nil then - UVManager.setPart(t, part) - end - - t=setmetatable(t, mt) - return t - end - - --- @param part ModelPart Model part to manage - function UVManager.setPart(self, part) - self.part=part - self.dimensions=part:getTextureSize() - end - - function UVManager.getUV(self, input) - local vect={} - local stp=self.step - local offset=self.offset - if type(input) == "string" then - if self.positions[input] == nil then return nil end - vect=self.positions[input] - else - vect=vectors.of(input) - end - local u=offset.x+(vect.x*stp.x) - local v=offset.y+(vect.y*stp.y) - if self.dimensions ~= nil then - -- TODO override for my specific texture, replace this with matrix stuff - -- (get rid of division once you figure out how setUVMatrix works) - return vec(u/(self.dimensions.x/2), v/(self.dimensions.y/2)) - else - return util.UV{u, v} - end - end - - function UVManager.setUV(self, input) - if self.part == nil then return false end - self.part:setUV(self:getUV(input)) - end -end --- }}} +UVManager=require("nulllib.UVManager") -- Parts, groups, other constants -- {{{ HEAD=model.Head.Head