ws-3d3-b: model/lwo: typed tables (no new type diagnostic)
This commit is contained in:
1 parent
1aaf8fce68
commit
27518c55c5
2 files changed
+12
-10
No files matched your search
@@ -108,7 +108,7 @@ local function groupLayer(layer: Parse.Layer, surfaceOf: (number?) -> number): {
|
|||||||
table.insert(g.polys, i - 1)
|
table.insert(g.polys, i - 1)
|
||||||
end
|
end
|
||||||
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
|
table.sort(groups, function(a: Group, b: Group): boolean
|
||||||
if a.material ~= b.material then
|
if a.material ~= b.material then
|
||||||
return a.material < b.material
|
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)
|
-- the corners of a face in output order (winding reversed for the handedness change, first corner kept)
|
||||||
local function ordered(corners: { number }): { number }
|
local function ordered(corners: { number }): { number }
|
||||||
local n = #corners
|
local n = #corners
|
||||||
local out = table.create(n)
|
local out = table.create(n) :: { number }
|
||||||
out[1] = corners[1]
|
out[1] = corners[1]
|
||||||
for k = 2, n do
|
for k = 2, n do
|
||||||
out[k] = corners[n - k + 2]
|
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
|
for _, f in g.polys do
|
||||||
local corners = ordered(layer.polys[f + 1].corners)
|
local corners = ordered(layer.polys[f + 1].corners)
|
||||||
local n = #corners
|
local n = #corners
|
||||||
local vs = table.create(n)
|
local vs = table.create(n) :: { number }
|
||||||
for k = 1, n do
|
for k = 1, n do
|
||||||
vs[k] = vertex(f, corners[k])
|
vs[k] = vertex(f, corners[k])
|
||||||
end
|
end
|
||||||
@@ -249,8 +249,8 @@ local function primitive(layer: Parse.Layer, g: Group, attrs: { Attr }, morphs:
|
|||||||
end
|
end
|
||||||
local prim: Types.Primitive = { attributes = attributes, mode = "triangles" }
|
local prim: Types.Primitive = { attributes = attributes, mode = "triangles" }
|
||||||
if #morphs > 0 then
|
if #morphs > 0 then
|
||||||
local targets = {}
|
local targets: { { [string]: Types.Accessor } } = {}
|
||||||
local targetNames = {}
|
local targetNames: { string } = {}
|
||||||
for _, m in morphs do
|
for _, m in morphs do
|
||||||
local d = buffer.create(nv * 12)
|
local d = buffer.create(nv * 12)
|
||||||
for v = 1, nv do
|
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)
|
writef32(d, (v - 1) * 12 + 8, -dz)
|
||||||
end
|
end
|
||||||
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)
|
table.insert(targetNames, m.name)
|
||||||
end
|
end
|
||||||
prim.targets = targets
|
prim.targets = targets
|
||||||
@@ -403,7 +404,8 @@ function Build.scene(m: Parse.Model, opts: { triangulate: boolean? }?): (Types.S
|
|||||||
local prims = {}
|
local prims = {}
|
||||||
for _, g in groups do
|
for _, g in groups do
|
||||||
local mat = scene.materials[g.material]
|
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)
|
local pa = table.clone(attrs)
|
||||||
nc = 0
|
nc = 0
|
||||||
for _, map in layer.maps do
|
for _, map in layer.maps do
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ local function readPolys(r: Bytes.Reader, layer: Layer, kind: string, ptBase: nu
|
|||||||
local npts = #layer.pts // 3
|
local npts = #layer.pts // 3
|
||||||
while r:remaining() >= 2 do
|
while r:remaining() >= 2 do
|
||||||
local n = bit32.band(r:u16be(), 0x3FF)
|
local n = bit32.band(r:u16be(), 0x3FF)
|
||||||
local corners = table.create(n)
|
local corners = table.create(n) :: { number }
|
||||||
for i = 1, n do
|
for i = 1, n do
|
||||||
local p = vx(r) + ptBase
|
local p = vx(r) + ptBase
|
||||||
if p >= npts and not r.err then
|
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
|
local npts = #layer.pts // 3
|
||||||
while r:remaining() >= 4 do
|
while r:remaining() >= 4 do
|
||||||
local n = r:u16be()
|
local n = r:u16be()
|
||||||
local corners = table.create(n)
|
local corners = table.create(n) :: { number }
|
||||||
for i = 1, n do
|
for i = 1, n do
|
||||||
local p = r:u16be()
|
local p = r:u16be()
|
||||||
if p >= npts and not r.err then
|
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
|
while r:remaining() >= 2 do
|
||||||
local p = vx(r) + ptBase
|
local p = vx(r) + ptBase
|
||||||
local f = if perPoly then vx(r) + polyBase else -1
|
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
|
for c = 1, dims do
|
||||||
local x = r:f32be()
|
local x = r:f32be()
|
||||||
if c <= want then
|
if c <= want then
|
||||||
|
|||||||
Reference in new issue
Block a user