ws-3d3-b: model/lwo: typed tables (no new type diagnostic)

This commit is contained in:
4DBug committed 2026-10-31 14:05:28 -05:00
1 parent 1aaf8fce68
commit 27518c55c5
2 files changed
+12 -10

No files matched your search

+9 -7
View File
@@ -108,7 +108,7 @@ local function groupLayer(layer: Parse.Layer, surfaceOf: (number?) -> number): {
table.insert(g.polys, i - 1)
end
end
local rank = { poly = 1, patch = 2, line = 3, point = 4 }
local rank: { [string]: number } = { poly = 1, patch = 2, line = 3, point = 4 }
table.sort(groups, function(a: Group, b: Group): boolean
if a.material ~= b.material then
return a.material < b.material
@@ -121,7 +121,7 @@ end
-- the corners of a face in output order (winding reversed for the handedness change, first corner kept)
local function ordered(corners: { number }): { number }
local n = #corners
local out = table.create(n)
local out = table.create(n) :: { number }
out[1] = corners[1]
for k = 2, n do
out[k] = corners[n - k + 2]
@@ -175,7 +175,7 @@ local function primitive(layer: Parse.Layer, g: Group, attrs: { Attr }, morphs:
for _, f in g.polys do
local corners = ordered(layer.polys[f + 1].corners)
local n = #corners
local vs = table.create(n)
local vs = table.create(n) :: { number }
for k = 1, n do
vs[k] = vertex(f, corners[k])
end
@@ -249,8 +249,8 @@ local function primitive(layer: Parse.Layer, g: Group, attrs: { Attr }, morphs:
end
local prim: Types.Primitive = { attributes = attributes, mode = "triangles" }
if #morphs > 0 then
local targets = {}
local targetNames = {}
local targets: { { [string]: Types.Accessor } } = {}
local targetNames: { string } = {}
for _, m in morphs do
local d = buffer.create(nv * 12)
for v = 1, nv do
@@ -267,7 +267,8 @@ local function primitive(layer: Parse.Layer, g: Group, attrs: { Attr }, morphs:
writef32(d, (v - 1) * 12 + 8, -dz)
end
end
table.insert(targets, { POSITION = Scene.accessor(d, "f32", 3, nv) })
local tgt: { [string]: Types.Accessor } = { POSITION = Scene.accessor(d, "f32", 3, nv) }
table.insert(targets, tgt)
table.insert(targetNames, m.name)
end
prim.targets = targets
@@ -403,7 +404,8 @@ function Build.scene(m: Parse.Model, opts: { triangulate: boolean? }?): (Types.S
local prims = {}
for _, g in groups do
local mat = scene.materials[g.material]
local vcol = mat and mat.extras and mat.extras.lwo and mat.extras.lwo.vcol
local ex: any = mat and mat.extras
local vcol = ex and ex.lwo and ex.lwo.vcol
local pa = table.clone(attrs)
nc = 0
for _, map in layer.maps do
+3 -3
View File
@@ -139,7 +139,7 @@ local function readPolys(r: Bytes.Reader, layer: Layer, kind: string, ptBase: nu
local npts = #layer.pts // 3
while r:remaining() >= 2 do
local n = bit32.band(r:u16be(), 0x3FF)
local corners = table.create(n)
local corners = table.create(n) :: { number }
for i = 1, n do
local p = vx(r) + ptBase
if p >= npts and not r.err then
@@ -165,7 +165,7 @@ local function readPolysB(r: Bytes.Reader, layer: Layer, budget: { number }): st
local npts = #layer.pts // 3
while r:remaining() >= 4 do
local n = r:u16be()
local corners = table.create(n)
local corners = table.create(n) :: { number }
for i = 1, n do
local p = r:u16be()
if p >= npts and not r.err then
@@ -224,7 +224,7 @@ local function readVmap(r: Bytes.Reader, layer: Layer, perPoly: boolean, ptBase:
while r:remaining() >= 2 do
local p = vx(r) + ptBase
local f = if perPoly then vx(r) + polyBase else -1
local v = table.create(want, 1)
local v = table.create(want, 1) :: { number }
for c = 1, dims do
local x = r:f32be()
if c <= want then