model formats (3ds..lwo): comments are specs only

This commit is contained in:
4DBug committed 2026-11-01 01:53:16 -05:00
1 parent 0bd7b87d2b
commit 3bddd582bc
35 files changed
+233 -697

No files matched your search

+5 -13
View File
@@ -1,11 +1,6 @@
--!strict
-- model/bsp/Quake3: Quake III Arena maps (IBSP version 46; Return to Castle Wolfenstein 47 has the same layout) to a
-- Scene: polygon and mesh faces (meshvert triangles, reversed to counter-clockwise), biquadratic patches
-- tessellated (opts.patchLevel subdivisions per 3x3 control patch, default 4), one primitive per shader and lightmap
-- per model (model 0 = the world, the others "*1", ...), POSITION / NORMAL / TEXCOORD_0 (surface) / TEXCOORD_1
-- (lightmap) / COLOR_0 (vertex colours, unorm8); shaders as texture URIs; the 128 x 128 RGB lightmaps as
-- texture.image (material.extras.bsp.lightmap = its texture index, texCoord 1). Billboards (flares) are skipped.
-- Written from the Unofficial Quake 3 Map Specs (Kekoa Proudfoot); no code taken.
-- model/bsp/Quake3: Quake III Arena maps (IBSP 46; RTCW 47 has the same layout) -> Scene, from the Unofficial Quake 3
-- Map Specs (Kekoa Proudfoot; no code taken). Lightmaps are 128 x 128 RGB; billboards (flares) are skipped.
local Types = require("@rosetta/Types")
local Quake3 = {}
@@ -17,19 +12,18 @@ local writef32, writeu32, writeu8 = buffer.writef32, buffer.writeu32, buffer.wri
export type Lump = { at: number, size: number }
export type Options = { patchLevel: number?, maxVertices: number? }
type Batch = { shader: number, lightmap: number, verts: { number } } -- vertex records (indices into the vertex lump, or -1 - k for patch vertices)
type Batch = { shader: number, lightmap: number, verts: { number } } -- indices into the vertex lump, or -1 - k for patch vertices
local function cstr(b: buffer, at: number, n: number): string
return (string.match(buffer.readstring(b, at, n), "^[^%z]*")) :: string
end
-- decode(b, base, lumps, opts) -> Scene | nil, message
function Quake3.decode(b: buffer, base: number, lumps: { [string]: Lump }, opts: Options?): (Types.Scene?, string?)
local T, M, VX, MV, F, LM = lumps.textures, lumps.models, lumps.vertexes, lumps.meshverts, lumps.faces, lumps.lightmaps
local nT, nM, nV, nMV, nF, nLM = T.size // 72, M.size // 40, VX.size // 44, MV.size // 4, F.size // 104, LM.size // 49152
local level = math.clamp(math.floor(opts and opts.patchLevel or 4), 1, 16)
local maxV = opts and opts.maxVertices or 2 ^ 24
-- patch vertices: 12 floats + 4 colour bytes each, appended as negative ids
-- patch vertices: 12 floats + 4 colour bytes each
local extra: { number } = {}
local function vertex(i: number): { number }
local o = base + VX.at + i * 44
@@ -92,7 +86,6 @@ function Quake3.decode(b: buffer, base: number, lumps: { [string]: Lump }, opts:
local L = level
for py = 0, (h - 1) // 2 - 1 do
for px = 0, (w - 1) // 2 - 1 do
-- the 3x3 control points of this sub-patch
local ctrl: { { number } } = {}
for j = 0, 2 do
for i = 0, 2 do
@@ -127,7 +120,7 @@ function Quake3.decode(b: buffer, base: number, lumps: { [string]: Lump }, opts:
for gx = 0, L - 1 do
local a, c2 = grid[gy * (L + 1) + gx + 1], grid[gy * (L + 1) + gx + 2]
local d, e = grid[(gy + 1) * (L + 1) + gx + 1], grid[(gy + 1) * (L + 1) + gx + 2]
-- counter-clockwise for Quake's clockwise-front control grids
-- Quake's control grids are clockwise-front
for _, v in { a, d, c2, c2, d, e } do
table.insert(tris, v)
end
@@ -166,7 +159,6 @@ function Quake3.decode(b: buffer, base: number, lumps: { [string]: Lump }, opts:
end
local scene = Scene.new()
scene.meta.up = "z"
-- shaders, lightmaps
for i = 0, nT - 1 do
local name = cstr(b, base + T.at + i * 72, 64)
table.insert(scene.textures, { name = name, uri = name })