codecs/model/Brush, codecs/model/Patch, codecs/image/Miptex; Pixels palette helpers
Brush: plane brushes -> polygons (qbsp-style clipping), Quake standard / Valve 220 / brush-primitive projection, optional coplanar merge and CSG hull; tested against ericw-tools qbsp -nofill (area per plane, texels per corner). Patch: Bezier control grids moved out of model/bsp/Quake3, per-axis subdivisions (patchDef2 / patchDef3), normals. Miptex: Quake / GoldSrc miptex decode / encode and the WAD2 / WAD3 directory (model/bsp uses it now). Pixels: grey, keyed, colorList, colormap, paletteBytes. STYLE: layout block and 2a table list the new modules.
This commit is contained in:
1 parent
01c044805f
commit
5ad934565d
19 files changed
+4520
-923
No files matched your search
@@ -1,7 +1,9 @@
|
||||
--!strict
|
||||
-- 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.
|
||||
-- Map Specs (Kekoa Proudfoot; no code taken). Lightmaps are 128 x 128 RGB; billboards (flares) are skipped; patches
|
||||
-- through codecs/model/Patch.
|
||||
local Types = require("@rosetta/Types")
|
||||
local Patch = require("@rosetta/codecs/model/Patch")
|
||||
|
||||
local Quake3 = {}
|
||||
|
||||
@@ -81,52 +83,23 @@ function Quake3.decode(b: buffer, base: number, lumps: { [string]: Lump }, opts:
|
||||
counts[if kind == 1 then "polygons" else "meshes"] += 1
|
||||
elseif kind == 2 and first >= 0 and n >= 0 and first + n <= nV then
|
||||
local w, h = readi32(b, o + 96), readi32(b, o + 100)
|
||||
if w >= 3 and h >= 3 and w % 2 == 1 and h % 2 == 1 and w * h == n then
|
||||
if Patch.valid(w, h, n) then
|
||||
counts.patches += 1
|
||||
local L = level
|
||||
for py = 0, (h - 1) // 2 - 1 do
|
||||
for px = 0, (w - 1) // 2 - 1 do
|
||||
local ctrl: { { number } } = {}
|
||||
for j = 0, 2 do
|
||||
for i = 0, 2 do
|
||||
ctrl[j * 3 + i + 1] = vertex(first + (py * 2 + j) * w + px * 2 + i)
|
||||
end
|
||||
end
|
||||
local grid: { number } = {}
|
||||
for gy = 0, L do
|
||||
local tv = gy / L
|
||||
for gx = 0, L do
|
||||
local tu = gx / L
|
||||
local bu = { (1 - tu) ^ 2, 2 * tu * (1 - tu), tu * tu }
|
||||
local bv = { (1 - tv) ^ 2, 2 * tv * (1 - tv), tv * tv }
|
||||
local v = table.create(14, 0)
|
||||
for j = 0, 2 do
|
||||
for i = 0, 2 do
|
||||
local wgt = bu[i + 1] * bv[j + 1]
|
||||
local cp = ctrl[j * 3 + i + 1]
|
||||
for k = 1, 14 do
|
||||
v[k] += cp[k] * wgt
|
||||
end
|
||||
end
|
||||
end
|
||||
local l = math.sqrt(v[8] ^ 2 + v[9] ^ 2 + v[10] ^ 2)
|
||||
if l > 0 then
|
||||
v[8], v[9], v[10] = v[8] / l, v[9] / l, v[10] / l
|
||||
end
|
||||
grid[gy * (L + 1) + gx + 1] = addExtra(v)
|
||||
end
|
||||
end
|
||||
for gy = 0, L - 1 do
|
||||
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]
|
||||
-- Quake's control grids are clockwise-front
|
||||
for _, v in { a, d, c2, c2, d, e } do
|
||||
table.insert(tris, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local ctrl = table.create(n * 14, 0) :: { number }
|
||||
for k = 0, n - 1 do
|
||||
table.move(vertex(first + k), 1, 14, k * 14 + 1, ctrl)
|
||||
end
|
||||
local pts, gw, gh = Patch.grid(ctrl, w, h, 14, level, level, maxV)
|
||||
if not pts then
|
||||
return nil, "limit: too many patch vertices"
|
||||
end
|
||||
Patch.normalize(pts, 14, 7)
|
||||
local ids = table.create(gw * gh) :: { number }
|
||||
for k = 0, gw * gh - 1 do
|
||||
ids[k + 1] = addExtra(table.move(pts, k * 14 + 1, k * 14 + 14, 1, table.create(14, 0)) :: { number })
|
||||
end
|
||||
for _, v in Patch.triangles(gw, gh) do
|
||||
table.insert(tris, ids[v + 1])
|
||||
end
|
||||
else
|
||||
counts.skipped += 1
|
||||
|
||||
Reference in new issue
Block a user