ws-game: model/md3 (Quake III MD3 -> Scene: surfaces as primitives, frames as morph targets, tags as nodes with channels, shaders as URIs)

This commit is contained in:
4DBug committed 2026-10-31 14:32:47 -05:00
1 parent 897a386c4f
commit 50eb827897
7 files changed
+500 -3

No files matched your search

+47
View File
@@ -48,4 +48,51 @@ function Soup.close(a: any, b: { number }, tol: number): (boolean, number?)
return true, nil
end
-- triangles(a, b, tol, stride?) -> true when the triangle lists a and b (flat numbers, stride per corner: 3 for
-- positions, 2 for texture coordinates) hold the same triangles in the same order, each up to a cyclic rotation of
-- its corners (assimp rotates them); false, the first differing triangle otherwise
function Soup.triangles(a: { number }, b: { number }, tol: number, stride: number?): (boolean, number?)
local s = stride or 3
if #a ~= #b then
return false, -1
end
local per = 3 * s
for t = 0, #a // per - 1 do
local found = false
for rot = 0, 2 do
local same = true
for c = 0, 2 do
local ca, cb = t * per + c * s, t * per + ((c + rot) % 3) * s
for k = 1, s do
if math.abs(a[ca + k] - b[cb + k]) > tol * math.max(1, math.abs(b[cb + k])) then
same = false
end
end
end
if same then
found = true
break
end
end
if not found then
return false, t
end
end
return true, nil
end
-- list(buf) -> the f32 values of a buffer as numbers
function Soup.list(b: buffer): { number }
local out = table.create(buffer.len(b) // 4)
for i = 0, buffer.len(b) // 4 - 1 do
out[i + 1] = buffer.readf32(b, i * 4)
end
return out
end
-- slice(list, from, n) -> n values from index from (1-based)
function Soup.slice(list: { number }, from: number, n: number): { number }
return table.move(list, from, from + n - 1, 1, table.create(n))
end
return Soup