Revert unnecessary changes

This commit is contained in:
Richard 2024-12-04 16:52:12 -08:00
parent 533d1b38a8
commit 4f2dc07dde

View file

@ -30,7 +30,16 @@ local update_descendants = graph.update_descendants
local push_child_to_scope = graph.push_child_to_scope local push_child_to_scope = graph.push_child_to_scope
local UPDATE_RATE = 120 local UPDATE_RATE = 120
local TOLERANCE = vector.create(0.001, 0.001, 0.001) local TOLERANCE = 0.001
local TOLERANCE_VECTOR = vector.create(TOLERANCE, TOLERANCE, TOLERANCE)
type Vec3 = Vector3
local function Vec3(x: number, y: number, z: number): Vec3
return vector.create(x, y, z)
end
local ZERO = Vec3(0, 0, 0)
type Animatable = number | CFrame | Color3 | UDim | UDim2 | Vector2 | Vector3 type Animatable = number | CFrame | Color3 | UDim | UDim2 | Vector2 | Vector3
@ -39,53 +48,53 @@ type SpringData<T> = {
c: number, -- damping coeff c: number, -- damping coeff
-- dimensions 1-3 -- dimensions 1-3
x0_123: Vector3, x0_123: Vec3,
x1_123: Vector3, x1_123: Vec3,
v_123: Vector3, v_123: Vec3,
-- dimensions 4-6 -- dimensions 4-6
x0_456: Vector3, x0_456: Vec3,
x1_456: Vector3, x1_456: Vec3,
v_456: Vector3, v_456: Vec3,
source_value: T -- current value of spring input source source_value: T -- current value of spring input source
} }
type TypeToVec6<T> = (T) -> (Vector3, Vector3) type TypeToVec6<T> = (T) -> (Vec3, Vec3)
type Vec6ToType<T> = (Vector3, Vector3) -> T type Vec6ToType<T> = (Vec3, Vec3) -> T
local type_to_vec6 = { local type_to_vec6 = {
number = function(v) number = function(v)
return Vector3.new(v, 0, 0), Vector3.zero return Vec3(v, 0, 0), ZERO
end :: TypeToVec6<number>, end :: TypeToVec6<number>,
CFrame = function(v) CFrame = function(v)
return v.Position, Vector3.new(v:ToEulerAnglesXYZ()) return v.Position, Vec3(v:ToEulerAnglesXYZ())
end :: TypeToVec6<CFrame>, end :: TypeToVec6<CFrame>,
Color3 = function(v) Color3 = function(v)
-- todo: hsv, oklab? -- todo: hsv, oklab?
return Vector3.new(v.R, v.G, v.B), Vector3.zero return Vec3(v.R, v.G, v.B), ZERO
end :: TypeToVec6<Color3>, end :: TypeToVec6<Color3>,
UDim = function(v) UDim = function(v)
return Vector3.new(v.Scale, v.Offset, 0), Vector3.zero return Vec3(v.Scale, v.Offset, 0), ZERO
end :: TypeToVec6<UDim>, end :: TypeToVec6<UDim>,
UDim2 = function(v) UDim2 = function(v)
return Vector3.new(v.X.Scale, v.X.Offset, v.Y.Scale), Vector3.new(v.Y.Offset, 0, 0) return Vec3(v.X.Scale, v.X.Offset, v.Y.Scale), Vec3(v.Y.Offset, 0, 0)
end :: TypeToVec6<UDim2>, end :: TypeToVec6<UDim2>,
Vector2 = function(v) Vector2 = function(v)
return Vector3.new(v.X, v.Y, 0), Vector3.zero return Vec3(v.X, v.Y, 0), ZERO
end :: TypeToVec6<Vector2>, end :: TypeToVec6<Vector2>,
Vector3 = function(v) Vector3 = function(v)
return v, Vector3.zero return v, ZERO
end :: TypeToVec6<Vector3>, end :: TypeToVec6<Vector3>,
Rect = function(v) Rect = function(v)
return Vector3.new(v.Min.X, v.Min.Y, v.Max.X), Vector3.new(v.Max.Y, 0, 0) return Vec3(v.Min.X, v.Min.Y, v.Max.X), Vec3(v.Max.Y, 0, 0)
end :: TypeToVec6<Rect> end :: TypeToVec6<Rect>
} }
@ -159,13 +168,13 @@ local function spring<T>(source: () -> T, period: number?, damping_ratio: number
k = k, k = k,
c = c, c = c,
x0_123 = Vector3.zero, x0_123 = ZERO,
x1_123 = Vector3.zero, x1_123 = ZERO,
v_123 = Vector3.zero, v_123 = ZERO,
x0_456 = Vector3.zero, x0_456 = ZERO,
x1_456 = Vector3.zero, x1_456 = ZERO,
v_456 = Vector3.zero, v_456 = ZERO,
source_value = false :: any, source_value = false :: any,
} }
@ -197,12 +206,12 @@ local function spring<T>(source: () -> T, period: number?, damping_ratio: number
end end
-- set current position to value -- set current position to value
local v: T = ... :: any local v = ... :: T
data.x0_123, data.x0_456 = type_to_vec6[typeof(v)](v) data.x0_123, data.x0_456 = type_to_vec6[typeof(v)](v)
-- reset velocity -- reset velocity
data.v_123 = Vector3.zero data.v_123 = ZERO
data.v_456 = Vector3.zero data.v_456 = ZERO
-- schedule spring -- schedule spring
springs[data] = output springs[data] = output
@ -266,10 +275,10 @@ local function update_spring_sources()
vector.abs(x0_456 - x1_456 :: any), vector.abs(x0_456 - x1_456 :: any),
vector.abs(v_123 :: any), vector.abs(v_123 :: any),
vector.abs(v_456 :: any), vector.abs(v_456 :: any),
TOLERANCE TOLERANCE_VECTOR
) )
if max_difference == TOLERANCE then if max_difference == TOLERANCE_VECTOR then
-- close enough to target, unshedule spring and set value to target -- close enough to target, unshedule spring and set value to target
table.insert(remove_queue, data) table.insert(remove_queue, data)
output.cache = data.source_value output.cache = data.source_value