model formats (mca..x3d): comments are specs only

This commit is contained in:
4DBug committed 2026-11-01 01:54:32 -05:00
1 parent 0bd7b87d2b
commit b952c10222
49 files changed
+310 -936

No files matched your search

+4 -18
View File
@@ -1,14 +1,7 @@
--!strict
-- model/mdl/HalfLife: Half-Life 1 (GoldSrc) studio models ("IDST" version 10) to a Scene. Written from the studio.h
-- layout of the Half-Life SDK and the format notes of the HLMV / Crowbar communities; no code taken.
-- Bones -> joint nodes and a Skin (bind pose from the bone defaults; Euler angles through Rig.angles), body parts ->
-- one mesh per body part (its first model, or opts.bodies[part]), its meshes -> primitives (triangle strips and fans
-- unrolled to counter-clockwise triangles; vertices transformed to model space by their bone's bind pose; JOINTS_0 =
-- that bone, WEIGHTS_0 = 1), textures (8-bit + their own palette) -> texture.image, the first skin family ->
-- materials, sequences of the main file -> animations (frames at the sequence's fps; the first blend only).
-- Not supported: sequence groups in other files (those sequences are listed in meta, without channels), bone
-- controllers, hitboxes / attachments / events (counted in meta), textures in a separate "<name>t.mdl" (pass it
-- as opts.textures = that file's bytes).
-- model/mdl/HalfLife: GoldSrc studio models ("IDST" v10), from the Half-Life SDK studio.h and HLMV / Crowbar notes; no
-- code taken. Not supported: sequence groups in other files, bone controllers, hitboxes / attachments / events, blends
-- past the first.
local Types = require("@rosetta/Types")
local Mat4 = require("@rosetta/codecs/model/Mat4")
local Pixels = require("@rosetta/codecs/image/Pixels")
@@ -27,7 +20,6 @@ local function str(b: buffer, at: number, n: number): string
return (string.match(buffer.readstring(b, at, n), "^[^%z]*")) :: string
end
-- the textures of a studio header at base (this file or a separate texture file) -> { Image }, names | nil, message
local function textures(b: buffer, base: number, size: number, maxPixels: number): ({ Types.Image }?, { string } | string)
local n, at = readi32(b, base + 180), readi32(b, base + 184)
if n < 0 or n > 4096 or at < 0 or at + n * 80 > size then
@@ -52,7 +44,7 @@ local function textures(b: buffer, base: number, size: number, maxPixels: number
return out, names
end
-- one animation value: bone default + stored value * scale (frame f, 0-based)
-- bone default + stored value * scale
local function animValue(b: buffer, at: number, limit: number, f: number): number?
local p = at
local k = f
@@ -77,7 +69,6 @@ local function animValue(b: buffer, at: number, limit: number, f: number): numbe
return nil
end
-- decode(b, base, size, opts) -> Scene | nil, message
function HalfLife.decode(b: buffer, base: number, size: number, opts: Options?): (Types.Scene?, string?)
if size < 244 then
return nil, "truncated header"
@@ -106,7 +97,6 @@ function HalfLife.decode(b: buffer, base: number, size: number, opts: Options?):
local maxPixels = opts and opts.maxPixels or 2 ^ 24
local scene = Scene.new()
scene.meta.up = "z"
-- bones
local bones: { Bone } = {}
local joints: { Rig.Joint } = {}
for i = 0, nBones - 1 do
@@ -124,7 +114,6 @@ function HalfLife.decode(b: buffer, base: number, size: number, opts: Options?):
table.insert(scene.nodes, root)
scene.roots[1] = 1
local jointNodes, skinIndex, world = Rig.skeleton(scene, joints, "local", 1)
-- textures and skins
local texSrc, texBase, texSize = b, base, size
if nTex == 0 and opts and opts.textures then
texSrc, texBase, texSize = opts.textures, 0, buffer.len(opts.textures)
@@ -151,7 +140,6 @@ function HalfLife.decode(b: buffer, base: number, size: number, opts: Options?):
skinMap[r + 1] = readi16(texSrc, texBase + oSkins + r * 2) + 1
end
end
-- body parts
local totalVerts = 0
for part = 0, nParts - 1 do
local po = base + oParts + part * 76
@@ -173,7 +161,6 @@ function HalfLife.decode(b: buffer, base: number, size: number, opts: Options?):
local tex = skinMap[skinref + 1] or (skinref + 1)
local img = images[tex]
local tw, th = if img then img.width else 1, if img then img.height else 1
-- triangle commands
local weld: { [string]: number } = {}
local corners: { { number } } = {}
local indices: { number } = {}
@@ -285,7 +272,6 @@ function HalfLife.decode(b: buffer, base: number, size: number, opts: Options?):
table.insert(root.children, #scene.nodes)
end
end
-- sequences
local seqs: { any } = {}
for s = 0, nSeq - 1 do
local so = base + oSeq + s * 176
+3 -9
View File
@@ -1,9 +1,6 @@
--!strict
-- model/mdl/Quake: Quake 1 MDL ("IDPO" version 6) to a Scene. Written from the Quake specs (Olivier Montanuy et
-- al., "Quake Specs 3.4", section 5) and the modelgen.h layout of the Quake source release; no code taken.
-- Skins (single and grouped: the first picture of a group) become texture.image through a 768-byte palette;
-- texture coordinates on the seam of back-facing triangles move half a skin width (the vertices are welded per
-- side); simple and grouped frames become morph targets with one animation per frame-name group.
-- model/mdl/Quake: Quake 1 MDL ("IDPO" v6), from "Quake Specs 3.4" section 5 and modelgen.h; no code taken. Seam
-- texture coordinates of back-facing triangles move half a skin width; a skin group shows its first picture.
local Types = require("@rosetta/Types")
local Pixels = require("@rosetta/codecs/image/Pixels")
local Rig = require("@rosetta/codecs/model/Rig")
@@ -19,7 +16,6 @@ local function name16(b: buffer, at: number): string
return (string.match(buffer.readstring(b, at, 16), "^[^%z]*")) :: string
end
-- decode(b, base, size, palette, opts) -> Scene | nil, message (offsets relative to base)
function Quake.decode(b: buffer, base: number, size: number, palette: buffer?, opts: Options?): (Types.Scene?, string?)
if size < 84 then
return nil, "truncated header"
@@ -41,7 +37,6 @@ function Quake.decode(b: buffer, base: number, size: number, palette: buffer?, o
local function need(n: number): boolean
return n >= 0 and p + n <= size
end
-- skins
local pal = if palette then Pixels.palette(palette, 0, 256) else nil
local skins: { Types.Image } = {}
local px = sw * sh
@@ -79,7 +74,6 @@ function Quake.decode(b: buffer, base: number, size: number, palette: buffer?, o
table.insert(skins, img)
p += count * px
end
-- texture coordinates and triangles
if not need(nVerts * 12 + nTris * 16) then
return nil, "truncated vertices / triangles"
end
@@ -117,7 +111,7 @@ function Quake.decode(b: buffer, base: number, size: number, palette: buffer?, o
table.insert(indices, c[1])
end
p += nTris * 16
-- frames: simple (type 0) or groups of simple frames
-- frames: simple (type 0) or groups
local frameAt: { number } = {}
local names: { string } = {}
local fsize = 24 + nVerts * 4
+8 -12
View File
@@ -1,10 +1,6 @@
--!strict
-- model/mdl: Quake 1 ("IDPO" version 6: model/mdl/Quake) and Half-Life 1 / GoldSrc ("IDST" version 10:
-- model/mdl/HalfLife) models, read into a Scene. See the two submodules for what each maps. Quake skins need the
-- game's 768-byte palette (gfx/palette.lmp, not redistributable: never built in): opts.palette (a buffer / string),
-- else opts.resolve("gfx/palette.lmp") / opts.files["gfx/palette.lmp"], else a grey ramp (meta.source.palette =
-- false). Half-Life textures carry their own palettes. Source engine MDL ("IDST" version 44+, with .vvd / .vtx
-- files) is UNSUPPORTED.
-- model/mdl: Quake 1 ("IDPO" v6, model/mdl/Quake) and GoldSrc ("IDST" v10, model/mdl/HalfLife) models. Quake skins
-- need gfx/palette.lmp (not redistributable, never built in; else a grey ramp). Not supported: Source MDL (v44+).
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@rosetta/core/Err")
@@ -26,14 +22,14 @@ local Mdl = {
-- ------------------------------------------------------------------------------------------------ types
export type DecodeOptions = {
palette: (buffer | string)?, -- Quake: the 768-byte palette (default: resolved gfx/palette.lmp, else grey)
palette: (buffer | string)?, -- default: resolved gfx/palette.lmp, else grey
resolve: ((uri: string) -> (buffer | string)?)?,
files: { [string]: buffer | string }?,
frame: number?, -- Quake: the frame used as the base POSITION (default 1)
morph: boolean?, -- Quake: frames as morph targets + animations (default true)
fps: number?, -- Quake: animation frame rate (default 10)
bodies: { number }?, -- Half-Life: the model picked for each body part (1-based, default 1)
textures: (buffer | string)?, -- Half-Life: the "<name>t.mdl" texture file of a model without textures
frame: number?, -- Quake; default 1
morph: boolean?, -- Quake; default true
fps: number?, -- Quake; default 10
bodies: { number }?, -- Half-Life; 1-based, default 1
textures: (buffer | string)?,
maxPixels: number?, -- default 2^24
maxVertices: number?, -- default 2^24
}