ws-game: model/mdl (Quake 1 IDPO: skins via palette, frames as morph targets; Half-Life 1 IDST: bones, skin, body parts, strips / fans, textures with palettes, sequences as animations); Rig.angles, Rig.skeleton returns world matrices

This commit is contained in:
4DBug committed 2026-10-31 14:41:33 -05:00
1 parent 50eb827897
commit f14d5ac4ef
9 files changed
+1105 -6

No files matched your search

+12 -3
View File
@@ -139,11 +139,20 @@ local function trs(j: Joint): { number }
return Mat4.compose(j.translation, j.rotation, j.scale)
end
-- skeleton(scene, joints, space, root?) -> (joint node indices, skin index): one node per joint (TRS relative to its
-- angles(x, y, z) -> quaternion { x, y, z, w } of the Euler angles in radians applied x first, then y, then z
-- (R = Rz * Ry * Rx: the Quake / Half-Life "AngleQuaternion" convention of MDL bones and SMD skeletons)
function Rig.angles(x: number, y: number, z: number): { number }
local sy, cy = math.sin(z / 2), math.cos(z / 2)
local sp, cp = math.sin(y / 2), math.cos(y / 2)
local sr, cr = math.sin(x / 2), math.cos(x / 2)
return { sr * cp * cy - cr * sp * sy, cr * sp * cy + sr * cp * sy, cr * cp * sy - sr * sp * cy, cr * cp * cy + sr * sp * sy }
end
-- skeleton(scene, joints, space, root?) -> (joint node indices, skin index, world matrices): one node per joint (TRS relative to its
-- parent), parented as listed, roots added to scene.roots (or as children of node `root`); a Skin with the inverse
-- bind matrices. space "local": joint TRS are relative to the parent (SMD, MDL); "world": in model space (MD5's
-- bind pose), converted to local here. A parent index that does not come earlier makes the joint a root.
function Rig.skeleton(scene: Types.Scene, joints: { Joint }, space: "local" | "world", root: number?): ({ number }, number)
function Rig.skeleton(scene: Types.Scene, joints: { Joint }, space: "local" | "world", root: number?): ({ number }, number, { { number } })
local n = #joints
local world: { { number } } = {}
local nodes: { number } = {}
@@ -185,7 +194,7 @@ function Rig.skeleton(scene: Types.Scene, joints: { Joint }, space: "local" | "w
local acc = Scene.accessor(ibm, "f32", 16, n)
acc.matrix = true
table.insert(scene.skins, { joints = nodes, inverseBindMatrices = acc, skeleton = if n > 0 then nodes[1] else nil })
return nodes, #scene.skins
return nodes, #scene.skins, world
end
-- influences(lists) -> JOINTS_0 (u16 x4), WEIGHTS_0 (f32 x4): lists[v] = { joint, weight, joint, weight, ... } with