Add updated UVManager code
Still needs work, I don't know how matrices work and I am going to take a 12 hour linear algebra course to fix that.
This commit is contained in:
parent
42245a7062
commit
ef6b307c0e
40
script.lua
40
script.lua
@ -517,21 +517,36 @@ do
|
|||||||
UVManager = {
|
UVManager = {
|
||||||
step=vec(0,0),
|
step=vec(0,0),
|
||||||
offset=vec(0,0),
|
offset=vec(0,0),
|
||||||
positions={}
|
positions={},
|
||||||
|
part=nil,
|
||||||
|
dimensions=nil
|
||||||
}
|
}
|
||||||
mt.__index=UVManager
|
mt.__index=UVManager
|
||||||
--- @return UVManager
|
--- @return UVManager
|
||||||
--- @param step Vector2 A vector representing the distance between UVs
|
--- @param step Vector2 A vector representing the distance between UVs
|
||||||
--- @param offset Vector2 A vector represnting the starting point for UVs, or nil
|
--- @param offset Vector2 A vector represnting the starting point for UVs, or nil
|
||||||
--- @param positions table A dictionary of names and offset vectors
|
--- @param positions table A dictionary of names and offset vectors
|
||||||
function UVManager.new(self, step, offset, positions)
|
--- @param part ModelPart Model part to manage
|
||||||
|
function UVManager.new(self, step, offset, positions, part)
|
||||||
local t={}
|
local t={}
|
||||||
if step ~= nil then t.step=step end
|
if step ~= nil then t.step=step end
|
||||||
if offset ~= nil then t.offset=offset end
|
if offset ~= nil then t.offset=offset end
|
||||||
if positions ~= nil then t.positions=positions end
|
if positions ~= nil then t.positions=positions end
|
||||||
|
|
||||||
|
if part ~= nil then
|
||||||
|
UVManager.setPart(t, part)
|
||||||
|
end
|
||||||
|
|
||||||
t=setmetatable(t, mt)
|
t=setmetatable(t, mt)
|
||||||
return t
|
return t
|
||||||
end
|
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)
|
function UVManager.getUV(self, input)
|
||||||
local vect={}
|
local vect={}
|
||||||
local stp=self.step
|
local stp=self.step
|
||||||
@ -544,7 +559,18 @@ do
|
|||||||
end
|
end
|
||||||
local u=offset.x+(vect.x*stp.x)
|
local u=offset.x+(vect.x*stp.x)
|
||||||
local v=offset.y+(vect.y*stp.y)
|
local v=offset.y+(vect.y*stp.y)
|
||||||
return UV{u, v}
|
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 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
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
@ -781,7 +807,7 @@ do
|
|||||||
expressions["end"]=expressions.neutral
|
expressions["end"]=expressions.neutral
|
||||||
expressions.hurt=vec(0,1)
|
expressions.hurt=vec(0,1)
|
||||||
expressions.owo=vec(0,2)
|
expressions.owo=vec(0,2)
|
||||||
local expruvm=UVManager:new(vec(8, 8), nil, expressions)
|
local expruvm=UVManager:new(vec(8, 8), nil, expressions, FACE)
|
||||||
current_expression="neutral"
|
current_expression="neutral"
|
||||||
|
|
||||||
-- color/expression rules
|
-- color/expression rules
|
||||||
@ -811,12 +837,12 @@ do
|
|||||||
-- Expression change code
|
-- Expression change code
|
||||||
function setExpression(expression)
|
function setExpression(expression)
|
||||||
current_expression=expression
|
current_expression=expression
|
||||||
FACE:setUV(expruvm:getUV(current_expression))
|
expruvm:setUV(current_expression)
|
||||||
-- This expression sticks, so do not set color explicitly
|
-- This expression sticks, so do not set color explicitly
|
||||||
setColor()
|
setColor()
|
||||||
end
|
end
|
||||||
function changeExpression(expression, ticks)
|
function changeExpression(expression, ticks)
|
||||||
FACE:setUV(expruvm:getUV(expression))
|
expruvm:setUV(expression)
|
||||||
-- This one is for more explicit "flashes" such as player hurt
|
-- This one is for more explicit "flashes" such as player hurt
|
||||||
-- animations, get color explicitly
|
-- animations, get color explicitly
|
||||||
setColor(COLORS[expression])
|
setColor(COLORS[expression])
|
||||||
@ -824,7 +850,7 @@ do
|
|||||||
end
|
end
|
||||||
function resetExpression()
|
function resetExpression()
|
||||||
lock_color=false
|
lock_color=false
|
||||||
FACE:setUV(expruvm:getUV(current_expression))
|
expruvm:setUV(current_expression)
|
||||||
setColor()
|
setColor()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user