diff --git a/README.md b/README.md index 7970e63..e1e8f1e 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ print(F.detect(webp), #F.formats()) -- "webp", the format list ## Formats -178 formats. Generated from the format contracts by `tools/gen_registry.py`; [docs/FORMATS.md](docs/FORMATS.md) +179 formats. Generated from the format contracts by `tools/gen_registry.py`; [docs/FORMATS.md](docs/FORMATS.md) adds each format's capabilities. | Category | Format | Extensions | Read | Write | @@ -116,6 +116,7 @@ adds each format's capabilities. | 3D models | iqm | .iqm | yes | yes | | 3D models | ldraw | .ldr .mpd .dat | yes | - | | 3D models | lwo | .lwo .lxo | yes | - | +| 3D models | map | .map | yes | yes | | 3D models | mca | .mca .mcr | yes | - | | 3D models | md2 | .md2 | yes | - | | 3D models | md3 | .md3 | yes | - | @@ -241,8 +242,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 | DoomMap, 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, DoomMap, Draco, Mat4, MeshFlatten, Minecraft, Patch, Polygon, Rbx, Rig, Sampler, Vrml | | text | Json, Lexer, 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 7cfc87a..6dc7979 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") @@ -1688,6 +1688,18 @@ local list: { Entry } = { return __include("model/lwo") end, }, + { + name = "map", + category = "model", + path = "model/map", + extensions = { "map" }, + mime = { "text/x-quake-map" }, + deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Miptex", "codecs/model/Brush", "codecs/model/Patch" }, + caps = { decode = true, encode = true, variants = { "quake", "valve220", "quake2", "quake3" }, patches = true }, + load = function() + return __include("model/map") + end, + }, { name = "mca", category = "model", @@ -69523,12 +69535,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 @@ -69785,6 +70014,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() @@ -76351,6 +76635,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/DoomMap"] = function() -- codecs/model/DoomMap: Doom / Heretic / Hexen binary map lumps (Hexen when BEHAVIOR is present) and UDMF TEXTMAP to @@ -82711,6 +83635,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. @@ -145183,7 +146231,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" }, } @@ -145315,6 +146363,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 = {} @@ -145347,34 +146396,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 @@ -145589,8 +146622,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 = {} @@ -145670,52 +146705,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 @@ -156446,6 +157452,1097 @@ end return Parse end +__FILES["model/map"] = function() + +-- model/map: editor .map files of Quake, Half-Life (Valve 220), Quake II (surface / content flags) and Quake III +-- (brushDef brush primitives, patchDef2; patchDef3 meshes), read and write. Grammar of the qbsp / q3map2 parsers (no +-- code taken). Brushes become polygons through codecs/model/Brush (optionally CSG'd and merged), patches through +-- codecs/model/Patch; a mesh per entity with brushes; entities as nodes with their keys in extras. Texture sizes from +-- opts.textureSizes, the worldspawn's WADs, .wal files or images through resolve; else 64 x 64. Not supported: Doom 3 +-- brushDef3, Build engine maps (binary: model/buildmap), compiling (no BSP, vis or light). + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Input = __include("core/Input") +local Types = __include("Types") +local Miptex = __include("codecs/image/Miptex") +local Brush = __include("codecs/model/Brush") +local Parse = __include("model/map/Parse") +local Write = __include("model/map/Write") +local Build = __include("model/map/Build") + +-- ------------------------------------------------------------------------------------------------ contract +local Map = { + name = "map", + category = "model", + extensions = { "map" }, + mime = { "text/x-quake-map" }, + deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Miptex", "codecs/model/Brush", "codecs/model/Patch" }, + caps = { decode = true, encode = true, variants = { "quake", "valve220", "quake2", "quake3" }, patches = true }, +} + +-- ------------------------------------------------------------------------------------------------ types +type DecodeOptions = { + hull: boolean?, -- drop faces inside / touching other brushes of the same entity, default false + merge: boolean?, -- merge coplanar faces with the same texture projection, default false + epsilon: number?, -- default 1e-3 + patchLevel: number?, -- patchDef2 segments per sub-patch, default 4 + skip: { string }?, -- texture names left out of the meshes ("clip", "skip", "common/caulk", ...) + textureSizes: { [string]: { number } }?, -- name -> { width, height } + resolve: ((uri: string) -> (buffer | string)?)?, + files: { [string]: buffer | string }?, + decodeImage: ((buf: buffer) -> (Types.Image?, Err.Err?))?, -- Quake III: texture image sizes + maxBrushes: number?, -- default 2^20 + maxPolygons: number?, -- default 2^20 +} +type EncodeOptions = { + variant: string?, -- "valve220" converts Quake standard faces to Valve 220 axes; default: as stored +} + +-- ------------------------------------------------------------------------------------------------ sniff +function Map.sniff(r: Bytes.Reader): number + local head = r:peek(math.min(r:remaining(), 4096)) + if #head < 2 or string.find(head, "[%z\1-\8\14-\31]") then + return 0 + end + if string.sub(head, 1, 3) == "\239\187\191" then + head = string.sub(head, 4) + end + local s = head + local game = false + while true do + local c = string.match(s, "^%s*//[^\n]*\n?()") + if not c then + break + end + if string.match(s, "^%s*//%s*Game:") then + game = true + end + s = string.sub(s, c :: number) + end + local body = string.match(s, '^%s*{%s*"[^"\n]*"%s*"') or string.match(s, "^%s*{%s*{%s*[%(bp]") + if not body then + return if game and string.match(s, "^%s*{") then 0.6 else 0 + end + return if game or string.find(head, '"classname"', 1, true) then 0.9 else 0.6 +end + +-- ------------------------------------------------------------------------------------------------ decode +local function variantOf(m: Parse.Map): string + local game = string.lower(m.game or "") + local fmt = string.lower(m.mapFormat or "") + local q2, valve, q3 = false, false, false + for _, e in m.entities do + if e.keys.mapversion == "220" then + valve = true + end + for _, b in e.brushes do + if b.type ~= "brush" then + q3 = true + end + for _, f in b.faces or {} do + if f.u then + valve = true + elseif f.flags and #f.flags >= 3 then + q2 = true + end + end + end + end + if q3 or string.find(game, "quake 3") or string.find(game, "quake iii") or fmt == "quake3" or fmt == "quake3 (valve)" then + return "quake3" + end + if string.find(game, "quake 2") or string.find(game, "quake ii") or fmt == "quake2" or fmt == "quake2 (valve)" then + return "quake2" + end + if valve or fmt == "valve" then + return "valve220" + end + return if q2 then "quake2" else "quake" +end + +local function sizer(m: Parse.Map, variant: string, opts: DecodeOptions?): (name: string) -> (number, number, boolean) + local cache: { [string]: { number } } = {} + local wads: { { buf: buffer, lumps: { Miptex.Lump } } }? = nil + local function loadWads(): { { buf: buffer, lumps: { Miptex.Lump } } } + local list = {} + local ws = m.entities[1] and m.entities[1].keys + local spec = ws and (ws.wad or ws._wad) or "" + for path in string.gmatch(spec, "[^;]+") do + local p = string.gsub(path, "\\", "/") + local b = Input.sibling(opts, p) or Input.sibling(opts, string.match(p, "([^/]+)$") or p) + if b then + local lumps = Miptex.wad(b, 0, buffer.len(b)) + if lumps then + table.insert(list, { buf = b, lumps = lumps }) + end + end + end + return list + end + return function(name: string): (number, number, boolean) + local c = cache[name] + if c then + return c[1], c[2], c[3] == 1 + end + local w: number, h: number = 0, 0 + local given = opts and opts.textureSizes and opts.textureSizes[name] + if type(given) == "table" and type(given[1]) == "number" and type(given[2]) == "number" then + w, h = given[1] :: number, given[2] :: number + elseif variant == "quake" or variant == "valve220" then + wads = wads or loadWads() + for i = #(wads :: any), 1, -1 do + local wd = (wads :: any)[i] + local l = Miptex.find(wd.lumps, name) + if l then + local hd = Miptex.header(wd.buf, l.offset, l.disksize) + if hd then + w, h = hd.width, hd.height + break + end + end + end + elseif variant == "quake2" then + local wal = Input.sibling(opts, "textures/" .. name .. ".wal") + if wal and buffer.len(wal) >= 40 then + w, h = buffer.readu32(wal, 32), buffer.readu32(wal, 36) + end + elseif opts and opts.decodeImage then + for _, ext in { ".tga", ".jpg", ".png" } do + local b = Input.sibling(opts, "textures/" .. name .. ext) + if b then + local ok, img = pcall(opts.decodeImage :: any, b) + if ok and img then + w, h = img.width, img.height + break + end + end + end + end + local fw: number, fh: number = w :: number, h :: number + local known = fw > 0 and fh > 0 + if not known then + fw, fh = 64, 64 + end + cache[name] = { fw, fh, if known then 1 else 0 } + return fw, fh, known + end +end + +function Map.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?) + local text = buffer.readstring(r.buf, r.base, r.limit - r.base) + local m, msg, at = Parse.parse(text, opts and opts.maxBrushes) + if not m then + return nil, Err.from(msg, at) + end + if #m.entities == 0 then + return nil, Err.new(Err.CORRUPT, "no entities", 0) + end + local variant = variantOf(m) + local scene, err = Build.scene(m, { + variant = variant, + size = sizer(m, variant, opts), + hull = opts and opts.hull, + merge = opts and opts.merge, + epsilon = opts and opts.epsilon, + patchLevel = opts and opts.patchLevel, + skip = opts and opts.skip, + maxPolygons = opts and opts.maxPolygons, + }) + if not scene then + return nil, Err.from(err) + end + local counts = scene.meta.counts + scene.meta.counts = nil + scene.meta.source = { format = "map", variant = variant, game = m.game, mapFormat = m.mapFormat, entities = #m.entities, brushes = counts.brushes, patches = counts.patches } + return scene, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +local function toValve(f: Parse.Face): Parse.Face + if f.u or f.matrix then + return f + end + local bf = Build.face(f) + if not bf or not bf.vecs then + return f + end + local v = bf.vecs + local out = table.clone(f) + out.offset = nil + out.u, out.v = { v[1][1], v[1][2], v[1][3], v[1][4] }, { v[2][1], v[2][2], v[2][3], v[2][4] } + out.rotation, out.scale = 0, { 1, 1 } + return out +end + +local function fmtNum(x: number): string + return Write.num(x) +end + +function Map.encode(scene: Types.Scene, opts: EncodeOptions?): (buffer?, Err.Err?) + if type(scene) ~= "table" or type(scene.nodes) ~= "table" then + return nil, Err.new(Err.ARG, "expected a Scene") + end + local valve = opts and opts.variant == "valve220" + local ents: { any } = {} + for _, node in scene.nodes do + local ex: any = node.extras + if type(ex) == "table" and type(ex.keys) == "table" then + local keys = ex.keys + local brushes: { Parse.Brush } = if type(ex.brushes) == "table" then ex.brushes else {} + if node.translation and keys.origin and #brushes == 0 then + local t = node.translation + keys = Types.object(table.clone(keys), Types.keys(keys)) + keys.origin = fmtNum(t[1]) .. " " .. fmtNum(t[2]) .. " " .. fmtNum(t[3]) + end + if valve then + local conv: { Parse.Brush } = {} + for _, b in brushes do + if b.faces then + local nb = table.clone(b) + local faces = {} + for i, f in b.faces do + faces[i] = toValve(f) + end + nb.faces = faces + table.insert(conv, nb) + else + table.insert(conv, b) + end + end + brushes = conv + if #ents == 0 and keys.mapversion ~= "220" then + keys = Types.object(table.clone(keys), Types.keys(keys)) + Types.set(keys, "mapversion", "220") + end + end + table.insert(ents, { keys = keys, brushes = brushes }) + end + end + if #ents == 0 then + return nil, Err.new(Err.ARG, "no map entities (nodes with extras.keys, as model/map loads them)") + end + local src: any = scene.meta and scene.meta.source + local fromMap = type(src) == "table" and src.format == "map" + local text, err = Write.text({ + entities = ents :: { Parse.Entity }, + game = if fromMap then src.game else nil, + mapFormat = if valve then "Valve" elseif fromMap then src.mapFormat else nil, + comments = {}, + }) + if not text then + return nil, Err.new(Err.ARG, err or "bad entity") + end + return buffer.fromstring(text), nil +end + +-- ------------------------------------------------------------------------------------------------ extras +-- the entities as parsed: { entities = { { keys, brushes } }, game, mapFormat } +function Map.parse(src: buffer | string): (Parse.Map?, Err.Err?) + local text = if type(src) == "buffer" then buffer.tostring(src) elseif type(src) == "string" then src else nil + if not text then + return nil, Err.new(Err.ARG, "expected a buffer or a string") + end + local m, msg, at = Parse.parse(text) + if not m then + return nil, Err.from(msg, at) + end + return m, nil +end + +function Map.write(m: Parse.Map): (string?, Err.Err?) + if type(m) ~= "table" or type(m.entities) ~= "table" then + return nil, Err.new(Err.ARG, "expected { entities = ... }") + end + local text, err = Write.text(m) + if not text then + return nil, Err.new(Err.ARG, err or "bad entity") + end + return text, nil +end + +-- a parsed face -> its Brush face (plane and projection): Brush.uv / Brush.polygons take it +function Map.face(f: Parse.Face): Brush.Face? + return Build.face(f) +end + +return Map +end +__FILES["model/map/Build"] = function() + +-- model/map/Build: parsed entities -> Scene: brushes through codecs/model/Brush, patches through codecs/model/Patch, +-- a mesh per entity with brushes, a primitive per texture, entities as nodes (keys in extras), z up, map units. +local Types = __include("Types") +local Brush = __include("codecs/model/Brush") +local Patch = __include("codecs/model/Patch") +local Parse = __include("model/map/Parse") + +local Build = {} + +local Scene = Types.Scene +local writef32, writeu32 = buffer.writef32, buffer.writeu32 + +type Options = { + variant: string, -- "quake" | "valve220" | "quake2" | "quake3" + size: (name: string) -> (number, number, boolean), -- width, height, known + hull: boolean?, + merge: boolean?, + epsilon: number?, + patchLevel: number?, + skip: { string }?, + maxPolygons: number?, +} + +function Build.face(f: Parse.Face): Brush.Face? + local p = f.points + 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 out: Brush.Face = { plane = plane, texture = f.texture } + if f.matrix then + out.bp = f.matrix + elseif f.u and f.v then + local sc = f.scale or { 1, 1 } + out.vecs = Brush.valveVecs(f.u, f.v, sc[1], sc[2]) + else + local o, sc = f.offset or { 0, 0 }, f.scale or { 1, 1 } + out.vecs = Brush.quakeVecs(plane, o[1], o[2], f.rotation or 0, sc[1], sc[2]) + end + return out +end + +type Acc = { pos: { number }, nrm: { number }, uv: { number }, idx: { number } } + +local function patchPrim(b: Parse.Brush, level: number, acc: Acc): boolean + local size, pts = b.size :: { number }, b.points :: { number } + local w: number, h: number = size[1] :: number, size[2] :: number + if not Patch.valid(w, h, #pts // 5) then + return false + end + -- file order is column by column (q3map2 ParsePatch: verts[i * width + j] for column j, point i) + local ctrl = table.create(w * h * 5, 0) :: { number } + for j = 0, w - 1 do + for i = 0, h - 1 do + table.move(pts, (j * h + i) * 5 + 1, (j * h + i) * 5 + 5, (i * w + j) * 5 + 1, ctrl) + end + end + local params: { number } = b.params or {} + local explicit = b.type == "patchDef3" + local lu: number = if explicit then math.max(1, params[1] or 1) else level + local lv: number = if explicit then math.max(1, params[2] or 1) else level + local g, gw, gh = Patch.grid(ctrl, w, h, 5, lu, lv) + if not g then + return false + end + local nrm = Patch.normals(g, 5, gw, gh) + local base = #acc.pos // 3 + for k = 0, gw * gh - 1 do + local o = k * 5 + table.insert(acc.pos, g[o + 1]) + table.insert(acc.pos, g[o + 2]) + table.insert(acc.pos, g[o + 3]) + table.insert(acc.uv, g[o + 4]) + table.insert(acc.uv, g[o + 5]) + table.insert(acc.nrm, nrm[k * 3 + 1]) + table.insert(acc.nrm, nrm[k * 3 + 2]) + table.insert(acc.nrm, nrm[k * 3 + 3]) + end + for _, v in Patch.triangles(gw, gh) do + table.insert(acc.idx, base + v) + end + return true +end + +local function primitive(a: Acc): Types.Primitive + 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 + return { + attributes = { POSITION = Scene.accessor(pb, "f32", 3, nv), NORMAL = Scene.accessor(nb, "f32", 3, nv), TEXCOORD_0 = Scene.accessor(ub, "f32", 2, nv) }, + indices = Scene.accessor(ib, "u32", 1, ni), + mode = "triangles", + } +end + +local function vec3(s: string?): { number }? + if not s then + return nil + end + local x, y, z = string.match(s, "^%s*(%S+)%s+(%S+)%s+(%S+)") + local a, b, c = tonumber(x), tonumber(y), tonumber(z) + if a and b and c then + return { a, b, c } + end + return nil +end + +function Build.scene(map: Parse.Map, o: Options): (Types.Scene?, string?) + local scene = Scene.new() + scene.meta.up = "z" + local skip: { [string]: boolean } = {} + for _, n in o.skip or {} do + skip[string.lower(n)] = true + end + local matOf: { [string]: number } = {} + local function material(name: string): number + local m = matOf[name] + if m then + return m + end + local w, h, known = o.size(name) + local uri = name + if o.variant == "quake2" then + uri = "textures/" .. name .. ".wal" + elseif o.variant == "quake3" then + uri = "textures/" .. name + end + table.insert(scene.textures, { name = name, uri = uri }) + local mat = Scene.material(name) + mat.metallic = 0 + mat.baseColorTexture = { texture = #scene.textures } + mat.extras = { map = { width = w, height = h, sizeKnown = known } } + table.insert(scene.materials, mat) + matOf[name] = #scene.materials + return #scene.materials + end + local root: Types.Node = { name = "map", children = {} } + table.insert(scene.nodes, root) + scene.roots[1] = 1 + local skipped = { faces = 0, patches = 0 } + local counts = { brushes = 0, patches = 0 } + local entities: { { [string]: string } } = {} + local polyTotal = 0 + for ei, ent in map.entities do + local keys = ent.keys + table.insert(entities, keys) + local node: Types.Node = { name = keys.targetname or keys.classname or ("entity " .. (ei - 1)), children = {}, + extras = { classname = keys.classname, keys = keys, brushes = ent.brushes, entity = ei - 1 } } + local brushes: { { Brush.Face } } = {} + local patchAcc: { [string]: Acc } = {} + local patchOrder: { string } = {} + for _, b in ent.brushes do + if b.faces then + counts.brushes += 1 + local faces: { Brush.Face } = {} + for _, f in b.faces do + local bf = Build.face(f) + if bf then + table.insert(faces, bf) + else + skipped.faces += 1 + end + end + table.insert(brushes, faces) + else + counts.patches += 1 + local tex = b.texture or "" + if not skip[string.lower(tex)] then + local acc = patchAcc[tex] + if not acc then + acc = { pos = {}, nrm = {}, uv = {}, idx = {} } + patchAcc[tex] = acc + table.insert(patchOrder, tex) + end + if not patchPrim(b, o.patchLevel or 4, acc :: Acc) then + skipped.patches += 1 + end + end + end + end + local prims: { Types.Primitive } = {} + if #brushes > 0 then + local polys, err = Brush.polygons(brushes, { hull = o.hull, merge = o.merge, epsilon = o.epsilon, maxPolygons = o.maxPolygons }) + if not polys then + return nil, err + end + polyTotal += #polys + if polyTotal > (o.maxPolygons or 2 ^ 20) then + return nil, "limit: too many polygons" + end + local kept: { Brush.Polygon } = {} + for _, p in polys do + local t = brushes[p.brush][p.face].texture or "" + if not skip[string.lower(t)] then + table.insert(kept, p) + end + end + local built = Brush.primitives(kept, brushes, function(name: string): (number, number) + local m = scene.materials[material(name)] + local e = (m.extras :: any).map + return e.width, e.height + end) + for _, bt in built do + bt.primitive.material = material(bt.texture) + table.insert(prims, bt.primitive) + end + end + for _, tex in patchOrder do + local acc = patchAcc[tex] + if #acc.idx > 0 then + local prim = primitive(acc) + prim.material = material(tex) + table.insert(prims, prim) + end + end + if #prims > 0 then + table.insert(scene.meshes, { name = node.name, primitives = prims }) + node.mesh = #scene.meshes + elseif #ent.brushes == 0 then + node.translation = vec3(keys.origin) + end + table.insert(scene.nodes, node) + table.insert(root.children, #scene.nodes) + end + scene.meta.entities = entities + scene.meta.skipped = skipped + scene.meta.counts = counts + return scene, nil +end + +return Build +end +__FILES["model/map/Parse"] = function() + +-- model/map/Parse: .map text -> entities (key / value pairs in order, brushes and patches as written). Grammar of the +-- Quake / Quake II / Half-Life (Valve 220) / Quake III editors (qbsp / q3map2 map parsers; no code taken). +local Types = __include("Types") + +local Parse = {} + +type Face = { + points: { number }, -- 3 points: x, y, z each + texture: string, + offset: { number }?, -- Quake standard: x, y offset + rotation: number?, -- standard / Valve 220 (degrees) + scale: { number }?, -- standard / Valve 220 + u: { number }?, -- Valve 220: axis x, y, z, offset + v: { number }?, + matrix: { { number } }?, -- Quake III brush primitives: 2 x 3 + flags: { number }?, -- trailing numbers: Quake II / III contents, surface flags, value (Hexen II: light) +} +type Brush = { + type: string, -- "brush" | "brushDef" | "patchDef2" | "patchDef3" + faces: { Face }?, + texture: string?, -- patches + size: { number }?, -- patches: width, height (columns, points per column as written) + params: { number }?, -- patches: the header numbers after width, height + points: { number }?, -- patches: 5 numbers (x, y, z, s, t) per control point, in file order (column by column) +} +type Entity = { keys: { [string]: string }, brushes: { Brush } } -- keys: an ordered object (Types.object) +type Map = { entities: { Entity }, game: string?, mapFormat: string?, comments: { string } } + +type St = { s: string, pos: number, n: number, comments: { string } } + +local function skip(st: St) + local s = st.s + while true do + local p = string.find(s, "[^%s]", st.pos) + if not p then + st.pos = st.n + 1 + return + end + if string.sub(s, p, p + 1) == "//" then + local e = string.find(s, "\n", p, true) or st.n + table.insert(st.comments, (string.gsub(string.sub(s, p + 2, e), "^%s*(.-)%s*$", "%1"))) + st.pos = e + 1 + else + st.pos = p + return + end + end +end + +local function peek(st: St): string + skip(st) + return string.sub(st.s, st.pos, st.pos) +end + +local function expect(st: St, c: string): string? + if peek(st) ~= c then + return "expected '" .. c .. "' at " .. (st.pos - 1) + end + st.pos += 1 + return nil +end + +local function word(st: St): string? + skip(st) + local a, b = string.find(st.s, "^[^%s]+", st.pos) + if not a then + return nil + end + st.pos = (b :: number) + 1 + return string.sub(st.s, a, b) +end + +local function number(st: St): number? + skip(st) + local a, b = string.find(st.s, "^[^%s%(%)%[%]{}]+", st.pos) + if not a then + return nil + end + local v = tonumber(string.sub(st.s, a, b)) + if v then + st.pos = (b :: number) + 1 + end + return v +end + +local function quoted(st: St): string? + if peek(st) ~= '"' then + return nil + end + local e = string.find(st.s, '"', st.pos + 1, true) + if not e then + return nil + end + local v = string.sub(st.s, st.pos + 1, e - 1) + st.pos = e + 1 + return v +end + +local function numbers(st: St, n: number, out: { number }): string? + for _ = 1, n do + local v = number(st) + if not v then + return "expected a number at " .. (st.pos - 1) + end + table.insert(out, v) + end + return nil +end + +local function vec(st: St, n: number, open: string, close: string): ({ number }?, string?) + local e = expect(st, open) + if e then + return nil, e + end + local out = {} + e = numbers(st, n, out) + if e then + return nil, e + end + e = expect(st, close) + if e then + return nil, e + end + return out, nil +end + +local function trailing(st: St): { number }? + local out: { number } = {} + while true do + local c = peek(st) + if not string.match(c, "[%d%-%+%.]") then + break + end + local v = number(st) + if not v then + break + end + table.insert(out, v) + end + return if #out > 0 then out else nil +end + +local function plane(st: St): ({ number }?, string?) + local pts: { number } = {} + for _ = 1, 3 do + local p, e = vec(st, 3, "(", ")") + if not p then + return nil, e + end + table.move(p, 1, 3, #pts + 1, pts) + end + return pts, nil +end + +local function face(st: St, bp: boolean): (Face?, string?) + local pts, e = plane(st) + if not pts then + return nil, e + end + local f: Face = { points = pts, texture = "" } + if bp then + e = expect(st, "(") + if e then + return nil, e + end + local r1, e1 = vec(st, 3, "(", ")") + if not r1 then + return nil, e1 + end + local r2, e2 = vec(st, 3, "(", ")") + if not r2 then + return nil, e2 + end + e = expect(st, ")") + if e then + return nil, e + end + f.matrix = { r1, r2 } + end + local tex = word(st) + if not tex then + return nil, "expected a texture name at " .. (st.pos - 1) + end + f.texture = tex + if not bp then + if peek(st) == "[" then + local u, eu = vec(st, 4, "[", "]") + if not u then + return nil, eu + end + local v, ev = vec(st, 4, "[", "]") + if not v then + return nil, ev + end + local rest = {} + e = numbers(st, 3, rest) + if e then + return nil, e + end + f.u, f.v, f.rotation, f.scale = u, v, rest[1], { rest[2], rest[3] } + else + local rest = {} + e = numbers(st, 5, rest) + if e then + return nil, e + end + f.offset, f.rotation, f.scale = { rest[1], rest[2] }, rest[3], { rest[4], rest[5] } + end + end + f.flags = trailing(st) + return f, nil +end + +local function patch(st: St, kind: string, maxPoints: number): (Brush?, string?) + local e = expect(st, "{") + if e then + return nil, e + end + local tex = word(st) + if not tex then + return nil, "expected a patch texture" + end + local hn = if kind == "patchDef3" then 7 else 5 + local head, eh = vec(st, hn, "(", ")") + if not head then + return nil, eh + end + local w, h = head[1], head[2] + if w ~= math.floor(w) or h ~= math.floor(h) or w < 1 or h < 1 or w * h > maxPoints then + return nil, "bad patch size " .. w .. " x " .. h + end + local pts: { number } = {} + e = expect(st, "(") + if e then + return nil, e + end + for _ = 1, w do + e = expect(st, "(") + if e then + return nil, e + end + for _ = 1, h do + local p, ep = vec(st, 5, "(", ")") + if not p then + return nil, ep + end + table.move(p, 1, 5, #pts + 1, pts) + end + e = expect(st, ")") + if e then + return nil, e + end + end + e = expect(st, ")") + if e then + return nil, e + end + e = expect(st, "}") + if e then + return nil, e + end + return { type = kind, texture = tex, size = { w, h }, params = { table.unpack(head, 3) }, points = pts }, nil +end + +local function brush(st: St, maxPoints: number): (Brush?, string?) + local c = peek(st) + if c == "(" then + local faces: { Face } = {} + while peek(st) == "(" do + local f, e = face(st, false) + if not f then + return nil, e + end + table.insert(faces, f) + end + local e = expect(st, "}") + if e then + return nil, e + end + return { type = "brush", faces = faces }, nil + end + if c == "}" then + st.pos += 1 + return { type = "brush", faces = {} }, nil + end + local kw = word(st) + local out: any, err: string? + if kw == "brushDef" then + local e = expect(st, "{") + if e then + return nil, e + end + local faces: { Face } = {} + while peek(st) == "(" do + local f, ef = face(st, true) + if not f then + return nil, ef + end + table.insert(faces, f) + end + e = expect(st, "}") + if e then + return nil, e + end + out = { type = "brushDef", faces = faces } + elseif kw == "patchDef2" or kw == "patchDef3" then + out, err = patch(st, kw, maxPoints) + if not out then + return nil, err + end + elseif kw == "brushDef3" then + return nil, "unsupported: Doom 3 / Quake 4 brushDef3" + else + return nil, "unexpected '" .. tostring(kw) .. "' in a brush at " .. (st.pos - 1) + end + local e = expect(st, "}") + if e then + return nil, e + end + return out, nil +end + +function Parse.parse(s: string, maxBrushes: number?): (Map?, string?, number?) + local st: St = { s = s, pos = 1, n = #s, comments = {} } + if string.sub(s, 1, 3) == "\239\187\191" then + st.pos = 4 + end + local limit = maxBrushes or 2 ^ 20 + local count = 0 + local ents: { Entity } = {} + while peek(st) ~= "" do + local at = st.pos - 1 + local e = expect(st, "{") + if e then + return nil, e, at + end + local keys: { [string]: string } = {} + local order: { string } = {} + local brushes: { Brush } = {} + while true do + local c = peek(st) + if c == "}" then + st.pos += 1 + break + elseif c == '"' then + local k = quoted(st) + local v = quoted(st) + if not k or not v then + return nil, "bad key / value at " .. (st.pos - 1), st.pos - 1 + end + if keys[k] == nil then + table.insert(order, k) + end + keys[k] = v + elseif c == "{" then + st.pos += 1 + local b, eb = brush(st, limit) + if not b then + return nil, eb, st.pos - 1 + end + count += 1 + if count > limit then + return nil, "limit: too many brushes", st.pos - 1 + end + table.insert(brushes, b) + elseif c == "" then + return nil, "truncated entity", st.pos - 1 + else + return nil, "unexpected '" .. c .. "' in an entity at " .. (st.pos - 1), st.pos - 1 + end + end + table.insert(ents, { keys = Types.object(keys, order) :: { [string]: string }, brushes = brushes }) + end + local game, fmt + for _, c in st.comments do + game = game or string.match(c, "^Game:%s*(.-)%s*$") + fmt = fmt or string.match(c, "^Format:%s*(.-)%s*$") + end + return { entities = ents, game = game, mapFormat = fmt, comments = st.comments }, nil, nil +end + +return Parse +end +__FILES["model/map/Write"] = function() + +-- model/map/Write: entities (model/map/Parse's layout) -> .map text in the editors' layout (TrenchBroom / Radiant: +-- one face per line, numbers in their shortest exact form). +local Types = __include("Types") +local Parse = __include("model/map/Parse") + +local Write = {} + +function Write.num(x: number): string + if x ~= x or x == math.huge or x == -math.huge then + return "0" + end + if x == math.floor(x) and math.abs(x) < 2 ^ 53 then + return string.format("%d", x) + end + for p = 6, 17 do + local s = string.format("%." .. p .. "g", x) + if tonumber(s) == x then + return s + end + end + return string.format("%.17g", x) +end + +local function nums(t: { number }, a: number, b: number): string + local out = table.create(b - a + 1) :: { string } + for i = a, b do + out[#out + 1] = Write.num(t[i] or 0) + end + return table.concat(out, " ") +end + +local function faceLine(f: Parse.Face, bp: boolean): (string?, string?) + local p = f.points + if type(p) ~= "table" or #p < 9 or type(f.texture) ~= "string" or f.texture == "" or string.find(f.texture, "%s") then + return nil, "a face needs 9 point numbers and a texture name without spaces" + end + local parts: { string } = { "( " .. nums(p, 1, 3) .. " ) ( " .. nums(p, 4, 6) .. " ) ( " .. nums(p, 7, 9) .. " )" } + if bp then + local m = f.matrix + if not m or not m[1] or not m[2] then + return nil, "a brushDef face needs a texture matrix" + end + table.insert(parts, "( ( " .. nums(m[1], 1, 3) .. " ) ( " .. nums(m[2], 1, 3) .. " ) )") + table.insert(parts, f.texture) + elseif f.u and f.v then + local sc = f.scale or { 1, 1 } + table.insert(parts, f.texture) + table.insert(parts, "[ " .. nums(f.u, 1, 4) .. " ] [ " .. nums(f.v, 1, 4) .. " ] " .. Write.num(f.rotation or 0) .. " " .. nums(sc, 1, 2)) + else + local o, sc = f.offset or { 0, 0 }, f.scale or { 1, 1 } + table.insert(parts, f.texture) + table.insert(parts, nums(o, 1, 2) .. " " .. Write.num(f.rotation or 0) .. " " .. nums(sc, 1, 2)) + end + if f.flags and #f.flags > 0 then + table.insert(parts, nums(f.flags, 1, #f.flags)) + end + return table.concat(parts, " "), nil +end + +local function patchText(b: Parse.Brush, out: { string }): string? + local size, pts = b.size, b.points + if not size or not pts or type(b.texture) ~= "string" then + return "a patch needs a texture, a size and control points" + end + local w, h = size[1], size[2] + if #pts < w * h * 5 then + return "a patch needs width * height * 5 control numbers" + end + local params = b.params or {} + local nParams = if b.type == "patchDef3" then 5 else 3 + table.insert(out, b.type) + table.insert(out, "{") + table.insert(out, b.texture) + table.insert(out, "( " .. Write.num(w) .. " " .. Write.num(h) .. " " .. nums(params, 1, nParams) .. " )") + table.insert(out, "(") + for i = 0, w - 1 do + local row = { "(" } + for j = 0, h - 1 do + local o = (i * h + j) * 5 + table.insert(row, "( " .. nums(pts, o + 1, o + 5) .. " )") + end + table.insert(row, ")") + table.insert(out, table.concat(row, " ")) + end + table.insert(out, ")") + table.insert(out, "}") + return nil +end + +function Write.text(map: Parse.Map): (string?, string?) + local out: { string } = {} + if map.game then + table.insert(out, "// Game: " .. map.game) + end + if map.mapFormat then + table.insert(out, "// Format: " .. map.mapFormat) + end + for ei, ent in map.entities do + table.insert(out, "// entity " .. (ei - 1)) + table.insert(out, "{") + for _, k in Types.keys(ent.keys) do + local v = ent.keys[k] + if v ~= nil then + if string.find(k, '"', 1, true) or string.find(tostring(v), '"', 1, true) or string.find(k, "[\r\n]") or string.find(tostring(v), "[\r\n]") then + return nil, "keys and values cannot hold quotes or line breaks: " .. k + end + table.insert(out, '"' .. k .. '" "' .. tostring(v) .. '"') + end + end + for bi, b in ent.brushes or {} do + table.insert(out, "// brush " .. (bi - 1)) + table.insert(out, "{") + if b.type == "patchDef2" or b.type == "patchDef3" then + local e = patchText(b, out) + if e then + return nil, e + end + else + local bp = b.type == "brushDef" + if bp then + table.insert(out, "brushDef") + table.insert(out, "{") + end + for _, f in b.faces or {} do + local line, e = faceLine(f, bp) + if not line then + return nil, e + end + table.insert(out, line) + end + if bp then + table.insert(out, "}") + end + end + table.insert(out, "}") + end + table.insert(out, "}") + end + table.insert(out, "") + return table.concat(out, "\n"), nil +end + +return Write +end __FILES["model/mca"] = function() -- model/mca: Minecraft Anvil region files (wiki "Region file format", "Chunk format"), read-only. Supports: gzip, zlib, diff --git a/build/Rosetta.luau.linemap.json b/build/Rosetta.luau.linemap.json index 41c4b9d..ca64952 100644 --- a/build/Rosetta.luau.linemap.json +++ b/build/Rosetta.luau.linemap.json @@ -1,546 +1,553 @@ [ [27, "src/Rosetta/init.luau"], [871, "src/Rosetta/Registry.luau"], -[3028, "src/Rosetta/Types.luau"], -[4111, "src/Rosetta/archive/7z/init.luau"], -[4496, "src/Rosetta/archive/7z/Header.luau"], -[5023, "src/Rosetta/archive/adf/init.luau"], -[5305, "src/Rosetta/archive/applesingle/init.luau"], -[5491, "src/Rosetta/archive/ar/init.luau"], -[5894, "src/Rosetta/archive/arj/init.luau"], -[6104, "src/Rosetta/archive/binhex/init.luau"], -[6353, "src/Rosetta/archive/br/init.luau"], -[6428, "src/Rosetta/archive/bz2/init.luau"], -[6492, "src/Rosetta/archive/cab/init.luau"], -[6905, "src/Rosetta/archive/cab/Sum.luau"], -[6946, "src/Rosetta/archive/cpio/init.luau"], -[7114, "src/Rosetta/archive/d64/init.luau"], -[7528, "src/Rosetta/archive/fat/init.luau"], -[7650, "src/Rosetta/archive/grp/init.luau"], -[7764, "src/Rosetta/archive/gzip/init.luau"], -[7949, "src/Rosetta/archive/iso/init.luau"], -[8021, "src/Rosetta/archive/lha/init.luau"], -[8446, "src/Rosetta/archive/lz4/init.luau"], -[8790, "src/Rosetta/archive/macbinary/init.luau"], -[8988, "src/Rosetta/archive/mpq/init.luau"], -[9394, "src/Rosetta/archive/mpq/Crypt.luau"], -[9459, "src/Rosetta/archive/pak/init.luau"], -[9593, "src/Rosetta/archive/rpm/init.luau"], -[9917, "src/Rosetta/archive/tar/init.luau"], -[10035, "src/Rosetta/archive/uu/init.luau"], -[10305, "src/Rosetta/archive/vpk/init.luau"], -[10616, "src/Rosetta/archive/vswap/init.luau"], -[10886, "src/Rosetta/archive/wad/init.luau"], -[11340, "src/Rosetta/archive/wad/Picture.luau"], -[11442, "src/Rosetta/archive/xz/init.luau"], -[11542, "src/Rosetta/archive/yenc/init.luau"], -[11814, "src/Rosetta/archive/z/init.luau"], -[11910, "src/Rosetta/archive/zip/init.luau"], -[12129, "src/Rosetta/archive/zoo/init.luau"], -[12325, "src/Rosetta/archive/zst/init.luau"], -[12389, "src/Rosetta/audio/aac/init.luau"], -[12595, "src/Rosetta/audio/ac3/init.luau"], -[12741, "src/Rosetta/audio/adpcm/init.luau"], -[12886, "src/Rosetta/audio/adx/init.luau"], -[13117, "src/Rosetta/audio/aiff/init.luau"], -[13508, "src/Rosetta/audio/ape/init.luau"], -[13636, "src/Rosetta/audio/au/init.luau"], -[13797, "src/Rosetta/audio/brstm/init.luau"], -[14088, "src/Rosetta/audio/caf/init.luau"], -[14750, "src/Rosetta/audio/flac/init.luau"], -[14898, "src/Rosetta/audio/flac/Meta.luau"], -[15120, "src/Rosetta/audio/flac/Stream.luau"], -[15490, "src/Rosetta/audio/m4a/init.luau"], -[15824, "src/Rosetta/audio/mp3/init.luau"], -[16084, "src/Rosetta/audio/mp3/Index.luau"], -[16275, "src/Rosetta/audio/mp3/Stream.luau"], -[16502, "src/Rosetta/audio/mp3/Tags.luau"], -[16814, "src/Rosetta/audio/mpc/init.luau"], -[16908, "src/Rosetta/audio/opus/init.luau"], -[17286, "src/Rosetta/audio/opus/Encode.luau"], -[17397, "src/Rosetta/audio/qoa/init.luau"], -[17577, "src/Rosetta/audio/tta/init.luau"], -[17695, "src/Rosetta/audio/vag/init.luau"], -[17918, "src/Rosetta/audio/voc/init.luau"], -[18193, "src/Rosetta/audio/vorbis/init.luau"], -[18647, "src/Rosetta/audio/vorbis/Encode.luau"], -[19460, "src/Rosetta/audio/wav/init.luau"], -[20081, "src/Rosetta/audio/wav/Codecs.luau"], -[20247, "src/Rosetta/audio/wavpack/init.luau"], -[20454, "src/Rosetta/cad/step/init.luau"], -[20836, "src/Rosetta/cad/step/Brep.luau"], -[21071, "src/Rosetta/cad/step/Parse.luau"], -[21628, "src/Rosetta/cad/step/Write.luau"], -[21876, "src/Rosetta/codecs/audio/Aac/init.luau"], -[22195, "src/Rosetta/codecs/audio/Aac/Decode.luau"], -[23078, "src/Rosetta/codecs/audio/Aac/Tables.luau"], -[23413, "src/Rosetta/codecs/audio/Ac3/init.luau"], -[23572, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], -[24457, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], -[24558, "src/Rosetta/codecs/audio/Adpcm/init.luau"], -[25312, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], -[25614, "src/Rosetta/codecs/audio/Alac/init.luau"], -[25848, "src/Rosetta/codecs/audio/Alac/Decode.luau"], -[26267, "src/Rosetta/codecs/audio/Alac/Encode.luau"], -[26679, "src/Rosetta/codecs/audio/Ape/init.luau"], -[26894, "src/Rosetta/codecs/audio/Ape/Decode.luau"], -[27655, "src/Rosetta/codecs/audio/ApeTag.luau"], -[27752, "src/Rosetta/codecs/audio/Flac/init.luau"], -[27763, "src/Rosetta/codecs/audio/Flac/Encode.luau"], -[28712, "src/Rosetta/codecs/audio/Flac/Frame.luau"], -[29309, "src/Rosetta/codecs/audio/Hively/init.luau"], -[29505, "src/Rosetta/codecs/audio/Hively/Load.luau"], -[29754, "src/Rosetta/codecs/audio/Hively/Player.luau"], -[30712, "src/Rosetta/codecs/audio/Hively/Tables.luau"], -[30931, "src/Rosetta/codecs/audio/Mdct/init.luau"], -[31115, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], -[31324, "src/Rosetta/codecs/audio/MidiRender.luau"], -[31670, "src/Rosetta/codecs/audio/Mpa/init.luau"], -[31684, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], -[31743, "src/Rosetta/codecs/audio/Mpa/Core.luau"], -[33346, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], -[33638, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], -[34023, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], -[34664, "src/Rosetta/codecs/audio/Mpa/Header.luau"], -[34805, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], -[35031, "src/Rosetta/codecs/audio/Musepack/init.luau"], -[35376, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], -[36257, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], -[36635, "src/Rosetta/codecs/audio/Opus/init.luau"], -[36649, "src/Rosetta/codecs/audio/Opus/Celt.luau"], -[38496, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], -[39561, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], -[39621, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], -[40081, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], -[40418, "src/Rosetta/codecs/audio/Opus/Packet.luau"], -[40651, "src/Rosetta/codecs/audio/Opus/Silk.luau"], -[42687, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], -[43061, "src/Rosetta/codecs/audio/Pcm/init.luau"], -[43324, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], -[43621, "src/Rosetta/codecs/audio/Qoa/init.luau"], -[43903, "src/Rosetta/codecs/audio/Resample/init.luau"], -[44262, "src/Rosetta/codecs/audio/SoundFont/init.luau"], -[44316, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], -[44459, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], -[44972, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], -[45753, "src/Rosetta/codecs/audio/Stream.luau"], -[45914, "src/Rosetta/codecs/audio/Tracker/init.luau"], -[46396, "src/Rosetta/codecs/audio/Tracker/Load.luau"], -[46674, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], -[46843, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], -[46971, "src/Rosetta/codecs/audio/Tracker/Player.luau"], -[48959, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], -[49075, "src/Rosetta/codecs/audio/Tta/init.luau"], -[49192, "src/Rosetta/codecs/audio/Tta/Decode.luau"], -[49444, "src/Rosetta/codecs/audio/Vorbis/init.luau"], -[49457, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], -[49841, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], -[50407, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], -[50828, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], -[50867, "src/Rosetta/codecs/audio/VorbisComment.luau"], -[50919, "src/Rosetta/codecs/audio/WavPack/init.luau"], -[51141, "src/Rosetta/codecs/audio/WavPack/Block.luau"], -[52596, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], -[52659, "src/Rosetta/codecs/compress/Brotli/init.luau"], -[52746, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], -[53715, "src/Rosetta/codecs/compress/Brotli/Static.luau"], -[54583, "src/Rosetta/codecs/compress/Bzip2/init.luau"], -[54631, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], -[55147, "src/Rosetta/codecs/compress/Deflate/init.luau"], -[55473, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], -[55893, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], -[56328, "src/Rosetta/codecs/compress/Explode.luau"], -[56524, "src/Rosetta/codecs/compress/Lz4.luau"], -[56793, "src/Rosetta/codecs/compress/Lzh/init.luau"], -[57397, "src/Rosetta/codecs/compress/Lzma/init.luau"], -[57937, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], -[57975, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], -[58448, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], -[58624, "src/Rosetta/codecs/compress/Lzw/init.luau"], -[58892, "src/Rosetta/codecs/compress/Lzx.luau"], -[59326, "src/Rosetta/codecs/compress/PackBits.luau"], -[59416, "src/Rosetta/codecs/compress/Quantum.luau"], -[59653, "src/Rosetta/codecs/compress/UnixCompress.luau"], -[59957, "src/Rosetta/codecs/compress/Xxh32.luau"], -[60026, "src/Rosetta/codecs/compress/Zstd/init.luau"], -[60083, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], -[61041, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], -[61193, "src/Rosetta/codecs/entropy/Huffman.luau"], -[61475, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], -[61486, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], -[61700, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], -[61944, "src/Rosetta/codecs/font/Bitmap.luau"], -[62145, "src/Rosetta/codecs/font/Cff/init.luau"], -[62786, "src/Rosetta/codecs/font/GlyphNames.luau"], -[62936, "src/Rosetta/codecs/font/TrueType/init.luau"], -[63250, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], -[63642, "src/Rosetta/codecs/font/TrueType/Tables.luau"], -[64144, "src/Rosetta/codecs/image/Bcn/init.luau"], -[64251, "src/Rosetta/codecs/image/Bcn/Decode.luau"], -[64740, "src/Rosetta/codecs/image/Bcn/Encode.luau"], -[65169, "src/Rosetta/codecs/image/Blend.luau"], -[65548, "src/Rosetta/codecs/image/Dct/init.luau"], -[65929, "src/Rosetta/codecs/image/Etc.luau"], -[66227, "src/Rosetta/codecs/image/Half.luau"], -[66296, "src/Rosetta/codecs/image/Jpeg/init.luau"], -[66650, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], -[67058, "src/Rosetta/codecs/image/Jpeg/Color.luau"], -[67295, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], -[68055, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], -[68936, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], -[69382, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], -[69460, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], -[69527, "src/Rosetta/codecs/image/Pixels.luau"], -[69791, "src/Rosetta/codecs/image/Quantize/init.luau"], -[70250, "src/Rosetta/codecs/image/Raster.luau"], -[70947, "src/Rosetta/codecs/image/Texel.luau"], -[71320, "src/Rosetta/codecs/image/Texture.luau"], -[71465, "src/Rosetta/codecs/image/Vp8/init.luau"], -[71595, "src/Rosetta/codecs/image/Vp8/Decode.luau"], -[73551, "src/Rosetta/codecs/image/Vp8/Predict.luau"], -[73810, "src/Rosetta/codecs/image/Vp8/Tables.luau"], -[74059, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], -[74178, "src/Rosetta/codecs/image/Vp8L/init.luau"], -[74282, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], -[75135, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], -[76087, "src/Rosetta/codecs/image/Yuv.luau"], -[76355, "src/Rosetta/codecs/model/DoomMap/init.luau"], -[76800, "src/Rosetta/codecs/model/DoomMap/Udmf.luau"], -[77050, "src/Rosetta/codecs/model/Draco/init.luau"], -[77382, "src/Rosetta/codecs/model/Draco/Attributes.luau"], -[77851, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], -[79040, "src/Rosetta/codecs/model/Draco/Int64.luau"], -[79189, "src/Rosetta/codecs/model/Draco/KdTree.luau"], -[79548, "src/Rosetta/codecs/model/Draco/Predict.luau"], -[80510, "src/Rosetta/codecs/model/Draco/Reader.luau"], -[80984, "src/Rosetta/codecs/model/Mat4.luau"], -[81243, "src/Rosetta/codecs/model/MeshFlatten.luau"], -[81771, "src/Rosetta/codecs/model/Minecraft/init.luau"], -[82323, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], -[82402, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], -[82509, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], -[82715, "src/Rosetta/codecs/model/Polygon.luau"], -[82949, "src/Rosetta/codecs/model/Rbx/init.luau"], -[83186, "src/Rosetta/codecs/model/Rbx/Binary.luau"], -[83940, "src/Rosetta/codecs/model/Rig.luau"], -[84183, "src/Rosetta/codecs/model/Sampler.luau"], -[84343, "src/Rosetta/codecs/model/Vrml/init.luau"], -[84491, "src/Rosetta/codecs/model/Vrml/Build.luau"], -[85065, "src/Rosetta/codecs/model/Vrml/Fields.luau"], -[85228, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], -[85977, "src/Rosetta/codecs/model/Vrml/Parse.luau"], -[86499, "src/Rosetta/codecs/model/Vrml/Write.luau"], -[87226, "src/Rosetta/codecs/model/Vrml/Xml.luau"], -[87458, "src/Rosetta/codecs/text/Json/init.luau"], -[87727, "src/Rosetta/codecs/text/Json/Decode.luau"], -[88141, "src/Rosetta/codecs/text/Json/Encode.luau"], -[88443, "src/Rosetta/codecs/text/Lexer/init.luau"], -[88575, "src/Rosetta/codecs/text/Nbt/init.luau"], -[88928, "src/Rosetta/codecs/text/Nbt/Binary.luau"], -[89620, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], -[90260, "src/Rosetta/codecs/text/Nbt/Value.luau"], -[90498, "src/Rosetta/codecs/text/Text/init.luau"], -[90589, "src/Rosetta/codecs/text/Url/init.luau"], -[90794, "src/Rosetta/codecs/text/Xml/init.luau"], -[91197, "src/Rosetta/codecs/text/Xml/Parse.luau"], -[91937, "src/Rosetta/codecs/video/Dsp.luau"], -[92660, "src/Rosetta/codecs/video/H263/init.luau"], -[92816, "src/Rosetta/codecs/video/H263/Decoder.luau"], -[93674, "src/Rosetta/codecs/video/H263/Tables.luau"], -[93877, "src/Rosetta/codecs/video/H264/init.luau"], -[94250, "src/Rosetta/codecs/video/H264/Bitstream.luau"], -[94525, "src/Rosetta/codecs/video/H264/Cabac.luau"], -[95656, "src/Rosetta/codecs/video/H264/Cavlc.luau"], -[96424, "src/Rosetta/codecs/video/H264/Deblock.luau"], -[96682, "src/Rosetta/codecs/video/H264/Decoder.luau"], -[97691, "src/Rosetta/codecs/video/H264/Inter.luau"], -[97945, "src/Rosetta/codecs/video/H264/Intra.luau"], -[98352, "src/Rosetta/codecs/video/H264/Mb.luau"], -[99258, "src/Rosetta/codecs/video/H264/Params.luau"], -[99705, "src/Rosetta/codecs/video/H264/Slice.luau"], -[99956, "src/Rosetta/codecs/video/H264/Tables.luau"], -[99997, "src/Rosetta/codecs/video/H264/Transform.luau"], -[100162, "src/Rosetta/codecs/video/Legacy/init.luau"], -[100360, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], -[100657, "src/Rosetta/codecs/video/Legacy/Flic.luau"], -[101024, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], -[101142, "src/Rosetta/codecs/video/Legacy/Picture.luau"], -[101250, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], -[101523, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], -[101918, "src/Rosetta/codecs/video/Legacy/Smc.luau"], -[102095, "src/Rosetta/codecs/video/Mpeg1/init.luau"], -[102107, "src/Rosetta/codecs/video/Mpeg2/init.luau"], -[102474, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], -[103981, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], -[104120, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], -[104258, "src/Rosetta/codecs/video/Theora/init.luau"], -[104521, "src/Rosetta/codecs/video/Theora/Decoder.luau"], -[105785, "src/Rosetta/codecs/video/Theora/Header.luau"], -[106148, "src/Rosetta/codecs/video/Video/init.luau"], -[106705, "src/Rosetta/codecs/video/Video/Source.luau"], -[106990, "src/Rosetta/containers/Archive.luau"], -[107257, "src/Rosetta/containers/AudioWrap.luau"], -[107760, "src/Rosetta/containers/Avi/init.luau"], -[108312, "src/Rosetta/containers/Chunks.luau"], -[108447, "src/Rosetta/containers/Cpio.luau"], -[108875, "src/Rosetta/containers/Demux.luau"], -[109150, "src/Rosetta/containers/Ebml/init.luau"], -[109463, "src/Rosetta/containers/Fat.luau"], -[110151, "src/Rosetta/containers/Iso9660.luau"], -[110656, "src/Rosetta/containers/IsoBmff/init.luau"], -[110826, "src/Rosetta/containers/IsoBmff/Box.luau"], -[111014, "src/Rosetta/containers/IsoBmff/Demux.luau"], -[111859, "src/Rosetta/containers/IsoBmff/Meta.luau"], -[112380, "src/Rosetta/containers/IsoBmff/Mux.luau"], -[112896, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], -[113013, "src/Rosetta/containers/MacFile.luau"], -[113162, "src/Rosetta/containers/MpegEs.luau"], -[113328, "src/Rosetta/containers/MpegPs/init.luau"], -[113548, "src/Rosetta/containers/MpegTs/init.luau"], -[114340, "src/Rosetta/containers/Ogg/init.luau"], -[114765, "src/Rosetta/containers/Ogg/Mux.luau"], -[114960, "src/Rosetta/containers/Ogg/Page.luau"], -[115129, "src/Rosetta/containers/Riff/init.luau"], -[115446, "src/Rosetta/containers/Tar.luau"], -[115860, "src/Rosetta/containers/Zip/init.luau"], -[116492, "src/Rosetta/core/Adler32.luau"], -[116538, "src/Rosetta/core/Base64.luau"], -[116697, "src/Rosetta/core/Bits.luau"], -[116990, "src/Rosetta/core/Bytes.luau"], -[117517, "src/Rosetta/core/Crc16.luau"], -[117569, "src/Rosetta/core/Crc32.luau"], -[117681, "src/Rosetta/core/Err.luau"], -[117763, "src/Rosetta/core/Input.luau"], -[117839, "src/Rosetta/core/Md5.luau"], -[117998, "src/Rosetta/core/Sniff.luau"], -[118027, "src/Rosetta/data/cbor/init.luau"], -[118126, "src/Rosetta/data/cbor/Codec.luau"], -[118695, "src/Rosetta/data/csv/init.luau"], -[119007, "src/Rosetta/data/ini/init.luau"], -[119253, "src/Rosetta/data/json/init.luau"], -[119345, "src/Rosetta/data/msgpack/init.luau"], -[119434, "src/Rosetta/data/msgpack/Codec.luau"], -[119876, "src/Rosetta/data/nbt/init.luau"], -[119935, "src/Rosetta/data/plist/init.luau"], -[120241, "src/Rosetta/data/plist/Binary.luau"], -[120508, "src/Rosetta/data/snbt/init.luau"], -[120571, "src/Rosetta/data/toml/init.luau"], -[120638, "src/Rosetta/data/toml/Decode.luau"], -[121266, "src/Rosetta/data/toml/Encode.luau"], -[121475, "src/Rosetta/data/xml/init.luau"], -[121531, "src/Rosetta/data/yaml/init.luau"], -[121604, "src/Rosetta/data/yaml/Emit.luau"], -[121894, "src/Rosetta/data/yaml/Parse.luau"], -[123187, "src/Rosetta/font/bdf/init.luau"], -[123476, "src/Rosetta/font/bmfont/init.luau"], -[123903, "src/Rosetta/font/bmfont/Parse.luau"], -[124356, "src/Rosetta/font/eot/init.luau"], -[124588, "src/Rosetta/font/fon/init.luau"], -[124871, "src/Rosetta/font/hershey/init.luau"], -[125066, "src/Rosetta/font/pcf/init.luau"], -[125346, "src/Rosetta/font/psf/init.luau"], -[125666, "src/Rosetta/font/ttf/init.luau"], -[125717, "src/Rosetta/font/type1/init.luau"], -[126076, "src/Rosetta/font/type1/Charstring.luau"], -[126354, "src/Rosetta/font/woff/init.luau"], -[126486, "src/Rosetta/font/woff2/init.luau"], -[126543, "src/Rosetta/font/woff2/Rebuild.luau"], -[127083, "src/Rosetta/host/init.luau"], -[127128, "src/Rosetta/host/Love.luau"], -[127271, "src/Rosetta/host/LuaJIT.luau"], -[127321, "src/Rosetta/host/Luau.luau"], -[127344, "src/Rosetta/host/Roblox.luau"], -[127703, "src/Rosetta/image/ani/init.luau"], -[127883, "src/Rosetta/image/blp/init.luau"], -[128141, "src/Rosetta/image/bmp/init.luau"], -[128556, "src/Rosetta/image/dds/init.luau"], -[129039, "src/Rosetta/image/exr/init.luau"], -[129799, "src/Rosetta/image/exr/Codec.luau"], -[129910, "src/Rosetta/image/exr/Piz.luau"], -[130267, "src/Rosetta/image/gif/init.luau"], -[130783, "src/Rosetta/image/gif/Decode.luau"], -[130846, "src/Rosetta/image/hdr/init.luau"], -[131075, "src/Rosetta/image/hdr/Codec.luau"], -[131286, "src/Rosetta/image/icns/init.luau"], -[131617, "src/Rosetta/image/ico/init.luau"], -[131894, "src/Rosetta/image/ico/Dib.luau"], -[131989, "src/Rosetta/image/ilbm/init.luau"], -[132308, "src/Rosetta/image/jpeg/init.luau"], -[132444, "src/Rosetta/image/ktx/init.luau"], -[133104, "src/Rosetta/image/pcx/init.luau"], -[133368, "src/Rosetta/image/png/init.luau"], -[133948, "src/Rosetta/image/png/Apng.luau"], -[134028, "src/Rosetta/image/png/Decode.luau"], -[134268, "src/Rosetta/image/png/Encode.luau"], -[134423, "src/Rosetta/image/pnm/init.luau"], -[134801, "src/Rosetta/image/pnm/Codec.luau"], -[135078, "src/Rosetta/image/qoi/init.luau"], -[135200, "src/Rosetta/image/qoi/Codec.luau"], -[135350, "src/Rosetta/image/sgi/init.luau"], -[135635, "src/Rosetta/image/sunras/init.luau"], -[135881, "src/Rosetta/image/tga/init.luau"], -[136151, "src/Rosetta/image/tga/Codec.luau"], -[136303, "src/Rosetta/image/tiff/init.luau"], -[137130, "src/Rosetta/image/tiff/Pixels.luau"], -[137520, "src/Rosetta/image/tim/init.luau"], -[137762, "src/Rosetta/image/vtf/init.luau"], -[137997, "src/Rosetta/image/webp/init.luau"], -[138607, "src/Rosetta/image/webp/Alpha.luau"], -[138683, "src/Rosetta/image/webp/Anim.luau"], -[138838, "src/Rosetta/image/xbm/init.luau"], -[138999, "src/Rosetta/image/xpm/init.luau"], -[139267, "src/Rosetta/image/xpm/Names.luau"], -[139323, "src/Rosetta/layered/aseprite/init.luau"], -[140061, "src/Rosetta/layered/ora/init.luau"], -[140348, "src/Rosetta/layered/psd/init.luau"], -[141083, "src/Rosetta/layered/psd/Channels.luau"], -[141435, "src/Rosetta/model/3ds/init.luau"], -[141518, "src/Rosetta/model/3ds/Build.luau"], -[142165, "src/Rosetta/model/3ds/Read.luau"], -[142661, "src/Rosetta/model/3ds/Write.luau"], -[143466, "src/Rosetta/model/3mf/init.luau"], -[143548, "src/Rosetta/model/3mf/Read.luau"], -[144136, "src/Rosetta/model/3mf/Write.luau"], -[144541, "src/Rosetta/model/b3d/init.luau"], -[144596, "src/Rosetta/model/b3d/Read.luau"], -[145167, "src/Rosetta/model/bsp/init.luau"], -[145312, "src/Rosetta/model/bsp/Brush.luau"], -[145590, "src/Rosetta/model/bsp/Quake3.luau"], -[145845, "src/Rosetta/model/dae/init.luau"], -[146034, "src/Rosetta/model/dae/Math.luau"], -[146081, "src/Rosetta/model/dae/Read.luau"], -[147931, "src/Rosetta/model/dae/Write.luau"], -[148300, "src/Rosetta/model/fbx/init.luau"], -[148448, "src/Rosetta/model/fbx/Ascii.luau"], -[148718, "src/Rosetta/model/fbx/Binary.luau"], -[149173, "src/Rosetta/model/fbx/Read.luau"], -[150535, "src/Rosetta/model/fbx/Write.luau"], -[151520, "src/Rosetta/model/fbx/Xform.luau"], -[151561, "src/Rosetta/model/gltf/init.luau"], -[151798, "src/Rosetta/model/gltf/Pack.luau"], -[151867, "src/Rosetta/model/gltf/Read.luau"], -[152598, "src/Rosetta/model/gltf/Write.luau"], -[153278, "src/Rosetta/model/iqm/init.luau"], -[153354, "src/Rosetta/model/iqm/Read.luau"], -[153709, "src/Rosetta/model/iqm/Write.luau"], -[154396, "src/Rosetta/model/ldraw/init.luau"], -[154474, "src/Rosetta/model/ldraw/Colors.luau"], -[154792, "src/Rosetta/model/ldraw/Read.luau"], -[155369, "src/Rosetta/model/lwo/init.luau"], -[155445, "src/Rosetta/model/lwo/Build.luau"], -[155907, "src/Rosetta/model/lwo/Parse.luau"], -[156450, "src/Rosetta/model/mca/init.luau"], -[156792, "src/Rosetta/model/mca/Chunk.luau"], -[156925, "src/Rosetta/model/mca/Lz4Block.luau"], -[156995, "src/Rosetta/model/md2/init.luau"], -[157194, "src/Rosetta/model/md3/init.luau"], -[157422, "src/Rosetta/model/md5/init.luau"], -[157503, "src/Rosetta/model/md5/Read.luau"], -[157936, "src/Rosetta/model/mdl/init.luau"], -[158018, "src/Rosetta/model/mdl/HalfLife.luau"], -[158346, "src/Rosetta/model/mdl/Quake.luau"], -[158564, "src/Rosetta/model/ms3d/init.luau"], -[158636, "src/Rosetta/model/ms3d/Read.luau"], -[159082, "src/Rosetta/model/ms3d/Write.luau"], -[159551, "src/Rosetta/model/obj/init.luau"], -[160293, "src/Rosetta/model/obj/Mtl.luau"], -[160580, "src/Rosetta/model/off/init.luau"], -[161042, "src/Rosetta/model/ply/init.luau"], -[162147, "src/Rosetta/model/ply/Binary.luau"], -[162348, "src/Rosetta/model/pmx/init.luau"], -[162417, "src/Rosetta/model/pmx/Build.luau"], -[162713, "src/Rosetta/model/pmx/Pmd.luau"], -[163048, "src/Rosetta/model/pmx/Read.luau"], -[163452, "src/Rosetta/model/proc/init.luau"], -[163834, "src/Rosetta/model/qb/init.luau"], -[164227, "src/Rosetta/model/rbxm/init.luau"], -[164819, "src/Rosetta/model/rbxmx/init.luau"], -[165472, "src/Rosetta/model/robloxmesh/init.luau"], -[166131, "src/Rosetta/model/robloxmesh/Parse.luau"], -[166588, "src/Rosetta/model/robloxmesh/Write.luau"], -[166697, "src/Rosetta/model/schematic/init.luau"], -[167018, "src/Rosetta/model/schematic/Common.luau"], -[167138, "src/Rosetta/model/schematic/Litematic.luau"], -[167349, "src/Rosetta/model/schematic/Mcedit.luau"], -[167593, "src/Rosetta/model/schematic/Sponge.luau"], -[167722, "src/Rosetta/model/smd/init.luau"], -[167789, "src/Rosetta/model/smd/Read.luau"], -[168058, "src/Rosetta/model/smd/Write.luau"], -[168301, "src/Rosetta/model/stl/init.luau"], -[168751, "src/Rosetta/model/stl/Decode.luau"], -[168825, "src/Rosetta/model/udmf/init.luau"], -[168908, "src/Rosetta/model/usda/init.luau"], -[169117, "src/Rosetta/model/usda/Build.luau"], -[170395, "src/Rosetta/model/usda/Parse.luau"], -[171193, "src/Rosetta/model/usda/Write.luau"], -[172010, "src/Rosetta/model/vox/init.luau"], -[172896, "src/Rosetta/model/vox/Grid.luau"], -[172953, "src/Rosetta/model/vrml/init.luau"], -[173019, "src/Rosetta/model/x/init.luau"], -[173149, "src/Rosetta/model/x/Build.luau"], -[173712, "src/Rosetta/model/x/Parse.luau"], -[174009, "src/Rosetta/model/x3d/init.luau"], -[174087, "src/Rosetta/music/669/init.luau"], -[174293, "src/Rosetta/music/ahx/init.luau"], -[174344, "src/Rosetta/music/far/init.luau"], -[174573, "src/Rosetta/music/hmp/init.luau"], -[174837, "src/Rosetta/music/hvl/init.luau"], -[174888, "src/Rosetta/music/it/init.luau"], -[175306, "src/Rosetta/music/it/Itsex.luau"], -[175422, "src/Rosetta/music/med/init.luau"], -[176069, "src/Rosetta/music/midi/init.luau"], -[176212, "src/Rosetta/music/midi/Smf.luau"], -[176623, "src/Rosetta/music/mod/init.luau"], -[176976, "src/Rosetta/music/mtm/init.luau"], -[177198, "src/Rosetta/music/mus/init.luau"], -[177355, "src/Rosetta/music/okt/init.luau"], -[177636, "src/Rosetta/music/ptm/init.luau"], -[177858, "src/Rosetta/music/s3m/init.luau"], -[178094, "src/Rosetta/music/sf2/init.luau"], -[178137, "src/Rosetta/music/stm/init.luau"], -[178368, "src/Rosetta/music/ult/init.luau"], -[178672, "src/Rosetta/music/umx/init.luau"], -[178888, "src/Rosetta/music/xm/init.luau"], -[179449, "src/Rosetta/music/xmi/init.luau"], -[179657, "src/Rosetta/ops/AudioOps.luau"], -[180106, "src/Rosetta/ops/ImageOps/init.luau"], -[180750, "src/Rosetta/ops/ImageOps/Kernels.luau"], -[181260, "src/Rosetta/ops/LayerOps.luau"], -[181353, "src/Rosetta/ops/MeshOps/init.luau"], -[182389, "src/Rosetta/ops/MeshOps/Greedy.luau"], -[182556, "src/Rosetta/ops/MusicOps.luau"], -[182904, "src/Rosetta/playlist/m3u/init.luau"], -[183257, "src/Rosetta/playlist/pls/init.luau"], -[183435, "src/Rosetta/playlist/xspf/init.luau"], -[183638, "src/Rosetta/subtitle/ass/init.luau"], -[184082, "src/Rosetta/subtitle/srt/init.luau"], -[184255, "src/Rosetta/subtitle/vtt/init.luau"], -[184458, "src/Rosetta/vector/gamemaps/init.luau"], -[184645, "src/Rosetta/vector/gamemaps/Expand.luau"], -[184742, "src/Rosetta/vector/svg/init.luau"], -[184828, "src/Rosetta/vector/svg/Parse.luau"], -[185574, "src/Rosetta/vector/svg/PathData.luau"], -[185942, "src/Rosetta/vector/svg/Render.luau"], -[186359, "src/Rosetta/vector/svg/Style.luau"], -[186731, "src/Rosetta/vector/svg/Write.luau"], -[186931, "src/Rosetta/vector/tiled/init.luau"], -[187111, "src/Rosetta/vector/tiled/Data.luau"], -[187262, "src/Rosetta/vector/tiled/Tmj.luau"], -[187893, "src/Rosetta/vector/tiled/Tmx.luau"], -[188505, "src/Rosetta/video/avi/init.luau"], -[188799, "src/Rosetta/video/fli/init.luau"], -[188950, "src/Rosetta/video/flv/init.luau"], -[189334, "src/Rosetta/video/flv/Amf.luau"], -[189492, "src/Rosetta/video/flv/Mux.luau"], -[189773, "src/Rosetta/video/h264/init.luau"], -[189912, "src/Rosetta/video/mkv/init.luau"], -[190068, "src/Rosetta/video/mkv/Mux.luau"], -[190347, "src/Rosetta/video/mkv/Parse.luau"], -[191068, "src/Rosetta/video/mp4/init.luau"], -[191396, "src/Rosetta/video/mpegps/init.luau"], -[191583, "src/Rosetta/video/mpegts/init.luau"], -[191821, "src/Rosetta/video/ogv/init.luau"], -[192216, "src/Rosetta/video/smk/init.luau"], -[192525, "src/Rosetta/video/smk/Audio.luau"], -[192645, "src/Rosetta/video/y4m/init.luau"] +[3040, "src/Rosetta/Types.luau"], +[4123, "src/Rosetta/archive/7z/init.luau"], +[4508, "src/Rosetta/archive/7z/Header.luau"], +[5035, "src/Rosetta/archive/adf/init.luau"], +[5317, "src/Rosetta/archive/applesingle/init.luau"], +[5503, "src/Rosetta/archive/ar/init.luau"], +[5906, "src/Rosetta/archive/arj/init.luau"], +[6116, "src/Rosetta/archive/binhex/init.luau"], +[6365, "src/Rosetta/archive/br/init.luau"], +[6440, "src/Rosetta/archive/bz2/init.luau"], +[6504, "src/Rosetta/archive/cab/init.luau"], +[6917, "src/Rosetta/archive/cab/Sum.luau"], +[6958, "src/Rosetta/archive/cpio/init.luau"], +[7126, "src/Rosetta/archive/d64/init.luau"], +[7540, "src/Rosetta/archive/fat/init.luau"], +[7662, "src/Rosetta/archive/grp/init.luau"], +[7776, "src/Rosetta/archive/gzip/init.luau"], +[7961, "src/Rosetta/archive/iso/init.luau"], +[8033, "src/Rosetta/archive/lha/init.luau"], +[8458, "src/Rosetta/archive/lz4/init.luau"], +[8802, "src/Rosetta/archive/macbinary/init.luau"], +[9000, "src/Rosetta/archive/mpq/init.luau"], +[9406, "src/Rosetta/archive/mpq/Crypt.luau"], +[9471, "src/Rosetta/archive/pak/init.luau"], +[9605, "src/Rosetta/archive/rpm/init.luau"], +[9929, "src/Rosetta/archive/tar/init.luau"], +[10047, "src/Rosetta/archive/uu/init.luau"], +[10317, "src/Rosetta/archive/vpk/init.luau"], +[10628, "src/Rosetta/archive/vswap/init.luau"], +[10898, "src/Rosetta/archive/wad/init.luau"], +[11352, "src/Rosetta/archive/wad/Picture.luau"], +[11454, "src/Rosetta/archive/xz/init.luau"], +[11554, "src/Rosetta/archive/yenc/init.luau"], +[11826, "src/Rosetta/archive/z/init.luau"], +[11922, "src/Rosetta/archive/zip/init.luau"], +[12141, "src/Rosetta/archive/zoo/init.luau"], +[12337, "src/Rosetta/archive/zst/init.luau"], +[12401, "src/Rosetta/audio/aac/init.luau"], +[12607, "src/Rosetta/audio/ac3/init.luau"], +[12753, "src/Rosetta/audio/adpcm/init.luau"], +[12898, "src/Rosetta/audio/adx/init.luau"], +[13129, "src/Rosetta/audio/aiff/init.luau"], +[13520, "src/Rosetta/audio/ape/init.luau"], +[13648, "src/Rosetta/audio/au/init.luau"], +[13809, "src/Rosetta/audio/brstm/init.luau"], +[14100, "src/Rosetta/audio/caf/init.luau"], +[14762, "src/Rosetta/audio/flac/init.luau"], +[14910, "src/Rosetta/audio/flac/Meta.luau"], +[15132, "src/Rosetta/audio/flac/Stream.luau"], +[15502, "src/Rosetta/audio/m4a/init.luau"], +[15836, "src/Rosetta/audio/mp3/init.luau"], +[16096, "src/Rosetta/audio/mp3/Index.luau"], +[16287, "src/Rosetta/audio/mp3/Stream.luau"], +[16514, "src/Rosetta/audio/mp3/Tags.luau"], +[16826, "src/Rosetta/audio/mpc/init.luau"], +[16920, "src/Rosetta/audio/opus/init.luau"], +[17298, "src/Rosetta/audio/opus/Encode.luau"], +[17409, "src/Rosetta/audio/qoa/init.luau"], +[17589, "src/Rosetta/audio/tta/init.luau"], +[17707, "src/Rosetta/audio/vag/init.luau"], +[17930, "src/Rosetta/audio/voc/init.luau"], +[18205, "src/Rosetta/audio/vorbis/init.luau"], +[18659, "src/Rosetta/audio/vorbis/Encode.luau"], +[19472, "src/Rosetta/audio/wav/init.luau"], +[20093, "src/Rosetta/audio/wav/Codecs.luau"], +[20259, "src/Rosetta/audio/wavpack/init.luau"], +[20466, "src/Rosetta/cad/step/init.luau"], +[20848, "src/Rosetta/cad/step/Brep.luau"], +[21083, "src/Rosetta/cad/step/Parse.luau"], +[21640, "src/Rosetta/cad/step/Write.luau"], +[21888, "src/Rosetta/codecs/audio/Aac/init.luau"], +[22207, "src/Rosetta/codecs/audio/Aac/Decode.luau"], +[23090, "src/Rosetta/codecs/audio/Aac/Tables.luau"], +[23425, "src/Rosetta/codecs/audio/Ac3/init.luau"], +[23584, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], +[24469, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], +[24570, "src/Rosetta/codecs/audio/Adpcm/init.luau"], +[25324, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], +[25626, "src/Rosetta/codecs/audio/Alac/init.luau"], +[25860, "src/Rosetta/codecs/audio/Alac/Decode.luau"], +[26279, "src/Rosetta/codecs/audio/Alac/Encode.luau"], +[26691, "src/Rosetta/codecs/audio/Ape/init.luau"], +[26906, "src/Rosetta/codecs/audio/Ape/Decode.luau"], +[27667, "src/Rosetta/codecs/audio/ApeTag.luau"], +[27764, "src/Rosetta/codecs/audio/Flac/init.luau"], +[27775, "src/Rosetta/codecs/audio/Flac/Encode.luau"], +[28724, "src/Rosetta/codecs/audio/Flac/Frame.luau"], +[29321, "src/Rosetta/codecs/audio/Hively/init.luau"], +[29517, "src/Rosetta/codecs/audio/Hively/Load.luau"], +[29766, "src/Rosetta/codecs/audio/Hively/Player.luau"], +[30724, "src/Rosetta/codecs/audio/Hively/Tables.luau"], +[30943, "src/Rosetta/codecs/audio/Mdct/init.luau"], +[31127, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], +[31336, "src/Rosetta/codecs/audio/MidiRender.luau"], +[31682, "src/Rosetta/codecs/audio/Mpa/init.luau"], +[31696, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], +[31755, "src/Rosetta/codecs/audio/Mpa/Core.luau"], +[33358, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], +[33650, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], +[34035, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], +[34676, "src/Rosetta/codecs/audio/Mpa/Header.luau"], +[34817, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], +[35043, "src/Rosetta/codecs/audio/Musepack/init.luau"], +[35388, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], +[36269, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], +[36647, "src/Rosetta/codecs/audio/Opus/init.luau"], +[36661, "src/Rosetta/codecs/audio/Opus/Celt.luau"], +[38508, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], +[39573, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], +[39633, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], +[40093, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], +[40430, "src/Rosetta/codecs/audio/Opus/Packet.luau"], +[40663, "src/Rosetta/codecs/audio/Opus/Silk.luau"], +[42699, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], +[43073, "src/Rosetta/codecs/audio/Pcm/init.luau"], +[43336, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], +[43633, "src/Rosetta/codecs/audio/Qoa/init.luau"], +[43915, "src/Rosetta/codecs/audio/Resample/init.luau"], +[44274, "src/Rosetta/codecs/audio/SoundFont/init.luau"], +[44328, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], +[44471, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], +[44984, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], +[45765, "src/Rosetta/codecs/audio/Stream.luau"], +[45926, "src/Rosetta/codecs/audio/Tracker/init.luau"], +[46408, "src/Rosetta/codecs/audio/Tracker/Load.luau"], +[46686, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], +[46855, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], +[46983, "src/Rosetta/codecs/audio/Tracker/Player.luau"], +[48971, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], +[49087, "src/Rosetta/codecs/audio/Tta/init.luau"], +[49204, "src/Rosetta/codecs/audio/Tta/Decode.luau"], +[49456, "src/Rosetta/codecs/audio/Vorbis/init.luau"], +[49469, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], +[49853, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], +[50419, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], +[50840, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], +[50879, "src/Rosetta/codecs/audio/VorbisComment.luau"], +[50931, "src/Rosetta/codecs/audio/WavPack/init.luau"], +[51153, "src/Rosetta/codecs/audio/WavPack/Block.luau"], +[52608, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], +[52671, "src/Rosetta/codecs/compress/Brotli/init.luau"], +[52758, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], +[53727, "src/Rosetta/codecs/compress/Brotli/Static.luau"], +[54595, "src/Rosetta/codecs/compress/Bzip2/init.luau"], +[54643, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], +[55159, "src/Rosetta/codecs/compress/Deflate/init.luau"], +[55485, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], +[55905, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], +[56340, "src/Rosetta/codecs/compress/Explode.luau"], +[56536, "src/Rosetta/codecs/compress/Lz4.luau"], +[56805, "src/Rosetta/codecs/compress/Lzh/init.luau"], +[57409, "src/Rosetta/codecs/compress/Lzma/init.luau"], +[57949, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], +[57987, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], +[58460, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], +[58636, "src/Rosetta/codecs/compress/Lzw/init.luau"], +[58904, "src/Rosetta/codecs/compress/Lzx.luau"], +[59338, "src/Rosetta/codecs/compress/PackBits.luau"], +[59428, "src/Rosetta/codecs/compress/Quantum.luau"], +[59665, "src/Rosetta/codecs/compress/UnixCompress.luau"], +[59969, "src/Rosetta/codecs/compress/Xxh32.luau"], +[60038, "src/Rosetta/codecs/compress/Zstd/init.luau"], +[60095, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], +[61053, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], +[61205, "src/Rosetta/codecs/entropy/Huffman.luau"], +[61487, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], +[61498, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], +[61712, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], +[61956, "src/Rosetta/codecs/font/Bitmap.luau"], +[62157, "src/Rosetta/codecs/font/Cff/init.luau"], +[62798, "src/Rosetta/codecs/font/GlyphNames.luau"], +[62948, "src/Rosetta/codecs/font/TrueType/init.luau"], +[63262, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], +[63654, "src/Rosetta/codecs/font/TrueType/Tables.luau"], +[64156, "src/Rosetta/codecs/image/Bcn/init.luau"], +[64263, "src/Rosetta/codecs/image/Bcn/Decode.luau"], +[64752, "src/Rosetta/codecs/image/Bcn/Encode.luau"], +[65181, "src/Rosetta/codecs/image/Blend.luau"], +[65560, "src/Rosetta/codecs/image/Dct/init.luau"], +[65941, "src/Rosetta/codecs/image/Etc.luau"], +[66239, "src/Rosetta/codecs/image/Half.luau"], +[66308, "src/Rosetta/codecs/image/Jpeg/init.luau"], +[66662, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], +[67070, "src/Rosetta/codecs/image/Jpeg/Color.luau"], +[67307, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], +[68067, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], +[68948, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], +[69394, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], +[69472, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], +[69539, "src/Rosetta/codecs/image/Miptex.luau"], +[69755, "src/Rosetta/codecs/image/Pixels.luau"], +[70075, "src/Rosetta/codecs/image/Quantize/init.luau"], +[70534, "src/Rosetta/codecs/image/Raster.luau"], +[71231, "src/Rosetta/codecs/image/Texel.luau"], +[71604, "src/Rosetta/codecs/image/Texture.luau"], +[71749, "src/Rosetta/codecs/image/Vp8/init.luau"], +[71879, "src/Rosetta/codecs/image/Vp8/Decode.luau"], +[73835, "src/Rosetta/codecs/image/Vp8/Predict.luau"], +[74094, "src/Rosetta/codecs/image/Vp8/Tables.luau"], +[74343, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], +[74462, "src/Rosetta/codecs/image/Vp8L/init.luau"], +[74566, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], +[75419, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], +[76371, "src/Rosetta/codecs/image/Yuv.luau"], +[76639, "src/Rosetta/codecs/model/Brush.luau"], +[77279, "src/Rosetta/codecs/model/DoomMap/init.luau"], +[77724, "src/Rosetta/codecs/model/DoomMap/Udmf.luau"], +[77974, "src/Rosetta/codecs/model/Draco/init.luau"], +[78306, "src/Rosetta/codecs/model/Draco/Attributes.luau"], +[78775, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], +[79964, "src/Rosetta/codecs/model/Draco/Int64.luau"], +[80113, "src/Rosetta/codecs/model/Draco/KdTree.luau"], +[80472, "src/Rosetta/codecs/model/Draco/Predict.luau"], +[81434, "src/Rosetta/codecs/model/Draco/Reader.luau"], +[81908, "src/Rosetta/codecs/model/Mat4.luau"], +[82167, "src/Rosetta/codecs/model/MeshFlatten.luau"], +[82695, "src/Rosetta/codecs/model/Minecraft/init.luau"], +[83247, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], +[83326, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], +[83433, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], +[83639, "src/Rosetta/codecs/model/Patch.luau"], +[83763, "src/Rosetta/codecs/model/Polygon.luau"], +[83997, "src/Rosetta/codecs/model/Rbx/init.luau"], +[84234, "src/Rosetta/codecs/model/Rbx/Binary.luau"], +[84988, "src/Rosetta/codecs/model/Rig.luau"], +[85231, "src/Rosetta/codecs/model/Sampler.luau"], +[85391, "src/Rosetta/codecs/model/Vrml/init.luau"], +[85539, "src/Rosetta/codecs/model/Vrml/Build.luau"], +[86113, "src/Rosetta/codecs/model/Vrml/Fields.luau"], +[86276, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], +[87025, "src/Rosetta/codecs/model/Vrml/Parse.luau"], +[87547, "src/Rosetta/codecs/model/Vrml/Write.luau"], +[88274, "src/Rosetta/codecs/model/Vrml/Xml.luau"], +[88506, "src/Rosetta/codecs/text/Json/init.luau"], +[88775, "src/Rosetta/codecs/text/Json/Decode.luau"], +[89189, "src/Rosetta/codecs/text/Json/Encode.luau"], +[89491, "src/Rosetta/codecs/text/Lexer/init.luau"], +[89623, "src/Rosetta/codecs/text/Nbt/init.luau"], +[89976, "src/Rosetta/codecs/text/Nbt/Binary.luau"], +[90668, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], +[91308, "src/Rosetta/codecs/text/Nbt/Value.luau"], +[91546, "src/Rosetta/codecs/text/Text/init.luau"], +[91637, "src/Rosetta/codecs/text/Url/init.luau"], +[91842, "src/Rosetta/codecs/text/Xml/init.luau"], +[92245, "src/Rosetta/codecs/text/Xml/Parse.luau"], +[92985, "src/Rosetta/codecs/video/Dsp.luau"], +[93708, "src/Rosetta/codecs/video/H263/init.luau"], +[93864, "src/Rosetta/codecs/video/H263/Decoder.luau"], +[94722, "src/Rosetta/codecs/video/H263/Tables.luau"], +[94925, "src/Rosetta/codecs/video/H264/init.luau"], +[95298, "src/Rosetta/codecs/video/H264/Bitstream.luau"], +[95573, "src/Rosetta/codecs/video/H264/Cabac.luau"], +[96704, "src/Rosetta/codecs/video/H264/Cavlc.luau"], +[97472, "src/Rosetta/codecs/video/H264/Deblock.luau"], +[97730, "src/Rosetta/codecs/video/H264/Decoder.luau"], +[98739, "src/Rosetta/codecs/video/H264/Inter.luau"], +[98993, "src/Rosetta/codecs/video/H264/Intra.luau"], +[99400, "src/Rosetta/codecs/video/H264/Mb.luau"], +[100306, "src/Rosetta/codecs/video/H264/Params.luau"], +[100753, "src/Rosetta/codecs/video/H264/Slice.luau"], +[101004, "src/Rosetta/codecs/video/H264/Tables.luau"], +[101045, "src/Rosetta/codecs/video/H264/Transform.luau"], +[101210, "src/Rosetta/codecs/video/Legacy/init.luau"], +[101408, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], +[101705, "src/Rosetta/codecs/video/Legacy/Flic.luau"], +[102072, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], +[102190, "src/Rosetta/codecs/video/Legacy/Picture.luau"], +[102298, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], +[102571, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], +[102966, "src/Rosetta/codecs/video/Legacy/Smc.luau"], +[103143, "src/Rosetta/codecs/video/Mpeg1/init.luau"], +[103155, "src/Rosetta/codecs/video/Mpeg2/init.luau"], +[103522, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], +[105029, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], +[105168, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], +[105306, "src/Rosetta/codecs/video/Theora/init.luau"], +[105569, "src/Rosetta/codecs/video/Theora/Decoder.luau"], +[106833, "src/Rosetta/codecs/video/Theora/Header.luau"], +[107196, "src/Rosetta/codecs/video/Video/init.luau"], +[107753, "src/Rosetta/codecs/video/Video/Source.luau"], +[108038, "src/Rosetta/containers/Archive.luau"], +[108305, "src/Rosetta/containers/AudioWrap.luau"], +[108808, "src/Rosetta/containers/Avi/init.luau"], +[109360, "src/Rosetta/containers/Chunks.luau"], +[109495, "src/Rosetta/containers/Cpio.luau"], +[109923, "src/Rosetta/containers/Demux.luau"], +[110198, "src/Rosetta/containers/Ebml/init.luau"], +[110511, "src/Rosetta/containers/Fat.luau"], +[111199, "src/Rosetta/containers/Iso9660.luau"], +[111704, "src/Rosetta/containers/IsoBmff/init.luau"], +[111874, "src/Rosetta/containers/IsoBmff/Box.luau"], +[112062, "src/Rosetta/containers/IsoBmff/Demux.luau"], +[112907, "src/Rosetta/containers/IsoBmff/Meta.luau"], +[113428, "src/Rosetta/containers/IsoBmff/Mux.luau"], +[113944, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], +[114061, "src/Rosetta/containers/MacFile.luau"], +[114210, "src/Rosetta/containers/MpegEs.luau"], +[114376, "src/Rosetta/containers/MpegPs/init.luau"], +[114596, "src/Rosetta/containers/MpegTs/init.luau"], +[115388, "src/Rosetta/containers/Ogg/init.luau"], +[115813, "src/Rosetta/containers/Ogg/Mux.luau"], +[116008, "src/Rosetta/containers/Ogg/Page.luau"], +[116177, "src/Rosetta/containers/Riff/init.luau"], +[116494, "src/Rosetta/containers/Tar.luau"], +[116908, "src/Rosetta/containers/Zip/init.luau"], +[117540, "src/Rosetta/core/Adler32.luau"], +[117586, "src/Rosetta/core/Base64.luau"], +[117745, "src/Rosetta/core/Bits.luau"], +[118038, "src/Rosetta/core/Bytes.luau"], +[118565, "src/Rosetta/core/Crc16.luau"], +[118617, "src/Rosetta/core/Crc32.luau"], +[118729, "src/Rosetta/core/Err.luau"], +[118811, "src/Rosetta/core/Input.luau"], +[118887, "src/Rosetta/core/Md5.luau"], +[119046, "src/Rosetta/core/Sniff.luau"], +[119075, "src/Rosetta/data/cbor/init.luau"], +[119174, "src/Rosetta/data/cbor/Codec.luau"], +[119743, "src/Rosetta/data/csv/init.luau"], +[120055, "src/Rosetta/data/ini/init.luau"], +[120301, "src/Rosetta/data/json/init.luau"], +[120393, "src/Rosetta/data/msgpack/init.luau"], +[120482, "src/Rosetta/data/msgpack/Codec.luau"], +[120924, "src/Rosetta/data/nbt/init.luau"], +[120983, "src/Rosetta/data/plist/init.luau"], +[121289, "src/Rosetta/data/plist/Binary.luau"], +[121556, "src/Rosetta/data/snbt/init.luau"], +[121619, "src/Rosetta/data/toml/init.luau"], +[121686, "src/Rosetta/data/toml/Decode.luau"], +[122314, "src/Rosetta/data/toml/Encode.luau"], +[122523, "src/Rosetta/data/xml/init.luau"], +[122579, "src/Rosetta/data/yaml/init.luau"], +[122652, "src/Rosetta/data/yaml/Emit.luau"], +[122942, "src/Rosetta/data/yaml/Parse.luau"], +[124235, "src/Rosetta/font/bdf/init.luau"], +[124524, "src/Rosetta/font/bmfont/init.luau"], +[124951, "src/Rosetta/font/bmfont/Parse.luau"], +[125404, "src/Rosetta/font/eot/init.luau"], +[125636, "src/Rosetta/font/fon/init.luau"], +[125919, "src/Rosetta/font/hershey/init.luau"], +[126114, "src/Rosetta/font/pcf/init.luau"], +[126394, "src/Rosetta/font/psf/init.luau"], +[126714, "src/Rosetta/font/ttf/init.luau"], +[126765, "src/Rosetta/font/type1/init.luau"], +[127124, "src/Rosetta/font/type1/Charstring.luau"], +[127402, "src/Rosetta/font/woff/init.luau"], +[127534, "src/Rosetta/font/woff2/init.luau"], +[127591, "src/Rosetta/font/woff2/Rebuild.luau"], +[128131, "src/Rosetta/host/init.luau"], +[128176, "src/Rosetta/host/Love.luau"], +[128319, "src/Rosetta/host/LuaJIT.luau"], +[128369, "src/Rosetta/host/Luau.luau"], +[128392, "src/Rosetta/host/Roblox.luau"], +[128751, "src/Rosetta/image/ani/init.luau"], +[128931, "src/Rosetta/image/blp/init.luau"], +[129189, "src/Rosetta/image/bmp/init.luau"], +[129604, "src/Rosetta/image/dds/init.luau"], +[130087, "src/Rosetta/image/exr/init.luau"], +[130847, "src/Rosetta/image/exr/Codec.luau"], +[130958, "src/Rosetta/image/exr/Piz.luau"], +[131315, "src/Rosetta/image/gif/init.luau"], +[131831, "src/Rosetta/image/gif/Decode.luau"], +[131894, "src/Rosetta/image/hdr/init.luau"], +[132123, "src/Rosetta/image/hdr/Codec.luau"], +[132334, "src/Rosetta/image/icns/init.luau"], +[132665, "src/Rosetta/image/ico/init.luau"], +[132942, "src/Rosetta/image/ico/Dib.luau"], +[133037, "src/Rosetta/image/ilbm/init.luau"], +[133356, "src/Rosetta/image/jpeg/init.luau"], +[133492, "src/Rosetta/image/ktx/init.luau"], +[134152, "src/Rosetta/image/pcx/init.luau"], +[134416, "src/Rosetta/image/png/init.luau"], +[134996, "src/Rosetta/image/png/Apng.luau"], +[135076, "src/Rosetta/image/png/Decode.luau"], +[135316, "src/Rosetta/image/png/Encode.luau"], +[135471, "src/Rosetta/image/pnm/init.luau"], +[135849, "src/Rosetta/image/pnm/Codec.luau"], +[136126, "src/Rosetta/image/qoi/init.luau"], +[136248, "src/Rosetta/image/qoi/Codec.luau"], +[136398, "src/Rosetta/image/sgi/init.luau"], +[136683, "src/Rosetta/image/sunras/init.luau"], +[136929, "src/Rosetta/image/tga/init.luau"], +[137199, "src/Rosetta/image/tga/Codec.luau"], +[137351, "src/Rosetta/image/tiff/init.luau"], +[138178, "src/Rosetta/image/tiff/Pixels.luau"], +[138568, "src/Rosetta/image/tim/init.luau"], +[138810, "src/Rosetta/image/vtf/init.luau"], +[139045, "src/Rosetta/image/webp/init.luau"], +[139655, "src/Rosetta/image/webp/Alpha.luau"], +[139731, "src/Rosetta/image/webp/Anim.luau"], +[139886, "src/Rosetta/image/xbm/init.luau"], +[140047, "src/Rosetta/image/xpm/init.luau"], +[140315, "src/Rosetta/image/xpm/Names.luau"], +[140371, "src/Rosetta/layered/aseprite/init.luau"], +[141109, "src/Rosetta/layered/ora/init.luau"], +[141396, "src/Rosetta/layered/psd/init.luau"], +[142131, "src/Rosetta/layered/psd/Channels.luau"], +[142483, "src/Rosetta/model/3ds/init.luau"], +[142566, "src/Rosetta/model/3ds/Build.luau"], +[143213, "src/Rosetta/model/3ds/Read.luau"], +[143709, "src/Rosetta/model/3ds/Write.luau"], +[144514, "src/Rosetta/model/3mf/init.luau"], +[144596, "src/Rosetta/model/3mf/Read.luau"], +[145184, "src/Rosetta/model/3mf/Write.luau"], +[145589, "src/Rosetta/model/b3d/init.luau"], +[145644, "src/Rosetta/model/b3d/Read.luau"], +[146215, "src/Rosetta/model/bsp/init.luau"], +[146360, "src/Rosetta/model/bsp/Brush.luau"], +[146623, "src/Rosetta/model/bsp/Quake3.luau"], +[146851, "src/Rosetta/model/dae/init.luau"], +[147040, "src/Rosetta/model/dae/Math.luau"], +[147087, "src/Rosetta/model/dae/Read.luau"], +[148937, "src/Rosetta/model/dae/Write.luau"], +[149306, "src/Rosetta/model/fbx/init.luau"], +[149454, "src/Rosetta/model/fbx/Ascii.luau"], +[149724, "src/Rosetta/model/fbx/Binary.luau"], +[150179, "src/Rosetta/model/fbx/Read.luau"], +[151541, "src/Rosetta/model/fbx/Write.luau"], +[152526, "src/Rosetta/model/fbx/Xform.luau"], +[152567, "src/Rosetta/model/gltf/init.luau"], +[152804, "src/Rosetta/model/gltf/Pack.luau"], +[152873, "src/Rosetta/model/gltf/Read.luau"], +[153604, "src/Rosetta/model/gltf/Write.luau"], +[154284, "src/Rosetta/model/iqm/init.luau"], +[154360, "src/Rosetta/model/iqm/Read.luau"], +[154715, "src/Rosetta/model/iqm/Write.luau"], +[155402, "src/Rosetta/model/ldraw/init.luau"], +[155480, "src/Rosetta/model/ldraw/Colors.luau"], +[155798, "src/Rosetta/model/ldraw/Read.luau"], +[156375, "src/Rosetta/model/lwo/init.luau"], +[156451, "src/Rosetta/model/lwo/Build.luau"], +[156913, "src/Rosetta/model/lwo/Parse.luau"], +[157456, "src/Rosetta/model/map/init.luau"], +[157773, "src/Rosetta/model/map/Build.luau"], +[158016, "src/Rosetta/model/map/Parse.luau"], +[158401, "src/Rosetta/model/map/Write.luau"], +[158547, "src/Rosetta/model/mca/init.luau"], +[158889, "src/Rosetta/model/mca/Chunk.luau"], +[159022, "src/Rosetta/model/mca/Lz4Block.luau"], +[159092, "src/Rosetta/model/md2/init.luau"], +[159291, "src/Rosetta/model/md3/init.luau"], +[159519, "src/Rosetta/model/md5/init.luau"], +[159600, "src/Rosetta/model/md5/Read.luau"], +[160033, "src/Rosetta/model/mdl/init.luau"], +[160115, "src/Rosetta/model/mdl/HalfLife.luau"], +[160443, "src/Rosetta/model/mdl/Quake.luau"], +[160661, "src/Rosetta/model/ms3d/init.luau"], +[160733, "src/Rosetta/model/ms3d/Read.luau"], +[161179, "src/Rosetta/model/ms3d/Write.luau"], +[161648, "src/Rosetta/model/obj/init.luau"], +[162390, "src/Rosetta/model/obj/Mtl.luau"], +[162677, "src/Rosetta/model/off/init.luau"], +[163139, "src/Rosetta/model/ply/init.luau"], +[164244, "src/Rosetta/model/ply/Binary.luau"], +[164445, "src/Rosetta/model/pmx/init.luau"], +[164514, "src/Rosetta/model/pmx/Build.luau"], +[164810, "src/Rosetta/model/pmx/Pmd.luau"], +[165145, "src/Rosetta/model/pmx/Read.luau"], +[165549, "src/Rosetta/model/proc/init.luau"], +[165931, "src/Rosetta/model/qb/init.luau"], +[166324, "src/Rosetta/model/rbxm/init.luau"], +[166916, "src/Rosetta/model/rbxmx/init.luau"], +[167569, "src/Rosetta/model/robloxmesh/init.luau"], +[168228, "src/Rosetta/model/robloxmesh/Parse.luau"], +[168685, "src/Rosetta/model/robloxmesh/Write.luau"], +[168794, "src/Rosetta/model/schematic/init.luau"], +[169115, "src/Rosetta/model/schematic/Common.luau"], +[169235, "src/Rosetta/model/schematic/Litematic.luau"], +[169446, "src/Rosetta/model/schematic/Mcedit.luau"], +[169690, "src/Rosetta/model/schematic/Sponge.luau"], +[169819, "src/Rosetta/model/smd/init.luau"], +[169886, "src/Rosetta/model/smd/Read.luau"], +[170155, "src/Rosetta/model/smd/Write.luau"], +[170398, "src/Rosetta/model/stl/init.luau"], +[170848, "src/Rosetta/model/stl/Decode.luau"], +[170922, "src/Rosetta/model/udmf/init.luau"], +[171005, "src/Rosetta/model/usda/init.luau"], +[171214, "src/Rosetta/model/usda/Build.luau"], +[172492, "src/Rosetta/model/usda/Parse.luau"], +[173290, "src/Rosetta/model/usda/Write.luau"], +[174107, "src/Rosetta/model/vox/init.luau"], +[174993, "src/Rosetta/model/vox/Grid.luau"], +[175050, "src/Rosetta/model/vrml/init.luau"], +[175116, "src/Rosetta/model/x/init.luau"], +[175246, "src/Rosetta/model/x/Build.luau"], +[175809, "src/Rosetta/model/x/Parse.luau"], +[176106, "src/Rosetta/model/x3d/init.luau"], +[176184, "src/Rosetta/music/669/init.luau"], +[176390, "src/Rosetta/music/ahx/init.luau"], +[176441, "src/Rosetta/music/far/init.luau"], +[176670, "src/Rosetta/music/hmp/init.luau"], +[176934, "src/Rosetta/music/hvl/init.luau"], +[176985, "src/Rosetta/music/it/init.luau"], +[177403, "src/Rosetta/music/it/Itsex.luau"], +[177519, "src/Rosetta/music/med/init.luau"], +[178166, "src/Rosetta/music/midi/init.luau"], +[178309, "src/Rosetta/music/midi/Smf.luau"], +[178720, "src/Rosetta/music/mod/init.luau"], +[179073, "src/Rosetta/music/mtm/init.luau"], +[179295, "src/Rosetta/music/mus/init.luau"], +[179452, "src/Rosetta/music/okt/init.luau"], +[179733, "src/Rosetta/music/ptm/init.luau"], +[179955, "src/Rosetta/music/s3m/init.luau"], +[180191, "src/Rosetta/music/sf2/init.luau"], +[180234, "src/Rosetta/music/stm/init.luau"], +[180465, "src/Rosetta/music/ult/init.luau"], +[180769, "src/Rosetta/music/umx/init.luau"], +[180985, "src/Rosetta/music/xm/init.luau"], +[181546, "src/Rosetta/music/xmi/init.luau"], +[181754, "src/Rosetta/ops/AudioOps.luau"], +[182203, "src/Rosetta/ops/ImageOps/init.luau"], +[182847, "src/Rosetta/ops/ImageOps/Kernels.luau"], +[183357, "src/Rosetta/ops/LayerOps.luau"], +[183450, "src/Rosetta/ops/MeshOps/init.luau"], +[184486, "src/Rosetta/ops/MeshOps/Greedy.luau"], +[184653, "src/Rosetta/ops/MusicOps.luau"], +[185001, "src/Rosetta/playlist/m3u/init.luau"], +[185354, "src/Rosetta/playlist/pls/init.luau"], +[185532, "src/Rosetta/playlist/xspf/init.luau"], +[185735, "src/Rosetta/subtitle/ass/init.luau"], +[186179, "src/Rosetta/subtitle/srt/init.luau"], +[186352, "src/Rosetta/subtitle/vtt/init.luau"], +[186555, "src/Rosetta/vector/gamemaps/init.luau"], +[186742, "src/Rosetta/vector/gamemaps/Expand.luau"], +[186839, "src/Rosetta/vector/svg/init.luau"], +[186925, "src/Rosetta/vector/svg/Parse.luau"], +[187671, "src/Rosetta/vector/svg/PathData.luau"], +[188039, "src/Rosetta/vector/svg/Render.luau"], +[188456, "src/Rosetta/vector/svg/Style.luau"], +[188828, "src/Rosetta/vector/svg/Write.luau"], +[189028, "src/Rosetta/vector/tiled/init.luau"], +[189208, "src/Rosetta/vector/tiled/Data.luau"], +[189359, "src/Rosetta/vector/tiled/Tmj.luau"], +[189990, "src/Rosetta/vector/tiled/Tmx.luau"], +[190602, "src/Rosetta/video/avi/init.luau"], +[190896, "src/Rosetta/video/fli/init.luau"], +[191047, "src/Rosetta/video/flv/init.luau"], +[191431, "src/Rosetta/video/flv/Amf.luau"], +[191589, "src/Rosetta/video/flv/Mux.luau"], +[191870, "src/Rosetta/video/h264/init.luau"], +[192009, "src/Rosetta/video/mkv/init.luau"], +[192165, "src/Rosetta/video/mkv/Mux.luau"], +[192444, "src/Rosetta/video/mkv/Parse.luau"], +[193165, "src/Rosetta/video/mp4/init.luau"], +[193493, "src/Rosetta/video/mpegps/init.luau"], +[193680, "src/Rosetta/video/mpegts/init.luau"], +[193918, "src/Rosetta/video/ogv/init.luau"], +[194313, "src/Rosetta/video/smk/init.luau"], +[194622, "src/Rosetta/video/smk/Audio.luau"], +[194742, "src/Rosetta/video/y4m/init.luau"] ] diff --git a/build/rosetta.lua b/build/rosetta.lua index e408c46..f7a60c5 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") @@ -2321,6 +2321,18 @@ local list= { return __include("model/lwo") end, }, + { + name = "map", + category = "model", + path = "model/map", + extensions = { "map" }, + mime = { "text/x-quake-map" }, + deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Miptex", "codecs/model/Brush", "codecs/model/Patch" }, + caps = { decode = true, encode = true, variants = { "quake", "valve220", "quake2", "quake3" }, patches = true }, + load = function() + return __include("model/map") + end, + }, { name = "mca", category = "model", @@ -70156,12 +70168,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 @@ -70418,6 +70647,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() @@ -76984,6 +77268,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/DoomMap"] = function() local __compat = __compat local buffer, bit32, type, __iter = __compat.buffer, __compat.bit32, __compat.type, __compat.__iter --!strict -- codecs/model/DoomMap: Doom / Heretic / Hexen binary map lumps (Hexen when BEHAVIOR is present) and UDMF TEXTMAP to @@ -83344,6 +84268,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. @@ -145816,7 +146864,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 @@ -145948,6 +146996,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 = {} @@ -145980,34 +147029,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 @@ -146085,12 +147118,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 @@ -146113,7 +147146,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) @@ -146169,7 +147202,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) @@ -146222,8 +147255,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 = {} @@ -146303,52 +147338,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 @@ -157079,6 +158085,1097 @@ end return Parse end +__FILES["model/map"] = function() +local __compat = __compat local buffer, type, __iter = __compat.buffer, __compat.type, __compat.__iter --!strict +-- model/map: editor .map files of Quake, Half-Life (Valve 220), Quake II (surface / content flags) and Quake III +-- (brushDef brush primitives, patchDef2; patchDef3 meshes), read and write. Grammar of the qbsp / q3map2 parsers (no +-- code taken). Brushes become polygons through codecs/model/Brush (optionally CSG'd and merged), patches through +-- codecs/model/Patch; a mesh per entity with brushes; entities as nodes with their keys in extras. Texture sizes from +-- opts.textureSizes, the worldspawn's WADs, .wal files or images through resolve; else 64 x 64. Not supported: Doom 3 +-- brushDef3, Build engine maps (binary: model/buildmap), compiling (no BSP, vis or light). + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Input = __include("core/Input") +local Types = __include("Types") +local Miptex = __include("codecs/image/Miptex") +local Brush = __include("codecs/model/Brush") +local Parse = __include("model/map/Parse") +local Write = __include("model/map/Write") +local Build = __include("model/map/Build") + +-- ------------------------------------------------------------------------------------------------ contract +local Map = { + name = "map", + category = "model", + extensions = { "map" }, + mime = { "text/x-quake-map" }, + deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Miptex", "codecs/model/Brush", "codecs/model/Patch" }, + caps = { decode = true, encode = true, variants = { "quake", "valve220", "quake2", "quake3" }, patches = true }, +} +-- ------------------------------------------------------------------------------------------------ types +-- ------------------------------------------------------------------------------------------------ sniff + + + + + + + + + + + + + + + + + + +function Map.sniff(r) +local head = r:peek(math.min(r:remaining(), 4096)) + if #head < 2 or string.find(head, "[%z\1-\8\14-\31]") then + return 0 + end + if string.sub(head, 1, 3) == "\239\187\191" then + head = string.sub(head, 4) + end + local s = head + local game = false + while true do + local c = string.match(s, "^%s*//[^\n]*\n?()") + if not c then + break + end + if string.match(s, "^%s*//%s*Game:") then + game = true + end + s = string.sub(s, c ) + end + local body = string.match(s, '^%s*{%s*"[^"\n]*"%s*"') or string.match(s, "^%s*{%s*{%s*[%(bp]") + if not body then + return game and string.match(s, "^%s*{") and 0.6 or 0 + end + return (game or string.find(head, '"classname"', 1, true) )and 0.9 or 0.6 +end + +-- ------------------------------------------------------------------------------------------------ decode +local function variantOf(m) +local game = string.lower(m.game or "") + local fmt = string.lower(m.mapFormat or "") + local q2, valve, q3 = false, false, false + for _, e in __iter(m.entities) do + if e.keys.mapversion == "220" then + valve = true + end + for _, b in __iter(e.brushes) do + if b.type ~= "brush" then + q3 = true + end + for _, f in __iter(b.faces or {}) do + if f.u then + valve = true + elseif f.flags and #f.flags >= 3 then + q2 = true + end + end + end + end + if q3 or string.find(game, "quake 3") or string.find(game, "quake iii") or fmt == "quake3" or fmt == "quake3 (valve)" then + return "quake3" + end + if string.find(game, "quake 2") or string.find(game, "quake ii") or fmt == "quake2" or fmt == "quake2 (valve)" then + return "quake2" + end + if valve or fmt == "valve" then + return "valve220" + end + return q2 and"quake2" or"quake" +end + +local function sizer(m, variant, opts) +local cache= {} + local wads= nil + local function loadWads() +local list = {} + local ws = m.entities[1] and m.entities[1].keys + local spec = ws and (ws.wad or ws._wad) or "" + for path in __iter(string.gmatch(spec, "[^;]+")) do + local p = string.gsub(path, "\\", "/") + local b = Input.sibling(opts, p) or Input.sibling(opts, string.match(p, "([^/]+)$") or p) + if b then + local lumps = Miptex.wad(b, 0, buffer.len(b)) + if lumps then + table.insert(list, { buf = b, lumps = lumps }) + end + end + end + return list + end + return function(name) +local c = cache[name] + if c then + return c[1], c[2], c[3] == 1 + end + local w, h= 0, 0 + local given = opts and opts.textureSizes and opts.textureSizes[name] + if type(given) == "table" and type(given[1]) == "number" and type(given[2]) == "number" then + w, h = given[1] , given[2] +elseif variant == "quake" or variant == "valve220" then + wads = wads or loadWads() + for i = #(wads ), 1, -1 do + local wd = (wads )[i] + local l = Miptex.find(wd.lumps, name) + if l then + local hd = Miptex.header(wd.buf, l.offset, l.disksize) + if hd then + w, h = hd.width, hd.height + break + end + end + end + elseif variant == "quake2" then + local wal = Input.sibling(opts, "textures/" .. name .. ".wal") + if wal and buffer.len(wal) >= 40 then + w, h = buffer.readu32(wal, 32), buffer.readu32(wal, 36) + end + elseif opts and opts.decodeImage then + for _, ext in __iter({ ".tga", ".jpg", ".png" }) do + local b = Input.sibling(opts, "textures/" .. name .. ext) + if b then + local ok, img = pcall(opts.decodeImage , b) + if ok and img then + w, h = img.width, img.height + break + end + end + end + end + local fw, fh= w , h +local known = fw > 0 and fh > 0 + if not known then + fw, fh = 64, 64 + end + cache[name] = { fw, fh, known and 1 or 0 } + return fw, fh, known + end +end + +function Map.decode(r, opts) +local text = buffer.readstring(r.buf, r.base, r.limit - r.base) + local m, msg, at = Parse.parse(text, opts and opts.maxBrushes) + if not m then + return nil, Err.from(msg, at) + end + if #m.entities == 0 then + return nil, Err.new(Err.CORRUPT, "no entities", 0) + end + local variant = variantOf(m) + local scene, err = Build.scene(m, { + variant = variant, + size = sizer(m, variant, opts), + hull = opts and opts.hull, + merge = opts and opts.merge, + epsilon = opts and opts.epsilon, + patchLevel = opts and opts.patchLevel, + skip = opts and opts.skip, + maxPolygons = opts and opts.maxPolygons, + }) + if not scene then + return nil, Err.from(err) + end + local counts = scene.meta.counts + scene.meta.counts = nil + scene.meta.source = { format = "map", variant = variant, game = m.game, mapFormat = m.mapFormat, entities = #m.entities, brushes = counts.brushes, patches = counts.patches } + return scene, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +local function toValve(f) +if f.u or f.matrix then + return f + end + local bf = Build.face(f) + if not bf or not bf.vecs then + return f + end + local v = bf.vecs + local out = table.clone(f) + out.offset = nil + out.u, out.v = { v[1][1], v[1][2], v[1][3], v[1][4] }, { v[2][1], v[2][2], v[2][3], v[2][4] } + out.rotation, out.scale = 0, { 1, 1 } + return out +end + +local function fmtNum(x) +return Write.num(x) +end + +function Map.encode(scene, opts) +if type(scene) ~= "table" or type(scene.nodes) ~= "table" then + return nil, Err.new(Err.ARG, "expected a Scene") + end + local valve = opts and opts.variant == "valve220" + local ents= {} + for _, node in __iter(scene.nodes) do + local ex= node.extras + if type(ex) == "table" and type(ex.keys) == "table" then + local keys = ex.keys + local brushes= (type(ex.brushes) == "table" and{ex.brushes }or{{} +})[1] if node.translation and keys.origin and #brushes == 0 then + local t = node.translation + keys = Types.object(table.clone(keys), Types.keys(keys)) + keys.origin = fmtNum(t[1]) .. " " .. fmtNum(t[2]) .. " " .. fmtNum(t[3]) + end + if valve then + local conv= {} + for _, b in __iter(brushes) do + if b.faces then + local nb = table.clone(b) + local faces = {} + for i, f in __iter(b.faces) do + faces[i] = toValve(f) + end + nb.faces = faces + table.insert(conv, nb) + else + table.insert(conv, b) + end + end + brushes = conv + if #ents == 0 and keys.mapversion ~= "220" then + keys = Types.object(table.clone(keys), Types.keys(keys)) + Types.set(keys, "mapversion", "220") + end + end + table.insert(ents, { keys = keys, brushes = brushes }) + end + end + if #ents == 0 then + return nil, Err.new(Err.ARG, "no map entities (nodes with extras.keys, as model/map loads them)") + end + local src= scene.meta and scene.meta.source + local fromMap = type(src) == "table" and src.format == "map" + local text, err = Write.text({ + entities = ents , + game = (fromMap and{src.game }or{nil})[1], + mapFormat = valve and"Valve" or(fromMap and{src.mapFormat }or{nil})[1], + comments = {}, + }) + if not text then + return nil, Err.new(Err.ARG, err or "bad entity") + end + return buffer.fromstring(text), nil +end + +-- ------------------------------------------------------------------------------------------------ extras +-- the entities as parsed: { entities = { { keys, brushes } }, game, mapFormat } +function Map.parse(src) +local text = (type(src) == "buffer" and{(buffer.tostring(src) )}or{(type(src) == "string" and{src }or{nil +})[1]})[1] if not text then + return nil, Err.new(Err.ARG, "expected a buffer or a string") + end + local m, msg, at = Parse.parse(text) + if not m then + return nil, Err.from(msg, at) + end + return m, nil +end + +function Map.write(m) +if type(m) ~= "table" or type(m.entities) ~= "table" then + return nil, Err.new(Err.ARG, "expected { entities = ... }") + end + local text, err = Write.text(m) + if not text then + return nil, Err.new(Err.ARG, err or "bad entity") + end + return text, nil +end + +-- a parsed face -> its Brush face (plane and projection): Brush.uv / Brush.polygons take it +function Map.face(f) +return Build.face(f) +end + +return Map +end +__FILES["model/map/Build"] = function() +local __compat = __compat local buffer, type, __iter = __compat.buffer, __compat.type, __compat.__iter --!strict +-- model/map/Build: parsed entities -> Scene: brushes through codecs/model/Brush, patches through codecs/model/Patch, +-- a mesh per entity with brushes, a primitive per texture, entities as nodes (keys in extras), z up, map units. +local Types = __include("Types") +local Brush = __include("codecs/model/Brush") +local Patch = __include("codecs/model/Patch") +local Parse = __include("model/map/Parse") + +local Build = {} + +local Scene = Types.Scene +local writef32, writeu32 = buffer.writef32, buffer.writeu32 + + + + + + + + + + + + +function Build.face(f) +local p = f.points + 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 out= { plane = plane, texture = f.texture } + if f.matrix then + out.bp = f.matrix + elseif f.u and f.v then + local sc = f.scale or { 1, 1 } + out.vecs = Brush.valveVecs(f.u, f.v, sc[1], sc[2]) + else + local o, sc = f.offset or { 0, 0 }, f.scale or { 1, 1 } + out.vecs = Brush.quakeVecs(plane, o[1], o[2], f.rotation or 0, sc[1], sc[2]) + end + return out +end + + + +local function patchPrim(b, level, acc) +local size, pts = b.size , b.points +local w, h= size[1] , size[2] +if not Patch.valid(w, h, math.floor(#pts / 5)) then + return false + end + -- file order is column by column (q3map2 ParsePatch: verts[i * width + j] for column j, point i) + local ctrl = (table.create(w * h * 5, 0) ) +for j = 0, w - 1 do + for i = 0, h - 1 do + table.move(pts, (j * h + i) * 5 + 1, (j * h + i) * 5 + 5, (i * w + j) * 5 + 1, ctrl) + end + end + local params= b.params or {} + local explicit = b.type == "patchDef3" + local lu= (explicit and{(math.max(1, params[1] or 1) )}or{level +})[1] local lv= (explicit and{(math.max(1, params[2] or 1) )}or{level +})[1] local g, gw, gh = Patch.grid(ctrl, w, h, 5, lu, lv) + if not g then + return false + end + local nrm = Patch.normals(g, 5, gw, gh) + local base = math.floor(#acc.pos / 3 +) for k = 0, gw * gh - 1 do + local o = k * 5 + table.insert(acc.pos, g[o + 1]) + table.insert(acc.pos, g[o + 2]) + table.insert(acc.pos, g[o + 3]) + table.insert(acc.uv, g[o + 4]) + table.insert(acc.uv, g[o + 5]) + table.insert(acc.nrm, nrm[k * 3 + 1]) + table.insert(acc.nrm, nrm[k * 3 + 2]) + table.insert(acc.nrm, nrm[k * 3 + 3]) + end + for _, v in __iter(Patch.triangles(gw, gh)) do + table.insert(acc.idx, base + v) + end + return true +end + +local function primitive(a) +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 + return { + attributes = { POSITION = Scene.accessor(pb, "f32", 3, nv), NORMAL = Scene.accessor(nb, "f32", 3, nv), TEXCOORD_0 = Scene.accessor(ub, "f32", 2, nv) }, + indices = Scene.accessor(ib, "u32", 1, ni), + mode = "triangles", + } +end + +local function vec3(s) +if not s then + return nil + end + local x, y, z = string.match(s, "^%s*(%S+)%s+(%S+)%s+(%S+)") + local a, b, c = tonumber(x), tonumber(y), tonumber(z) + if a and b and c then + return { a, b, c } + end + return nil +end + +function Build.scene(map, o) +local scene = Scene.new() + scene.meta.up = "z" + local skip= {} + for _, n in __iter(o.skip or {}) do + skip[string.lower(n)] = true + end + local matOf= {} + local function material(name) +local m = matOf[name] + if m then + return m + end + local w, h, known = o.size(name) + local uri = name + if o.variant == "quake2" then + uri = "textures/" .. name .. ".wal" + elseif o.variant == "quake3" then + uri = "textures/" .. name + end + table.insert(scene.textures, { name = name, uri = uri }) + local mat = Scene.material(name) + mat.metallic = 0 + mat.baseColorTexture = { texture = #scene.textures } + mat.extras = { map = { width = w, height = h, sizeKnown = known } } + table.insert(scene.materials, mat) + matOf[name] = #scene.materials + return #scene.materials + end + local root= { name = "map", children = {} } + table.insert(scene.nodes, root) + scene.roots[1] = 1 + local skipped = { faces = 0, patches = 0 } + local counts = { brushes = 0, patches = 0 } + local entities= {} + local polyTotal = 0 + for ei, ent in __iter(map.entities) do + local keys = ent.keys + table.insert(entities, keys) + local node= { name = keys.targetname or keys.classname or ("entity " .. (ei - 1)), children = {}, + extras = { classname = keys.classname, keys = keys, brushes = ent.brushes, entity = ei - 1 } } + local brushes= {} + local patchAcc= {} + local patchOrder= {} + for _, b in __iter(ent.brushes) do + if b.faces then + counts.brushes =counts.brushes+ 1 + local faces= {} + for _, f in __iter(b.faces) do + local bf = Build.face(f) + if bf then + table.insert(faces, bf) + else + skipped.faces =skipped.faces+ 1 + end + end + table.insert(brushes, faces) + else + counts.patches =counts.patches+ 1 + local tex = b.texture or "" + if not skip[string.lower(tex)] then + local acc = patchAcc[tex] + if not acc then + acc = { pos = {}, nrm = {}, uv = {}, idx = {} } + patchAcc[tex] = acc + table.insert(patchOrder, tex) + end + if not patchPrim(b, o.patchLevel or 4, acc ) then + skipped.patches =skipped.patches+ 1 + end + end + end + end + local prims= {} + if #brushes > 0 then + local polys, err = Brush.polygons(brushes, { hull = o.hull, merge = o.merge, epsilon = o.epsilon, maxPolygons = o.maxPolygons }) + if not polys then + return nil, err + end + polyTotal =polyTotal+ #polys + if polyTotal > (o.maxPolygons or 2 ^ 20) then + return nil, "limit: too many polygons" + end + local kept= {} + for _, p in __iter(polys) do + local t = brushes[p.brush][p.face].texture or "" + if not skip[string.lower(t)] then + table.insert(kept, p) + end + end + local built = Brush.primitives(kept, brushes, function(name) +local m = scene.materials[material(name)] + local e = (m.extras ).map + return e.width, e.height + end) + for _, bt in __iter(built) do + bt.primitive.material = material(bt.texture) + table.insert(prims, bt.primitive) + end + end + for _, tex in __iter(patchOrder) do + local acc = patchAcc[tex] + if #acc.idx > 0 then + local prim = primitive(acc) + prim.material = material(tex) + table.insert(prims, prim) + end + end + if #prims > 0 then + table.insert(scene.meshes, { name = node.name, primitives = prims }) + node.mesh = #scene.meshes + elseif #ent.brushes == 0 then + node.translation = vec3(keys.origin) + end + table.insert(scene.nodes, node) + table.insert(root.children, #scene.nodes) + end + scene.meta.entities = entities + scene.meta.skipped = skipped + scene.meta.counts = counts + return scene, nil +end + +return Build +end +__FILES["model/map/Parse"] = function() +local __compat = __compat local type, __iter = __compat.type, __compat.__iter --!strict +-- model/map/Parse: .map text -> entities (key / value pairs in order, brushes and patches as written). Grammar of the +-- Quake / Quake II / Half-Life (Valve 220) / Quake III editors (qbsp / q3map2 map parsers; no code taken). +local Types = __include("Types") + +local Parse = {} + + + + + + + + + + + + + + + + + + + + + + + + + +local function skip(st) + local s = st.s + while true do + local p = string.find(s, "[^%s]", st.pos) + if not p then + st.pos = st.n + 1 + return + end + if string.sub(s, p, p + 1) == "//" then + local e = string.find(s, "\n", p, true) or st.n + table.insert(st.comments, (string.gsub(string.sub(s, p + 2, e), "^%s*(.-)%s*$", "%1"))) + st.pos = e + 1 + else + st.pos = p + return + end + end +end + +local function peek(st) +skip(st) + return string.sub(st.s, st.pos, st.pos) +end + +local function expect(st, c) +if peek(st) ~= c then + return "expected '" .. c .. "' at " .. (st.pos - 1) + end + st.pos =st.pos+ 1 + return nil +end + +local function word(st) +skip(st) + local a, b = string.find(st.s, "^[^%s]+", st.pos) + if not a then + return nil + end + st.pos = (b ) + 1 + return string.sub(st.s, a, b) +end + +local function number(st) +skip(st) + local a, b = string.find(st.s, "^[^%s%(%)%[%]{}]+", st.pos) + if not a then + return nil + end + local v = tonumber(string.sub(st.s, a, b)) + if v then + st.pos = (b ) + 1 + end + return v +end + +local function quoted(st) +if peek(st) ~= '"' then + return nil + end + local e = string.find(st.s, '"', st.pos + 1, true) + if not e then + return nil + end + local v = string.sub(st.s, st.pos + 1, e - 1) + st.pos = e + 1 + return v +end + +local function numbers(st, n, out) +for _ = 1, n do + local v = number(st) + if not v then + return "expected a number at " .. (st.pos - 1) + end + table.insert(out, v) + end + return nil +end + +local function vec(st, n, open, close) +local e = expect(st, open) + if e then + return nil, e + end + local out = {} + e = numbers(st, n, out) + if e then + return nil, e + end + e = expect(st, close) + if e then + return nil, e + end + return out, nil +end + +local function trailing(st) +local out= {} + while true do + local c = peek(st) + if not string.match(c, "[%d%-%+%.]") then + break + end + local v = number(st) + if not v then + break + end + table.insert(out, v) + end + return (#out > 0 and{out }or{nil +})[1]end + +local function plane(st) +local pts= {} + for _ = 1, 3 do + local p, e = vec(st, 3, "(", ")") + if not p then + return nil, e + end + table.move(p, 1, 3, #pts + 1, pts) + end + return pts, nil +end + +local function face(st, bp) +local pts, e = plane(st) + if not pts then + return nil, e + end + local f= { points = pts, texture = "" } + if bp then + e = expect(st, "(") + if e then + return nil, e + end + local r1, e1 = vec(st, 3, "(", ")") + if not r1 then + return nil, e1 + end + local r2, e2 = vec(st, 3, "(", ")") + if not r2 then + return nil, e2 + end + e = expect(st, ")") + if e then + return nil, e + end + f.matrix = { r1, r2 } + end + local tex = word(st) + if not tex then + return nil, "expected a texture name at " .. (st.pos - 1) + end + f.texture = tex + if not bp then + if peek(st) == "[" then + local u, eu = vec(st, 4, "[", "]") + if not u then + return nil, eu + end + local v, ev = vec(st, 4, "[", "]") + if not v then + return nil, ev + end + local rest = {} + e = numbers(st, 3, rest) + if e then + return nil, e + end + f.u, f.v, f.rotation, f.scale = u, v, rest[1], { rest[2], rest[3] } + else + local rest = {} + e = numbers(st, 5, rest) + if e then + return nil, e + end + f.offset, f.rotation, f.scale = { rest[1], rest[2] }, rest[3], { rest[4], rest[5] } + end + end + f.flags = trailing(st) + return f, nil +end + +local function patch(st, kind, maxPoints) +local e = expect(st, "{") + if e then + return nil, e + end + local tex = word(st) + if not tex then + return nil, "expected a patch texture" + end + local hn = kind == "patchDef3" and 7 or 5 + local head, eh = vec(st, hn, "(", ")") + if not head then + return nil, eh + end + local w, h = head[1], head[2] + if w ~= math.floor(w) or h ~= math.floor(h) or w < 1 or h < 1 or w * h > maxPoints then + return nil, "bad patch size " .. w .. " x " .. h + end + local pts= {} + e = expect(st, "(") + if e then + return nil, e + end + for _ = 1, w do + e = expect(st, "(") + if e then + return nil, e + end + for _ = 1, h do + local p, ep = vec(st, 5, "(", ")") + if not p then + return nil, ep + end + table.move(p, 1, 5, #pts + 1, pts) + end + e = expect(st, ")") + if e then + return nil, e + end + end + e = expect(st, ")") + if e then + return nil, e + end + e = expect(st, "}") + if e then + return nil, e + end + return { type = kind, texture = tex, size = { w, h }, params = { table.unpack(head, 3) }, points = pts }, nil +end + +local function brush(st, maxPoints) +local c = peek(st) + if c == "(" then + local faces= {} + while peek(st) == "(" do + local f, e = face(st, false) + if not f then + return nil, e + end + table.insert(faces, f) + end + local e = expect(st, "}") + if e then + return nil, e + end + return { type = "brush", faces = faces }, nil + end + if c == "}" then + st.pos =st.pos+ 1 + return { type = "brush", faces = {} }, nil + end + local kw = word(st) + local out, err +if kw == "brushDef" then + local e = expect(st, "{") + if e then + return nil, e + end + local faces= {} + while peek(st) == "(" do + local f, ef = face(st, true) + if not f then + return nil, ef + end + table.insert(faces, f) + end + e = expect(st, "}") + if e then + return nil, e + end + out = { type = "brushDef", faces = faces } + elseif kw == "patchDef2" or kw == "patchDef3" then + out, err = patch(st, kw, maxPoints) + if not out then + return nil, err + end + elseif kw == "brushDef3" then + return nil, "unsupported: Doom 3 / Quake 4 brushDef3" + else + return nil, "unexpected '" .. tostring(kw) .. "' in a brush at " .. (st.pos - 1) + end + local e = expect(st, "}") + if e then + return nil, e + end + return out, nil +end + +function Parse.parse(s, maxBrushes) +local st= { s = s, pos = 1, n = #s, comments = {} } + if string.sub(s, 1, 3) == "\239\187\191" then + st.pos = 4 + end + local limit = maxBrushes or 2 ^ 20 + local count = 0 + local ents= {} + while peek(st) ~= "" do + local at = st.pos - 1 + local e = expect(st, "{") + if e then + return nil, e, at + end + local keys= {} + local order= {} + local brushes= {} + while true do + local c = peek(st) + if c == "}" then + st.pos =st.pos+ 1 + break + elseif c == '"' then + local k = quoted(st) + local v = quoted(st) + if not k or not v then + return nil, "bad key / value at " .. (st.pos - 1), st.pos - 1 + end + if keys[k] == nil then + table.insert(order, k) + end + keys[k] = v + elseif c == "{" then + st.pos =st.pos+ 1 + local b, eb = brush(st, limit) + if not b then + return nil, eb, st.pos - 1 + end + count =count+ 1 + if count > limit then + return nil, "limit: too many brushes", st.pos - 1 + end + table.insert(brushes, b) + elseif c == "" then + return nil, "truncated entity", st.pos - 1 + else + return nil, "unexpected '" .. c .. "' in an entity at " .. (st.pos - 1), st.pos - 1 + end + end + table.insert(ents, { keys = (Types.object(keys, order) ), brushes = brushes }) + end + local game, fmt + for _, c in __iter(st.comments) do + game = game or string.match(c, "^Game:%s*(.-)%s*$") + fmt = fmt or string.match(c, "^Format:%s*(.-)%s*$") + end + return { entities = ents, game = game, mapFormat = fmt, comments = st.comments }, nil, nil +end + +return Parse +end +__FILES["model/map/Write"] = function() +local __compat = __compat local type, __iter = __compat.type, __compat.__iter --!strict +-- model/map/Write: entities (model/map/Parse's layout) -> .map text in the editors' layout (TrenchBroom / Radiant: +-- one face per line, numbers in their shortest exact form). +local Types = __include("Types") +local Parse = __include("model/map/Parse") + +local Write = {} + +function Write.num(x) +if x ~= x or x == math.huge or x == -math.huge then + return "0" + end + if x == math.floor(x) and math.abs(x) < 2 ^ 53 then + return string.format("%d", x) + end + for p = 6, 17 do + local s = string.format("%." .. p .. "g", x) + if tonumber(s) == x then + return s + end + end + return string.format("%.17g", x) +end + +local function nums(t, a, b) +local out = (table.create(b - a + 1) ) +for i = a, b do + out[#out + 1] = Write.num(t[i] or 0) + end + return table.concat(out, " ") +end + +local function faceLine(f, bp) +local p = f.points + if type(p) ~= "table" or #p < 9 or type(f.texture) ~= "string" or f.texture == "" or string.find(f.texture, "%s") then + return nil, "a face needs 9 point numbers and a texture name without spaces" + end + local parts= { "( " .. nums(p, 1, 3) .. " ) ( " .. nums(p, 4, 6) .. " ) ( " .. nums(p, 7, 9) .. " )" } + if bp then + local m = f.matrix + if not m or not m[1] or not m[2] then + return nil, "a brushDef face needs a texture matrix" + end + table.insert(parts, "( ( " .. nums(m[1], 1, 3) .. " ) ( " .. nums(m[2], 1, 3) .. " ) )") + table.insert(parts, f.texture) + elseif f.u and f.v then + local sc = f.scale or { 1, 1 } + table.insert(parts, f.texture) + table.insert(parts, "[ " .. nums(f.u, 1, 4) .. " ] [ " .. nums(f.v, 1, 4) .. " ] " .. Write.num(f.rotation or 0) .. " " .. nums(sc, 1, 2)) + else + local o, sc = f.offset or { 0, 0 }, f.scale or { 1, 1 } + table.insert(parts, f.texture) + table.insert(parts, nums(o, 1, 2) .. " " .. Write.num(f.rotation or 0) .. " " .. nums(sc, 1, 2)) + end + if f.flags and #f.flags > 0 then + table.insert(parts, nums(f.flags, 1, #f.flags)) + end + return table.concat(parts, " "), nil +end + +local function patchText(b, out) +local size, pts = b.size, b.points + if not size or not pts or type(b.texture) ~= "string" then + return "a patch needs a texture, a size and control points" + end + local w, h = size[1], size[2] + if #pts < w * h * 5 then + return "a patch needs width * height * 5 control numbers" + end + local params = b.params or {} + local nParams = b.type == "patchDef3" and 5 or 3 + table.insert(out, b.type) + table.insert(out, "{") + table.insert(out, b.texture) + table.insert(out, "( " .. Write.num(w) .. " " .. Write.num(h) .. " " .. nums(params, 1, nParams) .. " )") + table.insert(out, "(") + for i = 0, w - 1 do + local row = { "(" } + for j = 0, h - 1 do + local o = (i * h + j) * 5 + table.insert(row, "( " .. nums(pts, o + 1, o + 5) .. " )") + end + table.insert(row, ")") + table.insert(out, table.concat(row, " ")) + end + table.insert(out, ")") + table.insert(out, "}") + return nil +end + +function Write.text(map) +local out= {} + if map.game then + table.insert(out, "// Game: " .. map.game) + end + if map.mapFormat then + table.insert(out, "// Format: " .. map.mapFormat) + end + for ei, ent in __iter(map.entities) do + table.insert(out, "// entity " .. (ei - 1)) + table.insert(out, "{") + for _, k in __iter(Types.keys(ent.keys)) do + local v = ent.keys[k] + if v ~= nil then + if string.find(k, '"', 1, true) or string.find(tostring(v), '"', 1, true) or string.find(k, "[\r\n]") or string.find(tostring(v), "[\r\n]") then + return nil, "keys and values cannot hold quotes or line breaks: " .. k + end + table.insert(out, '"' .. k .. '" "' .. tostring(v) .. '"') + end + end + for bi, b in __iter(ent.brushes or {}) do + table.insert(out, "// brush " .. (bi - 1)) + table.insert(out, "{") + if b.type == "patchDef2" or b.type == "patchDef3" then + local e = patchText(b, out) + if e then + return nil, e + end + else + local bp = b.type == "brushDef" + if bp then + table.insert(out, "brushDef") + table.insert(out, "{") + end + for _, f in __iter(b.faces or {}) do + local line, e = faceLine(f, bp) + if not line then + return nil, e + end + table.insert(out, line) + end + if bp then + table.insert(out, "}") + end + end + table.insert(out, "}") + end + table.insert(out, "}") + end + table.insert(out, "") + return table.concat(out, "\n"), nil +end + +return Write +end __FILES["model/mca"] = function() local __compat = __compat local buffer, bit32, type, __iter = __compat.buffer, __compat.bit32, __compat.type, __compat.__iter --!strict -- model/mca: Minecraft Anvil region files (wiki "Region file format", "Chunk format"), read-only. Supports: gzip, zlib, diff --git a/build/rosetta.lua.linemap.json b/build/rosetta.lua.linemap.json index 29c4448..177aeaa 100644 --- a/build/rosetta.lua.linemap.json +++ b/build/rosetta.lua.linemap.json @@ -1,546 +1,553 @@ [ [660, "src/Rosetta/init.luau"], [1504, "src/Rosetta/Registry.luau"], -[3661, "src/Rosetta/Types.luau"], -[4744, "src/Rosetta/archive/7z/init.luau"], -[5129, "src/Rosetta/archive/7z/Header.luau"], -[5656, "src/Rosetta/archive/adf/init.luau"], -[5938, "src/Rosetta/archive/applesingle/init.luau"], -[6124, "src/Rosetta/archive/ar/init.luau"], -[6527, "src/Rosetta/archive/arj/init.luau"], -[6737, "src/Rosetta/archive/binhex/init.luau"], -[6986, "src/Rosetta/archive/br/init.luau"], -[7061, "src/Rosetta/archive/bz2/init.luau"], -[7125, "src/Rosetta/archive/cab/init.luau"], -[7538, "src/Rosetta/archive/cab/Sum.luau"], -[7579, "src/Rosetta/archive/cpio/init.luau"], -[7747, "src/Rosetta/archive/d64/init.luau"], -[8161, "src/Rosetta/archive/fat/init.luau"], -[8283, "src/Rosetta/archive/grp/init.luau"], -[8397, "src/Rosetta/archive/gzip/init.luau"], -[8582, "src/Rosetta/archive/iso/init.luau"], -[8654, "src/Rosetta/archive/lha/init.luau"], -[9079, "src/Rosetta/archive/lz4/init.luau"], -[9423, "src/Rosetta/archive/macbinary/init.luau"], -[9621, "src/Rosetta/archive/mpq/init.luau"], -[10027, "src/Rosetta/archive/mpq/Crypt.luau"], -[10092, "src/Rosetta/archive/pak/init.luau"], -[10226, "src/Rosetta/archive/rpm/init.luau"], -[10550, "src/Rosetta/archive/tar/init.luau"], -[10668, "src/Rosetta/archive/uu/init.luau"], -[10938, "src/Rosetta/archive/vpk/init.luau"], -[11249, "src/Rosetta/archive/vswap/init.luau"], -[11519, "src/Rosetta/archive/wad/init.luau"], -[11973, "src/Rosetta/archive/wad/Picture.luau"], -[12075, "src/Rosetta/archive/xz/init.luau"], -[12175, "src/Rosetta/archive/yenc/init.luau"], -[12447, "src/Rosetta/archive/z/init.luau"], -[12543, "src/Rosetta/archive/zip/init.luau"], -[12762, "src/Rosetta/archive/zoo/init.luau"], -[12958, "src/Rosetta/archive/zst/init.luau"], -[13022, "src/Rosetta/audio/aac/init.luau"], -[13228, "src/Rosetta/audio/ac3/init.luau"], -[13374, "src/Rosetta/audio/adpcm/init.luau"], -[13519, "src/Rosetta/audio/adx/init.luau"], -[13750, "src/Rosetta/audio/aiff/init.luau"], -[14141, "src/Rosetta/audio/ape/init.luau"], -[14269, "src/Rosetta/audio/au/init.luau"], -[14430, "src/Rosetta/audio/brstm/init.luau"], -[14721, "src/Rosetta/audio/caf/init.luau"], -[15383, "src/Rosetta/audio/flac/init.luau"], -[15531, "src/Rosetta/audio/flac/Meta.luau"], -[15753, "src/Rosetta/audio/flac/Stream.luau"], -[16123, "src/Rosetta/audio/m4a/init.luau"], -[16457, "src/Rosetta/audio/mp3/init.luau"], -[16717, "src/Rosetta/audio/mp3/Index.luau"], -[16908, "src/Rosetta/audio/mp3/Stream.luau"], -[17135, "src/Rosetta/audio/mp3/Tags.luau"], -[17447, "src/Rosetta/audio/mpc/init.luau"], -[17541, "src/Rosetta/audio/opus/init.luau"], -[17919, "src/Rosetta/audio/opus/Encode.luau"], -[18030, "src/Rosetta/audio/qoa/init.luau"], -[18210, "src/Rosetta/audio/tta/init.luau"], -[18328, "src/Rosetta/audio/vag/init.luau"], -[18551, "src/Rosetta/audio/voc/init.luau"], -[18826, "src/Rosetta/audio/vorbis/init.luau"], -[19280, "src/Rosetta/audio/vorbis/Encode.luau"], -[20093, "src/Rosetta/audio/wav/init.luau"], -[20714, "src/Rosetta/audio/wav/Codecs.luau"], -[20880, "src/Rosetta/audio/wavpack/init.luau"], -[21087, "src/Rosetta/cad/step/init.luau"], -[21469, "src/Rosetta/cad/step/Brep.luau"], -[21704, "src/Rosetta/cad/step/Parse.luau"], -[22261, "src/Rosetta/cad/step/Write.luau"], -[22509, "src/Rosetta/codecs/audio/Aac/init.luau"], -[22828, "src/Rosetta/codecs/audio/Aac/Decode.luau"], -[23711, "src/Rosetta/codecs/audio/Aac/Tables.luau"], -[24046, "src/Rosetta/codecs/audio/Ac3/init.luau"], -[24205, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], -[25090, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], -[25191, "src/Rosetta/codecs/audio/Adpcm/init.luau"], -[25945, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], -[26247, "src/Rosetta/codecs/audio/Alac/init.luau"], -[26481, "src/Rosetta/codecs/audio/Alac/Decode.luau"], -[26900, "src/Rosetta/codecs/audio/Alac/Encode.luau"], -[27312, "src/Rosetta/codecs/audio/Ape/init.luau"], -[27527, "src/Rosetta/codecs/audio/Ape/Decode.luau"], -[28288, "src/Rosetta/codecs/audio/ApeTag.luau"], -[28385, "src/Rosetta/codecs/audio/Flac/init.luau"], -[28396, "src/Rosetta/codecs/audio/Flac/Encode.luau"], -[29345, "src/Rosetta/codecs/audio/Flac/Frame.luau"], -[29942, "src/Rosetta/codecs/audio/Hively/init.luau"], -[30138, "src/Rosetta/codecs/audio/Hively/Load.luau"], -[30387, "src/Rosetta/codecs/audio/Hively/Player.luau"], -[31345, "src/Rosetta/codecs/audio/Hively/Tables.luau"], -[31564, "src/Rosetta/codecs/audio/Mdct/init.luau"], -[31748, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], -[31957, "src/Rosetta/codecs/audio/MidiRender.luau"], -[32303, "src/Rosetta/codecs/audio/Mpa/init.luau"], -[32317, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], -[32376, "src/Rosetta/codecs/audio/Mpa/Core.luau"], -[33979, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], -[34271, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], -[34656, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], -[35297, "src/Rosetta/codecs/audio/Mpa/Header.luau"], -[35438, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], -[35664, "src/Rosetta/codecs/audio/Musepack/init.luau"], -[36009, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], -[36890, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], -[37268, "src/Rosetta/codecs/audio/Opus/init.luau"], -[37282, "src/Rosetta/codecs/audio/Opus/Celt.luau"], -[39129, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], -[40194, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], -[40254, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], -[40714, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], -[41051, "src/Rosetta/codecs/audio/Opus/Packet.luau"], -[41284, "src/Rosetta/codecs/audio/Opus/Silk.luau"], -[43320, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], -[43694, "src/Rosetta/codecs/audio/Pcm/init.luau"], -[43957, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], -[44254, "src/Rosetta/codecs/audio/Qoa/init.luau"], -[44536, "src/Rosetta/codecs/audio/Resample/init.luau"], -[44895, "src/Rosetta/codecs/audio/SoundFont/init.luau"], -[44949, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], -[45092, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], -[45605, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], -[46386, "src/Rosetta/codecs/audio/Stream.luau"], -[46547, "src/Rosetta/codecs/audio/Tracker/init.luau"], -[47029, "src/Rosetta/codecs/audio/Tracker/Load.luau"], -[47307, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], -[47476, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], -[47604, "src/Rosetta/codecs/audio/Tracker/Player.luau"], -[49592, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], -[49708, "src/Rosetta/codecs/audio/Tta/init.luau"], -[49825, "src/Rosetta/codecs/audio/Tta/Decode.luau"], -[50077, "src/Rosetta/codecs/audio/Vorbis/init.luau"], -[50090, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], -[50474, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], -[51040, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], -[51461, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], -[51500, "src/Rosetta/codecs/audio/VorbisComment.luau"], -[51552, "src/Rosetta/codecs/audio/WavPack/init.luau"], -[51774, "src/Rosetta/codecs/audio/WavPack/Block.luau"], -[53229, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], -[53292, "src/Rosetta/codecs/compress/Brotli/init.luau"], -[53379, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], -[54348, "src/Rosetta/codecs/compress/Brotli/Static.luau"], -[55216, "src/Rosetta/codecs/compress/Bzip2/init.luau"], -[55264, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], -[55780, "src/Rosetta/codecs/compress/Deflate/init.luau"], -[56106, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], -[56526, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], -[56961, "src/Rosetta/codecs/compress/Explode.luau"], -[57157, "src/Rosetta/codecs/compress/Lz4.luau"], -[57426, "src/Rosetta/codecs/compress/Lzh/init.luau"], -[58030, "src/Rosetta/codecs/compress/Lzma/init.luau"], -[58570, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], -[58608, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], -[59081, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], -[59257, "src/Rosetta/codecs/compress/Lzw/init.luau"], -[59525, "src/Rosetta/codecs/compress/Lzx.luau"], -[59959, "src/Rosetta/codecs/compress/PackBits.luau"], -[60049, "src/Rosetta/codecs/compress/Quantum.luau"], -[60286, "src/Rosetta/codecs/compress/UnixCompress.luau"], -[60590, "src/Rosetta/codecs/compress/Xxh32.luau"], -[60659, "src/Rosetta/codecs/compress/Zstd/init.luau"], -[60716, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], -[61674, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], -[61826, "src/Rosetta/codecs/entropy/Huffman.luau"], -[62108, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], -[62119, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], -[62333, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], -[62577, "src/Rosetta/codecs/font/Bitmap.luau"], -[62778, "src/Rosetta/codecs/font/Cff/init.luau"], -[63419, "src/Rosetta/codecs/font/GlyphNames.luau"], -[63569, "src/Rosetta/codecs/font/TrueType/init.luau"], -[63883, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], -[64275, "src/Rosetta/codecs/font/TrueType/Tables.luau"], -[64777, "src/Rosetta/codecs/image/Bcn/init.luau"], -[64884, "src/Rosetta/codecs/image/Bcn/Decode.luau"], -[65373, "src/Rosetta/codecs/image/Bcn/Encode.luau"], -[65802, "src/Rosetta/codecs/image/Blend.luau"], -[66181, "src/Rosetta/codecs/image/Dct/init.luau"], -[66562, "src/Rosetta/codecs/image/Etc.luau"], -[66860, "src/Rosetta/codecs/image/Half.luau"], -[66929, "src/Rosetta/codecs/image/Jpeg/init.luau"], -[67283, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], -[67691, "src/Rosetta/codecs/image/Jpeg/Color.luau"], -[67928, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], -[68688, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], -[69569, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], -[70015, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], -[70093, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], -[70160, "src/Rosetta/codecs/image/Pixels.luau"], -[70424, "src/Rosetta/codecs/image/Quantize/init.luau"], -[70883, "src/Rosetta/codecs/image/Raster.luau"], -[71580, "src/Rosetta/codecs/image/Texel.luau"], -[71953, "src/Rosetta/codecs/image/Texture.luau"], -[72098, "src/Rosetta/codecs/image/Vp8/init.luau"], -[72228, "src/Rosetta/codecs/image/Vp8/Decode.luau"], -[74184, "src/Rosetta/codecs/image/Vp8/Predict.luau"], -[74443, "src/Rosetta/codecs/image/Vp8/Tables.luau"], -[74692, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], -[74811, "src/Rosetta/codecs/image/Vp8L/init.luau"], -[74915, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], -[75768, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], -[76720, "src/Rosetta/codecs/image/Yuv.luau"], -[76988, "src/Rosetta/codecs/model/DoomMap/init.luau"], -[77433, "src/Rosetta/codecs/model/DoomMap/Udmf.luau"], -[77683, "src/Rosetta/codecs/model/Draco/init.luau"], -[78015, "src/Rosetta/codecs/model/Draco/Attributes.luau"], -[78484, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], -[79673, "src/Rosetta/codecs/model/Draco/Int64.luau"], -[79822, "src/Rosetta/codecs/model/Draco/KdTree.luau"], -[80181, "src/Rosetta/codecs/model/Draco/Predict.luau"], -[81143, "src/Rosetta/codecs/model/Draco/Reader.luau"], -[81617, "src/Rosetta/codecs/model/Mat4.luau"], -[81876, "src/Rosetta/codecs/model/MeshFlatten.luau"], -[82404, "src/Rosetta/codecs/model/Minecraft/init.luau"], -[82956, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], -[83035, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], -[83142, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], -[83348, "src/Rosetta/codecs/model/Polygon.luau"], -[83582, "src/Rosetta/codecs/model/Rbx/init.luau"], -[83819, "src/Rosetta/codecs/model/Rbx/Binary.luau"], -[84573, "src/Rosetta/codecs/model/Rig.luau"], -[84816, "src/Rosetta/codecs/model/Sampler.luau"], -[84976, "src/Rosetta/codecs/model/Vrml/init.luau"], -[85124, "src/Rosetta/codecs/model/Vrml/Build.luau"], -[85698, "src/Rosetta/codecs/model/Vrml/Fields.luau"], -[85861, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], -[86610, "src/Rosetta/codecs/model/Vrml/Parse.luau"], -[87132, "src/Rosetta/codecs/model/Vrml/Write.luau"], -[87859, "src/Rosetta/codecs/model/Vrml/Xml.luau"], -[88091, "src/Rosetta/codecs/text/Json/init.luau"], -[88360, "src/Rosetta/codecs/text/Json/Decode.luau"], -[88774, "src/Rosetta/codecs/text/Json/Encode.luau"], -[89076, "src/Rosetta/codecs/text/Lexer/init.luau"], -[89208, "src/Rosetta/codecs/text/Nbt/init.luau"], -[89561, "src/Rosetta/codecs/text/Nbt/Binary.luau"], -[90253, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], -[90893, "src/Rosetta/codecs/text/Nbt/Value.luau"], -[91131, "src/Rosetta/codecs/text/Text/init.luau"], -[91222, "src/Rosetta/codecs/text/Url/init.luau"], -[91427, "src/Rosetta/codecs/text/Xml/init.luau"], -[91830, "src/Rosetta/codecs/text/Xml/Parse.luau"], -[92570, "src/Rosetta/codecs/video/Dsp.luau"], -[93293, "src/Rosetta/codecs/video/H263/init.luau"], -[93449, "src/Rosetta/codecs/video/H263/Decoder.luau"], -[94307, "src/Rosetta/codecs/video/H263/Tables.luau"], -[94510, "src/Rosetta/codecs/video/H264/init.luau"], -[94883, "src/Rosetta/codecs/video/H264/Bitstream.luau"], -[95158, "src/Rosetta/codecs/video/H264/Cabac.luau"], -[96289, "src/Rosetta/codecs/video/H264/Cavlc.luau"], -[97057, "src/Rosetta/codecs/video/H264/Deblock.luau"], -[97315, "src/Rosetta/codecs/video/H264/Decoder.luau"], -[98324, "src/Rosetta/codecs/video/H264/Inter.luau"], -[98578, "src/Rosetta/codecs/video/H264/Intra.luau"], -[98985, "src/Rosetta/codecs/video/H264/Mb.luau"], -[99891, "src/Rosetta/codecs/video/H264/Params.luau"], -[100338, "src/Rosetta/codecs/video/H264/Slice.luau"], -[100589, "src/Rosetta/codecs/video/H264/Tables.luau"], -[100630, "src/Rosetta/codecs/video/H264/Transform.luau"], -[100795, "src/Rosetta/codecs/video/Legacy/init.luau"], -[100993, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], -[101290, "src/Rosetta/codecs/video/Legacy/Flic.luau"], -[101657, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], -[101775, "src/Rosetta/codecs/video/Legacy/Picture.luau"], -[101883, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], -[102156, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], -[102551, "src/Rosetta/codecs/video/Legacy/Smc.luau"], -[102728, "src/Rosetta/codecs/video/Mpeg1/init.luau"], -[102740, "src/Rosetta/codecs/video/Mpeg2/init.luau"], -[103107, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], -[104614, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], -[104753, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], -[104891, "src/Rosetta/codecs/video/Theora/init.luau"], -[105154, "src/Rosetta/codecs/video/Theora/Decoder.luau"], -[106418, "src/Rosetta/codecs/video/Theora/Header.luau"], -[106781, "src/Rosetta/codecs/video/Video/init.luau"], -[107338, "src/Rosetta/codecs/video/Video/Source.luau"], -[107623, "src/Rosetta/containers/Archive.luau"], -[107890, "src/Rosetta/containers/AudioWrap.luau"], -[108393, "src/Rosetta/containers/Avi/init.luau"], -[108945, "src/Rosetta/containers/Chunks.luau"], -[109080, "src/Rosetta/containers/Cpio.luau"], -[109508, "src/Rosetta/containers/Demux.luau"], -[109783, "src/Rosetta/containers/Ebml/init.luau"], -[110096, "src/Rosetta/containers/Fat.luau"], -[110784, "src/Rosetta/containers/Iso9660.luau"], -[111289, "src/Rosetta/containers/IsoBmff/init.luau"], -[111459, "src/Rosetta/containers/IsoBmff/Box.luau"], -[111647, "src/Rosetta/containers/IsoBmff/Demux.luau"], -[112492, "src/Rosetta/containers/IsoBmff/Meta.luau"], -[113013, "src/Rosetta/containers/IsoBmff/Mux.luau"], -[113529, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], -[113646, "src/Rosetta/containers/MacFile.luau"], -[113795, "src/Rosetta/containers/MpegEs.luau"], -[113961, "src/Rosetta/containers/MpegPs/init.luau"], -[114181, "src/Rosetta/containers/MpegTs/init.luau"], -[114973, "src/Rosetta/containers/Ogg/init.luau"], -[115398, "src/Rosetta/containers/Ogg/Mux.luau"], -[115593, "src/Rosetta/containers/Ogg/Page.luau"], -[115762, "src/Rosetta/containers/Riff/init.luau"], -[116079, "src/Rosetta/containers/Tar.luau"], -[116493, "src/Rosetta/containers/Zip/init.luau"], -[117125, "src/Rosetta/core/Adler32.luau"], -[117171, "src/Rosetta/core/Base64.luau"], -[117330, "src/Rosetta/core/Bits.luau"], -[117623, "src/Rosetta/core/Bytes.luau"], -[118150, "src/Rosetta/core/Crc16.luau"], -[118202, "src/Rosetta/core/Crc32.luau"], -[118314, "src/Rosetta/core/Err.luau"], -[118396, "src/Rosetta/core/Input.luau"], -[118472, "src/Rosetta/core/Md5.luau"], -[118631, "src/Rosetta/core/Sniff.luau"], -[118660, "src/Rosetta/data/cbor/init.luau"], -[118759, "src/Rosetta/data/cbor/Codec.luau"], -[119328, "src/Rosetta/data/csv/init.luau"], -[119640, "src/Rosetta/data/ini/init.luau"], -[119886, "src/Rosetta/data/json/init.luau"], -[119978, "src/Rosetta/data/msgpack/init.luau"], -[120067, "src/Rosetta/data/msgpack/Codec.luau"], -[120509, "src/Rosetta/data/nbt/init.luau"], -[120568, "src/Rosetta/data/plist/init.luau"], -[120874, "src/Rosetta/data/plist/Binary.luau"], -[121141, "src/Rosetta/data/snbt/init.luau"], -[121204, "src/Rosetta/data/toml/init.luau"], -[121271, "src/Rosetta/data/toml/Decode.luau"], -[121899, "src/Rosetta/data/toml/Encode.luau"], -[122108, "src/Rosetta/data/xml/init.luau"], -[122164, "src/Rosetta/data/yaml/init.luau"], -[122237, "src/Rosetta/data/yaml/Emit.luau"], -[122527, "src/Rosetta/data/yaml/Parse.luau"], -[123820, "src/Rosetta/font/bdf/init.luau"], -[124109, "src/Rosetta/font/bmfont/init.luau"], -[124536, "src/Rosetta/font/bmfont/Parse.luau"], -[124989, "src/Rosetta/font/eot/init.luau"], -[125221, "src/Rosetta/font/fon/init.luau"], -[125504, "src/Rosetta/font/hershey/init.luau"], -[125699, "src/Rosetta/font/pcf/init.luau"], -[125979, "src/Rosetta/font/psf/init.luau"], -[126299, "src/Rosetta/font/ttf/init.luau"], -[126350, "src/Rosetta/font/type1/init.luau"], -[126709, "src/Rosetta/font/type1/Charstring.luau"], -[126987, "src/Rosetta/font/woff/init.luau"], -[127119, "src/Rosetta/font/woff2/init.luau"], -[127176, "src/Rosetta/font/woff2/Rebuild.luau"], -[127716, "src/Rosetta/host/init.luau"], -[127761, "src/Rosetta/host/Love.luau"], -[127904, "src/Rosetta/host/LuaJIT.luau"], -[127954, "src/Rosetta/host/Luau.luau"], -[127977, "src/Rosetta/host/Roblox.luau"], -[128336, "src/Rosetta/image/ani/init.luau"], -[128516, "src/Rosetta/image/blp/init.luau"], -[128774, "src/Rosetta/image/bmp/init.luau"], -[129189, "src/Rosetta/image/dds/init.luau"], -[129672, "src/Rosetta/image/exr/init.luau"], -[130432, "src/Rosetta/image/exr/Codec.luau"], -[130543, "src/Rosetta/image/exr/Piz.luau"], -[130900, "src/Rosetta/image/gif/init.luau"], -[131416, "src/Rosetta/image/gif/Decode.luau"], -[131479, "src/Rosetta/image/hdr/init.luau"], -[131708, "src/Rosetta/image/hdr/Codec.luau"], -[131919, "src/Rosetta/image/icns/init.luau"], -[132250, "src/Rosetta/image/ico/init.luau"], -[132527, "src/Rosetta/image/ico/Dib.luau"], -[132622, "src/Rosetta/image/ilbm/init.luau"], -[132941, "src/Rosetta/image/jpeg/init.luau"], -[133077, "src/Rosetta/image/ktx/init.luau"], -[133737, "src/Rosetta/image/pcx/init.luau"], -[134001, "src/Rosetta/image/png/init.luau"], -[134581, "src/Rosetta/image/png/Apng.luau"], -[134661, "src/Rosetta/image/png/Decode.luau"], -[134901, "src/Rosetta/image/png/Encode.luau"], -[135056, "src/Rosetta/image/pnm/init.luau"], -[135434, "src/Rosetta/image/pnm/Codec.luau"], -[135711, "src/Rosetta/image/qoi/init.luau"], -[135833, "src/Rosetta/image/qoi/Codec.luau"], -[135983, "src/Rosetta/image/sgi/init.luau"], -[136268, "src/Rosetta/image/sunras/init.luau"], -[136514, "src/Rosetta/image/tga/init.luau"], -[136784, "src/Rosetta/image/tga/Codec.luau"], -[136936, "src/Rosetta/image/tiff/init.luau"], -[137763, "src/Rosetta/image/tiff/Pixels.luau"], -[138153, "src/Rosetta/image/tim/init.luau"], -[138395, "src/Rosetta/image/vtf/init.luau"], -[138630, "src/Rosetta/image/webp/init.luau"], -[139240, "src/Rosetta/image/webp/Alpha.luau"], -[139316, "src/Rosetta/image/webp/Anim.luau"], -[139471, "src/Rosetta/image/xbm/init.luau"], -[139632, "src/Rosetta/image/xpm/init.luau"], -[139900, "src/Rosetta/image/xpm/Names.luau"], -[139956, "src/Rosetta/layered/aseprite/init.luau"], -[140694, "src/Rosetta/layered/ora/init.luau"], -[140981, "src/Rosetta/layered/psd/init.luau"], -[141716, "src/Rosetta/layered/psd/Channels.luau"], -[142068, "src/Rosetta/model/3ds/init.luau"], -[142151, "src/Rosetta/model/3ds/Build.luau"], -[142798, "src/Rosetta/model/3ds/Read.luau"], -[143294, "src/Rosetta/model/3ds/Write.luau"], -[144099, "src/Rosetta/model/3mf/init.luau"], -[144181, "src/Rosetta/model/3mf/Read.luau"], -[144769, "src/Rosetta/model/3mf/Write.luau"], -[145174, "src/Rosetta/model/b3d/init.luau"], -[145229, "src/Rosetta/model/b3d/Read.luau"], -[145800, "src/Rosetta/model/bsp/init.luau"], -[145945, "src/Rosetta/model/bsp/Brush.luau"], -[146223, "src/Rosetta/model/bsp/Quake3.luau"], -[146478, "src/Rosetta/model/dae/init.luau"], -[146667, "src/Rosetta/model/dae/Math.luau"], -[146714, "src/Rosetta/model/dae/Read.luau"], -[148564, "src/Rosetta/model/dae/Write.luau"], -[148933, "src/Rosetta/model/fbx/init.luau"], -[149081, "src/Rosetta/model/fbx/Ascii.luau"], -[149351, "src/Rosetta/model/fbx/Binary.luau"], -[149806, "src/Rosetta/model/fbx/Read.luau"], -[151168, "src/Rosetta/model/fbx/Write.luau"], -[152153, "src/Rosetta/model/fbx/Xform.luau"], -[152194, "src/Rosetta/model/gltf/init.luau"], -[152431, "src/Rosetta/model/gltf/Pack.luau"], -[152500, "src/Rosetta/model/gltf/Read.luau"], -[153231, "src/Rosetta/model/gltf/Write.luau"], -[153911, "src/Rosetta/model/iqm/init.luau"], -[153987, "src/Rosetta/model/iqm/Read.luau"], -[154342, "src/Rosetta/model/iqm/Write.luau"], -[155029, "src/Rosetta/model/ldraw/init.luau"], -[155107, "src/Rosetta/model/ldraw/Colors.luau"], -[155425, "src/Rosetta/model/ldraw/Read.luau"], -[156002, "src/Rosetta/model/lwo/init.luau"], -[156078, "src/Rosetta/model/lwo/Build.luau"], -[156540, "src/Rosetta/model/lwo/Parse.luau"], -[157083, "src/Rosetta/model/mca/init.luau"], -[157425, "src/Rosetta/model/mca/Chunk.luau"], -[157558, "src/Rosetta/model/mca/Lz4Block.luau"], -[157628, "src/Rosetta/model/md2/init.luau"], -[157827, "src/Rosetta/model/md3/init.luau"], -[158055, "src/Rosetta/model/md5/init.luau"], -[158136, "src/Rosetta/model/md5/Read.luau"], -[158569, "src/Rosetta/model/mdl/init.luau"], -[158651, "src/Rosetta/model/mdl/HalfLife.luau"], -[158979, "src/Rosetta/model/mdl/Quake.luau"], -[159197, "src/Rosetta/model/ms3d/init.luau"], -[159269, "src/Rosetta/model/ms3d/Read.luau"], -[159715, "src/Rosetta/model/ms3d/Write.luau"], -[160184, "src/Rosetta/model/obj/init.luau"], -[160926, "src/Rosetta/model/obj/Mtl.luau"], -[161213, "src/Rosetta/model/off/init.luau"], -[161675, "src/Rosetta/model/ply/init.luau"], -[162780, "src/Rosetta/model/ply/Binary.luau"], -[162981, "src/Rosetta/model/pmx/init.luau"], -[163050, "src/Rosetta/model/pmx/Build.luau"], -[163346, "src/Rosetta/model/pmx/Pmd.luau"], -[163681, "src/Rosetta/model/pmx/Read.luau"], -[164085, "src/Rosetta/model/proc/init.luau"], -[164467, "src/Rosetta/model/qb/init.luau"], -[164860, "src/Rosetta/model/rbxm/init.luau"], -[165452, "src/Rosetta/model/rbxmx/init.luau"], -[166105, "src/Rosetta/model/robloxmesh/init.luau"], -[166764, "src/Rosetta/model/robloxmesh/Parse.luau"], -[167221, "src/Rosetta/model/robloxmesh/Write.luau"], -[167330, "src/Rosetta/model/schematic/init.luau"], -[167651, "src/Rosetta/model/schematic/Common.luau"], -[167771, "src/Rosetta/model/schematic/Litematic.luau"], -[167982, "src/Rosetta/model/schematic/Mcedit.luau"], -[168226, "src/Rosetta/model/schematic/Sponge.luau"], -[168355, "src/Rosetta/model/smd/init.luau"], -[168422, "src/Rosetta/model/smd/Read.luau"], -[168691, "src/Rosetta/model/smd/Write.luau"], -[168934, "src/Rosetta/model/stl/init.luau"], -[169384, "src/Rosetta/model/stl/Decode.luau"], -[169458, "src/Rosetta/model/udmf/init.luau"], -[169541, "src/Rosetta/model/usda/init.luau"], -[169750, "src/Rosetta/model/usda/Build.luau"], -[171028, "src/Rosetta/model/usda/Parse.luau"], -[171826, "src/Rosetta/model/usda/Write.luau"], -[172643, "src/Rosetta/model/vox/init.luau"], -[173529, "src/Rosetta/model/vox/Grid.luau"], -[173586, "src/Rosetta/model/vrml/init.luau"], -[173652, "src/Rosetta/model/x/init.luau"], -[173782, "src/Rosetta/model/x/Build.luau"], -[174345, "src/Rosetta/model/x/Parse.luau"], -[174642, "src/Rosetta/model/x3d/init.luau"], -[174720, "src/Rosetta/music/669/init.luau"], -[174926, "src/Rosetta/music/ahx/init.luau"], -[174977, "src/Rosetta/music/far/init.luau"], -[175206, "src/Rosetta/music/hmp/init.luau"], -[175470, "src/Rosetta/music/hvl/init.luau"], -[175521, "src/Rosetta/music/it/init.luau"], -[175939, "src/Rosetta/music/it/Itsex.luau"], -[176055, "src/Rosetta/music/med/init.luau"], -[176702, "src/Rosetta/music/midi/init.luau"], -[176845, "src/Rosetta/music/midi/Smf.luau"], -[177256, "src/Rosetta/music/mod/init.luau"], -[177609, "src/Rosetta/music/mtm/init.luau"], -[177831, "src/Rosetta/music/mus/init.luau"], -[177988, "src/Rosetta/music/okt/init.luau"], -[178269, "src/Rosetta/music/ptm/init.luau"], -[178491, "src/Rosetta/music/s3m/init.luau"], -[178727, "src/Rosetta/music/sf2/init.luau"], -[178770, "src/Rosetta/music/stm/init.luau"], -[179001, "src/Rosetta/music/ult/init.luau"], -[179305, "src/Rosetta/music/umx/init.luau"], -[179521, "src/Rosetta/music/xm/init.luau"], -[180082, "src/Rosetta/music/xmi/init.luau"], -[180290, "src/Rosetta/ops/AudioOps.luau"], -[180739, "src/Rosetta/ops/ImageOps/init.luau"], -[181383, "src/Rosetta/ops/ImageOps/Kernels.luau"], -[181893, "src/Rosetta/ops/LayerOps.luau"], -[181986, "src/Rosetta/ops/MeshOps/init.luau"], -[183022, "src/Rosetta/ops/MeshOps/Greedy.luau"], -[183189, "src/Rosetta/ops/MusicOps.luau"], -[183537, "src/Rosetta/playlist/m3u/init.luau"], -[183890, "src/Rosetta/playlist/pls/init.luau"], -[184068, "src/Rosetta/playlist/xspf/init.luau"], -[184271, "src/Rosetta/subtitle/ass/init.luau"], -[184715, "src/Rosetta/subtitle/srt/init.luau"], -[184888, "src/Rosetta/subtitle/vtt/init.luau"], -[185091, "src/Rosetta/vector/gamemaps/init.luau"], -[185278, "src/Rosetta/vector/gamemaps/Expand.luau"], -[185375, "src/Rosetta/vector/svg/init.luau"], -[185461, "src/Rosetta/vector/svg/Parse.luau"], -[186207, "src/Rosetta/vector/svg/PathData.luau"], -[186575, "src/Rosetta/vector/svg/Render.luau"], -[186992, "src/Rosetta/vector/svg/Style.luau"], -[187364, "src/Rosetta/vector/svg/Write.luau"], -[187564, "src/Rosetta/vector/tiled/init.luau"], -[187744, "src/Rosetta/vector/tiled/Data.luau"], -[187895, "src/Rosetta/vector/tiled/Tmj.luau"], -[188526, "src/Rosetta/vector/tiled/Tmx.luau"], -[189138, "src/Rosetta/video/avi/init.luau"], -[189432, "src/Rosetta/video/fli/init.luau"], -[189583, "src/Rosetta/video/flv/init.luau"], -[189967, "src/Rosetta/video/flv/Amf.luau"], -[190125, "src/Rosetta/video/flv/Mux.luau"], -[190406, "src/Rosetta/video/h264/init.luau"], -[190545, "src/Rosetta/video/mkv/init.luau"], -[190701, "src/Rosetta/video/mkv/Mux.luau"], -[190980, "src/Rosetta/video/mkv/Parse.luau"], -[191701, "src/Rosetta/video/mp4/init.luau"], -[192029, "src/Rosetta/video/mpegps/init.luau"], -[192216, "src/Rosetta/video/mpegts/init.luau"], -[192454, "src/Rosetta/video/ogv/init.luau"], -[192849, "src/Rosetta/video/smk/init.luau"], -[193158, "src/Rosetta/video/smk/Audio.luau"], -[193278, "src/Rosetta/video/y4m/init.luau"] +[3673, "src/Rosetta/Types.luau"], +[4756, "src/Rosetta/archive/7z/init.luau"], +[5141, "src/Rosetta/archive/7z/Header.luau"], +[5668, "src/Rosetta/archive/adf/init.luau"], +[5950, "src/Rosetta/archive/applesingle/init.luau"], +[6136, "src/Rosetta/archive/ar/init.luau"], +[6539, "src/Rosetta/archive/arj/init.luau"], +[6749, "src/Rosetta/archive/binhex/init.luau"], +[6998, "src/Rosetta/archive/br/init.luau"], +[7073, "src/Rosetta/archive/bz2/init.luau"], +[7137, "src/Rosetta/archive/cab/init.luau"], +[7550, "src/Rosetta/archive/cab/Sum.luau"], +[7591, "src/Rosetta/archive/cpio/init.luau"], +[7759, "src/Rosetta/archive/d64/init.luau"], +[8173, "src/Rosetta/archive/fat/init.luau"], +[8295, "src/Rosetta/archive/grp/init.luau"], +[8409, "src/Rosetta/archive/gzip/init.luau"], +[8594, "src/Rosetta/archive/iso/init.luau"], +[8666, "src/Rosetta/archive/lha/init.luau"], +[9091, "src/Rosetta/archive/lz4/init.luau"], +[9435, "src/Rosetta/archive/macbinary/init.luau"], +[9633, "src/Rosetta/archive/mpq/init.luau"], +[10039, "src/Rosetta/archive/mpq/Crypt.luau"], +[10104, "src/Rosetta/archive/pak/init.luau"], +[10238, "src/Rosetta/archive/rpm/init.luau"], +[10562, "src/Rosetta/archive/tar/init.luau"], +[10680, "src/Rosetta/archive/uu/init.luau"], +[10950, "src/Rosetta/archive/vpk/init.luau"], +[11261, "src/Rosetta/archive/vswap/init.luau"], +[11531, "src/Rosetta/archive/wad/init.luau"], +[11985, "src/Rosetta/archive/wad/Picture.luau"], +[12087, "src/Rosetta/archive/xz/init.luau"], +[12187, "src/Rosetta/archive/yenc/init.luau"], +[12459, "src/Rosetta/archive/z/init.luau"], +[12555, "src/Rosetta/archive/zip/init.luau"], +[12774, "src/Rosetta/archive/zoo/init.luau"], +[12970, "src/Rosetta/archive/zst/init.luau"], +[13034, "src/Rosetta/audio/aac/init.luau"], +[13240, "src/Rosetta/audio/ac3/init.luau"], +[13386, "src/Rosetta/audio/adpcm/init.luau"], +[13531, "src/Rosetta/audio/adx/init.luau"], +[13762, "src/Rosetta/audio/aiff/init.luau"], +[14153, "src/Rosetta/audio/ape/init.luau"], +[14281, "src/Rosetta/audio/au/init.luau"], +[14442, "src/Rosetta/audio/brstm/init.luau"], +[14733, "src/Rosetta/audio/caf/init.luau"], +[15395, "src/Rosetta/audio/flac/init.luau"], +[15543, "src/Rosetta/audio/flac/Meta.luau"], +[15765, "src/Rosetta/audio/flac/Stream.luau"], +[16135, "src/Rosetta/audio/m4a/init.luau"], +[16469, "src/Rosetta/audio/mp3/init.luau"], +[16729, "src/Rosetta/audio/mp3/Index.luau"], +[16920, "src/Rosetta/audio/mp3/Stream.luau"], +[17147, "src/Rosetta/audio/mp3/Tags.luau"], +[17459, "src/Rosetta/audio/mpc/init.luau"], +[17553, "src/Rosetta/audio/opus/init.luau"], +[17931, "src/Rosetta/audio/opus/Encode.luau"], +[18042, "src/Rosetta/audio/qoa/init.luau"], +[18222, "src/Rosetta/audio/tta/init.luau"], +[18340, "src/Rosetta/audio/vag/init.luau"], +[18563, "src/Rosetta/audio/voc/init.luau"], +[18838, "src/Rosetta/audio/vorbis/init.luau"], +[19292, "src/Rosetta/audio/vorbis/Encode.luau"], +[20105, "src/Rosetta/audio/wav/init.luau"], +[20726, "src/Rosetta/audio/wav/Codecs.luau"], +[20892, "src/Rosetta/audio/wavpack/init.luau"], +[21099, "src/Rosetta/cad/step/init.luau"], +[21481, "src/Rosetta/cad/step/Brep.luau"], +[21716, "src/Rosetta/cad/step/Parse.luau"], +[22273, "src/Rosetta/cad/step/Write.luau"], +[22521, "src/Rosetta/codecs/audio/Aac/init.luau"], +[22840, "src/Rosetta/codecs/audio/Aac/Decode.luau"], +[23723, "src/Rosetta/codecs/audio/Aac/Tables.luau"], +[24058, "src/Rosetta/codecs/audio/Ac3/init.luau"], +[24217, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], +[25102, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], +[25203, "src/Rosetta/codecs/audio/Adpcm/init.luau"], +[25957, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], +[26259, "src/Rosetta/codecs/audio/Alac/init.luau"], +[26493, "src/Rosetta/codecs/audio/Alac/Decode.luau"], +[26912, "src/Rosetta/codecs/audio/Alac/Encode.luau"], +[27324, "src/Rosetta/codecs/audio/Ape/init.luau"], +[27539, "src/Rosetta/codecs/audio/Ape/Decode.luau"], +[28300, "src/Rosetta/codecs/audio/ApeTag.luau"], +[28397, "src/Rosetta/codecs/audio/Flac/init.luau"], +[28408, "src/Rosetta/codecs/audio/Flac/Encode.luau"], +[29357, "src/Rosetta/codecs/audio/Flac/Frame.luau"], +[29954, "src/Rosetta/codecs/audio/Hively/init.luau"], +[30150, "src/Rosetta/codecs/audio/Hively/Load.luau"], +[30399, "src/Rosetta/codecs/audio/Hively/Player.luau"], +[31357, "src/Rosetta/codecs/audio/Hively/Tables.luau"], +[31576, "src/Rosetta/codecs/audio/Mdct/init.luau"], +[31760, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], +[31969, "src/Rosetta/codecs/audio/MidiRender.luau"], +[32315, "src/Rosetta/codecs/audio/Mpa/init.luau"], +[32329, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], +[32388, "src/Rosetta/codecs/audio/Mpa/Core.luau"], +[33991, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], +[34283, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], +[34668, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], +[35309, "src/Rosetta/codecs/audio/Mpa/Header.luau"], +[35450, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], +[35676, "src/Rosetta/codecs/audio/Musepack/init.luau"], +[36021, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], +[36902, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], +[37280, "src/Rosetta/codecs/audio/Opus/init.luau"], +[37294, "src/Rosetta/codecs/audio/Opus/Celt.luau"], +[39141, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], +[40206, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], +[40266, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], +[40726, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], +[41063, "src/Rosetta/codecs/audio/Opus/Packet.luau"], +[41296, "src/Rosetta/codecs/audio/Opus/Silk.luau"], +[43332, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], +[43706, "src/Rosetta/codecs/audio/Pcm/init.luau"], +[43969, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], +[44266, "src/Rosetta/codecs/audio/Qoa/init.luau"], +[44548, "src/Rosetta/codecs/audio/Resample/init.luau"], +[44907, "src/Rosetta/codecs/audio/SoundFont/init.luau"], +[44961, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], +[45104, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], +[45617, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], +[46398, "src/Rosetta/codecs/audio/Stream.luau"], +[46559, "src/Rosetta/codecs/audio/Tracker/init.luau"], +[47041, "src/Rosetta/codecs/audio/Tracker/Load.luau"], +[47319, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], +[47488, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], +[47616, "src/Rosetta/codecs/audio/Tracker/Player.luau"], +[49604, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], +[49720, "src/Rosetta/codecs/audio/Tta/init.luau"], +[49837, "src/Rosetta/codecs/audio/Tta/Decode.luau"], +[50089, "src/Rosetta/codecs/audio/Vorbis/init.luau"], +[50102, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], +[50486, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], +[51052, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], +[51473, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], +[51512, "src/Rosetta/codecs/audio/VorbisComment.luau"], +[51564, "src/Rosetta/codecs/audio/WavPack/init.luau"], +[51786, "src/Rosetta/codecs/audio/WavPack/Block.luau"], +[53241, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], +[53304, "src/Rosetta/codecs/compress/Brotli/init.luau"], +[53391, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], +[54360, "src/Rosetta/codecs/compress/Brotli/Static.luau"], +[55228, "src/Rosetta/codecs/compress/Bzip2/init.luau"], +[55276, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], +[55792, "src/Rosetta/codecs/compress/Deflate/init.luau"], +[56118, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], +[56538, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], +[56973, "src/Rosetta/codecs/compress/Explode.luau"], +[57169, "src/Rosetta/codecs/compress/Lz4.luau"], +[57438, "src/Rosetta/codecs/compress/Lzh/init.luau"], +[58042, "src/Rosetta/codecs/compress/Lzma/init.luau"], +[58582, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], +[58620, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], +[59093, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], +[59269, "src/Rosetta/codecs/compress/Lzw/init.luau"], +[59537, "src/Rosetta/codecs/compress/Lzx.luau"], +[59971, "src/Rosetta/codecs/compress/PackBits.luau"], +[60061, "src/Rosetta/codecs/compress/Quantum.luau"], +[60298, "src/Rosetta/codecs/compress/UnixCompress.luau"], +[60602, "src/Rosetta/codecs/compress/Xxh32.luau"], +[60671, "src/Rosetta/codecs/compress/Zstd/init.luau"], +[60728, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], +[61686, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], +[61838, "src/Rosetta/codecs/entropy/Huffman.luau"], +[62120, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], +[62131, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], +[62345, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], +[62589, "src/Rosetta/codecs/font/Bitmap.luau"], +[62790, "src/Rosetta/codecs/font/Cff/init.luau"], +[63431, "src/Rosetta/codecs/font/GlyphNames.luau"], +[63581, "src/Rosetta/codecs/font/TrueType/init.luau"], +[63895, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], +[64287, "src/Rosetta/codecs/font/TrueType/Tables.luau"], +[64789, "src/Rosetta/codecs/image/Bcn/init.luau"], +[64896, "src/Rosetta/codecs/image/Bcn/Decode.luau"], +[65385, "src/Rosetta/codecs/image/Bcn/Encode.luau"], +[65814, "src/Rosetta/codecs/image/Blend.luau"], +[66193, "src/Rosetta/codecs/image/Dct/init.luau"], +[66574, "src/Rosetta/codecs/image/Etc.luau"], +[66872, "src/Rosetta/codecs/image/Half.luau"], +[66941, "src/Rosetta/codecs/image/Jpeg/init.luau"], +[67295, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], +[67703, "src/Rosetta/codecs/image/Jpeg/Color.luau"], +[67940, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], +[68700, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], +[69581, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], +[70027, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], +[70105, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], +[70172, "src/Rosetta/codecs/image/Miptex.luau"], +[70388, "src/Rosetta/codecs/image/Pixels.luau"], +[70708, "src/Rosetta/codecs/image/Quantize/init.luau"], +[71167, "src/Rosetta/codecs/image/Raster.luau"], +[71864, "src/Rosetta/codecs/image/Texel.luau"], +[72237, "src/Rosetta/codecs/image/Texture.luau"], +[72382, "src/Rosetta/codecs/image/Vp8/init.luau"], +[72512, "src/Rosetta/codecs/image/Vp8/Decode.luau"], +[74468, "src/Rosetta/codecs/image/Vp8/Predict.luau"], +[74727, "src/Rosetta/codecs/image/Vp8/Tables.luau"], +[74976, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], +[75095, "src/Rosetta/codecs/image/Vp8L/init.luau"], +[75199, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], +[76052, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], +[77004, "src/Rosetta/codecs/image/Yuv.luau"], +[77272, "src/Rosetta/codecs/model/Brush.luau"], +[77912, "src/Rosetta/codecs/model/DoomMap/init.luau"], +[78357, "src/Rosetta/codecs/model/DoomMap/Udmf.luau"], +[78607, "src/Rosetta/codecs/model/Draco/init.luau"], +[78939, "src/Rosetta/codecs/model/Draco/Attributes.luau"], +[79408, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], +[80597, "src/Rosetta/codecs/model/Draco/Int64.luau"], +[80746, "src/Rosetta/codecs/model/Draco/KdTree.luau"], +[81105, "src/Rosetta/codecs/model/Draco/Predict.luau"], +[82067, "src/Rosetta/codecs/model/Draco/Reader.luau"], +[82541, "src/Rosetta/codecs/model/Mat4.luau"], +[82800, "src/Rosetta/codecs/model/MeshFlatten.luau"], +[83328, "src/Rosetta/codecs/model/Minecraft/init.luau"], +[83880, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], +[83959, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], +[84066, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], +[84272, "src/Rosetta/codecs/model/Patch.luau"], +[84396, "src/Rosetta/codecs/model/Polygon.luau"], +[84630, "src/Rosetta/codecs/model/Rbx/init.luau"], +[84867, "src/Rosetta/codecs/model/Rbx/Binary.luau"], +[85621, "src/Rosetta/codecs/model/Rig.luau"], +[85864, "src/Rosetta/codecs/model/Sampler.luau"], +[86024, "src/Rosetta/codecs/model/Vrml/init.luau"], +[86172, "src/Rosetta/codecs/model/Vrml/Build.luau"], +[86746, "src/Rosetta/codecs/model/Vrml/Fields.luau"], +[86909, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], +[87658, "src/Rosetta/codecs/model/Vrml/Parse.luau"], +[88180, "src/Rosetta/codecs/model/Vrml/Write.luau"], +[88907, "src/Rosetta/codecs/model/Vrml/Xml.luau"], +[89139, "src/Rosetta/codecs/text/Json/init.luau"], +[89408, "src/Rosetta/codecs/text/Json/Decode.luau"], +[89822, "src/Rosetta/codecs/text/Json/Encode.luau"], +[90124, "src/Rosetta/codecs/text/Lexer/init.luau"], +[90256, "src/Rosetta/codecs/text/Nbt/init.luau"], +[90609, "src/Rosetta/codecs/text/Nbt/Binary.luau"], +[91301, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], +[91941, "src/Rosetta/codecs/text/Nbt/Value.luau"], +[92179, "src/Rosetta/codecs/text/Text/init.luau"], +[92270, "src/Rosetta/codecs/text/Url/init.luau"], +[92475, "src/Rosetta/codecs/text/Xml/init.luau"], +[92878, "src/Rosetta/codecs/text/Xml/Parse.luau"], +[93618, "src/Rosetta/codecs/video/Dsp.luau"], +[94341, "src/Rosetta/codecs/video/H263/init.luau"], +[94497, "src/Rosetta/codecs/video/H263/Decoder.luau"], +[95355, "src/Rosetta/codecs/video/H263/Tables.luau"], +[95558, "src/Rosetta/codecs/video/H264/init.luau"], +[95931, "src/Rosetta/codecs/video/H264/Bitstream.luau"], +[96206, "src/Rosetta/codecs/video/H264/Cabac.luau"], +[97337, "src/Rosetta/codecs/video/H264/Cavlc.luau"], +[98105, "src/Rosetta/codecs/video/H264/Deblock.luau"], +[98363, "src/Rosetta/codecs/video/H264/Decoder.luau"], +[99372, "src/Rosetta/codecs/video/H264/Inter.luau"], +[99626, "src/Rosetta/codecs/video/H264/Intra.luau"], +[100033, "src/Rosetta/codecs/video/H264/Mb.luau"], +[100939, "src/Rosetta/codecs/video/H264/Params.luau"], +[101386, "src/Rosetta/codecs/video/H264/Slice.luau"], +[101637, "src/Rosetta/codecs/video/H264/Tables.luau"], +[101678, "src/Rosetta/codecs/video/H264/Transform.luau"], +[101843, "src/Rosetta/codecs/video/Legacy/init.luau"], +[102041, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], +[102338, "src/Rosetta/codecs/video/Legacy/Flic.luau"], +[102705, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], +[102823, "src/Rosetta/codecs/video/Legacy/Picture.luau"], +[102931, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], +[103204, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], +[103599, "src/Rosetta/codecs/video/Legacy/Smc.luau"], +[103776, "src/Rosetta/codecs/video/Mpeg1/init.luau"], +[103788, "src/Rosetta/codecs/video/Mpeg2/init.luau"], +[104155, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], +[105662, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], +[105801, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], +[105939, "src/Rosetta/codecs/video/Theora/init.luau"], +[106202, "src/Rosetta/codecs/video/Theora/Decoder.luau"], +[107466, "src/Rosetta/codecs/video/Theora/Header.luau"], +[107829, "src/Rosetta/codecs/video/Video/init.luau"], +[108386, "src/Rosetta/codecs/video/Video/Source.luau"], +[108671, "src/Rosetta/containers/Archive.luau"], +[108938, "src/Rosetta/containers/AudioWrap.luau"], +[109441, "src/Rosetta/containers/Avi/init.luau"], +[109993, "src/Rosetta/containers/Chunks.luau"], +[110128, "src/Rosetta/containers/Cpio.luau"], +[110556, "src/Rosetta/containers/Demux.luau"], +[110831, "src/Rosetta/containers/Ebml/init.luau"], +[111144, "src/Rosetta/containers/Fat.luau"], +[111832, "src/Rosetta/containers/Iso9660.luau"], +[112337, "src/Rosetta/containers/IsoBmff/init.luau"], +[112507, "src/Rosetta/containers/IsoBmff/Box.luau"], +[112695, "src/Rosetta/containers/IsoBmff/Demux.luau"], +[113540, "src/Rosetta/containers/IsoBmff/Meta.luau"], +[114061, "src/Rosetta/containers/IsoBmff/Mux.luau"], +[114577, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], +[114694, "src/Rosetta/containers/MacFile.luau"], +[114843, "src/Rosetta/containers/MpegEs.luau"], +[115009, "src/Rosetta/containers/MpegPs/init.luau"], +[115229, "src/Rosetta/containers/MpegTs/init.luau"], +[116021, "src/Rosetta/containers/Ogg/init.luau"], +[116446, "src/Rosetta/containers/Ogg/Mux.luau"], +[116641, "src/Rosetta/containers/Ogg/Page.luau"], +[116810, "src/Rosetta/containers/Riff/init.luau"], +[117127, "src/Rosetta/containers/Tar.luau"], +[117541, "src/Rosetta/containers/Zip/init.luau"], +[118173, "src/Rosetta/core/Adler32.luau"], +[118219, "src/Rosetta/core/Base64.luau"], +[118378, "src/Rosetta/core/Bits.luau"], +[118671, "src/Rosetta/core/Bytes.luau"], +[119198, "src/Rosetta/core/Crc16.luau"], +[119250, "src/Rosetta/core/Crc32.luau"], +[119362, "src/Rosetta/core/Err.luau"], +[119444, "src/Rosetta/core/Input.luau"], +[119520, "src/Rosetta/core/Md5.luau"], +[119679, "src/Rosetta/core/Sniff.luau"], +[119708, "src/Rosetta/data/cbor/init.luau"], +[119807, "src/Rosetta/data/cbor/Codec.luau"], +[120376, "src/Rosetta/data/csv/init.luau"], +[120688, "src/Rosetta/data/ini/init.luau"], +[120934, "src/Rosetta/data/json/init.luau"], +[121026, "src/Rosetta/data/msgpack/init.luau"], +[121115, "src/Rosetta/data/msgpack/Codec.luau"], +[121557, "src/Rosetta/data/nbt/init.luau"], +[121616, "src/Rosetta/data/plist/init.luau"], +[121922, "src/Rosetta/data/plist/Binary.luau"], +[122189, "src/Rosetta/data/snbt/init.luau"], +[122252, "src/Rosetta/data/toml/init.luau"], +[122319, "src/Rosetta/data/toml/Decode.luau"], +[122947, "src/Rosetta/data/toml/Encode.luau"], +[123156, "src/Rosetta/data/xml/init.luau"], +[123212, "src/Rosetta/data/yaml/init.luau"], +[123285, "src/Rosetta/data/yaml/Emit.luau"], +[123575, "src/Rosetta/data/yaml/Parse.luau"], +[124868, "src/Rosetta/font/bdf/init.luau"], +[125157, "src/Rosetta/font/bmfont/init.luau"], +[125584, "src/Rosetta/font/bmfont/Parse.luau"], +[126037, "src/Rosetta/font/eot/init.luau"], +[126269, "src/Rosetta/font/fon/init.luau"], +[126552, "src/Rosetta/font/hershey/init.luau"], +[126747, "src/Rosetta/font/pcf/init.luau"], +[127027, "src/Rosetta/font/psf/init.luau"], +[127347, "src/Rosetta/font/ttf/init.luau"], +[127398, "src/Rosetta/font/type1/init.luau"], +[127757, "src/Rosetta/font/type1/Charstring.luau"], +[128035, "src/Rosetta/font/woff/init.luau"], +[128167, "src/Rosetta/font/woff2/init.luau"], +[128224, "src/Rosetta/font/woff2/Rebuild.luau"], +[128764, "src/Rosetta/host/init.luau"], +[128809, "src/Rosetta/host/Love.luau"], +[128952, "src/Rosetta/host/LuaJIT.luau"], +[129002, "src/Rosetta/host/Luau.luau"], +[129025, "src/Rosetta/host/Roblox.luau"], +[129384, "src/Rosetta/image/ani/init.luau"], +[129564, "src/Rosetta/image/blp/init.luau"], +[129822, "src/Rosetta/image/bmp/init.luau"], +[130237, "src/Rosetta/image/dds/init.luau"], +[130720, "src/Rosetta/image/exr/init.luau"], +[131480, "src/Rosetta/image/exr/Codec.luau"], +[131591, "src/Rosetta/image/exr/Piz.luau"], +[131948, "src/Rosetta/image/gif/init.luau"], +[132464, "src/Rosetta/image/gif/Decode.luau"], +[132527, "src/Rosetta/image/hdr/init.luau"], +[132756, "src/Rosetta/image/hdr/Codec.luau"], +[132967, "src/Rosetta/image/icns/init.luau"], +[133298, "src/Rosetta/image/ico/init.luau"], +[133575, "src/Rosetta/image/ico/Dib.luau"], +[133670, "src/Rosetta/image/ilbm/init.luau"], +[133989, "src/Rosetta/image/jpeg/init.luau"], +[134125, "src/Rosetta/image/ktx/init.luau"], +[134785, "src/Rosetta/image/pcx/init.luau"], +[135049, "src/Rosetta/image/png/init.luau"], +[135629, "src/Rosetta/image/png/Apng.luau"], +[135709, "src/Rosetta/image/png/Decode.luau"], +[135949, "src/Rosetta/image/png/Encode.luau"], +[136104, "src/Rosetta/image/pnm/init.luau"], +[136482, "src/Rosetta/image/pnm/Codec.luau"], +[136759, "src/Rosetta/image/qoi/init.luau"], +[136881, "src/Rosetta/image/qoi/Codec.luau"], +[137031, "src/Rosetta/image/sgi/init.luau"], +[137316, "src/Rosetta/image/sunras/init.luau"], +[137562, "src/Rosetta/image/tga/init.luau"], +[137832, "src/Rosetta/image/tga/Codec.luau"], +[137984, "src/Rosetta/image/tiff/init.luau"], +[138811, "src/Rosetta/image/tiff/Pixels.luau"], +[139201, "src/Rosetta/image/tim/init.luau"], +[139443, "src/Rosetta/image/vtf/init.luau"], +[139678, "src/Rosetta/image/webp/init.luau"], +[140288, "src/Rosetta/image/webp/Alpha.luau"], +[140364, "src/Rosetta/image/webp/Anim.luau"], +[140519, "src/Rosetta/image/xbm/init.luau"], +[140680, "src/Rosetta/image/xpm/init.luau"], +[140948, "src/Rosetta/image/xpm/Names.luau"], +[141004, "src/Rosetta/layered/aseprite/init.luau"], +[141742, "src/Rosetta/layered/ora/init.luau"], +[142029, "src/Rosetta/layered/psd/init.luau"], +[142764, "src/Rosetta/layered/psd/Channels.luau"], +[143116, "src/Rosetta/model/3ds/init.luau"], +[143199, "src/Rosetta/model/3ds/Build.luau"], +[143846, "src/Rosetta/model/3ds/Read.luau"], +[144342, "src/Rosetta/model/3ds/Write.luau"], +[145147, "src/Rosetta/model/3mf/init.luau"], +[145229, "src/Rosetta/model/3mf/Read.luau"], +[145817, "src/Rosetta/model/3mf/Write.luau"], +[146222, "src/Rosetta/model/b3d/init.luau"], +[146277, "src/Rosetta/model/b3d/Read.luau"], +[146848, "src/Rosetta/model/bsp/init.luau"], +[146993, "src/Rosetta/model/bsp/Brush.luau"], +[147256, "src/Rosetta/model/bsp/Quake3.luau"], +[147484, "src/Rosetta/model/dae/init.luau"], +[147673, "src/Rosetta/model/dae/Math.luau"], +[147720, "src/Rosetta/model/dae/Read.luau"], +[149570, "src/Rosetta/model/dae/Write.luau"], +[149939, "src/Rosetta/model/fbx/init.luau"], +[150087, "src/Rosetta/model/fbx/Ascii.luau"], +[150357, "src/Rosetta/model/fbx/Binary.luau"], +[150812, "src/Rosetta/model/fbx/Read.luau"], +[152174, "src/Rosetta/model/fbx/Write.luau"], +[153159, "src/Rosetta/model/fbx/Xform.luau"], +[153200, "src/Rosetta/model/gltf/init.luau"], +[153437, "src/Rosetta/model/gltf/Pack.luau"], +[153506, "src/Rosetta/model/gltf/Read.luau"], +[154237, "src/Rosetta/model/gltf/Write.luau"], +[154917, "src/Rosetta/model/iqm/init.luau"], +[154993, "src/Rosetta/model/iqm/Read.luau"], +[155348, "src/Rosetta/model/iqm/Write.luau"], +[156035, "src/Rosetta/model/ldraw/init.luau"], +[156113, "src/Rosetta/model/ldraw/Colors.luau"], +[156431, "src/Rosetta/model/ldraw/Read.luau"], +[157008, "src/Rosetta/model/lwo/init.luau"], +[157084, "src/Rosetta/model/lwo/Build.luau"], +[157546, "src/Rosetta/model/lwo/Parse.luau"], +[158089, "src/Rosetta/model/map/init.luau"], +[158406, "src/Rosetta/model/map/Build.luau"], +[158649, "src/Rosetta/model/map/Parse.luau"], +[159034, "src/Rosetta/model/map/Write.luau"], +[159180, "src/Rosetta/model/mca/init.luau"], +[159522, "src/Rosetta/model/mca/Chunk.luau"], +[159655, "src/Rosetta/model/mca/Lz4Block.luau"], +[159725, "src/Rosetta/model/md2/init.luau"], +[159924, "src/Rosetta/model/md3/init.luau"], +[160152, "src/Rosetta/model/md5/init.luau"], +[160233, "src/Rosetta/model/md5/Read.luau"], +[160666, "src/Rosetta/model/mdl/init.luau"], +[160748, "src/Rosetta/model/mdl/HalfLife.luau"], +[161076, "src/Rosetta/model/mdl/Quake.luau"], +[161294, "src/Rosetta/model/ms3d/init.luau"], +[161366, "src/Rosetta/model/ms3d/Read.luau"], +[161812, "src/Rosetta/model/ms3d/Write.luau"], +[162281, "src/Rosetta/model/obj/init.luau"], +[163023, "src/Rosetta/model/obj/Mtl.luau"], +[163310, "src/Rosetta/model/off/init.luau"], +[163772, "src/Rosetta/model/ply/init.luau"], +[164877, "src/Rosetta/model/ply/Binary.luau"], +[165078, "src/Rosetta/model/pmx/init.luau"], +[165147, "src/Rosetta/model/pmx/Build.luau"], +[165443, "src/Rosetta/model/pmx/Pmd.luau"], +[165778, "src/Rosetta/model/pmx/Read.luau"], +[166182, "src/Rosetta/model/proc/init.luau"], +[166564, "src/Rosetta/model/qb/init.luau"], +[166957, "src/Rosetta/model/rbxm/init.luau"], +[167549, "src/Rosetta/model/rbxmx/init.luau"], +[168202, "src/Rosetta/model/robloxmesh/init.luau"], +[168861, "src/Rosetta/model/robloxmesh/Parse.luau"], +[169318, "src/Rosetta/model/robloxmesh/Write.luau"], +[169427, "src/Rosetta/model/schematic/init.luau"], +[169748, "src/Rosetta/model/schematic/Common.luau"], +[169868, "src/Rosetta/model/schematic/Litematic.luau"], +[170079, "src/Rosetta/model/schematic/Mcedit.luau"], +[170323, "src/Rosetta/model/schematic/Sponge.luau"], +[170452, "src/Rosetta/model/smd/init.luau"], +[170519, "src/Rosetta/model/smd/Read.luau"], +[170788, "src/Rosetta/model/smd/Write.luau"], +[171031, "src/Rosetta/model/stl/init.luau"], +[171481, "src/Rosetta/model/stl/Decode.luau"], +[171555, "src/Rosetta/model/udmf/init.luau"], +[171638, "src/Rosetta/model/usda/init.luau"], +[171847, "src/Rosetta/model/usda/Build.luau"], +[173125, "src/Rosetta/model/usda/Parse.luau"], +[173923, "src/Rosetta/model/usda/Write.luau"], +[174740, "src/Rosetta/model/vox/init.luau"], +[175626, "src/Rosetta/model/vox/Grid.luau"], +[175683, "src/Rosetta/model/vrml/init.luau"], +[175749, "src/Rosetta/model/x/init.luau"], +[175879, "src/Rosetta/model/x/Build.luau"], +[176442, "src/Rosetta/model/x/Parse.luau"], +[176739, "src/Rosetta/model/x3d/init.luau"], +[176817, "src/Rosetta/music/669/init.luau"], +[177023, "src/Rosetta/music/ahx/init.luau"], +[177074, "src/Rosetta/music/far/init.luau"], +[177303, "src/Rosetta/music/hmp/init.luau"], +[177567, "src/Rosetta/music/hvl/init.luau"], +[177618, "src/Rosetta/music/it/init.luau"], +[178036, "src/Rosetta/music/it/Itsex.luau"], +[178152, "src/Rosetta/music/med/init.luau"], +[178799, "src/Rosetta/music/midi/init.luau"], +[178942, "src/Rosetta/music/midi/Smf.luau"], +[179353, "src/Rosetta/music/mod/init.luau"], +[179706, "src/Rosetta/music/mtm/init.luau"], +[179928, "src/Rosetta/music/mus/init.luau"], +[180085, "src/Rosetta/music/okt/init.luau"], +[180366, "src/Rosetta/music/ptm/init.luau"], +[180588, "src/Rosetta/music/s3m/init.luau"], +[180824, "src/Rosetta/music/sf2/init.luau"], +[180867, "src/Rosetta/music/stm/init.luau"], +[181098, "src/Rosetta/music/ult/init.luau"], +[181402, "src/Rosetta/music/umx/init.luau"], +[181618, "src/Rosetta/music/xm/init.luau"], +[182179, "src/Rosetta/music/xmi/init.luau"], +[182387, "src/Rosetta/ops/AudioOps.luau"], +[182836, "src/Rosetta/ops/ImageOps/init.luau"], +[183480, "src/Rosetta/ops/ImageOps/Kernels.luau"], +[183990, "src/Rosetta/ops/LayerOps.luau"], +[184083, "src/Rosetta/ops/MeshOps/init.luau"], +[185119, "src/Rosetta/ops/MeshOps/Greedy.luau"], +[185286, "src/Rosetta/ops/MusicOps.luau"], +[185634, "src/Rosetta/playlist/m3u/init.luau"], +[185987, "src/Rosetta/playlist/pls/init.luau"], +[186165, "src/Rosetta/playlist/xspf/init.luau"], +[186368, "src/Rosetta/subtitle/ass/init.luau"], +[186812, "src/Rosetta/subtitle/srt/init.luau"], +[186985, "src/Rosetta/subtitle/vtt/init.luau"], +[187188, "src/Rosetta/vector/gamemaps/init.luau"], +[187375, "src/Rosetta/vector/gamemaps/Expand.luau"], +[187472, "src/Rosetta/vector/svg/init.luau"], +[187558, "src/Rosetta/vector/svg/Parse.luau"], +[188304, "src/Rosetta/vector/svg/PathData.luau"], +[188672, "src/Rosetta/vector/svg/Render.luau"], +[189089, "src/Rosetta/vector/svg/Style.luau"], +[189461, "src/Rosetta/vector/svg/Write.luau"], +[189661, "src/Rosetta/vector/tiled/init.luau"], +[189841, "src/Rosetta/vector/tiled/Data.luau"], +[189992, "src/Rosetta/vector/tiled/Tmj.luau"], +[190623, "src/Rosetta/vector/tiled/Tmx.luau"], +[191235, "src/Rosetta/video/avi/init.luau"], +[191529, "src/Rosetta/video/fli/init.luau"], +[191680, "src/Rosetta/video/flv/init.luau"], +[192064, "src/Rosetta/video/flv/Amf.luau"], +[192222, "src/Rosetta/video/flv/Mux.luau"], +[192503, "src/Rosetta/video/h264/init.luau"], +[192642, "src/Rosetta/video/mkv/init.luau"], +[192798, "src/Rosetta/video/mkv/Mux.luau"], +[193077, "src/Rosetta/video/mkv/Parse.luau"], +[193798, "src/Rosetta/video/mp4/init.luau"], +[194126, "src/Rosetta/video/mpegps/init.luau"], +[194313, "src/Rosetta/video/mpegts/init.luau"], +[194551, "src/Rosetta/video/ogv/init.luau"], +[194946, "src/Rosetta/video/smk/init.luau"], +[195255, "src/Rosetta/video/smk/Audio.luau"], +[195375, "src/Rosetta/video/y4m/init.luau"] ] diff --git a/docs/FORMATS.md b/docs/FORMATS.md index d4743bc..65604f0 100644 --- a/docs/FORMATS.md +++ b/docs/FORMATS.md @@ -72,6 +72,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build | model | iqm | .iqm | yes | yes | materials: true, skins: true, animation: true, vertexColors: true | `tests/model/iqm.luau` | | model | ldraw | .ldr .mpd .dat | yes | - | materials: true, lines: true, instancing: true | `tests/model/ldraw.luau` | | model | lwo | .lwo .lxo | yes | - | materials: true, polygons: true, vertexColors: true, morphTargets: true | `tests/model/lwo.luau` | +| model | map | .map | yes | yes | variants: "quake", "valve220", "quake2", "quake3", patches: true | `tests/model/map.luau` | | model | mca | .mca .mcr | yes | - | voxels: true, blocks: true | `tests/model/mca.luau` | | model | md2 | .md2 | yes | - | morph: true, animation: true | `tests/model/md2.luau` | | model | md3 | .md3 | yes | - | morph: true, animation: true, tags: true | `tests/model/md3.luau` | @@ -240,7 +241,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. @@ -249,11 +251,13 @@ 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/DoomMap: Doom / Heretic / Hexen binary map lumps (Hexen when BEHAVIOR is present) and UDMF TEXTMAP to - 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 bc6b9ee..f09e0f9 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 Lexer Nbt Text Url Xml font/ Bitmap Cff GlyphNames TrueType - model/ DoomMap Draco Mat4 MeshFlatten Minecraft Polygon Rbx Rig Sampler Vrml + model/ Brush DoomMap 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 @@ -244,6 +244,8 @@ them. Anything generic goes down a layer and is called: | polygons with holes -> triangles | `codecs/model/Polygon` | | Doom-engine maps (binary lumps, UDMF) -> tables and a Scene | `codecs/model/DoomMap` | | C-style tokens (id Tech / UDMF text: comments, strings, numbers, words) | `codecs/text/Lexer` | +| 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 e2d2479..e98cca5 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") @@ -818,6 +818,18 @@ local list: { Entry } = { return require("@rosetta/model/lwo") end, }, + { + name = "map", + category = "model", + path = "model/map", + extensions = { "map" }, + mime = { "text/x-quake-map" }, + deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Miptex", "codecs/model/Brush", "codecs/model/Patch" }, + caps = { decode = true, encode = true, variants = { "quake", "valve220", "quake2", "quake3" }, patches = true }, + load = function() + return require("@rosetta/model/map") + end, + }, { name = "mca", category = "model", 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/src/Rosetta/model/map/Build.luau b/src/Rosetta/model/map/Build.luau new file mode 100644 index 0000000..cde0d0a --- /dev/null +++ b/src/Rosetta/model/map/Build.luau @@ -0,0 +1,241 @@ +--!strict +-- model/map/Build: parsed entities -> Scene: brushes through codecs/model/Brush, patches through codecs/model/Patch, +-- a mesh per entity with brushes, a primitive per texture, entities as nodes (keys in extras), z up, map units. +local Types = require("@rosetta/Types") +local Brush = require("@rosetta/codecs/model/Brush") +local Patch = require("@rosetta/codecs/model/Patch") +local Parse = require("@rosetta/model/map/Parse") + +local Build = {} + +local Scene = Types.Scene +local writef32, writeu32 = buffer.writef32, buffer.writeu32 + +export type Options = { + variant: string, -- "quake" | "valve220" | "quake2" | "quake3" + size: (name: string) -> (number, number, boolean), -- width, height, known + hull: boolean?, + merge: boolean?, + epsilon: number?, + patchLevel: number?, + skip: { string }?, + maxPolygons: number?, +} + +function Build.face(f: Parse.Face): Brush.Face? + local p = f.points + 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 out: Brush.Face = { plane = plane, texture = f.texture } + if f.matrix then + out.bp = f.matrix + elseif f.u and f.v then + local sc = f.scale or { 1, 1 } + out.vecs = Brush.valveVecs(f.u, f.v, sc[1], sc[2]) + else + local o, sc = f.offset or { 0, 0 }, f.scale or { 1, 1 } + out.vecs = Brush.quakeVecs(plane, o[1], o[2], f.rotation or 0, sc[1], sc[2]) + end + return out +end + +type Acc = { pos: { number }, nrm: { number }, uv: { number }, idx: { number } } + +local function patchPrim(b: Parse.Brush, level: number, acc: Acc): boolean + local size, pts = b.size :: { number }, b.points :: { number } + local w: number, h: number = size[1] :: number, size[2] :: number + if not Patch.valid(w, h, #pts // 5) then + return false + end + -- file order is column by column (q3map2 ParsePatch: verts[i * width + j] for column j, point i) + local ctrl = table.create(w * h * 5, 0) :: { number } + for j = 0, w - 1 do + for i = 0, h - 1 do + table.move(pts, (j * h + i) * 5 + 1, (j * h + i) * 5 + 5, (i * w + j) * 5 + 1, ctrl) + end + end + local params: { number } = b.params or {} + local explicit = b.type == "patchDef3" + local lu: number = if explicit then math.max(1, params[1] or 1) else level + local lv: number = if explicit then math.max(1, params[2] or 1) else level + local g, gw, gh = Patch.grid(ctrl, w, h, 5, lu, lv) + if not g then + return false + end + local nrm = Patch.normals(g, 5, gw, gh) + local base = #acc.pos // 3 + for k = 0, gw * gh - 1 do + local o = k * 5 + table.insert(acc.pos, g[o + 1]) + table.insert(acc.pos, g[o + 2]) + table.insert(acc.pos, g[o + 3]) + table.insert(acc.uv, g[o + 4]) + table.insert(acc.uv, g[o + 5]) + table.insert(acc.nrm, nrm[k * 3 + 1]) + table.insert(acc.nrm, nrm[k * 3 + 2]) + table.insert(acc.nrm, nrm[k * 3 + 3]) + end + for _, v in Patch.triangles(gw, gh) do + table.insert(acc.idx, base + v) + end + return true +end + +local function primitive(a: Acc): Types.Primitive + 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 + return { + attributes = { POSITION = Scene.accessor(pb, "f32", 3, nv), NORMAL = Scene.accessor(nb, "f32", 3, nv), TEXCOORD_0 = Scene.accessor(ub, "f32", 2, nv) }, + indices = Scene.accessor(ib, "u32", 1, ni), + mode = "triangles", + } +end + +local function vec3(s: string?): { number }? + if not s then + return nil + end + local x, y, z = string.match(s, "^%s*(%S+)%s+(%S+)%s+(%S+)") + local a, b, c = tonumber(x), tonumber(y), tonumber(z) + if a and b and c then + return { a, b, c } + end + return nil +end + +function Build.scene(map: Parse.Map, o: Options): (Types.Scene?, string?) + local scene = Scene.new() + scene.meta.up = "z" + local skip: { [string]: boolean } = {} + for _, n in o.skip or {} do + skip[string.lower(n)] = true + end + local matOf: { [string]: number } = {} + local function material(name: string): number + local m = matOf[name] + if m then + return m + end + local w, h, known = o.size(name) + local uri = name + if o.variant == "quake2" then + uri = "textures/" .. name .. ".wal" + elseif o.variant == "quake3" then + uri = "textures/" .. name + end + table.insert(scene.textures, { name = name, uri = uri }) + local mat = Scene.material(name) + mat.metallic = 0 + mat.baseColorTexture = { texture = #scene.textures } + mat.extras = { map = { width = w, height = h, sizeKnown = known } } + table.insert(scene.materials, mat) + matOf[name] = #scene.materials + return #scene.materials + end + local root: Types.Node = { name = "map", children = {} } + table.insert(scene.nodes, root) + scene.roots[1] = 1 + local skipped = { faces = 0, patches = 0 } + local counts = { brushes = 0, patches = 0 } + local entities: { { [string]: string } } = {} + local polyTotal = 0 + for ei, ent in map.entities do + local keys = ent.keys + table.insert(entities, keys) + local node: Types.Node = { name = keys.targetname or keys.classname or ("entity " .. (ei - 1)), children = {}, + extras = { classname = keys.classname, keys = keys, brushes = ent.brushes, entity = ei - 1 } } + local brushes: { { Brush.Face } } = {} + local patchAcc: { [string]: Acc } = {} + local patchOrder: { string } = {} + for _, b in ent.brushes do + if b.faces then + counts.brushes += 1 + local faces: { Brush.Face } = {} + for _, f in b.faces do + local bf = Build.face(f) + if bf then + table.insert(faces, bf) + else + skipped.faces += 1 + end + end + table.insert(brushes, faces) + else + counts.patches += 1 + local tex = b.texture or "" + if not skip[string.lower(tex)] then + local acc = patchAcc[tex] + if not acc then + acc = { pos = {}, nrm = {}, uv = {}, idx = {} } + patchAcc[tex] = acc + table.insert(patchOrder, tex) + end + if not patchPrim(b, o.patchLevel or 4, acc :: Acc) then + skipped.patches += 1 + end + end + end + end + local prims: { Types.Primitive } = {} + if #brushes > 0 then + local polys, err = Brush.polygons(brushes, { hull = o.hull, merge = o.merge, epsilon = o.epsilon, maxPolygons = o.maxPolygons }) + if not polys then + return nil, err + end + polyTotal += #polys + if polyTotal > (o.maxPolygons or 2 ^ 20) then + return nil, "limit: too many polygons" + end + local kept: { Brush.Polygon } = {} + for _, p in polys do + local t = brushes[p.brush][p.face].texture or "" + if not skip[string.lower(t)] then + table.insert(kept, p) + end + end + local built = Brush.primitives(kept, brushes, function(name: string): (number, number) + local m = scene.materials[material(name)] + local e = (m.extras :: any).map + return e.width, e.height + end) + for _, bt in built do + bt.primitive.material = material(bt.texture) + table.insert(prims, bt.primitive) + end + end + for _, tex in patchOrder do + local acc = patchAcc[tex] + if #acc.idx > 0 then + local prim = primitive(acc) + prim.material = material(tex) + table.insert(prims, prim) + end + end + if #prims > 0 then + table.insert(scene.meshes, { name = node.name, primitives = prims }) + node.mesh = #scene.meshes + elseif #ent.brushes == 0 then + node.translation = vec3(keys.origin) + end + table.insert(scene.nodes, node) + table.insert(root.children, #scene.nodes) + end + scene.meta.entities = entities + scene.meta.skipped = skipped + scene.meta.counts = counts + return scene, nil +end + +return Build diff --git a/src/Rosetta/model/map/Parse.luau b/src/Rosetta/model/map/Parse.luau new file mode 100644 index 0000000..cc18e3a --- /dev/null +++ b/src/Rosetta/model/map/Parse.luau @@ -0,0 +1,383 @@ +--!strict +-- model/map/Parse: .map text -> entities (key / value pairs in order, brushes and patches as written). Grammar of the +-- Quake / Quake II / Half-Life (Valve 220) / Quake III editors (qbsp / q3map2 map parsers; no code taken). +local Types = require("@rosetta/Types") + +local Parse = {} + +export type Face = { + points: { number }, -- 3 points: x, y, z each + texture: string, + offset: { number }?, -- Quake standard: x, y offset + rotation: number?, -- standard / Valve 220 (degrees) + scale: { number }?, -- standard / Valve 220 + u: { number }?, -- Valve 220: axis x, y, z, offset + v: { number }?, + matrix: { { number } }?, -- Quake III brush primitives: 2 x 3 + flags: { number }?, -- trailing numbers: Quake II / III contents, surface flags, value (Hexen II: light) +} +export type Brush = { + type: string, -- "brush" | "brushDef" | "patchDef2" | "patchDef3" + faces: { Face }?, + texture: string?, -- patches + size: { number }?, -- patches: width, height (columns, points per column as written) + params: { number }?, -- patches: the header numbers after width, height + points: { number }?, -- patches: 5 numbers (x, y, z, s, t) per control point, in file order (column by column) +} +export type Entity = { keys: { [string]: string }, brushes: { Brush } } -- keys: an ordered object (Types.object) +export type Map = { entities: { Entity }, game: string?, mapFormat: string?, comments: { string } } + +type St = { s: string, pos: number, n: number, comments: { string } } + +local function skip(st: St) + local s = st.s + while true do + local p = string.find(s, "[^%s]", st.pos) + if not p then + st.pos = st.n + 1 + return + end + if string.sub(s, p, p + 1) == "//" then + local e = string.find(s, "\n", p, true) or st.n + table.insert(st.comments, (string.gsub(string.sub(s, p + 2, e), "^%s*(.-)%s*$", "%1"))) + st.pos = e + 1 + else + st.pos = p + return + end + end +end + +local function peek(st: St): string + skip(st) + return string.sub(st.s, st.pos, st.pos) +end + +local function expect(st: St, c: string): string? + if peek(st) ~= c then + return "expected '" .. c .. "' at " .. (st.pos - 1) + end + st.pos += 1 + return nil +end + +local function word(st: St): string? + skip(st) + local a, b = string.find(st.s, "^[^%s]+", st.pos) + if not a then + return nil + end + st.pos = (b :: number) + 1 + return string.sub(st.s, a, b) +end + +local function number(st: St): number? + skip(st) + local a, b = string.find(st.s, "^[^%s%(%)%[%]{}]+", st.pos) + if not a then + return nil + end + local v = tonumber(string.sub(st.s, a, b)) + if v then + st.pos = (b :: number) + 1 + end + return v +end + +local function quoted(st: St): string? + if peek(st) ~= '"' then + return nil + end + local e = string.find(st.s, '"', st.pos + 1, true) + if not e then + return nil + end + local v = string.sub(st.s, st.pos + 1, e - 1) + st.pos = e + 1 + return v +end + +local function numbers(st: St, n: number, out: { number }): string? + for _ = 1, n do + local v = number(st) + if not v then + return "expected a number at " .. (st.pos - 1) + end + table.insert(out, v) + end + return nil +end + +local function vec(st: St, n: number, open: string, close: string): ({ number }?, string?) + local e = expect(st, open) + if e then + return nil, e + end + local out = {} + e = numbers(st, n, out) + if e then + return nil, e + end + e = expect(st, close) + if e then + return nil, e + end + return out, nil +end + +local function trailing(st: St): { number }? + local out: { number } = {} + while true do + local c = peek(st) + if not string.match(c, "[%d%-%+%.]") then + break + end + local v = number(st) + if not v then + break + end + table.insert(out, v) + end + return if #out > 0 then out else nil +end + +local function plane(st: St): ({ number }?, string?) + local pts: { number } = {} + for _ = 1, 3 do + local p, e = vec(st, 3, "(", ")") + if not p then + return nil, e + end + table.move(p, 1, 3, #pts + 1, pts) + end + return pts, nil +end + +local function face(st: St, bp: boolean): (Face?, string?) + local pts, e = plane(st) + if not pts then + return nil, e + end + local f: Face = { points = pts, texture = "" } + if bp then + e = expect(st, "(") + if e then + return nil, e + end + local r1, e1 = vec(st, 3, "(", ")") + if not r1 then + return nil, e1 + end + local r2, e2 = vec(st, 3, "(", ")") + if not r2 then + return nil, e2 + end + e = expect(st, ")") + if e then + return nil, e + end + f.matrix = { r1, r2 } + end + local tex = word(st) + if not tex then + return nil, "expected a texture name at " .. (st.pos - 1) + end + f.texture = tex + if not bp then + if peek(st) == "[" then + local u, eu = vec(st, 4, "[", "]") + if not u then + return nil, eu + end + local v, ev = vec(st, 4, "[", "]") + if not v then + return nil, ev + end + local rest = {} + e = numbers(st, 3, rest) + if e then + return nil, e + end + f.u, f.v, f.rotation, f.scale = u, v, rest[1], { rest[2], rest[3] } + else + local rest = {} + e = numbers(st, 5, rest) + if e then + return nil, e + end + f.offset, f.rotation, f.scale = { rest[1], rest[2] }, rest[3], { rest[4], rest[5] } + end + end + f.flags = trailing(st) + return f, nil +end + +local function patch(st: St, kind: string, maxPoints: number): (Brush?, string?) + local e = expect(st, "{") + if e then + return nil, e + end + local tex = word(st) + if not tex then + return nil, "expected a patch texture" + end + local hn = if kind == "patchDef3" then 7 else 5 + local head, eh = vec(st, hn, "(", ")") + if not head then + return nil, eh + end + local w, h = head[1], head[2] + if w ~= math.floor(w) or h ~= math.floor(h) or w < 1 or h < 1 or w * h > maxPoints then + return nil, "bad patch size " .. w .. " x " .. h + end + local pts: { number } = {} + e = expect(st, "(") + if e then + return nil, e + end + for _ = 1, w do + e = expect(st, "(") + if e then + return nil, e + end + for _ = 1, h do + local p, ep = vec(st, 5, "(", ")") + if not p then + return nil, ep + end + table.move(p, 1, 5, #pts + 1, pts) + end + e = expect(st, ")") + if e then + return nil, e + end + end + e = expect(st, ")") + if e then + return nil, e + end + e = expect(st, "}") + if e then + return nil, e + end + return { type = kind, texture = tex, size = { w, h }, params = { table.unpack(head, 3) }, points = pts }, nil +end + +local function brush(st: St, maxPoints: number): (Brush?, string?) + local c = peek(st) + if c == "(" then + local faces: { Face } = {} + while peek(st) == "(" do + local f, e = face(st, false) + if not f then + return nil, e + end + table.insert(faces, f) + end + local e = expect(st, "}") + if e then + return nil, e + end + return { type = "brush", faces = faces }, nil + end + if c == "}" then + st.pos += 1 + return { type = "brush", faces = {} }, nil + end + local kw = word(st) + local out: any, err: string? + if kw == "brushDef" then + local e = expect(st, "{") + if e then + return nil, e + end + local faces: { Face } = {} + while peek(st) == "(" do + local f, ef = face(st, true) + if not f then + return nil, ef + end + table.insert(faces, f) + end + e = expect(st, "}") + if e then + return nil, e + end + out = { type = "brushDef", faces = faces } + elseif kw == "patchDef2" or kw == "patchDef3" then + out, err = patch(st, kw, maxPoints) + if not out then + return nil, err + end + elseif kw == "brushDef3" then + return nil, "unsupported: Doom 3 / Quake 4 brushDef3" + else + return nil, "unexpected '" .. tostring(kw) .. "' in a brush at " .. (st.pos - 1) + end + local e = expect(st, "}") + if e then + return nil, e + end + return out, nil +end + +function Parse.parse(s: string, maxBrushes: number?): (Map?, string?, number?) + local st: St = { s = s, pos = 1, n = #s, comments = {} } + if string.sub(s, 1, 3) == "\239\187\191" then + st.pos = 4 + end + local limit = maxBrushes or 2 ^ 20 + local count = 0 + local ents: { Entity } = {} + while peek(st) ~= "" do + local at = st.pos - 1 + local e = expect(st, "{") + if e then + return nil, e, at + end + local keys: { [string]: string } = {} + local order: { string } = {} + local brushes: { Brush } = {} + while true do + local c = peek(st) + if c == "}" then + st.pos += 1 + break + elseif c == '"' then + local k = quoted(st) + local v = quoted(st) + if not k or not v then + return nil, "bad key / value at " .. (st.pos - 1), st.pos - 1 + end + if keys[k] == nil then + table.insert(order, k) + end + keys[k] = v + elseif c == "{" then + st.pos += 1 + local b, eb = brush(st, limit) + if not b then + return nil, eb, st.pos - 1 + end + count += 1 + if count > limit then + return nil, "limit: too many brushes", st.pos - 1 + end + table.insert(brushes, b) + elseif c == "" then + return nil, "truncated entity", st.pos - 1 + else + return nil, "unexpected '" .. c .. "' in an entity at " .. (st.pos - 1), st.pos - 1 + end + end + table.insert(ents, { keys = Types.object(keys, order) :: { [string]: string }, brushes = brushes }) + end + local game, fmt + for _, c in st.comments do + game = game or string.match(c, "^Game:%s*(.-)%s*$") + fmt = fmt or string.match(c, "^Format:%s*(.-)%s*$") + end + return { entities = ents, game = game, mapFormat = fmt, comments = st.comments }, nil, nil +end + +return Parse diff --git a/src/Rosetta/model/map/Write.luau b/src/Rosetta/model/map/Write.luau new file mode 100644 index 0000000..47ce084 --- /dev/null +++ b/src/Rosetta/model/map/Write.luau @@ -0,0 +1,144 @@ +--!strict +-- model/map/Write: entities (model/map/Parse's layout) -> .map text in the editors' layout (TrenchBroom / Radiant: +-- one face per line, numbers in their shortest exact form). +local Types = require("@rosetta/Types") +local Parse = require("@rosetta/model/map/Parse") + +local Write = {} + +function Write.num(x: number): string + if x ~= x or x == math.huge or x == -math.huge then + return "0" + end + if x == math.floor(x) and math.abs(x) < 2 ^ 53 then + return string.format("%d", x) + end + for p = 6, 17 do + local s = string.format("%." .. p .. "g", x) + if tonumber(s) == x then + return s + end + end + return string.format("%.17g", x) +end + +local function nums(t: { number }, a: number, b: number): string + local out = table.create(b - a + 1) :: { string } + for i = a, b do + out[#out + 1] = Write.num(t[i] or 0) + end + return table.concat(out, " ") +end + +local function faceLine(f: Parse.Face, bp: boolean): (string?, string?) + local p = f.points + if type(p) ~= "table" or #p < 9 or type(f.texture) ~= "string" or f.texture == "" or string.find(f.texture, "%s") then + return nil, "a face needs 9 point numbers and a texture name without spaces" + end + local parts: { string } = { "( " .. nums(p, 1, 3) .. " ) ( " .. nums(p, 4, 6) .. " ) ( " .. nums(p, 7, 9) .. " )" } + if bp then + local m = f.matrix + if not m or not m[1] or not m[2] then + return nil, "a brushDef face needs a texture matrix" + end + table.insert(parts, "( ( " .. nums(m[1], 1, 3) .. " ) ( " .. nums(m[2], 1, 3) .. " ) )") + table.insert(parts, f.texture) + elseif f.u and f.v then + local sc = f.scale or { 1, 1 } + table.insert(parts, f.texture) + table.insert(parts, "[ " .. nums(f.u, 1, 4) .. " ] [ " .. nums(f.v, 1, 4) .. " ] " .. Write.num(f.rotation or 0) .. " " .. nums(sc, 1, 2)) + else + local o, sc = f.offset or { 0, 0 }, f.scale or { 1, 1 } + table.insert(parts, f.texture) + table.insert(parts, nums(o, 1, 2) .. " " .. Write.num(f.rotation or 0) .. " " .. nums(sc, 1, 2)) + end + if f.flags and #f.flags > 0 then + table.insert(parts, nums(f.flags, 1, #f.flags)) + end + return table.concat(parts, " "), nil +end + +local function patchText(b: Parse.Brush, out: { string }): string? + local size, pts = b.size, b.points + if not size or not pts or type(b.texture) ~= "string" then + return "a patch needs a texture, a size and control points" + end + local w, h = size[1], size[2] + if #pts < w * h * 5 then + return "a patch needs width * height * 5 control numbers" + end + local params = b.params or {} + local nParams = if b.type == "patchDef3" then 5 else 3 + table.insert(out, b.type) + table.insert(out, "{") + table.insert(out, b.texture) + table.insert(out, "( " .. Write.num(w) .. " " .. Write.num(h) .. " " .. nums(params, 1, nParams) .. " )") + table.insert(out, "(") + for i = 0, w - 1 do + local row = { "(" } + for j = 0, h - 1 do + local o = (i * h + j) * 5 + table.insert(row, "( " .. nums(pts, o + 1, o + 5) .. " )") + end + table.insert(row, ")") + table.insert(out, table.concat(row, " ")) + end + table.insert(out, ")") + table.insert(out, "}") + return nil +end + +function Write.text(map: Parse.Map): (string?, string?) + local out: { string } = {} + if map.game then + table.insert(out, "// Game: " .. map.game) + end + if map.mapFormat then + table.insert(out, "// Format: " .. map.mapFormat) + end + for ei, ent in map.entities do + table.insert(out, "// entity " .. (ei - 1)) + table.insert(out, "{") + for _, k in Types.keys(ent.keys) do + local v = ent.keys[k] + if v ~= nil then + if string.find(k, '"', 1, true) or string.find(tostring(v), '"', 1, true) or string.find(k, "[\r\n]") or string.find(tostring(v), "[\r\n]") then + return nil, "keys and values cannot hold quotes or line breaks: " .. k + end + table.insert(out, '"' .. k .. '" "' .. tostring(v) .. '"') + end + end + for bi, b in ent.brushes or {} do + table.insert(out, "// brush " .. (bi - 1)) + table.insert(out, "{") + if b.type == "patchDef2" or b.type == "patchDef3" then + local e = patchText(b, out) + if e then + return nil, e + end + else + local bp = b.type == "brushDef" + if bp then + table.insert(out, "brushDef") + table.insert(out, "{") + end + for _, f in b.faces or {} do + local line, e = faceLine(f, bp) + if not line then + return nil, e + end + table.insert(out, line) + end + if bp then + table.insert(out, "}") + end + end + table.insert(out, "}") + end + table.insert(out, "}") + end + table.insert(out, "") + return table.concat(out, "\n"), nil +end + +return Write diff --git a/src/Rosetta/model/map/init.luau b/src/Rosetta/model/map/init.luau new file mode 100644 index 0000000..10b6841 --- /dev/null +++ b/src/Rosetta/model/map/init.luau @@ -0,0 +1,315 @@ +--!strict +-- model/map: editor .map files of Quake, Half-Life (Valve 220), Quake II (surface / content flags) and Quake III +-- (brushDef brush primitives, patchDef2; patchDef3 meshes), read and write. Grammar of the qbsp / q3map2 parsers (no +-- code taken). Brushes become polygons through codecs/model/Brush (optionally CSG'd and merged), patches through +-- codecs/model/Patch; a mesh per entity with brushes; entities as nodes with their keys in extras. Texture sizes from +-- opts.textureSizes, the worldspawn's WADs, .wal files or images through resolve; else 64 x 64. Not supported: Doom 3 +-- brushDef3, Build engine maps (binary: model/buildmap), compiling (no BSP, vis or light). + +-- ------------------------------------------------------------------------------------------------ requires +local Err = require("@rosetta/core/Err") +local Bytes = require("@rosetta/core/Bytes") +local Input = require("@rosetta/core/Input") +local Types = require("@rosetta/Types") +local Miptex = require("@rosetta/codecs/image/Miptex") +local Brush = require("@rosetta/codecs/model/Brush") +local Parse = require("@rosetta/model/map/Parse") +local Write = require("@rosetta/model/map/Write") +local Build = require("@rosetta/model/map/Build") + +-- ------------------------------------------------------------------------------------------------ contract +local Map = { + name = "map", + category = "model", + extensions = { "map" }, + mime = { "text/x-quake-map" }, + deps = { "core/Err", "core/Bytes", "core/Input", "Types", "codecs/image/Miptex", "codecs/model/Brush", "codecs/model/Patch" }, + caps = { decode = true, encode = true, variants = { "quake", "valve220", "quake2", "quake3" }, patches = true }, +} + +-- ------------------------------------------------------------------------------------------------ types +export type DecodeOptions = { + hull: boolean?, -- drop faces inside / touching other brushes of the same entity, default false + merge: boolean?, -- merge coplanar faces with the same texture projection, default false + epsilon: number?, -- default 1e-3 + patchLevel: number?, -- patchDef2 segments per sub-patch, default 4 + skip: { string }?, -- texture names left out of the meshes ("clip", "skip", "common/caulk", ...) + textureSizes: { [string]: { number } }?, -- name -> { width, height } + resolve: ((uri: string) -> (buffer | string)?)?, + files: { [string]: buffer | string }?, + decodeImage: ((buf: buffer) -> (Types.Image?, Err.Err?))?, -- Quake III: texture image sizes + maxBrushes: number?, -- default 2^20 + maxPolygons: number?, -- default 2^20 +} +export type EncodeOptions = { + variant: string?, -- "valve220" converts Quake standard faces to Valve 220 axes; default: as stored +} + +-- ------------------------------------------------------------------------------------------------ sniff +function Map.sniff(r: Bytes.Reader): number + local head = r:peek(math.min(r:remaining(), 4096)) + if #head < 2 or string.find(head, "[%z\1-\8\14-\31]") then + return 0 + end + if string.sub(head, 1, 3) == "\239\187\191" then + head = string.sub(head, 4) + end + local s = head + local game = false + while true do + local c = string.match(s, "^%s*//[^\n]*\n?()") + if not c then + break + end + if string.match(s, "^%s*//%s*Game:") then + game = true + end + s = string.sub(s, c :: number) + end + local body = string.match(s, '^%s*{%s*"[^"\n]*"%s*"') or string.match(s, "^%s*{%s*{%s*[%(bp]") + if not body then + return if game and string.match(s, "^%s*{") then 0.6 else 0 + end + return if game or string.find(head, '"classname"', 1, true) then 0.9 else 0.6 +end + +-- ------------------------------------------------------------------------------------------------ decode +local function variantOf(m: Parse.Map): string + local game = string.lower(m.game or "") + local fmt = string.lower(m.mapFormat or "") + local q2, valve, q3 = false, false, false + for _, e in m.entities do + if e.keys.mapversion == "220" then + valve = true + end + for _, b in e.brushes do + if b.type ~= "brush" then + q3 = true + end + for _, f in b.faces or {} do + if f.u then + valve = true + elseif f.flags and #f.flags >= 3 then + q2 = true + end + end + end + end + if q3 or string.find(game, "quake 3") or string.find(game, "quake iii") or fmt == "quake3" or fmt == "quake3 (valve)" then + return "quake3" + end + if string.find(game, "quake 2") or string.find(game, "quake ii") or fmt == "quake2" or fmt == "quake2 (valve)" then + return "quake2" + end + if valve or fmt == "valve" then + return "valve220" + end + return if q2 then "quake2" else "quake" +end + +local function sizer(m: Parse.Map, variant: string, opts: DecodeOptions?): (name: string) -> (number, number, boolean) + local cache: { [string]: { number } } = {} + local wads: { { buf: buffer, lumps: { Miptex.Lump } } }? = nil + local function loadWads(): { { buf: buffer, lumps: { Miptex.Lump } } } + local list = {} + local ws = m.entities[1] and m.entities[1].keys + local spec = ws and (ws.wad or ws._wad) or "" + for path in string.gmatch(spec, "[^;]+") do + local p = string.gsub(path, "\\", "/") + local b = Input.sibling(opts, p) or Input.sibling(opts, string.match(p, "([^/]+)$") or p) + if b then + local lumps = Miptex.wad(b, 0, buffer.len(b)) + if lumps then + table.insert(list, { buf = b, lumps = lumps }) + end + end + end + return list + end + return function(name: string): (number, number, boolean) + local c = cache[name] + if c then + return c[1], c[2], c[3] == 1 + end + local w: number, h: number = 0, 0 + local given = opts and opts.textureSizes and opts.textureSizes[name] + if type(given) == "table" and type(given[1]) == "number" and type(given[2]) == "number" then + w, h = given[1] :: number, given[2] :: number + elseif variant == "quake" or variant == "valve220" then + wads = wads or loadWads() + for i = #(wads :: any), 1, -1 do + local wd = (wads :: any)[i] + local l = Miptex.find(wd.lumps, name) + if l then + local hd = Miptex.header(wd.buf, l.offset, l.disksize) + if hd then + w, h = hd.width, hd.height + break + end + end + end + elseif variant == "quake2" then + local wal = Input.sibling(opts, "textures/" .. name .. ".wal") + if wal and buffer.len(wal) >= 40 then + w, h = buffer.readu32(wal, 32), buffer.readu32(wal, 36) + end + elseif opts and opts.decodeImage then + for _, ext in { ".tga", ".jpg", ".png" } do + local b = Input.sibling(opts, "textures/" .. name .. ext) + if b then + local ok, img = pcall(opts.decodeImage :: any, b) + if ok and img then + w, h = img.width, img.height + break + end + end + end + end + local fw: number, fh: number = w :: number, h :: number + local known = fw > 0 and fh > 0 + if not known then + fw, fh = 64, 64 + end + cache[name] = { fw, fh, if known then 1 else 0 } + return fw, fh, known + end +end + +function Map.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?) + local text = buffer.readstring(r.buf, r.base, r.limit - r.base) + local m, msg, at = Parse.parse(text, opts and opts.maxBrushes) + if not m then + return nil, Err.from(msg, at) + end + if #m.entities == 0 then + return nil, Err.new(Err.CORRUPT, "no entities", 0) + end + local variant = variantOf(m) + local scene, err = Build.scene(m, { + variant = variant, + size = sizer(m, variant, opts), + hull = opts and opts.hull, + merge = opts and opts.merge, + epsilon = opts and opts.epsilon, + patchLevel = opts and opts.patchLevel, + skip = opts and opts.skip, + maxPolygons = opts and opts.maxPolygons, + }) + if not scene then + return nil, Err.from(err) + end + local counts = scene.meta.counts + scene.meta.counts = nil + scene.meta.source = { format = "map", variant = variant, game = m.game, mapFormat = m.mapFormat, entities = #m.entities, brushes = counts.brushes, patches = counts.patches } + return scene, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +local function toValve(f: Parse.Face): Parse.Face + if f.u or f.matrix then + return f + end + local bf = Build.face(f) + if not bf or not bf.vecs then + return f + end + local v = bf.vecs + local out = table.clone(f) + out.offset = nil + out.u, out.v = { v[1][1], v[1][2], v[1][3], v[1][4] }, { v[2][1], v[2][2], v[2][3], v[2][4] } + out.rotation, out.scale = 0, { 1, 1 } + return out +end + +local function fmtNum(x: number): string + return Write.num(x) +end + +function Map.encode(scene: Types.Scene, opts: EncodeOptions?): (buffer?, Err.Err?) + if type(scene) ~= "table" or type(scene.nodes) ~= "table" then + return nil, Err.new(Err.ARG, "expected a Scene") + end + local valve = opts and opts.variant == "valve220" + local ents: { any } = {} + for _, node in scene.nodes do + local ex: any = node.extras + if type(ex) == "table" and type(ex.keys) == "table" then + local keys = ex.keys + local brushes: { Parse.Brush } = if type(ex.brushes) == "table" then ex.brushes else {} + if node.translation and keys.origin and #brushes == 0 then + local t = node.translation + keys = Types.object(table.clone(keys), Types.keys(keys)) + keys.origin = fmtNum(t[1]) .. " " .. fmtNum(t[2]) .. " " .. fmtNum(t[3]) + end + if valve then + local conv: { Parse.Brush } = {} + for _, b in brushes do + if b.faces then + local nb = table.clone(b) + local faces = {} + for i, f in b.faces do + faces[i] = toValve(f) + end + nb.faces = faces + table.insert(conv, nb) + else + table.insert(conv, b) + end + end + brushes = conv + if #ents == 0 and keys.mapversion ~= "220" then + keys = Types.object(table.clone(keys), Types.keys(keys)) + Types.set(keys, "mapversion", "220") + end + end + table.insert(ents, { keys = keys, brushes = brushes }) + end + end + if #ents == 0 then + return nil, Err.new(Err.ARG, "no map entities (nodes with extras.keys, as model/map loads them)") + end + local src: any = scene.meta and scene.meta.source + local fromMap = type(src) == "table" and src.format == "map" + local text, err = Write.text({ + entities = ents :: { Parse.Entity }, + game = if fromMap then src.game else nil, + mapFormat = if valve then "Valve" elseif fromMap then src.mapFormat else nil, + comments = {}, + }) + if not text then + return nil, Err.new(Err.ARG, err or "bad entity") + end + return buffer.fromstring(text), nil +end + +-- ------------------------------------------------------------------------------------------------ extras +-- the entities as parsed: { entities = { { keys, brushes } }, game, mapFormat } +function Map.parse(src: buffer | string): (Parse.Map?, Err.Err?) + local text = if type(src) == "buffer" then buffer.tostring(src) elseif type(src) == "string" then src else nil + if not text then + return nil, Err.new(Err.ARG, "expected a buffer or a string") + end + local m, msg, at = Parse.parse(text) + if not m then + return nil, Err.from(msg, at) + end + return m, nil +end + +function Map.write(m: Parse.Map): (string?, Err.Err?) + if type(m) ~= "table" or type(m.entities) ~= "table" then + return nil, Err.new(Err.ARG, "expected { entities = ... }") + end + local text, err = Write.text(m) + if not text then + return nil, Err.new(Err.ARG, err or "bad entity") + end + return text, nil +end + +-- a parsed face -> its Brush face (plane and projection): Brush.uv / Brush.polygons take it +function Map.face(f: Parse.Face): Brush.Face? + return Build.face(f) +end + +return Map 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/tests/model/map.luau b/tests/model/map.luau new file mode 100644 index 0000000..1710320 --- /dev/null +++ b/tests/model/map.luau @@ -0,0 +1,325 @@ +-- model/map tests: Quake / Valve 220 / Quake II / Quake III .map files against ericw-tools qbsp (CSG'd face area per +-- plane and texture coordinates at every compiled corner, per entity), texture sizes from WAD2 / WAD3 / .wal through +-- files, the patchDef2 against a Bezier evaluation, entities as nodes, write round trips, errors, the fuzz pass. +-- Fixtures: tools/fixtures/map.py. +local T = require("@tests/T") +local F = require("@rosetta") +local MapFmt = require("@rosetta/model/map") +local Bytes = require("@rosetta/core/Bytes") +local Err = require("@rosetta/core/Err") +local Types = require("@rosetta/Types") +local Fx = require("@tests/gen/map") + +local t = T.suite("map") +t:eq(MapFmt.name, "map", "name") + +local function r(x: number, k: number): number + return math.floor(x * k + 0.5) +end +local function key(nx: number, ny: number, nz: number, d: number): string + return string.format("%d %d %d %d", r(nx, 1000), r(ny, 1000), r(nz, 1000), r(d, 100)) +end + +type Tri = { p: { number }, uv: { number }, n: { number }, tex: string } + +local function triangles(s: any, mesh: any): { Tri } + local out: { Tri } = {} + for _, p in mesh.primitives do + local pos = Types.Scene.reader(p.attributes.POSITION) :: any + local uv = Types.Scene.reader(p.attributes.TEXCOORD_0) :: any + local nrm = Types.Scene.reader(p.attributes.NORMAL) :: any + local tex = s.materials[p.material].name + for k = 0, p.indices.count - 1, 3 do + local tri: Tri = { p = {}, uv = {}, n = {}, tex = tex } + for c = 0, 2 do + local v = buffer.readu32(p.indices.data, (k + c) * 4) + for a = 0, 2 do + table.insert(tri.p, pos(v, a)) + end + table.insert(tri.uv, uv(v, 0)) + table.insert(tri.uv, uv(v, 1)) + if c == 0 then + tri.n = { nrm(v, 0), nrm(v, 1), nrm(v, 2) } + end + end + table.insert(out, tri) + end + end + return out +end + +local function area(p: { number }): number + local ux, uy, uz = p[4] - p[1], p[5] - p[2], p[6] - p[3] + local vx, vy, vz = p[7] - p[1], p[8] - p[2], p[9] - p[3] + local cx, cy, cz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + return math.sqrt(cx * cx + cy * cy + cz * cz) / 2 +end + +local function polyArea(p: { number }): number + local a = 0 + for k = 1, #p // 3 - 2 do + a += area({ p[1], p[2], p[3], p[k * 3 + 1], p[k * 3 + 2], p[k * 3 + 3], p[k * 3 + 4], p[k * 3 + 5], p[k * 3 + 6] }) + end + return a +end + +-- barycentric coordinates of x on the triangle's plane (nil when outside) +local function bary(tri: Tri, x: number, y: number, z: number): (number?, number?) + local p = tri.p + local ux, uy, uz = p[4] - p[1], p[5] - p[2], p[6] - p[3] + local vx, vy, vz = p[7] - p[1], p[8] - p[2], p[9] - p[3] + local wx, wy, wz = x - p[1], y - p[2], z - p[3] + local uu, uv, vv = ux * ux + uy * uy + uz * uz, ux * vx + uy * vy + uz * vz, vx * vx + vy * vy + vz * vz + local wu, wv = wx * ux + wy * uy + wz * uz, wx * vx + wy * vy + wz * vz + local den = uu * vv - uv * uv + if den == 0 then + return nil, nil + end + local b = (vv * wu - uv * wv) / den + local c = (uu * wv - uv * wu) / den + local tol = 1e-4 + if b < -tol or c < -tol or b + c > 1 + tol then + return nil, nil + end + return b, c +end + +local function compare(label: string, s: any, model: string, faces: any) + local node + for _, n in s.nodes do + if n.extras and n.extras.entity == tonumber(model) then + node = n + end + end + t:check(node and node.mesh, label .. ": entity " .. model .. " has a mesh") + local tris = {} + for _, tri in triangles(s, s.meshes[node.mesh]) do + if tri.tex ~= "base/curve" then -- the patch: qbsp has no patches + table.insert(tris, tri) + end + end + local ours, theirs = {}, {} + for _, tri in tris do + local n = tri.n + local k = key(n[1], n[2], n[3], n[1] * tri.p[1] + n[2] * tri.p[2] + n[3] * tri.p[3]) + ours[k] = (ours[k] or 0) + area(tri.p) + end + for _, f in faces do + local k = key(f.plane[1], f.plane[2], f.plane[3], f.plane[4]) + theirs[k] = (theirs[k] or 0) + polyArea(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 model %s plane %s: %s vs qbsp %s", label, model, k, tostring(ours[k]), tostring(a)) + end + end + for k in ours do + if not theirs[k] then + bad += 1 + end + end + t:eq(bad, 0, label .. ": model " .. model .. " face area per plane") + local miss, off = 0, 0 + for _, f in faces do + local fk = key(f.plane[1], f.plane[2], f.plane[3], f.plane[4]) + 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] + local s0 = (f.vecs[1] * x + f.vecs[2] * y + f.vecs[3] * z + f.vecs[4]) / f.size[1] + local t0 = (f.vecs[5] * x + f.vecs[6] * y + f.vecs[7] * z + f.vecs[8]) / f.size[2] + local found, best = false, math.huge + for _, tri in tris do + local n = tri.n + if tri.tex == f.tex and key(n[1], n[2], n[3], n[1] * tri.p[1] + n[2] * tri.p[2] + n[3] * tri.p[3]) == fk then + local b, cc = bary(tri, x, y, z) + if b and cc then + found = true + local u = tri.uv[1] + b * (tri.uv[3] - tri.uv[1]) + cc * (tri.uv[5] - tri.uv[1]) + local v = tri.uv[2] + b * (tri.uv[4] - tri.uv[2]) + cc * (tri.uv[6] - tri.uv[2]) + best = math.min(best, math.max(math.abs(u - s0) * f.size[1], math.abs(v - t0) * f.size[2])) + end + end + end + if not found then + miss += 1 + if miss <= 3 then + local on = {} + for _, tri in tris do + local n = tri.n + if key(n[1], n[2], n[3], n[1] * tri.p[1] + n[2] * tri.p[2] + n[3] * tri.p[3]) == fk then + table.insert(on, tri.tex) + end + end + t:note("%s model %s: corner %s %s %s (%s) on %s, ours there: %s", label, model, x, y, z, f.tex, fk, table.concat(on, ",")) + end + elseif best > 0.05 then + off += 1 + end + end + end + t:eq(miss, 0, label .. ": model " .. model .. " every qbsp corner on one of our triangles") + t:eq(off, 0, label .. ": model " .. model .. " texture coordinates match qbsp") +end + +for _, label in { "quake", "valve", "quake2", "quake3" } do + local c = Fx[label] + t:eq(F.detect(c.text), "map", label .. ": F.detect") + local s, err = MapFmt.decode(Bytes.reader(buffer.fromstring(c.text)), { files = c.files, hull = true }) + t:check(s, label .. ": " .. tostring(err)) + local scene = s :: any + t:eq(scene.meta.source.variant, ({ quake = "quake", valve = "valve220", quake2 = "quake2", quake3 = "quake3" } :: any)[label], label .. ": variant") + t:eq(scene.meta.up, "z", label .. ": z up") + for model, faces in c.models do + compare(label, scene, model, faces) + end + -- texture sizes found in the WAD / .wal files (Quake III needs images: 64 x 64 without decodeImage) + for _, m in scene.materials do + local want = c.sizes[m.name] + if want and label ~= "quake3" then + t:check(m.extras.map.width == want[1] and m.extras.map.height == want[2] and m.extras.map.sizeKnown, label .. ": size of " .. m.name) + end + end + -- entities: nodes with their keys in order + t:eq(#scene.meta.entities, 4, label .. ": entities") + local door = scene.nodes[3] + t:eq(door.name, "door1", label .. ": brush entity named by targetname") + t:eq(door.extras.classname, "func_door", label .. ": classname") + t:eq(table.concat(Types.keys(door.extras.keys), ","), "classname,targetname,angle", label .. ": key order") + local start = scene.nodes[4] + t:eq(start.translation and table.concat(start.translation, " "), "-128 -128 24", label .. ": point entity at its origin") + t:check(start.mesh == nil, label .. ": point entity without a mesh") + -- round trip: write, read again, same entities and geometry + local out, eerr = MapFmt.encode(scene) + t:check(out, label .. ": encode " .. tostring(eerr)) + local again = MapFmt.decode(Bytes.reader(out :: buffer), { files = c.files, hull = true }) :: any + t:check(again ~= nil, label .. ": reload") + local a1, a2 = MapFmt.parse(c.text) :: any, MapFmt.parse(out :: buffer) :: any + local same = #a1.entities == #a2.entities + for i, e in a1.entities do + local e2 = a2.entities[i] + same = same and e2 ~= nil and #e.brushes == #e2.brushes + for k, v in e.keys do + same = same and e2.keys[k] == v + end + for bi, b in e.brushes do + local b2 = e2.brushes[bi] + same = same and b.type == b2.type and #(b.faces or {}) == #(b2.faces or {}) + for fi, f in b.faces or {} do + local f2 = b2.faces[fi] + same = same and f.texture == f2.texture and table.concat(f.points, " ") == table.concat(f2.points, " ") + for _, fld in { "offset", "scale", "u", "v", "flags" } do + same = same and table.concat((f :: any)[fld] or {}, " ") == table.concat((f2 :: any)[fld] or {}, " ") + end + same = same and f.rotation == f2.rotation + if f.matrix then + same = same and table.concat(f.matrix[1], " ") == table.concat(f2.matrix[1], " ") and table.concat(f.matrix[2], " ") == table.concat(f2.matrix[2], " ") + end + end + if b.points then + same = same and table.concat(b.points, " ") == table.concat(b2.points, " ") + end + end + end + t:check(same, label .. ": write -> parse gives the same entities, brushes and faces") + t:eq(again.meta.source.variant, scene.meta.source.variant, label .. ": variant survives the round trip") + t:eq(#again.meshes, #scene.meshes, label .. ": meshes survive the round trip") +end + +-- the Quake III patch: our grid = the Bezier evaluation +do + local c = Fx.quake3 + local s = MapFmt.decode(Bytes.reader(buffer.fromstring(c.text)), { files = c.files }) :: any + t:eq(s.meta.source.patches, 1, "quake3: one patch") + local prim + for _, p in s.meshes[1].primitives do + if s.materials[p.material].name == "base/curve" then + prim = p + end + end + t:check(prim, "quake3: patch primitive") + local pos = Types.Scene.reader(prim.attributes.POSITION) :: any + local uv = Types.Scene.reader(prim.attributes.TEXCOORD_0) :: any + t:eq(prim.attributes.POSITION.count, c.patch.w * c.patch.h, "quake3: grid size") + local worst = 0 + for k = 0, c.patch.w * c.patch.h - 1 do + for a = 0, 2 do + worst = math.max(worst, math.abs(pos(k, a) - c.patch.grid[k * 5 + a + 1])) + end + worst = math.max(worst, math.abs(uv(k, 0) - c.patch.grid[k * 5 + 4]) * 64, math.abs(uv(k, 1) - c.patch.grid[k * 5 + 5]) * 64) + end + t:check(worst < 1e-4, "quake3: patch points match the Bezier evaluation (" .. worst .. ")") + t:eq(s.textures[s.materials[prim.material].baseColorTexture.texture].uri, "textures/base/curve", "quake3: texture URI") + local lean = MapFmt.decode(Bytes.reader(buffer.fromstring(c.text)), { patchLevel = 1, skip = { "brick" } }) :: any + for _, p in lean.meshes[1].primitives do + t:check(lean.materials[p.material].name ~= "brick", "skip: brick left out") + end +end + +-- options and conversions +do + local c = Fx.quake + local merged = MapFmt.decode(Bytes.reader(buffer.fromstring(c.text)), { files = c.files, hull = true, merge = true }) :: any + local plain = MapFmt.decode(Bytes.reader(buffer.fromstring(c.text)), { files = c.files }) :: any + local function count(sc: any): number + local n = 0 + for _, p in sc.meshes[1].primitives do + n += p.indices.count + end + return n + end + t:check(count(merged) < count(plain), "hull + merge: fewer triangles than every face") + t:eq(plain.materials[1].extras.map.sizeKnown, true, "sizes from the worldspawn WAD") + local nowad = MapFmt.decode(Bytes.reader(buffer.fromstring(c.text))) :: any + t:eq(nowad.materials[1].extras.map.width, 64, "no WAD: 64 x 64") + local sized = MapFmt.decode(Bytes.reader(buffer.fromstring(c.text)), { textureSizes = { brick = { 8, 8 } } }) :: any + for _, m in sized.materials do + if m.name == "brick" then + t:eq(m.extras.map.width, 8, "textureSizes") + end + end + -- Quake standard -> Valve 220: same texture coordinates + local valve = assert(MapFmt.encode(plain, { variant = "valve220" })) + local v = MapFmt.decode(Bytes.reader(valve), { files = c.files }) :: any + t:eq(v.meta.source.variant, "valve220", "converted to Valve 220") + local u1 = Types.Scene.reader(plain.meshes[1].primitives[1].attributes.TEXCOORD_0) :: any + local u2 = Types.Scene.reader(v.meshes[1].primitives[1].attributes.TEXCOORD_0) :: any + local worst = 0 + for k = 0, plain.meshes[1].primitives[1].attributes.TEXCOORD_0.count - 1 do + worst = math.max(worst, math.abs(u1(k, 0) - u2(k, 0)), math.abs(u1(k, 1) - u2(k, 1))) + end + t:check(worst < 1e-5, "Valve 220 conversion keeps the texture coordinates (" .. worst .. ")") + -- edits: a moved point entity writes its new origin + plain.nodes[4].translation = { 1, 2, 3 } + local moved = MapFmt.parse(assert(MapFmt.encode(plain))) :: any + t:eq(moved.entities[3].keys.origin, "1 2 3", "moved entity origin") + -- through the api + local viaApi = assert(F.model.load(c.text, { files = c.files })) + t:eq(viaApi.meta.source.format, "map", "F.model.load") + local saved = assert(F.save(viaApi, nil, { format = "map" })) + t:check(buffer.len(saved) > 100, "F.save as map") +end + +-- sniffing and errors +do + local build = buffer.create(64) + buffer.writeu32(build, 0, 7) + t:eq(MapFmt.sniff(Bytes.reader(build)), 0, "Build engine (binary) .map: not ours") + t:eq(MapFmt.sniff(Bytes.reader(buffer.fromstring('{"classname": "x"}'))), 0, "JSON: not a map") + t:check(MapFmt.sniff(Bytes.reader(buffer.fromstring('{\n"classname" "worldspawn"\n}'))) > 0.5, "minimal map") + local _, e1 = MapFmt.decode(Bytes.reader(buffer.fromstring('{ "classname" "worldspawn" { ( 0 0 0 ) ( 1 0 0 ) brick'))) + t:check(e1 and e1.code == Err.CORRUPT, "truncated face: " .. tostring(e1)) + local _, e2 = MapFmt.decode(Bytes.reader(buffer.fromstring('{ "classname" "worldspawn" { brushDef3 { } } }'))) + t:check(e2 and e2.code == Err.UNSUPPORTED, "Doom 3 brushDef3: unsupported") + local _, e3 = MapFmt.encode(Types.Scene.new()) + t:check(e3 and e3.code == Err.ARG, "encode without entities") + local bad = assert(MapFmt.decode(Bytes.reader(buffer.fromstring(Fx.quake.text)))) :: any + bad.nodes[2].extras.keys.message = 'a "quoted" value' + local _, e4 = MapFmt.encode(bad) + t:check(e4 and e4.code == Err.ARG, "quotes in a value") +end + +t:fuzz("decode", function(b: buffer) + return MapFmt.decode(Bytes.reader(b), { hull = true, merge = true }) +end, { buffer.fromstring(Fx.quake.text), buffer.fromstring(Fx.quake3.text), buffer.fromstring(Fx.valve.text) }, { mutations = 60, garbage = 20 }) +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) diff --git a/tools/fixtures/map.py b/tools/fixtures/map.py new file mode 100644 index 0000000..8f49fc2 --- /dev/null +++ b/tools/fixtures/map.py @@ -0,0 +1,172 @@ +# model/map fixtures (tools/fixtures.py): .map files written here in the four dialects and compiled with ericw-tools +# qbsp -nofill (Quake 1 BSP; it reads all four). Reference: qbsp's faces per model (plane, corners, texinfo vectors, +# texture and its size from the WAD), so the test checks our CSG'd polygons and texture coordinates per entity. +# quake: a room (6 wall boxes), a pillar, a func_door, point entities, Quake standard faces, "wad" -> tex.wad (WAD2) +# valve: the same layout in Valve 220 with a WAD3 named by a Windows path +# quake2: Quake II faces with contents / flags / value; sizes from textures/.wal +# quake3: brushDef faces + a patchDef2 (qbsp compiles the brushes of a copy without the patch; the patch reference is +# evaluated here: biquadratic Bezier, 4 segments per sub-patch) +# tests/gen/map.luau { [name] = { text, files = { [name] = bytes }, models = { [model] = { faces } }, sizes, patch? } } +import importlib.util, os + +INPUTS = ["tools/fixtures/_qbsp.py", "tools/fixtures/brush.py"] + +TEX = [("brick", 64, 32), ("metal", 32, 128), ("wood", 128, 64), ("+0lava", 64, 64), ("stone", 16, 16)] + + +def load(ctx, name): + spec = importlib.util.spec_from_file_location(name, os.path.join(ctx.root, "tools", "fixtures", name + ".py")) + m = importlib.util.module_from_spec(spec) + spec.loader.exec_module(m) + return m + + +def layout(rng): + world = [] + # room [-256, 256] x [-256, 256] x [0, 256], walls 16 thick + lo, hi = (-256, -256, 0), (256, 256, 256) + t = 16 + world.append(((lo[0] - t, lo[1] - t, lo[2] - t), (hi[0] + t, hi[1] + t, lo[2]))) + world.append(((lo[0] - t, lo[1] - t, hi[2]), (hi[0] + t, hi[1] + t, hi[2] + t))) + world.append(((lo[0] - t, lo[1] - t, lo[2]), (lo[0], hi[1] + t, hi[2]))) + world.append(((hi[0], lo[1] - t, lo[2]), (hi[0] + t, hi[1] + t, hi[2]))) + world.append(((lo[0], lo[1] - t, lo[2]), (hi[0], lo[1], hi[2]))) + world.append(((lo[0], hi[1], lo[2]), (hi[0], hi[1] + t, hi[2]))) + world.append(((-32, -32, 0), (32, 32, 192))) # pillar standing on the floor + world.append(((64, 64, -8), (160, 128, 48))) # a box sunk into the floor + door = [((100, -200, 0), (116, -120, 128))] + return world, door + + +def faces_for(B, box, rng, kind): + out = [] + for pts in B.box_faces(*box): + tex = rng.choice(TEX)[0] + out.append((pts, tex, B.projection(rng, "bp" if kind == "quake3" else ("valve" if kind == "valve" else "standard")))) + return out + + +def face_text(B, kind, pts, tex, a, flags): + k = {"quake": "standard", "quake2": "standard", "valve": "valve", "quake3": "bp"}[kind] + line = B.face_line(k, pts, tex, a) + if kind == "quake3": + line = line[: -len(" 0 0 0")] + " " + " ".join(str(x) for x in flags) + elif kind == "quake2": + line += " " + " ".join(str(x) for x in flags) + return line + + +def write(B, kind, world, door, rng, wadkey, patch=None): + head = {"quake": "// Game: Quake\n// Format: Standard\n", "valve": "// Game: Half-Life\n// Format: Valve\n", + "quake2": "// Game: Quake 2\n// Format: Quake2\n", "quake3": "// Game: Quake 3\n// Format: Quake3\n"}[kind] + lines = [head + "{", '"classname" "worldspawn"', '"message" "fixture room"'] + if wadkey: + lines.append('"wad" "%s"' % wadkey) + if kind == "valve": + lines.append('"mapversion" "220"') + for box in world: + lines.append("{") + if kind == "quake3": + lines += ["brushDef", "{"] + for pts, tex, a in faces_for(B, box, rng, kind): + lines.append(face_text(B, kind, pts, tex, a, [0, rng.randrange(0, 4), 0])) + if kind == "quake3": + lines.append("}") + lines.append("}") + if patch: + lines.append(patch) + lines += ["}", "{", '"classname" "func_door"', '"targetname" "door1"', '"angle" "90"'] + for box in door: + lines.append("{") + if kind == "quake3": + lines += ["brushDef", "{"] + for pts, tex, a in faces_for(B, box, rng, kind): + lines.append(face_text(B, kind, pts, tex, a, [1, 0, 5])) + if kind == "quake3": + lines.append("}") + lines.append("}") + lines += ["}", "{", '"classname" "info_player_start"', '"origin" "-128 -128 24"', '"angle" "45"', "}", + "{", '"classname" "light"', '"origin" "0 0 200"', '"light" "300"', "}", ""] + return "\n".join(lines) + + +def bezier_patch(w, h, ctrl, level): + # ctrl[(i * w + j)] row-major (row i, column j) of (x, y, z, s, t); quadratic Bezier per 3 x 3 sub-patch + px, py = (w - 1) // 2, (h - 1) // 2 + gw, gh = px * level + 1, py * level + 1 + out = [] + for gy in range(gh): + sy = min(gy // level, py - 1) + tv = (gy - sy * level) / level + bv = [(1 - tv) ** 2, 2 * tv * (1 - tv), tv * tv] + for gx in range(gw): + sx = min(gx // level, px - 1) + tu = (gx - sx * level) / level + bu = [(1 - tu) ** 2, 2 * tu * (1 - tu), tu * tu] + p = [0.0] * 5 + for j in range(3): + for i in range(3): + c = ctrl[(sy * 2 + j) * w + sx * 2 + i] + for k in range(5): + p[k] += c[k] * bu[i] * bv[j] + out.append(p) + return out, gw, gh + + +def compile_faces(H, ctx, text, files): + res = H.compile(ctx, text, files, ["-nofill", "-noclip", "-nopercent"]) + b = H.read_bsp(res["bsp"]) + models = {} + for mi, m in enumerate(b["models"]): + first, count = m[14], m[15] + faces = [] + for f in b["faces"][first:first + count]: + ti = b["texinfo"][f["texinfo"]] + name, w, h = b["textures"][ti[8]] + assert name and w and h, "qbsp did not find the texture WAD" + faces.append({"plane": list(H.face_plane(b, f)), "pts": [c for p in H.face_points(b, f) for c in p], + "tex": name, "vecs": list(ti[0:8]), "size": [w, h]}) + models[str(mi)] = faces + return models + + +def generate(ctx): + H = load(ctx, "_qbsp") + B = load(ctx, "brush") + rng = ctx.rng(4242) + world, door = layout(rng) + out = {} + wad2 = H.wad([(n, 0x44, H.miptex(n, w, h, rng)) for n, w, h in TEX]) + pal = bytes(rng.randrange(256) for _ in range(768)) + wad3 = H.wad([(n, 0x43, H.miptex(n, w, h, rng, pal)) for n, w, h in TEX], b"WAD3") + sizes = {n: [w, h] for n, w, h in TEX} + # quake + text = write(B, "quake", world, door, rng, "gfx/tex.wad") + out["quake"] = {"text": text, "files": {"gfx/tex.wad": wad2}, "models": compile_faces(H, ctx, text.replace("gfx/tex.wad", "tex.wad"), {"tex.wad": wad2}), "sizes": sizes} + # valve 220 with a WAD3 under a Windows path + text = write(B, "valve", world, door, rng, "\\half-life\\valve\\tex3.wad") + qtext = text.replace("\\half-life\\valve\\tex3.wad", "tex3.wad") + out["valve"] = {"text": text, "files": {"tex3.wad": wad3}, "models": compile_faces(H, ctx, qtext, {"tex3.wad": wad3}), "sizes": sizes} + # quake 2: .wal sizes (qbsp is given the same sizes through a WAD of the same names) + text = write(B, "quake2", world, door, rng, None) + wals = {} + for n, w, h in TEX: + wals["textures/" + n + ".wal"] = (n.encode() + b"\0" * (32 - len(n))) + w.to_bytes(4, "little") + h.to_bytes(4, "little") + bytes(60) + qtext = text.replace('"message" "fixture room"', '"message" "fixture room"\n"wad" "tex.wad"') + out["quake2"] = {"text": text, "files": wals, "models": compile_faces(H, ctx, qtext, {"tex.wad": wad2}), "sizes": sizes} + # quake 3: brushDef + a 5 x 3 patch + W, Hh = 5, 3 + ctrl = [] + for i in range(Hh): + for j in range(W): + ctrl.append([-200 + j * 40, 100 + i * 50, 64 + (48 if i == 1 else 0) + (24 if j % 2 else 0), j / 4, i / 2]) + rows = [] + for j in range(W): # file order: column by column + rows.append("( " + " ".join("( %s )" % " ".join(B.num(x) for x in ctrl[i * W + j]) for i in range(Hh)) + " )") + patch = "{\npatchDef2\n{\nbase/curve\n( %d %d 0 0 0 )\n(\n%s\n)\n}\n}" % (W, Hh, "\n".join(rows)) + text = write(B, "quake3", world, door, rng, "tex.wad", patch) + plain = text.replace(patch + "\n", "") + grid, gw, gh = bezier_patch(W, Hh, ctrl, 4) + out["quake3"] = {"text": text, "files": {"tex.wad": wad2}, "models": compile_faces(H, ctx, plain, {"tex.wad": wad2}), "sizes": sizes, + "patch": {"grid": [c for p in grid for c in p], "w": gw, "h": gh}} + ctx.emit("map", out)