ws-cleanup: merge ws/cleanup-types (type annotations)

This commit is contained in:
4DBug committed 2026-10-31 11:27:42 -05:00
commit 4478332a61
115 files changed
+583 -515

No files matched your search

+6 -6
View File
@@ -24,7 +24,7 @@ local SIZE = { [5120] = 1, [5121] = 1, [5122] = 2, [5123] = 2, [5125] = 4, [5126
local TYPE_COMPONENTS = { SCALAR = 1, VEC2 = 2, VEC3 = 3, VEC4 = 4, MAT2 = 4, MAT3 = 9, MAT4 = 16 }
local TYPE_COLUMNS = { MAT2 = 2, MAT3 = 3, MAT4 = 4 }
local MODES = { [0] = "points", [1] = "lines", [2] = "line_loop", [3] = "line_strip", [4] = "triangles", [5] = "triangle_strip", [6] = "triangle_fan" }
local WRAP = { [33071] = "clamp", [33648] = "mirror", [10497] = "repeat" }
local WRAP: { [number]: "clamp" | "mirror" | "repeat" } = { [33071] = "clamp", [33648] = "mirror", [10497] = "repeat" }
local MIN_FILTER = { [9728] = "nearest", [9729] = "linear", [9984] = "nearest_mipmap_nearest", [9985] = "linear_mipmap_nearest", [9986] = "nearest_mipmap_linear", [9987] = "linear_mipmap_linear" }
-- the extensions this reader understands (everything else that is required -> UNSUPPORTED)
local KNOWN = {
@@ -78,7 +78,7 @@ local function numbers(v: any, n: number): { number }?
return nil
end
end
return table.move(v, 1, n, 1, {})
return table.move(v, 1, n, 1, {} :: { number })
end
-- extras.gltf: the JSON extras and the extensions not turned into Scene fields
@@ -449,13 +449,13 @@ function Read.scene(doc: any, bin: buffer?, fetch: Fetch, opts: any?): (Types.Sc
return nil, Err.new(Err.CORRUPT, "bad indices accessor")
end
-- indices must reference existing vertices
local get = Types.Scene.reader(ind) :: any
local get = Types.Scene.reader(ind :: Types.Accessor) :: any
for q = 0, ind.count - 1 do
if get(q, 0) >= count then
return nil, Err.new(Err.CORRUPT, "index out of range")
end
end
prim.indices = ind
prim.indices = ind :: Types.Accessor
end
if type(p.targets) == "table" then
local targets = {}
@@ -484,10 +484,10 @@ function Read.scene(doc: any, bin: buffer?, fetch: Fetch, opts: any?): (Types.Sc
end
if c.type == "orthographic" and type(c.orthographic) == "table" then
local o = c.orthographic
table.insert(scene.cameras, { name = str(c.name), type = "orthographic", xmag = num(o.xmag, 1), ymag = num(o.ymag, 1), znear = num(o.znear, 0), zfar = num(o.zfar, 100) })
table.insert(scene.cameras, { name = str(c.name), type = "orthographic" :: "orthographic", xmag = num(o.xmag, 1), ymag = num(o.ymag, 1), znear = num(o.znear, 0), zfar = num(o.zfar, 100) } :: Types.Camera)
else
local p = if type(c.perspective) == "table" then c.perspective else {}
table.insert(scene.cameras, { name = str(c.name), type = "perspective", yfov = num(p.yfov, 0.8), aspect = if type(p.aspectRatio) == "number" then p.aspectRatio else nil, znear = num(p.znear, 0.01), zfar = if type(p.zfar) == "number" then p.zfar else nil })
table.insert(scene.cameras, { name = str(c.name), type = "perspective" :: "perspective", yfov = num(p.yfov, 0.8), aspect = if type(p.aspectRatio) == "number" then p.aspectRatio else nil, znear = num(p.znear, 0.01), zfar = if type(p.zfar) == "number" then p.zfar else nil } :: Types.Camera)
end
end
local lp = type(doc.extensions) == "table" and doc.extensions.KHR_lights_punctual
+2 -2
View File
@@ -385,7 +385,7 @@ function Write.build(scene: Types.Scene, opts: Options?): (Out?, Err.Err?)
end
local gp = object()
gp.attributes = object()
local names = {}
local names: { string } = {}
for name in p.attributes do
table.insert(names, name)
end
@@ -603,7 +603,7 @@ function Write.build(scene: Types.Scene, opts: Options?): (Out?, Err.Err?)
return nil, failure
end
-- scenes: the original list (meta.gltf.scenes) when it is there, else the roots
local meta = if type(scene.meta) == "table" then scene.meta else {}
local meta: { [string]: any } = if type(scene.meta) == "table" then scene.meta else {}
local mg = type(meta.gltf) == "table" and meta.gltf or {}
local scenes = {}
if type(mg.scenes) == "table" and #mg.scenes > 0 then
+1 -1
View File
@@ -158,7 +158,7 @@ function Gltf.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.
end
-- ------------------------------------------------------------------------------------------------ encode
local EXT = { ["image/png"] = "png", ["image/jpeg"] = "jpg", ["image/webp"] = "webp", ["image/ktx2"] = "ktx2", ["image/avif"] = "avif" }
local EXT: { [string]: string } = { ["image/png"] = "png", ["image/jpeg"] = "jpg", ["image/webp"] = "webp", ["image/ktx2"] = "ktx2", ["image/avif"] = "avif" }
function Gltf.encode(scene: Types.Scene, opts: EncodeOptions?): (buffer?, Err.Err?)
if type(scene) ~= "table" or scene.kind ~= "scene" then