From 5ad934565dee2da9c77610d5ec11b897d388bb7c Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 18:40:29 -0600 Subject: [PATCH] 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. --- README.md | 4 +- build/Rosetta.luau | 1142 +++++++++++++++++++++++-- build/Rosetta.luau.linemap.json | 695 ++++++++-------- build/rosetta.lua | 1150 ++++++++++++++++++++++++-- build/rosetta.lua.linemap.json | 695 ++++++++-------- docs/FORMATS.md | 5 +- docs/STYLE.md | 6 +- src/Rosetta/Registry.luau | 2 +- src/Rosetta/codecs/image/Miptex.luau | 214 +++++ src/Rosetta/codecs/image/Pixels.luau | 60 +- src/Rosetta/codecs/model/Brush.luau | 638 ++++++++++++++ src/Rosetta/codecs/model/Patch.luau | 122 +++ src/Rosetta/model/bsp/Brush.luau | 33 +- src/Rosetta/model/bsp/Quake3.luau | 65 +- src/Rosetta/model/bsp/init.luau | 2 +- tests/codecs/brush.luau | 224 +++++ tests/codecs/patch.luau | 85 ++ tools/fixtures/_qbsp.py | 153 ++++ tools/fixtures/brush.py | 148 ++++ 19 files changed, 4520 insertions(+), 923 deletions(-) create mode 100644 src/Rosetta/codecs/image/Miptex.luau create mode 100644 src/Rosetta/codecs/model/Brush.luau create mode 100644 src/Rosetta/codecs/model/Patch.luau create mode 100644 tests/codecs/brush.luau create mode 100644 tests/codecs/patch.luau create mode 100644 tools/fixtures/_qbsp.py create mode 100644 tools/fixtures/brush.py diff --git a/README.md b/README.md index 7af4b19..b79492a 100644 --- a/README.md +++ b/README.md @@ -237,8 +237,8 @@ Shared by the formats, not loadable on their own (`src/Rosetta/codecs//` | compress | Brotli, Bzip2, Deflate, Explode, Lz4, Lzh, Lzma, Lzw, Lzx, PackBits, Quantum, UnixCompress, Xxh32, Zstd | | entropy | Huffman, RangeCoder | | font | Bitmap, Cff, GlyphNames, TrueType | -| image | Bcn, Blend, Dct, Etc, Half, Jpeg, Pixels, Quantize, Raster, Texel, Texture, Vp8, Vp8L, Yuv | -| model | Draco, Mat4, MeshFlatten, Minecraft, Polygon, Rbx, Rig, Sampler, Vrml | +| image | Bcn, Blend, Dct, Etc, Half, Jpeg, Miptex, Pixels, Quantize, Raster, Texel, Texture, Vp8, Vp8L, Yuv | +| model | Brush, Draco, Mat4, MeshFlatten, Minecraft, Patch, Polygon, Rbx, Rig, Sampler, Vrml | | text | Json, Nbt, Text, Url, Xml | | video | Dsp, H263, H264, Legacy, Mpeg1, Mpeg2, Theora, Video | | containers | Archive, AudioWrap, Avi, Chunks, Cpio, Demux, Ebml, Fat, Iso9660, IsoBmff, MacFile, MpegEs, MpegPs, MpegTs, Ogg, Riff, Tar, Zip | diff --git a/build/Rosetta.luau b/build/Rosetta.luau index 7d956b2..876cf6f 100644 --- a/build/Rosetta.luau +++ b/build/Rosetta.luau @@ -1610,7 +1610,7 @@ local list: { Entry } = { path = "model/bsp", extensions = { "bsp" }, mime = { "model/x-bsp" }, - deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels" }, + deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels", "codecs/image/Miptex", "codecs/model/Patch" }, caps = { decode = true, encode = false, variants = { "quake", "halflife", "quake2", "quake3" }, lightmaps = "quake3" }, load = function() return __include("model/bsp") @@ -69631,12 +69631,229 @@ end return Yuv end +__FILES["codecs/image/Miptex"] = function() + +-- codecs/image/Miptex: Quake / GoldSrc mip textures and the WAD2 / WAD3 lump directory, read and write. +-- miptex_t of bspfile.h: name[16], width, height, offsets[4], four 8-bit mip levels; GoldSrc adds u16 count + count * 3 +-- palette bytes after mip 3. wad.h: "WAD2" / "WAD3", numlumps, infotableofs; 32-byte lumpinfo_t. No code taken. +local Types = __include("Types") +local Pixels = __include("codecs/image/Pixels") +local Quantize = __include("codecs/image/Quantize") + +local Miptex = {} + +local readu8, readu32, readi32 = buffer.readu8, buffer.readu32, buffer.readi32 + +type Header = { name: string, width: number, height: number, offsets: { number } } +type Lump = { name: string, offset: number, disksize: number, size: number, type: number, compression: number } +type DecodeOptions = { + palette: buffer?, -- 1024-byte rgba8 palette (Pixels.palette) when the texture has none of its own + goldsrc: boolean?, -- read the palette stored after mip 3 + mip: number?, -- 0..3, default 0 + keyed: boolean?, -- index 255 transparent; default: names starting with '{' + maxPixels: number?, -- default 2^24 +} + +-- lumpinfo_t types (wad.h TYP_*; WAD3: 0x43 is a miptex with its palette, 0x46 a font) +Miptex.TYPES = table.freeze({ palette = 0x40, qtex = 0x41, qpic = 0x42, sound = 0x43, miptex = 0x44, font = 0x46 }) + +local function cstr(b: buffer, at: number, n: number): string + return (string.match(buffer.readstring(b, at, n), "^[^%z]*")) :: string +end + +function Miptex.header(b: buffer, at: number, size: number): (Header?, string?) + if at < 0 or size < 40 or at + 40 > buffer.len(b) then + return nil, "truncated miptex header" + end + local w, h = readu32(b, at + 16), readu32(b, at + 20) + local offs = { readu32(b, at + 24), readu32(b, at + 28), readu32(b, at + 32), readu32(b, at + 36) } + return { name = cstr(b, at, 16), width = w, height = h, offsets = offs }, nil +end + +-- the GoldSrc palette after mip 3, as a 1024-byte rgba8 palette, or nil when it is missing / out of range +function Miptex.ownPalette(b: buffer, at: number, size: number, hd: Header): buffer? + local w, h = hd.width, hd.height + local p = hd.offsets[4] + (w // 8) * (h // 8) + if hd.offsets[4] == 0 or p + 2 > size then + return nil + end + local n = buffer.readu16(b, at + p) + if n == 0 or n > 256 or p + 2 + n * 3 > size then + return nil + end + return Pixels.palette(b, at + p + 2, n) +end + +-- decodes one mip level to rgba8; without pixels (offsets 0: the texture lives in a WAD) returns nil, "external" +function Miptex.decode(b: buffer, at: number, size: number, opts: DecodeOptions?): (Types.Image?, string?) + local hd, err = Miptex.header(b, at, size) + if not hd then + return nil, err + end + local mip = math.clamp(math.floor(opts and opts.mip or 0), 0, 3) + local w, h = hd.width // (2 ^ mip), hd.height // (2 ^ mip) + if hd.width == 0 or hd.height == 0 or w == 0 or h == 0 then + return nil, "empty miptex" + end + if hd.width * hd.height > (opts and opts.maxPixels or 2 ^ 24) then + return nil, "limit: miptex " .. hd.width .. " x " .. hd.height + end + local off = hd.offsets[mip + 1] + if off == 0 then + return nil, "external" + end + if off + w * h > size or at + off + w * h > buffer.len(b) then + return nil, "truncated miptex pixels" + end + local own = if opts and opts.goldsrc then Miptex.ownPalette(b, at, size, hd) else nil + local pal = own or (opts and opts.palette) or Pixels.grey() + local keyed = if opts and opts.keyed ~= nil then opts.keyed else string.sub(hd.name, 1, 1) == "{" + if keyed then + pal = Pixels.keyed(pal, 255) + end + local img = Types.Image.new(w, h) + Pixels.indexed(b, at + off, w, 8, img.pixels, w, h, true, pal) + img.meta.source = { format = "miptex", name = hd.name, mip = mip, palette = own ~= nil or (opts ~= nil and opts.palette ~= nil), keyed = keyed or nil } + return img, nil +end + +local function halve(px: buffer, w: number, h: number): (buffer, number, number) + local w2, h2 = math.max(1, w // 2), math.max(1, h // 2) + local out = buffer.create(w2 * h2 * 4) + for y = 0, h2 - 1 do + for x = 0, w2 - 1 do + for c = 0, 3 do + local s = 0 + for dy = 0, 1 do + for dx = 0, 1 do + local sx, sy = math.min(x * 2 + dx, w - 1), math.min(y * 2 + dy, h - 1) + s += readu8(px, (sy * w + sx) * 4 + c) + end + end + buffer.writeu8(out, (y * w2 + x) * 4 + c, (s + 2) // 4) + end + end + end + return out, w2, h2 +end + +-- an rgba8 image -> a miptex_t with four mip levels (box filtered, mapped to the nearest palette entry); goldsrc +-- appends the palette. palette: 1024-byte rgba8; without it (GoldSrc only) a 256-colour median-cut palette is made. +function Miptex.encode(img: Types.Image, name: string, palette: buffer?, goldsrc: boolean?): (buffer?, string?) + local w, h = img.width, img.height + if w <= 0 or h <= 0 or w % 16 ~= 0 or h % 16 ~= 0 then + return nil, "miptex sizes must be multiples of 16" + end + if #name > 15 then + return nil, "miptex name over 15 bytes" + end + local colors: { { number } } + if palette then + colors = Pixels.colorList(palette) + elseif goldsrc then + colors = Quantize.palette(img.pixels, w, h, 256) + else + return nil, "a Quake miptex needs a palette" + end + local keyed = string.sub(name, 1, 1) == "{" + local levels: { buffer } = {} + local px, lw, lh = img.pixels, w, h + for m = 0, 3 do + if m > 0 then + px, lw, lh = halve(px, lw, lh) + end + local idx = Quantize.map(px, lw, lh, colors, { transparentIndex = if keyed then 255 else nil }) + if keyed then + for k = 0, lw * lh - 1 do + if readu8(px, k * 4 + 3) < 128 then + buffer.writeu8(idx, k, 255) + end + end + end + levels[m + 1] = idx + end + local total = 40 + for _, l in levels do + total += buffer.len(l) + end + local palAt = total + if goldsrc then + total += 2 + 768 + 2 + end + local out = buffer.create(total) + buffer.writestring(out, 0, name) + buffer.writeu32(out, 16, w) + buffer.writeu32(out, 20, h) + local o = 40 + for m, l in levels do + buffer.writeu32(out, 24 + (m - 1) * 4, o) + buffer.copy(out, o, l) + o += buffer.len(l) + end + if goldsrc then + buffer.writeu16(out, palAt, 256) + for i = 0, 255 do + local c = colors[i + 1] or { 0, 0, 0 } + buffer.writeu8(out, palAt + 2 + i * 3, c[1]) + buffer.writeu8(out, palAt + 3 + i * 3, c[2]) + buffer.writeu8(out, palAt + 4 + i * 3, c[3]) + end + end + return out, nil +end + +-- the lump directory of a WAD2 / WAD3 file (offsets relative to base), or nil, message +function Miptex.wad(b: buffer, base: number, size: number, maxLumps: number?): ({ Lump }?, string?, string?) + if size < 12 or base + 12 > buffer.len(b) then + return nil, "truncated header", nil + end + local magic = buffer.readstring(b, base, 4) + if magic ~= "WAD2" and magic ~= "WAD3" then + return nil, "bad magic", nil + end + local n, dir = readi32(b, base + 4), readi32(b, base + 8) + if n < 0 or dir < 0 then + return nil, "negative directory field", nil + end + if n > (maxLumps or 1e6) then + return nil, "limit: too many lumps: " .. n, nil + end + if dir + n * 32 > size then + return nil, "truncated directory past the end", nil + end + local out: { Lump } = {} + for i = 0, n - 1 do + local o = base + dir + i * 32 + local at, disk, full = readi32(b, o), readi32(b, o + 4), readi32(b, o + 8) + if at < 0 or disk < 0 or at + disk > size then + return nil, "truncated lump past the end", nil + end + out[i + 1] = { name = cstr(b, o + 16, 16), offset = at, disksize = disk, size = full, type = readu8(b, o + 12), compression = readu8(b, o + 13) } + end + return out, nil, magic +end + +-- the lump named name (case-insensitive, the last one wins as in W_GetLumpinfo) +function Miptex.find(lumps: { Lump }, name: string): Lump? + local want = string.lower(name) + local best: Lump? = nil + for _, l in lumps do + if string.lower(l.name) == want then + best = l + end + end + return best +end + +return Miptex +end __FILES["codecs/image/Pixels"] = @native function() --- codecs/image/Pixels: row loops between packed pixel layouts and rgba8 for BMP / DIB. --- Indexed, BGR(A), 5-5-5, bit masks, RLE4 / RLE8. From bmp-luau b86aed6 (same author); the encoder loops are new. +-- codecs/image/Pixels: row loops between packed pixel layouts and rgba8 for BMP / DIB, and palette helpers. +-- Indexed, BGR(A), 5-5-5, bit masks, RLE4 / RLE8; palettes: keyed index (Quake 255), grey ramp, Quake colormap light +-- levels. From bmp-luau b86aed6 (same author); the encoder loops and palette helpers are new. local readu8, readu16, readu32, writeu32, writeu8 = buffer.readu8, buffer.readu16, buffer.readu32, buffer.writeu32, buffer.writeu8 local band, rshift, bor, lshift = bit32.band, bit32.rshift, bit32.bor, bit32.lshift @@ -69893,6 +70110,61 @@ end return list, alpha end +-- a 256-entry rgba8 palette (u32 LE per entry) with entry i = { i, i, i, 255 } +@native function Pixels.grey(): buffer + local pal = buffer.create(1024) + for i = 0, 255 do + writeu32(pal, i * 4, 0xFF000000 + i * 0x10101) + end + return pal +end + +-- a copy of a 1024-byte palette with entry index fully transparent (Quake / GoldSrc: index 255 of sprites, qpics and +-- '{' textures) +@native function Pixels.keyed(pal: buffer, index: number): buffer + local out = buffer.create(1024) + buffer.copy(out, 0, pal, 0, math.min(buffer.len(pal), 1024)) + if index >= 0 and index < 256 then + writeu32(out, index * 4, 0) + end + return out +end + +-- palette (1024 bytes) -> { { r, g, b, a } } for codecs/image/Quantize +@native function Pixels.colorList(pal: buffer, n: number?): { { number } } + local out: { { number } } = {} + for i = 0, math.clamp(n or 256, 0, buffer.len(pal) // 4) - 1 do + out[i + 1] = { readu8(pal, i * 4), readu8(pal, i * 4 + 1), readu8(pal, i * 4 + 2), readu8(pal, i * 4 + 3) } + end + return out +end + +-- Quake colormap.lmp: rows of 256 palette indices, row 0 brightest .. 63 darkest (32 = unlit); the palette for one +-- light level, or nil past the end of the map +@native function Pixels.colormap(pal: buffer, cmap: buffer, base: number, row: number): buffer? + local o = base + row * 256 + if row < 0 or base < 0 or o + 256 > buffer.len(cmap) then + return nil + end + local out = buffer.create(1024) + for i = 0, 255 do + writeu32(out, i * 4, readu32(pal, readu8(cmap, o + i) * 4)) + end + return out +end + +-- rgba8 palette (1024 bytes) -> 3 * n bytes R, G, B (the Quake / GoldSrc palette layout) +@native function Pixels.paletteBytes(pal: buffer, n: number?): buffer + local m = math.clamp(n or 256, 0, 256) + local out = buffer.create(m * 3) + for i = 0, m - 1 do + writeu8(out, i * 3, readu8(pal, i * 4)) + writeu8(out, i * 3 + 1, readu8(pal, i * 4 + 1)) + writeu8(out, i * 3 + 2, readu8(pal, i * 4 + 2)) + end + return out +end + return Pixels end __FILES["codecs/image/Quantize"] = @native function() @@ -76459,6 +76731,646 @@ end return Yuv end +__FILES["codecs/model/Brush"] = @native function() + + + +-- codecs/model/Brush: convex plane brushes -> polygons and Scene primitives, with Quake-family texture projection. +-- As qbsp (Quake / ericw-tools; no code taken): a big square on every plane (inside n . p <= d) clipped by the others. +-- Projections: Quake standard (TextureAxisFromPlane + rotate / scale / shift), Valve 220 (explicit U / V axes), Quake +-- III brush primitives (q3map2 ComputeAxisBase + 2 x 3 matrix). Options: merge coplanar faces with one projection +-- (qbsp TryMerge), drop face parts inside / touching other brushes (qbsp CSGFaces; earlier brushes win coplanar ties). +local Types = __include("Types") + +local Brush = {} + +local abs, sqrt, floor, sin, cos, atan2, min, max = math.abs, math.sqrt, math.floor, math.sin, math.cos, math.atan2, math.min, math.max +local writef32, writeu32 = buffer.writef32, buffer.writeu32 + +type Plane = { number } -- nx, ny, nz, d (unit normal pointing out of the brush) +type Face = { + plane: Plane, + texture: string?, + vecs: { { number } }?, -- 2 x 4: s = p . vecs[1].xyz + vecs[1][4] in texels (Quake standard / Valve 220) + bp: { { number } }?, -- 2 x 3 brush-primitive matrix: s = bp[1] . (p . texS, p . texT, 1) in texture widths + [string]: any, +} +type Polygon = { + brush: number, + face: number, + points: { number }, -- x, y, z per corner, counter-clockwise seen from the front + normal: { number }, +} +type Options = { + epsilon: number?, -- plane side tolerance, default 1e-3 + size: number?, -- half size of the starting winding, default 2^17 + merge: boolean?, -- merge coplanar faces with the same texture projection, default false + hull: boolean?, -- drop face parts inside / touching other brushes, default false + maxPolygons: number?, -- default 2^20 +} +type Built = { texture: string, primitive: Types.Primitive } + +-- TextureAxisFromPlane's baseaxis table (normal, s axis, t axis per row): floor, ceiling, west, east, south, north +local BASEAXIS = { + { 0, 0, 1 }, { 1, 0, 0 }, { 0, -1, 0 }, + { 0, 0, -1 }, { 1, 0, 0 }, { 0, -1, 0 }, + { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, -1 }, + { -1, 0, 0 }, { 0, 1, 0 }, { 0, 0, -1 }, + { 0, 1, 0 }, { 1, 0, 0 }, { 0, 0, -1 }, + { 0, -1, 0 }, { 1, 0, 0 }, { 0, 0, -1 }, +} + +@native local function snap(x: number): number + local r = floor(x + 0.5) + return if abs(x - r) < 1e-6 then r else x +end + +-- qbsp PlaneFromPoints: normal = (p1 - p2) x (p3 - p2), the brush lies behind it; nil when the points are colinear +@native function Brush.planeFromPoints(a: { number }, b: { number }, c: { number }): Plane? + local ux, uy, uz = a[1] - b[1], a[2] - b[2], a[3] - b[3] + local vx, vy, vz = c[1] - b[1], c[2] - b[2], c[3] - b[3] + local nx, ny, nz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + local l = sqrt(nx * nx + ny * ny + nz * nz) + if l < 1e-12 then + return nil + end + nx, ny, nz = nx / l, ny / l, nz / l + return { nx, ny, nz, b[1] * nx + b[2] * ny + b[3] * nz } +end + +-- the base axis row (0..5) of TextureAxisFromPlane: the first with the largest dot product (strictly greater) +@native function Brush.baseAxis(n: { number }): number + local best, axis = 0, 0 + for i = 0, 5 do + local a = BASEAXIS[i * 3 + 1] + local d = n[1] * a[1] + n[2] * a[2] + n[3] * a[3] + if d > best then + best, axis = d, i + end + end + return axis +end + +-- Quake standard texture vectors (texels): offsets, rotation (degrees), scales (0 = 1) +@native function Brush.quakeVecs(n: { number }, xoff: number, yoff: number, rot: number, xscale: number, yscale: number): { { number } } + local axis = Brush.baseAxis(n) + local s0, t0 = BASEAXIS[axis * 3 + 2], BASEAXIS[axis * 3 + 3] + local vecs = { { s0[1], s0[2], s0[3] }, { t0[1], t0[2], t0[3] } } + local sinv, cosv + if rot == 0 then + sinv, cosv = 0, 1 + elseif rot == 90 then + sinv, cosv = 1, 0 + elseif rot == 180 then + sinv, cosv = 0, -1 + elseif rot == 270 then + sinv, cosv = -1, 0 + else + local ang = rot / 180 * math.pi + sinv, cosv = sin(ang), cos(ang) + end + local sv = if vecs[1][1] ~= 0 then 1 elseif vecs[1][2] ~= 0 then 2 else 3 + local tv = if vecs[2][1] ~= 0 then 1 elseif vecs[2][2] ~= 0 then 2 else 3 + for i = 1, 2 do + local v = vecs[i] + local ns = cosv * v[sv] - sinv * v[tv] + local nt = sinv * v[sv] + cosv * v[tv] + v[sv], v[tv] = ns, nt + end + local sc = { if xscale == 0 then 1 else xscale, if yscale == 0 then 1 else yscale } + for i = 1, 2 do + local v = vecs[i] + v[1], v[2], v[3] = v[1] / sc[i], v[2] / sc[i], v[3] / sc[i] + end + vecs[1][4], vecs[2][4] = xoff, yoff + return vecs +end + +-- Valve 220: u / v = axis (x, y, z, offset); the rotation is already in the axes +@native function Brush.valveVecs(u: { number }, v: { number }, xscale: number, yscale: number): { { number } } + local su, sv = if xscale == 0 then 1 else xscale, if yscale == 0 then 1 else yscale + return { { u[1] / su, u[2] / su, u[3] / su, u[4] }, { v[1] / sv, v[2] / sv, v[3] / sv, v[4] } } +end + +-- q3map2 ComputeAxisBase: the texture plane axes of a brush-primitive face +@native function Brush.axisBase(normal: { number }): ({ number }, { number }) + local nx, ny, nz = normal[1], normal[2], normal[3] + nx = if abs(nx) < 1e-6 then 0 else nx + ny = if abs(ny) < 1e-6 then 0 else ny + nz = if abs(nz) < 1e-6 then 0 else nz + local rotY = -atan2(nz, sqrt(ny * ny + nx * nx)) + local rotZ = atan2(ny, nx) + return { -sin(rotZ), cos(rotZ), 0 }, { -sin(rotY) * cos(rotZ), -sin(rotY) * sin(rotZ), -cos(rotY) } +end + +-- brush primitives -> texel vectors for a w x h texture (ericw-tools SetTexinfo_BrushPrimitives) +@native function Brush.bpVecs(normal: { number }, m: { { number } }, w: number, h: number): { { number } } + local tx, ty = Brush.axisBase(normal) + local out = {} + for i, size in { w, h } do + local r = m[i] + out[i] = { size * (tx[1] * r[1] + ty[1] * r[2]), size * (tx[2] * r[1] + ty[2] * r[2]), size * (tx[3] * r[1] + ty[3] * r[2]), size * r[3] } + end + return out +end + +-- texel vectors -> brush primitives (the inverse of bpVecs for vectors lying in the face plane) +@native function Brush.vecsToBp(normal: { number }, vecs: { { number } }, w: number, h: number): { { number } } + local tx, ty = Brush.axisBase(normal) + local out = {} + for i, size in { w, h } do + local v = vecs[i] + out[i] = { + (v[1] * tx[1] + v[2] * tx[2] + v[3] * tx[3]) / size, + (v[1] * ty[1] + v[2] * ty[2] + v[3] * ty[3]) / size, + v[4] / size, + } + end + return out +end + +-- texture coordinates of a point on a face, in texture widths / heights (glTF uv: t grows down the image) +@native function Brush.uv(face: Face, x: number, y: number, z: number, w: number, h: number): (number, number) + local bp = face.bp + if bp then + local tx, ty = Brush.axisBase(face.plane) + local a = x * tx[1] + y * tx[2] + z * tx[3] + local b = x * ty[1] + y * ty[2] + z * ty[3] + return bp[1][1] * a + bp[1][2] * b + bp[1][3], bp[2][1] * a + bp[2][2] * b + bp[2][3] + end + local v = face.vecs + if v then + local s, t = v[1], v[2] + return (x * s[1] + y * s[2] + z * s[3] + s[4]) / w, (x * t[1] + y * t[2] + z * t[3] + t[4]) / h + end + return 0, 0 +end + +-- qbsp BaseWindingForPlane: a square of half size `size` on the plane, counter-clockwise seen from the front +@native function Brush.baseWinding(p: Plane, size: number): { number } + local nx, ny, nz, d = p[1], p[2], p[3], p[4] + local ax, ay, az = abs(nx), abs(ny), abs(nz) + local ux, uy, uz = 0, 0, 1 + if az >= ax and az >= ay then + ux, uy, uz = 1, 0, 0 + end + local dv = ux * nx + uy * ny + uz * nz + ux, uy, uz = ux - dv * nx, uy - dv * ny, uz - dv * nz + local l = sqrt(ux * ux + uy * uy + uz * uz) + ux, uy, uz = ux / l * size, uy / l * size, uz / l * size + -- right = up x n, so right x up = n: right -> up turns counter-clockwise about n + local rx, ry, rz = (uy * nz - uz * ny), (uz * nx - ux * nz), (ux * ny - uy * nx) + local ox, oy, oz = nx * d, ny * d, nz * d + return { + ox - rx - ux, oy - ry - uy, oz - rz - uz, + ox + rx - ux, oy + ry - uy, oz + rz - uz, + ox + rx + ux, oy + ry + uy, oz + rz + uz, + ox - rx + ux, oy - ry + uy, oz - rz + uz, + } +end + +-- splits a polygon by a plane: the parts in front and behind (nil when empty), and whether it lies on the plane +@native function Brush.split(pts: { number }, p: Plane, eps: number): ({ number }?, { number }?, boolean) + local n = #pts // 3 + local nx, ny, nz, d = p[1], p[2], p[3], p[4] + local dist = table.create(n, 0) :: { number } + local side = table.create(n, 0) :: { number } + local front, back = 0, 0 + for i = 0, n - 1 do + local v = pts[i * 3 + 1] * nx + pts[i * 3 + 2] * ny + pts[i * 3 + 3] * nz - d + dist[i + 1] = v + if v > eps then + side[i + 1] = 1 + front += 1 + elseif v < -eps then + side[i + 1] = -1 + back += 1 + end + end + if front == 0 and back == 0 then + return nil, nil, true + end + if front == 0 then + return nil, pts, false + end + if back == 0 then + return pts, nil, false + end + local f: { number }, b: { number } = {}, {} + for i = 0, n - 1 do + local j = (i + 1) % n + local x, y, z = pts[i * 3 + 1], pts[i * 3 + 2], pts[i * 3 + 3] + local si = side[i + 1] + if si >= 0 then + f[#f + 1], f[#f + 2], f[#f + 3] = x, y, z + end + if si <= 0 then + b[#b + 1], b[#b + 2], b[#b + 3] = x, y, z + end + local sj = side[j + 1] + if si ~= 0 and sj ~= 0 and si ~= sj then + local t = dist[i + 1] / (dist[i + 1] - dist[j + 1]) + local mx, my, mz = x + t * (pts[j * 3 + 1] - x), y + t * (pts[j * 3 + 2] - y), z + t * (pts[j * 3 + 3] - z) + -- exact on axis-aligned planes, as qbsp + if nx == 1 then + mx = d + elseif nx == -1 then + mx = -d + end + if ny == 1 then + my = d + elseif ny == -1 then + my = -d + end + if nz == 1 then + mz = d + elseif nz == -1 then + mz = -d + end + f[#f + 1], f[#f + 2], f[#f + 3] = mx, my, mz + b[#b + 1], b[#b + 2], b[#b + 3] = mx, my, mz + end + end + return (if #f >= 9 then f else nil), (if #b >= 9 then b else nil), false +end + +-- removes repeated and colinear corners; nil when fewer than 3 remain +@native local function clean(pts: { number }, eps: number): { number }? + local out: { number } = {} + local n = #pts // 3 + for i = 0, n - 1 do + local x, y, z = snap(pts[i * 3 + 1]), snap(pts[i * 3 + 2]), snap(pts[i * 3 + 3]) + local m = #out + if m < 3 or abs(out[m - 2] - x) > eps or abs(out[m - 1] - y) > eps or abs(out[m] - z) > eps then + out[m + 1], out[m + 2], out[m + 3] = x, y, z + end + end + while #out >= 6 and abs(out[1] - out[#out - 2]) <= eps and abs(out[2] - out[#out - 1]) <= eps and abs(out[3] - out[#out]) <= eps do + out[#out], out[#out - 1], out[#out - 2] = nil, nil, nil + end + -- colinear corners + local changed = true + while changed and #out >= 9 do + changed = false + local k = #out // 3 + for i = 0, k - 1 do + local a, b, c = ((i + k - 1) % k) * 3, i * 3, ((i + 1) % k) * 3 + local ux, uy, uz = out[b + 1] - out[a + 1], out[b + 2] - out[a + 2], out[b + 3] - out[a + 3] + local vx, vy, vz = out[c + 1] - out[b + 1], out[c + 2] - out[b + 2], out[c + 3] - out[b + 3] + local cx, cy, cz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + local lu, lv = sqrt(ux * ux + uy * uy + uz * uz), sqrt(vx * vx + vy * vy + vz * vz) + if lu * lv == 0 or sqrt(cx * cx + cy * cy + cz * cz) <= 1e-9 * lu * lv then + table.remove(out, b + 3) + table.remove(out, b + 2) + table.remove(out, b + 1) + changed = true + break + end + end + end + return if #out >= 9 then out else nil +end + +@native local function samePlane(a: Plane, b: Plane, eps: number): boolean + return abs(a[1] - b[1]) < 1e-5 and abs(a[2] - b[2]) < 1e-5 and abs(a[3] - b[3]) < 1e-5 and abs(a[4] - b[4]) < eps +end + +@native local function oppositePlane(a: Plane, b: Plane, eps: number): boolean + return abs(a[1] + b[1]) < 1e-5 and abs(a[2] + b[2]) < 1e-5 and abs(a[3] + b[3]) < 1e-5 and abs(a[4] + b[4]) < eps +end + +-- one polygon per plane of a convex brush (nil for planes clipped away or repeating an earlier plane) +@native function Brush.windings(planes: { Plane }, opts: Options?): { { number }? } + local eps = opts and opts.epsilon or 1e-3 + local size = opts and opts.size or 2 ^ 17 + local out: { { number }? } = {} + for i, p in planes do + local w: { number }? = Brush.baseWinding(p, size) + for j, q in planes do + if not w then + break + end + if j ~= i then + if samePlane(p, q, eps) then + if j < i then + w = nil + end + else + local _, back, on = Brush.split(w, q, eps) + w = if on then nil else back + end + end + end + out[i] = if w then clean(w, eps) else nil + end + return out +end + +@native local function bounds(polys: { Polygon }): { number } + local b = { math.huge, math.huge, math.huge, -math.huge, -math.huge, -math.huge } + for _, p in polys do + local pts = p.points + for k = 0, #pts // 3 - 1 do + for c = 1, 3 do + local v = pts[k * 3 + c] + b[c] = min(b[c], v) + b[c + 3] = max(b[c + 3], v) + end + end + end + return b +end + +-- the parts of pts (on plane `own` of brush a) outside brush b +@native local function outside(pts: { number }, own: Plane, a: number, b: number, planes: { Plane }, eps: number): { { number } } + local kept: { { number } } = {} + local inside: { number }? = pts + for _, q in planes do + if not inside then + break + end + if samePlane(own, q, eps) then + if a < b then + return { pts } + end + elseif not oppositePlane(own, q, eps) then + local front, back = Brush.split(inside, q, eps) + if front then + table.insert(kept, front) + end + inside = back + end + end + return kept +end + +@native local function faceKey(f: Face): string + local parts = { f.texture or "" } + for _, m in { f.vecs, f.bp } do + if m then + for _, row in m do + for _, v in row do + table.insert(parts, string.format("%.6g", v)) + end + end + end + end + return table.concat(parts, " ") +end + +@native local function convex(pts: { number }, n: { number }, eps: number): boolean + local k = #pts // 3 + for i = 0, k - 1 do + local a, b, c = ((i + k - 1) % k) * 3, i * 3, ((i + 1) % k) * 3 + local ux, uy, uz = pts[b + 1] - pts[a + 1], pts[b + 2] - pts[a + 2], pts[b + 3] - pts[a + 3] + local vx, vy, vz = pts[c + 1] - pts[b + 1], pts[c + 2] - pts[b + 2], pts[c + 3] - pts[b + 3] + local cx, cy, cz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + local lu, lv = sqrt(ux * ux + uy * uy + uz * uz), sqrt(vx * vx + vy * vy + vz * vz) + if (cx * n[1] + cy * n[2] + cz * n[3]) < -eps * max(lu, lv, 1) then + return false + end + end + return true +end + +-- qbsp TryMerge: two polygons sharing an edge (in opposite directions) -> their union, when convex +@native local function tryMerge(f1: { number }, f2: { number }, n: { number }, eps: number): { number }? + local n1, n2 = #f1 // 3, #f2 // 3 + for i = 0, n1 - 1 do + local i2 = (i + 1) % n1 + for j = 0, n2 - 1 do + local j2 = (j + 1) % n2 + local match = true + for c = 1, 3 do + if abs(f1[i * 3 + c] - f2[j2 * 3 + c]) > eps or abs(f1[i2 * 3 + c] - f2[j * 3 + c]) > eps then + match = false + break + end + end + if match then + local out: { number } = {} + for k = 0, n1 - 1 do + local s = ((i2 + k) % n1) * 3 + out[#out + 1], out[#out + 2], out[#out + 3] = f1[s + 1], f1[s + 2], f1[s + 3] + end + for k = 2, n2 - 1 do + local s = ((j + k) % n2) * 3 + out[#out + 1], out[#out + 2], out[#out + 3] = f2[s + 1], f2[s + 2], f2[s + 3] + end + local c = clean(out, eps) + if c and convex(c, n, eps) then + return c + end + return nil + end + end + end + return nil +end + +@native local function mergeAll(polys: { Polygon }, faces: { [number]: { Face } }, eps: number): { Polygon } + local groups: { [string]: { Polygon } } = {} + local order: { string } = {} + for _, p in polys do + local f = faces[p.brush][p.face] + local pl = f.plane + local key = string.format("%.5f %.5f %.5f %.3f|", pl[1], pl[2], pl[3], pl[4]) .. faceKey(f) + local g = groups[key] + if not g then + g = {} + groups[key] = g + table.insert(order, key) + end + table.insert(g, p) + end + local out: { Polygon } = {} + for _, key in order do + local g = groups[key] + local changed = true + while changed do + changed = false + for a = 1, #g do + for b = a + 1, #g do + local m = tryMerge(g[a].points, g[b].points, g[a].normal, eps) + if m then + g[a] = { brush = g[a].brush, face = g[a].face, points = m, normal = g[a].normal } + table.remove(g, b) + changed = true + break + end + end + if changed then + break + end + end + end + for _, p in g do + table.insert(out, p) + end + end + return out +end + +-- every brush's faces -> polygons (brushes[i] is a list of faces); nil, message past opts.maxPolygons +@native function Brush.polygons(brushes: { { Face } }, opts: Options?): ({ Polygon }?, string?) + local eps = opts and opts.epsilon or 1e-3 + local limit = opts and opts.maxPolygons or 2 ^ 20 + local per: { { Polygon } } = {} + local planesOf: { { Plane } } = {} + local count = 0 + for bi, faces in brushes do + local planes: { Plane } = {} + for fi, f in faces do + planes[fi] = f.plane + end + planesOf[bi] = planes + local list: { Polygon } = {} + local ws = Brush.windings(planes, opts) + for fi = 1, #faces do + local w = ws[fi] + if w then + table.insert(list, { brush = bi, face = fi, points = w, normal = { planes[fi][1], planes[fi][2], planes[fi][3] } }) + end + end + per[bi] = list + count += #list + if count > limit then + return nil, "limit: too many brush faces" + end + end + local all: { Polygon } = {} + if opts and opts.hull then + local boxes: { { number } } = {} + for bi = 1, #brushes do + boxes[bi] = bounds(per[bi]) + end + for bi = 1, #brushes do + for _, p in per[bi] do + local frags: { { number } } = { p.points } + local own = brushes[bi][p.face].plane + local pb = bounds({ p }) + for bj = 1, #brushes do + if #frags == 0 then + break + end + local ob = boxes[bj] + if bj ~= bi and #per[bj] > 0 and pb[1] <= ob[4] + eps and pb[4] >= ob[1] - eps and pb[2] <= ob[5] + eps + and pb[5] >= ob[2] - eps and pb[3] <= ob[6] + eps and pb[6] >= ob[3] - eps then + local nextFrags: { { number } } = {} + for _, fr in frags do + for _, kept in outside(fr, own, bi, bj, planesOf[bj], eps) do + table.insert(nextFrags, kept) + end + end + frags = nextFrags + if #frags > limit then + return nil, "limit: too many brush fragments" + end + end + end + for _, fr in frags do + local c = clean(fr, eps) + if c then + table.insert(all, { brush = p.brush, face = p.face, points = c, normal = p.normal }) + end + end + end + end + else + for bi = 1, #brushes do + for _, p in per[bi] do + table.insert(all, p) + end + end + end + if opts and opts.merge then + all = mergeAll(all, brushes, eps) + end + return all, nil +end + +-- polygon area (for checks against compilers) +@native function Brush.area(pts: { number }): number + local n = #pts // 3 + local ax, ay, az = 0, 0, 0 + for k = 1, n - 2 do + local ux, uy, uz = pts[k * 3 + 1] - pts[1], pts[k * 3 + 2] - pts[2], pts[k * 3 + 3] - pts[3] + local vx, vy, vz = pts[k * 3 + 4] - pts[1], pts[k * 3 + 5] - pts[2], pts[k * 3 + 6] - pts[3] + ax += uy * vz - uz * vy + ay += uz * vx - ux * vz + az += ux * vy - uy * vx + end + return sqrt(ax * ax + ay * ay + az * az) / 2 +end + +-- polygons -> one indexed triangle primitive per texture, in order of first use. size(name) gives a texture's +-- width, height (texel projections divide by them) +@native function Brush.primitives(polys: { Polygon }, brushes: { { Face } }, size: (name: string) -> (number, number)): { Built } + type Acc = { texture: string, pos: { number }, nrm: { number }, uv: { number }, idx: { number } } + local byTex: { [string]: Acc } = {} + local order: { Acc } = {} + local sizes: { [string]: { number } } = {} + for _, p in polys do + local f = brushes[p.brush][p.face] + local name = f.texture or "" + local acc = byTex[name] + if not acc then + acc = { texture = name, pos = {}, nrm = {}, uv = {}, idx = {} } + byTex[name] = acc + table.insert(order, acc) + end + local sz = sizes[name] + if not sz then + local w, h = size(name) + sz = { math.max(w, 1), math.max(h, 1) } + sizes[name] = sz + end + local a: Acc = acc + local pts = p.points + local n = #pts // 3 + local base = #a.pos // 3 + for k = 0, n - 1 do + local x, y, z = pts[k * 3 + 1], pts[k * 3 + 2], pts[k * 3 + 3] + local pp, nn, uu = a.pos, a.nrm, a.uv + pp[#pp + 1], pp[#pp + 2], pp[#pp + 3] = x, y, z + nn[#nn + 1], nn[#nn + 2], nn[#nn + 3] = p.normal[1], p.normal[2], p.normal[3] + local u, v = Brush.uv(f, x, y, z, sz[1], sz[2]) + uu[#uu + 1], uu[#uu + 2] = u, v + end + local ii = a.idx + for k = 1, n - 2 do + ii[#ii + 1], ii[#ii + 2], ii[#ii + 3] = base, base + k, base + k + 1 + end + end + local out: { Built } = {} + for _, a in order do + local nv, ni = #a.pos // 3, #a.idx + local pb, nb, ub, ib = buffer.create(nv * 12), buffer.create(nv * 12), buffer.create(nv * 8), buffer.create(ni * 4) + for k = 1, nv * 3 do + writef32(pb, (k - 1) * 4, a.pos[k]) + writef32(nb, (k - 1) * 4, a.nrm[k]) + end + for k = 1, nv * 2 do + writef32(ub, (k - 1) * 4, a.uv[k]) + end + for k = 1, ni do + writeu32(ib, (k - 1) * 4, a.idx[k]) + end + local S = Types.Scene + table.insert(out, { + texture = a.texture, + primitive = { + attributes = { POSITION = S.accessor(pb, "f32", 3, nv), NORMAL = S.accessor(nb, "f32", 3, nv), TEXCOORD_0 = S.accessor(ub, "f32", 2, nv) }, + indices = S.accessor(ib, "u32", 1, ni), + mode = "triangles" :: "triangles", + }, + }) + end + return out +end + +return Brush +end __FILES["codecs/model/Draco"] = function() -- codecs/model/Draco: Google Draco geometry decompression (.drc; glTF KHR_draco_mesh_compression; Roblox mesh v6 / v7). @@ -82124,6 +83036,130 @@ end return Packed end +__FILES["codecs/model/Patch"] = @native function() + + + +-- codecs/model/Patch: Quake III / Doom 3 Bezier patches (control grids) -> evaluated grids, triangles, normals. +-- A w x h grid (w, h odd, >= 3) is a mesh of 3 x 3 biquadratic sub-patches (Unofficial Quake 3 Map Specs; patchDef2 / +-- patchDef3), evaluated at fixed segments per sub-patch and axis (patchDef3's explicit subdivisions; Quake III's adaptive +-- subdivision is not reproduced). Shared edges are evaluated once. +local Patch = {} + +local sqrt = math.sqrt + +@native function Patch.valid(w: number, h: number, n: number): boolean + return w >= 3 and h >= 3 and w % 2 == 1 and h % 2 == 1 and w * h == n +end + +-- ctrl: w * h points of comps numbers, row-major (row j holds points j * w .. j * w + w - 1); returns the evaluated grid +-- (gw * gh points of comps numbers, row-major) and its size; nil when the grid is not w x h odd or a limit is passed +@native function Patch.grid(ctrl: { number }, w: number, h: number, comps: number, levelU: number, levelV: number, maxPoints: number?): ({ number }?, number, number) + local lu, lv = math.max(1, math.floor(levelU)), math.max(1, math.floor(levelV)) + if not Patch.valid(w, h, #ctrl // comps) or #ctrl ~= w * h * comps then + return nil, 0, 0 + end + local px, py = (w - 1) // 2, (h - 1) // 2 + local gw, gh = px * lu + 1, py * lv + 1 + if gw * gh > (maxPoints or 2 ^ 24) then + return nil, 0, 0 + end + local out = table.create(gw * gh * comps, 0) :: { number } + for gy = 0, gh - 1 do + local sy = math.min(gy // lv, py - 1) + local tv = (gy - sy * lv) / lv + local bv0, bv1, bv2 = (1 - tv) * (1 - tv), 2 * tv * (1 - tv), tv * tv + for gx = 0, gw - 1 do + local sx = math.min(gx // lu, px - 1) + local tu = (gx - sx * lu) / lu + local bu0, bu1, bu2 = (1 - tu) * (1 - tu), 2 * tu * (1 - tu), tu * tu + local o = (gy * gw + gx) * comps + for j = 0, 2 do + local bv = if j == 0 then bv0 elseif j == 1 then bv1 else bv2 + local row = ((sy * 2 + j) * w + sx * 2) * comps + for i = 0, 2 do + local wgt = bv * (if i == 0 then bu0 elseif i == 1 then bu1 else bu2) + local c = row + i * comps + for k = 1, comps do + out[o + k] += ctrl[c + k] * wgt + end + end + end + end + end + return out, gw, gh +end + +-- 0-based triangle indices over a gw x gh grid; Quake's control grids are clockwise-front, these are counter-clockwise +@native function Patch.triangles(gw: number, gh: number): { number } + local out = table.create(math.max(0, (gw - 1) * (gh - 1) * 6)) :: { number } + for gy = 0, gh - 2 do + for gx = 0, gw - 2 do + local a, b = gy * gw + gx, gy * gw + gx + 1 + local d, e = a + gw, b + gw + local n = #out + out[n + 1], out[n + 2], out[n + 3] = a, d, b + out[n + 4], out[n + 5], out[n + 6] = b, d, e + end + end + return out +end + +-- renormalizes the vec3 at component offset at (0-based) of every point +@native function Patch.normalize(pts: { number }, comps: number, at: number) + for o = 0, #pts - comps, comps do + local x, y, z = pts[o + at + 1], pts[o + at + 2], pts[o + at + 3] + local l = sqrt(x * x + y * y + z * z) + if l > 0 then + pts[o + at + 1], pts[o + at + 2], pts[o + at + 3] = x / l, y / l, z / l + end + end +end + +-- unit normals (3 per point) of the evaluated grid from the positions (components 1..3), facing the front of +-- Patch.triangles; points where the surface degenerates take a neighbour's normal +@native function Patch.normals(pts: { number }, comps: number, gw: number, gh: number): { number } + local out = table.create(gw * gh * 3, 0) :: { number } + @native local function at(x: number, y: number, k: number): number + return pts[(y * gw + x) * comps + k] + end + for gy = 0, gh - 1 do + local y0, y1 = math.max(gy - 1, 0), math.min(gy + 1, gh - 1) + for gx = 0, gw - 1 do + local x0, x1 = math.max(gx - 1, 0), math.min(gx + 1, gw - 1) + local ux, uy, uz = at(x1, gy, 1) - at(x0, gy, 1), at(x1, gy, 2) - at(x0, gy, 2), at(x1, gy, 3) - at(x0, gy, 3) + local vx, vy, vz = at(gx, y1, 1) - at(gx, y0, 1), at(gx, y1, 2) - at(gx, y0, 2), at(gx, y1, 3) - at(gx, y0, 3) + local nx, ny, nz = vy * uz - vz * uy, vz * ux - vx * uz, vx * uy - vy * ux + local l = sqrt(nx * nx + ny * ny + nz * nz) + local o = (gy * gw + gx) * 3 + if l > 1e-12 then + out[o + 1], out[o + 2], out[o + 3] = nx / l, ny / l, nz / l + end + end + end + for _ = 1, 2 do + for i = 0, gw * gh - 1 do + local o = i * 3 + if out[o + 1] == 0 and out[o + 2] == 0 and out[o + 3] == 0 then + local x, y = i % gw, i // gw + for _, d in { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 1 }, { -1, -1 }, { 1, -1 }, { -1, 1 } } do + local nx2, ny2 = x + d[1], y + d[2] + if nx2 >= 0 and nx2 < gw and ny2 >= 0 and ny2 < gh then + local q = (ny2 * gw + nx2) * 3 + if out[q + 1] ~= 0 or out[q + 2] ~= 0 or out[q + 3] ~= 0 then + out[o + 1], out[o + 2], out[o + 3] = out[q + 1], out[q + 2], out[q + 3] + break + end + end + end + end + end + end + return out +end + +return Patch +end __FILES["codecs/model/Polygon"] = function() -- codecs/model/Polygon: 2D polygons with holes to triangles by hole bridging and ear clipping. New code. @@ -144464,7 +145500,7 @@ local Bsp = { category = "model", extensions = { "bsp" }, mime = { "model/x-bsp" }, - deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels" }, + deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels", "codecs/image/Miptex", "codecs/model/Patch" }, caps = { decode = true, encode = false, variants = { "quake", "halflife", "quake2", "quake3" }, lightmaps = "quake3" }, } @@ -144596,6 +145632,7 @@ __FILES["model/bsp/Brush"] = function() -- size. local Types = __include("Types") local Pixels = __include("codecs/image/Pixels") +local Miptex = __include("codecs/image/Miptex") local Brush = {} @@ -144628,34 +145665,18 @@ local function miptex(b: buffer, base: number, l: Lump, hl: boolean, pal: buffer if n < 0 or n > 65536 or 4 + n * 4 > l.size then return nil, "bad miptex lump" end - local gpal = if pal then Pixels.palette(pal, 0, 256) else nil + local gpal = if pal and not hl then Pixels.palette(pal, 0, 256) else nil for i = 0, n - 1 do local o = readi32(b, at + 4 + i * 4) - if o < 0 or o + 40 > l.size then + local hd = if o >= 0 and o + 40 <= l.size then Miptex.header(b, at + o, l.size - o) else nil + if not hd then out[i + 1] = { name = "missing" .. i, width = 64, height = 64, image = nil, texels = false } else - local m = at + o - local name = cstr(b, m, 16) - local w, h, off0 = readu32(b, m + 16), readu32(b, m + 20), readu32(b, m + 24) - local t: Tex = { name = name, width = math.max(w, 1), height = math.max(h, 1), image = nil, texels = false } - if off0 ~= 0 and w > 0 and h > 0 and w * h <= maxPixels then - local px = m + off0 - local need = w * h - local palAt = m + readu32(b, m + 36) + (w // 8) * (h // 8) + 2 - if o + off0 + need <= l.size then - local p = gpal - if hl then - p = if palAt - at + 768 <= l.size then Pixels.palette(b, palAt, 256) else nil - end - local img = Types.Image.new(w, h) - if p then - Pixels.indexed(b, px, w, 8, img.pixels, w, h, true, p) - else - for k = 0, need - 1 do - writeu32(img.pixels, k * 4, 0xFF000000 + buffer.readu8(b, px + k) * 0x10101) - end - end - img.meta.source = { format = "bsp", miptex = name, palette = p ~= nil } + local t: Tex = { name = hd.name, width = math.max(hd.width, 1), height = math.max(hd.height, 1), image = nil, texels = false } + if hd.offsets[1] ~= 0 and hd.width * hd.height <= maxPixels then + local img = Miptex.decode(b, at + o, l.size - o, { palette = gpal, goldsrc = hl, keyed = false, maxPixels = maxPixels }) + if img then + img.meta.source = { format = "bsp", miptex = hd.name, palette = img.meta.source and img.meta.source.palette } t.image = img end end @@ -144870,8 +145891,10 @@ end __FILES["model/bsp/Quake3"] = function() -- 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 = __include("Types") +local Patch = __include("codecs/model/Patch") local Quake3 = {} @@ -144951,52 +145974,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 diff --git a/build/Rosetta.luau.linemap.json b/build/Rosetta.luau.linemap.json index f0d926f..3b16bf1 100644 --- a/build/Rosetta.luau.linemap.json +++ b/build/Rosetta.luau.linemap.json @@ -190,350 +190,353 @@ [69044, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], [69490, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], [69568, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], -[69635, "src/Rosetta/codecs/image/Pixels.luau"], -[69899, "src/Rosetta/codecs/image/Quantize/init.luau"], -[70358, "src/Rosetta/codecs/image/Raster.luau"], -[71055, "src/Rosetta/codecs/image/Texel.luau"], -[71428, "src/Rosetta/codecs/image/Texture.luau"], -[71573, "src/Rosetta/codecs/image/Vp8/init.luau"], -[71703, "src/Rosetta/codecs/image/Vp8/Decode.luau"], -[73659, "src/Rosetta/codecs/image/Vp8/Predict.luau"], -[73918, "src/Rosetta/codecs/image/Vp8/Tables.luau"], -[74167, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], -[74286, "src/Rosetta/codecs/image/Vp8L/init.luau"], -[74390, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], -[75243, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], -[76195, "src/Rosetta/codecs/image/Yuv.luau"], -[76463, "src/Rosetta/codecs/model/Draco/init.luau"], -[76795, "src/Rosetta/codecs/model/Draco/Attributes.luau"], -[77264, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], -[78453, "src/Rosetta/codecs/model/Draco/Int64.luau"], -[78602, "src/Rosetta/codecs/model/Draco/KdTree.luau"], -[78961, "src/Rosetta/codecs/model/Draco/Predict.luau"], -[79923, "src/Rosetta/codecs/model/Draco/Reader.luau"], -[80397, "src/Rosetta/codecs/model/Mat4.luau"], -[80656, "src/Rosetta/codecs/model/MeshFlatten.luau"], -[81184, "src/Rosetta/codecs/model/Minecraft/init.luau"], -[81736, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], -[81815, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], -[81922, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], -[82128, "src/Rosetta/codecs/model/Polygon.luau"], -[82362, "src/Rosetta/codecs/model/Rbx/init.luau"], -[82599, "src/Rosetta/codecs/model/Rbx/Binary.luau"], -[83353, "src/Rosetta/codecs/model/Rig.luau"], -[83596, "src/Rosetta/codecs/model/Sampler.luau"], -[83756, "src/Rosetta/codecs/model/Vrml/init.luau"], -[83904, "src/Rosetta/codecs/model/Vrml/Build.luau"], -[84478, "src/Rosetta/codecs/model/Vrml/Fields.luau"], -[84641, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], -[85390, "src/Rosetta/codecs/model/Vrml/Parse.luau"], -[85912, "src/Rosetta/codecs/model/Vrml/Write.luau"], -[86639, "src/Rosetta/codecs/model/Vrml/Xml.luau"], -[86871, "src/Rosetta/codecs/text/Json/init.luau"], -[87140, "src/Rosetta/codecs/text/Json/Decode.luau"], -[87554, "src/Rosetta/codecs/text/Json/Encode.luau"], -[87856, "src/Rosetta/codecs/text/Nbt/init.luau"], -[88209, "src/Rosetta/codecs/text/Nbt/Binary.luau"], -[88901, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], -[89541, "src/Rosetta/codecs/text/Nbt/Value.luau"], -[89779, "src/Rosetta/codecs/text/Text/init.luau"], -[89870, "src/Rosetta/codecs/text/Url/init.luau"], -[90075, "src/Rosetta/codecs/text/Xml/init.luau"], -[90478, "src/Rosetta/codecs/text/Xml/Parse.luau"], -[91218, "src/Rosetta/codecs/video/Dsp.luau"], -[91941, "src/Rosetta/codecs/video/H263/init.luau"], -[92097, "src/Rosetta/codecs/video/H263/Decoder.luau"], -[92955, "src/Rosetta/codecs/video/H263/Tables.luau"], -[93158, "src/Rosetta/codecs/video/H264/init.luau"], -[93531, "src/Rosetta/codecs/video/H264/Bitstream.luau"], -[93806, "src/Rosetta/codecs/video/H264/Cabac.luau"], -[94937, "src/Rosetta/codecs/video/H264/Cavlc.luau"], -[95705, "src/Rosetta/codecs/video/H264/Deblock.luau"], -[95963, "src/Rosetta/codecs/video/H264/Decoder.luau"], -[96972, "src/Rosetta/codecs/video/H264/Inter.luau"], -[97226, "src/Rosetta/codecs/video/H264/Intra.luau"], -[97633, "src/Rosetta/codecs/video/H264/Mb.luau"], -[98539, "src/Rosetta/codecs/video/H264/Params.luau"], -[98986, "src/Rosetta/codecs/video/H264/Slice.luau"], -[99237, "src/Rosetta/codecs/video/H264/Tables.luau"], -[99278, "src/Rosetta/codecs/video/H264/Transform.luau"], -[99443, "src/Rosetta/codecs/video/Legacy/init.luau"], -[99641, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], -[99938, "src/Rosetta/codecs/video/Legacy/Flic.luau"], -[100305, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], -[100423, "src/Rosetta/codecs/video/Legacy/Picture.luau"], -[100531, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], -[100804, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], -[101199, "src/Rosetta/codecs/video/Legacy/Smc.luau"], -[101376, "src/Rosetta/codecs/video/Mpeg1/init.luau"], -[101388, "src/Rosetta/codecs/video/Mpeg2/init.luau"], -[101755, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], -[103262, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], -[103401, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], -[103539, "src/Rosetta/codecs/video/Theora/init.luau"], -[103802, "src/Rosetta/codecs/video/Theora/Decoder.luau"], -[105066, "src/Rosetta/codecs/video/Theora/Header.luau"], -[105429, "src/Rosetta/codecs/video/Video/init.luau"], -[105986, "src/Rosetta/codecs/video/Video/Source.luau"], -[106271, "src/Rosetta/containers/Archive.luau"], -[106538, "src/Rosetta/containers/AudioWrap.luau"], -[107041, "src/Rosetta/containers/Avi/init.luau"], -[107593, "src/Rosetta/containers/Chunks.luau"], -[107728, "src/Rosetta/containers/Cpio.luau"], -[108156, "src/Rosetta/containers/Demux.luau"], -[108431, "src/Rosetta/containers/Ebml/init.luau"], -[108744, "src/Rosetta/containers/Fat.luau"], -[109432, "src/Rosetta/containers/Iso9660.luau"], -[109937, "src/Rosetta/containers/IsoBmff/init.luau"], -[110107, "src/Rosetta/containers/IsoBmff/Box.luau"], -[110295, "src/Rosetta/containers/IsoBmff/Demux.luau"], -[111140, "src/Rosetta/containers/IsoBmff/Meta.luau"], -[111661, "src/Rosetta/containers/IsoBmff/Mux.luau"], -[112177, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], -[112294, "src/Rosetta/containers/MacFile.luau"], -[112443, "src/Rosetta/containers/MpegEs.luau"], -[112609, "src/Rosetta/containers/MpegPs/init.luau"], -[112829, "src/Rosetta/containers/MpegTs/init.luau"], -[113621, "src/Rosetta/containers/Ogg/init.luau"], -[114046, "src/Rosetta/containers/Ogg/Mux.luau"], -[114241, "src/Rosetta/containers/Ogg/Page.luau"], -[114410, "src/Rosetta/containers/Riff/init.luau"], -[114727, "src/Rosetta/containers/Tar.luau"], -[115141, "src/Rosetta/containers/Zip/init.luau"], -[115773, "src/Rosetta/core/Adler32.luau"], -[115819, "src/Rosetta/core/Base64.luau"], -[115978, "src/Rosetta/core/Bits.luau"], -[116271, "src/Rosetta/core/Bytes.luau"], -[116798, "src/Rosetta/core/Crc16.luau"], -[116850, "src/Rosetta/core/Crc32.luau"], -[116962, "src/Rosetta/core/Err.luau"], -[117044, "src/Rosetta/core/Input.luau"], -[117120, "src/Rosetta/core/Md5.luau"], -[117279, "src/Rosetta/core/Sniff.luau"], -[117308, "src/Rosetta/data/cbor/init.luau"], -[117407, "src/Rosetta/data/cbor/Codec.luau"], -[117976, "src/Rosetta/data/csv/init.luau"], -[118288, "src/Rosetta/data/ini/init.luau"], -[118534, "src/Rosetta/data/json/init.luau"], -[118626, "src/Rosetta/data/msgpack/init.luau"], -[118715, "src/Rosetta/data/msgpack/Codec.luau"], -[119157, "src/Rosetta/data/nbt/init.luau"], -[119216, "src/Rosetta/data/plist/init.luau"], -[119522, "src/Rosetta/data/plist/Binary.luau"], -[119789, "src/Rosetta/data/snbt/init.luau"], -[119852, "src/Rosetta/data/toml/init.luau"], -[119919, "src/Rosetta/data/toml/Decode.luau"], -[120547, "src/Rosetta/data/toml/Encode.luau"], -[120756, "src/Rosetta/data/xml/init.luau"], -[120812, "src/Rosetta/data/yaml/init.luau"], -[120885, "src/Rosetta/data/yaml/Emit.luau"], -[121175, "src/Rosetta/data/yaml/Parse.luau"], -[122468, "src/Rosetta/font/bdf/init.luau"], -[122757, "src/Rosetta/font/bmfont/init.luau"], -[123184, "src/Rosetta/font/bmfont/Parse.luau"], -[123637, "src/Rosetta/font/eot/init.luau"], -[123869, "src/Rosetta/font/fon/init.luau"], -[124152, "src/Rosetta/font/hershey/init.luau"], -[124347, "src/Rosetta/font/pcf/init.luau"], -[124627, "src/Rosetta/font/psf/init.luau"], -[124947, "src/Rosetta/font/ttf/init.luau"], -[124998, "src/Rosetta/font/type1/init.luau"], -[125357, "src/Rosetta/font/type1/Charstring.luau"], -[125635, "src/Rosetta/font/woff/init.luau"], -[125767, "src/Rosetta/font/woff2/init.luau"], -[125824, "src/Rosetta/font/woff2/Rebuild.luau"], -[126364, "src/Rosetta/host/init.luau"], -[126409, "src/Rosetta/host/Love.luau"], -[126552, "src/Rosetta/host/LuaJIT.luau"], -[126602, "src/Rosetta/host/Luau.luau"], -[126625, "src/Rosetta/host/Roblox.luau"], -[126984, "src/Rosetta/image/ani/init.luau"], -[127164, "src/Rosetta/image/blp/init.luau"], -[127422, "src/Rosetta/image/bmp/init.luau"], -[127837, "src/Rosetta/image/dds/init.luau"], -[128320, "src/Rosetta/image/exr/init.luau"], -[129080, "src/Rosetta/image/exr/Codec.luau"], -[129191, "src/Rosetta/image/exr/Piz.luau"], -[129548, "src/Rosetta/image/gif/init.luau"], -[130064, "src/Rosetta/image/gif/Decode.luau"], -[130127, "src/Rosetta/image/hdr/init.luau"], -[130356, "src/Rosetta/image/hdr/Codec.luau"], -[130567, "src/Rosetta/image/icns/init.luau"], -[130898, "src/Rosetta/image/ico/init.luau"], -[131175, "src/Rosetta/image/ico/Dib.luau"], -[131270, "src/Rosetta/image/ilbm/init.luau"], -[131589, "src/Rosetta/image/jpeg/init.luau"], -[131725, "src/Rosetta/image/ktx/init.luau"], -[132385, "src/Rosetta/image/pcx/init.luau"], -[132649, "src/Rosetta/image/png/init.luau"], -[133229, "src/Rosetta/image/png/Apng.luau"], -[133309, "src/Rosetta/image/png/Decode.luau"], -[133549, "src/Rosetta/image/png/Encode.luau"], -[133704, "src/Rosetta/image/pnm/init.luau"], -[134082, "src/Rosetta/image/pnm/Codec.luau"], -[134359, "src/Rosetta/image/qoi/init.luau"], -[134481, "src/Rosetta/image/qoi/Codec.luau"], -[134631, "src/Rosetta/image/sgi/init.luau"], -[134916, "src/Rosetta/image/sunras/init.luau"], -[135162, "src/Rosetta/image/tga/init.luau"], -[135432, "src/Rosetta/image/tga/Codec.luau"], -[135584, "src/Rosetta/image/tiff/init.luau"], -[136411, "src/Rosetta/image/tiff/Pixels.luau"], -[136801, "src/Rosetta/image/tim/init.luau"], -[137043, "src/Rosetta/image/vtf/init.luau"], -[137278, "src/Rosetta/image/webp/init.luau"], -[137888, "src/Rosetta/image/webp/Alpha.luau"], -[137964, "src/Rosetta/image/webp/Anim.luau"], -[138119, "src/Rosetta/image/xbm/init.luau"], -[138280, "src/Rosetta/image/xpm/init.luau"], -[138548, "src/Rosetta/image/xpm/Names.luau"], -[138604, "src/Rosetta/layered/aseprite/init.luau"], -[139342, "src/Rosetta/layered/ora/init.luau"], -[139629, "src/Rosetta/layered/psd/init.luau"], -[140364, "src/Rosetta/layered/psd/Channels.luau"], -[140716, "src/Rosetta/model/3ds/init.luau"], -[140799, "src/Rosetta/model/3ds/Build.luau"], -[141446, "src/Rosetta/model/3ds/Read.luau"], -[141942, "src/Rosetta/model/3ds/Write.luau"], -[142747, "src/Rosetta/model/3mf/init.luau"], -[142829, "src/Rosetta/model/3mf/Read.luau"], -[143417, "src/Rosetta/model/3mf/Write.luau"], -[143822, "src/Rosetta/model/b3d/init.luau"], -[143877, "src/Rosetta/model/b3d/Read.luau"], -[144448, "src/Rosetta/model/bsp/init.luau"], -[144593, "src/Rosetta/model/bsp/Brush.luau"], -[144871, "src/Rosetta/model/bsp/Quake3.luau"], -[145126, "src/Rosetta/model/dae/init.luau"], -[145315, "src/Rosetta/model/dae/Math.luau"], -[145362, "src/Rosetta/model/dae/Read.luau"], -[147212, "src/Rosetta/model/dae/Write.luau"], -[147581, "src/Rosetta/model/fbx/init.luau"], -[147729, "src/Rosetta/model/fbx/Ascii.luau"], -[147999, "src/Rosetta/model/fbx/Binary.luau"], -[148454, "src/Rosetta/model/fbx/Read.luau"], -[149816, "src/Rosetta/model/fbx/Write.luau"], -[150801, "src/Rosetta/model/fbx/Xform.luau"], -[150842, "src/Rosetta/model/gltf/init.luau"], -[151079, "src/Rosetta/model/gltf/Pack.luau"], -[151148, "src/Rosetta/model/gltf/Read.luau"], -[151879, "src/Rosetta/model/gltf/Write.luau"], -[152559, "src/Rosetta/model/iqm/init.luau"], -[152635, "src/Rosetta/model/iqm/Read.luau"], -[152990, "src/Rosetta/model/iqm/Write.luau"], -[153677, "src/Rosetta/model/ldraw/init.luau"], -[153755, "src/Rosetta/model/ldraw/Colors.luau"], -[154073, "src/Rosetta/model/ldraw/Read.luau"], -[154650, "src/Rosetta/model/lwo/init.luau"], -[154726, "src/Rosetta/model/lwo/Build.luau"], -[155188, "src/Rosetta/model/lwo/Parse.luau"], -[155731, "src/Rosetta/model/mca/init.luau"], -[156073, "src/Rosetta/model/mca/Chunk.luau"], -[156206, "src/Rosetta/model/mca/Lz4Block.luau"], -[156276, "src/Rosetta/model/md2/init.luau"], -[156475, "src/Rosetta/model/md3/init.luau"], -[156703, "src/Rosetta/model/md5/init.luau"], -[156784, "src/Rosetta/model/md5/Read.luau"], -[157217, "src/Rosetta/model/mdl/init.luau"], -[157299, "src/Rosetta/model/mdl/HalfLife.luau"], -[157627, "src/Rosetta/model/mdl/Quake.luau"], -[157845, "src/Rosetta/model/ms3d/init.luau"], -[157917, "src/Rosetta/model/ms3d/Read.luau"], -[158363, "src/Rosetta/model/ms3d/Write.luau"], -[158832, "src/Rosetta/model/obj/init.luau"], -[159574, "src/Rosetta/model/obj/Mtl.luau"], -[159861, "src/Rosetta/model/off/init.luau"], -[160323, "src/Rosetta/model/ply/init.luau"], -[161428, "src/Rosetta/model/ply/Binary.luau"], -[161629, "src/Rosetta/model/pmx/init.luau"], -[161698, "src/Rosetta/model/pmx/Build.luau"], -[161994, "src/Rosetta/model/pmx/Pmd.luau"], -[162329, "src/Rosetta/model/pmx/Read.luau"], -[162733, "src/Rosetta/model/qb/init.luau"], -[163126, "src/Rosetta/model/rbxm/init.luau"], -[163718, "src/Rosetta/model/rbxmx/init.luau"], -[164371, "src/Rosetta/model/robloxmesh/init.luau"], -[165030, "src/Rosetta/model/robloxmesh/Parse.luau"], -[165487, "src/Rosetta/model/robloxmesh/Write.luau"], -[165596, "src/Rosetta/model/schematic/init.luau"], -[165917, "src/Rosetta/model/schematic/Common.luau"], -[166037, "src/Rosetta/model/schematic/Litematic.luau"], -[166248, "src/Rosetta/model/schematic/Mcedit.luau"], -[166492, "src/Rosetta/model/schematic/Sponge.luau"], -[166621, "src/Rosetta/model/smd/init.luau"], -[166688, "src/Rosetta/model/smd/Read.luau"], -[166957, "src/Rosetta/model/smd/Write.luau"], -[167200, "src/Rosetta/model/stl/init.luau"], -[167650, "src/Rosetta/model/stl/Decode.luau"], -[167724, "src/Rosetta/model/usda/init.luau"], -[167933, "src/Rosetta/model/usda/Build.luau"], -[169211, "src/Rosetta/model/usda/Parse.luau"], -[170009, "src/Rosetta/model/usda/Write.luau"], -[170826, "src/Rosetta/model/vox/init.luau"], -[171712, "src/Rosetta/model/vox/Grid.luau"], -[171769, "src/Rosetta/model/vrml/init.luau"], -[171835, "src/Rosetta/model/x/init.luau"], -[171965, "src/Rosetta/model/x/Build.luau"], -[172528, "src/Rosetta/model/x/Parse.luau"], -[172825, "src/Rosetta/model/x3d/init.luau"], -[172903, "src/Rosetta/music/669/init.luau"], -[173109, "src/Rosetta/music/ahx/init.luau"], -[173160, "src/Rosetta/music/far/init.luau"], -[173389, "src/Rosetta/music/hmp/init.luau"], -[173653, "src/Rosetta/music/hvl/init.luau"], -[173704, "src/Rosetta/music/it/init.luau"], -[174122, "src/Rosetta/music/it/Itsex.luau"], -[174238, "src/Rosetta/music/med/init.luau"], -[174885, "src/Rosetta/music/midi/init.luau"], -[175028, "src/Rosetta/music/midi/Smf.luau"], -[175439, "src/Rosetta/music/mod/init.luau"], -[175792, "src/Rosetta/music/mtm/init.luau"], -[176014, "src/Rosetta/music/mus/init.luau"], -[176171, "src/Rosetta/music/okt/init.luau"], -[176452, "src/Rosetta/music/ptm/init.luau"], -[176674, "src/Rosetta/music/s3m/init.luau"], -[176910, "src/Rosetta/music/sf2/init.luau"], -[176953, "src/Rosetta/music/stm/init.luau"], -[177184, "src/Rosetta/music/ult/init.luau"], -[177488, "src/Rosetta/music/umx/init.luau"], -[177704, "src/Rosetta/music/xm/init.luau"], -[178265, "src/Rosetta/music/xmi/init.luau"], -[178473, "src/Rosetta/ops/AudioOps.luau"], -[178922, "src/Rosetta/ops/ImageOps/init.luau"], -[179566, "src/Rosetta/ops/ImageOps/Kernels.luau"], -[180076, "src/Rosetta/ops/LayerOps.luau"], -[180169, "src/Rosetta/ops/MeshOps/init.luau"], -[181205, "src/Rosetta/ops/MeshOps/Greedy.luau"], -[181372, "src/Rosetta/ops/MusicOps.luau"], -[181720, "src/Rosetta/playlist/m3u/init.luau"], -[182073, "src/Rosetta/playlist/pls/init.luau"], -[182251, "src/Rosetta/playlist/xspf/init.luau"], -[182454, "src/Rosetta/subtitle/ass/init.luau"], -[182898, "src/Rosetta/subtitle/srt/init.luau"], -[183071, "src/Rosetta/subtitle/vtt/init.luau"], -[183274, "src/Rosetta/vector/svg/init.luau"], -[183360, "src/Rosetta/vector/svg/Parse.luau"], -[184106, "src/Rosetta/vector/svg/PathData.luau"], -[184474, "src/Rosetta/vector/svg/Render.luau"], -[184891, "src/Rosetta/vector/svg/Style.luau"], -[185263, "src/Rosetta/vector/svg/Write.luau"], -[185463, "src/Rosetta/vector/tiled/init.luau"], -[185643, "src/Rosetta/vector/tiled/Data.luau"], -[185794, "src/Rosetta/vector/tiled/Tmj.luau"], -[186425, "src/Rosetta/vector/tiled/Tmx.luau"], -[187037, "src/Rosetta/video/avi/init.luau"], -[187331, "src/Rosetta/video/fli/init.luau"], -[187482, "src/Rosetta/video/flv/init.luau"], -[187866, "src/Rosetta/video/flv/Amf.luau"], -[188024, "src/Rosetta/video/flv/Mux.luau"], -[188305, "src/Rosetta/video/h264/init.luau"], -[188444, "src/Rosetta/video/mkv/init.luau"], -[188600, "src/Rosetta/video/mkv/Mux.luau"], -[188879, "src/Rosetta/video/mkv/Parse.luau"], -[189600, "src/Rosetta/video/mp4/init.luau"], -[189928, "src/Rosetta/video/mpegps/init.luau"], -[190115, "src/Rosetta/video/mpegts/init.luau"], -[190353, "src/Rosetta/video/ogv/init.luau"], -[190748, "src/Rosetta/video/smk/init.luau"], -[191057, "src/Rosetta/video/smk/Audio.luau"], -[191177, "src/Rosetta/video/y4m/init.luau"] +[69635, "src/Rosetta/codecs/image/Miptex.luau"], +[69851, "src/Rosetta/codecs/image/Pixels.luau"], +[70171, "src/Rosetta/codecs/image/Quantize/init.luau"], +[70630, "src/Rosetta/codecs/image/Raster.luau"], +[71327, "src/Rosetta/codecs/image/Texel.luau"], +[71700, "src/Rosetta/codecs/image/Texture.luau"], +[71845, "src/Rosetta/codecs/image/Vp8/init.luau"], +[71975, "src/Rosetta/codecs/image/Vp8/Decode.luau"], +[73931, "src/Rosetta/codecs/image/Vp8/Predict.luau"], +[74190, "src/Rosetta/codecs/image/Vp8/Tables.luau"], +[74439, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], +[74558, "src/Rosetta/codecs/image/Vp8L/init.luau"], +[74662, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], +[75515, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], +[76467, "src/Rosetta/codecs/image/Yuv.luau"], +[76735, "src/Rosetta/codecs/model/Brush.luau"], +[77375, "src/Rosetta/codecs/model/Draco/init.luau"], +[77707, "src/Rosetta/codecs/model/Draco/Attributes.luau"], +[78176, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], +[79365, "src/Rosetta/codecs/model/Draco/Int64.luau"], +[79514, "src/Rosetta/codecs/model/Draco/KdTree.luau"], +[79873, "src/Rosetta/codecs/model/Draco/Predict.luau"], +[80835, "src/Rosetta/codecs/model/Draco/Reader.luau"], +[81309, "src/Rosetta/codecs/model/Mat4.luau"], +[81568, "src/Rosetta/codecs/model/MeshFlatten.luau"], +[82096, "src/Rosetta/codecs/model/Minecraft/init.luau"], +[82648, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], +[82727, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], +[82834, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], +[83040, "src/Rosetta/codecs/model/Patch.luau"], +[83164, "src/Rosetta/codecs/model/Polygon.luau"], +[83398, "src/Rosetta/codecs/model/Rbx/init.luau"], +[83635, "src/Rosetta/codecs/model/Rbx/Binary.luau"], +[84389, "src/Rosetta/codecs/model/Rig.luau"], +[84632, "src/Rosetta/codecs/model/Sampler.luau"], +[84792, "src/Rosetta/codecs/model/Vrml/init.luau"], +[84940, "src/Rosetta/codecs/model/Vrml/Build.luau"], +[85514, "src/Rosetta/codecs/model/Vrml/Fields.luau"], +[85677, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], +[86426, "src/Rosetta/codecs/model/Vrml/Parse.luau"], +[86948, "src/Rosetta/codecs/model/Vrml/Write.luau"], +[87675, "src/Rosetta/codecs/model/Vrml/Xml.luau"], +[87907, "src/Rosetta/codecs/text/Json/init.luau"], +[88176, "src/Rosetta/codecs/text/Json/Decode.luau"], +[88590, "src/Rosetta/codecs/text/Json/Encode.luau"], +[88892, "src/Rosetta/codecs/text/Nbt/init.luau"], +[89245, "src/Rosetta/codecs/text/Nbt/Binary.luau"], +[89937, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], +[90577, "src/Rosetta/codecs/text/Nbt/Value.luau"], +[90815, "src/Rosetta/codecs/text/Text/init.luau"], +[90906, "src/Rosetta/codecs/text/Url/init.luau"], +[91111, "src/Rosetta/codecs/text/Xml/init.luau"], +[91514, "src/Rosetta/codecs/text/Xml/Parse.luau"], +[92254, "src/Rosetta/codecs/video/Dsp.luau"], +[92977, "src/Rosetta/codecs/video/H263/init.luau"], +[93133, "src/Rosetta/codecs/video/H263/Decoder.luau"], +[93991, "src/Rosetta/codecs/video/H263/Tables.luau"], +[94194, "src/Rosetta/codecs/video/H264/init.luau"], +[94567, "src/Rosetta/codecs/video/H264/Bitstream.luau"], +[94842, "src/Rosetta/codecs/video/H264/Cabac.luau"], +[95973, "src/Rosetta/codecs/video/H264/Cavlc.luau"], +[96741, "src/Rosetta/codecs/video/H264/Deblock.luau"], +[96999, "src/Rosetta/codecs/video/H264/Decoder.luau"], +[98008, "src/Rosetta/codecs/video/H264/Inter.luau"], +[98262, "src/Rosetta/codecs/video/H264/Intra.luau"], +[98669, "src/Rosetta/codecs/video/H264/Mb.luau"], +[99575, "src/Rosetta/codecs/video/H264/Params.luau"], +[100022, "src/Rosetta/codecs/video/H264/Slice.luau"], +[100273, "src/Rosetta/codecs/video/H264/Tables.luau"], +[100314, "src/Rosetta/codecs/video/H264/Transform.luau"], +[100479, "src/Rosetta/codecs/video/Legacy/init.luau"], +[100677, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], +[100974, "src/Rosetta/codecs/video/Legacy/Flic.luau"], +[101341, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], +[101459, "src/Rosetta/codecs/video/Legacy/Picture.luau"], +[101567, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], +[101840, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], +[102235, "src/Rosetta/codecs/video/Legacy/Smc.luau"], +[102412, "src/Rosetta/codecs/video/Mpeg1/init.luau"], +[102424, "src/Rosetta/codecs/video/Mpeg2/init.luau"], +[102791, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], +[104298, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], +[104437, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], +[104575, "src/Rosetta/codecs/video/Theora/init.luau"], +[104838, "src/Rosetta/codecs/video/Theora/Decoder.luau"], +[106102, "src/Rosetta/codecs/video/Theora/Header.luau"], +[106465, "src/Rosetta/codecs/video/Video/init.luau"], +[107022, "src/Rosetta/codecs/video/Video/Source.luau"], +[107307, "src/Rosetta/containers/Archive.luau"], +[107574, "src/Rosetta/containers/AudioWrap.luau"], +[108077, "src/Rosetta/containers/Avi/init.luau"], +[108629, "src/Rosetta/containers/Chunks.luau"], +[108764, "src/Rosetta/containers/Cpio.luau"], +[109192, "src/Rosetta/containers/Demux.luau"], +[109467, "src/Rosetta/containers/Ebml/init.luau"], +[109780, "src/Rosetta/containers/Fat.luau"], +[110468, "src/Rosetta/containers/Iso9660.luau"], +[110973, "src/Rosetta/containers/IsoBmff/init.luau"], +[111143, "src/Rosetta/containers/IsoBmff/Box.luau"], +[111331, "src/Rosetta/containers/IsoBmff/Demux.luau"], +[112176, "src/Rosetta/containers/IsoBmff/Meta.luau"], +[112697, "src/Rosetta/containers/IsoBmff/Mux.luau"], +[113213, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], +[113330, "src/Rosetta/containers/MacFile.luau"], +[113479, "src/Rosetta/containers/MpegEs.luau"], +[113645, "src/Rosetta/containers/MpegPs/init.luau"], +[113865, "src/Rosetta/containers/MpegTs/init.luau"], +[114657, "src/Rosetta/containers/Ogg/init.luau"], +[115082, "src/Rosetta/containers/Ogg/Mux.luau"], +[115277, "src/Rosetta/containers/Ogg/Page.luau"], +[115446, "src/Rosetta/containers/Riff/init.luau"], +[115763, "src/Rosetta/containers/Tar.luau"], +[116177, "src/Rosetta/containers/Zip/init.luau"], +[116809, "src/Rosetta/core/Adler32.luau"], +[116855, "src/Rosetta/core/Base64.luau"], +[117014, "src/Rosetta/core/Bits.luau"], +[117307, "src/Rosetta/core/Bytes.luau"], +[117834, "src/Rosetta/core/Crc16.luau"], +[117886, "src/Rosetta/core/Crc32.luau"], +[117998, "src/Rosetta/core/Err.luau"], +[118080, "src/Rosetta/core/Input.luau"], +[118156, "src/Rosetta/core/Md5.luau"], +[118315, "src/Rosetta/core/Sniff.luau"], +[118344, "src/Rosetta/data/cbor/init.luau"], +[118443, "src/Rosetta/data/cbor/Codec.luau"], +[119012, "src/Rosetta/data/csv/init.luau"], +[119324, "src/Rosetta/data/ini/init.luau"], +[119570, "src/Rosetta/data/json/init.luau"], +[119662, "src/Rosetta/data/msgpack/init.luau"], +[119751, "src/Rosetta/data/msgpack/Codec.luau"], +[120193, "src/Rosetta/data/nbt/init.luau"], +[120252, "src/Rosetta/data/plist/init.luau"], +[120558, "src/Rosetta/data/plist/Binary.luau"], +[120825, "src/Rosetta/data/snbt/init.luau"], +[120888, "src/Rosetta/data/toml/init.luau"], +[120955, "src/Rosetta/data/toml/Decode.luau"], +[121583, "src/Rosetta/data/toml/Encode.luau"], +[121792, "src/Rosetta/data/xml/init.luau"], +[121848, "src/Rosetta/data/yaml/init.luau"], +[121921, "src/Rosetta/data/yaml/Emit.luau"], +[122211, "src/Rosetta/data/yaml/Parse.luau"], +[123504, "src/Rosetta/font/bdf/init.luau"], +[123793, "src/Rosetta/font/bmfont/init.luau"], +[124220, "src/Rosetta/font/bmfont/Parse.luau"], +[124673, "src/Rosetta/font/eot/init.luau"], +[124905, "src/Rosetta/font/fon/init.luau"], +[125188, "src/Rosetta/font/hershey/init.luau"], +[125383, "src/Rosetta/font/pcf/init.luau"], +[125663, "src/Rosetta/font/psf/init.luau"], +[125983, "src/Rosetta/font/ttf/init.luau"], +[126034, "src/Rosetta/font/type1/init.luau"], +[126393, "src/Rosetta/font/type1/Charstring.luau"], +[126671, "src/Rosetta/font/woff/init.luau"], +[126803, "src/Rosetta/font/woff2/init.luau"], +[126860, "src/Rosetta/font/woff2/Rebuild.luau"], +[127400, "src/Rosetta/host/init.luau"], +[127445, "src/Rosetta/host/Love.luau"], +[127588, "src/Rosetta/host/LuaJIT.luau"], +[127638, "src/Rosetta/host/Luau.luau"], +[127661, "src/Rosetta/host/Roblox.luau"], +[128020, "src/Rosetta/image/ani/init.luau"], +[128200, "src/Rosetta/image/blp/init.luau"], +[128458, "src/Rosetta/image/bmp/init.luau"], +[128873, "src/Rosetta/image/dds/init.luau"], +[129356, "src/Rosetta/image/exr/init.luau"], +[130116, "src/Rosetta/image/exr/Codec.luau"], +[130227, "src/Rosetta/image/exr/Piz.luau"], +[130584, "src/Rosetta/image/gif/init.luau"], +[131100, "src/Rosetta/image/gif/Decode.luau"], +[131163, "src/Rosetta/image/hdr/init.luau"], +[131392, "src/Rosetta/image/hdr/Codec.luau"], +[131603, "src/Rosetta/image/icns/init.luau"], +[131934, "src/Rosetta/image/ico/init.luau"], +[132211, "src/Rosetta/image/ico/Dib.luau"], +[132306, "src/Rosetta/image/ilbm/init.luau"], +[132625, "src/Rosetta/image/jpeg/init.luau"], +[132761, "src/Rosetta/image/ktx/init.luau"], +[133421, "src/Rosetta/image/pcx/init.luau"], +[133685, "src/Rosetta/image/png/init.luau"], +[134265, "src/Rosetta/image/png/Apng.luau"], +[134345, "src/Rosetta/image/png/Decode.luau"], +[134585, "src/Rosetta/image/png/Encode.luau"], +[134740, "src/Rosetta/image/pnm/init.luau"], +[135118, "src/Rosetta/image/pnm/Codec.luau"], +[135395, "src/Rosetta/image/qoi/init.luau"], +[135517, "src/Rosetta/image/qoi/Codec.luau"], +[135667, "src/Rosetta/image/sgi/init.luau"], +[135952, "src/Rosetta/image/sunras/init.luau"], +[136198, "src/Rosetta/image/tga/init.luau"], +[136468, "src/Rosetta/image/tga/Codec.luau"], +[136620, "src/Rosetta/image/tiff/init.luau"], +[137447, "src/Rosetta/image/tiff/Pixels.luau"], +[137837, "src/Rosetta/image/tim/init.luau"], +[138079, "src/Rosetta/image/vtf/init.luau"], +[138314, "src/Rosetta/image/webp/init.luau"], +[138924, "src/Rosetta/image/webp/Alpha.luau"], +[139000, "src/Rosetta/image/webp/Anim.luau"], +[139155, "src/Rosetta/image/xbm/init.luau"], +[139316, "src/Rosetta/image/xpm/init.luau"], +[139584, "src/Rosetta/image/xpm/Names.luau"], +[139640, "src/Rosetta/layered/aseprite/init.luau"], +[140378, "src/Rosetta/layered/ora/init.luau"], +[140665, "src/Rosetta/layered/psd/init.luau"], +[141400, "src/Rosetta/layered/psd/Channels.luau"], +[141752, "src/Rosetta/model/3ds/init.luau"], +[141835, "src/Rosetta/model/3ds/Build.luau"], +[142482, "src/Rosetta/model/3ds/Read.luau"], +[142978, "src/Rosetta/model/3ds/Write.luau"], +[143783, "src/Rosetta/model/3mf/init.luau"], +[143865, "src/Rosetta/model/3mf/Read.luau"], +[144453, "src/Rosetta/model/3mf/Write.luau"], +[144858, "src/Rosetta/model/b3d/init.luau"], +[144913, "src/Rosetta/model/b3d/Read.luau"], +[145484, "src/Rosetta/model/bsp/init.luau"], +[145629, "src/Rosetta/model/bsp/Brush.luau"], +[145892, "src/Rosetta/model/bsp/Quake3.luau"], +[146120, "src/Rosetta/model/dae/init.luau"], +[146309, "src/Rosetta/model/dae/Math.luau"], +[146356, "src/Rosetta/model/dae/Read.luau"], +[148206, "src/Rosetta/model/dae/Write.luau"], +[148575, "src/Rosetta/model/fbx/init.luau"], +[148723, "src/Rosetta/model/fbx/Ascii.luau"], +[148993, "src/Rosetta/model/fbx/Binary.luau"], +[149448, "src/Rosetta/model/fbx/Read.luau"], +[150810, "src/Rosetta/model/fbx/Write.luau"], +[151795, "src/Rosetta/model/fbx/Xform.luau"], +[151836, "src/Rosetta/model/gltf/init.luau"], +[152073, "src/Rosetta/model/gltf/Pack.luau"], +[152142, "src/Rosetta/model/gltf/Read.luau"], +[152873, "src/Rosetta/model/gltf/Write.luau"], +[153553, "src/Rosetta/model/iqm/init.luau"], +[153629, "src/Rosetta/model/iqm/Read.luau"], +[153984, "src/Rosetta/model/iqm/Write.luau"], +[154671, "src/Rosetta/model/ldraw/init.luau"], +[154749, "src/Rosetta/model/ldraw/Colors.luau"], +[155067, "src/Rosetta/model/ldraw/Read.luau"], +[155644, "src/Rosetta/model/lwo/init.luau"], +[155720, "src/Rosetta/model/lwo/Build.luau"], +[156182, "src/Rosetta/model/lwo/Parse.luau"], +[156725, "src/Rosetta/model/mca/init.luau"], +[157067, "src/Rosetta/model/mca/Chunk.luau"], +[157200, "src/Rosetta/model/mca/Lz4Block.luau"], +[157270, "src/Rosetta/model/md2/init.luau"], +[157469, "src/Rosetta/model/md3/init.luau"], +[157697, "src/Rosetta/model/md5/init.luau"], +[157778, "src/Rosetta/model/md5/Read.luau"], +[158211, "src/Rosetta/model/mdl/init.luau"], +[158293, "src/Rosetta/model/mdl/HalfLife.luau"], +[158621, "src/Rosetta/model/mdl/Quake.luau"], +[158839, "src/Rosetta/model/ms3d/init.luau"], +[158911, "src/Rosetta/model/ms3d/Read.luau"], +[159357, "src/Rosetta/model/ms3d/Write.luau"], +[159826, "src/Rosetta/model/obj/init.luau"], +[160568, "src/Rosetta/model/obj/Mtl.luau"], +[160855, "src/Rosetta/model/off/init.luau"], +[161317, "src/Rosetta/model/ply/init.luau"], +[162422, "src/Rosetta/model/ply/Binary.luau"], +[162623, "src/Rosetta/model/pmx/init.luau"], +[162692, "src/Rosetta/model/pmx/Build.luau"], +[162988, "src/Rosetta/model/pmx/Pmd.luau"], +[163323, "src/Rosetta/model/pmx/Read.luau"], +[163727, "src/Rosetta/model/qb/init.luau"], +[164120, "src/Rosetta/model/rbxm/init.luau"], +[164712, "src/Rosetta/model/rbxmx/init.luau"], +[165365, "src/Rosetta/model/robloxmesh/init.luau"], +[166024, "src/Rosetta/model/robloxmesh/Parse.luau"], +[166481, "src/Rosetta/model/robloxmesh/Write.luau"], +[166590, "src/Rosetta/model/schematic/init.luau"], +[166911, "src/Rosetta/model/schematic/Common.luau"], +[167031, "src/Rosetta/model/schematic/Litematic.luau"], +[167242, "src/Rosetta/model/schematic/Mcedit.luau"], +[167486, "src/Rosetta/model/schematic/Sponge.luau"], +[167615, "src/Rosetta/model/smd/init.luau"], +[167682, "src/Rosetta/model/smd/Read.luau"], +[167951, "src/Rosetta/model/smd/Write.luau"], +[168194, "src/Rosetta/model/stl/init.luau"], +[168644, "src/Rosetta/model/stl/Decode.luau"], +[168718, "src/Rosetta/model/usda/init.luau"], +[168927, "src/Rosetta/model/usda/Build.luau"], +[170205, "src/Rosetta/model/usda/Parse.luau"], +[171003, "src/Rosetta/model/usda/Write.luau"], +[171820, "src/Rosetta/model/vox/init.luau"], +[172706, "src/Rosetta/model/vox/Grid.luau"], +[172763, "src/Rosetta/model/vrml/init.luau"], +[172829, "src/Rosetta/model/x/init.luau"], +[172959, "src/Rosetta/model/x/Build.luau"], +[173522, "src/Rosetta/model/x/Parse.luau"], +[173819, "src/Rosetta/model/x3d/init.luau"], +[173897, "src/Rosetta/music/669/init.luau"], +[174103, "src/Rosetta/music/ahx/init.luau"], +[174154, "src/Rosetta/music/far/init.luau"], +[174383, "src/Rosetta/music/hmp/init.luau"], +[174647, "src/Rosetta/music/hvl/init.luau"], +[174698, "src/Rosetta/music/it/init.luau"], +[175116, "src/Rosetta/music/it/Itsex.luau"], +[175232, "src/Rosetta/music/med/init.luau"], +[175879, "src/Rosetta/music/midi/init.luau"], +[176022, "src/Rosetta/music/midi/Smf.luau"], +[176433, "src/Rosetta/music/mod/init.luau"], +[176786, "src/Rosetta/music/mtm/init.luau"], +[177008, "src/Rosetta/music/mus/init.luau"], +[177165, "src/Rosetta/music/okt/init.luau"], +[177446, "src/Rosetta/music/ptm/init.luau"], +[177668, "src/Rosetta/music/s3m/init.luau"], +[177904, "src/Rosetta/music/sf2/init.luau"], +[177947, "src/Rosetta/music/stm/init.luau"], +[178178, "src/Rosetta/music/ult/init.luau"], +[178482, "src/Rosetta/music/umx/init.luau"], +[178698, "src/Rosetta/music/xm/init.luau"], +[179259, "src/Rosetta/music/xmi/init.luau"], +[179467, "src/Rosetta/ops/AudioOps.luau"], +[179916, "src/Rosetta/ops/ImageOps/init.luau"], +[180560, "src/Rosetta/ops/ImageOps/Kernels.luau"], +[181070, "src/Rosetta/ops/LayerOps.luau"], +[181163, "src/Rosetta/ops/MeshOps/init.luau"], +[182199, "src/Rosetta/ops/MeshOps/Greedy.luau"], +[182366, "src/Rosetta/ops/MusicOps.luau"], +[182714, "src/Rosetta/playlist/m3u/init.luau"], +[183067, "src/Rosetta/playlist/pls/init.luau"], +[183245, "src/Rosetta/playlist/xspf/init.luau"], +[183448, "src/Rosetta/subtitle/ass/init.luau"], +[183892, "src/Rosetta/subtitle/srt/init.luau"], +[184065, "src/Rosetta/subtitle/vtt/init.luau"], +[184268, "src/Rosetta/vector/svg/init.luau"], +[184354, "src/Rosetta/vector/svg/Parse.luau"], +[185100, "src/Rosetta/vector/svg/PathData.luau"], +[185468, "src/Rosetta/vector/svg/Render.luau"], +[185885, "src/Rosetta/vector/svg/Style.luau"], +[186257, "src/Rosetta/vector/svg/Write.luau"], +[186457, "src/Rosetta/vector/tiled/init.luau"], +[186637, "src/Rosetta/vector/tiled/Data.luau"], +[186788, "src/Rosetta/vector/tiled/Tmj.luau"], +[187419, "src/Rosetta/vector/tiled/Tmx.luau"], +[188031, "src/Rosetta/video/avi/init.luau"], +[188325, "src/Rosetta/video/fli/init.luau"], +[188476, "src/Rosetta/video/flv/init.luau"], +[188860, "src/Rosetta/video/flv/Amf.luau"], +[189018, "src/Rosetta/video/flv/Mux.luau"], +[189299, "src/Rosetta/video/h264/init.luau"], +[189438, "src/Rosetta/video/mkv/init.luau"], +[189594, "src/Rosetta/video/mkv/Mux.luau"], +[189873, "src/Rosetta/video/mkv/Parse.luau"], +[190594, "src/Rosetta/video/mp4/init.luau"], +[190922, "src/Rosetta/video/mpegps/init.luau"], +[191109, "src/Rosetta/video/mpegts/init.luau"], +[191347, "src/Rosetta/video/ogv/init.luau"], +[191742, "src/Rosetta/video/smk/init.luau"], +[192051, "src/Rosetta/video/smk/Audio.luau"], +[192171, "src/Rosetta/video/y4m/init.luau"] ] diff --git a/build/rosetta.lua b/build/rosetta.lua index 18bac8a..652a723 100644 --- a/build/rosetta.lua +++ b/build/rosetta.lua @@ -2243,7 +2243,7 @@ local list= { path = "model/bsp", extensions = { "bsp" }, mime = { "model/x-bsp" }, - deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels" }, + deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels", "codecs/image/Miptex", "codecs/model/Patch" }, caps = { decode = true, encode = false, variants = { "quake", "halflife", "quake2", "quake3" }, lightmaps = "quake3" }, load = function() return __include("model/bsp") @@ -70264,12 +70264,229 @@ end return Yuv end +__FILES["codecs/image/Miptex"] = function() +local __compat = __compat local buffer, type, __iter = __compat.buffer, __compat.type, __compat.__iter --!strict +-- codecs/image/Miptex: Quake / GoldSrc mip textures and the WAD2 / WAD3 lump directory, read and write. +-- miptex_t of bspfile.h: name[16], width, height, offsets[4], four 8-bit mip levels; GoldSrc adds u16 count + count * 3 +-- palette bytes after mip 3. wad.h: "WAD2" / "WAD3", numlumps, infotableofs; 32-byte lumpinfo_t. No code taken. +local Types = __include("Types") +local Pixels = __include("codecs/image/Pixels") +local Quantize = __include("codecs/image/Quantize") + +local Miptex = {} + +local readu8, readu32, readi32 = buffer.readu8, buffer.readu32, buffer.readi32 + +-- lumpinfo_t types (wad.h TYP_*; WAD3: 0x43 is a miptex with its palette, 0x46 a font) + + + + + + + + + + +Miptex.TYPES = table.freeze({ palette = 0x40, qtex = 0x41, qpic = 0x42, sound = 0x43, miptex = 0x44, font = 0x46 }) + +local function cstr(b, at, n) +return (string.match(buffer.readstring(b, at, n), "^[^%z]*")) +end + +function Miptex.header(b, at, size) +if at < 0 or size < 40 or at + 40 > buffer.len(b) then + return nil, "truncated miptex header" + end + local w, h = readu32(b, at + 16), readu32(b, at + 20) + local offs = { readu32(b, at + 24), readu32(b, at + 28), readu32(b, at + 32), readu32(b, at + 36) } + return { name = cstr(b, at, 16), width = w, height = h, offsets = offs }, nil +end + +-- the GoldSrc palette after mip 3, as a 1024-byte rgba8 palette, or nil when it is missing / out of range +function Miptex.ownPalette(b, at, size, hd) +local w, h = hd.width, hd.height + local p = hd.offsets[4] + (math.floor(w / 8)) * (math.floor(h / 8)) + if hd.offsets[4] == 0 or p + 2 > size then + return nil + end + local n = buffer.readu16(b, at + p) + if n == 0 or n > 256 or p + 2 + n * 3 > size then + return nil + end + return Pixels.palette(b, at + p + 2, n) +end + +-- decodes one mip level to rgba8; without pixels (offsets 0: the texture lives in a WAD) returns nil, "external" +function Miptex.decode(b, at, size, opts) +local hd, err = Miptex.header(b, at, size) + if not hd then + return nil, err + end + local mip = math.clamp(math.floor(opts and opts.mip or 0), 0, 3) + local w, h = math.floor(hd.width / (2 ^ mip)), math.floor(hd.height / (2 ^ mip) +) if hd.width == 0 or hd.height == 0 or w == 0 or h == 0 then + return nil, "empty miptex" + end + if hd.width * hd.height > (opts and opts.maxPixels or 2 ^ 24) then + return nil, "limit: miptex " .. hd.width .. " x " .. hd.height + end + local off = hd.offsets[mip + 1] + if off == 0 then + return nil, "external" + end + if off + w * h > size or at + off + w * h > buffer.len(b) then + return nil, "truncated miptex pixels" + end + local own = (opts and opts.goldsrc and{(Miptex.ownPalette(b, at, size, hd) )}or{nil +})[1] local pal = own or (opts and opts.palette) or Pixels.grey() + local keyed = (opts and opts.keyed ~= nil and{opts.keyed }or{(string.sub(hd.name, 1, 1) == "{" +)})[1] if keyed then + pal = Pixels.keyed(pal, 255) + end + local img = Types.Image.new(w, h) + Pixels.indexed(b, at + off, w, 8, img.pixels, w, h, true, pal) + img.meta.source = { format = "miptex", name = hd.name, mip = mip, palette = own ~= nil or (opts ~= nil and opts.palette ~= nil), keyed = keyed or nil } + return img, nil +end + +local function halve(px, w, h) +local w2, h2 = math.max(1, math.floor(w / 2)), math.max(1, math.floor(h / 2)) + local out = buffer.create(w2 * h2 * 4) + for y = 0, h2 - 1 do + for x = 0, w2 - 1 do + for c = 0, 3 do + local s = 0 + for dy = 0, 1 do + for dx = 0, 1 do + local sx, sy = math.min(x * 2 + dx, w - 1), math.min(y * 2 + dy, h - 1) + s =s+ readu8(px, (sy * w + sx) * 4 + c) + end + end + buffer.writeu8(out, (y * w2 + x) * 4 + c, math.floor((s + 2) / 4)) + end + end + end + return out, w2, h2 +end + +-- an rgba8 image -> a miptex_t with four mip levels (box filtered, mapped to the nearest palette entry); goldsrc +-- appends the palette. palette: 1024-byte rgba8; without it (GoldSrc only) a 256-colour median-cut palette is made. +function Miptex.encode(img, name, palette, goldsrc) +local w, h = img.width, img.height + if w <= 0 or h <= 0 or w % 16 ~= 0 or h % 16 ~= 0 then + return nil, "miptex sizes must be multiples of 16" + end + if #name > 15 then + return nil, "miptex name over 15 bytes" + end + local colors +if palette then + colors = Pixels.colorList(palette) + elseif goldsrc then + colors = Quantize.palette(img.pixels, w, h, 256) + else + return nil, "a Quake miptex needs a palette" + end + local keyed = string.sub(name, 1, 1) == "{" + local levels= {} + local px, lw, lh = img.pixels, w, h + for m = 0, 3 do + if m > 0 then + px, lw, lh = halve(px, lw, lh) + end + local idx = Quantize.map(px, lw, lh, colors, { transparentIndex = keyed and 255 or nil }) + if keyed then + for k = 0, lw * lh - 1 do + if readu8(px, k * 4 + 3) < 128 then + buffer.writeu8(idx, k, 255) + end + end + end + levels[m + 1] = idx + end + local total = 40 + for _, l in __iter(levels) do + total =total+ buffer.len(l) + end + local palAt = total + if goldsrc then + total =total+ (2 + 768 + 2 +) end + local out = buffer.create(total) + buffer.writestring(out, 0, name) + buffer.writeu32(out, 16, w) + buffer.writeu32(out, 20, h) + local o = 40 + for m, l in __iter(levels) do + buffer.writeu32(out, 24 + (m - 1) * 4, o) + buffer.copy(out, o, l) + o =o+ buffer.len(l) + end + if goldsrc then + buffer.writeu16(out, palAt, 256) + for i = 0, 255 do + local c = colors[i + 1] or { 0, 0, 0 } + buffer.writeu8(out, palAt + 2 + i * 3, c[1]) + buffer.writeu8(out, palAt + 3 + i * 3, c[2]) + buffer.writeu8(out, palAt + 4 + i * 3, c[3]) + end + end + return out, nil +end + +-- the lump directory of a WAD2 / WAD3 file (offsets relative to base), or nil, message +function Miptex.wad(b, base, size, maxLumps) +if size < 12 or base + 12 > buffer.len(b) then + return nil, "truncated header", nil + end + local magic = buffer.readstring(b, base, 4) + if magic ~= "WAD2" and magic ~= "WAD3" then + return nil, "bad magic", nil + end + local n, dir = readi32(b, base + 4), readi32(b, base + 8) + if n < 0 or dir < 0 then + return nil, "negative directory field", nil + end + if n > (maxLumps or 1e6) then + return nil, "limit: too many lumps: " .. n, nil + end + if dir + n * 32 > size then + return nil, "truncated directory past the end", nil + end + local out= {} + for i = 0, n - 1 do + local o = base + dir + i * 32 + local at, disk, full = readi32(b, o), readi32(b, o + 4), readi32(b, o + 8) + if at < 0 or disk < 0 or at + disk > size then + return nil, "truncated lump past the end", nil + end + out[i + 1] = { name = cstr(b, o + 16, 16), offset = at, disksize = disk, size = full, type = readu8(b, o + 12), compression = readu8(b, o + 13) } + end + return out, nil, magic +end + +-- the lump named name (case-insensitive, the last one wins as in W_GetLumpinfo) +function Miptex.find(lumps, name) +local want = string.lower(name) + local best= nil + for _, l in __iter(lumps) do + if string.lower(l.name) == want then + best = l + end + end + return best +end + +return Miptex +end __FILES["codecs/image/Pixels"] = function() local __compat = __compat local buffer, bit32 = __compat.buffer, __compat.bit32 --!strict --!native --!optimize 2 --- codecs/image/Pixels: row loops between packed pixel layouts and rgba8 for BMP / DIB. --- Indexed, BGR(A), 5-5-5, bit masks, RLE4 / RLE8. From bmp-luau b86aed6 (same author); the encoder loops are new. +-- codecs/image/Pixels: row loops between packed pixel layouts and rgba8 for BMP / DIB, and palette helpers. +-- Indexed, BGR(A), 5-5-5, bit masks, RLE4 / RLE8; palettes: keyed index (Quake 255), grey ramp, Quake colormap light +-- levels. From bmp-luau b86aed6 (same author); the encoder loops and palette helpers are new. local readu8, readu16, readu32, writeu32, writeu8 = buffer.readu8, buffer.readu16, buffer.readu32, buffer.writeu32, buffer.writeu8 local band, rshift, bor, lshift = bit32.band, bit32.rshift, bit32.bor, bit32.lshift @@ -70526,6 +70743,61 @@ local seen= {} return list, alpha end +-- a 256-entry rgba8 palette (u32 LE per entry) with entry i = { i, i, i, 255 } +function Pixels.grey() +local pal = buffer.create(1024) + for i = 0, 255 do + writeu32(pal, i * 4, 0xFF000000 + i * 0x10101) + end + return pal +end + +-- a copy of a 1024-byte palette with entry index fully transparent (Quake / GoldSrc: index 255 of sprites, qpics and +-- '{' textures) +function Pixels.keyed(pal, index) +local out = buffer.create(1024) + buffer.copy(out, 0, pal, 0, math.min(buffer.len(pal), 1024)) + if index >= 0 and index < 256 then + writeu32(out, index * 4, 0) + end + return out +end + +-- palette (1024 bytes) -> { { r, g, b, a } } for codecs/image/Quantize +function Pixels.colorList(pal, n) +local out= {} + for i = 0, math.clamp(n or 256, 0, math.floor(buffer.len(pal) / 4)) - 1 do + out[i + 1] = { readu8(pal, i * 4), readu8(pal, i * 4 + 1), readu8(pal, i * 4 + 2), readu8(pal, i * 4 + 3) } + end + return out +end + +-- Quake colormap.lmp: rows of 256 palette indices, row 0 brightest .. 63 darkest (32 = unlit); the palette for one +-- light level, or nil past the end of the map +function Pixels.colormap(pal, cmap, base, row) +local o = base + row * 256 + if row < 0 or base < 0 or o + 256 > buffer.len(cmap) then + return nil + end + local out = buffer.create(1024) + for i = 0, 255 do + writeu32(out, i * 4, readu32(pal, readu8(cmap, o + i) * 4)) + end + return out +end + +-- rgba8 palette (1024 bytes) -> 3 * n bytes R, G, B (the Quake / GoldSrc palette layout) +function Pixels.paletteBytes(pal, n) +local m = math.clamp(n or 256, 0, 256) + local out = buffer.create(m * 3) + for i = 0, m - 1 do + writeu8(out, i * 3, readu8(pal, i * 4)) + writeu8(out, i * 3 + 1, readu8(pal, i * 4 + 1)) + writeu8(out, i * 3 + 2, readu8(pal, i * 4 + 2)) + end + return out +end + return Pixels end __FILES["codecs/image/Quantize"] = function() @@ -77092,6 +77364,646 @@ end return Yuv end +__FILES["codecs/model/Brush"] = function() +local __compat = __compat local buffer, __iter = __compat.buffer, __compat.__iter --!strict +--!native +--!optimize 2 +-- codecs/model/Brush: convex plane brushes -> polygons and Scene primitives, with Quake-family texture projection. +-- As qbsp (Quake / ericw-tools; no code taken): a big square on every plane (inside n . p <= d) clipped by the others. +-- Projections: Quake standard (TextureAxisFromPlane + rotate / scale / shift), Valve 220 (explicit U / V axes), Quake +-- III brush primitives (q3map2 ComputeAxisBase + 2 x 3 matrix). Options: merge coplanar faces with one projection +-- (qbsp TryMerge), drop face parts inside / touching other brushes (qbsp CSGFaces; earlier brushes win coplanar ties). +local Types = __include("Types") + +local Brush = {} + +local abs, sqrt, floor, sin, cos, atan2, min, max = math.abs, math.sqrt, math.floor, math.sin, math.cos, math.atan2, math.min, math.max +local writef32, writeu32 = buffer.writef32, buffer.writeu32 + +-- TextureAxisFromPlane's baseaxis table (normal, s axis, t axis per row): floor, ceiling, west, east, south, north + + + + + + + + + + + + + + + + + + + + + + + +local BASEAXIS = { + { 0, 0, 1 }, { 1, 0, 0 }, { 0, -1, 0 }, + { 0, 0, -1 }, { 1, 0, 0 }, { 0, -1, 0 }, + { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, -1 }, + { -1, 0, 0 }, { 0, 1, 0 }, { 0, 0, -1 }, + { 0, 1, 0 }, { 1, 0, 0 }, { 0, 0, -1 }, + { 0, -1, 0 }, { 1, 0, 0 }, { 0, 0, -1 }, +} + +local function snap(x) +local r = floor(x + 0.5) + return (abs(x - r) < 1e-6 and{r }or{x +})[1]end + +-- qbsp PlaneFromPoints: normal = (p1 - p2) x (p3 - p2), the brush lies behind it; nil when the points are colinear +function Brush.planeFromPoints(a, b, c) +local ux, uy, uz = a[1] - b[1], a[2] - b[2], a[3] - b[3] + local vx, vy, vz = c[1] - b[1], c[2] - b[2], c[3] - b[3] + local nx, ny, nz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + local l = sqrt(nx * nx + ny * ny + nz * nz) + if l < 1e-12 then + return nil + end + nx, ny, nz = nx / l, ny / l, nz / l + return { nx, ny, nz, b[1] * nx + b[2] * ny + b[3] * nz } +end + +-- the base axis row (0..5) of TextureAxisFromPlane: the first with the largest dot product (strictly greater) +function Brush.baseAxis(n) +local best, axis = 0, 0 + for i = 0, 5 do + local a = BASEAXIS[i * 3 + 1] + local d = n[1] * a[1] + n[2] * a[2] + n[3] * a[3] + if d > best then + best, axis = d, i + end + end + return axis +end + +-- Quake standard texture vectors (texels): offsets, rotation (degrees), scales (0 = 1) +function Brush.quakeVecs(n, xoff, yoff, rot, xscale, yscale) +local axis = Brush.baseAxis(n) + local s0, t0 = BASEAXIS[axis * 3 + 2], BASEAXIS[axis * 3 + 3] + local vecs = { { s0[1], s0[2], s0[3] }, { t0[1], t0[2], t0[3] } } + local sinv, cosv + if rot == 0 then + sinv, cosv = 0, 1 + elseif rot == 90 then + sinv, cosv = 1, 0 + elseif rot == 180 then + sinv, cosv = 0, -1 + elseif rot == 270 then + sinv, cosv = -1, 0 + else + local ang = rot / 180 * math.pi + sinv, cosv = sin(ang), cos(ang) + end + local sv = vecs[1][1] ~= 0 and 1 or(vecs[1][2] ~= 0 and 2 or 3 +) local tv = vecs[2][1] ~= 0 and 1 or(vecs[2][2] ~= 0 and 2 or 3 +) for i = 1, 2 do + local v = vecs[i] + local ns = cosv * v[sv] - sinv * v[tv] + local nt = sinv * v[sv] + cosv * v[tv] + v[sv], v[tv] = ns, nt + end + local sc = { xscale == 0 and 1 or xscale, yscale == 0 and 1 or yscale } + for i = 1, 2 do + local v = vecs[i] + v[1], v[2], v[3] = v[1] / sc[i], v[2] / sc[i], v[3] / sc[i] + end + vecs[1][4], vecs[2][4] = xoff, yoff + return vecs +end + +-- Valve 220: u / v = axis (x, y, z, offset); the rotation is already in the axes +function Brush.valveVecs(u, v, xscale, yscale) +local su, sv = xscale == 0 and 1 or xscale, yscale == 0 and 1 or yscale + return { { u[1] / su, u[2] / su, u[3] / su, u[4] }, { v[1] / sv, v[2] / sv, v[3] / sv, v[4] } } +end + +-- q3map2 ComputeAxisBase: the texture plane axes of a brush-primitive face +function Brush.axisBase(normal) +local nx, ny, nz = normal[1], normal[2], normal[3] + nx = abs(nx) < 1e-6 and 0 or nx + ny = abs(ny) < 1e-6 and 0 or ny + nz = abs(nz) < 1e-6 and 0 or nz + local rotY = -atan2(nz, sqrt(ny * ny + nx * nx)) + local rotZ = atan2(ny, nx) + return { -sin(rotZ), cos(rotZ), 0 }, { -sin(rotY) * cos(rotZ), -sin(rotY) * sin(rotZ), -cos(rotY) } +end + +-- brush primitives -> texel vectors for a w x h texture (ericw-tools SetTexinfo_BrushPrimitives) +function Brush.bpVecs(normal, m, w, h) +local tx, ty = Brush.axisBase(normal) + local out = {} + for i, size in __iter({ w, h }) do + local r = m[i] + out[i] = { size * (tx[1] * r[1] + ty[1] * r[2]), size * (tx[2] * r[1] + ty[2] * r[2]), size * (tx[3] * r[1] + ty[3] * r[2]), size * r[3] } + end + return out +end + +-- texel vectors -> brush primitives (the inverse of bpVecs for vectors lying in the face plane) +function Brush.vecsToBp(normal, vecs, w, h) +local tx, ty = Brush.axisBase(normal) + local out = {} + for i, size in __iter({ w, h }) do + local v = vecs[i] + out[i] = { + (v[1] * tx[1] + v[2] * tx[2] + v[3] * tx[3]) / size, + (v[1] * ty[1] + v[2] * ty[2] + v[3] * ty[3]) / size, + v[4] / size, + } + end + return out +end + +-- texture coordinates of a point on a face, in texture widths / heights (glTF uv: t grows down the image) +function Brush.uv(face, x, y, z, w, h) +local bp = face.bp + if bp then + local tx, ty = Brush.axisBase(face.plane) + local a = x * tx[1] + y * tx[2] + z * tx[3] + local b = x * ty[1] + y * ty[2] + z * ty[3] + return bp[1][1] * a + bp[1][2] * b + bp[1][3], bp[2][1] * a + bp[2][2] * b + bp[2][3] + end + local v = face.vecs + if v then + local s, t = v[1], v[2] + return (x * s[1] + y * s[2] + z * s[3] + s[4]) / w, (x * t[1] + y * t[2] + z * t[3] + t[4]) / h + end + return 0, 0 +end + +-- qbsp BaseWindingForPlane: a square of half size `size` on the plane, counter-clockwise seen from the front +function Brush.baseWinding(p, size) +local nx, ny, nz, d = p[1], p[2], p[3], p[4] + local ax, ay, az = abs(nx), abs(ny), abs(nz) + local ux, uy, uz = 0, 0, 1 + if az >= ax and az >= ay then + ux, uy, uz = 1, 0, 0 + end + local dv = ux * nx + uy * ny + uz * nz + ux, uy, uz = ux - dv * nx, uy - dv * ny, uz - dv * nz + local l = sqrt(ux * ux + uy * uy + uz * uz) + ux, uy, uz = ux / l * size, uy / l * size, uz / l * size + -- right = up x n, so right x up = n: right -> up turns counter-clockwise about n + local rx, ry, rz = (uy * nz - uz * ny), (uz * nx - ux * nz), (ux * ny - uy * nx) + local ox, oy, oz = nx * d, ny * d, nz * d + return { + ox - rx - ux, oy - ry - uy, oz - rz - uz, + ox + rx - ux, oy + ry - uy, oz + rz - uz, + ox + rx + ux, oy + ry + uy, oz + rz + uz, + ox - rx + ux, oy - ry + uy, oz - rz + uz, + } +end + +-- splits a polygon by a plane: the parts in front and behind (nil when empty), and whether it lies on the plane +function Brush.split(pts, p, eps) +local n = math.floor(#pts / 3 +) local nx, ny, nz, d = p[1], p[2], p[3], p[4] + local dist = (table.create(n, 0) ) +local side = (table.create(n, 0) ) +local front, back = 0, 0 + for i = 0, n - 1 do + local v = pts[i * 3 + 1] * nx + pts[i * 3 + 2] * ny + pts[i * 3 + 3] * nz - d + dist[i + 1] = v + if v > eps then + side[i + 1] = 1 + front =front+ 1 + elseif v < -eps then + side[i + 1] = -1 + back =back+ 1 + end + end + if front == 0 and back == 0 then + return nil, nil, true + end + if front == 0 then + return nil, pts, false + end + if back == 0 then + return pts, nil, false + end + local f, b= {}, {} + for i = 0, n - 1 do + local j = (i + 1) % n + local x, y, z = pts[i * 3 + 1], pts[i * 3 + 2], pts[i * 3 + 3] + local si = side[i + 1] + if si >= 0 then + f[#f + 1], f[#f + 2], f[#f + 3] = x, y, z + end + if si <= 0 then + b[#b + 1], b[#b + 2], b[#b + 3] = x, y, z + end + local sj = side[j + 1] + if si ~= 0 and sj ~= 0 and si ~= sj then + local t = dist[i + 1] / (dist[i + 1] - dist[j + 1]) + local mx, my, mz = x + t * (pts[j * 3 + 1] - x), y + t * (pts[j * 3 + 2] - y), z + t * (pts[j * 3 + 3] - z) + -- exact on axis-aligned planes, as qbsp + if nx == 1 then + mx = d + elseif nx == -1 then + mx = -d + end + if ny == 1 then + my = d + elseif ny == -1 then + my = -d + end + if nz == 1 then + mz = d + elseif nz == -1 then + mz = -d + end + f[#f + 1], f[#f + 2], f[#f + 3] = mx, my, mz + b[#b + 1], b[#b + 2], b[#b + 3] = mx, my, mz + end + end + return ((#f >= 9 and{f }or{nil})[1]), ((#b >= 9 and{b }or{nil})[1]), false +end + +-- removes repeated and colinear corners; nil when fewer than 3 remain +local function clean(pts, eps) +local out= {} + local n = math.floor(#pts / 3 +) for i = 0, n - 1 do + local x, y, z = snap(pts[i * 3 + 1]), snap(pts[i * 3 + 2]), snap(pts[i * 3 + 3]) + local m = #out + if m < 3 or abs(out[m - 2] - x) > eps or abs(out[m - 1] - y) > eps or abs(out[m] - z) > eps then + out[m + 1], out[m + 2], out[m + 3] = x, y, z + end + end + while #out >= 6 and abs(out[1] - out[#out - 2]) <= eps and abs(out[2] - out[#out - 1]) <= eps and abs(out[3] - out[#out]) <= eps do + out[#out], out[#out - 1], out[#out - 2] = nil, nil, nil + end + -- colinear corners + local changed = true + while changed and #out >= 9 do + changed = false + local k = math.floor(#out / 3 +) for i = 0, k - 1 do + local a, b, c = ((i + k - 1) % k) * 3, i * 3, ((i + 1) % k) * 3 + local ux, uy, uz = out[b + 1] - out[a + 1], out[b + 2] - out[a + 2], out[b + 3] - out[a + 3] + local vx, vy, vz = out[c + 1] - out[b + 1], out[c + 2] - out[b + 2], out[c + 3] - out[b + 3] + local cx, cy, cz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + local lu, lv = sqrt(ux * ux + uy * uy + uz * uz), sqrt(vx * vx + vy * vy + vz * vz) + if lu * lv == 0 or sqrt(cx * cx + cy * cy + cz * cz) <= 1e-9 * lu * lv then + table.remove(out, b + 3) + table.remove(out, b + 2) + table.remove(out, b + 1) + changed = true + break + end + end + end + return (#out >= 9 and{out }or{nil +})[1]end + +local function samePlane(a, b, eps) +return abs(a[1] - b[1]) < 1e-5 and abs(a[2] - b[2]) < 1e-5 and abs(a[3] - b[3]) < 1e-5 and abs(a[4] - b[4]) < eps +end + +local function oppositePlane(a, b, eps) +return abs(a[1] + b[1]) < 1e-5 and abs(a[2] + b[2]) < 1e-5 and abs(a[3] + b[3]) < 1e-5 and abs(a[4] + b[4]) < eps +end + +-- one polygon per plane of a convex brush (nil for planes clipped away or repeating an earlier plane) +function Brush.windings(planes, opts) +local eps = opts and opts.epsilon or 1e-3 + local size = opts and opts.size or 2 ^ 17 + local out= {} + for i, p in __iter(planes) do + local w= Brush.baseWinding(p, size) + for j, q in __iter(planes) do + if not w then + break + end + if j ~= i then + if samePlane(p, q, eps) then + if j < i then + w = nil + end + else + local _, back, on = Brush.split(w, q, eps) + w = (on and{nil }or{back +})[1] end + end + end + out[i] = (w and{(clean(w, eps) )}or{nil +})[1] end + return out +end + +local function bounds(polys) +local b = { math.huge, math.huge, math.huge, -math.huge, -math.huge, -math.huge } + for _, p in __iter(polys) do + local pts = p.points + for k = 0, math.floor(#pts / 3 )- 1 do + for c = 1, 3 do + local v = pts[k * 3 + c] + b[c] = min(b[c], v) + b[c + 3] = max(b[c + 3], v) + end + end + end + return b +end + +-- the parts of pts (on plane `own` of brush a) outside brush b +local function outside(pts, own, a, b, planes, eps) +local kept= {} + local inside= pts + for _, q in __iter(planes) do + if not inside then + break + end + if samePlane(own, q, eps) then + if a < b then + return { pts } + end + elseif not oppositePlane(own, q, eps) then + local front, back = Brush.split(inside, q, eps) + if front then + table.insert(kept, front) + end + inside = back + end + end + return kept +end + +local function faceKey(f) +local parts = { f.texture or "" } + for _, m in __iter({ f.vecs, f.bp }) do + if m then + for _, row in __iter(m) do + for _, v in __iter(row) do + table.insert(parts, string.format("%.6g", v)) + end + end + end + end + return table.concat(parts, " ") +end + +local function convex(pts, n, eps) +local k = math.floor(#pts / 3 +) for i = 0, k - 1 do + local a, b, c = ((i + k - 1) % k) * 3, i * 3, ((i + 1) % k) * 3 + local ux, uy, uz = pts[b + 1] - pts[a + 1], pts[b + 2] - pts[a + 2], pts[b + 3] - pts[a + 3] + local vx, vy, vz = pts[c + 1] - pts[b + 1], pts[c + 2] - pts[b + 2], pts[c + 3] - pts[b + 3] + local cx, cy, cz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + local lu, lv = sqrt(ux * ux + uy * uy + uz * uz), sqrt(vx * vx + vy * vy + vz * vz) + if (cx * n[1] + cy * n[2] + cz * n[3]) < -eps * max(lu, lv, 1) then + return false + end + end + return true +end + +-- qbsp TryMerge: two polygons sharing an edge (in opposite directions) -> their union, when convex +local function tryMerge(f1, f2, n, eps) +local n1, n2 = math.floor(#f1 / 3), math.floor(#f2 / 3 +) for i = 0, n1 - 1 do + local i2 = (i + 1) % n1 + for j = 0, n2 - 1 do + local j2 = (j + 1) % n2 + local match = true + for c = 1, 3 do + if abs(f1[i * 3 + c] - f2[j2 * 3 + c]) > eps or abs(f1[i2 * 3 + c] - f2[j * 3 + c]) > eps then + match = false + break + end + end + if match then + local out= {} + for k = 0, n1 - 1 do + local s = ((i2 + k) % n1) * 3 + out[#out + 1], out[#out + 2], out[#out + 3] = f1[s + 1], f1[s + 2], f1[s + 3] + end + for k = 2, n2 - 1 do + local s = ((j + k) % n2) * 3 + out[#out + 1], out[#out + 2], out[#out + 3] = f2[s + 1], f2[s + 2], f2[s + 3] + end + local c = clean(out, eps) + if c and convex(c, n, eps) then + return c + end + return nil + end + end + end + return nil +end + +local function mergeAll(polys, faces, eps) +local groups= {} + local order= {} + for _, p in __iter(polys) do + local f = faces[p.brush][p.face] + local pl = f.plane + local key = string.format("%.5f %.5f %.5f %.3f|", pl[1], pl[2], pl[3], pl[4]) .. faceKey(f) + local g = groups[key] + if not g then + g = {} + groups[key] = g + table.insert(order, key) + end + table.insert(g, p) + end + local out= {} + for _, key in __iter(order) do + local g = groups[key] + local changed = true + while changed do + changed = false + for a = 1, #g do + for b = a + 1, #g do + local m = tryMerge(g[a].points, g[b].points, g[a].normal, eps) + if m then + g[a] = { brush = g[a].brush, face = g[a].face, points = m, normal = g[a].normal } + table.remove(g, b) + changed = true + break + end + end + if changed then + break + end + end + end + for _, p in __iter(g) do + table.insert(out, p) + end + end + return out +end + +-- every brush's faces -> polygons (brushes[i] is a list of faces); nil, message past opts.maxPolygons +function Brush.polygons(brushes, opts) +local eps = opts and opts.epsilon or 1e-3 + local limit = opts and opts.maxPolygons or 2 ^ 20 + local per= {} + local planesOf= {} + local count = 0 + for bi, faces in __iter(brushes) do + local planes= {} + for fi, f in __iter(faces) do + planes[fi] = f.plane + end + planesOf[bi] = planes + local list= {} + local ws = Brush.windings(planes, opts) + for fi = 1, #faces do + local w = ws[fi] + if w then + table.insert(list, { brush = bi, face = fi, points = w, normal = { planes[fi][1], planes[fi][2], planes[fi][3] } }) + end + end + per[bi] = list + count =count+ #list + if count > limit then + return nil, "limit: too many brush faces" + end + end + local all= {} + if opts and opts.hull then + local boxes= {} + for bi = 1, #brushes do + boxes[bi] = bounds(per[bi]) + end + for bi = 1, #brushes do + for _, p in __iter(per[bi]) do + local frags= { p.points } + local own = brushes[bi][p.face].plane + local pb = bounds({ p }) + for bj = 1, #brushes do + if #frags == 0 then + break + end + local ob = boxes[bj] + if bj ~= bi and #per[bj] > 0 and pb[1] <= ob[4] + eps and pb[4] >= ob[1] - eps and pb[2] <= ob[5] + eps + and pb[5] >= ob[2] - eps and pb[3] <= ob[6] + eps and pb[6] >= ob[3] - eps then + local nextFrags= {} + for _, fr in __iter(frags) do + for _, kept in __iter(outside(fr, own, bi, bj, planesOf[bj], eps)) do + table.insert(nextFrags, kept) + end + end + frags = nextFrags + if #frags > limit then + return nil, "limit: too many brush fragments" + end + end + end + for _, fr in __iter(frags) do + local c = clean(fr, eps) + if c then + table.insert(all, { brush = p.brush, face = p.face, points = c, normal = p.normal }) + end + end + end + end + else + for bi = 1, #brushes do + for _, p in __iter(per[bi]) do + table.insert(all, p) + end + end + end + if opts and opts.merge then + all = mergeAll(all, brushes, eps) + end + return all, nil +end + +-- polygon area (for checks against compilers) +function Brush.area(pts) +local n = math.floor(#pts / 3 +) local ax, ay, az = 0, 0, 0 + for k = 1, n - 2 do + local ux, uy, uz = pts[k * 3 + 1] - pts[1], pts[k * 3 + 2] - pts[2], pts[k * 3 + 3] - pts[3] + local vx, vy, vz = pts[k * 3 + 4] - pts[1], pts[k * 3 + 5] - pts[2], pts[k * 3 + 6] - pts[3] + ax =ax+ (uy * vz - uz * vy +) ay =ay+ (uz * vx - ux * vz +) az =az+ (ux * vy - uy * vx +) end + return sqrt(ax * ax + ay * ay + az * az) / 2 +end + +-- polygons -> one indexed triangle primitive per texture, in order of first use. size(name) gives a texture's +-- width, height (texel projections divide by them) +function Brush.primitives(polys, brushes, size) + +local byTex= {} + local order= {} + local sizes= {} + for _, p in __iter(polys) do + local f = brushes[p.brush][p.face] + local name = f.texture or "" + local acc = byTex[name] + if not acc then + acc = { texture = name, pos = {}, nrm = {}, uv = {}, idx = {} } + byTex[name] = acc + table.insert(order, acc) + end + local sz = sizes[name] + if not sz then + local w, h = size(name) + sz = { math.max(w, 1), math.max(h, 1) } + sizes[name] = sz + end + local a= acc + local pts = p.points + local n = math.floor(#pts / 3 +) local base = math.floor(#a.pos / 3 +) for k = 0, n - 1 do + local x, y, z = pts[k * 3 + 1], pts[k * 3 + 2], pts[k * 3 + 3] + local pp, nn, uu = a.pos, a.nrm, a.uv + pp[#pp + 1], pp[#pp + 2], pp[#pp + 3] = x, y, z + nn[#nn + 1], nn[#nn + 2], nn[#nn + 3] = p.normal[1], p.normal[2], p.normal[3] + local u, v = Brush.uv(f, x, y, z, sz[1], sz[2]) + uu[#uu + 1], uu[#uu + 2] = u, v + end + local ii = a.idx + for k = 1, n - 2 do + ii[#ii + 1], ii[#ii + 2], ii[#ii + 3] = base, base + k, base + k + 1 + end + end + local out= {} + for _, a in __iter(order) do + local nv, ni = math.floor(#a.pos / 3), #a.idx + local pb, nb, ub, ib = buffer.create(nv * 12), buffer.create(nv * 12), buffer.create(nv * 8), buffer.create(ni * 4) + for k = 1, nv * 3 do + writef32(pb, (k - 1) * 4, a.pos[k]) + writef32(nb, (k - 1) * 4, a.nrm[k]) + end + for k = 1, nv * 2 do + writef32(ub, (k - 1) * 4, a.uv[k]) + end + for k = 1, ni do + writeu32(ib, (k - 1) * 4, a.idx[k]) + end + local S = Types.Scene + table.insert(out, { + texture = a.texture, + primitive = { + attributes = { POSITION = S.accessor(pb, "f32", 3, nv), NORMAL = S.accessor(nb, "f32", 3, nv), TEXCOORD_0 = S.accessor(ub, "f32", 2, nv) }, + indices = S.accessor(ib, "u32", 1, ni), + mode = "triangles" , + }, + }) + end + return out +end + +return Brush +end __FILES["codecs/model/Draco"] = function() local __compat = __compat local buffer, bit32, type, __iter = __compat.buffer, __compat.bit32, __compat.type, __compat.__iter --!strict -- codecs/model/Draco: Google Draco geometry decompression (.drc; glTF KHR_draco_mesh_compression; Roblox mesh v6 / v7). @@ -82757,6 +83669,130 @@ end return Packed end +__FILES["codecs/model/Patch"] = function() +local __compat = __compat local __iter = __compat.__iter --!strict +--!native +--!optimize 2 +-- codecs/model/Patch: Quake III / Doom 3 Bezier patches (control grids) -> evaluated grids, triangles, normals. +-- A w x h grid (w, h odd, >= 3) is a mesh of 3 x 3 biquadratic sub-patches (Unofficial Quake 3 Map Specs; patchDef2 / +-- patchDef3), evaluated at fixed segments per sub-patch and axis (patchDef3's explicit subdivisions; Quake III's adaptive +-- subdivision is not reproduced). Shared edges are evaluated once. +local Patch = {} + +local sqrt = math.sqrt + +function Patch.valid(w, h, n) +return w >= 3 and h >= 3 and w % 2 == 1 and h % 2 == 1 and w * h == n +end + +-- ctrl: w * h points of comps numbers, row-major (row j holds points j * w .. j * w + w - 1); returns the evaluated grid +-- (gw * gh points of comps numbers, row-major) and its size; nil when the grid is not w x h odd or a limit is passed +function Patch.grid(ctrl, w, h, comps, levelU, levelV, maxPoints) +local lu, lv = math.max(1, math.floor(levelU)), math.max(1, math.floor(levelV)) + if not Patch.valid(w, h, math.floor(#ctrl / comps)) or #ctrl ~= w * h * comps then + return nil, 0, 0 + end + local px, py = math.floor((w - 1) / 2), math.floor((h - 1) / 2 +) local gw, gh = px * lu + 1, py * lv + 1 + if gw * gh > (maxPoints or 2 ^ 24) then + return nil, 0, 0 + end + local out = (table.create(gw * gh * comps, 0) ) +for gy = 0, gh - 1 do + local sy = math.min(math.floor(gy / lv), py - 1) + local tv = (gy - sy * lv) / lv + local bv0, bv1, bv2 = (1 - tv) * (1 - tv), 2 * tv * (1 - tv), tv * tv + for gx = 0, gw - 1 do + local sx = math.min(math.floor(gx / lu), px - 1) + local tu = (gx - sx * lu) / lu + local bu0, bu1, bu2 = (1 - tu) * (1 - tu), 2 * tu * (1 - tu), tu * tu + local o = (gy * gw + gx) * comps + for j = 0, 2 do + local bv = (j == 0 and{bv0 }or{(j == 1 and{bv1 }or{bv2 +})[1]})[1] local row = ((sy * 2 + j) * w + sx * 2) * comps + for i = 0, 2 do + local wgt = bv * ((i == 0 and{bu0 }or{(i == 1 and{bu1 }or{bu2})[1]})[1]) + local c = row + i * comps + for k = 1, comps do +do local __DARKLUA_VAR=o + k out[__DARKLUA_VAR]=out[__DARKLUA_VAR]+ ctrl[c + k] * wgt +end end + end + end + end + end + return out, gw, gh +end + +-- 0-based triangle indices over a gw x gh grid; Quake's control grids are clockwise-front, these are counter-clockwise +function Patch.triangles(gw, gh) +local out = (table.create(math.max(0, (gw - 1) * (gh - 1) * 6)) ) +for gy = 0, gh - 2 do + for gx = 0, gw - 2 do + local a, b = gy * gw + gx, gy * gw + gx + 1 + local d, e = a + gw, b + gw + local n = #out + out[n + 1], out[n + 2], out[n + 3] = a, d, b + out[n + 4], out[n + 5], out[n + 6] = b, d, e + end + end + return out +end + +-- renormalizes the vec3 at component offset at (0-based) of every point +function Patch.normalize(pts, comps, at) + for o = 0, #pts - comps, comps do + local x, y, z = pts[o + at + 1], pts[o + at + 2], pts[o + at + 3] + local l = sqrt(x * x + y * y + z * z) + if l > 0 then + pts[o + at + 1], pts[o + at + 2], pts[o + at + 3] = x / l, y / l, z / l + end + end +end + +-- unit normals (3 per point) of the evaluated grid from the positions (components 1..3), facing the front of +-- Patch.triangles; points where the surface degenerates take a neighbour's normal +function Patch.normals(pts, comps, gw, gh) +local out = (table.create(gw * gh * 3, 0) ) +local function at(x, y, k) +return pts[(y * gw + x) * comps + k] + end + for gy = 0, gh - 1 do + local y0, y1 = math.max(gy - 1, 0), math.min(gy + 1, gh - 1) + for gx = 0, gw - 1 do + local x0, x1 = math.max(gx - 1, 0), math.min(gx + 1, gw - 1) + local ux, uy, uz = at(x1, gy, 1) - at(x0, gy, 1), at(x1, gy, 2) - at(x0, gy, 2), at(x1, gy, 3) - at(x0, gy, 3) + local vx, vy, vz = at(gx, y1, 1) - at(gx, y0, 1), at(gx, y1, 2) - at(gx, y0, 2), at(gx, y1, 3) - at(gx, y0, 3) + local nx, ny, nz = vy * uz - vz * uy, vz * ux - vx * uz, vx * uy - vy * ux + local l = sqrt(nx * nx + ny * ny + nz * nz) + local o = (gy * gw + gx) * 3 + if l > 1e-12 then + out[o + 1], out[o + 2], out[o + 3] = nx / l, ny / l, nz / l + end + end + end + for _ = 1, 2 do + for i = 0, gw * gh - 1 do + local o = i * 3 + if out[o + 1] == 0 and out[o + 2] == 0 and out[o + 3] == 0 then + local x, y = i % gw, math.floor(i / gw +) for _, d in __iter({ { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 1 }, { -1, -1 }, { 1, -1 }, { -1, 1 } }) do + local nx2, ny2 = x + d[1], y + d[2] + if nx2 >= 0 and nx2 < gw and ny2 >= 0 and ny2 < gh then + local q = (ny2 * gw + nx2) * 3 + if out[q + 1] ~= 0 or out[q + 2] ~= 0 or out[q + 3] ~= 0 then + out[o + 1], out[o + 2], out[o + 3] = out[q + 1], out[q + 2], out[q + 3] + break + end + end + end + end + end + end + return out +end + +return Patch +end __FILES["codecs/model/Polygon"] = function() local __compat = __compat local type, __iter = __compat.type, __compat.__iter --!strict -- codecs/model/Polygon: 2D polygons with holes to triangles by hole bridging and ear clipping. New code. @@ -145097,7 +146133,7 @@ local Bsp = { category = "model", extensions = { "bsp" }, mime = { "model/x-bsp" }, - deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels" }, + deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels", "codecs/image/Miptex", "codecs/model/Patch" }, caps = { decode = true, encode = false, variants = { "quake", "halflife", "quake2", "quake3" }, lightmaps = "quake3" }, } -- ------------------------------------------------------------------------------------------------ types @@ -145229,6 +146265,7 @@ local __compat = __compat local buffer, __iter = __compat.buffer, __compat.__ite -- size. local Types = __include("Types") local Pixels = __include("codecs/image/Pixels") +local Miptex = __include("codecs/image/Miptex") local Brush = {} @@ -145261,34 +146298,18 @@ local out= {} if n < 0 or n > 65536 or 4 + n * 4 > l.size then return nil, "bad miptex lump" end - local gpal = (pal and{(Pixels.palette(pal, 0, 256) )}or{nil + local gpal = (pal and not hl and{(Pixels.palette(pal, 0, 256) )}or{nil })[1] for i = 0, n - 1 do local o = readi32(b, at + 4 + i * 4) - if o < 0 or o + 40 > l.size then + local hd = (o >= 0 and o + 40 <= l.size and{(Miptex.header(b, at + o, l.size - o) )}or{nil +})[1] if not hd then out[i + 1] = { name = "missing" .. i, width = 64, height = 64, image = nil, texels = false } else - local m = at + o - local name = cstr(b, m, 16) - local w, h, off0 = readu32(b, m + 16), readu32(b, m + 20), readu32(b, m + 24) - local t= { name = name, width = math.max(w, 1), height = math.max(h, 1), image = nil, texels = false } - if off0 ~= 0 and w > 0 and h > 0 and w * h <= maxPixels then - local px = m + off0 - local need = w * h - local palAt = m + readu32(b, m + 36) + (math.floor(w / 8)) * (math.floor(h / 8)) + 2 - if o + off0 + need <= l.size then - local p = gpal - if hl then - p = (palAt - at + 768 <= l.size and{(Pixels.palette(b, palAt, 256) )}or{nil -})[1] end - local img = Types.Image.new(w, h) - if p then - Pixels.indexed(b, px, w, 8, img.pixels, w, h, true, p) - else - for k = 0, need - 1 do - writeu32(img.pixels, k * 4, 0xFF000000 + buffer.readu8(b, px + k) * 0x10101) - end - end - img.meta.source = { format = "bsp", miptex = name, palette = p ~= nil } + local t= { name = hd.name, width = math.max(hd.width, 1), height = math.max(hd.height, 1), image = nil, texels = false } + if hd.offsets[1] ~= 0 and hd.width * hd.height <= maxPixels then + local img = Miptex.decode(b, at + o, l.size - o, { palette = gpal, goldsrc = hl, keyed = false, maxPixels = maxPixels }) + if img then + img.meta.source = { format = "bsp", miptex = hd.name, palette = img.meta.source and img.meta.source.palette } t.image = img end end @@ -145366,12 +146387,12 @@ local q2 = variant == "q2" local orders= {} local skipped = 0 for f = 0, nF - 1 do -local __DARKLUA_CONTINUE_8=false repeat local fo = base + Fc.at + f * 20 +local __DARKLUA_CONTINUE_7=false repeat local fo = base + Fc.at + f * 20 local plane, side, firstEdge, numEdges, texinfo = readu16(b, fo), readu16(b, fo + 2), readi32(b, fo + 4), readu16(b, fo + 8), readu16(b, fo + 10) local model = faceModel[f + 1] if not model or numEdges < 3 or firstEdge < 0 or firstEdge + numEdges > nSE or plane >= nP or texinfo >= nTI then skipped =skipped+ 1 -__DARKLUA_CONTINUE_8=true break +__DARKLUA_CONTINUE_7=true break end local poly= {} local ok = true @@ -145394,7 +146415,7 @@ __DARKLUA_CONTINUE_8=true break end if not ok then skipped =skipped+ 1 -__DARKLUA_CONTINUE_8=true break +__DARKLUA_CONTINUE_7=true break end local po = base + P.at + plane * 20 local nx, ny, nz = readf32(b, po), readf32(b, po + 4), readf32(b, po + 8) @@ -145450,7 +146471,7 @@ __DARKLUA_CONTINUE_8=true break uu[#uu + 1] = (x * tx + y * ty + z * tz + to) / h end end -__DARKLUA_CONTINUE_8=true until true if not __DARKLUA_CONTINUE_8 then break end end +__DARKLUA_CONTINUE_7=true until true if not __DARKLUA_CONTINUE_7 then break end end for i, t in __iter(texs) do local tex= { name = t.name, image = t.image, uri = (t.image and{nil }or{((q2 and(("textures/" .. t.name .. ".wal" ))or(t.name))) })[1]} table.insert(scene.textures, tex) @@ -145503,8 +146524,10 @@ end __FILES["model/bsp/Quake3"] = function() local __compat = __compat local buffer, __iter = __compat.buffer, __compat.__iter --!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 = __include("Types") +local Patch = __include("codecs/model/Patch") local Quake3 = {} @@ -145584,52 +146607,23 @@ for k = 1, 14 do do local __DARKLUA_VAR=kind == 1 and"polygons" or"meshes" counts[__DARKLUA_VAR]=counts[__DARKLUA_VAR]+ 1 end 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 =counts.patches+ 1 - local L = level - for py = 0, math.floor((h - 1) / 2 )- 1 do - for px = 0, math.floor((w - 1) / 2 )- 1 do - local ctrl= {} - 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= {} - 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]=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 __iter({ a, d, c2, c2, d, e }) do - table.insert(tris, v) - end - end - end - end + local ctrl = (table.create(n * 14, 0) ) +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) ) +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)) )) + end + for _, v in __iter(Patch.triangles(gw, gh)) do + table.insert(tris, ids[v + 1]) end else counts.skipped =counts.skipped+ 1 diff --git a/build/rosetta.lua.linemap.json b/build/rosetta.lua.linemap.json index 45c4801..9a346e6 100644 --- a/build/rosetta.lua.linemap.json +++ b/build/rosetta.lua.linemap.json @@ -190,350 +190,353 @@ [69677, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], [70123, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], [70201, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], -[70268, "src/Rosetta/codecs/image/Pixels.luau"], -[70532, "src/Rosetta/codecs/image/Quantize/init.luau"], -[70991, "src/Rosetta/codecs/image/Raster.luau"], -[71688, "src/Rosetta/codecs/image/Texel.luau"], -[72061, "src/Rosetta/codecs/image/Texture.luau"], -[72206, "src/Rosetta/codecs/image/Vp8/init.luau"], -[72336, "src/Rosetta/codecs/image/Vp8/Decode.luau"], -[74292, "src/Rosetta/codecs/image/Vp8/Predict.luau"], -[74551, "src/Rosetta/codecs/image/Vp8/Tables.luau"], -[74800, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], -[74919, "src/Rosetta/codecs/image/Vp8L/init.luau"], -[75023, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], -[75876, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], -[76828, "src/Rosetta/codecs/image/Yuv.luau"], -[77096, "src/Rosetta/codecs/model/Draco/init.luau"], -[77428, "src/Rosetta/codecs/model/Draco/Attributes.luau"], -[77897, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], -[79086, "src/Rosetta/codecs/model/Draco/Int64.luau"], -[79235, "src/Rosetta/codecs/model/Draco/KdTree.luau"], -[79594, "src/Rosetta/codecs/model/Draco/Predict.luau"], -[80556, "src/Rosetta/codecs/model/Draco/Reader.luau"], -[81030, "src/Rosetta/codecs/model/Mat4.luau"], -[81289, "src/Rosetta/codecs/model/MeshFlatten.luau"], -[81817, "src/Rosetta/codecs/model/Minecraft/init.luau"], -[82369, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], -[82448, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], -[82555, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], -[82761, "src/Rosetta/codecs/model/Polygon.luau"], -[82995, "src/Rosetta/codecs/model/Rbx/init.luau"], -[83232, "src/Rosetta/codecs/model/Rbx/Binary.luau"], -[83986, "src/Rosetta/codecs/model/Rig.luau"], -[84229, "src/Rosetta/codecs/model/Sampler.luau"], -[84389, "src/Rosetta/codecs/model/Vrml/init.luau"], -[84537, "src/Rosetta/codecs/model/Vrml/Build.luau"], -[85111, "src/Rosetta/codecs/model/Vrml/Fields.luau"], -[85274, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], -[86023, "src/Rosetta/codecs/model/Vrml/Parse.luau"], -[86545, "src/Rosetta/codecs/model/Vrml/Write.luau"], -[87272, "src/Rosetta/codecs/model/Vrml/Xml.luau"], -[87504, "src/Rosetta/codecs/text/Json/init.luau"], -[87773, "src/Rosetta/codecs/text/Json/Decode.luau"], -[88187, "src/Rosetta/codecs/text/Json/Encode.luau"], -[88489, "src/Rosetta/codecs/text/Nbt/init.luau"], -[88842, "src/Rosetta/codecs/text/Nbt/Binary.luau"], -[89534, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], -[90174, "src/Rosetta/codecs/text/Nbt/Value.luau"], -[90412, "src/Rosetta/codecs/text/Text/init.luau"], -[90503, "src/Rosetta/codecs/text/Url/init.luau"], -[90708, "src/Rosetta/codecs/text/Xml/init.luau"], -[91111, "src/Rosetta/codecs/text/Xml/Parse.luau"], -[91851, "src/Rosetta/codecs/video/Dsp.luau"], -[92574, "src/Rosetta/codecs/video/H263/init.luau"], -[92730, "src/Rosetta/codecs/video/H263/Decoder.luau"], -[93588, "src/Rosetta/codecs/video/H263/Tables.luau"], -[93791, "src/Rosetta/codecs/video/H264/init.luau"], -[94164, "src/Rosetta/codecs/video/H264/Bitstream.luau"], -[94439, "src/Rosetta/codecs/video/H264/Cabac.luau"], -[95570, "src/Rosetta/codecs/video/H264/Cavlc.luau"], -[96338, "src/Rosetta/codecs/video/H264/Deblock.luau"], -[96596, "src/Rosetta/codecs/video/H264/Decoder.luau"], -[97605, "src/Rosetta/codecs/video/H264/Inter.luau"], -[97859, "src/Rosetta/codecs/video/H264/Intra.luau"], -[98266, "src/Rosetta/codecs/video/H264/Mb.luau"], -[99172, "src/Rosetta/codecs/video/H264/Params.luau"], -[99619, "src/Rosetta/codecs/video/H264/Slice.luau"], -[99870, "src/Rosetta/codecs/video/H264/Tables.luau"], -[99911, "src/Rosetta/codecs/video/H264/Transform.luau"], -[100076, "src/Rosetta/codecs/video/Legacy/init.luau"], -[100274, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], -[100571, "src/Rosetta/codecs/video/Legacy/Flic.luau"], -[100938, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], -[101056, "src/Rosetta/codecs/video/Legacy/Picture.luau"], -[101164, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], -[101437, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], -[101832, "src/Rosetta/codecs/video/Legacy/Smc.luau"], -[102009, "src/Rosetta/codecs/video/Mpeg1/init.luau"], -[102021, "src/Rosetta/codecs/video/Mpeg2/init.luau"], -[102388, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], -[103895, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], -[104034, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], -[104172, "src/Rosetta/codecs/video/Theora/init.luau"], -[104435, "src/Rosetta/codecs/video/Theora/Decoder.luau"], -[105699, "src/Rosetta/codecs/video/Theora/Header.luau"], -[106062, "src/Rosetta/codecs/video/Video/init.luau"], -[106619, "src/Rosetta/codecs/video/Video/Source.luau"], -[106904, "src/Rosetta/containers/Archive.luau"], -[107171, "src/Rosetta/containers/AudioWrap.luau"], -[107674, "src/Rosetta/containers/Avi/init.luau"], -[108226, "src/Rosetta/containers/Chunks.luau"], -[108361, "src/Rosetta/containers/Cpio.luau"], -[108789, "src/Rosetta/containers/Demux.luau"], -[109064, "src/Rosetta/containers/Ebml/init.luau"], -[109377, "src/Rosetta/containers/Fat.luau"], -[110065, "src/Rosetta/containers/Iso9660.luau"], -[110570, "src/Rosetta/containers/IsoBmff/init.luau"], -[110740, "src/Rosetta/containers/IsoBmff/Box.luau"], -[110928, "src/Rosetta/containers/IsoBmff/Demux.luau"], -[111773, "src/Rosetta/containers/IsoBmff/Meta.luau"], -[112294, "src/Rosetta/containers/IsoBmff/Mux.luau"], -[112810, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], -[112927, "src/Rosetta/containers/MacFile.luau"], -[113076, "src/Rosetta/containers/MpegEs.luau"], -[113242, "src/Rosetta/containers/MpegPs/init.luau"], -[113462, "src/Rosetta/containers/MpegTs/init.luau"], -[114254, "src/Rosetta/containers/Ogg/init.luau"], -[114679, "src/Rosetta/containers/Ogg/Mux.luau"], -[114874, "src/Rosetta/containers/Ogg/Page.luau"], -[115043, "src/Rosetta/containers/Riff/init.luau"], -[115360, "src/Rosetta/containers/Tar.luau"], -[115774, "src/Rosetta/containers/Zip/init.luau"], -[116406, "src/Rosetta/core/Adler32.luau"], -[116452, "src/Rosetta/core/Base64.luau"], -[116611, "src/Rosetta/core/Bits.luau"], -[116904, "src/Rosetta/core/Bytes.luau"], -[117431, "src/Rosetta/core/Crc16.luau"], -[117483, "src/Rosetta/core/Crc32.luau"], -[117595, "src/Rosetta/core/Err.luau"], -[117677, "src/Rosetta/core/Input.luau"], -[117753, "src/Rosetta/core/Md5.luau"], -[117912, "src/Rosetta/core/Sniff.luau"], -[117941, "src/Rosetta/data/cbor/init.luau"], -[118040, "src/Rosetta/data/cbor/Codec.luau"], -[118609, "src/Rosetta/data/csv/init.luau"], -[118921, "src/Rosetta/data/ini/init.luau"], -[119167, "src/Rosetta/data/json/init.luau"], -[119259, "src/Rosetta/data/msgpack/init.luau"], -[119348, "src/Rosetta/data/msgpack/Codec.luau"], -[119790, "src/Rosetta/data/nbt/init.luau"], -[119849, "src/Rosetta/data/plist/init.luau"], -[120155, "src/Rosetta/data/plist/Binary.luau"], -[120422, "src/Rosetta/data/snbt/init.luau"], -[120485, "src/Rosetta/data/toml/init.luau"], -[120552, "src/Rosetta/data/toml/Decode.luau"], -[121180, "src/Rosetta/data/toml/Encode.luau"], -[121389, "src/Rosetta/data/xml/init.luau"], -[121445, "src/Rosetta/data/yaml/init.luau"], -[121518, "src/Rosetta/data/yaml/Emit.luau"], -[121808, "src/Rosetta/data/yaml/Parse.luau"], -[123101, "src/Rosetta/font/bdf/init.luau"], -[123390, "src/Rosetta/font/bmfont/init.luau"], -[123817, "src/Rosetta/font/bmfont/Parse.luau"], -[124270, "src/Rosetta/font/eot/init.luau"], -[124502, "src/Rosetta/font/fon/init.luau"], -[124785, "src/Rosetta/font/hershey/init.luau"], -[124980, "src/Rosetta/font/pcf/init.luau"], -[125260, "src/Rosetta/font/psf/init.luau"], -[125580, "src/Rosetta/font/ttf/init.luau"], -[125631, "src/Rosetta/font/type1/init.luau"], -[125990, "src/Rosetta/font/type1/Charstring.luau"], -[126268, "src/Rosetta/font/woff/init.luau"], -[126400, "src/Rosetta/font/woff2/init.luau"], -[126457, "src/Rosetta/font/woff2/Rebuild.luau"], -[126997, "src/Rosetta/host/init.luau"], -[127042, "src/Rosetta/host/Love.luau"], -[127185, "src/Rosetta/host/LuaJIT.luau"], -[127235, "src/Rosetta/host/Luau.luau"], -[127258, "src/Rosetta/host/Roblox.luau"], -[127617, "src/Rosetta/image/ani/init.luau"], -[127797, "src/Rosetta/image/blp/init.luau"], -[128055, "src/Rosetta/image/bmp/init.luau"], -[128470, "src/Rosetta/image/dds/init.luau"], -[128953, "src/Rosetta/image/exr/init.luau"], -[129713, "src/Rosetta/image/exr/Codec.luau"], -[129824, "src/Rosetta/image/exr/Piz.luau"], -[130181, "src/Rosetta/image/gif/init.luau"], -[130697, "src/Rosetta/image/gif/Decode.luau"], -[130760, "src/Rosetta/image/hdr/init.luau"], -[130989, "src/Rosetta/image/hdr/Codec.luau"], -[131200, "src/Rosetta/image/icns/init.luau"], -[131531, "src/Rosetta/image/ico/init.luau"], -[131808, "src/Rosetta/image/ico/Dib.luau"], -[131903, "src/Rosetta/image/ilbm/init.luau"], -[132222, "src/Rosetta/image/jpeg/init.luau"], -[132358, "src/Rosetta/image/ktx/init.luau"], -[133018, "src/Rosetta/image/pcx/init.luau"], -[133282, "src/Rosetta/image/png/init.luau"], -[133862, "src/Rosetta/image/png/Apng.luau"], -[133942, "src/Rosetta/image/png/Decode.luau"], -[134182, "src/Rosetta/image/png/Encode.luau"], -[134337, "src/Rosetta/image/pnm/init.luau"], -[134715, "src/Rosetta/image/pnm/Codec.luau"], -[134992, "src/Rosetta/image/qoi/init.luau"], -[135114, "src/Rosetta/image/qoi/Codec.luau"], -[135264, "src/Rosetta/image/sgi/init.luau"], -[135549, "src/Rosetta/image/sunras/init.luau"], -[135795, "src/Rosetta/image/tga/init.luau"], -[136065, "src/Rosetta/image/tga/Codec.luau"], -[136217, "src/Rosetta/image/tiff/init.luau"], -[137044, "src/Rosetta/image/tiff/Pixels.luau"], -[137434, "src/Rosetta/image/tim/init.luau"], -[137676, "src/Rosetta/image/vtf/init.luau"], -[137911, "src/Rosetta/image/webp/init.luau"], -[138521, "src/Rosetta/image/webp/Alpha.luau"], -[138597, "src/Rosetta/image/webp/Anim.luau"], -[138752, "src/Rosetta/image/xbm/init.luau"], -[138913, "src/Rosetta/image/xpm/init.luau"], -[139181, "src/Rosetta/image/xpm/Names.luau"], -[139237, "src/Rosetta/layered/aseprite/init.luau"], -[139975, "src/Rosetta/layered/ora/init.luau"], -[140262, "src/Rosetta/layered/psd/init.luau"], -[140997, "src/Rosetta/layered/psd/Channels.luau"], -[141349, "src/Rosetta/model/3ds/init.luau"], -[141432, "src/Rosetta/model/3ds/Build.luau"], -[142079, "src/Rosetta/model/3ds/Read.luau"], -[142575, "src/Rosetta/model/3ds/Write.luau"], -[143380, "src/Rosetta/model/3mf/init.luau"], -[143462, "src/Rosetta/model/3mf/Read.luau"], -[144050, "src/Rosetta/model/3mf/Write.luau"], -[144455, "src/Rosetta/model/b3d/init.luau"], -[144510, "src/Rosetta/model/b3d/Read.luau"], -[145081, "src/Rosetta/model/bsp/init.luau"], -[145226, "src/Rosetta/model/bsp/Brush.luau"], -[145504, "src/Rosetta/model/bsp/Quake3.luau"], -[145759, "src/Rosetta/model/dae/init.luau"], -[145948, "src/Rosetta/model/dae/Math.luau"], -[145995, "src/Rosetta/model/dae/Read.luau"], -[147845, "src/Rosetta/model/dae/Write.luau"], -[148214, "src/Rosetta/model/fbx/init.luau"], -[148362, "src/Rosetta/model/fbx/Ascii.luau"], -[148632, "src/Rosetta/model/fbx/Binary.luau"], -[149087, "src/Rosetta/model/fbx/Read.luau"], -[150449, "src/Rosetta/model/fbx/Write.luau"], -[151434, "src/Rosetta/model/fbx/Xform.luau"], -[151475, "src/Rosetta/model/gltf/init.luau"], -[151712, "src/Rosetta/model/gltf/Pack.luau"], -[151781, "src/Rosetta/model/gltf/Read.luau"], -[152512, "src/Rosetta/model/gltf/Write.luau"], -[153192, "src/Rosetta/model/iqm/init.luau"], -[153268, "src/Rosetta/model/iqm/Read.luau"], -[153623, "src/Rosetta/model/iqm/Write.luau"], -[154310, "src/Rosetta/model/ldraw/init.luau"], -[154388, "src/Rosetta/model/ldraw/Colors.luau"], -[154706, "src/Rosetta/model/ldraw/Read.luau"], -[155283, "src/Rosetta/model/lwo/init.luau"], -[155359, "src/Rosetta/model/lwo/Build.luau"], -[155821, "src/Rosetta/model/lwo/Parse.luau"], -[156364, "src/Rosetta/model/mca/init.luau"], -[156706, "src/Rosetta/model/mca/Chunk.luau"], -[156839, "src/Rosetta/model/mca/Lz4Block.luau"], -[156909, "src/Rosetta/model/md2/init.luau"], -[157108, "src/Rosetta/model/md3/init.luau"], -[157336, "src/Rosetta/model/md5/init.luau"], -[157417, "src/Rosetta/model/md5/Read.luau"], -[157850, "src/Rosetta/model/mdl/init.luau"], -[157932, "src/Rosetta/model/mdl/HalfLife.luau"], -[158260, "src/Rosetta/model/mdl/Quake.luau"], -[158478, "src/Rosetta/model/ms3d/init.luau"], -[158550, "src/Rosetta/model/ms3d/Read.luau"], -[158996, "src/Rosetta/model/ms3d/Write.luau"], -[159465, "src/Rosetta/model/obj/init.luau"], -[160207, "src/Rosetta/model/obj/Mtl.luau"], -[160494, "src/Rosetta/model/off/init.luau"], -[160956, "src/Rosetta/model/ply/init.luau"], -[162061, "src/Rosetta/model/ply/Binary.luau"], -[162262, "src/Rosetta/model/pmx/init.luau"], -[162331, "src/Rosetta/model/pmx/Build.luau"], -[162627, "src/Rosetta/model/pmx/Pmd.luau"], -[162962, "src/Rosetta/model/pmx/Read.luau"], -[163366, "src/Rosetta/model/qb/init.luau"], -[163759, "src/Rosetta/model/rbxm/init.luau"], -[164351, "src/Rosetta/model/rbxmx/init.luau"], -[165004, "src/Rosetta/model/robloxmesh/init.luau"], -[165663, "src/Rosetta/model/robloxmesh/Parse.luau"], -[166120, "src/Rosetta/model/robloxmesh/Write.luau"], -[166229, "src/Rosetta/model/schematic/init.luau"], -[166550, "src/Rosetta/model/schematic/Common.luau"], -[166670, "src/Rosetta/model/schematic/Litematic.luau"], -[166881, "src/Rosetta/model/schematic/Mcedit.luau"], -[167125, "src/Rosetta/model/schematic/Sponge.luau"], -[167254, "src/Rosetta/model/smd/init.luau"], -[167321, "src/Rosetta/model/smd/Read.luau"], -[167590, "src/Rosetta/model/smd/Write.luau"], -[167833, "src/Rosetta/model/stl/init.luau"], -[168283, "src/Rosetta/model/stl/Decode.luau"], -[168357, "src/Rosetta/model/usda/init.luau"], -[168566, "src/Rosetta/model/usda/Build.luau"], -[169844, "src/Rosetta/model/usda/Parse.luau"], -[170642, "src/Rosetta/model/usda/Write.luau"], -[171459, "src/Rosetta/model/vox/init.luau"], -[172345, "src/Rosetta/model/vox/Grid.luau"], -[172402, "src/Rosetta/model/vrml/init.luau"], -[172468, "src/Rosetta/model/x/init.luau"], -[172598, "src/Rosetta/model/x/Build.luau"], -[173161, "src/Rosetta/model/x/Parse.luau"], -[173458, "src/Rosetta/model/x3d/init.luau"], -[173536, "src/Rosetta/music/669/init.luau"], -[173742, "src/Rosetta/music/ahx/init.luau"], -[173793, "src/Rosetta/music/far/init.luau"], -[174022, "src/Rosetta/music/hmp/init.luau"], -[174286, "src/Rosetta/music/hvl/init.luau"], -[174337, "src/Rosetta/music/it/init.luau"], -[174755, "src/Rosetta/music/it/Itsex.luau"], -[174871, "src/Rosetta/music/med/init.luau"], -[175518, "src/Rosetta/music/midi/init.luau"], -[175661, "src/Rosetta/music/midi/Smf.luau"], -[176072, "src/Rosetta/music/mod/init.luau"], -[176425, "src/Rosetta/music/mtm/init.luau"], -[176647, "src/Rosetta/music/mus/init.luau"], -[176804, "src/Rosetta/music/okt/init.luau"], -[177085, "src/Rosetta/music/ptm/init.luau"], -[177307, "src/Rosetta/music/s3m/init.luau"], -[177543, "src/Rosetta/music/sf2/init.luau"], -[177586, "src/Rosetta/music/stm/init.luau"], -[177817, "src/Rosetta/music/ult/init.luau"], -[178121, "src/Rosetta/music/umx/init.luau"], -[178337, "src/Rosetta/music/xm/init.luau"], -[178898, "src/Rosetta/music/xmi/init.luau"], -[179106, "src/Rosetta/ops/AudioOps.luau"], -[179555, "src/Rosetta/ops/ImageOps/init.luau"], -[180199, "src/Rosetta/ops/ImageOps/Kernels.luau"], -[180709, "src/Rosetta/ops/LayerOps.luau"], -[180802, "src/Rosetta/ops/MeshOps/init.luau"], -[181838, "src/Rosetta/ops/MeshOps/Greedy.luau"], -[182005, "src/Rosetta/ops/MusicOps.luau"], -[182353, "src/Rosetta/playlist/m3u/init.luau"], -[182706, "src/Rosetta/playlist/pls/init.luau"], -[182884, "src/Rosetta/playlist/xspf/init.luau"], -[183087, "src/Rosetta/subtitle/ass/init.luau"], -[183531, "src/Rosetta/subtitle/srt/init.luau"], -[183704, "src/Rosetta/subtitle/vtt/init.luau"], -[183907, "src/Rosetta/vector/svg/init.luau"], -[183993, "src/Rosetta/vector/svg/Parse.luau"], -[184739, "src/Rosetta/vector/svg/PathData.luau"], -[185107, "src/Rosetta/vector/svg/Render.luau"], -[185524, "src/Rosetta/vector/svg/Style.luau"], -[185896, "src/Rosetta/vector/svg/Write.luau"], -[186096, "src/Rosetta/vector/tiled/init.luau"], -[186276, "src/Rosetta/vector/tiled/Data.luau"], -[186427, "src/Rosetta/vector/tiled/Tmj.luau"], -[187058, "src/Rosetta/vector/tiled/Tmx.luau"], -[187670, "src/Rosetta/video/avi/init.luau"], -[187964, "src/Rosetta/video/fli/init.luau"], -[188115, "src/Rosetta/video/flv/init.luau"], -[188499, "src/Rosetta/video/flv/Amf.luau"], -[188657, "src/Rosetta/video/flv/Mux.luau"], -[188938, "src/Rosetta/video/h264/init.luau"], -[189077, "src/Rosetta/video/mkv/init.luau"], -[189233, "src/Rosetta/video/mkv/Mux.luau"], -[189512, "src/Rosetta/video/mkv/Parse.luau"], -[190233, "src/Rosetta/video/mp4/init.luau"], -[190561, "src/Rosetta/video/mpegps/init.luau"], -[190748, "src/Rosetta/video/mpegts/init.luau"], -[190986, "src/Rosetta/video/ogv/init.luau"], -[191381, "src/Rosetta/video/smk/init.luau"], -[191690, "src/Rosetta/video/smk/Audio.luau"], -[191810, "src/Rosetta/video/y4m/init.luau"] +[70268, "src/Rosetta/codecs/image/Miptex.luau"], +[70484, "src/Rosetta/codecs/image/Pixels.luau"], +[70804, "src/Rosetta/codecs/image/Quantize/init.luau"], +[71263, "src/Rosetta/codecs/image/Raster.luau"], +[71960, "src/Rosetta/codecs/image/Texel.luau"], +[72333, "src/Rosetta/codecs/image/Texture.luau"], +[72478, "src/Rosetta/codecs/image/Vp8/init.luau"], +[72608, "src/Rosetta/codecs/image/Vp8/Decode.luau"], +[74564, "src/Rosetta/codecs/image/Vp8/Predict.luau"], +[74823, "src/Rosetta/codecs/image/Vp8/Tables.luau"], +[75072, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], +[75191, "src/Rosetta/codecs/image/Vp8L/init.luau"], +[75295, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], +[76148, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], +[77100, "src/Rosetta/codecs/image/Yuv.luau"], +[77368, "src/Rosetta/codecs/model/Brush.luau"], +[78008, "src/Rosetta/codecs/model/Draco/init.luau"], +[78340, "src/Rosetta/codecs/model/Draco/Attributes.luau"], +[78809, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], +[79998, "src/Rosetta/codecs/model/Draco/Int64.luau"], +[80147, "src/Rosetta/codecs/model/Draco/KdTree.luau"], +[80506, "src/Rosetta/codecs/model/Draco/Predict.luau"], +[81468, "src/Rosetta/codecs/model/Draco/Reader.luau"], +[81942, "src/Rosetta/codecs/model/Mat4.luau"], +[82201, "src/Rosetta/codecs/model/MeshFlatten.luau"], +[82729, "src/Rosetta/codecs/model/Minecraft/init.luau"], +[83281, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], +[83360, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], +[83467, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], +[83673, "src/Rosetta/codecs/model/Patch.luau"], +[83797, "src/Rosetta/codecs/model/Polygon.luau"], +[84031, "src/Rosetta/codecs/model/Rbx/init.luau"], +[84268, "src/Rosetta/codecs/model/Rbx/Binary.luau"], +[85022, "src/Rosetta/codecs/model/Rig.luau"], +[85265, "src/Rosetta/codecs/model/Sampler.luau"], +[85425, "src/Rosetta/codecs/model/Vrml/init.luau"], +[85573, "src/Rosetta/codecs/model/Vrml/Build.luau"], +[86147, "src/Rosetta/codecs/model/Vrml/Fields.luau"], +[86310, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], +[87059, "src/Rosetta/codecs/model/Vrml/Parse.luau"], +[87581, "src/Rosetta/codecs/model/Vrml/Write.luau"], +[88308, "src/Rosetta/codecs/model/Vrml/Xml.luau"], +[88540, "src/Rosetta/codecs/text/Json/init.luau"], +[88809, "src/Rosetta/codecs/text/Json/Decode.luau"], +[89223, "src/Rosetta/codecs/text/Json/Encode.luau"], +[89525, "src/Rosetta/codecs/text/Nbt/init.luau"], +[89878, "src/Rosetta/codecs/text/Nbt/Binary.luau"], +[90570, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], +[91210, "src/Rosetta/codecs/text/Nbt/Value.luau"], +[91448, "src/Rosetta/codecs/text/Text/init.luau"], +[91539, "src/Rosetta/codecs/text/Url/init.luau"], +[91744, "src/Rosetta/codecs/text/Xml/init.luau"], +[92147, "src/Rosetta/codecs/text/Xml/Parse.luau"], +[92887, "src/Rosetta/codecs/video/Dsp.luau"], +[93610, "src/Rosetta/codecs/video/H263/init.luau"], +[93766, "src/Rosetta/codecs/video/H263/Decoder.luau"], +[94624, "src/Rosetta/codecs/video/H263/Tables.luau"], +[94827, "src/Rosetta/codecs/video/H264/init.luau"], +[95200, "src/Rosetta/codecs/video/H264/Bitstream.luau"], +[95475, "src/Rosetta/codecs/video/H264/Cabac.luau"], +[96606, "src/Rosetta/codecs/video/H264/Cavlc.luau"], +[97374, "src/Rosetta/codecs/video/H264/Deblock.luau"], +[97632, "src/Rosetta/codecs/video/H264/Decoder.luau"], +[98641, "src/Rosetta/codecs/video/H264/Inter.luau"], +[98895, "src/Rosetta/codecs/video/H264/Intra.luau"], +[99302, "src/Rosetta/codecs/video/H264/Mb.luau"], +[100208, "src/Rosetta/codecs/video/H264/Params.luau"], +[100655, "src/Rosetta/codecs/video/H264/Slice.luau"], +[100906, "src/Rosetta/codecs/video/H264/Tables.luau"], +[100947, "src/Rosetta/codecs/video/H264/Transform.luau"], +[101112, "src/Rosetta/codecs/video/Legacy/init.luau"], +[101310, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], +[101607, "src/Rosetta/codecs/video/Legacy/Flic.luau"], +[101974, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], +[102092, "src/Rosetta/codecs/video/Legacy/Picture.luau"], +[102200, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], +[102473, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], +[102868, "src/Rosetta/codecs/video/Legacy/Smc.luau"], +[103045, "src/Rosetta/codecs/video/Mpeg1/init.luau"], +[103057, "src/Rosetta/codecs/video/Mpeg2/init.luau"], +[103424, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], +[104931, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], +[105070, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], +[105208, "src/Rosetta/codecs/video/Theora/init.luau"], +[105471, "src/Rosetta/codecs/video/Theora/Decoder.luau"], +[106735, "src/Rosetta/codecs/video/Theora/Header.luau"], +[107098, "src/Rosetta/codecs/video/Video/init.luau"], +[107655, "src/Rosetta/codecs/video/Video/Source.luau"], +[107940, "src/Rosetta/containers/Archive.luau"], +[108207, "src/Rosetta/containers/AudioWrap.luau"], +[108710, "src/Rosetta/containers/Avi/init.luau"], +[109262, "src/Rosetta/containers/Chunks.luau"], +[109397, "src/Rosetta/containers/Cpio.luau"], +[109825, "src/Rosetta/containers/Demux.luau"], +[110100, "src/Rosetta/containers/Ebml/init.luau"], +[110413, "src/Rosetta/containers/Fat.luau"], +[111101, "src/Rosetta/containers/Iso9660.luau"], +[111606, "src/Rosetta/containers/IsoBmff/init.luau"], +[111776, "src/Rosetta/containers/IsoBmff/Box.luau"], +[111964, "src/Rosetta/containers/IsoBmff/Demux.luau"], +[112809, "src/Rosetta/containers/IsoBmff/Meta.luau"], +[113330, "src/Rosetta/containers/IsoBmff/Mux.luau"], +[113846, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], +[113963, "src/Rosetta/containers/MacFile.luau"], +[114112, "src/Rosetta/containers/MpegEs.luau"], +[114278, "src/Rosetta/containers/MpegPs/init.luau"], +[114498, "src/Rosetta/containers/MpegTs/init.luau"], +[115290, "src/Rosetta/containers/Ogg/init.luau"], +[115715, "src/Rosetta/containers/Ogg/Mux.luau"], +[115910, "src/Rosetta/containers/Ogg/Page.luau"], +[116079, "src/Rosetta/containers/Riff/init.luau"], +[116396, "src/Rosetta/containers/Tar.luau"], +[116810, "src/Rosetta/containers/Zip/init.luau"], +[117442, "src/Rosetta/core/Adler32.luau"], +[117488, "src/Rosetta/core/Base64.luau"], +[117647, "src/Rosetta/core/Bits.luau"], +[117940, "src/Rosetta/core/Bytes.luau"], +[118467, "src/Rosetta/core/Crc16.luau"], +[118519, "src/Rosetta/core/Crc32.luau"], +[118631, "src/Rosetta/core/Err.luau"], +[118713, "src/Rosetta/core/Input.luau"], +[118789, "src/Rosetta/core/Md5.luau"], +[118948, "src/Rosetta/core/Sniff.luau"], +[118977, "src/Rosetta/data/cbor/init.luau"], +[119076, "src/Rosetta/data/cbor/Codec.luau"], +[119645, "src/Rosetta/data/csv/init.luau"], +[119957, "src/Rosetta/data/ini/init.luau"], +[120203, "src/Rosetta/data/json/init.luau"], +[120295, "src/Rosetta/data/msgpack/init.luau"], +[120384, "src/Rosetta/data/msgpack/Codec.luau"], +[120826, "src/Rosetta/data/nbt/init.luau"], +[120885, "src/Rosetta/data/plist/init.luau"], +[121191, "src/Rosetta/data/plist/Binary.luau"], +[121458, "src/Rosetta/data/snbt/init.luau"], +[121521, "src/Rosetta/data/toml/init.luau"], +[121588, "src/Rosetta/data/toml/Decode.luau"], +[122216, "src/Rosetta/data/toml/Encode.luau"], +[122425, "src/Rosetta/data/xml/init.luau"], +[122481, "src/Rosetta/data/yaml/init.luau"], +[122554, "src/Rosetta/data/yaml/Emit.luau"], +[122844, "src/Rosetta/data/yaml/Parse.luau"], +[124137, "src/Rosetta/font/bdf/init.luau"], +[124426, "src/Rosetta/font/bmfont/init.luau"], +[124853, "src/Rosetta/font/bmfont/Parse.luau"], +[125306, "src/Rosetta/font/eot/init.luau"], +[125538, "src/Rosetta/font/fon/init.luau"], +[125821, "src/Rosetta/font/hershey/init.luau"], +[126016, "src/Rosetta/font/pcf/init.luau"], +[126296, "src/Rosetta/font/psf/init.luau"], +[126616, "src/Rosetta/font/ttf/init.luau"], +[126667, "src/Rosetta/font/type1/init.luau"], +[127026, "src/Rosetta/font/type1/Charstring.luau"], +[127304, "src/Rosetta/font/woff/init.luau"], +[127436, "src/Rosetta/font/woff2/init.luau"], +[127493, "src/Rosetta/font/woff2/Rebuild.luau"], +[128033, "src/Rosetta/host/init.luau"], +[128078, "src/Rosetta/host/Love.luau"], +[128221, "src/Rosetta/host/LuaJIT.luau"], +[128271, "src/Rosetta/host/Luau.luau"], +[128294, "src/Rosetta/host/Roblox.luau"], +[128653, "src/Rosetta/image/ani/init.luau"], +[128833, "src/Rosetta/image/blp/init.luau"], +[129091, "src/Rosetta/image/bmp/init.luau"], +[129506, "src/Rosetta/image/dds/init.luau"], +[129989, "src/Rosetta/image/exr/init.luau"], +[130749, "src/Rosetta/image/exr/Codec.luau"], +[130860, "src/Rosetta/image/exr/Piz.luau"], +[131217, "src/Rosetta/image/gif/init.luau"], +[131733, "src/Rosetta/image/gif/Decode.luau"], +[131796, "src/Rosetta/image/hdr/init.luau"], +[132025, "src/Rosetta/image/hdr/Codec.luau"], +[132236, "src/Rosetta/image/icns/init.luau"], +[132567, "src/Rosetta/image/ico/init.luau"], +[132844, "src/Rosetta/image/ico/Dib.luau"], +[132939, "src/Rosetta/image/ilbm/init.luau"], +[133258, "src/Rosetta/image/jpeg/init.luau"], +[133394, "src/Rosetta/image/ktx/init.luau"], +[134054, "src/Rosetta/image/pcx/init.luau"], +[134318, "src/Rosetta/image/png/init.luau"], +[134898, "src/Rosetta/image/png/Apng.luau"], +[134978, "src/Rosetta/image/png/Decode.luau"], +[135218, "src/Rosetta/image/png/Encode.luau"], +[135373, "src/Rosetta/image/pnm/init.luau"], +[135751, "src/Rosetta/image/pnm/Codec.luau"], +[136028, "src/Rosetta/image/qoi/init.luau"], +[136150, "src/Rosetta/image/qoi/Codec.luau"], +[136300, "src/Rosetta/image/sgi/init.luau"], +[136585, "src/Rosetta/image/sunras/init.luau"], +[136831, "src/Rosetta/image/tga/init.luau"], +[137101, "src/Rosetta/image/tga/Codec.luau"], +[137253, "src/Rosetta/image/tiff/init.luau"], +[138080, "src/Rosetta/image/tiff/Pixels.luau"], +[138470, "src/Rosetta/image/tim/init.luau"], +[138712, "src/Rosetta/image/vtf/init.luau"], +[138947, "src/Rosetta/image/webp/init.luau"], +[139557, "src/Rosetta/image/webp/Alpha.luau"], +[139633, "src/Rosetta/image/webp/Anim.luau"], +[139788, "src/Rosetta/image/xbm/init.luau"], +[139949, "src/Rosetta/image/xpm/init.luau"], +[140217, "src/Rosetta/image/xpm/Names.luau"], +[140273, "src/Rosetta/layered/aseprite/init.luau"], +[141011, "src/Rosetta/layered/ora/init.luau"], +[141298, "src/Rosetta/layered/psd/init.luau"], +[142033, "src/Rosetta/layered/psd/Channels.luau"], +[142385, "src/Rosetta/model/3ds/init.luau"], +[142468, "src/Rosetta/model/3ds/Build.luau"], +[143115, "src/Rosetta/model/3ds/Read.luau"], +[143611, "src/Rosetta/model/3ds/Write.luau"], +[144416, "src/Rosetta/model/3mf/init.luau"], +[144498, "src/Rosetta/model/3mf/Read.luau"], +[145086, "src/Rosetta/model/3mf/Write.luau"], +[145491, "src/Rosetta/model/b3d/init.luau"], +[145546, "src/Rosetta/model/b3d/Read.luau"], +[146117, "src/Rosetta/model/bsp/init.luau"], +[146262, "src/Rosetta/model/bsp/Brush.luau"], +[146525, "src/Rosetta/model/bsp/Quake3.luau"], +[146753, "src/Rosetta/model/dae/init.luau"], +[146942, "src/Rosetta/model/dae/Math.luau"], +[146989, "src/Rosetta/model/dae/Read.luau"], +[148839, "src/Rosetta/model/dae/Write.luau"], +[149208, "src/Rosetta/model/fbx/init.luau"], +[149356, "src/Rosetta/model/fbx/Ascii.luau"], +[149626, "src/Rosetta/model/fbx/Binary.luau"], +[150081, "src/Rosetta/model/fbx/Read.luau"], +[151443, "src/Rosetta/model/fbx/Write.luau"], +[152428, "src/Rosetta/model/fbx/Xform.luau"], +[152469, "src/Rosetta/model/gltf/init.luau"], +[152706, "src/Rosetta/model/gltf/Pack.luau"], +[152775, "src/Rosetta/model/gltf/Read.luau"], +[153506, "src/Rosetta/model/gltf/Write.luau"], +[154186, "src/Rosetta/model/iqm/init.luau"], +[154262, "src/Rosetta/model/iqm/Read.luau"], +[154617, "src/Rosetta/model/iqm/Write.luau"], +[155304, "src/Rosetta/model/ldraw/init.luau"], +[155382, "src/Rosetta/model/ldraw/Colors.luau"], +[155700, "src/Rosetta/model/ldraw/Read.luau"], +[156277, "src/Rosetta/model/lwo/init.luau"], +[156353, "src/Rosetta/model/lwo/Build.luau"], +[156815, "src/Rosetta/model/lwo/Parse.luau"], +[157358, "src/Rosetta/model/mca/init.luau"], +[157700, "src/Rosetta/model/mca/Chunk.luau"], +[157833, "src/Rosetta/model/mca/Lz4Block.luau"], +[157903, "src/Rosetta/model/md2/init.luau"], +[158102, "src/Rosetta/model/md3/init.luau"], +[158330, "src/Rosetta/model/md5/init.luau"], +[158411, "src/Rosetta/model/md5/Read.luau"], +[158844, "src/Rosetta/model/mdl/init.luau"], +[158926, "src/Rosetta/model/mdl/HalfLife.luau"], +[159254, "src/Rosetta/model/mdl/Quake.luau"], +[159472, "src/Rosetta/model/ms3d/init.luau"], +[159544, "src/Rosetta/model/ms3d/Read.luau"], +[159990, "src/Rosetta/model/ms3d/Write.luau"], +[160459, "src/Rosetta/model/obj/init.luau"], +[161201, "src/Rosetta/model/obj/Mtl.luau"], +[161488, "src/Rosetta/model/off/init.luau"], +[161950, "src/Rosetta/model/ply/init.luau"], +[163055, "src/Rosetta/model/ply/Binary.luau"], +[163256, "src/Rosetta/model/pmx/init.luau"], +[163325, "src/Rosetta/model/pmx/Build.luau"], +[163621, "src/Rosetta/model/pmx/Pmd.luau"], +[163956, "src/Rosetta/model/pmx/Read.luau"], +[164360, "src/Rosetta/model/qb/init.luau"], +[164753, "src/Rosetta/model/rbxm/init.luau"], +[165345, "src/Rosetta/model/rbxmx/init.luau"], +[165998, "src/Rosetta/model/robloxmesh/init.luau"], +[166657, "src/Rosetta/model/robloxmesh/Parse.luau"], +[167114, "src/Rosetta/model/robloxmesh/Write.luau"], +[167223, "src/Rosetta/model/schematic/init.luau"], +[167544, "src/Rosetta/model/schematic/Common.luau"], +[167664, "src/Rosetta/model/schematic/Litematic.luau"], +[167875, "src/Rosetta/model/schematic/Mcedit.luau"], +[168119, "src/Rosetta/model/schematic/Sponge.luau"], +[168248, "src/Rosetta/model/smd/init.luau"], +[168315, "src/Rosetta/model/smd/Read.luau"], +[168584, "src/Rosetta/model/smd/Write.luau"], +[168827, "src/Rosetta/model/stl/init.luau"], +[169277, "src/Rosetta/model/stl/Decode.luau"], +[169351, "src/Rosetta/model/usda/init.luau"], +[169560, "src/Rosetta/model/usda/Build.luau"], +[170838, "src/Rosetta/model/usda/Parse.luau"], +[171636, "src/Rosetta/model/usda/Write.luau"], +[172453, "src/Rosetta/model/vox/init.luau"], +[173339, "src/Rosetta/model/vox/Grid.luau"], +[173396, "src/Rosetta/model/vrml/init.luau"], +[173462, "src/Rosetta/model/x/init.luau"], +[173592, "src/Rosetta/model/x/Build.luau"], +[174155, "src/Rosetta/model/x/Parse.luau"], +[174452, "src/Rosetta/model/x3d/init.luau"], +[174530, "src/Rosetta/music/669/init.luau"], +[174736, "src/Rosetta/music/ahx/init.luau"], +[174787, "src/Rosetta/music/far/init.luau"], +[175016, "src/Rosetta/music/hmp/init.luau"], +[175280, "src/Rosetta/music/hvl/init.luau"], +[175331, "src/Rosetta/music/it/init.luau"], +[175749, "src/Rosetta/music/it/Itsex.luau"], +[175865, "src/Rosetta/music/med/init.luau"], +[176512, "src/Rosetta/music/midi/init.luau"], +[176655, "src/Rosetta/music/midi/Smf.luau"], +[177066, "src/Rosetta/music/mod/init.luau"], +[177419, "src/Rosetta/music/mtm/init.luau"], +[177641, "src/Rosetta/music/mus/init.luau"], +[177798, "src/Rosetta/music/okt/init.luau"], +[178079, "src/Rosetta/music/ptm/init.luau"], +[178301, "src/Rosetta/music/s3m/init.luau"], +[178537, "src/Rosetta/music/sf2/init.luau"], +[178580, "src/Rosetta/music/stm/init.luau"], +[178811, "src/Rosetta/music/ult/init.luau"], +[179115, "src/Rosetta/music/umx/init.luau"], +[179331, "src/Rosetta/music/xm/init.luau"], +[179892, "src/Rosetta/music/xmi/init.luau"], +[180100, "src/Rosetta/ops/AudioOps.luau"], +[180549, "src/Rosetta/ops/ImageOps/init.luau"], +[181193, "src/Rosetta/ops/ImageOps/Kernels.luau"], +[181703, "src/Rosetta/ops/LayerOps.luau"], +[181796, "src/Rosetta/ops/MeshOps/init.luau"], +[182832, "src/Rosetta/ops/MeshOps/Greedy.luau"], +[182999, "src/Rosetta/ops/MusicOps.luau"], +[183347, "src/Rosetta/playlist/m3u/init.luau"], +[183700, "src/Rosetta/playlist/pls/init.luau"], +[183878, "src/Rosetta/playlist/xspf/init.luau"], +[184081, "src/Rosetta/subtitle/ass/init.luau"], +[184525, "src/Rosetta/subtitle/srt/init.luau"], +[184698, "src/Rosetta/subtitle/vtt/init.luau"], +[184901, "src/Rosetta/vector/svg/init.luau"], +[184987, "src/Rosetta/vector/svg/Parse.luau"], +[185733, "src/Rosetta/vector/svg/PathData.luau"], +[186101, "src/Rosetta/vector/svg/Render.luau"], +[186518, "src/Rosetta/vector/svg/Style.luau"], +[186890, "src/Rosetta/vector/svg/Write.luau"], +[187090, "src/Rosetta/vector/tiled/init.luau"], +[187270, "src/Rosetta/vector/tiled/Data.luau"], +[187421, "src/Rosetta/vector/tiled/Tmj.luau"], +[188052, "src/Rosetta/vector/tiled/Tmx.luau"], +[188664, "src/Rosetta/video/avi/init.luau"], +[188958, "src/Rosetta/video/fli/init.luau"], +[189109, "src/Rosetta/video/flv/init.luau"], +[189493, "src/Rosetta/video/flv/Amf.luau"], +[189651, "src/Rosetta/video/flv/Mux.luau"], +[189932, "src/Rosetta/video/h264/init.luau"], +[190071, "src/Rosetta/video/mkv/init.luau"], +[190227, "src/Rosetta/video/mkv/Mux.luau"], +[190506, "src/Rosetta/video/mkv/Parse.luau"], +[191227, "src/Rosetta/video/mp4/init.luau"], +[191555, "src/Rosetta/video/mpegps/init.luau"], +[191742, "src/Rosetta/video/mpegts/init.luau"], +[191980, "src/Rosetta/video/ogv/init.luau"], +[192375, "src/Rosetta/video/smk/init.luau"], +[192684, "src/Rosetta/video/smk/Audio.luau"], +[192804, "src/Rosetta/video/y4m/init.luau"] ] diff --git a/docs/FORMATS.md b/docs/FORMATS.md index f2a9a60..6d65cc7 100644 --- a/docs/FORMATS.md +++ b/docs/FORMATS.md @@ -236,7 +236,8 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain: - codecs/image/Etc: ETC1 / ETC2 / EAC block texture decoding (Khronos Data Format Specification 1.3, section 21). - codecs/image/Half: IEEE 754 binary16 <-> number (round to nearest even, overflow to infinity). New in rosetta. - codecs/image/Jpeg: the JPEG codec (ITU T.81), bit-exact with libjpeg-turbo's djpeg and byte-identical with cjpeg. - - codecs/image/Pixels: row loops between packed pixel layouts and rgba8 for BMP / DIB. + - codecs/image/Miptex: Quake / GoldSrc mip textures and the WAD2 / WAD3 lump directory, read and write. + - codecs/image/Pixels: row loops between packed pixel layouts and rgba8 for BMP / DIB, and palette helpers. - codecs/image/Quantize: palette quantization of rgba8 pixels (median cut or octree, Floyd-Steinberg dithering). - codecs/image/Raster: an antialiased scanline rasterizer (nonzero / even-odd) for line and Bézier paths, plus a stroker. - codecs/image/Texel: uncompressed GPU texel formats -> the standard pixel formats. New in rosetta. @@ -245,10 +246,12 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain: - codecs/image/Vp8L: WebP lossless (VP8L, RFC 9649 section 3). - codecs/image/Yuv: planar 4:2:0 Y'CbCr <-> rgba8, BT.601 / BT.709, limited or full range. - **model** + - codecs/model/Brush: convex plane brushes -> polygons and Scene primitives, with Quake-family texture projection. - codecs/model/Draco: Google Draco geometry decompression (.drc; glTF KHR_draco_mesh_compression; Roblox mesh v6 / v7). - codecs/model/Mat4: 4x4 matrix (column-major, glTF / Types.Scene layout) and quaternion { x, y, z, w } helpers. - codecs/model/MeshFlatten: a Scene to one world-space mesh, for the writers of mesh-only formats (STL, PLY, OFF). - codecs/model/Minecraft: what Minecraft's voxel formats share (model/schematic, model/mca). New code. + - codecs/model/Patch: Quake III / Doom 3 Bezier patches (control grids) -> evaluated grids, triangles, normals. - codecs/model/Polygon: 2D polygons with holes to triangles by hole bridging and ear clipping. New code. - codecs/model/Rbx: the Roblox instance tree and property values shared by model/rbxm and model/rbxmx. - codecs/model/Rig: the Scene mapping shared by game model formats (MD2 / MD3 / MDL / MD5 / SMD / ...). New code. diff --git a/docs/STYLE.md b/docs/STYLE.md index b1a40f4..0238ae0 100644 --- a/docs/STYLE.md +++ b/docs/STYLE.md @@ -29,13 +29,13 @@ src/Rosetta/ codecs// codecs (layer 3) generic algorithms, by domain: compress/ Brotli Bzip2 Deflate Explode Lz4 Lzh Lzma Lzw Lzx PackBits Quantum UnixCompress Xxh32 Zstd entropy/ Huffman RangeCoder - image/ Bcn Blend Dct Etc Half Jpeg Pixels Quantize Raster Texel Texture Vp8 Vp8L Yuv + image/ Bcn Blend Dct Etc Half Jpeg Miptex Pixels Quantize Raster Texel Texture Vp8 Vp8L Yuv audio/ Aac Ac3 Adpcm Alac Ape ApeTag Flac Hively Mdct MidiRender Mpa Musepack Opus Pcm Qoa Resample SoundFont Stream Tracker Tta Vorbis VorbisComment WavPack video/ Dsp H263 H264 Legacy Mpeg1 Mpeg2 Theora Video (the video codec registry) text/ Json Nbt Text Url Xml font/ Bitmap Cff GlyphNames TrueType - model/ Draco Mat4 MeshFlatten Minecraft Polygon Rbx Rig Sampler Vrml + model/ Brush Draco Mat4 MeshFlatten Minecraft Patch Polygon Rbx Rig Sampler Vrml host/ host (layer 2) runtime adapters; only the api uses them Types.luau types (layer 1) standard types + constructors core/ core (layer 0) Adler32 Base64 Bits Bytes Crc16 Crc32 Err Input @@ -242,6 +242,8 @@ them. Anything generic goes down a layer and is called: | GPU texture pixels (BCn, ETC / EAC, uncompressed texel layouts, half floats) | `codecs/image/Texture` (`Bcn`, `Etc`, `Texel`, `Half`) | | animation channels sampled at a time; game-model frames, joints and skins -> Scene | `codecs/model/Sampler`, `codecs/model/Rig` | | polygons with holes -> triangles | `codecs/model/Polygon` | +| plane brushes -> polygons (CSG hull, coplanar merge, Quake / Valve 220 / brush-primitive texturing); Bezier patches | `codecs/model/Brush`, `codecs/model/Patch` | +| Quake / GoldSrc mip textures, WAD2 / WAD3 directories; palettes (keyed index, grey, colormap) | `codecs/image/Miptex`, `codecs/image/Pixels` | | NBT / SNBT values; Minecraft block states and colours | `codecs/text/Nbt`, `codecs/model/Minecraft` | | Roblox instance trees and property values | `codecs/model/Rbx` | | bitmap fonts as a Font; PostScript glyph names | `codecs/font/Bitmap`, `codecs/font/GlyphNames` | diff --git a/src/Rosetta/Registry.luau b/src/Rosetta/Registry.luau index 062b60a..28da06f 100644 --- a/src/Rosetta/Registry.luau +++ b/src/Rosetta/Registry.luau @@ -740,7 +740,7 @@ local list: { Entry } = { path = "model/bsp", extensions = { "bsp" }, mime = { "model/x-bsp" }, - deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels" }, + deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels", "codecs/image/Miptex", "codecs/model/Patch" }, caps = { decode = true, encode = false, variants = { "quake", "halflife", "quake2", "quake3" }, lightmaps = "quake3" }, load = function() return require("@rosetta/model/bsp") diff --git a/src/Rosetta/codecs/image/Miptex.luau b/src/Rosetta/codecs/image/Miptex.luau new file mode 100644 index 0000000..eb6edbf --- /dev/null +++ b/src/Rosetta/codecs/image/Miptex.luau @@ -0,0 +1,214 @@ +--!strict +-- codecs/image/Miptex: Quake / GoldSrc mip textures and the WAD2 / WAD3 lump directory, read and write. +-- miptex_t of bspfile.h: name[16], width, height, offsets[4], four 8-bit mip levels; GoldSrc adds u16 count + count * 3 +-- palette bytes after mip 3. wad.h: "WAD2" / "WAD3", numlumps, infotableofs; 32-byte lumpinfo_t. No code taken. +local Types = require("@rosetta/Types") +local Pixels = require("@rosetta/codecs/image/Pixels") +local Quantize = require("@rosetta/codecs/image/Quantize") + +local Miptex = {} + +local readu8, readu32, readi32 = buffer.readu8, buffer.readu32, buffer.readi32 + +export type Header = { name: string, width: number, height: number, offsets: { number } } +export type Lump = { name: string, offset: number, disksize: number, size: number, type: number, compression: number } +export type DecodeOptions = { + palette: buffer?, -- 1024-byte rgba8 palette (Pixels.palette) when the texture has none of its own + goldsrc: boolean?, -- read the palette stored after mip 3 + mip: number?, -- 0..3, default 0 + keyed: boolean?, -- index 255 transparent; default: names starting with '{' + maxPixels: number?, -- default 2^24 +} + +-- lumpinfo_t types (wad.h TYP_*; WAD3: 0x43 is a miptex with its palette, 0x46 a font) +Miptex.TYPES = table.freeze({ palette = 0x40, qtex = 0x41, qpic = 0x42, sound = 0x43, miptex = 0x44, font = 0x46 }) + +local function cstr(b: buffer, at: number, n: number): string + return (string.match(buffer.readstring(b, at, n), "^[^%z]*")) :: string +end + +function Miptex.header(b: buffer, at: number, size: number): (Header?, string?) + if at < 0 or size < 40 or at + 40 > buffer.len(b) then + return nil, "truncated miptex header" + end + local w, h = readu32(b, at + 16), readu32(b, at + 20) + local offs = { readu32(b, at + 24), readu32(b, at + 28), readu32(b, at + 32), readu32(b, at + 36) } + return { name = cstr(b, at, 16), width = w, height = h, offsets = offs }, nil +end + +-- the GoldSrc palette after mip 3, as a 1024-byte rgba8 palette, or nil when it is missing / out of range +function Miptex.ownPalette(b: buffer, at: number, size: number, hd: Header): buffer? + local w, h = hd.width, hd.height + local p = hd.offsets[4] + (w // 8) * (h // 8) + if hd.offsets[4] == 0 or p + 2 > size then + return nil + end + local n = buffer.readu16(b, at + p) + if n == 0 or n > 256 or p + 2 + n * 3 > size then + return nil + end + return Pixels.palette(b, at + p + 2, n) +end + +-- decodes one mip level to rgba8; without pixels (offsets 0: the texture lives in a WAD) returns nil, "external" +function Miptex.decode(b: buffer, at: number, size: number, opts: DecodeOptions?): (Types.Image?, string?) + local hd, err = Miptex.header(b, at, size) + if not hd then + return nil, err + end + local mip = math.clamp(math.floor(opts and opts.mip or 0), 0, 3) + local w, h = hd.width // (2 ^ mip), hd.height // (2 ^ mip) + if hd.width == 0 or hd.height == 0 or w == 0 or h == 0 then + return nil, "empty miptex" + end + if hd.width * hd.height > (opts and opts.maxPixels or 2 ^ 24) then + return nil, "limit: miptex " .. hd.width .. " x " .. hd.height + end + local off = hd.offsets[mip + 1] + if off == 0 then + return nil, "external" + end + if off + w * h > size or at + off + w * h > buffer.len(b) then + return nil, "truncated miptex pixels" + end + local own = if opts and opts.goldsrc then Miptex.ownPalette(b, at, size, hd) else nil + local pal = own or (opts and opts.palette) or Pixels.grey() + local keyed = if opts and opts.keyed ~= nil then opts.keyed else string.sub(hd.name, 1, 1) == "{" + if keyed then + pal = Pixels.keyed(pal, 255) + end + local img = Types.Image.new(w, h) + Pixels.indexed(b, at + off, w, 8, img.pixels, w, h, true, pal) + img.meta.source = { format = "miptex", name = hd.name, mip = mip, palette = own ~= nil or (opts ~= nil and opts.palette ~= nil), keyed = keyed or nil } + return img, nil +end + +local function halve(px: buffer, w: number, h: number): (buffer, number, number) + local w2, h2 = math.max(1, w // 2), math.max(1, h // 2) + local out = buffer.create(w2 * h2 * 4) + for y = 0, h2 - 1 do + for x = 0, w2 - 1 do + for c = 0, 3 do + local s = 0 + for dy = 0, 1 do + for dx = 0, 1 do + local sx, sy = math.min(x * 2 + dx, w - 1), math.min(y * 2 + dy, h - 1) + s += readu8(px, (sy * w + sx) * 4 + c) + end + end + buffer.writeu8(out, (y * w2 + x) * 4 + c, (s + 2) // 4) + end + end + end + return out, w2, h2 +end + +-- an rgba8 image -> a miptex_t with four mip levels (box filtered, mapped to the nearest palette entry); goldsrc +-- appends the palette. palette: 1024-byte rgba8; without it (GoldSrc only) a 256-colour median-cut palette is made. +function Miptex.encode(img: Types.Image, name: string, palette: buffer?, goldsrc: boolean?): (buffer?, string?) + local w, h = img.width, img.height + if w <= 0 or h <= 0 or w % 16 ~= 0 or h % 16 ~= 0 then + return nil, "miptex sizes must be multiples of 16" + end + if #name > 15 then + return nil, "miptex name over 15 bytes" + end + local colors: { { number } } + if palette then + colors = Pixels.colorList(palette) + elseif goldsrc then + colors = Quantize.palette(img.pixels, w, h, 256) + else + return nil, "a Quake miptex needs a palette" + end + local keyed = string.sub(name, 1, 1) == "{" + local levels: { buffer } = {} + local px, lw, lh = img.pixels, w, h + for m = 0, 3 do + if m > 0 then + px, lw, lh = halve(px, lw, lh) + end + local idx = Quantize.map(px, lw, lh, colors, { transparentIndex = if keyed then 255 else nil }) + if keyed then + for k = 0, lw * lh - 1 do + if readu8(px, k * 4 + 3) < 128 then + buffer.writeu8(idx, k, 255) + end + end + end + levels[m + 1] = idx + end + local total = 40 + for _, l in levels do + total += buffer.len(l) + end + local palAt = total + if goldsrc then + total += 2 + 768 + 2 + end + local out = buffer.create(total) + buffer.writestring(out, 0, name) + buffer.writeu32(out, 16, w) + buffer.writeu32(out, 20, h) + local o = 40 + for m, l in levels do + buffer.writeu32(out, 24 + (m - 1) * 4, o) + buffer.copy(out, o, l) + o += buffer.len(l) + end + if goldsrc then + buffer.writeu16(out, palAt, 256) + for i = 0, 255 do + local c = colors[i + 1] or { 0, 0, 0 } + buffer.writeu8(out, palAt + 2 + i * 3, c[1]) + buffer.writeu8(out, palAt + 3 + i * 3, c[2]) + buffer.writeu8(out, palAt + 4 + i * 3, c[3]) + end + end + return out, nil +end + +-- the lump directory of a WAD2 / WAD3 file (offsets relative to base), or nil, message +function Miptex.wad(b: buffer, base: number, size: number, maxLumps: number?): ({ Lump }?, string?, string?) + if size < 12 or base + 12 > buffer.len(b) then + return nil, "truncated header", nil + end + local magic = buffer.readstring(b, base, 4) + if magic ~= "WAD2" and magic ~= "WAD3" then + return nil, "bad magic", nil + end + local n, dir = readi32(b, base + 4), readi32(b, base + 8) + if n < 0 or dir < 0 then + return nil, "negative directory field", nil + end + if n > (maxLumps or 1e6) then + return nil, "limit: too many lumps: " .. n, nil + end + if dir + n * 32 > size then + return nil, "truncated directory past the end", nil + end + local out: { Lump } = {} + for i = 0, n - 1 do + local o = base + dir + i * 32 + local at, disk, full = readi32(b, o), readi32(b, o + 4), readi32(b, o + 8) + if at < 0 or disk < 0 or at + disk > size then + return nil, "truncated lump past the end", nil + end + out[i + 1] = { name = cstr(b, o + 16, 16), offset = at, disksize = disk, size = full, type = readu8(b, o + 12), compression = readu8(b, o + 13) } + end + return out, nil, magic +end + +-- the lump named name (case-insensitive, the last one wins as in W_GetLumpinfo) +function Miptex.find(lumps: { Lump }, name: string): Lump? + local want = string.lower(name) + local best: Lump? = nil + for _, l in lumps do + if string.lower(l.name) == want then + best = l + end + end + return best +end + +return Miptex diff --git a/src/Rosetta/codecs/image/Pixels.luau b/src/Rosetta/codecs/image/Pixels.luau index 30a15a8..d7db8ab 100644 --- a/src/Rosetta/codecs/image/Pixels.luau +++ b/src/Rosetta/codecs/image/Pixels.luau @@ -1,8 +1,9 @@ --!strict --!native --!optimize 2 --- codecs/image/Pixels: row loops between packed pixel layouts and rgba8 for BMP / DIB. --- Indexed, BGR(A), 5-5-5, bit masks, RLE4 / RLE8. From bmp-luau b86aed6 (same author); the encoder loops are new. +-- codecs/image/Pixels: row loops between packed pixel layouts and rgba8 for BMP / DIB, and palette helpers. +-- Indexed, BGR(A), 5-5-5, bit masks, RLE4 / RLE8; palettes: keyed index (Quake 255), grey ramp, Quake colormap light +-- levels. From bmp-luau b86aed6 (same author); the encoder loops and palette helpers are new. local readu8, readu16, readu32, writeu32, writeu8 = buffer.readu8, buffer.readu16, buffer.readu32, buffer.writeu32, buffer.writeu8 local band, rshift, bor, lshift = bit32.band, bit32.rshift, bit32.bor, bit32.lshift @@ -259,4 +260,59 @@ function Pixels.colours(src: buffer, n: number, max: number): ({ number }, boole return list, alpha end +-- a 256-entry rgba8 palette (u32 LE per entry) with entry i = { i, i, i, 255 } +function Pixels.grey(): buffer + local pal = buffer.create(1024) + for i = 0, 255 do + writeu32(pal, i * 4, 0xFF000000 + i * 0x10101) + end + return pal +end + +-- a copy of a 1024-byte palette with entry index fully transparent (Quake / GoldSrc: index 255 of sprites, qpics and +-- '{' textures) +function Pixels.keyed(pal: buffer, index: number): buffer + local out = buffer.create(1024) + buffer.copy(out, 0, pal, 0, math.min(buffer.len(pal), 1024)) + if index >= 0 and index < 256 then + writeu32(out, index * 4, 0) + end + return out +end + +-- palette (1024 bytes) -> { { r, g, b, a } } for codecs/image/Quantize +function Pixels.colorList(pal: buffer, n: number?): { { number } } + local out: { { number } } = {} + for i = 0, math.clamp(n or 256, 0, buffer.len(pal) // 4) - 1 do + out[i + 1] = { readu8(pal, i * 4), readu8(pal, i * 4 + 1), readu8(pal, i * 4 + 2), readu8(pal, i * 4 + 3) } + end + return out +end + +-- Quake colormap.lmp: rows of 256 palette indices, row 0 brightest .. 63 darkest (32 = unlit); the palette for one +-- light level, or nil past the end of the map +function Pixels.colormap(pal: buffer, cmap: buffer, base: number, row: number): buffer? + local o = base + row * 256 + if row < 0 or base < 0 or o + 256 > buffer.len(cmap) then + return nil + end + local out = buffer.create(1024) + for i = 0, 255 do + writeu32(out, i * 4, readu32(pal, readu8(cmap, o + i) * 4)) + end + return out +end + +-- rgba8 palette (1024 bytes) -> 3 * n bytes R, G, B (the Quake / GoldSrc palette layout) +function Pixels.paletteBytes(pal: buffer, n: number?): buffer + local m = math.clamp(n or 256, 0, 256) + local out = buffer.create(m * 3) + for i = 0, m - 1 do + writeu8(out, i * 3, readu8(pal, i * 4)) + writeu8(out, i * 3 + 1, readu8(pal, i * 4 + 1)) + writeu8(out, i * 3 + 2, readu8(pal, i * 4 + 2)) + end + return out +end + return Pixels diff --git a/src/Rosetta/codecs/model/Brush.luau b/src/Rosetta/codecs/model/Brush.luau new file mode 100644 index 0000000..a76dfb3 --- /dev/null +++ b/src/Rosetta/codecs/model/Brush.luau @@ -0,0 +1,638 @@ +--!strict +--!native +--!optimize 2 +-- codecs/model/Brush: convex plane brushes -> polygons and Scene primitives, with Quake-family texture projection. +-- As qbsp (Quake / ericw-tools; no code taken): a big square on every plane (inside n . p <= d) clipped by the others. +-- Projections: Quake standard (TextureAxisFromPlane + rotate / scale / shift), Valve 220 (explicit U / V axes), Quake +-- III brush primitives (q3map2 ComputeAxisBase + 2 x 3 matrix). Options: merge coplanar faces with one projection +-- (qbsp TryMerge), drop face parts inside / touching other brushes (qbsp CSGFaces; earlier brushes win coplanar ties). +local Types = require("@rosetta/Types") + +local Brush = {} + +local abs, sqrt, floor, sin, cos, atan2, min, max = math.abs, math.sqrt, math.floor, math.sin, math.cos, math.atan2, math.min, math.max +local writef32, writeu32 = buffer.writef32, buffer.writeu32 + +export type Plane = { number } -- nx, ny, nz, d (unit normal pointing out of the brush) +export type Face = { + plane: Plane, + texture: string?, + vecs: { { number } }?, -- 2 x 4: s = p . vecs[1].xyz + vecs[1][4] in texels (Quake standard / Valve 220) + bp: { { number } }?, -- 2 x 3 brush-primitive matrix: s = bp[1] . (p . texS, p . texT, 1) in texture widths + [string]: any, +} +export type Polygon = { + brush: number, + face: number, + points: { number }, -- x, y, z per corner, counter-clockwise seen from the front + normal: { number }, +} +export type Options = { + epsilon: number?, -- plane side tolerance, default 1e-3 + size: number?, -- half size of the starting winding, default 2^17 + merge: boolean?, -- merge coplanar faces with the same texture projection, default false + hull: boolean?, -- drop face parts inside / touching other brushes, default false + maxPolygons: number?, -- default 2^20 +} +export type Built = { texture: string, primitive: Types.Primitive } + +-- TextureAxisFromPlane's baseaxis table (normal, s axis, t axis per row): floor, ceiling, west, east, south, north +local BASEAXIS = { + { 0, 0, 1 }, { 1, 0, 0 }, { 0, -1, 0 }, + { 0, 0, -1 }, { 1, 0, 0 }, { 0, -1, 0 }, + { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, -1 }, + { -1, 0, 0 }, { 0, 1, 0 }, { 0, 0, -1 }, + { 0, 1, 0 }, { 1, 0, 0 }, { 0, 0, -1 }, + { 0, -1, 0 }, { 1, 0, 0 }, { 0, 0, -1 }, +} + +local function snap(x: number): number + local r = floor(x + 0.5) + return if abs(x - r) < 1e-6 then r else x +end + +-- qbsp PlaneFromPoints: normal = (p1 - p2) x (p3 - p2), the brush lies behind it; nil when the points are colinear +function Brush.planeFromPoints(a: { number }, b: { number }, c: { number }): Plane? + local ux, uy, uz = a[1] - b[1], a[2] - b[2], a[3] - b[3] + local vx, vy, vz = c[1] - b[1], c[2] - b[2], c[3] - b[3] + local nx, ny, nz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + local l = sqrt(nx * nx + ny * ny + nz * nz) + if l < 1e-12 then + return nil + end + nx, ny, nz = nx / l, ny / l, nz / l + return { nx, ny, nz, b[1] * nx + b[2] * ny + b[3] * nz } +end + +-- the base axis row (0..5) of TextureAxisFromPlane: the first with the largest dot product (strictly greater) +function Brush.baseAxis(n: { number }): number + local best, axis = 0, 0 + for i = 0, 5 do + local a = BASEAXIS[i * 3 + 1] + local d = n[1] * a[1] + n[2] * a[2] + n[3] * a[3] + if d > best then + best, axis = d, i + end + end + return axis +end + +-- Quake standard texture vectors (texels): offsets, rotation (degrees), scales (0 = 1) +function Brush.quakeVecs(n: { number }, xoff: number, yoff: number, rot: number, xscale: number, yscale: number): { { number } } + local axis = Brush.baseAxis(n) + local s0, t0 = BASEAXIS[axis * 3 + 2], BASEAXIS[axis * 3 + 3] + local vecs = { { s0[1], s0[2], s0[3] }, { t0[1], t0[2], t0[3] } } + local sinv, cosv + if rot == 0 then + sinv, cosv = 0, 1 + elseif rot == 90 then + sinv, cosv = 1, 0 + elseif rot == 180 then + sinv, cosv = 0, -1 + elseif rot == 270 then + sinv, cosv = -1, 0 + else + local ang = rot / 180 * math.pi + sinv, cosv = sin(ang), cos(ang) + end + local sv = if vecs[1][1] ~= 0 then 1 elseif vecs[1][2] ~= 0 then 2 else 3 + local tv = if vecs[2][1] ~= 0 then 1 elseif vecs[2][2] ~= 0 then 2 else 3 + for i = 1, 2 do + local v = vecs[i] + local ns = cosv * v[sv] - sinv * v[tv] + local nt = sinv * v[sv] + cosv * v[tv] + v[sv], v[tv] = ns, nt + end + local sc = { if xscale == 0 then 1 else xscale, if yscale == 0 then 1 else yscale } + for i = 1, 2 do + local v = vecs[i] + v[1], v[2], v[3] = v[1] / sc[i], v[2] / sc[i], v[3] / sc[i] + end + vecs[1][4], vecs[2][4] = xoff, yoff + return vecs +end + +-- Valve 220: u / v = axis (x, y, z, offset); the rotation is already in the axes +function Brush.valveVecs(u: { number }, v: { number }, xscale: number, yscale: number): { { number } } + local su, sv = if xscale == 0 then 1 else xscale, if yscale == 0 then 1 else yscale + return { { u[1] / su, u[2] / su, u[3] / su, u[4] }, { v[1] / sv, v[2] / sv, v[3] / sv, v[4] } } +end + +-- q3map2 ComputeAxisBase: the texture plane axes of a brush-primitive face +function Brush.axisBase(normal: { number }): ({ number }, { number }) + local nx, ny, nz = normal[1], normal[2], normal[3] + nx = if abs(nx) < 1e-6 then 0 else nx + ny = if abs(ny) < 1e-6 then 0 else ny + nz = if abs(nz) < 1e-6 then 0 else nz + local rotY = -atan2(nz, sqrt(ny * ny + nx * nx)) + local rotZ = atan2(ny, nx) + return { -sin(rotZ), cos(rotZ), 0 }, { -sin(rotY) * cos(rotZ), -sin(rotY) * sin(rotZ), -cos(rotY) } +end + +-- brush primitives -> texel vectors for a w x h texture (ericw-tools SetTexinfo_BrushPrimitives) +function Brush.bpVecs(normal: { number }, m: { { number } }, w: number, h: number): { { number } } + local tx, ty = Brush.axisBase(normal) + local out = {} + for i, size in { w, h } do + local r = m[i] + out[i] = { size * (tx[1] * r[1] + ty[1] * r[2]), size * (tx[2] * r[1] + ty[2] * r[2]), size * (tx[3] * r[1] + ty[3] * r[2]), size * r[3] } + end + return out +end + +-- texel vectors -> brush primitives (the inverse of bpVecs for vectors lying in the face plane) +function Brush.vecsToBp(normal: { number }, vecs: { { number } }, w: number, h: number): { { number } } + local tx, ty = Brush.axisBase(normal) + local out = {} + for i, size in { w, h } do + local v = vecs[i] + out[i] = { + (v[1] * tx[1] + v[2] * tx[2] + v[3] * tx[3]) / size, + (v[1] * ty[1] + v[2] * ty[2] + v[3] * ty[3]) / size, + v[4] / size, + } + end + return out +end + +-- texture coordinates of a point on a face, in texture widths / heights (glTF uv: t grows down the image) +function Brush.uv(face: Face, x: number, y: number, z: number, w: number, h: number): (number, number) + local bp = face.bp + if bp then + local tx, ty = Brush.axisBase(face.plane) + local a = x * tx[1] + y * tx[2] + z * tx[3] + local b = x * ty[1] + y * ty[2] + z * ty[3] + return bp[1][1] * a + bp[1][2] * b + bp[1][3], bp[2][1] * a + bp[2][2] * b + bp[2][3] + end + local v = face.vecs + if v then + local s, t = v[1], v[2] + return (x * s[1] + y * s[2] + z * s[3] + s[4]) / w, (x * t[1] + y * t[2] + z * t[3] + t[4]) / h + end + return 0, 0 +end + +-- qbsp BaseWindingForPlane: a square of half size `size` on the plane, counter-clockwise seen from the front +function Brush.baseWinding(p: Plane, size: number): { number } + local nx, ny, nz, d = p[1], p[2], p[3], p[4] + local ax, ay, az = abs(nx), abs(ny), abs(nz) + local ux, uy, uz = 0, 0, 1 + if az >= ax and az >= ay then + ux, uy, uz = 1, 0, 0 + end + local dv = ux * nx + uy * ny + uz * nz + ux, uy, uz = ux - dv * nx, uy - dv * ny, uz - dv * nz + local l = sqrt(ux * ux + uy * uy + uz * uz) + ux, uy, uz = ux / l * size, uy / l * size, uz / l * size + -- right = up x n, so right x up = n: right -> up turns counter-clockwise about n + local rx, ry, rz = (uy * nz - uz * ny), (uz * nx - ux * nz), (ux * ny - uy * nx) + local ox, oy, oz = nx * d, ny * d, nz * d + return { + ox - rx - ux, oy - ry - uy, oz - rz - uz, + ox + rx - ux, oy + ry - uy, oz + rz - uz, + ox + rx + ux, oy + ry + uy, oz + rz + uz, + ox - rx + ux, oy - ry + uy, oz - rz + uz, + } +end + +-- splits a polygon by a plane: the parts in front and behind (nil when empty), and whether it lies on the plane +function Brush.split(pts: { number }, p: Plane, eps: number): ({ number }?, { number }?, boolean) + local n = #pts // 3 + local nx, ny, nz, d = p[1], p[2], p[3], p[4] + local dist = table.create(n, 0) :: { number } + local side = table.create(n, 0) :: { number } + local front, back = 0, 0 + for i = 0, n - 1 do + local v = pts[i * 3 + 1] * nx + pts[i * 3 + 2] * ny + pts[i * 3 + 3] * nz - d + dist[i + 1] = v + if v > eps then + side[i + 1] = 1 + front += 1 + elseif v < -eps then + side[i + 1] = -1 + back += 1 + end + end + if front == 0 and back == 0 then + return nil, nil, true + end + if front == 0 then + return nil, pts, false + end + if back == 0 then + return pts, nil, false + end + local f: { number }, b: { number } = {}, {} + for i = 0, n - 1 do + local j = (i + 1) % n + local x, y, z = pts[i * 3 + 1], pts[i * 3 + 2], pts[i * 3 + 3] + local si = side[i + 1] + if si >= 0 then + f[#f + 1], f[#f + 2], f[#f + 3] = x, y, z + end + if si <= 0 then + b[#b + 1], b[#b + 2], b[#b + 3] = x, y, z + end + local sj = side[j + 1] + if si ~= 0 and sj ~= 0 and si ~= sj then + local t = dist[i + 1] / (dist[i + 1] - dist[j + 1]) + local mx, my, mz = x + t * (pts[j * 3 + 1] - x), y + t * (pts[j * 3 + 2] - y), z + t * (pts[j * 3 + 3] - z) + -- exact on axis-aligned planes, as qbsp + if nx == 1 then + mx = d + elseif nx == -1 then + mx = -d + end + if ny == 1 then + my = d + elseif ny == -1 then + my = -d + end + if nz == 1 then + mz = d + elseif nz == -1 then + mz = -d + end + f[#f + 1], f[#f + 2], f[#f + 3] = mx, my, mz + b[#b + 1], b[#b + 2], b[#b + 3] = mx, my, mz + end + end + return (if #f >= 9 then f else nil), (if #b >= 9 then b else nil), false +end + +-- removes repeated and colinear corners; nil when fewer than 3 remain +local function clean(pts: { number }, eps: number): { number }? + local out: { number } = {} + local n = #pts // 3 + for i = 0, n - 1 do + local x, y, z = snap(pts[i * 3 + 1]), snap(pts[i * 3 + 2]), snap(pts[i * 3 + 3]) + local m = #out + if m < 3 or abs(out[m - 2] - x) > eps or abs(out[m - 1] - y) > eps or abs(out[m] - z) > eps then + out[m + 1], out[m + 2], out[m + 3] = x, y, z + end + end + while #out >= 6 and abs(out[1] - out[#out - 2]) <= eps and abs(out[2] - out[#out - 1]) <= eps and abs(out[3] - out[#out]) <= eps do + out[#out], out[#out - 1], out[#out - 2] = nil, nil, nil + end + -- colinear corners + local changed = true + while changed and #out >= 9 do + changed = false + local k = #out // 3 + for i = 0, k - 1 do + local a, b, c = ((i + k - 1) % k) * 3, i * 3, ((i + 1) % k) * 3 + local ux, uy, uz = out[b + 1] - out[a + 1], out[b + 2] - out[a + 2], out[b + 3] - out[a + 3] + local vx, vy, vz = out[c + 1] - out[b + 1], out[c + 2] - out[b + 2], out[c + 3] - out[b + 3] + local cx, cy, cz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + local lu, lv = sqrt(ux * ux + uy * uy + uz * uz), sqrt(vx * vx + vy * vy + vz * vz) + if lu * lv == 0 or sqrt(cx * cx + cy * cy + cz * cz) <= 1e-9 * lu * lv then + table.remove(out, b + 3) + table.remove(out, b + 2) + table.remove(out, b + 1) + changed = true + break + end + end + end + return if #out >= 9 then out else nil +end + +local function samePlane(a: Plane, b: Plane, eps: number): boolean + return abs(a[1] - b[1]) < 1e-5 and abs(a[2] - b[2]) < 1e-5 and abs(a[3] - b[3]) < 1e-5 and abs(a[4] - b[4]) < eps +end + +local function oppositePlane(a: Plane, b: Plane, eps: number): boolean + return abs(a[1] + b[1]) < 1e-5 and abs(a[2] + b[2]) < 1e-5 and abs(a[3] + b[3]) < 1e-5 and abs(a[4] + b[4]) < eps +end + +-- one polygon per plane of a convex brush (nil for planes clipped away or repeating an earlier plane) +function Brush.windings(planes: { Plane }, opts: Options?): { { number }? } + local eps = opts and opts.epsilon or 1e-3 + local size = opts and opts.size or 2 ^ 17 + local out: { { number }? } = {} + for i, p in planes do + local w: { number }? = Brush.baseWinding(p, size) + for j, q in planes do + if not w then + break + end + if j ~= i then + if samePlane(p, q, eps) then + if j < i then + w = nil + end + else + local _, back, on = Brush.split(w, q, eps) + w = if on then nil else back + end + end + end + out[i] = if w then clean(w, eps) else nil + end + return out +end + +local function bounds(polys: { Polygon }): { number } + local b = { math.huge, math.huge, math.huge, -math.huge, -math.huge, -math.huge } + for _, p in polys do + local pts = p.points + for k = 0, #pts // 3 - 1 do + for c = 1, 3 do + local v = pts[k * 3 + c] + b[c] = min(b[c], v) + b[c + 3] = max(b[c + 3], v) + end + end + end + return b +end + +-- the parts of pts (on plane `own` of brush a) outside brush b +local function outside(pts: { number }, own: Plane, a: number, b: number, planes: { Plane }, eps: number): { { number } } + local kept: { { number } } = {} + local inside: { number }? = pts + for _, q in planes do + if not inside then + break + end + if samePlane(own, q, eps) then + if a < b then + return { pts } + end + elseif not oppositePlane(own, q, eps) then + local front, back = Brush.split(inside, q, eps) + if front then + table.insert(kept, front) + end + inside = back + end + end + return kept +end + +local function faceKey(f: Face): string + local parts = { f.texture or "" } + for _, m in { f.vecs, f.bp } do + if m then + for _, row in m do + for _, v in row do + table.insert(parts, string.format("%.6g", v)) + end + end + end + end + return table.concat(parts, " ") +end + +local function convex(pts: { number }, n: { number }, eps: number): boolean + local k = #pts // 3 + for i = 0, k - 1 do + local a, b, c = ((i + k - 1) % k) * 3, i * 3, ((i + 1) % k) * 3 + local ux, uy, uz = pts[b + 1] - pts[a + 1], pts[b + 2] - pts[a + 2], pts[b + 3] - pts[a + 3] + local vx, vy, vz = pts[c + 1] - pts[b + 1], pts[c + 2] - pts[b + 2], pts[c + 3] - pts[b + 3] + local cx, cy, cz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + local lu, lv = sqrt(ux * ux + uy * uy + uz * uz), sqrt(vx * vx + vy * vy + vz * vz) + if (cx * n[1] + cy * n[2] + cz * n[3]) < -eps * max(lu, lv, 1) then + return false + end + end + return true +end + +-- qbsp TryMerge: two polygons sharing an edge (in opposite directions) -> their union, when convex +local function tryMerge(f1: { number }, f2: { number }, n: { number }, eps: number): { number }? + local n1, n2 = #f1 // 3, #f2 // 3 + for i = 0, n1 - 1 do + local i2 = (i + 1) % n1 + for j = 0, n2 - 1 do + local j2 = (j + 1) % n2 + local match = true + for c = 1, 3 do + if abs(f1[i * 3 + c] - f2[j2 * 3 + c]) > eps or abs(f1[i2 * 3 + c] - f2[j * 3 + c]) > eps then + match = false + break + end + end + if match then + local out: { number } = {} + for k = 0, n1 - 1 do + local s = ((i2 + k) % n1) * 3 + out[#out + 1], out[#out + 2], out[#out + 3] = f1[s + 1], f1[s + 2], f1[s + 3] + end + for k = 2, n2 - 1 do + local s = ((j + k) % n2) * 3 + out[#out + 1], out[#out + 2], out[#out + 3] = f2[s + 1], f2[s + 2], f2[s + 3] + end + local c = clean(out, eps) + if c and convex(c, n, eps) then + return c + end + return nil + end + end + end + return nil +end + +local function mergeAll(polys: { Polygon }, faces: { [number]: { Face } }, eps: number): { Polygon } + local groups: { [string]: { Polygon } } = {} + local order: { string } = {} + for _, p in polys do + local f = faces[p.brush][p.face] + local pl = f.plane + local key = string.format("%.5f %.5f %.5f %.3f|", pl[1], pl[2], pl[3], pl[4]) .. faceKey(f) + local g = groups[key] + if not g then + g = {} + groups[key] = g + table.insert(order, key) + end + table.insert(g, p) + end + local out: { Polygon } = {} + for _, key in order do + local g = groups[key] + local changed = true + while changed do + changed = false + for a = 1, #g do + for b = a + 1, #g do + local m = tryMerge(g[a].points, g[b].points, g[a].normal, eps) + if m then + g[a] = { brush = g[a].brush, face = g[a].face, points = m, normal = g[a].normal } + table.remove(g, b) + changed = true + break + end + end + if changed then + break + end + end + end + for _, p in g do + table.insert(out, p) + end + end + return out +end + +-- every brush's faces -> polygons (brushes[i] is a list of faces); nil, message past opts.maxPolygons +function Brush.polygons(brushes: { { Face } }, opts: Options?): ({ Polygon }?, string?) + local eps = opts and opts.epsilon or 1e-3 + local limit = opts and opts.maxPolygons or 2 ^ 20 + local per: { { Polygon } } = {} + local planesOf: { { Plane } } = {} + local count = 0 + for bi, faces in brushes do + local planes: { Plane } = {} + for fi, f in faces do + planes[fi] = f.plane + end + planesOf[bi] = planes + local list: { Polygon } = {} + local ws = Brush.windings(planes, opts) + for fi = 1, #faces do + local w = ws[fi] + if w then + table.insert(list, { brush = bi, face = fi, points = w, normal = { planes[fi][1], planes[fi][2], planes[fi][3] } }) + end + end + per[bi] = list + count += #list + if count > limit then + return nil, "limit: too many brush faces" + end + end + local all: { Polygon } = {} + if opts and opts.hull then + local boxes: { { number } } = {} + for bi = 1, #brushes do + boxes[bi] = bounds(per[bi]) + end + for bi = 1, #brushes do + for _, p in per[bi] do + local frags: { { number } } = { p.points } + local own = brushes[bi][p.face].plane + local pb = bounds({ p }) + for bj = 1, #brushes do + if #frags == 0 then + break + end + local ob = boxes[bj] + if bj ~= bi and #per[bj] > 0 and pb[1] <= ob[4] + eps and pb[4] >= ob[1] - eps and pb[2] <= ob[5] + eps + and pb[5] >= ob[2] - eps and pb[3] <= ob[6] + eps and pb[6] >= ob[3] - eps then + local nextFrags: { { number } } = {} + for _, fr in frags do + for _, kept in outside(fr, own, bi, bj, planesOf[bj], eps) do + table.insert(nextFrags, kept) + end + end + frags = nextFrags + if #frags > limit then + return nil, "limit: too many brush fragments" + end + end + end + for _, fr in frags do + local c = clean(fr, eps) + if c then + table.insert(all, { brush = p.brush, face = p.face, points = c, normal = p.normal }) + end + end + end + end + else + for bi = 1, #brushes do + for _, p in per[bi] do + table.insert(all, p) + end + end + end + if opts and opts.merge then + all = mergeAll(all, brushes, eps) + end + return all, nil +end + +-- polygon area (for checks against compilers) +function Brush.area(pts: { number }): number + local n = #pts // 3 + local ax, ay, az = 0, 0, 0 + for k = 1, n - 2 do + local ux, uy, uz = pts[k * 3 + 1] - pts[1], pts[k * 3 + 2] - pts[2], pts[k * 3 + 3] - pts[3] + local vx, vy, vz = pts[k * 3 + 4] - pts[1], pts[k * 3 + 5] - pts[2], pts[k * 3 + 6] - pts[3] + ax += uy * vz - uz * vy + ay += uz * vx - ux * vz + az += ux * vy - uy * vx + end + return sqrt(ax * ax + ay * ay + az * az) / 2 +end + +-- polygons -> one indexed triangle primitive per texture, in order of first use. size(name) gives a texture's +-- width, height (texel projections divide by them) +function Brush.primitives(polys: { Polygon }, brushes: { { Face } }, size: (name: string) -> (number, number)): { Built } + type Acc = { texture: string, pos: { number }, nrm: { number }, uv: { number }, idx: { number } } + local byTex: { [string]: Acc } = {} + local order: { Acc } = {} + local sizes: { [string]: { number } } = {} + for _, p in polys do + local f = brushes[p.brush][p.face] + local name = f.texture or "" + local acc = byTex[name] + if not acc then + acc = { texture = name, pos = {}, nrm = {}, uv = {}, idx = {} } + byTex[name] = acc + table.insert(order, acc) + end + local sz = sizes[name] + if not sz then + local w, h = size(name) + sz = { math.max(w, 1), math.max(h, 1) } + sizes[name] = sz + end + local a: Acc = acc + local pts = p.points + local n = #pts // 3 + local base = #a.pos // 3 + for k = 0, n - 1 do + local x, y, z = pts[k * 3 + 1], pts[k * 3 + 2], pts[k * 3 + 3] + local pp, nn, uu = a.pos, a.nrm, a.uv + pp[#pp + 1], pp[#pp + 2], pp[#pp + 3] = x, y, z + nn[#nn + 1], nn[#nn + 2], nn[#nn + 3] = p.normal[1], p.normal[2], p.normal[3] + local u, v = Brush.uv(f, x, y, z, sz[1], sz[2]) + uu[#uu + 1], uu[#uu + 2] = u, v + end + local ii = a.idx + for k = 1, n - 2 do + ii[#ii + 1], ii[#ii + 2], ii[#ii + 3] = base, base + k, base + k + 1 + end + end + local out: { Built } = {} + for _, a in order do + local nv, ni = #a.pos // 3, #a.idx + local pb, nb, ub, ib = buffer.create(nv * 12), buffer.create(nv * 12), buffer.create(nv * 8), buffer.create(ni * 4) + for k = 1, nv * 3 do + writef32(pb, (k - 1) * 4, a.pos[k]) + writef32(nb, (k - 1) * 4, a.nrm[k]) + end + for k = 1, nv * 2 do + writef32(ub, (k - 1) * 4, a.uv[k]) + end + for k = 1, ni do + writeu32(ib, (k - 1) * 4, a.idx[k]) + end + local S = Types.Scene + table.insert(out, { + texture = a.texture, + primitive = { + attributes = { POSITION = S.accessor(pb, "f32", 3, nv), NORMAL = S.accessor(nb, "f32", 3, nv), TEXCOORD_0 = S.accessor(ub, "f32", 2, nv) }, + indices = S.accessor(ib, "u32", 1, ni), + mode = "triangles" :: "triangles", + }, + }) + end + return out +end + +return Brush diff --git a/src/Rosetta/codecs/model/Patch.luau b/src/Rosetta/codecs/model/Patch.luau new file mode 100644 index 0000000..188dc00 --- /dev/null +++ b/src/Rosetta/codecs/model/Patch.luau @@ -0,0 +1,122 @@ +--!strict +--!native +--!optimize 2 +-- codecs/model/Patch: Quake III / Doom 3 Bezier patches (control grids) -> evaluated grids, triangles, normals. +-- A w x h grid (w, h odd, >= 3) is a mesh of 3 x 3 biquadratic sub-patches (Unofficial Quake 3 Map Specs; patchDef2 / +-- patchDef3), evaluated at fixed segments per sub-patch and axis (patchDef3's explicit subdivisions; Quake III's adaptive +-- subdivision is not reproduced). Shared edges are evaluated once. +local Patch = {} + +local sqrt = math.sqrt + +function Patch.valid(w: number, h: number, n: number): boolean + return w >= 3 and h >= 3 and w % 2 == 1 and h % 2 == 1 and w * h == n +end + +-- ctrl: w * h points of comps numbers, row-major (row j holds points j * w .. j * w + w - 1); returns the evaluated grid +-- (gw * gh points of comps numbers, row-major) and its size; nil when the grid is not w x h odd or a limit is passed +function Patch.grid(ctrl: { number }, w: number, h: number, comps: number, levelU: number, levelV: number, maxPoints: number?): ({ number }?, number, number) + local lu, lv = math.max(1, math.floor(levelU)), math.max(1, math.floor(levelV)) + if not Patch.valid(w, h, #ctrl // comps) or #ctrl ~= w * h * comps then + return nil, 0, 0 + end + local px, py = (w - 1) // 2, (h - 1) // 2 + local gw, gh = px * lu + 1, py * lv + 1 + if gw * gh > (maxPoints or 2 ^ 24) then + return nil, 0, 0 + end + local out = table.create(gw * gh * comps, 0) :: { number } + for gy = 0, gh - 1 do + local sy = math.min(gy // lv, py - 1) + local tv = (gy - sy * lv) / lv + local bv0, bv1, bv2 = (1 - tv) * (1 - tv), 2 * tv * (1 - tv), tv * tv + for gx = 0, gw - 1 do + local sx = math.min(gx // lu, px - 1) + local tu = (gx - sx * lu) / lu + local bu0, bu1, bu2 = (1 - tu) * (1 - tu), 2 * tu * (1 - tu), tu * tu + local o = (gy * gw + gx) * comps + for j = 0, 2 do + local bv = if j == 0 then bv0 elseif j == 1 then bv1 else bv2 + local row = ((sy * 2 + j) * w + sx * 2) * comps + for i = 0, 2 do + local wgt = bv * (if i == 0 then bu0 elseif i == 1 then bu1 else bu2) + local c = row + i * comps + for k = 1, comps do + out[o + k] += ctrl[c + k] * wgt + end + end + end + end + end + return out, gw, gh +end + +-- 0-based triangle indices over a gw x gh grid; Quake's control grids are clockwise-front, these are counter-clockwise +function Patch.triangles(gw: number, gh: number): { number } + local out = table.create(math.max(0, (gw - 1) * (gh - 1) * 6)) :: { number } + for gy = 0, gh - 2 do + for gx = 0, gw - 2 do + local a, b = gy * gw + gx, gy * gw + gx + 1 + local d, e = a + gw, b + gw + local n = #out + out[n + 1], out[n + 2], out[n + 3] = a, d, b + out[n + 4], out[n + 5], out[n + 6] = b, d, e + end + end + return out +end + +-- renormalizes the vec3 at component offset at (0-based) of every point +function Patch.normalize(pts: { number }, comps: number, at: number) + for o = 0, #pts - comps, comps do + local x, y, z = pts[o + at + 1], pts[o + at + 2], pts[o + at + 3] + local l = sqrt(x * x + y * y + z * z) + if l > 0 then + pts[o + at + 1], pts[o + at + 2], pts[o + at + 3] = x / l, y / l, z / l + end + end +end + +-- unit normals (3 per point) of the evaluated grid from the positions (components 1..3), facing the front of +-- Patch.triangles; points where the surface degenerates take a neighbour's normal +function Patch.normals(pts: { number }, comps: number, gw: number, gh: number): { number } + local out = table.create(gw * gh * 3, 0) :: { number } + local function at(x: number, y: number, k: number): number + return pts[(y * gw + x) * comps + k] + end + for gy = 0, gh - 1 do + local y0, y1 = math.max(gy - 1, 0), math.min(gy + 1, gh - 1) + for gx = 0, gw - 1 do + local x0, x1 = math.max(gx - 1, 0), math.min(gx + 1, gw - 1) + local ux, uy, uz = at(x1, gy, 1) - at(x0, gy, 1), at(x1, gy, 2) - at(x0, gy, 2), at(x1, gy, 3) - at(x0, gy, 3) + local vx, vy, vz = at(gx, y1, 1) - at(gx, y0, 1), at(gx, y1, 2) - at(gx, y0, 2), at(gx, y1, 3) - at(gx, y0, 3) + local nx, ny, nz = vy * uz - vz * uy, vz * ux - vx * uz, vx * uy - vy * ux + local l = sqrt(nx * nx + ny * ny + nz * nz) + local o = (gy * gw + gx) * 3 + if l > 1e-12 then + out[o + 1], out[o + 2], out[o + 3] = nx / l, ny / l, nz / l + end + end + end + for _ = 1, 2 do + for i = 0, gw * gh - 1 do + local o = i * 3 + if out[o + 1] == 0 and out[o + 2] == 0 and out[o + 3] == 0 then + local x, y = i % gw, i // gw + for _, d in { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 1 }, { -1, -1 }, { 1, -1 }, { -1, 1 } } do + local nx2, ny2 = x + d[1], y + d[2] + if nx2 >= 0 and nx2 < gw and ny2 >= 0 and ny2 < gh then + local q = (ny2 * gw + nx2) * 3 + if out[q + 1] ~= 0 or out[q + 2] ~= 0 or out[q + 3] ~= 0 then + out[o + 1], out[o + 2], out[o + 3] = out[q + 1], out[q + 2], out[q + 3] + break + end + end + end + end + end + end + return out +end + +return Patch diff --git a/src/Rosetta/model/bsp/Brush.luau b/src/Rosetta/model/bsp/Brush.luau index f745199..fd47cf7 100644 --- a/src/Rosetta/model/bsp/Brush.luau +++ b/src/Rosetta/model/bsp/Brush.luau @@ -4,6 +4,7 @@ -- size. local Types = require("@rosetta/Types") local Pixels = require("@rosetta/codecs/image/Pixels") +local Miptex = require("@rosetta/codecs/image/Miptex") local Brush = {} @@ -36,34 +37,18 @@ local function miptex(b: buffer, base: number, l: Lump, hl: boolean, pal: buffer if n < 0 or n > 65536 or 4 + n * 4 > l.size then return nil, "bad miptex lump" end - local gpal = if pal then Pixels.palette(pal, 0, 256) else nil + local gpal = if pal and not hl then Pixels.palette(pal, 0, 256) else nil for i = 0, n - 1 do local o = readi32(b, at + 4 + i * 4) - if o < 0 or o + 40 > l.size then + local hd = if o >= 0 and o + 40 <= l.size then Miptex.header(b, at + o, l.size - o) else nil + if not hd then out[i + 1] = { name = "missing" .. i, width = 64, height = 64, image = nil, texels = false } else - local m = at + o - local name = cstr(b, m, 16) - local w, h, off0 = readu32(b, m + 16), readu32(b, m + 20), readu32(b, m + 24) - local t: Tex = { name = name, width = math.max(w, 1), height = math.max(h, 1), image = nil, texels = false } - if off0 ~= 0 and w > 0 and h > 0 and w * h <= maxPixels then - local px = m + off0 - local need = w * h - local palAt = m + readu32(b, m + 36) + (w // 8) * (h // 8) + 2 - if o + off0 + need <= l.size then - local p = gpal - if hl then - p = if palAt - at + 768 <= l.size then Pixels.palette(b, palAt, 256) else nil - end - local img = Types.Image.new(w, h) - if p then - Pixels.indexed(b, px, w, 8, img.pixels, w, h, true, p) - else - for k = 0, need - 1 do - writeu32(img.pixels, k * 4, 0xFF000000 + buffer.readu8(b, px + k) * 0x10101) - end - end - img.meta.source = { format = "bsp", miptex = name, palette = p ~= nil } + local t: Tex = { name = hd.name, width = math.max(hd.width, 1), height = math.max(hd.height, 1), image = nil, texels = false } + if hd.offsets[1] ~= 0 and hd.width * hd.height <= maxPixels then + local img = Miptex.decode(b, at + o, l.size - o, { palette = gpal, goldsrc = hl, keyed = false, maxPixels = maxPixels }) + if img then + img.meta.source = { format = "bsp", miptex = hd.name, palette = img.meta.source and img.meta.source.palette } t.image = img end end diff --git a/src/Rosetta/model/bsp/Quake3.luau b/src/Rosetta/model/bsp/Quake3.luau index de8c1a4..0c149b8 100644 --- a/src/Rosetta/model/bsp/Quake3.luau +++ b/src/Rosetta/model/bsp/Quake3.luau @@ -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 diff --git a/src/Rosetta/model/bsp/init.luau b/src/Rosetta/model/bsp/init.luau index 02ae8d9..2249bde 100644 --- a/src/Rosetta/model/bsp/init.luau +++ b/src/Rosetta/model/bsp/init.luau @@ -17,7 +17,7 @@ local Bsp = { category = "model", extensions = { "bsp" }, mime = { "model/x-bsp" }, - deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels" }, + deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Pixels", "codecs/image/Miptex", "codecs/model/Patch" }, caps = { decode = true, encode = false, variants = { "quake", "halflife", "quake2", "quake3" }, lightmaps = "quake3" }, } diff --git a/tests/codecs/brush.luau b/tests/codecs/brush.luau new file mode 100644 index 0000000..174a3b1 --- /dev/null +++ b/tests/codecs/brush.luau @@ -0,0 +1,224 @@ +-- codecs/model/Brush tests: random overlapping brushes in Quake standard / Valve 220 / brush-primitive projections +-- against ericw-tools qbsp -nofill (face area per plane after CSG, texture coordinates at every compiled corner); +-- merging, the primitive builder, the fuzz pass. Fixtures: tools/fixtures/brush.py. +local T = require("@tests/T") +local Brush = require("@rosetta/codecs/model/Brush") +local Types = require("@rosetta/Types") +local Fx = require("@tests/gen/brush") + +local t = T.suite("brush") + +local function faceOf(rec: any): Brush.Face? + local p = rec.pts + local plane = Brush.planeFromPoints({ p[1], p[2], p[3] }, { p[4], p[5], p[6] }, { p[7], p[8], p[9] }) + if not plane then + return nil + end + local a = rec.args + local f: Brush.Face = { plane = plane, texture = rec.tex } + if rec.kind == "standard" then + f.vecs = Brush.quakeVecs(plane, a[1], a[2], a[3], a[4], a[5]) + elseif rec.kind == "valve" then + f.vecs = Brush.valveVecs({ a[1], a[2], a[3], a[4] }, { a[5], a[6], a[7], a[8] }, a[10], a[11]) + else + f.bp = { { a[1], a[2], a[3] }, { a[4], a[5], a[6] } } + end + return f +end + +local function key(n: { number }): string + local function r(x: number, k: number): number + return math.floor(x * k + 0.5) + end + return string.format("%d %d %d %d", r(n[1], 1000), r(n[2], 1000), r(n[3], 1000), r(n[4], 100)) +end + +local function inside(pts: { number }, n: { number }, x: number, y: number, z: number, tol: number): boolean + local k = #pts // 3 + for i = 0, k - 1 do + local j = (i + 1) % k + local ex, ey, ez = pts[j * 3 + 1] - pts[i * 3 + 1], pts[j * 3 + 2] - pts[i * 3 + 2], pts[j * 3 + 3] - pts[i * 3 + 3] + -- inward edge normal = n x e (counter-clockwise polygons) + local ix, iy, iz = n[2] * ez - n[3] * ey, n[3] * ex - n[1] * ez, n[1] * ey - n[2] * ex + local l = math.sqrt(ix * ix + iy * iy + iz * iz) + if l > 0 and ((x - pts[i * 3 + 1]) * ix + (y - pts[i * 3 + 2]) * iy + (z - pts[i * 3 + 3]) * iz) / l < -tol then + return false + end + end + return true +end + +for kind, m in Fx do + local brushes: { { Brush.Face } } = {} + for _, b in m.brushes do + local faces = {} + for _, rec in b do + table.insert(faces, assert(faceOf(rec))) + end + table.insert(brushes, faces) + end + local polys = assert(Brush.polygons(brushes, { hull = true })) + -- area per plane: ours after CSG = qbsp's faces (split by its BSP, merged, subdivided) + local ours, theirs = {}, {} + for _, p in polys do + local k = key(brushes[p.brush][p.face].plane) + ours[k] = (ours[k] or 0) + Brush.area(p.points) + end + for _, f in m.faces do + local k = key(f.plane) + theirs[k] = (theirs[k] or 0) + Brush.area(f.pts) + end + local bad = 0 + for k, a in theirs do + if math.abs((ours[k] or 0) - a) > 0.05 then + bad += 1 + t:note("%s: plane %s area %s, qbsp %s", kind, k, tostring(ours[k]), tostring(a)) + end + end + for k in ours do + if not theirs[k] then + bad += 1 + t:note("%s: plane %s only in ours", kind, k) + end + end + t:eq(bad, 0, kind .. ": face area per plane matches qbsp") + -- every compiled corner lies on one of our polygons with the same texture, and maps to the same texels + local miss, off, worst = 0, 0, 0 + local corners = 0 + for _, f in m.faces do + local pk = key(f.plane) + for c = 0, #f.pts // 3 - 1 do + local x, y, z = f.pts[c * 3 + 1], f.pts[c * 3 + 2], f.pts[c * 3 + 3] + corners += 1 + local s = f.vecs[1] * x + f.vecs[2] * y + f.vecs[3] * z + f.vecs[4] + local tt = f.vecs[5] * x + f.vecs[6] * y + f.vecs[7] * z + f.vecs[8] + local found = false + local best = math.huge + for _, p in polys do + local face = brushes[p.brush][p.face] + if face.texture == f.tex and key(face.plane) == pk and inside(p.points, p.normal, x, y, z, 0.02) then + found = true + local size = m.sizes[f.tex] + local u, v = Brush.uv(face, x, y, z, size[1], size[2]) + best = math.min(best, math.max(math.abs(u * size[1] - s), math.abs(v * size[2] - tt))) + end + end + if not found then + miss += 1 + local any = {} + for _, p in polys do + local face = brushes[p.brush][p.face] + if key(face.plane) == pk and inside(p.points, p.normal, x, y, z, 0.02) then + table.insert(any, face.texture .. "#" .. p.brush) + end + end + t:note("%s miss %s %s %s on %s tex %s: ours %s", kind, x, y, z, pk, f.tex, table.concat(any, ",")) + elseif best > 0.02 then + off += 1 + t:note("%s off %s %s %s on %s tex %s best %s vecs %s", kind, x, y, z, pk, f.tex, best, table.concat(f.vecs, " ")) + worst = math.max(worst, best) + end + end + end + t:eq(miss, 0, kind .. ": every qbsp corner is on one of our faces (" .. corners .. " corners)") + t:eq(off, 0, kind .. ": texture coordinates match qbsp's texinfo (worst " .. worst .. " texels)") + -- primitives: counter-clockwise about the face normals, one per texture + local built = Brush.primitives(polys, brushes, function(name: string) + local s = m.sizes[name] + return s[1], s[2] + end) + local seen, wrong = {}, 0 + for _, b in built do + t:check(not seen[b.texture], kind .. ": one primitive per texture " .. b.texture) + seen[b.texture] = true + local prim = b.primitive + local pos = Types.Scene.reader(prim.attributes.POSITION) :: any + local nrm = Types.Scene.reader(prim.attributes.NORMAL) :: any + local idx = prim.indices :: Types.Accessor + for k = 0, idx.count - 1, 3 do + local i0, i1, i2 = buffer.readu32(idx.data, k * 4), buffer.readu32(idx.data, k * 4 + 4), buffer.readu32(idx.data, k * 4 + 8) + local ux, uy, uz = pos(i1, 0) - pos(i0, 0), pos(i1, 1) - pos(i0, 1), pos(i1, 2) - pos(i0, 2) + local vx, vy, vz = pos(i2, 0) - pos(i0, 0), pos(i2, 1) - pos(i0, 1), pos(i2, 2) - pos(i0, 2) + local cx, cy, cz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + if cx * nrm(i0, 0) + cy * nrm(i0, 1) + cz * nrm(i0, 2) <= 0 then + wrong += 1 + end + end + end + t:eq(wrong, 0, kind .. ": triangles counter-clockwise about their normals") + -- merging keeps the area per plane + local merged = assert(Brush.polygons(brushes, { hull = true, merge = true })) + t:check(#merged <= #polys, kind .. ": merge does not add polygons") + local after = {} + for _, p in merged do + local k = key(brushes[p.brush][p.face].plane) + after[k] = (after[k] or 0) + Brush.area(p.points) + end + local drift = 0 + for k, a in ours do + drift = math.max(drift, math.abs((after[k] or 0) - a)) + end + t:check(drift < 1e-6, kind .. ": merged area per plane unchanged") +end + +-- two touching cubes merge into one box: 6 faces, no inner faces +do + local function cube(x0: number, x1: number): { Brush.Face } + local f = {} + for _, p in { { 1, 0, 0, x1 }, { -1, 0, 0, -x0 }, { 0, 1, 0, 64 }, { 0, -1, 0, 0 }, { 0, 0, 1, 64 }, { 0, 0, -1, 0 } } do + table.insert(f, { plane = p, texture = "t", vecs = Brush.quakeVecs(p, 0, 0, 0, 1, 1) }) + end + return f + end + local polys = assert(Brush.polygons({ cube(0, 64), cube(64, 128) }, { hull = true, merge = true })) + t:eq(#polys, 6, "touching cubes: 6 merged faces") + local area = 0 + for _, p in polys do + area += Brush.area(p.points) + end + t:eq(area, 2 * 128 * 64 * 2 + 2 * 64 * 64, "touching cubes: surface area") + local plain = assert(Brush.polygons({ cube(0, 64), cube(64, 128) })) + t:eq(#plain, 12, "without hull / merge: every face") + t:check(Brush.planeFromPoints({ 0, 0, 0 }, { 1, 1, 1 }, { 2, 2, 2 }) == nil, "colinear points: no plane") + -- Quake standard with exact rotations, against TextureAxisFromPlane by hand: a floor, rotated 90 degrees + local v = Brush.quakeVecs({ 0, 0, 1, 0 }, 8, 4, 90, 2, 1) + t:eq(v[1][1] .. " " .. v[1][2] .. " " .. v[1][4], "0 0.5 8", "rotated floor s axis") + t:eq(v[2][1] .. " " .. v[2][2] .. " " .. v[2][4], "1 0 4", "rotated floor t axis") + -- brush primitives <-> texel vectors + local n = { 0.6, 0, 0.8, 10 } + local bp = { { 0.01, 0.02, 0.5 }, { -0.03, 0.004, 0.25 } } + local back = Brush.vecsToBp(n, Brush.bpVecs(n, bp, 64, 32), 64, 32) + local err = 0 + for i = 1, 2 do + for j = 1, 3 do + err = math.max(err, math.abs(back[i][j] - bp[i][j])) + end + end + t:check(err < 1e-12, "bpVecs / vecsToBp round trip") +end + +-- fuzz: random planes never throw +do + local rand = T.rng(5) + local threw = 0 + for _ = 1, 200 do + local faces = {} + for _ = 1, 1 + rand(10) do + local p = { rand(2001) / 1000 - 1, rand(2001) / 1000 - 1, rand(2001) / 1000 - 1, rand(200) - 100 } + table.insert(faces, { plane = p, texture = "x", vecs = { { 1, 0, 0, 0 }, { 0, 1, 0, 0 } } }) + end + local ok = pcall(function() + local polys = Brush.polygons({ faces, faces }, { hull = true, merge = true }) + if polys then + Brush.primitives(polys, { faces, faces }, function() + return 64, 64 + end) + end + end) + if not ok then + threw += 1 + end + end + t:eq(threw, 0, "random planes never throw") +end +t:done() diff --git a/tests/codecs/patch.luau b/tests/codecs/patch.luau new file mode 100644 index 0000000..1989e66 --- /dev/null +++ b/tests/codecs/patch.luau @@ -0,0 +1,85 @@ +-- codecs/model/Patch tests: biquadratic Bezier evaluation against the closed form, shared sub-patch edges, triangle +-- winding and normals, explicit (patchDef3-style) subdivisions per axis, the fuzz pass. +local T = require("@tests/T") +local Patch = require("@rosetta/codecs/model/Patch") + +local t = T.suite("patch") + +-- a 5 x 3 grid (two sub-patches along u): x = column * 8, y = row * 8, z = a bump on the middle control row +local ctrl = {} +for j = 0, 2 do + for i = 0, 4 do + table.insert(ctrl, i * 8) + table.insert(ctrl, j * 8) + table.insert(ctrl, if j == 1 then 16 else 0) + end +end +local pts, gw, gh = Patch.grid(ctrl, 5, 3, 3, 4, 2) +t:check(pts ~= nil, "grid") +t:eq(gw, 9, "width: 2 sub-patches x 4 segments + 1") +t:eq(gh, 3, "height: 2 segments + 1") +local p = pts :: { number } +-- z(v) = 2 v (1 - v) * 16 on every column (the bump is constant along u); x is linear in u +local worst = 0 +for gy = 0, gh - 1 do + local v = gy / 2 + for gx = 0, gw - 1 do + local o = (gy * gw + gx) * 3 + worst = math.max(worst, math.abs(p[o + 1] - gx * 4), math.abs(p[o + 2] - v * 16), math.abs(p[o + 3] - 32 * v * (1 - v))) + end +end +t:check(worst < 1e-12, "closed form (worst " .. worst .. ")") +-- corners interpolate the control points +t:eq(p[1] .. " " .. p[2] .. " " .. p[3], "0 0 0", "first corner") +local last = (gw * gh - 1) * 3 +t:eq(p[last + 1] .. " " .. p[last + 2] .. " " .. p[last + 3], "32 16 0", "last corner") + +local tris = Patch.triangles(gw, gh) +t:eq(#tris, (gw - 1) * (gh - 1) * 6, "two triangles per cell") +local nrm = Patch.normals(p, 3, gw, gh) +local bad = 0 +for k = 1, #tris, 3 do + local a, b, c = tris[k] * 3, tris[k + 1] * 3, tris[k + 2] * 3 + local ux, uy, uz = p[b + 1] - p[a + 1], p[b + 2] - p[a + 2], p[b + 3] - p[a + 3] + local vx, vy, vz = p[c + 1] - p[a + 1], p[c + 2] - p[a + 2], p[c + 3] - p[a + 3] + local cx, cy, cz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + if cx * nrm[a + 1] + cy * nrm[a + 2] + cz * nrm[a + 3] <= 0 then + bad += 1 + end +end +t:eq(bad, 0, "normals face the front of the triangles") + +-- extra components (texture coordinates) interpolate too; normalize renormalizes a vec3 +local flat = {} +for j = 0, 2 do + for i = 0, 2 do + for _, v in { i, j, 0, i / 2, j / 2, 0, 0, 2 } do + table.insert(flat, v) + end + end +end +local q, qw, qh = Patch.grid(flat, 3, 3, 8, 3, 5) +t:eq(qw * qh, 4 * 6, "explicit subdivisions per axis") +Patch.normalize(q :: { number }, 8, 5) +t:eq((q :: { number })[8], 1, "renormalized normal") +t:eq((q :: { number })[(qw * qh - 1) * 8 + 4], 1, "texture coordinate at the far corner") + +t:check(Patch.grid({ 1, 2, 3 }, 2, 2, 3, 4, 4) == nil, "even grid: nil") +t:check(Patch.grid(ctrl, 5, 3, 3, 1000, 1000, 1000) == nil, "point limit: nil") + +t:fuzz("grid", function(b: buffer) + local n = buffer.len(b) + local w = 1 + 2 * (if n > 0 then buffer.readu8(b, 0) % 4 else 1) + local h = 1 + 2 * (if n > 1 then buffer.readu8(b, 1) % 4 else 1) + local c = {} + for k = 0, n - 1 do + table.insert(c, buffer.readu8(b, k) - 128) + end + local g, gw2, gh2 = Patch.grid(c, w, h, 3, 1 + n % 5, 1 + n % 3) + if g then + Patch.normals(g, 3, gw2, gh2) + Patch.triangles(gw2, gh2) + end + return g +end, { buffer.create(27), buffer.create(45), buffer.create(75) }) +t:done() diff --git a/tools/fixtures/_qbsp.py b/tools/fixtures/_qbsp.py new file mode 100644 index 0000000..074439a --- /dev/null +++ b/tools/fixtures/_qbsp.py @@ -0,0 +1,153 @@ +# Shared helpers for the Quake map fixtures (brush.py, map.py, bsp.py, wad2.py): WAD2 / WAD3 writing, running +# ericw-tools (qbsp, light, vis from nixpkgs) on a .map, and a reader of the Quake 1 family BSP files they write +# (BSP 29, BSP2, 2PSB: layouts from bspfile.h of the Quake source release and ericw-tools; no code taken). +# wad(lumps, magic) -> bytes: lumps = [(name, type, data)] +# miptex(name, w, h, rng, palette=None) -> bytes (four mip levels of random indices; WAD3 / BSP 30 add the palette) +# compile(ctx, text, files, qbsp_args, light_args=None, vis=False) -> { bsp, obj?, log } +# read_bsp(data) -> dict of the parsed lumps +import os, shutil, struct, subprocess, tempfile + +Q1_LUMPS = ["entities", "planes", "miptex", "vertices", "visibility", "nodes", "texinfo", "faces", "lighting", + "clipnodes", "leaves", "marksurfaces", "edges", "surfedges", "models"] + + +def wad(lumps, magic=b"WAD2"): + body = b"" + dirs = [] + for name, typ, data in lumps: + dirs.append(struct.pack("> m, h >> m + px = pixels[m] if pixels else bytes(rng.randrange(256) for _ in range(lw * lh)) + offs.append(o) + levels.append(px) + o += lw * lh + out += struct.pack("<4I", *offs) + b"".join(levels) + if palette is not None: + out += struct.pack("= 4: + n = struct.unpack_from("= 0 else e[1]]) + return pts + + +def face_plane(b, f): + nx, ny, nz, d, _ = b["planes"][f["plane"]] + if f["side"]: + return (-nx, -ny, -nz, -d) + return (nx, ny, nz, d) diff --git a/tools/fixtures/brush.py b/tools/fixtures/brush.py new file mode 100644 index 0000000..cdbfae9 --- /dev/null +++ b/tools/fixtures/brush.py @@ -0,0 +1,148 @@ +# codecs/model/Brush fixtures (tools/fixtures.py): random convex brushes (boxes on a 16-unit grid, some with corners cut +# by planes through three integer points; overlapping, touching and coplanar ones) written as Quake standard, Valve 220 +# and brush-primitive .map files, compiled with ericw-tools' qbsp -nofill (no outside fill: every CSG face survives) +# against a WAD2 of textures with their sizes. Reference: qbsp's faces (plane, corners, texinfo vectors and texture). +# tests/gen/brush.luau { [format] = { brushes = { { { pts = { 9 numbers }, tex, kind, args } } }, +# sizes = { [tex] = { w, h } }, faces = { { plane = { 4 }, pts = { 3n }, tex, vecs = { 8 } } } } } +import importlib.util, os + +INPUTS = ["tools/fixtures/_qbsp.py"] + +TEXTURES = [("brick", 64, 32), ("metal", 32, 128), ("wood", 128, 64), ("stone", 16, 16)] + + +def helper(ctx): + spec = importlib.util.spec_from_file_location("_qbsp", os.path.join(ctx.root, "tools", "fixtures", "_qbsp.py")) + m = importlib.util.module_from_spec(spec) + spec.loader.exec_module(m) + return m + + +def sub(a, b): + return (a[0] - b[0], a[1] - b[1], a[2] - b[2]) + + +def cross(u, v): + return (u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2], u[0] * v[1] - u[1] * v[0]) + + +def dot(u, v): + return u[0] * v[0] + u[1] * v[1] + u[2] * v[2] + + +def oriented(p1, p2, p3, center): + # qbsp: normal = (p1 - p2) x (p3 - p2) points out of the brush + n = cross(sub(p1, p2), sub(p3, p2)) + if dot(n, sub(center, p2)) > 0: + return (p3, p2, p1) + return (p1, p2, p3) + + +def box_faces(lo, hi): + (x0, y0, z0), (x1, y1, z1) = lo, hi + return [ + ((x0, y0, z0), (x0, y0 + 1, z0), (x0, y0, z0 + 1)), + ((x1, y1, z1), (x1, y1, z1 + 1), (x1, y1 + 1, z1)), + ((x0, y0, z0), (x0, y0, z0 + 1), (x0 + 1, y0, z0)), + ((x1, y1, z1), (x1 + 1, y1, z1), (x1, y1, z1 + 1)), + ((x0, y0, z0), (x0 + 1, y0, z0), (x0, y0 + 1, z0)), + ((x1, y1, z1), (x1, y1 + 1, z1), (x1 + 1, y1, z1)), + ] + + +def brushes(rng): + out = [] + for i in range(14): + lo = tuple(rng.randrange(-8, 6) * 16 for _ in range(3)) + hi = tuple(lo[k] + rng.randrange(2, 7) * 16 for k in range(3)) + faces = box_faces(lo, hi) + center = tuple((lo[k] + hi[k]) / 2 for k in range(3)) + for _ in range(rng.randrange(0, 3)): + corner = tuple(rng.choice((lo[k], hi[k])) for k in range(3)) + pts = [] + for k in range(3): + p = list(corner) + size = hi[k] - lo[k] + step = rng.randrange(4, size // 2 + 1) + p[k] += step if corner[k] == lo[k] else -step + pts.append(tuple(p)) + faces.append(oriented(pts[0], pts[1], pts[2], center)) + out.append(faces) + return out + + +def num(x): + s = ("%.6f" % x).rstrip("0").rstrip(".") + return "0" if s in ("-0", "") else s + + +def projection(rng, kind): + if kind == "standard": + return [rng.randrange(-64, 65), rng.randrange(-64, 65), rng.choice([0, 90, 180, 270, 15, 30, 45, 33.5]), + rng.choice([1, 0.5, 2, -1, 0.25, 1.5]), rng.choice([1, 0.5, 2, -1, 0.75])] + if kind == "valve": + u = [round(rng.uniform(-1, 1), 4) for _ in range(3)] + v = [round(rng.uniform(-1, 1), 4) for _ in range(3)] + return u + [rng.randrange(-32, 33)] + v + [rng.randrange(-32, 33), 0, rng.choice([1, 0.5, 2, -1]), rng.choice([1, 0.25, 2])] + while True: # qbsp replaces a singular matrix by the default projection + m = [rng.randrange(-8, 9) / 256, rng.randrange(-8, 9) / 256, rng.randrange(-16, 17) / 16, + rng.randrange(-8, 9) / 256, rng.randrange(-8, 9) / 256, rng.randrange(-16, 17) / 16] + if m[0] * m[4] - m[1] * m[3] != 0: + return m + + +def face_line(kind, pts, tex, a): + p = " ".join("( %s )" % " ".join(num(c) for c in q) for q in pts) + if kind == "standard": + return "%s %s %s" % (p, tex, " ".join(num(x) for x in a)) + if kind == "valve": + return "%s %s [ %s ] [ %s ] %s" % (p, tex, " ".join(num(x) for x in a[0:4]), " ".join(num(x) for x in a[4:8]), + " ".join(num(x) for x in a[8:11])) + return "%s ( ( %s ) ( %s ) ) %s 0 0 0" % (p, " ".join(num(x) for x in a[0:3]), " ".join(num(x) for x in a[3:6]), tex) + + +def write_map(kind, bl, rng): + lines = ["// Game: Quake", "{", '"classname" "worldspawn"', '"wad" "tex.wad"'] + if kind == "valve": + lines.append('"mapversion" "220"') + recs = [] + for faces in bl: + lines.append("{") + if kind == "bp": + lines.append("brushDef") + lines.append("{") + rec = [] + for pts in faces: + tex = rng.choice(TEXTURES)[0] + a = projection(rng, kind) + lines.append(face_line(kind, pts, tex, a)) + rec.append({"pts": [float(c) for q in pts for c in q], "tex": tex, "kind": kind, "args": [float(x) for x in a]}) + if kind == "bp": + lines.append("}") + lines.append("}") + recs.append(rec) + lines += ["}", "{", '"classname" "info_player_start"', '"origin" "0 0 0"', "}", ""] + return "\n".join(lines), recs + + +def generate(ctx): + H = helper(ctx) + rng = ctx.rng(777) + lumps = [(n, 0x44, H.miptex(n, w, h, rng)) for n, w, h in TEXTURES] + w2 = H.wad(lumps) + out = {} + for kind in ("standard", "valve", "bp"): + bl = brushes(rng) + text, recs = write_map(kind, bl, rng) + res = H.compile(ctx, text, {"tex.wad": w2}, ["-nofill", "-noclip", "-nopercent"]) + b = H.read_bsp(res["bsp"]) + world = b["models"][0] + first, count = world[14], world[15] + faces = [] + for f in b["faces"][first:first + count]: + ti = b["texinfo"][f["texinfo"]] + tex = b["textures"][ti[8]][0] + faces.append({"plane": list(H.face_plane(b, f)), "pts": [c for p in H.face_points(b, f) for c in p], + "tex": tex, "vecs": list(ti[0:8])}) + out[kind] = {"brushes": recs, "sizes": {n: [w, h] for n, w, h in TEXTURES}, "faces": faces, "map": text} + ctx.emit("brush", out)