ws-game: model/md2 (Quake II MD2 -> Scene: frames as morph targets + grouped animations, skins as URIs); codecs/model/Rig.normals
This commit is contained in:
1 parent
ec32f359bc
commit
de1d2c2bba
8 files changed
+499
No files matched your search
@@ -0,0 +1,51 @@
|
||||
-- tests/model/_soup: helpers for the game model tests: a primitive's triangle soup (positions, morph target frames,
|
||||
-- texture coordinates in index order) and a tolerant comparison against assimp's soup.
|
||||
local Types = require("@formats/Types")
|
||||
|
||||
local Soup = {}
|
||||
|
||||
-- positions(prim, target?) -> f32 x3 buffer of the corners in index order (target k adds morph target k's deltas)
|
||||
function Soup.positions(prim: any, target: number?): buffer
|
||||
local pos = Types.Scene.reader(prim.attributes.POSITION) :: any
|
||||
local d = if target then Types.Scene.reader(prim.targets[target].POSITION) :: any else nil
|
||||
local idx = prim.indices
|
||||
local n = idx.count
|
||||
local out = buffer.create(n * 12)
|
||||
for k = 0, n - 1 do
|
||||
local v = buffer.readu32(idx.data, k * 4)
|
||||
for c = 0, 2 do
|
||||
buffer.writef32(out, k * 12 + c * 4, pos(v, c) + (if d then d(v, c) else 0))
|
||||
end
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
-- uvs(prim, set?, flip?) -> { u, v, ... } of the corners in index order (flip: v -> 1 - v, assimp's convention)
|
||||
function Soup.uvs(prim: any, set: number?, flip: boolean?): { number }
|
||||
local tc = Types.Scene.reader(prim.attributes["TEXCOORD_" .. (set or 0)]) :: any
|
||||
local idx = prim.indices
|
||||
local out = {}
|
||||
for k = 0, idx.count - 1 do
|
||||
local v = buffer.readu32(idx.data, k * 4)
|
||||
table.insert(out, tc(v, 0))
|
||||
table.insert(out, if flip then 1 - tc(v, 1) else tc(v, 1))
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
-- close(a: buffer f32 | {number}, b: {number}, tol) -> true | false, first index that differs
|
||||
function Soup.close(a: any, b: { number }, tol: number): (boolean, number?)
|
||||
local n = if type(a) == "buffer" then buffer.len(a) // 4 else #a
|
||||
if n ~= #b then
|
||||
return false, -1
|
||||
end
|
||||
for i = 1, n do
|
||||
local x = if type(a) == "buffer" then buffer.readf32(a, (i - 1) * 4) else a[i]
|
||||
if math.abs(x - b[i]) > tol * math.max(1, math.abs(b[i])) then
|
||||
return false, i
|
||||
end
|
||||
end
|
||||
return true, nil
|
||||
end
|
||||
|
||||
return Soup
|
||||
Reference in new issue
Block a user