From 0b6773db8b64d53d73386dc5b128698e2ec6ce00 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 18:34:55 -0600 Subject: [PATCH 01/10] model/ase: 3ds Max ASCII Scene Export read + write (geometry, Multi/Sub-Object materials, texture channels, colours, normals, NODE_TM hierarchy, helpers, cameras, lights; checked against assimp) --- README.md | 3 +- docs/FORMATS.md | 1 + docs/guide/scene.md | 24 ++ src/Rosetta/Registry.luau | 12 + src/Rosetta/model/ase/Build.luau | 572 +++++++++++++++++++++++++++++++ src/Rosetta/model/ase/Parse.luau | 67 ++++ src/Rosetta/model/ase/Write.luau | 461 +++++++++++++++++++++++++ src/Rosetta/model/ase/init.luau | 121 +++++++ tests/model/ase.luau | 256 ++++++++++++++ tools/fixtures/_ase_encode.luau | 29 ++ tools/fixtures/ase.py | 249 ++++++++++++++ tools/fixtures/docs_engines.py | 20 ++ 12 files changed, 1814 insertions(+), 1 deletion(-) create mode 100644 src/Rosetta/model/ase/Build.luau create mode 100644 src/Rosetta/model/ase/Parse.luau create mode 100644 src/Rosetta/model/ase/Write.luau create mode 100644 src/Rosetta/model/ase/init.luau create mode 100644 tests/model/ase.luau create mode 100644 tools/fixtures/_ase_encode.luau create mode 100644 tools/fixtures/ase.py create mode 100644 tools/fixtures/docs_engines.py diff --git a/README.md b/README.md index 7af4b19..312443f 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ print(F.detect(webp), #F.formats()) -- "webp", the format list ## Formats -174 formats. Generated from the format contracts by `tools/gen_registry.py`; [docs/FORMATS.md](docs/FORMATS.md) +175 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 | @@ -108,6 +108,7 @@ adds each format's capabilities. | Video | y4m | .y4m | yes | yes | | 3D models | 3ds | .3ds | yes | yes | | 3D models | 3mf | .3mf | yes | yes | +| 3D models | ase | .ase .ask | yes | yes | | 3D models | b3d | .b3d | yes | - | | 3D models | bsp | .bsp | yes | - | | 3D models | dae | .dae .zae | yes | yes | diff --git a/docs/FORMATS.md b/docs/FORMATS.md index f2a9a60..52927d1 100644 --- a/docs/FORMATS.md +++ b/docs/FORMATS.md @@ -64,6 +64,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build | video | y4m | .y4m | yes | yes | streaming: true, video: "rawvideo", depths: 8, 10, 12, 16 | `tests/video/y4m.luau` | | model | 3ds | .3ds | yes | yes | materials: true, textures: true, animation: true, cameras: true, lights: true, instancing: true | `tests/model/3ds.luau` | | model | 3mf | .3mf | yes | yes | materials: true, vertexColors: true, textures: true, units: true | `tests/model/3mf.luau` | +| model | ase | .ase .ask | yes | yes | text: true, materials: true, cameras: true, lights: true, vertexColors: true | `tests/model/ase.luau` | | model | b3d | .b3d | yes | - | materials: true, textures: true, skins: true, animation: true, colors: true | `tests/model/b3d.luau` | | model | bsp | .bsp | yes | - | variants: "quake", "halflife", "quake2", "quake3", lightmaps: "quake3" | `tests/model/bsp.luau` | | model | dae | .dae .zae | yes | yes | materials: true, polygons: true, skins: true, morphTargets: true, animation: true, cameras: true, lights: true, zae: true | `tests/model/dae.luau` | diff --git a/docs/guide/scene.md b/docs/guide/scene.md index 40c3d7b..4650d39 100644 --- a/docs/guide/scene.md +++ b/docs/guide/scene.md @@ -716,6 +716,29 @@ assert(back.meta.source.format == "iqm" and back.meshes[1].name == "tri") assert(back.meshes[1].primitives[1].indices.count == 3) ``` +## 3ds Max ASCII export (ASE) + +`.ase` files (`*3DSMAX_ASCIIEXPORT`) load as a Z-up scene: one node per geometry, helper, camera and light object, +parented by `*NODE_PARENT`. ASE stores mesh vertices in world space; the reader moves them into the node's frame (the +inverse `*NODE_TM`), so `Scene.flatten` puts them back where 3ds Max had them. Faces split into one primitive per +sub-material of a Multi/Sub-Object material (`*MESH_MTLID`); each corner is its own vertex (texture channels, +vertex colours and `*MESH_VERTEXNORMAL`s are per corner). Materials are Phong (the raw values in `extras`), bitmaps +become textures with a `uri` (data through `opts.resolve`), UVW tiling / offset a texture transform. Camera FOVs +stay the stored horizontal angle. `*TM_ANIMATION` tracks are not read (`meta.source.animated` says they exist). +The writer puts every scene material in one Multi/Sub-Object material and writes world-space vertices. + +```luau +local scene = assert(F.load(aseText)) +assert(scene.meta.source.format == "ase" and scene.meta.up == "z") +assert(#scene.materials == 2 and scene.materials[1].name == "Brick") +local quad = scene.nodes[2] +assert(quad.name == "Quad" and #scene.meshes[quad.mesh].primitives == 2) +local tex = scene.textures[scene.materials[1].baseColorTexture.texture] +assert(tex.uri == "textures\\brick.png") +local again = assert(F.load(F.save(scene, nil, { format = "ase" }))) +assert(#again.meshes[again.nodes[2].mesh].primitives == 2) +``` + ## Formats | Format | Read | Write | Notes | @@ -746,6 +769,7 @@ assert(back.meshes[1].primitives[1].indices.count == 3) | STEP | via the CAD plug-in | | see [cad.md](cad.md) | | MD2, MD3, MDL, MD5, BSP | yes | - | game models and maps: see "Game models" above | | SMD | yes | yes | Valve studiomdl data | +| ASE (3ds Max ASCII) | yes | yes | Multi/Sub-Object materials, texture channels, vertex colours, normals, helpers, cameras, lights; no animation; Z up | | Roblox `.mesh` (robloxmesh) | yes | yes | see [roblox.md](roblox.md) | | Roblox `.rbxm` / `.rbxl`, `.rbxmx` / `.rbxlx` | as an `RbxTree` | yes | instance trees with typed properties: see [roblox.md](roblox.md) | diff --git a/src/Rosetta/Registry.luau b/src/Rosetta/Registry.luau index 062b60a..27a97c7 100644 --- a/src/Rosetta/Registry.luau +++ b/src/Rosetta/Registry.luau @@ -722,6 +722,18 @@ local list: { Entry } = { return require("@rosetta/model/3mf") end, }, + { + name = "ase", + category = "model", + path = "model/ase", + extensions = { "ase", "ask" }, + mime = { "model/x-ase", "text/plain" }, + deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Text", "codecs/model/Mat4" }, + caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, vertexColors = true }, + load = function() + return require("@rosetta/model/ase") + end, + }, { name = "b3d", category = "model", diff --git a/src/Rosetta/model/ase/Build.luau b/src/Rosetta/model/ase/Build.luau new file mode 100644 index 0000000..b3ece41 --- /dev/null +++ b/src/Rosetta/model/ase/Build.luau @@ -0,0 +1,572 @@ +--!strict +-- model/ase/Build: the parsed ASE tree into a Scene. Mesh vertices are stored in world space (3ds Max ASCII export): +-- they are moved into the node's frame by the inverse NODE_TM, and node matrices are made relative to *NODE_PARENT. +local Types = require("@rosetta/Types") +local Mat4 = require("@rosetta/codecs/model/Mat4") +local Parse = require("@rosetta/model/ase/Parse") + +type Item = Parse.Item + +local Build = {} + +local S = Types.Scene + +local function first(kids: { Item }?, key: string): Item? + if kids then + for _, it in kids do + if it.key == key then + return it + end + end + end + return nil +end + +local function num(it: Item?, i: number?): number? + if not it then + return nil + end + local v = tonumber(it.args[i or 1]) + if v and v == v and v ~= math.huge and v ~= -math.huge then + return v + end + return nil +end + +local function get(kids: { Item }?, key: string, i: number?): number? + return num(first(kids, key), i) +end + +local function str(kids: { Item }?, key: string): string? + local it = first(kids, key) + return if it then it.args[1] else nil +end + +local function triple(kids: { Item }?, key: string): { number }? + local it = first(kids, key) + if not it then + return nil + end + local a, b, c = num(it, 1), num(it, 2), num(it, 3) + if a and b and c then + return { a, b, c } + end + return nil +end + +-- *TM_ROW0..2 are the axes, *TM_ROW3 the translation (row vectors): the columns of a column-major matrix +local function nodeTm(kids: { Item }?): { number } + local tm = first(kids, "NODE_TM") + local m = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } + if not tm then + return m + end + for r = 0, 3 do + local row = triple(tm.kids, "TM_ROW" .. r) + if row then + m[r * 4 + 1], m[r * 4 + 2], m[r * 4 + 3] = row[1], row[2], row[3] + end + end + return m +end + +-- ------------------------------------------------------------------------------------------------ materials +local MAPS = { "MAP_DIFFUSE", "MAP_BUMP", "MAP_OPACITY", "MAP_SELFILLUM", "MAP_SPECULAR", "MAP_SHINE", "MAP_AMBIENT", "MAP_REFLECT", "MAP_REFRACT", "MAP_SHINESTRENGTH", "MAP_FILTERCOLOR" } + +local function textureRef(scene: Types.Scene, map: Item, opts: any): (Types.TextureRef?, { [string]: any }) + local k = map.kids + local info: { [string]: any } = { + name = str(k, "MAP_NAME"), + class = str(k, "MAP_CLASS"), + amount = get(k, "MAP_AMOUNT"), + bitmap = str(k, "BITMAP"), + uOffset = get(k, "UVW_U_OFFSET"), + vOffset = get(k, "UVW_V_OFFSET"), + uTiling = get(k, "UVW_U_TILING"), + vTiling = get(k, "UVW_V_TILING"), + angle = get(k, "UVW_ANGLE"), + } + local path = info.bitmap + if type(path) ~= "string" or path == "" then + return nil, info + end + local tex: Types.Texture = { name = path, uri = path } + if opts and type(opts.resolve) == "function" then + local ok, data = pcall(opts.resolve, path) + if ok and type(data) == "buffer" then + tex.data = data + end + end + table.insert(scene.textures, tex) + local ref: Types.TextureRef = { texture = #scene.textures } + local su, sv = info.uTiling or 1, info.vTiling or 1 + local ou, ov = info.uOffset or 0, info.vOffset or 0 + local ang = info.angle or 0 + if su ~= 1 or sv ~= 1 or ou ~= 0 or ov ~= 0 or ang ~= 0 then + ref.transform = { offset = { ou, ov }, scale = { su, sv }, rotation = ang } + end + return ref, info +end + +local function material(scene: Types.Scene, it: Item, opts: any): Types.Material + local k = it.kids + local m = S.material(str(k, "MATERIAL_NAME")) + local diffuse = triple(k, "MATERIAL_DIFFUSE") or { 0.8, 0.8, 0.8 } + local transparency = get(k, "MATERIAL_TRANSPARENCY") or 0 + local shine = get(k, "MATERIAL_SHINE") or 0 + local selfIllum = get(k, "MATERIAL_SELFILLUM") or 0 + m.baseColor = { diffuse[1], diffuse[2], diffuse[3], 1 - transparency } + m.metallic = 0 + m.roughness = math.clamp(1 - shine, 0, 1) + m.emissive = { diffuse[1] * selfIllum, diffuse[2] * selfIllum, diffuse[3] * selfIllum } + if transparency > 0 then + m.alphaMode = "blend" + end + m.doubleSided = first(k, "MATERIAL_TWOSIDED") ~= nil + local maps: { [string]: any } = {} + for _, key in MAPS do + local map = first(k, key) + if map then + local ref, info = textureRef(scene, map, opts) + maps[string.lower(string.sub(key, 5))] = info + if ref then + if key == "MAP_DIFFUSE" then + m.baseColorTexture = ref + elseif key == "MAP_BUMP" then + m.normalTexture = ref + elseif key == "MAP_SELFILLUM" then + m.emissiveTexture = ref + m.emissive = { 1, 1, 1 } + end + end + end + end + m.extras = { + ambient = triple(k, "MATERIAL_AMBIENT"), + diffuse = diffuse, + specular = triple(k, "MATERIAL_SPECULAR"), + shininess = shine, + shineStrength = get(k, "MATERIAL_SHINESTRENGTH"), + transparency = transparency, + selfIllum = selfIllum, + ase = { class = str(k, "MATERIAL_CLASS"), shading = str(k, "MATERIAL_SHADING"), maps = maps }, + } + return m +end + +-- ASE material index (0-based) -> { scene material per sub-material } (one entry when it has none) +local function materials(scene: Types.Scene, list: Item?, opts: any): { { number } } + local out: { { number } } = {} + if not list or not list.kids then + return out + end + for _, it in list.kids do + if it.key == "MATERIAL" then + local subs: { number } = {} + for _, sub in it.kids or {} do + if sub.key == "SUBMATERIAL" then + table.insert(scene.materials, material(scene, sub, opts)) + table.insert(subs, #scene.materials) + end + end + if #subs == 0 then + table.insert(scene.materials, material(scene, it, opts)) + subs[1] = #scene.materials + end + table.insert(out, subs) + end + end + return out +end + +-- ------------------------------------------------------------------------------------------------ meshes +type Lists = { v: { number }, n: number } + +local function vectors(kids: { Item }?, listKey: string, itemKey: string, comps: number, max: number): { number } + local out: { number } = {} + local list = first(kids, listKey) + if not list or not list.kids then + return out + end + for _, it in list.kids do + if it.key == itemKey then + local i = num(it, 1) + if i and i >= 0 and i < max and i % 1 == 0 then + for c = 1, comps do + out[i * comps + c] = num(it, c + 1) or 0 + end + end + end + end + return out +end + +local function corners(kids: { Item }?, listKey: string, itemKey: string, max: number): { number } + local out: { number } = {} + local list = first(kids, listKey) + if not list or not list.kids then + return out + end + for _, it in list.kids do + if it.key == itemKey then + local i = num(it, 1) + if i and i >= 0 and i < max and i % 1 == 0 then + out[i * 3 + 1], out[i * 3 + 2], out[i * 3 + 3] = num(it, 2) or 0, num(it, 3) or 0, num(it, 4) or 0 + end + end + end + return out +end + +type Face = { a: number, b: number, c: number, mtl: number, smoothing: string? } + +-- *MESH_FACE i: A: a B: b C: c AB: e BC: e CA: e, then its *MESH_SMOOTHING / *MESH_MTLID siblings +local function faces(list: Item?, nv: number, maxFaces: number): ({ Face }?, string?) + local out: { Face } = {} + if not list or not list.kids then + return out, nil + end + local last: Face? = nil + for _, it in list.kids do + if it.key == "MESH_FACE" then + local s = table.concat(it.args, " ") + local i = tonumber(string.match(s, "^(%d+)")) + local a = tonumber(string.match(s, "A:%s*(%d+)")) + local b = tonumber(string.match(s, "B:%s*(%d+)")) + local c = tonumber(string.match(s, "C:%s*(%d+)")) + if not (i and a and b and c) then + return nil, "bad *MESH_FACE at byte " .. it.at + end + if a >= nv or b >= nv or c >= nv then + return nil, "face vertex index out of range at byte " .. it.at + end + if i >= maxFaces then + return nil, "limit: face index " .. i + end + local f: Face = { a = a, b = b, c = c, mtl = 0, smoothing = nil } + out[i + 1] = f + last = f + elseif it.key == "MESH_MTLID" and last then + last.mtl = math.max(0, math.floor(num(it) or 0)) + elseif it.key == "MESH_SMOOTHING" and last then + last.smoothing = it.args[1] + end + end + for i = 1, #out do + if out[i] == nil then + out[i] = { a = 0, b = 0, c = 0, mtl = 0, smoothing = nil } + end + end + return out, nil +end + +type Channel = { verts: { number }, tf: { number }, comps: number } + +local function channel(kids: { Item }?, numKey: string, listKey: string, vertKey: string, tfKey: string, tfListKey: string, nf: number, maxV: number): Channel? + local n = get(kids, numKey) or 0 + if n <= 0 then + return nil + end + n = math.min(n, maxV) + local verts = vectors(kids, listKey, vertKey, 3, n) + local tf = corners(kids, tfListKey, tfKey, nf) + return { verts = verts, tf = tf, comps = 3 } +end + +local function writeVec(acc: Types.Accessor, i: number, x: number, y: number, z: number) + local d = acc.data + buffer.writef32(d, i * 12, x) + buffer.writef32(d, i * 12 + 4, y) + buffer.writef32(d, i * 12 + 8, z) +end + +local function mesh(scene: Types.Scene, obj: Item, matMap: { { number } }, world: { number }, opts: any): (number?, string?) + local m = first(obj.kids, "MESH") + if not m or not m.kids then + return nil, nil + end + local k = m.kids + local maxV = opts.maxVertices or 2 ^ 24 + local nv = get(k, "MESH_NUMVERTEX") or 0 + local nf = get(k, "MESH_NUMFACES") or 0 + if nv < 0 or nf < 0 or nv % 1 ~= 0 or nf % 1 ~= 0 then + return nil, "bad vertex or face count" + end + if nv > maxV or nf * 3 > maxV then + return nil, "limit: " .. nv .. " vertices, " .. nf .. " faces" + end + local pos = vectors(k, "MESH_VERTEX_LIST", "MESH_VERTEX", 3, nv) + local fl, ferr = faces(first(k, "MESH_FACE_LIST"), nv, nf) + if not fl then + return nil, ferr + end + if #fl == 0 then + return nil, nil + end + local uvs: { Channel } = {} + local ch0 = channel(k, "MESH_NUMTVERTEX", "MESH_TVERTLIST", "MESH_TVERT", "MESH_TFACE", "MESH_TFACELIST", #fl, maxV) + if ch0 then + uvs[1] = ch0 + end + for _, it in k do + if it.key == "MESH_MAPPINGCHANNEL" and it.kids then + local idx = num(it) or 0 + local ch = channel(it.kids, "MESH_NUMTVERTEX", "MESH_TVERTLIST", "MESH_TVERT", "MESH_TFACE", "MESH_TFACELIST", #fl, maxV) + if ch and idx >= 2 and idx <= 8 then + uvs[idx] = ch + end + end + end + local colors = channel(k, "MESH_NUMCVERTEX", "MESH_CVERTLIST", "MESH_VERTCOL", "MESH_CFACE", "MESH_CFACELIST", #fl, maxV) + -- *MESH_NORMALS: *MESH_FACENORMAL f, then *MESH_VERTEXNORMAL v x y z for each of its corners + local normals: { number }? = nil + local nlist = first(k, "MESH_NORMALS") + if nlist and nlist.kids then + local nn: { number } = {} + local face = -1 + for _, it in nlist.kids do + if it.key == "MESH_FACENORMAL" then + face = num(it) or -1 + elseif it.key == "MESH_VERTEXNORMAL" and face >= 0 and face < #fl then + local f = fl[face + 1] + local v = num(it) + local corner = if v == f.a then 0 elseif v == f.b then 1 elseif v == f.c then 2 else nil + if corner then + local o = (face * 3 + corner) * 3 + nn[o + 1], nn[o + 2], nn[o + 3] = num(it, 2) or 0, num(it, 3) or 0, num(it, 4) or 0 + end + end + end + normals = nn + end + -- faces by scene material (sub-material = *MESH_MTLID, the last one when out of range) + local ref = get(obj.kids, "MATERIAL_REF") + local subs: { number }? = if ref and ref >= 0 then matMap[math.min(ref, #matMap - 1) + 1] else nil + local groups: { [number]: { number } } = {} + local order: { number } = {} + for i, f in fl do + local key = 0 + if subs and #subs > 0 then + key = subs[math.min(f.mtl, #subs - 1) + 1] + end + local g = groups[key] + if not g then + g = {} + groups[key] = g + table.insert(order, key) + end + table.insert(g, i) + end + table.sort(order) + local inv = Mat4.inverse(world) + local local_ = inv or S.IDENTITY + local nmat = Mat4.normalMatrix(local_) + local out: Types.Mesh = { name = str(obj.kids, "NODE_NAME"), primitives = {} } + for _, key in order do + local list = groups[key] + local count = #list * 3 + local P = S.accessor(nil, "f32", 3, count) + local N = if normals then S.accessor(nil, "f32", 3, count) else nil + local UV: { [number]: Types.Accessor } = {} + for idx in uvs do + UV[idx] = S.accessor(nil, "f32", 2, count) + end + local C = if colors then S.accessor(nil, "f32", 4, count) else nil + local I = S.accessor(nil, "u32", 1, count) + local w = 0 + for _, fi in list do + local f = fl[fi] + local fc = { f.a, f.b, f.c } + for corner = 0, 2 do + local vi = fc[corner + 1] + local x, y, z = Mat4.point(local_, pos[vi * 3 + 1] or 0, pos[vi * 3 + 2] or 0, pos[vi * 3 + 3] or 0) + writeVec(P, w, x, y, z) + if N and normals then + local o = ((fi - 1) * 3 + corner) * 3 + local nx, ny, nz = normals[o + 1] or 0, normals[o + 2] or 0, normals[o + 3] or 0 + local tx = nmat[1] * nx + nmat[5] * ny + nmat[9] * nz + local ty = nmat[2] * nx + nmat[6] * ny + nmat[10] * nz + local tz = nmat[3] * nx + nmat[7] * ny + nmat[11] * nz + local len = math.sqrt(tx * tx + ty * ty + tz * tz) + if len > 0 then + tx, ty, tz = tx / len, ty / len, tz / len + end + writeVec(N, w, tx, ty, tz) + end + for idx, ch in uvs do + local ti = ch.tf[(fi - 1) * 3 + corner + 1] or 0 + local u, v = ch.verts[ti * 3 + 1] or 0, ch.verts[ti * 3 + 2] or 0 + buffer.writef32(UV[idx].data, w * 8, u) + buffer.writef32(UV[idx].data, w * 8 + 4, 1 - v) -- 3ds Max v goes up + end + if C and colors then + local ci = colors.tf[(fi - 1) * 3 + corner + 1] or 0 + local d = C.data + buffer.writef32(d, w * 16, colors.verts[ci * 3 + 1] or 1) + buffer.writef32(d, w * 16 + 4, colors.verts[ci * 3 + 2] or 1) + buffer.writef32(d, w * 16 + 8, colors.verts[ci * 3 + 3] or 1) + buffer.writef32(d, w * 16 + 12, 1) + end + buffer.writeu32(I.data, w * 4, w) + w += 1 + end + end + local attrs: { [string]: Types.Accessor } = { POSITION = P } + if N then + attrs.NORMAL = N + end + for idx, acc in UV do + attrs["TEXCOORD_" .. (idx - 1)] = acc + end + if C then + attrs.COLOR_0 = C + end + local smoothing: { string } = {} + for j, fi in list do + smoothing[j] = fl[fi].smoothing or "" + end + local prim: Types.Primitive = { + attributes = attrs, + indices = I, + mode = "triangles", + material = if key > 0 then key else nil, + extras = { smoothing = smoothing }, + } + table.insert(out.primitives, prim) + end + table.insert(scene.meshes, out) + return #scene.meshes, nil +end + +-- ------------------------------------------------------------------------------------------------ objects +local LIGHTS: { [string]: "directional" | "point" | "spot" } = { Omni = "point", Target = "spot", Free = "spot", Directional = "directional", TargetDirectional = "directional" } + +local function camera(scene: Types.Scene, obj: Item): number + local st = first(obj.kids, "CAMERA_SETTINGS") + local fov = get(st and st.kids, "CAMERA_FOV") or math.rad(45) + local cam: Types.Camera = { + name = str(obj.kids, "NODE_NAME"), + type = "perspective", + yfov = fov, -- 3ds Max stores the horizontal field of view (radians), kept as it is + znear = get(st and st.kids, "CAMERA_NEAR") or 0, + zfar = get(st and st.kids, "CAMERA_FAR"), + } + table.insert(scene.cameras, cam) + return #scene.cameras +end + +local function light(scene: Types.Scene, obj: Item): number + local st = first(obj.kids, "LIGHT_SETTINGS") + local sk = st and st.kids + local typ = LIGHTS[str(obj.kids, "LIGHT_TYPE") or "Omni"] or "point" + local l: Types.Light = { + name = str(obj.kids, "NODE_NAME"), + type = typ, + color = triple(sk, "LIGHT_COLOR") or { 1, 1, 1 }, + intensity = get(sk, "LIGHT_INTENS") or 1, + } + if typ == "spot" then + l.innerCone = math.rad((get(sk, "LIGHT_HOTSPOT") or 43) / 2) + l.outerCone = math.rad((get(sk, "LIGHT_FALLOFF") or 45) / 2) + end + table.insert(scene.lights, l) + return #scene.lights +end + +local KINDS = { GEOMOBJECT = true, HELPEROBJECT = true, CAMERAOBJECT = true, LIGHTOBJECT = true, SHAPEOBJECT = true } + +local function collect(kids: { Item }, into: { Item }, depth: number) + for _, it in kids do + if KINDS[it.key] then + table.insert(into, it) + elseif it.key == "GROUP" and it.kids and depth < 32 then + collect(it.kids, into, depth + 1) + end + end +end + +function Build.scene(root: { Item }, opts: any): (Types.Scene?, string?) + local o = opts or {} + local scene = S.new() + local version = get(root, "3DSMAX_ASCIIEXPORT") + local sk = (first(root, "SCENE") or { kids = nil } :: any).kids + scene.meta.up = "z" + scene.meta.source = { + format = "ase", + version = version, + comment = str(root, "COMMENT"), + firstFrame = get(sk, "SCENE_FIRSTFRAME"), + lastFrame = get(sk, "SCENE_LASTFRAME"), + frameSpeed = get(sk, "SCENE_FRAMESPEED"), + ticksPerFrame = get(sk, "SCENE_TICKSPERFRAME"), + background = triple(sk, "SCENE_BACKGROUND_STATIC"), + ambient = triple(sk, "SCENE_AMBIENT_STATIC"), + } + local matMap = materials(scene, first(root, "MATERIAL_LIST"), o) + local objs: { Item } = {} + collect(root, objs, 0) + local byName: { [string]: number } = {} + local worlds: { { number } } = {} + local parents: { string? } = {} + local animated = false + for i, obj in objs do + local name = str(obj.kids, "NODE_NAME") + local world = nodeTm(obj.kids) + local node: Types.Node = { name = name, children = {} } + local extras: { [string]: any } = { class = string.lower((string.gsub(obj.key, "OBJECT$", ""))) } + if obj.key == "GEOMOBJECT" then + local mi, merr = mesh(scene, obj, matMap, world, o) + if merr then + return nil, merr + end + node.mesh = mi + elseif obj.key == "CAMERAOBJECT" then + node.camera = camera(scene, obj) + elseif obj.key == "LIGHTOBJECT" then + node.light = light(scene, obj) + elseif obj.key == "HELPEROBJECT" then + extras.helperClass = str(obj.kids, "HELPER_CLASS") + end + if first(obj.kids, "TM_ANIMATION") then + animated = true + end + node.extras = { ase = extras } + scene.nodes[i] = node + worlds[i] = world + parents[i] = str(obj.kids, "NODE_PARENT") + if name and byName[name] == nil then + byName[name] = i + end + end + for i, node in scene.nodes do + local pname = parents[i] + local p = if pname then byName[pname] else nil + if p and p ~= i then + -- a parent cycle (or a parent listed later naming this node) falls back to a root + local q, steps = p, 0 + while q and q ~= i and steps < #objs do + local pn = parents[q] + q = if pn then byName[pn] else nil + steps += 1 + end + if q == i then + p = nil + end + else + p = nil + end + local inv = if p then Mat4.inverse(worlds[p :: number]) else nil + node.matrix = if inv then S.mul(inv, worlds[i]) else worlds[i] + if p then + table.insert(scene.nodes[p :: number].children, i) + else + table.insert(scene.roots, i) + end + end + if animated then + (scene.meta.source :: any).animated = true + end + return scene, nil +end + +return Build diff --git a/src/Rosetta/model/ase/Parse.luau b/src/Rosetta/model/ase/Parse.luau new file mode 100644 index 0000000..a0a5d96 --- /dev/null +++ b/src/Rosetta/model/ase/Parse.luau @@ -0,0 +1,67 @@ +--!strict +-- model/ase/Parse: ASE text into a tree of items (*KEY args { children }). Quoted strings carry no escapes (3ds Max +-- ASCII export). Several items may share a line (*MESH_FACE ... *MESH_SMOOTHING 1 *MESH_MTLID 0). +local Parse = {} + +export type Item = { key: string, args: { string }, kids: { Item }?, at: number } + +function Parse.tree(text: string, maxItems: number): ({ Item }?, string?) + local root: { Item } = {} + local stack: { { Item } } = { root } + local cur: Item? = nil + local p, n = 1, #text + local count = 0 + local find, sub, byte = string.find, string.sub, string.byte + while p <= n do + local s = find(text, "[^ \t\r\n]", p) + if not s then + break + end + local c = byte(text, s) + if c == 34 then -- '"' + local e = find(text, "\"", s + 1, true) + local stop = e or (n + 1) + if cur then + table.insert(cur.args, sub(text, s + 1, stop - 1)) + end + p = stop + 1 + elseif c == 123 then -- '{' + if not cur then + return nil, "'{' without an item at byte " .. s - 1 + end + if #stack > 64 then + return nil, "limit: nesting too deep" + end + local kids: { Item } = {} + cur.kids = kids + table.insert(stack, kids) + cur = nil + p = s + 1 + elseif c == 125 then -- '}' + if #stack == 1 then + return nil, "unbalanced '}' at byte " .. s - 1 + end + table.remove(stack) + cur = nil + p = s + 1 + else + local e = find(text, "[ \t\r\n{}\"]", s) or (n + 1) + local word = sub(text, s, e - 1) + if c == 42 then -- '*' + count += 1 + if count > maxItems then + return nil, "limit: over " .. maxItems .. " items" + end + local it: Item = { key = sub(word, 2), args = {}, kids = nil, at = s - 1 } + table.insert(stack[#stack], it) + cur = it + elseif cur then + table.insert(cur.args, word) + end + p = e + end + end + return root, nil +end + +return Parse diff --git a/src/Rosetta/model/ase/Write.luau b/src/Rosetta/model/ase/Write.luau new file mode 100644 index 0000000..a5039e2 --- /dev/null +++ b/src/Rosetta/model/ase/Write.luau @@ -0,0 +1,461 @@ +--!strict +-- model/ase/Write: a Scene as ASE text (3DSMAX_ASCIIEXPORT 200). Vertices are written in world space with each node's +-- world NODE_TM; every scene material is a sub-material of one Multi/Sub-Object material (faces pick it by +-- *MESH_MTLID). Triangles, strips, fans and polygons (fanned) are written; points and lines are skipped. +local Types = require("@rosetta/Types") +local Mat4 = require("@rosetta/codecs/model/Mat4") + +local Write = {} + +local S = Types.Scene + +local function f(v: number): string + if v ~= v or v == math.huge or v == -math.huge then + return "0.0000" + end + if v == math.floor(v) and math.abs(v) < 1e15 then + return string.format("%.4f", v) + end + return string.format("%.9g", v) +end + +local function q(s: string): string + return "\"" .. string.gsub(s, "\"", "'") .. "\"" +end + +type Out = { lines: { string } } + +local function put(out: Out, depth: number, s: string) + table.insert(out.lines, string.rep("\t", depth) .. s) +end + +local function tri(prim: any): { number }? + local pos = prim.attributes and prim.attributes.POSITION + if type(pos) ~= "table" then + return nil + end + local n = pos.count + local idx: { number } = {} + if prim.indices then + local rd = S.reader(prim.indices) + if not rd then + return nil + end + for i = 0, prim.indices.count - 1 do + idx[i + 1] = rd(i, 0) + end + else + for i = 0, n - 1 do + idx[i + 1] = i + end + end + local mode = prim.mode or "triangles" + local out: { number } = {} + if mode == "triangles" then + for i = 1, #idx - 2, 3 do + table.insert(out, idx[i]) + table.insert(out, idx[i + 1]) + table.insert(out, idx[i + 2]) + end + elseif mode == "triangle_strip" then + for i = 1, #idx - 2 do + if i % 2 == 1 then + table.insert(out, idx[i]) + table.insert(out, idx[i + 1]) + else + table.insert(out, idx[i + 1]) + table.insert(out, idx[i]) + end + table.insert(out, idx[i + 2]) + end + elseif mode == "triangle_fan" then + for i = 2, #idx - 1 do + table.insert(out, idx[1]) + table.insert(out, idx[i]) + table.insert(out, idx[i + 1]) + end + elseif mode == "polygons" and prim.faces then + local rd = S.reader(prim.faces) + local at = 1 + if rd then + for fi = 0, prim.faces.count - 1 do + local size = rd(fi, 0) + for k = 1, size - 2 do + table.insert(out, idx[at]) + table.insert(out, idx[at + k]) + table.insert(out, idx[at + k + 1]) + end + at += size + end + end + else + return nil + end + for _, v in out do + if v < 0 or v >= n then + return nil + end + end + return out +end + +local function material(out: Out, d: number, key: string, index: number, m: any) + put(out, d, "*" .. key .. " " .. index .. " {") + local c = if type(m.baseColor) == "table" then m.baseColor else { 1, 1, 1, 1 } + local x = if type(m.extras) == "table" then m.extras else {} + local amb = if type(x.ambient) == "table" then x.ambient else { c[1] or 1, c[2] or 1, c[3] or 1 } + local spec = if type(x.specular) == "table" then x.specular else { 0.9, 0.9, 0.9 } + put(out, d + 1, "*MATERIAL_NAME " .. q(if type(m.name) == "string" then m.name else "Material #" .. index)) + put(out, d + 1, "*MATERIAL_CLASS \"Standard\"") + put(out, d + 1, "*MATERIAL_AMBIENT " .. f(amb[1] or 0) .. "\t" .. f(amb[2] or 0) .. "\t" .. f(amb[3] or 0)) + put(out, d + 1, "*MATERIAL_DIFFUSE " .. f(c[1] or 1) .. "\t" .. f(c[2] or 1) .. "\t" .. f(c[3] or 1)) + put(out, d + 1, "*MATERIAL_SPECULAR " .. f(spec[1] or 0) .. "\t" .. f(spec[2] or 0) .. "\t" .. f(spec[3] or 0)) + put(out, d + 1, "*MATERIAL_SHINE " .. f(if type(x.shininess) == "number" then x.shininess else 1 - (m.roughness or 1))) + put(out, d + 1, "*MATERIAL_SHINESTRENGTH " .. f(if type(x.shineStrength) == "number" then x.shineStrength else 0)) + put(out, d + 1, "*MATERIAL_TRANSPARENCY " .. f(1 - (c[4] or 1))) + put(out, d + 1, "*MATERIAL_WIRESIZE 1.0000") + if m.doubleSided then + put(out, d + 1, "*MATERIAL_TWOSIDED") + end + put(out, d + 1, "*MATERIAL_SHADING Blinn") + put(out, d + 1, "*MATERIAL_SELFILLUM " .. f(if type(x.selfIllum) == "number" then x.selfIllum else 0)) + local ref = m.baseColorTexture + local tex = if type(ref) == "table" and type(m._textures) == "table" then m._textures[ref.texture] else nil + if tex and type(tex.uri) == "string" then + local tr = if type(ref.transform) == "table" then ref.transform else {} + local off = if type(tr.offset) == "table" then tr.offset else { 0, 0 } + local sc = if type(tr.scale) == "table" then tr.scale else { 1, 1 } + put(out, d + 1, "*MAP_DIFFUSE {") + put(out, d + 2, "*MAP_NAME " .. q(tex.name or tex.uri)) + put(out, d + 2, "*MAP_CLASS \"Bitmap\"") + put(out, d + 2, "*MAP_SUBNO 1") + put(out, d + 2, "*MAP_AMOUNT 1.0000") + put(out, d + 2, "*BITMAP " .. q(tex.uri)) + put(out, d + 2, "*MAP_TYPE Screen") + put(out, d + 2, "*UVW_U_OFFSET " .. f(off[1] or 0)) + put(out, d + 2, "*UVW_V_OFFSET " .. f(off[2] or 0)) + put(out, d + 2, "*UVW_U_TILING " .. f(sc[1] or 1)) + put(out, d + 2, "*UVW_V_TILING " .. f(sc[2] or 1)) + put(out, d + 2, "*UVW_ANGLE " .. f(tr.rotation or 0)) + put(out, d + 1, "}") + end + put(out, d, "}") +end + +local function nodeTm(out: Out, name: string, m: { number }) + put(out, 1, "*NODE_TM {") + put(out, 2, "*NODE_NAME " .. q(name)) + put(out, 2, "*INHERIT_POS 0 0 0") + put(out, 2, "*INHERIT_ROT 0 0 0") + put(out, 2, "*INHERIT_SCL 0 0 0") + for r = 0, 3 do + put(out, 2, "*TM_ROW" .. r .. " " .. f(m[r * 4 + 1]) .. "\t" .. f(m[r * 4 + 2]) .. "\t" .. f(m[r * 4 + 3])) + end + local t, r, s = Mat4.decompose(m) + local w = math.clamp(r[4], -1, 1) + local angle = 2 * math.acos(w) + local sn = math.sqrt(math.max(0, 1 - w * w)) + local ax = if sn > 1e-9 then { r[1] / sn, r[2] / sn, r[3] / sn } else { 0, 0, 0 } + put(out, 2, "*TM_POS " .. f(t[1]) .. "\t" .. f(t[2]) .. "\t" .. f(t[3])) + put(out, 2, "*TM_ROTAXIS " .. f(ax[1]) .. "\t" .. f(ax[2]) .. "\t" .. f(ax[3])) + put(out, 2, "*TM_ROTANGLE " .. f(angle)) + put(out, 2, "*TM_SCALE " .. f(s[1]) .. "\t" .. f(s[2]) .. "\t" .. f(s[3])) + put(out, 2, "*TM_SCALEAXIS 0.0000\t0.0000\t0.0000") + put(out, 2, "*TM_SCALEAXISANG 0.0000") + put(out, 1, "}") +end + +local function vec(rd: ((number, number) -> number)?, i: number, n: number, default: number): { number } + local v = {} + for c = 0, n - 1 do + v[c + 1] = if rd then rd(i, c) else default + end + return v +end + +local function geom(out: Out, scene: any, mesh: any, world: { number }, matBase: { [number]: number }, hasMulti: boolean): boolean + local P: { number } = {} + local N: { number } = {} + local T: { [number]: { number } } = {} + local C: { number } = {} + local F: { number } = {} + local M: { number } = {} + local hasN, hasC = false, false + local uvSets: { [number]: boolean } = {} + for _, prim in mesh.primitives or {} do + for name in prim.attributes or {} do + local k = string.match(name, "^TEXCOORD_(%d)$") + if k then + uvSets[tonumber(k) :: number] = true + end + end + end + local nm = Mat4.normalMatrix(world) + for _, prim in mesh.primitives or {} do + local idx = tri(prim) + if idx then + local a = prim.attributes + local base = #P // 3 + local rp = S.reader(a.POSITION) + local rn = if a.NORMAL then S.reader(a.NORMAL) else nil + local rc = if a.COLOR_0 then S.reader(a.COLOR_0) else nil + local cc = if a.COLOR_0 then a.COLOR_0.components else 0 + if rp then + for i = 0, a.POSITION.count - 1 do + local x, y, z = Mat4.point(world, rp(i, 0), rp(i, 1), rp(i, 2)) + table.insert(P, x) + table.insert(P, y) + table.insert(P, z) + local nv = vec(rn, i, 3, 0) + local tx = nm[1] * nv[1] + nm[5] * nv[2] + nm[9] * nv[3] + local ty = nm[2] * nv[1] + nm[6] * nv[2] + nm[10] * nv[3] + local tz = nm[3] * nv[1] + nm[7] * nv[2] + nm[11] * nv[3] + local len = math.sqrt(tx * tx + ty * ty + tz * tz) + if len > 0 then + tx, ty, tz = tx / len, ty / len, tz / len + end + table.insert(N, tx) + table.insert(N, ty) + table.insert(N, tz) + for k in uvSets do + local acc = a["TEXCOORD_" .. k] + local rt = if acc then S.reader(acc) else nil + local list = T[k] or {} + T[k] = list + table.insert(list, if rt then rt(i, 0) else 0) + table.insert(list, if rt then 1 - rt(i, 1) else 0) + end + local col = vec(rc, i, math.max(cc, 3), 1) + table.insert(C, col[1]) + table.insert(C, col[2]) + table.insert(C, col[3]) + end + hasN = hasN or rn ~= nil + hasC = hasC or rc ~= nil + local mid = if prim.material and matBase[prim.material] then matBase[prim.material] else (if hasMulti then #scene.materials else 0) + for i = 1, #idx, 3 do + table.insert(F, base + idx[i]) + table.insert(F, base + idx[i + 1]) + table.insert(F, base + idx[i + 2]) + table.insert(M, mid) + end + end + end + end + if #F == 0 then + return false + end + local nv, nf = #P // 3, #F // 3 + put(out, 1, "*MESH {") + put(out, 2, "*TIMEVALUE 0") + put(out, 2, "*MESH_NUMVERTEX " .. nv) + put(out, 2, "*MESH_NUMFACES " .. nf) + put(out, 2, "*MESH_VERTEX_LIST {") + for i = 0, nv - 1 do + put(out, 3, "*MESH_VERTEX " .. i .. "\t" .. f(P[i * 3 + 1]) .. "\t" .. f(P[i * 3 + 2]) .. "\t" .. f(P[i * 3 + 3])) + end + put(out, 2, "}") + put(out, 2, "*MESH_FACE_LIST {") + for i = 0, nf - 1 do + put(out, 3, string.format("*MESH_FACE %d: A: %d B: %d C: %d AB: 1 BC: 1 CA: 1\t*MESH_SMOOTHING 1\t*MESH_MTLID %d", i, F[i * 3 + 1], F[i * 3 + 2], F[i * 3 + 3], M[i + 1])) + end + put(out, 2, "}") + local function uvBlock(d: number, list: { number }) + put(out, d, "*MESH_NUMTVERTEX " .. nv) + put(out, d, "*MESH_TVERTLIST {") + for i = 0, nv - 1 do + put(out, d + 1, "*MESH_TVERT " .. i .. "\t" .. f(list[i * 2 + 1] or 0) .. "\t" .. f(list[i * 2 + 2] or 0) .. "\t0.0000") + end + put(out, d, "}") + put(out, d, "*MESH_NUMTVFACES " .. nf) + put(out, d, "*MESH_TFACELIST {") + for i = 0, nf - 1 do + put(out, d + 1, "*MESH_TFACE " .. i .. "\t" .. F[i * 3 + 1] .. "\t" .. F[i * 3 + 2] .. "\t" .. F[i * 3 + 3]) + end + put(out, d, "}") + end + if T[0] then + uvBlock(2, T[0]) + end + for k = 1, 7 do + if T[k] then + put(out, 2, "*MESH_MAPPINGCHANNEL " .. (k + 1) .. " {") + uvBlock(3, T[k]) + put(out, 2, "}") + end + end + if hasC then + put(out, 2, "*MESH_NUMCVERTEX " .. nv) + put(out, 2, "*MESH_CVERTLIST {") + for i = 0, nv - 1 do + put(out, 3, "*MESH_VERTCOL " .. i .. "\t" .. f(C[i * 3 + 1]) .. "\t" .. f(C[i * 3 + 2]) .. "\t" .. f(C[i * 3 + 3])) + end + put(out, 2, "}") + put(out, 2, "*MESH_NUMCVFACES " .. nf) + put(out, 2, "*MESH_CFACELIST {") + for i = 0, nf - 1 do + put(out, 3, "*MESH_CFACE " .. i .. "\t" .. F[i * 3 + 1] .. "\t" .. F[i * 3 + 2] .. "\t" .. F[i * 3 + 3]) + end + put(out, 2, "}") + end + if hasN then + put(out, 2, "*MESH_NORMALS {") + for i = 0, nf - 1 do + local a, b, c = F[i * 3 + 1], F[i * 3 + 2], F[i * 3 + 3] + local ux, uy, uz = P[b * 3 + 1] - P[a * 3 + 1], P[b * 3 + 2] - P[a * 3 + 2], P[b * 3 + 3] - P[a * 3 + 3] + local vx, vy, vz = P[c * 3 + 1] - P[a * 3 + 1], P[c * 3 + 2] - P[a * 3 + 2], P[c * 3 + 3] - P[a * 3 + 3] + local nx, ny, nz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + local len = math.sqrt(nx * nx + ny * ny + nz * nz) + if len > 0 then + nx, ny, nz = nx / len, ny / len, nz / len + end + put(out, 3, "*MESH_FACENORMAL " .. i .. "\t" .. f(nx) .. "\t" .. f(ny) .. "\t" .. f(nz)) + for _, v in { a, b, c } do + put(out, 4, "*MESH_VERTEXNORMAL " .. v .. "\t" .. f(N[v * 3 + 1]) .. "\t" .. f(N[v * 3 + 2]) .. "\t" .. f(N[v * 3 + 3])) + end + end + put(out, 2, "}") + end + put(out, 1, "}") + return true +end + +function Write.scene(scene: any, opts: any): (string?, string?) + local out: Out = { lines = {} } + local src = if type(scene.meta) == "table" and type(scene.meta.source) == "table" then scene.meta.source else {} + put(out, 0, "*3DSMAX_ASCIIEXPORT\t200") + put(out, 0, "*COMMENT " .. q(if opts and type(opts.comment) == "string" then opts.comment else "AsciiExport-Version 2,00 - rosetta")) + put(out, 0, "*SCENE {") + put(out, 1, "*SCENE_FILENAME \"\"") + put(out, 1, "*SCENE_FIRSTFRAME " .. math.floor(tonumber(src.firstFrame) or 0)) + put(out, 1, "*SCENE_LASTFRAME " .. math.floor(tonumber(src.lastFrame) or 100)) + put(out, 1, "*SCENE_FRAMESPEED " .. math.floor(tonumber(src.frameSpeed) or 30)) + put(out, 1, "*SCENE_TICKSPERFRAME " .. math.floor(tonumber(src.ticksPerFrame) or 160)) + put(out, 1, "*SCENE_BACKGROUND_STATIC 0.0000\t0.0000\t0.0000") + put(out, 1, "*SCENE_AMBIENT_STATIC 0.0000\t0.0000\t0.0000") + put(out, 0, "}") + local mats = scene.materials or {} + local nmat = #mats + local matBase: { [number]: number } = {} + -- a default sub-material for primitives without one, when other primitives have one + local needDefault = false + for _, mesh in scene.meshes or {} do + for _, prim in mesh.primitives or {} do + if not (prim.material and mats[prim.material]) then + needDefault = true + end + end + end + put(out, 0, "*MATERIAL_LIST {") + if nmat > 0 then + put(out, 1, "*MATERIAL_COUNT 1") + put(out, 1, "*MATERIAL 0 {") + put(out, 2, "*MATERIAL_NAME \"Multimaterial\"") + put(out, 2, "*MATERIAL_CLASS \"Multi/Sub-Object\"") + put(out, 2, "*NUMSUBMTLS " .. (nmat + (if needDefault then 1 else 0))) + for i, m in mats do + matBase[i] = i - 1 + local mm = table.clone(m) + mm._textures = scene.textures + material(out, 2, "SUBMATERIAL", i - 1, mm) + end + if needDefault then + material(out, 2, "SUBMATERIAL", nmat, S.material("Default")) + end + put(out, 1, "}") + else + put(out, 1, "*MATERIAL_COUNT 0") + end + put(out, 0, "}") + -- world matrices and unique names + local nodes = scene.nodes or {} + local worlds: { [number]: { number } } = {} + local parentOf: { [number]: number } = {} + local order: { number } = {} + local function walk(i: number, parent: { number }, depth: number) + local node = nodes[i] + if not node or worlds[i] or depth > 256 then + return + end + worlds[i] = S.mul(parent, S.nodeMatrix(node)) + table.insert(order, i) + for _, c in node.children or {} do + if nodes[c] and not worlds[c] then + parentOf[c] = i + walk(c, worlds[i], depth + 1) + end + end + end + local roots = scene.roots or {} + if #roots == 0 then + for i in nodes do + table.insert(roots, i) + end + end + for _, r in roots do + walk(r, S.IDENTITY, 0) + end + local names: { [number]: string } = {} + local used: { [string]: boolean } = {} + for _, i in order do + local base = if type(nodes[i].name) == "string" and nodes[i].name ~= "" then nodes[i].name else "Object" .. i + local name, k = base, 1 + while used[name] do + k += 1 + name = base .. "_" .. k + end + used[name] = true + names[i] = name + end + for _, i in order do + local node = nodes[i] + local w = worlds[i] + local mesh = if node.mesh then (scene.meshes or {})[node.mesh] else nil + local cam = if node.camera then (scene.cameras or {})[node.camera] else nil + local li = if node.light then (scene.lights or {})[node.light] else nil + local key = if mesh then "GEOMOBJECT" elseif cam then "CAMERAOBJECT" elseif li then "LIGHTOBJECT" else "HELPEROBJECT" + put(out, 0, "*" .. key .. " {") + put(out, 1, "*NODE_NAME " .. q(names[i])) + if parentOf[i] then + put(out, 1, "*NODE_PARENT " .. q(names[parentOf[i]])) + end + if key == "HELPEROBJECT" then + put(out, 1, "*HELPER_CLASS \"Dummy\"") + elseif key == "CAMERAOBJECT" then + put(out, 1, "*CAMERA_TYPE Free") + elseif key == "LIGHTOBJECT" then + put(out, 1, "*LIGHT_TYPE " .. (if li.type == "spot" then "Free" elseif li.type == "directional" then "Directional" else "Omni")) + end + nodeTm(out, names[i], w) + if mesh then + geom(out, scene, mesh, w, matBase, nmat > 0) + put(out, 1, "*PROP_MOTIONBLUR 0") + put(out, 1, "*PROP_CASTSHADOW 1") + put(out, 1, "*PROP_RECVSHADOW 1") + if nmat > 0 then + put(out, 1, "*MATERIAL_REF 0") + end + elseif cam then + put(out, 1, "*CAMERA_SETTINGS {") + put(out, 2, "*TIMEVALUE 0") + put(out, 2, "*CAMERA_NEAR " .. f(cam.znear or 0)) + put(out, 2, "*CAMERA_FAR " .. f(cam.zfar or 1000)) + put(out, 2, "*CAMERA_FOV " .. f(cam.yfov or math.rad(45))) + put(out, 2, "*CAMERA_TDIST 100.0000") + put(out, 1, "}") + elseif li then + local c = if type(li.color) == "table" then li.color else { 1, 1, 1 } + put(out, 1, "*LIGHT_SETTINGS {") + put(out, 2, "*TIMEVALUE 0") + put(out, 2, "*LIGHT_COLOR " .. f(c[1] or 1) .. "\t" .. f(c[2] or 1) .. "\t" .. f(c[3] or 1)) + put(out, 2, "*LIGHT_INTENS " .. f(li.intensity or 1)) + put(out, 2, "*LIGHT_HOTSPOT " .. f(math.deg(li.innerCone or 0) * 2)) + put(out, 2, "*LIGHT_FALLOFF " .. f(math.deg(li.outerCone or math.pi / 4) * 2)) + put(out, 1, "}") + end + put(out, 0, "}") + end + return table.concat(out.lines, "\n") .. "\n", nil +end + +return Write diff --git a/src/Rosetta/model/ase/init.luau b/src/Rosetta/model/ase/init.luau new file mode 100644 index 0000000..81443ce --- /dev/null +++ b/src/Rosetta/model/ase/init.luau @@ -0,0 +1,121 @@ +--!strict +-- model/ase: 3ds Max ASCII Scene Export (*3DSMAX_ASCIIEXPORT 200), read + write; checked against assimp's ASE loader. +-- Supports: geometry objects (texture channels, vertex colours, explicit normals, Multi/Sub-Object materials by +-- *MESH_MTLID), NODE_TM hierarchies, helpers, cameras, lights, material maps (paths; data through opts.resolve), +-- UTF-16 files. Not supported: *TM_ANIMATION tracks (meta.source.animated is set), shapes (nodes only), bones. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = require("@rosetta/core/Err") +local Bytes = require("@rosetta/core/Bytes") +local Types = require("@rosetta/Types") +local Text = require("@rosetta/codecs/text/Text") +local Parse = require("@rosetta/model/ase/Parse") +local Build = require("@rosetta/model/ase/Build") +local Write = require("@rosetta/model/ase/Write") + +-- ------------------------------------------------------------------------------------------------ contract +local Ase = { + name = "ase", + category = "model", + extensions = { "ase", "ask" }, + mime = { "model/x-ase", "text/plain" }, + deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Text", "codecs/model/Mat4" }, + caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, vertexColors = true }, +} + +-- ------------------------------------------------------------------------------------------------ types +export type DecodeOptions = { + maxBytes: number?, -- default 2^28 + maxItems: number?, -- default 2^24 (*KEY items) + maxVertices: number?, -- default 2^24 (per object) + resolve: ((string) -> buffer?)?, -- texture bitmaps by path +} +export type EncodeOptions = { + comment: string?, +} + +-- ------------------------------------------------------------------------------------------------ constants +local MAGIC = "*3DSMAX_ASCIIEXPORT" + +-- ------------------------------------------------------------------------------------------------ sniff +local function utf16(r: Bytes.Reader): (boolean?, boolean) + local h = r:peek(2) + if h == "\255\254" then + return true, false + elseif h == "\254\255" then + return true, true + elseif #h == 2 and string.byte(h, 2) == 0 and string.byte(h, 1) == 42 then + return true, false + elseif #h == 2 and string.byte(h, 1) == 0 and string.byte(h, 2) == 42 then + return true, true + end + return nil, false +end + +local function text(r: Bytes.Reader, n: number?): string + local wide, be = utf16(r) + local len = r.limit - r.pos + if n then + len = math.min(len, n) + end + if wide then + local skip = if r:peek(2) == "\255\254" or r:peek(2) == "\254\255" then 2 else 0 + return Text.utf16(r.buf, r.pos + skip, len - skip, be) + end + return Text.toUtf8(buffer.readstring(r.buf, r.pos, len)) +end + +function Ase.sniff(r: Bytes.Reader): number + local h = string.match(text(r, 256), "^%s*(%*[%w_]+)") + if h == MAGIC then + return 1 + end + return 0 +end + +-- ------------------------------------------------------------------------------------------------ decode +function Ase.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?) + local o: any = opts or {} + if r.limit - r.pos > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local s = text(r) + if not string.match(s, "^%s*%*") then + return nil, Err.new(Err.CORRUPT, "not an ASE file") + end + local ok, root, msg = pcall(Parse.tree, s, o.maxItems or 2 ^ 24) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad data: " .. tostring(root)) + end + if not root then + return nil, Err.from(msg) + end + local ok2, scene, msg2 = pcall(Build.scene, root, o) + if not ok2 then + return nil, Err.from(tostring(scene)) + end + if not scene then + return nil, Err.from(msg2) + end + if #scene.nodes == 0 and (scene.meta.source :: any).version == nil then + return nil, Err.new(Err.CORRUPT, "no *3DSMAX_ASCIIEXPORT header and no objects") + end + return scene, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +function Ase.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, "needs a Scene") + end + local ok, s, msg = pcall(Write.scene, scene, opts) + if not ok then + return nil, Err.new(Err.ARG, "bad scene: " .. tostring(s)) + end + if not s then + return nil, Err.new(Err.ARG, msg or "bad scene") + end + return buffer.fromstring(s), nil +end + +return Ase diff --git a/tests/model/ase.luau b/tests/model/ase.luau new file mode 100644 index 0000000..fed5ead --- /dev/null +++ b/tests/model/ase.luau @@ -0,0 +1,256 @@ +-- model/ase tests: assimp's ASE models and a hand-written file against assimp (meshes, faces, corners, cameras, lights, +-- world bounds); the hand file's values; round trips; assimp reading our output. Fixtures: tools/fixtures/ase.py. +local T = require("@tests/T") +local F = require("@rosetta") +local Ase = require("@rosetta/model/ase") +local MeshOps = require("@rosetta/ops/MeshOps") +local Bytes = require("@rosetta/core/Bytes") +local Err = require("@rosetta/core/Err") +local Types = require("@rosetta/Types") +local Cases = require("@tests/gen/ase_cases") +local Xcheck = require("@tests/gen/ase_xcheck") + +local t = T.suite("ase") +local S = Types.Scene + +local function decode(data: any, opts: any?): (any, any) + local b = if type(data) == "string" then buffer.fromstring(data) else data + return Ase.decode(Bytes.reader(b), opts) +end + +t:eq(Ase.name, "ase", "name") +t:eq(Ase.category, "model", "category") +t:check(Ase.caps.decode and Ase.caps.encode, "contract") + +local function near(a: number, b: number, eps: number): boolean + return math.abs(a - b) <= eps * math.max(1, math.abs(a), math.abs(b)) +end + +local function counts(scene: any): (number, number, number) + local prims, faces, corners = 0, 0, 0 + for _, pl in S.flatten(scene) do + prims += 1 + faces += pl.primitive.indices.count // 3 + corners += pl.primitive.indices.count + end + return prims, faces, corners +end + +-- assimp's ASE root rotates Z-up to Y-up: (x, z, -y) +local function boundsMatch(lo: { number }, hi: { number }, want: any, eps: number): boolean + local a, b = { lo[1], lo[3], -hi[2] }, { hi[1], hi[3], -lo[2] } + for k = 1, 3 do + if not near(a[k], want.min[k], eps) or not near(b[k], want.max[k], eps) then + return false + end + end + return true +end + +local function bstr(lo: any, hi: any): string + if not lo then + return "-" + end + return string.format("(%.4g %.4g %.4g) (%.4g %.4g %.4g)", lo[1], lo[2], lo[3], hi[1], hi[2], hi[3]) +end + +-- assimp mis-reads the UTF-16 copies of ThreeCubesGreen (one mesh of 8 faces, a bone): they are compared with the +-- UTF-8 file instead +local UTF16 = { ["assimp/models/ThreeCubesGreen_UTF16BE.ASE"] = true, ["assimp/models/ThreeCubesGreen_UTF16LE.ASE"] = true } + +local scenes: { [number]: any } = {} +local byName: { [string]: any } = {} +local samples = {} +for i, c in Cases do + local scene, err = decode(c.data) + t:check(scene, c.name .. ": decode: " .. tostring(err)) + t:eq(Ase.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, c.name .. ": sniff") + scenes[i] = scene + byName[c.name] = scene + if #c.data < 60000 then + table.insert(samples, c.data) + end + local a = c.assimp + if scene and not a.failed and not UTF16[c.name] then + local prims, faces, corners = counts(scene) + t:eq(prims, a.meshes, c.name .. ": meshes (assimp)") + t:eq(faces, a.faces, c.name .. ": faces (assimp)") + t:eq(corners, a.vertices, c.name .. ": corners (assimp)") + t:eq(#scene.cameras, a.cameras, c.name .. ": cameras (assimp)") + t:eq(#scene.lights, a.lights, c.name .. ": lights (assimp)") + if a.min then + local lo, hi = MeshOps.bounds(MeshOps.merge(scene)) + t:check(lo and boundsMatch(lo, hi, a, 1e-3), c.name .. ": world bounds (assimp) " .. bstr(lo, hi) .. " want " .. bstr(a.min, a.max)) + end + end +end + +do + local u8 = byName["assimp/models/ThreeCubesGreen.ASE"] + for name in UTF16 do + local s = byName[name] + if s and u8 then + local p1, f1 = counts(s) + local p2, f2 = counts(u8) + local lo1, hi1 = MeshOps.bounds(MeshOps.merge(s)) + local lo2, hi2 = MeshOps.bounds(MeshOps.merge(u8)) + t:check(p1 == p2 and f1 == f2 and bstr(lo1, hi1) == bstr(lo2, hi2), name .. ": same scene as the UTF-8 file") + end + end +end + +-- the hand-written file +do + local s = byName["hand.ase"] + t:eq(s.meta.up, "z", "hand: up") + t:eq(s.meta.source.frameSpeed, 25, "hand: frame speed") + t:eq(#s.materials, 2, "hand: sub-materials") + local brick, glass = s.materials[1], s.materials[2] + t:eq(brick.name, "Brick", "hand: material name") + t:check(near(brick.baseColor[1], 0.8, 1e-6) and near(brick.baseColor[3], 0.2, 1e-6), "hand: diffuse") + t:eq(s.textures[brick.baseColorTexture.texture].uri, "textures\\brick.png", "hand: bitmap path") + t:check(brick.baseColorTexture.transform and brick.baseColorTexture.transform.scale[2] == 3, "hand: UVW tiling") + t:check(glass.alphaMode == "blend" and near(glass.baseColor[4], 0.5, 1e-6) and glass.doubleSided, "hand: transparency, two-sided") + local quad + for _, n in s.nodes do + if n.name == "Quad" then + quad = n + end + end + local pivot = s.nodes[s.roots[1]] + t:eq(pivot.name, "Pivot", "hand: helper root") + t:check(table.find(pivot.children, table.find(s.nodes, quad)) ~= nil, "hand: NODE_PARENT") + -- local frame: Quad's world TM rotates 90 degrees about z at (10, 5, 0); relative to Pivot at (10, 0, 0) + t:check(near(quad.matrix[13], 0, 1e-6) and near(quad.matrix[14], 5, 1e-6) and near(quad.matrix[2], 1, 1e-6), "hand: matrix relative to the parent") + local mesh = s.meshes[quad.mesh] + t:eq(#mesh.primitives, 2, "hand: one primitive per sub-material") + local p1 = mesh.primitives[1] + t:eq(p1.material, 1, "hand: MESH_MTLID 0") + local P = S.reader(p1.attributes.POSITION) :: any + -- vertex 1 (10, 7, 0) world -> local: inverse of (rot z 90, t (10, 5, 0)) = (2, 0, 0) + t:check(near(P(1, 0), 2, 1e-6) and near(P(1, 1), 0, 1e-6), "hand: vertices in the node frame") + local UV = S.reader(p1.attributes.TEXCOORD_0) :: any + t:check(near(UV(1, 0), 1, 1e-6) and near(UV(1, 1), 1, 1e-6) and near(UV(2, 1), 0, 1e-6), "hand: UVs (v flipped)") + local UV2 = S.reader(p1.attributes.TEXCOORD_1) :: any + t:check(near(UV2(0, 0), 0.25, 1e-6) and near(UV2(0, 1), 0.25, 1e-6), "hand: mapping channel 2") + local C = S.reader(p1.attributes.COLOR_0) :: any + t:check(C(0, 0) == 1 and C(1, 1) == 1 and C(2, 0) == 1, "hand: vertex colours") + local N = S.reader(p1.attributes.NORMAL) :: any + -- (0, 0.6, 0.8) world under the inverse rotation: (0.6, 0, 0.8) + t:check(near(N(2, 0), 0.6, 1e-6) and near(N(2, 2), 0.8, 1e-6), "hand: explicit vertex normals") + t:eq(s.cameras[1].zfar, 500, "hand: camera far") + t:check(s.lights[1].type == "spot" and s.lights[1].intensity == 2 and near(s.lights[1].outerCone, math.rad(30), 1e-9), "hand: spot light") +end + +-- round trips: ours -> ours keeps counts, bounds, materials, UVs +local function sameScene(a: any, b: any, label: string) + local p1, f1, c1 = counts(a) + local p2, f2, c2 = counts(b) + t:check(p1 == p2 and f1 == f2 and c1 == c2, label .. ": counts " .. p1 .. "/" .. f1 .. " vs " .. p2 .. "/" .. f2) + local lo1, hi1 = MeshOps.bounds(MeshOps.merge(a)) + local lo2, hi2 = MeshOps.bounds(MeshOps.merge(b)) + if lo1 and lo2 then + local ok = true + for k = 1, 3 do + ok = ok and near(lo1[k], lo2[k], 1e-5) and near(hi1[k], hi2[k], 1e-5) + end + t:check(ok, label .. ": bounds " .. bstr(lo1, hi1) .. " vs " .. bstr(lo2, hi2)) + end + t:eq(#b.cameras, #a.cameras, label .. ": cameras") + t:eq(#b.lights, #a.lights, label .. ": lights") +end + +for i, c in Cases do + local s = scenes[i] + if s then + local out, err = Ase.encode(s) + t:check(out, c.name .. ": encode: " .. tostring(err)) + if out then + local back, berr = decode(out) + t:check(back, c.name .. ": re-decode: " .. tostring(berr)) + if back then + sameScene(s, back, c.name .. ": round trip") + end + end + end +end + +do + local s = byName["hand.ase"] + local back = decode(assert(Ase.encode(s))) + local m = back.materials[1] + t:eq(m.name, "Brick", "hand round trip: material") + t:eq(back.textures[m.baseColorTexture.texture].uri, "textures\\brick.png", "hand round trip: bitmap") + local q + for _, n in back.nodes do + if n.name == "Quad" then + q = n + end + end + local p = back.meshes[q.mesh].primitives[1] + t:check(p.attributes.TEXCOORD_1 and p.attributes.COLOR_0 and p.attributes.NORMAL, "hand round trip: attributes") +end + +-- glTF -> ASE (any Scene): a mesh with no materials, an n-gon, a strip +do + local s = S.new() + local P = S.accessor(nil, "f32", 3, 5) + for i, v in { { 0, 0, 0 }, { 1, 0, 0 }, { 1, 1, 0 }, { 0.5, 1.5, 0 }, { 0, 1, 0 } } do + for k = 1, 3 do + buffer.writef32(P.data, ((i - 1) * 3 + k - 1) * 4, v[k]) + end + end + local faces = S.accessor(nil, "u32", 1, 1) + buffer.writeu32(faces.data, 0, 5) + s.meshes[1] = { primitives = { { attributes = { POSITION = P }, mode = "polygons", faces = faces } } } + s.meshes[2] = { primitives = { { attributes = { POSITION = P }, mode = "triangle_strip" } } } + s.nodes = { { name = "ngon", children = { 2 }, mesh = 1, translation = { 0, 0, 3 } }, { name = "ngon", children = {}, mesh = 2, scale = { 2, 2, 2 } } } + s.roots = { 1 } + local out = assert(Ase.encode(s)) + local back = assert(decode(out)) + local _, faces2 = counts(back) + t:eq(faces2, 6, "n-gon (3) + strip (3) as triangles") + t:eq(back.nodes[2].name, "ngon_2", "duplicate names made unique") + local lo, hi = MeshOps.bounds(MeshOps.merge(back)) + t:check(near(lo[3], 3, 1e-6) and near(hi[1], 2, 1e-6), "child world transform " .. bstr(lo, hi)) + local via = F.save(s, nil, { format = "ase" }) + t:check(type(via) == "buffer" and F.detect(via) == "ase", "F.save / F.detect") +end + +-- assimp reads what we write +for _, x in Xcheck do + local c = Cases[x.case] + local s = scenes[x.case] + local a = x.assimp + t:check(not a.failed, x.name .. " (" .. c.name .. "): assimp reads it") + if s and not a.failed then + local prims, faces = counts(s) + t:eq(a.faces, faces, c.name .. ": assimp faces of ours") + t:eq(a.meshes, prims, c.name .. ": assimp meshes of ours") + t:eq(a.cameras, #s.cameras, c.name .. ": assimp cameras of ours") + t:eq(a.lights, #s.lights, c.name .. ": assimp lights of ours") + if a.min then + local lo, hi = MeshOps.bounds(MeshOps.merge(s)) + t:check(lo and boundsMatch(lo, hi, a, 1e-3), c.name .. ": assimp bounds of ours " .. bstr(lo, hi) .. " vs " .. bstr(a.min, a.max)) + end + end +end + +-- errors +do + local _, e = decode("*3DSMAX_ASCIIEXPORT 200\n*GEOMOBJECT { *MESH { *MESH_NUMVERTEX 1 *MESH_NUMFACES 1 *MESH_FACE_LIST { *MESH_FACE 0: A: 0 B: 5 C: 0 } } }") + t:check(e and e.code == Err.CORRUPT, "face index out of range: " .. tostring(e)) + local _, e2 = decode("*3DSMAX_ASCIIEXPORT 200\n}") + t:check(e2 and e2.code == Err.CORRUPT, "unbalanced brace") + local _, e3 = decode("hello") + t:check(e3 and e3.code == Err.CORRUPT, "not ASE") + local _, e4 = decode(Cases[1].data, { maxItems = 10 }) + t:check(e4 and e4.code == Err.LIMIT, "item limit") + local _, e5 = Ase.encode({} :: any) + t:check(e5 and e5.code == Err.ARG, "encode arg") +end + +t:fuzz("decode", function(b: buffer) + return Ase.decode(Bytes.reader(b)) +end, samples) +t:done() diff --git a/tools/fixtures/_ase_encode.luau b/tools/fixtures/_ase_encode.luau new file mode 100644 index 0000000..b02a90f --- /dev/null +++ b/tools/fixtures/_ase_encode.luau @@ -0,0 +1,29 @@ +-- tools/fixtures/_ase_encode: run by tools/fixtures/ase.py (luau CLI, repo root): decodes every ASE case and writes it +-- back with our ASE writer, printing "\t" lines for assimp to read. Files: case_.ase. +local Ase = require("@rosetta/model/ase") +local Bytes = require("@rosetta/core/Bytes") +local Cases = require("@tests/gen/ase_cases") + +local HEX = {} +for i = 0, 255 do + HEX[i] = string.format("%02x", i) +end +local function hex(b: buffer): string + local out = table.create(buffer.len(b)) + for i = 0, buffer.len(b) - 1 do + out[i + 1] = HEX[buffer.readu8(b, i)] + end + return table.concat(out) +end + +for i, c in Cases do + local scene = Ase.decode(Bytes.reader(buffer.fromstring(c.data))) + if scene then + local out, err = Ase.encode(scene) + if out then + print(string.format("case_%d.ase", i) .. "\t" .. hex(out)) + else + print("encode failed " .. c.name .. ": " .. tostring(err)) + end + end +end diff --git a/tools/fixtures/ase.py b/tools/fixtures/ase.py new file mode 100644 index 0000000..65e7caa --- /dev/null +++ b/tools/fixtures/ase.py @@ -0,0 +1,249 @@ +# ASE fixtures (tools/fixtures.py): assimp's ASE test models (test/models/ASE and test/models-nonbsd/ASE, read from the +# nixpkgs assimp source, never committed) plus a hand-written file (Multi/Sub-Object material, a bitmap map with UVW +# tiling, a second mapping channel, vertex colours, explicit normals, a helper parent, a camera, a light), with +# reference values from assimp (`assimp info -r`: meshes, faces, vertices, cameras, lights; world bounds from its +# PreTransformVertices export). Then our encoder's output (tools/fixtures/_ase_encode.luau) read back by assimp. +# tests/gen/ase_cases.luau { name, data, assimp } +# tests/gen/ase_xcheck.luau { name, case, assimp } +import importlib.util, os + +INPUTS = ["src/Rosetta/model/ase", "tools/fixtures/_model_ref.py", "tools/fixtures/fbx.py", "tools/fixtures/_ase_encode.luau"] + +HAND = """*3DSMAX_ASCIIEXPORT\t200 +*COMMENT "hand-written for rosetta" +*SCENE { +\t*SCENE_FILENAME "hand.max" +\t*SCENE_FIRSTFRAME 0 +\t*SCENE_LASTFRAME 50 +\t*SCENE_FRAMESPEED 25 +\t*SCENE_TICKSPERFRAME 192 +\t*SCENE_BACKGROUND_STATIC 0.1000\t0.2000\t0.3000 +\t*SCENE_AMBIENT_STATIC 0.0000\t0.0000\t0.0000 +} +*MATERIAL_LIST { +\t*MATERIAL_COUNT 1 +\t*MATERIAL 0 { +\t\t*MATERIAL_NAME "Multi" +\t\t*MATERIAL_CLASS "Multi/Sub-Object" +\t\t*NUMSUBMTLS 2 +\t\t*SUBMATERIAL 0 { +\t\t\t*MATERIAL_NAME "Brick" +\t\t\t*MATERIAL_CLASS "Standard" +\t\t\t*MATERIAL_AMBIENT 0.1000\t0.1000\t0.1000 +\t\t\t*MATERIAL_DIFFUSE 0.8000\t0.4000\t0.2000 +\t\t\t*MATERIAL_SPECULAR 0.9000\t0.9000\t0.9000 +\t\t\t*MATERIAL_SHINE 0.2500 +\t\t\t*MATERIAL_SHINESTRENGTH 0.5000 +\t\t\t*MATERIAL_TRANSPARENCY 0.0000 +\t\t\t*MATERIAL_SELFILLUM 0.0000 +\t\t\t*MAP_DIFFUSE { +\t\t\t\t*MAP_NAME "BrickMap" +\t\t\t\t*MAP_CLASS "Bitmap" +\t\t\t\t*MAP_SUBNO 1 +\t\t\t\t*MAP_AMOUNT 1.0000 +\t\t\t\t*BITMAP "textures\\brick.png" +\t\t\t\t*MAP_TYPE Screen +\t\t\t\t*UVW_U_OFFSET 0.0000 +\t\t\t\t*UVW_V_OFFSET 0.0000 +\t\t\t\t*UVW_U_TILING 2.0000 +\t\t\t\t*UVW_V_TILING 3.0000 +\t\t\t\t*UVW_ANGLE 0.0000 +\t\t\t} +\t\t} +\t\t*SUBMATERIAL 1 { +\t\t\t*MATERIAL_NAME "Glass" +\t\t\t*MATERIAL_CLASS "Standard" +\t\t\t*MATERIAL_AMBIENT 0.0000\t0.0000\t0.0000 +\t\t\t*MATERIAL_DIFFUSE 0.2000\t0.6000\t0.9000 +\t\t\t*MATERIAL_SPECULAR 1.0000\t1.0000\t1.0000 +\t\t\t*MATERIAL_SHINE 0.9000 +\t\t\t*MATERIAL_TRANSPARENCY 0.5000 +\t\t\t*MATERIAL_TWOSIDED +\t\t} +\t} +} +*HELPEROBJECT { +\t*NODE_NAME "Pivot" +\t*HELPER_CLASS "Dummy" +\t*NODE_TM { +\t\t*NODE_NAME "Pivot" +\t\t*TM_ROW0 1.0000\t0.0000\t0.0000 +\t\t*TM_ROW1 0.0000\t1.0000\t0.0000 +\t\t*TM_ROW2 0.0000\t0.0000\t1.0000 +\t\t*TM_ROW3 10.0000\t0.0000\t0.0000 +\t} +} +*GEOMOBJECT { +\t*NODE_NAME "Quad" +\t*NODE_PARENT "Pivot" +\t*NODE_TM { +\t\t*NODE_NAME "Quad" +\t\t*TM_ROW0 0.0000\t1.0000\t0.0000 +\t\t*TM_ROW1 -1.0000\t0.0000\t0.0000 +\t\t*TM_ROW2 0.0000\t0.0000\t1.0000 +\t\t*TM_ROW3 10.0000\t5.0000\t0.0000 +\t} +\t*MESH { +\t\t*TIMEVALUE 0 +\t\t*MESH_NUMVERTEX 4 +\t\t*MESH_NUMFACES 2 +\t\t*MESH_VERTEX_LIST { +\t\t\t*MESH_VERTEX 0\t10.0000\t5.0000\t0.0000 +\t\t\t*MESH_VERTEX 1\t10.0000\t7.0000\t0.0000 +\t\t\t*MESH_VERTEX 2\t8.0000\t7.0000\t0.0000 +\t\t\t*MESH_VERTEX 3\t8.0000\t5.0000\t0.0000 +\t\t} +\t\t*MESH_FACE_LIST { +\t\t\t*MESH_FACE 0: A: 0 B: 1 C: 2 AB: 1 BC: 1 CA: 0\t*MESH_SMOOTHING 1\t*MESH_MTLID 0 +\t\t\t*MESH_FACE 1: A: 0 B: 2 C: 3 AB: 1 BC: 1 CA: 0\t*MESH_SMOOTHING \t*MESH_MTLID 1 +\t\t} +\t\t*MESH_NUMTVERTEX 4 +\t\t*MESH_TVERTLIST { +\t\t\t*MESH_TVERT 0\t0.0000\t0.0000\t0.0000 +\t\t\t*MESH_TVERT 1\t1.0000\t0.0000\t0.0000 +\t\t\t*MESH_TVERT 2\t1.0000\t1.0000\t0.0000 +\t\t\t*MESH_TVERT 3\t0.0000\t1.0000\t0.0000 +\t\t} +\t\t*MESH_NUMTVFACES 2 +\t\t*MESH_TFACELIST { +\t\t\t*MESH_TFACE 0\t0\t1\t2 +\t\t\t*MESH_TFACE 1\t0\t2\t3 +\t\t} +\t\t*MESH_MAPPINGCHANNEL 2 { +\t\t\t*MESH_NUMTVERTEX 1 +\t\t\t*MESH_TVERTLIST { +\t\t\t\t*MESH_TVERT 0\t0.2500\t0.7500\t0.0000 +\t\t\t} +\t\t\t*MESH_NUMTVFACES 2 +\t\t\t*MESH_TFACELIST { +\t\t\t\t*MESH_TFACE 0\t0\t0\t0 +\t\t\t\t*MESH_TFACE 1\t0\t0\t0 +\t\t\t} +\t\t} +\t\t*MESH_NUMCVERTEX 2 +\t\t*MESH_CVERTLIST { +\t\t\t*MESH_VERTCOL 0\t1.0000\t0.0000\t0.0000 +\t\t\t*MESH_VERTCOL 1\t0.0000\t1.0000\t0.0000 +\t\t} +\t\t*MESH_NUMCVFACES 2 +\t\t*MESH_CFACELIST { +\t\t\t*MESH_CFACE 0\t0\t1\t0 +\t\t\t*MESH_CFACE 1\t1\t1\t1 +\t\t} +\t\t*MESH_NORMALS { +\t\t\t*MESH_FACENORMAL 0\t0.0000\t0.0000\t1.0000 +\t\t\t\t*MESH_VERTEXNORMAL 0\t0.0000\t0.0000\t1.0000 +\t\t\t\t*MESH_VERTEXNORMAL 1\t0.0000\t0.0000\t1.0000 +\t\t\t\t*MESH_VERTEXNORMAL 2\t0.0000\t0.6000\t0.8000 +\t\t\t*MESH_FACENORMAL 1\t0.0000\t0.0000\t1.0000 +\t\t\t\t*MESH_VERTEXNORMAL 0\t0.0000\t0.0000\t1.0000 +\t\t\t\t*MESH_VERTEXNORMAL 2\t0.0000\t0.6000\t0.8000 +\t\t\t\t*MESH_VERTEXNORMAL 3\t0.0000\t0.0000\t1.0000 +\t\t} +\t} +\t*PROP_MOTIONBLUR 0 +\t*PROP_CASTSHADOW 1 +\t*PROP_RECVSHADOW 1 +\t*MATERIAL_REF 0 +} +*CAMERAOBJECT { +\t*NODE_NAME "Cam" +\t*CAMERA_TYPE Free +\t*NODE_TM { +\t\t*NODE_NAME "Cam" +\t\t*TM_ROW0 1.0000\t0.0000\t0.0000 +\t\t*TM_ROW1 0.0000\t0.0000\t1.0000 +\t\t*TM_ROW2 0.0000\t-1.0000\t0.0000 +\t\t*TM_ROW3 0.0000\t-50.0000\t10.0000 +\t} +\t*CAMERA_SETTINGS { +\t\t*TIMEVALUE 0 +\t\t*CAMERA_NEAR 1.0000 +\t\t*CAMERA_FAR 500.0000 +\t\t*CAMERA_FOV 0.7854 +\t\t*CAMERA_TDIST 50.0000 +\t} +} +*LIGHTOBJECT { +\t*NODE_NAME "Spot" +\t*LIGHT_TYPE Target +\t*NODE_TM { +\t\t*NODE_NAME "Spot" +\t\t*TM_ROW0 1.0000\t0.0000\t0.0000 +\t\t*TM_ROW1 0.0000\t1.0000\t0.0000 +\t\t*TM_ROW2 0.0000\t0.0000\t1.0000 +\t\t*TM_ROW3 0.0000\t0.0000\t100.0000 +\t} +\t*NODE_TM { +\t\t*NODE_NAME "Spot.Target" +\t\t*TM_ROW0 1.0000\t0.0000\t0.0000 +\t\t*TM_ROW1 0.0000\t1.0000\t0.0000 +\t\t*TM_ROW2 0.0000\t0.0000\t1.0000 +\t\t*TM_ROW3 0.0000\t0.0000\t0.0000 +\t} +\t*LIGHT_SHADOWS Off +\t*LIGHT_SETTINGS { +\t\t*TIMEVALUE 0 +\t\t*LIGHT_COLOR 1.0000\t0.9000\t0.8000 +\t\t*LIGHT_INTENS 2.0000 +\t\t*LIGHT_HOTSPOT 30.0000 +\t\t*LIGHT_FALLOFF 60.0000 +\t} +} +""" + + +def load(ctx, name): + spec = importlib.util.spec_from_file_location("_" + name.replace(".", "_"), os.path.join(ctx.root, "tools", "fixtures", name + ".py")) + m = importlib.util.module_from_spec(spec) + spec.loader.exec_module(m) + return m + + +def reference(ctx, M, X, paths, tmp): + out = [] + for p, a in zip(paths, M.assimp_info(ctx, paths, raw=True)): + a.update(X.assimp_extra(ctx, p)) + for k in ("min", "max", "perMesh"): + a.pop(k, None) + if not a.get("failed"): + a.update(X.ptv_bounds(ctx, p, tmp)) + out.append(a) + return out + + +def generate(ctx): + M = load(ctx, "_model_ref") + X = load(ctx, "fbx") + tmp = M.tempdir() + src = X.assimp_src(ctx) + cases = [] + for sub in ("models", "models-nonbsd"): + d = os.path.join(src, "test", sub, "ASE") + for root, _, files in sorted(os.walk(d)): + for f in sorted(files): + if f.lower().endswith((".ase", ".ask")) or f == "TestFormatDetection": + p = os.path.join(root, f) + cases.append({"name": "assimp/%s/%s" % (sub, os.path.relpath(p, d)), "path": p}) + hand = os.path.join(tmp, "hand.ase") + with open(hand, "w") as fh: + fh.write(HAND) + cases.append({"name": "hand.ase", "path": hand}) + for c, a in zip(cases, reference(ctx, M, X, [c["path"] for c in cases], tmp)): + c["assimp"] = a + c["data"] = open(c["path"], "rb").read() + del c["path"] + ctx.emit("ase_cases", cases) + + ours = M.luau_encode(ctx, "tools/fixtures/_ase_encode.luau") + names = sorted((n for n in ours if n.endswith(".ase")), key=lambda n: int(n[5:-4])) + paths = [] + for n in names: + p = os.path.join(tmp, n) + with open(p, "wb") as f: + f.write(ours[n]) + paths.append(p) + xs = [] + for n, a in zip(names, reference(ctx, M, X, paths, tmp)): + xs.append({"name": n, "case": int(n[5:-4]), "assimp": a}) + ctx.emit("ase_xcheck", xs) diff --git a/tools/fixtures/docs_engines.py b/tools/fixtures/docs_engines.py new file mode 100644 index 0000000..4a998f0 --- /dev/null +++ b/tools/fixtures/docs_engines.py @@ -0,0 +1,20 @@ +# Docs inputs for the engine / level-editor sections of the scene, tile map, archive and data pages (tools/fixtures.py, +# tools/docs_check.py): the hand-written ASE of tools/fixtures/ase.py. +# tests/gen/docs_engines.luau { files = { [name] = bytes }, vars = { aseText = "hand.ase", ... } } +import importlib.util, os + +INPUTS = ["tools/docs_check.py", "tools/fixtures/ase.py"] + + +def mod(ctx, name): + spec = importlib.util.spec_from_file_location("fx_" + 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 generate(ctx): + check = mod(ctx, "../docs_check") + files = {"hand.ase": mod(ctx, "ase").HAND.encode()} + vars = {"aseText": "hand.ase"} + check.emit_inputs(ctx, files, vars) From 5096eb4898d110d0a15fe57899c3a85504a76f95 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 18:38:20 -0600 Subject: [PATCH 02/10] archive/unitypackage: Unity asset packages read + write as an Archive keyed by asset paths (.meta beside each asset, guids, folders, previews) --- README.md | 3 +- docs/FORMATS.md | 1 + docs/guide/archive.md | 21 ++ src/Rosetta/Registry.luau | 12 ++ src/Rosetta/archive/unitypackage/init.luau | 235 +++++++++++++++++++++ tests/archive/unitypackage.luau | 136 ++++++++++++ tools/fixtures/_unitypackage_encode.luau | 36 ++++ tools/fixtures/unitypackage.py | 95 +++++++++ 8 files changed, 538 insertions(+), 1 deletion(-) create mode 100644 src/Rosetta/archive/unitypackage/init.luau create mode 100644 tests/archive/unitypackage.luau create mode 100644 tools/fixtures/_unitypackage_encode.luau create mode 100644 tools/fixtures/unitypackage.py diff --git a/README.md b/README.md index 312443f..dc23830 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ print(F.detect(webp), #F.formats()) -- "webp", the format list ## Formats -175 formats. Generated from the format contracts by `tools/gen_registry.py`; [docs/FORMATS.md](docs/FORMATS.md) +176 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 | @@ -173,6 +173,7 @@ adds each format's capabilities. | Archives | pak | .pak .sin | yes | yes | | Archives | rpm | .rpm | yes | - | | Archives | tar | .tar | yes | yes | +| Archives | unitypackage | .unitypackage | yes | yes | | Archives | uu | .uu .uue .xxe .b64 | yes | yes | | Archives | vpk | .vpk | yes | yes | | Archives | wad | .wad | yes | yes | diff --git a/docs/FORMATS.md b/docs/FORMATS.md index 52927d1..2b96ec4 100644 --- a/docs/FORMATS.md +++ b/docs/FORMATS.md @@ -129,6 +129,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build | archive | pak | .pak .sin | yes | yes | variants: "quake", "sin" | `tests/archive/pak.luau` | | archive | rpm | .rpm | yes | - | compressors: "gzip", "bzip2", "xz", "lzma", "zstd" | `tests/archive/rpm.luau` | | archive | tar | .tar | yes | yes | variants: "ustar", "pax", "gnu" | `tests/archive/tar.luau` | +| archive | unitypackage | .unitypackage | yes | yes | | `tests/archive/unitypackage.luau` | | archive | uu | .uu .uue .xxe .b64 | yes | yes | variants: "uu", "xx", "base64" | `tests/archive/uu.luau` | | archive | vpk | .vpk | yes | yes | versions: 1, 2, multipart: true | `tests/archive/vpk.luau` | | archive | wad | .wad | yes | yes | images: true, maps: true, variants: "iwad", "pwad" | `tests/archive/wad.luau` | diff --git a/docs/guide/archive.md b/docs/guide/archive.md index acdaca3..5c91743 100644 --- a/docs/guide/archive.md +++ b/docs/guide/archive.md @@ -418,6 +418,26 @@ local out = assert(F.save(cab, nil, { format = "cab", compression = "none" })) assert(F.archive.load(out):list()[1].method == "store") ``` +## Unity packages + +A `.unitypackage` is a gzip'd tar of one folder per asset guid (`asset`, `asset.meta`, `pathname`). It loads as an +Archive keyed by the asset paths, each `.meta` next to its asset as in a Unity project folder; folders are `dir` +entries with their own `.meta`. Every entry carries its `guid`, and an asset's `preview` (when the package has a +`preview.png`) is a function returning its bytes. Without a name the file is plain gzip (it unwraps to the tar of +guid folders): pass a `.unitypackage` name or `format = "unitypackage"`. Any Archive saves as a package: guids come +from `entry.guid`, then the `.meta` entry's `guid:` line, else the path's MD5; missing `.meta` files are made. + +```luau +local pack = F.format("unitypackage").new() +pack:add("Assets/Scripts", "", { dir = true }) +pack:add("Assets/Scripts/Player.cs", "public class Player { }\n") +local bytes = assert(F.save(pack)) +local back = assert(F.load(bytes, { name = "game.unitypackage" })) +assert(back.format == "unitypackage") +local meta = buffer.tostring(assert(back:read("Assets/Scripts/Player.cs.meta"))) +assert(string.match(meta, "guid: (%x+)") == back:list()[3].guid) +``` + ## Formats | Format | Read | Write | Notes | @@ -452,6 +472,7 @@ assert(F.archive.load(out):list()[1].method == "store") | C64 disks (`.d64`, `.d71`, `.d81`) | yes | yes | PETSCII names; no GEOS VLIR | | Amiga disks (`.adf`) | yes | - | OFS / FFS; no long-name (DOS 6 / 7) volumes | | FAT images (`.img`, `.ima`) | yes | yes | FAT12 / 16 / 32, VFAT names, MBR partitions; writes FAT12 floppies | +| Unity package (`.unitypackage`) | yes | yes | assets by path, `.meta` files beside them, guids, previews; needs the extension to beat gzip | | Cabinet (`.cab`) | yes | yes | stored / MSZIP / LZX / Quantum (read), stored / MSZIP (write); no spanned files | Full capability list: [FORMATS.md](../FORMATS.md). diff --git a/src/Rosetta/Registry.luau b/src/Rosetta/Registry.luau index 27a97c7..10fd987 100644 --- a/src/Rosetta/Registry.luau +++ b/src/Rosetta/Registry.luau @@ -1502,6 +1502,18 @@ local list: { Entry } = { return require("@rosetta/archive/tar") end, }, + { + name = "unitypackage", + category = "archive", + path = "archive/unitypackage", + extensions = { "unitypackage" }, + mime = { "application/x-unitypackage" }, + deps = { "core/Err", "core/Bytes", "core/Md5", "codecs/compress/Deflate", "containers/Archive", "containers/Tar" }, + caps = { decode = true, encode = true }, + load = function() + return require("@rosetta/archive/unitypackage") + end, + }, { name = "uu", category = "archive", diff --git a/src/Rosetta/archive/unitypackage/init.luau b/src/Rosetta/archive/unitypackage/init.luau new file mode 100644 index 0000000..89aa2d8 --- /dev/null +++ b/src/Rosetta/archive/unitypackage/init.luau @@ -0,0 +1,235 @@ +--!strict +-- archive/unitypackage: Unity asset packages, a gzip'd tar of /asset, /asset.meta, /pathname +-- (+ preview.png), read + write as an Archive keyed by the asset paths (Assets/...), each .meta next to its asset as +-- in a Unity project. Supports: folders (meta only), lazy entries, guids kept (entry.guid) or made from the path. +-- Not supported: pre-5.x packages without pathname files. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = require("@rosetta/core/Err") +local Bytes = require("@rosetta/core/Bytes") +local Md5 = require("@rosetta/core/Md5") +local Deflate = require("@rosetta/codecs/compress/Deflate") +local Archive = require("@rosetta/containers/Archive") +local Tar = require("@rosetta/containers/Tar") + +-- ------------------------------------------------------------------------------------------------ contract +local UnityPackage = { + name = "unitypackage", + category = "archive", + extensions = { "unitypackage" }, + mime = { "application/x-unitypackage" }, + deps = { "core/Err", "core/Bytes", "core/Md5", "codecs/compress/Deflate", "containers/Archive", "containers/Tar" }, + caps = { decode = true, encode = true }, +} + +export type DecodeOptions = { + maxEntries: number?, -- default 1e6 + maxBytes: number?, -- inflated size, default 2^31 +} +export type EncodeOptions = { + level: number?, -- deflate 0..9, default 6 + mtime: number?, -- tar entry time, default 0 +} + +-- ------------------------------------------------------------------------------------------------ sniff +local function guidOf(name: string): (string?, string?) + local n = string.gsub(name, "^%./", "") + local guid, rest = string.match(n, "^(%x+)/?(.*)$") + if guid and #guid == 32 then + return string.lower(guid), rest + end + return nil, nil +end + +function UnityPackage.sniff(r: Bytes.Reader): number + if r:peek(3) ~= "\31\139\8" then + return 0 + end + local head = Deflate.peek(r.buf, r.pos, r.limit - r.pos, 512) + if not head or buffer.len(head) < 512 or not Tar.valid(head, 0) then + return 0 + end + local z = 0 + while z < 100 and buffer.readu8(head, z) ~= 0 do + z += 1 + end + return if guidOf(buffer.readstring(head, 0, z)) then 1 else 0 -- ties with archive/gzip go to the extension +end + +-- ------------------------------------------------------------------------------------------------ decode +local function encode(archive: any, opts: any?): (buffer?, Err.Err?) + return UnityPackage.encode(archive, opts) +end + +type Asset = { asset: Tar.Entry?, meta: Tar.Entry?, pathname: Tar.Entry?, preview: Tar.Entry? } + +local function text(b: buffer, e: Tar.Entry): string + return buffer.readstring(b, e.offset, e.size) +end + +function UnityPackage.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) + local o = opts or {} + local tar, err = Deflate.gunzip(r.buf, r.base, r.limit - r.base) + if not tar then + return nil, err + end + if buffer.len(tar) > (o.maxBytes or 2 ^ 31) then + return nil, Err.new(Err.LIMIT, "inflated size over the byte limit") + end + local list, terr = Tar.read(tar, 0, buffer.len(tar), { maxEntries = o.maxEntries }) + if not list then + return nil, terr + end + local byGuid: { [string]: Asset } = {} + local order: { string } = {} + for _, e in list do + local guid, rest = guidOf(e.name) + if guid and not e.dir then + local a = byGuid[guid] + if not a then + a = {} + byGuid[guid] = a + table.insert(order, guid) + end + if rest == "asset" then + a.asset = e + elseif rest == "asset.meta" then + a.meta = e + elseif rest == "pathname" then + a.pathname = e + elseif rest == "preview.png" then + a.preview = e + end + end + end + local arc = Archive.new("unitypackage", encode) + local skipped = 0 + for _, guid in order do + local a = byGuid[guid] + local pn = a.pathname + if not pn then + skipped += 1 + else + -- the first line is the path (Unity 5+ may add a second line, e.g. "00") + local path = string.match(text(tar, pn), "^[^\r\n]*") or "" + path = string.gsub(path, "\\", "/") + if path ~= "" then + local asset, meta = a.asset, a.meta + local isDir = asset == nil + Archive.put(arc, { + name = path, + size = if asset then asset.size else 0, + dir = isDir, + mtime = if asset then asset.mtime elseif meta then meta.mtime else nil, + method = "deflate", + guid = guid, + load = if asset and asset.size > 0 then Archive.slice(tar, asset.offset, asset.size) else nil, + preview = if a.preview then Archive.slice(tar, a.preview.offset, a.preview.size) else nil, + }) + if meta then + Archive.put(arc, { + name = path .. ".meta", + size = meta.size, + dir = false, + mtime = meta.mtime, + method = "deflate", + guid = guid, + load = if meta.size > 0 then Archive.slice(tar, meta.offset, meta.size) else nil, + }) + end + end + end + end + arc.meta.source = { format = "unitypackage", assets = #order - skipped, skipped = if skipped > 0 then skipped else nil } + return arc, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +local function metaGuid(b: buffer): string? + local s = buffer.readstring(b, 0, math.min(buffer.len(b), 4096)) + local g = string.match(s, "\nguid:%s*(%x+)") or string.match(s, "^guid:%s*(%x+)") + if g and #g == 32 then + return string.lower(g) + end + return nil +end + +local function defaultMeta(guid: string, dir: boolean): string + if dir then + return "fileFormatVersion: 2\nguid: " .. guid .. "\nfolderAsset: yes\nDefaultImporter:\n externalObjects: {}\n userData: \n assetBundleName: \n assetBundleVariant: \n" + end + return "fileFormatVersion: 2\nguid: " .. guid .. "\nDefaultImporter:\n externalObjects: {}\n userData: \n assetBundleName: \n assetBundleVariant: \n" +end + +function UnityPackage.encode(archive: any, opts: EncodeOptions?): (buffer?, Err.Err?) + local o = opts or {} + local items = Archive.entries(archive) + if not items then + return nil, Err.new(Err.ARG, "expected an Archive") + end + local byName: { [string]: any } = {} + for _, it in items do + byName[string.gsub(it.entry.name, "\\", "/")] = it + end + local mtime = o.mtime or 0 + local list: { Tar.WriteEntry } = {} + local used: { [string]: boolean } = {} + for _, it in items do + local e: any = it.entry + local path = string.gsub((string.gsub(e.name, "\\", "/")), "/+$", "") + local metaIt = byName[path .. ".meta"] + local isMeta = string.sub(path, -5) == ".meta" and byName[string.sub(path, 1, -6)] ~= nil + if path ~= "" and not isMeta then + local data: buffer? = nil + if not e.dir then + local b, rerr = it.read() + if not b then + return nil, rerr + end + data = b + end + local metaData: buffer? = nil + if metaIt then + local mb, merr = metaIt.read() + if not mb then + return nil, merr + end + metaData = mb + end + local guid = if type(e.guid) == "string" and #e.guid == 32 and string.match(e.guid, "^%x+$") then string.lower(e.guid) else nil + guid = guid or (if metaData then metaGuid(metaData) else nil) or Md5.of(buffer.fromstring(path)) + if used[guid :: string] then + guid = Md5.of(buffer.fromstring(path .. "\0" .. guid)) + end + used[guid :: string] = true + local g = guid :: string + metaData = metaData or buffer.fromstring(defaultMeta(g, e.dir == true)) + table.insert(list, { name = g .. "/", dir = true, mtime = mtime }) + if data then + table.insert(list, { name = g .. "/asset", data = data, mtime = mtime }) + end + table.insert(list, { name = g .. "/asset.meta", data = metaData, mtime = mtime }) + table.insert(list, { name = g .. "/pathname", data = buffer.fromstring(path), mtime = mtime }) + if type(e.preview) == "function" then + local ok, pb = pcall(e.preview) + if ok and type(pb) == "buffer" then + table.insert(list, { name = g .. "/preview.png", data = pb, mtime = mtime }) + end + end + end + end + local tar, terr = Tar.write(list, { format = "ustar" }) + if not tar then + return nil, terr + end + return Deflate.gzip(tar, { level = o.level or 6 }) +end + +-- ------------------------------------------------------------------------------------------------ extras +function UnityPackage.new(): any + local a = Archive.new("unitypackage", encode) + a.meta.source = { format = "unitypackage" } + return a +end + +return UnityPackage diff --git a/tests/archive/unitypackage.luau b/tests/archive/unitypackage.luau new file mode 100644 index 0000000..61f1b42 --- /dev/null +++ b/tests/archive/unitypackage.luau @@ -0,0 +1,136 @@ +-- archive/unitypackage tests: packages built with Python's tarfile against their asset tables (paths, guids, asset +-- and meta MD5s, folders); our writer's output read by Python's tarfile; api detection; errors; fuzz. +-- Fixtures: tools/fixtures/unitypackage.py. +local T = require("@tests/T") +local F = require("@rosetta") +local UnityPackage = require("@rosetta/archive/unitypackage") +local Bytes = require("@rosetta/core/Bytes") +local Err = require("@rosetta/core/Err") +local Md5 = require("@rosetta/core/Md5") +local Fx = require("@tests/gen/unitypackage") + +local t = T.suite("unitypackage") + +local function decode(s: string | buffer, opts: any?): (any, any) + local b = if type(s) == "string" then buffer.fromstring(s) else s + return UnityPackage.decode(Bytes.reader(b), opts) +end + +t:eq(UnityPackage.name, "unitypackage", "name") +t:eq(UnityPackage.category, "archive", "category") +t:check(UnityPackage.caps.decode and UnityPackage.caps.encode, "caps") + +local function checkAssets(a: any, assets: { any }, label: string) + local entries = {} + for _, e in a:list() do + entries[e.name] = e + end + local n = 0 + for _, want in assets do + local e = entries[want.path] + t:check(e, label .. ": " .. want.path .. " listed") + if e then + n += 1 + t:eq(e.dir, want.dir, label .. ": " .. want.path .. " dir") + t:eq(e.guid, want.guid, label .. ": " .. want.path .. " guid") + if not want.dir then + local b = a:read(want.path) + t:eq(Md5.of(b), want.md5, label .. ": " .. want.path .. " data") + end + local m = a:read(want.path .. ".meta") + t:check(m and Md5.of(m) == want.metaMd5, label .. ": " .. want.path .. ".meta") + end + end + t:eq(#a:list(), n * 2, label .. ": an entry and a .meta per asset, nothing else") +end + +local samples = {} +for _, c in Fx.cases do + local a, err = decode(c.data) + t:check(a, c.name .. ": decode: " .. tostring(err)) + if a then + checkAssets(a, c.assets, c.name) + t:eq(a.meta.source.assets, #c.assets, c.name .. ": asset count") + local e + for _, x in a:list() do + if x.name == "Assets/Textures/brick.png" then + e = x + end + end + local pv = e and e.preview and e.preview() + t:check(pv and buffer.readstring(pv, 8, 7) == "preview", c.name .. ": preview.png") + -- round trip through our writer + local out, werr = UnityPackage.encode(a) + t:check(out, c.name .. ": encode: " .. tostring(werr)) + local back = out and decode(out) + t:check(back, c.name .. ": re-decode") + if back then + checkAssets(back, c.assets, c.name .. " round trip") + end + end + t:eq(UnityPackage.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, c.name .. ": sniff") + t:eq(F.detect(c.data, { name = "pack.unitypackage" }), "unitypackage", c.name .. ": F.detect with the extension") + table.insert(samples, c.data) +end + +-- Python's tarfile reads ours +for _, o in Fx.ours do + t:check(o.ok, o.name .. ": Python reads it: " .. tostring(o.error)) + local want: any = nil + for _, c in Fx.cases do + if c.name .. ".unitypackage" == o.name then + want = c.assets + end + end + if want then + local got = {} + for _, x in o.assets do + got[x.path] = x + end + for _, w in want do + local g = got[w.path] + t:check(g and g.guid == w.guid and g.md5 == w.md5 and g.metaMd5 == w.metaMd5 and g.dir == w.dir, o.name .. ": " .. w.path) + end + t:eq(#o.assets, #want, o.name .. ": asset count") + elseif o.name == "scratch.unitypackage" then + local got = {} + for _, x in o.assets do + got[x.path] = x + end + t:check(got["Assets/Models"] and got["Assets/Models"].dir, "scratch: folder") + t:check(got["Assets/Models/cube.obj"] and not got["Assets/Models/cube.obj"].dir, "scratch: file") + t:eq(got["Assets/readme.txt"] and got["Assets/readme.txt"].guid, "0123456789abcdef0123456789abcdef", "scratch: guid from the .meta") + t:eq(#o.assets, 3, "scratch: assets") + end +end + +-- from any archive (a tar) through F.save +do + local tar = F.format("tar").new() + tar:add("Assets/a.txt", "a") + tar:add("Assets/b/", "", { dir = true }) + local out = assert(F.save(tar, nil, { format = "unitypackage" })) + local back = assert(decode(out)) + local names = {} + for _, e in back:list() do + names[e.name] = e.dir + end + t:check(names["Assets/a.txt"] == false and names["Assets/a.txt.meta"] == false and names["Assets/b"] == true, "tar -> unitypackage") + local meta = buffer.tostring(back:read("Assets/b.meta")) + t:check(string.find(meta, "folderAsset: yes", 1, true) ~= nil, "folder meta") +end + +do + local _, e = decode("\31\139\8\0\0\0\0\0\0\255garbage") + t:check(e ~= nil, "bad deflate data") + local _, e2 = decode(Fx.cases[1].data, { maxEntries = 2 }) + t:check(e2 and e2.code == Err.LIMIT, "entry limit: " .. tostring(e2)) + local _, e3 = UnityPackage.encode({} :: any) + t:check(e3 and e3.code == Err.ARG, "encode arg") + t:eq(UnityPackage.sniff(Bytes.reader(buffer.fromstring("hello"))), 0, "sniff text") +end + +t:fuzz("decode", function(b: buffer) + return decode(b) +end, samples) +t:done() diff --git a/tools/fixtures/_unitypackage_encode.luau b/tools/fixtures/_unitypackage_encode.luau new file mode 100644 index 0000000..eb2cfcb --- /dev/null +++ b/tools/fixtures/_unitypackage_encode.luau @@ -0,0 +1,36 @@ +-- tools/fixtures/_unitypackage_encode: run by tools/fixtures/unitypackage.py (luau CLI, repo root): re-encodes every +-- package case and a package built from scratch, printing "\t" lines for Python's tarfile to read. +local UnityPackage = require("@rosetta/archive/unitypackage") +local Bytes = require("@rosetta/core/Bytes") +local Fx = require("@tests/gen/unitypackage") + +local HEX = {} +for i = 0, 255 do + HEX[i] = string.format("%02x", i) +end +local function hex(b: buffer): string + local out = table.create(buffer.len(b)) + for i = 0, buffer.len(b) - 1 do + out[i + 1] = HEX[buffer.readu8(b, i)] + end + return table.concat(out) +end + +for _, c in Fx.cases do + local a = UnityPackage.decode(Bytes.reader(buffer.fromstring(c.data))) + if a then + local out = UnityPackage.encode(a) + if out then + print(c.name .. ".unitypackage\t" .. hex(out)) + end + end +end +local a = UnityPackage.new() +a:add("Assets/Models", "", { dir = true }) +a:add("Assets/Models/cube.obj", "v 0 0 0\n") +a:add("Assets/readme.txt", "hello\n") +a:add("Assets/readme.txt.meta", "fileFormatVersion: 2\nguid: 0123456789abcdef0123456789abcdef\n") +local out = UnityPackage.encode(a) +if out then + print("scratch.unitypackage\t" .. hex(out)) +end diff --git a/tools/fixtures/unitypackage.py b/tools/fixtures/unitypackage.py new file mode 100644 index 0000000..cb0276d --- /dev/null +++ b/tools/fixtures/unitypackage.py @@ -0,0 +1,95 @@ +# .unitypackage fixtures (tools/fixtures.py): packages built here with Python's tarfile + gzip to the layout Unity +# writes (/asset, /asset.meta, /pathname, optional preview.png; folders carry only a meta), with +# the expected asset table; then our encoder's output (tools/fixtures/_unitypackage_encode.luau) read back by +# Python's tarfile. +# tests/gen/unitypackage.luau { cases = { { name, data, assets = { { path, guid, md5?, metaMd5, dir } } } }, +# ours = { { name, ok, assets = { { path, guid, md5?, metaMd5, dir } }, error? } } } +import gzip, hashlib, importlib.util, io, os, tarfile, uuid + +INPUTS = ["src/Rosetta/archive/unitypackage", "tools/fixtures/_unitypackage_encode.luau", "tools/fixtures/_model_ref.py"] + + +def meta(guid, folder=False): + s = "fileFormatVersion: 2\nguid: %s\n" % guid + if folder: + s += "folderAsset: yes\n" + return (s + "DefaultImporter:\n externalObjects: {}\n userData: \n").encode() + + +def build(items, dot=False, extra_line=False, mtime=1600000000): + """items: [(path, data or None for a folder, preview bytes or None)]""" + raw = io.BytesIO() + assets = [] + with tarfile.open(fileobj=raw, mode="w", format=tarfile.GNU_FORMAT) as tf: + def add(name, data): + ti = tarfile.TarInfo(("./" if dot else "") + name) + ti.size = len(data) + ti.mtime = mtime + tf.addfile(ti, io.BytesIO(data)) + for path, data, preview in items: + guid = uuid.uuid5(uuid.NAMESPACE_URL, path).hex + d = tarfile.TarInfo(("./" if dot else "") + guid) + d.type = tarfile.DIRTYPE + d.mtime = mtime + tf.addfile(d) + m = meta(guid, data is None) + if data is not None: + add(guid + "/asset", data) + add(guid + "/asset.meta", m) + add(guid + "/pathname", (path + ("\n00" if extra_line else "")).encode()) + if preview: + add(guid + "/preview.png", preview) + a = {"path": path, "guid": guid, "metaMd5": hashlib.md5(m).hexdigest(), "dir": data is None} + if data is not None: + a["md5"] = hashlib.md5(data).hexdigest() + assets.append(a) + return gzip.compress(raw.getvalue(), mtime=0), assets + + +def read_package(data): + out = [] + with tarfile.open(fileobj=io.BytesIO(gzip.decompress(data))) as tf: + files = {} + for m in tf.getmembers(): + if m.isfile(): + files[m.name] = tf.extractfile(m).read() + guids = sorted({n.split("/")[0] for n in files}) + for g in guids: + path = files[g + "/pathname"].decode().split("\n")[0] + m = files[g + "/asset.meta"] + if ("guid: " + g).encode() not in m: + raise ValueError("meta guid mismatch for " + path) + a = {"path": path, "guid": g, "metaMd5": hashlib.md5(m).hexdigest(), "dir": (g + "/asset") not in files} + if not a["dir"]: + a["md5"] = hashlib.md5(files[g + "/asset"]).hexdigest() + out.append(a) + return out + + +def generate(ctx): + rng = ctx.rng(7) + png = b"\x89PNG\r\n\x1a\n" + rng.randbytes(200) + items = [ + ("Assets", None, None), + ("Assets/Textures", None, None), + ("Assets/Textures/brick.png", png, b"\x89PNG\r\n\x1a\npreview"), + ("Assets/Scripts/Player.cs", b"using UnityEngine;\npublic class Player : MonoBehaviour { }\n", None), + ("Assets/Scenes/Main Scene.unity", b"%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:\n--- !u!1 &1\n", None), + ("Assets/Audio/empty.wav", b"", None), + ("Assets/Big/blob.bin", rng.randbytes(70000), None), + ] + cases = [] + for name, kw in (("plain", {}), ("dot", {"dot": True}), ("extra-line", {"extra_line": True})): + data, assets = build(items, **kw) + cases.append({"name": name, "data": data, "assets": assets}) + ctx.emit("unitypackage", {"cases": cases, "ours": []}) + spec = importlib.util.spec_from_file_location("_model_ref", os.path.join(ctx.root, "tools", "fixtures", "_model_ref.py")) + M = importlib.util.module_from_spec(spec) + spec.loader.exec_module(M) + ours = [] + for name, data in sorted(M.luau_encode(ctx, "tools/fixtures/_unitypackage_encode.luau").items()): + try: + ours.append({"name": name, "ok": True, "assets": read_package(data)}) + except Exception as e: + ours.append({"name": name, "ok": False, "assets": [], "error": str(e)}) + ctx.emit("unitypackage", {"cases": cases, "ours": ours}) From 524179ec6749fe26c167c219abbfe640b8cbf537 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 18:39:06 -0600 Subject: [PATCH 03/10] archive/unitypackage: type annotations --- build/Rosetta.luau | 1490 ++++++++++++++++++++ build/Rosetta.luau.linemap.json | 1075 +++++++------- build/rosetta.lua | 1490 ++++++++++++++++++++ build/rosetta.lua.linemap.json | 1075 +++++++------- src/Rosetta/archive/unitypackage/init.luau | 19 +- tests/archive/unitypackage.luau | 2 +- 6 files changed, 4070 insertions(+), 1081 deletions(-) diff --git a/build/Rosetta.luau b/build/Rosetta.luau index 7d956b2..17f6ee9 100644 --- a/build/Rosetta.luau +++ b/build/Rosetta.luau @@ -1592,6 +1592,18 @@ local list: { Entry } = { return __include("model/3mf") end, }, + { + name = "ase", + category = "model", + path = "model/ase", + extensions = { "ase", "ask" }, + mime = { "model/x-ase", "text/plain" }, + deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Text", "codecs/model/Mat4" }, + caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, vertexColors = true }, + load = function() + return __include("model/ase") + end, + }, { name = "b3d", category = "model", @@ -2360,6 +2372,18 @@ local list: { Entry } = { return __include("archive/tar") end, }, + { + name = "unitypackage", + category = "archive", + path = "archive/unitypackage", + extensions = { "unitypackage" }, + mime = { "application/x-unitypackage" }, + deps = { "core/Err", "core/Bytes", "core/Md5", "codecs/compress/Deflate", "containers/Archive", "containers/Tar" }, + caps = { decode = true, encode = true }, + load = function() + return __include("archive/unitypackage") + end, + }, { name = "uu", category = "archive", @@ -9983,6 +10007,243 @@ end return TarFormat end +__FILES["archive/unitypackage"] = function() + +-- archive/unitypackage: Unity asset packages, a gzip'd tar of /asset, /asset.meta, /pathname +-- (+ preview.png), read + write as an Archive keyed by the asset paths (Assets/...), each .meta next to its asset as +-- in a Unity project. Supports: folders (meta only), lazy entries, guids kept (entry.guid) or made from the path. +-- Not supported: pre-5.x packages without pathname files. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Md5 = __include("core/Md5") +local Deflate = __include("codecs/compress/Deflate") +local Archive = __include("containers/Archive") +local Tar = __include("containers/Tar") + +-- ------------------------------------------------------------------------------------------------ contract +local UnityPackage = { + name = "unitypackage", + category = "archive", + extensions = { "unitypackage" }, + mime = { "application/x-unitypackage" }, + deps = { "core/Err", "core/Bytes", "core/Md5", "codecs/compress/Deflate", "containers/Archive", "containers/Tar" }, + caps = { decode = true, encode = true }, +} + +type DecodeOptions = { + maxEntries: number?, -- default 1e6 + maxBytes: number?, -- inflated size, default 2^31 +} +type EncodeOptions = { + level: number?, -- deflate 0..9, default 6 + mtime: number?, -- tar entry time, default 0 +} + +-- ------------------------------------------------------------------------------------------------ sniff +local function guidOf(name: string): (string?, string?) + local n = string.gsub(name, "^%./", "") + local guid, rest = string.match(n, "^(%x+)/?(.*)$") + if guid and #guid == 32 then + return string.lower(guid), rest + end + return nil, nil +end + +function UnityPackage.sniff(r: Bytes.Reader): number + if r:peek(3) ~= "\31\139\8" then + return 0 + end + local head = Deflate.peek(r.buf, r.pos, r.limit - r.pos, 512) + if not head or buffer.len(head) < 512 or not Tar.valid(head, 0) then + return 0 + end + local z = 0 + while z < 100 and buffer.readu8(head, z) ~= 0 do + z += 1 + end + return if guidOf(buffer.readstring(head, 0, z)) then 1 else 0 -- ties with archive/gzip go to the extension +end + +-- ------------------------------------------------------------------------------------------------ decode +local function encode(archive: any, opts: any?): (buffer?, Err.Err?) + return UnityPackage.encode(archive, opts) +end + +type Asset = { asset: Tar.Entry?, meta: Tar.Entry?, pathname: Tar.Entry?, preview: Tar.Entry? } + +local function text(b: buffer, e: Tar.Entry): string + return buffer.readstring(b, e.offset, e.size) +end + +function UnityPackage.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) + local o = opts or {} + local tar, err = Deflate.gunzip(r.buf, r.base, r.limit - r.base) + if not tar then + return nil, err + end + if buffer.len(tar) > (o.maxBytes or 2 ^ 31) then + return nil, Err.new(Err.LIMIT, "inflated size over the byte limit") + end + local list, terr = Tar.read(tar, 0, buffer.len(tar), { maxEntries = o.maxEntries }) + if not list then + return nil, terr + end + local byGuid: { [string]: Asset } = {} + local order: { string } = {} + for _, e in list do + local guid, rest = guidOf(e.name) + if guid and not e.dir then + local a = byGuid[guid] + if not a then + a = {} + byGuid[guid] = a + table.insert(order, guid) + end + if rest == "asset" then + a.asset = e + elseif rest == "asset.meta" then + a.meta = e + elseif rest == "pathname" then + a.pathname = e + elseif rest == "preview.png" then + a.preview = e + end + end + end + local arc = Archive.new("unitypackage", encode) + local skipped = 0 + for _, guid in order do + local a = byGuid[guid] + local pn = a.pathname + if not pn then + skipped += 1 + else + -- the first line is the path (Unity 5+ may add a second line, e.g. "00") + local path = string.match(text(tar, pn), "^[^\r\n]*") or "" + path = string.gsub(path, "\\", "/") + if path ~= "" then + local asset, meta = a.asset, a.meta + local isDir = asset == nil + Archive.put(arc, { + name = path, + size = if asset then asset.size else 0, + dir = isDir, + mtime = if asset then asset.mtime elseif meta then meta.mtime else nil, + method = "deflate", + guid = guid, + load = if asset and asset.size > 0 then Archive.slice(tar, asset.offset, asset.size) else nil, + preview = if a.preview then Archive.slice(tar, a.preview.offset, a.preview.size) else nil, + }) + if meta then + Archive.put(arc, { + name = path .. ".meta", + size = meta.size, + dir = false, + mtime = meta.mtime, + method = "deflate", + guid = guid, + load = if meta.size > 0 then Archive.slice(tar, meta.offset, meta.size) else nil, + }) + end + end + end + end + arc.meta.source = { format = "unitypackage", assets = #order - skipped, skipped = if skipped > 0 then skipped else nil } + return arc, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +local function metaGuid(b: buffer): string? + local s = buffer.readstring(b, 0, math.min(buffer.len(b), 4096)) + local g = string.match(s, "\nguid:%s*(%x+)") or string.match(s, "^guid:%s*(%x+)") + if g and #g == 32 then + return string.lower(g) + end + return nil +end + +local function defaultMeta(guid: string, dir: boolean): string + if dir then + return "fileFormatVersion: 2\nguid: " .. guid .. "\nfolderAsset: yes\nDefaultImporter:\n externalObjects: {}\n userData: \n assetBundleName: \n assetBundleVariant: \n" + end + return "fileFormatVersion: 2\nguid: " .. guid .. "\nDefaultImporter:\n externalObjects: {}\n userData: \n assetBundleName: \n assetBundleVariant: \n" +end + +function UnityPackage.encode(archive: any, opts: EncodeOptions?): (buffer?, Err.Err?) + local o = opts or {} + local items = Archive.entries(archive) + if not items then + return nil, Err.new(Err.ARG, "expected an Archive") + end + local byName: { [string]: any } = {} + for _, it in items do + byName[string.gsub(it.entry.name, "\\", "/")] = it + end + local mtime = o.mtime or 0 + local list: { Tar.WriteEntry } = {} + local used: { [string]: boolean } = {} + for _, it in items do + local e: any = it.entry + local path = string.gsub((string.gsub(e.name, "\\", "/")), "/+$", "") + local metaIt = byName[path .. ".meta"] + local isMeta = string.sub(path, -5) == ".meta" and byName[string.sub(path, 1, -6)] ~= nil + if path ~= "" and not isMeta then + local data: buffer? = nil + if not e.dir then + local b, rerr = it.read() + if not b then + return nil, rerr + end + data = b + end + local metaData: buffer? = nil + if metaIt then + local mb, merr = metaIt.read() + if not mb then + return nil, merr + end + metaData = mb + end + local guid = if type(e.guid) == "string" and #e.guid == 32 and string.match(e.guid, "^%x+$") then string.lower(e.guid) else nil + guid = guid or (if metaData then metaGuid(metaData) else nil) or Md5.of(buffer.fromstring(path)) + if used[guid :: string] then + guid = Md5.of(buffer.fromstring(path .. "\0" .. guid)) + end + used[guid :: string] = true + local g = guid :: string + metaData = metaData or buffer.fromstring(defaultMeta(g, e.dir == true)) + table.insert(list, { name = g .. "/", dir = true, mtime = mtime }) + if data then + table.insert(list, { name = g .. "/asset", data = data, mtime = mtime }) + end + table.insert(list, { name = g .. "/asset.meta", data = metaData, mtime = mtime }) + table.insert(list, { name = g .. "/pathname", data = buffer.fromstring(path), mtime = mtime }) + if type(e.preview) == "function" then + local ok, pb = pcall(e.preview) + if ok and type(pb) == "buffer" then + table.insert(list, { name = g .. "/preview.png", data = pb, mtime = mtime }) + end + end + end + end + local tar, terr = Tar.write(list, { format = "ustar" }) + if not tar then + return nil, terr + end + return Deflate.gzip(tar, { level = o.level or 6 }) +end + +-- ------------------------------------------------------------------------------------------------ extras +function UnityPackage.new(): any + local a = Archive.new("unitypackage", encode) + a.meta.source = { format = "unitypackage" } + return a +end + +return UnityPackage +end __FILES["archive/uu"] = function() -- archive/uu: uuencode (POSIX), xxencode and GNU "begin-base64" blocks, one entry each (variant detected per block); @@ -143816,6 +144077,1235 @@ function Write.build(scene: Types.Scene, opts: any): (buffer?, Err.Err?) return w:finish() end +return Write +end +__FILES["model/ase"] = function() + +-- model/ase: 3ds Max ASCII Scene Export (*3DSMAX_ASCIIEXPORT 200), read + write; checked against assimp's ASE loader. +-- Supports: geometry objects (texture channels, vertex colours, explicit normals, Multi/Sub-Object materials by +-- *MESH_MTLID), NODE_TM hierarchies, helpers, cameras, lights, material maps (paths; data through opts.resolve), +-- UTF-16 files. Not supported: *TM_ANIMATION tracks (meta.source.animated is set), shapes (nodes only), bones. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Types = __include("Types") +local Text = __include("codecs/text/Text") +local Parse = __include("model/ase/Parse") +local Build = __include("model/ase/Build") +local Write = __include("model/ase/Write") + +-- ------------------------------------------------------------------------------------------------ contract +local Ase = { + name = "ase", + category = "model", + extensions = { "ase", "ask" }, + mime = { "model/x-ase", "text/plain" }, + deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Text", "codecs/model/Mat4" }, + caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, vertexColors = true }, +} + +-- ------------------------------------------------------------------------------------------------ types +type DecodeOptions = { + maxBytes: number?, -- default 2^28 + maxItems: number?, -- default 2^24 (*KEY items) + maxVertices: number?, -- default 2^24 (per object) + resolve: ((string) -> buffer?)?, -- texture bitmaps by path +} +type EncodeOptions = { + comment: string?, +} + +-- ------------------------------------------------------------------------------------------------ constants +local MAGIC = "*3DSMAX_ASCIIEXPORT" + +-- ------------------------------------------------------------------------------------------------ sniff +local function utf16(r: Bytes.Reader): (boolean?, boolean) + local h = r:peek(2) + if h == "\255\254" then + return true, false + elseif h == "\254\255" then + return true, true + elseif #h == 2 and string.byte(h, 2) == 0 and string.byte(h, 1) == 42 then + return true, false + elseif #h == 2 and string.byte(h, 1) == 0 and string.byte(h, 2) == 42 then + return true, true + end + return nil, false +end + +local function text(r: Bytes.Reader, n: number?): string + local wide, be = utf16(r) + local len = r.limit - r.pos + if n then + len = math.min(len, n) + end + if wide then + local skip = if r:peek(2) == "\255\254" or r:peek(2) == "\254\255" then 2 else 0 + return Text.utf16(r.buf, r.pos + skip, len - skip, be) + end + return Text.toUtf8(buffer.readstring(r.buf, r.pos, len)) +end + +function Ase.sniff(r: Bytes.Reader): number + local h = string.match(text(r, 256), "^%s*(%*[%w_]+)") + if h == MAGIC then + return 1 + end + return 0 +end + +-- ------------------------------------------------------------------------------------------------ decode +function Ase.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?) + local o: any = opts or {} + if r.limit - r.pos > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local s = text(r) + if not string.match(s, "^%s*%*") then + return nil, Err.new(Err.CORRUPT, "not an ASE file") + end + local ok, root, msg = pcall(Parse.tree, s, o.maxItems or 2 ^ 24) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad data: " .. tostring(root)) + end + if not root then + return nil, Err.from(msg) + end + local ok2, scene, msg2 = pcall(Build.scene, root, o) + if not ok2 then + return nil, Err.from(tostring(scene)) + end + if not scene then + return nil, Err.from(msg2) + end + if #scene.nodes == 0 and (scene.meta.source :: any).version == nil then + return nil, Err.new(Err.CORRUPT, "no *3DSMAX_ASCIIEXPORT header and no objects") + end + return scene, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +function Ase.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, "needs a Scene") + end + local ok, s, msg = pcall(Write.scene, scene, opts) + if not ok then + return nil, Err.new(Err.ARG, "bad scene: " .. tostring(s)) + end + if not s then + return nil, Err.new(Err.ARG, msg or "bad scene") + end + return buffer.fromstring(s), nil +end + +return Ase +end +__FILES["model/ase/Build"] = function() + +-- model/ase/Build: the parsed ASE tree into a Scene. Mesh vertices are stored in world space (3ds Max ASCII export): +-- they are moved into the node's frame by the inverse NODE_TM, and node matrices are made relative to *NODE_PARENT. +local Types = __include("Types") +local Mat4 = __include("codecs/model/Mat4") +local Parse = __include("model/ase/Parse") + +type Item = Parse.Item + +local Build = {} + +local S = Types.Scene + +local function first(kids: { Item }?, key: string): Item? + if kids then + for _, it in kids do + if it.key == key then + return it + end + end + end + return nil +end + +local function num(it: Item?, i: number?): number? + if not it then + return nil + end + local v = tonumber(it.args[i or 1]) + if v and v == v and v ~= math.huge and v ~= -math.huge then + return v + end + return nil +end + +local function get(kids: { Item }?, key: string, i: number?): number? + return num(first(kids, key), i) +end + +local function str(kids: { Item }?, key: string): string? + local it = first(kids, key) + return if it then it.args[1] else nil +end + +local function triple(kids: { Item }?, key: string): { number }? + local it = first(kids, key) + if not it then + return nil + end + local a, b, c = num(it, 1), num(it, 2), num(it, 3) + if a and b and c then + return { a, b, c } + end + return nil +end + +-- *TM_ROW0..2 are the axes, *TM_ROW3 the translation (row vectors): the columns of a column-major matrix +local function nodeTm(kids: { Item }?): { number } + local tm = first(kids, "NODE_TM") + local m = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } + if not tm then + return m + end + for r = 0, 3 do + local row = triple(tm.kids, "TM_ROW" .. r) + if row then + m[r * 4 + 1], m[r * 4 + 2], m[r * 4 + 3] = row[1], row[2], row[3] + end + end + return m +end + +-- ------------------------------------------------------------------------------------------------ materials +local MAPS = { "MAP_DIFFUSE", "MAP_BUMP", "MAP_OPACITY", "MAP_SELFILLUM", "MAP_SPECULAR", "MAP_SHINE", "MAP_AMBIENT", "MAP_REFLECT", "MAP_REFRACT", "MAP_SHINESTRENGTH", "MAP_FILTERCOLOR" } + +local function textureRef(scene: Types.Scene, map: Item, opts: any): (Types.TextureRef?, { [string]: any }) + local k = map.kids + local info: { [string]: any } = { + name = str(k, "MAP_NAME"), + class = str(k, "MAP_CLASS"), + amount = get(k, "MAP_AMOUNT"), + bitmap = str(k, "BITMAP"), + uOffset = get(k, "UVW_U_OFFSET"), + vOffset = get(k, "UVW_V_OFFSET"), + uTiling = get(k, "UVW_U_TILING"), + vTiling = get(k, "UVW_V_TILING"), + angle = get(k, "UVW_ANGLE"), + } + local path = info.bitmap + if type(path) ~= "string" or path == "" then + return nil, info + end + local tex: Types.Texture = { name = path, uri = path } + if opts and type(opts.resolve) == "function" then + local ok, data = pcall(opts.resolve, path) + if ok and type(data) == "buffer" then + tex.data = data + end + end + table.insert(scene.textures, tex) + local ref: Types.TextureRef = { texture = #scene.textures } + local su, sv = info.uTiling or 1, info.vTiling or 1 + local ou, ov = info.uOffset or 0, info.vOffset or 0 + local ang = info.angle or 0 + if su ~= 1 or sv ~= 1 or ou ~= 0 or ov ~= 0 or ang ~= 0 then + ref.transform = { offset = { ou, ov }, scale = { su, sv }, rotation = ang } + end + return ref, info +end + +local function material(scene: Types.Scene, it: Item, opts: any): Types.Material + local k = it.kids + local m = S.material(str(k, "MATERIAL_NAME")) + local diffuse = triple(k, "MATERIAL_DIFFUSE") or { 0.8, 0.8, 0.8 } + local transparency = get(k, "MATERIAL_TRANSPARENCY") or 0 + local shine = get(k, "MATERIAL_SHINE") or 0 + local selfIllum = get(k, "MATERIAL_SELFILLUM") or 0 + m.baseColor = { diffuse[1], diffuse[2], diffuse[3], 1 - transparency } + m.metallic = 0 + m.roughness = math.clamp(1 - shine, 0, 1) + m.emissive = { diffuse[1] * selfIllum, diffuse[2] * selfIllum, diffuse[3] * selfIllum } + if transparency > 0 then + m.alphaMode = "blend" + end + m.doubleSided = first(k, "MATERIAL_TWOSIDED") ~= nil + local maps: { [string]: any } = {} + for _, key in MAPS do + local map = first(k, key) + if map then + local ref, info = textureRef(scene, map, opts) + maps[string.lower(string.sub(key, 5))] = info + if ref then + if key == "MAP_DIFFUSE" then + m.baseColorTexture = ref + elseif key == "MAP_BUMP" then + m.normalTexture = ref + elseif key == "MAP_SELFILLUM" then + m.emissiveTexture = ref + m.emissive = { 1, 1, 1 } + end + end + end + end + m.extras = { + ambient = triple(k, "MATERIAL_AMBIENT"), + diffuse = diffuse, + specular = triple(k, "MATERIAL_SPECULAR"), + shininess = shine, + shineStrength = get(k, "MATERIAL_SHINESTRENGTH"), + transparency = transparency, + selfIllum = selfIllum, + ase = { class = str(k, "MATERIAL_CLASS"), shading = str(k, "MATERIAL_SHADING"), maps = maps }, + } + return m +end + +-- ASE material index (0-based) -> { scene material per sub-material } (one entry when it has none) +local function materials(scene: Types.Scene, list: Item?, opts: any): { { number } } + local out: { { number } } = {} + if not list or not list.kids then + return out + end + for _, it in list.kids do + if it.key == "MATERIAL" then + local subs: { number } = {} + for _, sub in it.kids or {} do + if sub.key == "SUBMATERIAL" then + table.insert(scene.materials, material(scene, sub, opts)) + table.insert(subs, #scene.materials) + end + end + if #subs == 0 then + table.insert(scene.materials, material(scene, it, opts)) + subs[1] = #scene.materials + end + table.insert(out, subs) + end + end + return out +end + +-- ------------------------------------------------------------------------------------------------ meshes +type Lists = { v: { number }, n: number } + +local function vectors(kids: { Item }?, listKey: string, itemKey: string, comps: number, max: number): { number } + local out: { number } = {} + local list = first(kids, listKey) + if not list or not list.kids then + return out + end + for _, it in list.kids do + if it.key == itemKey then + local i = num(it, 1) + if i and i >= 0 and i < max and i % 1 == 0 then + for c = 1, comps do + out[i * comps + c] = num(it, c + 1) or 0 + end + end + end + end + return out +end + +local function corners(kids: { Item }?, listKey: string, itemKey: string, max: number): { number } + local out: { number } = {} + local list = first(kids, listKey) + if not list or not list.kids then + return out + end + for _, it in list.kids do + if it.key == itemKey then + local i = num(it, 1) + if i and i >= 0 and i < max and i % 1 == 0 then + out[i * 3 + 1], out[i * 3 + 2], out[i * 3 + 3] = num(it, 2) or 0, num(it, 3) or 0, num(it, 4) or 0 + end + end + end + return out +end + +type Face = { a: number, b: number, c: number, mtl: number, smoothing: string? } + +-- *MESH_FACE i: A: a B: b C: c AB: e BC: e CA: e, then its *MESH_SMOOTHING / *MESH_MTLID siblings +local function faces(list: Item?, nv: number, maxFaces: number): ({ Face }?, string?) + local out: { Face } = {} + if not list or not list.kids then + return out, nil + end + local last: Face? = nil + for _, it in list.kids do + if it.key == "MESH_FACE" then + local s = table.concat(it.args, " ") + local i = tonumber(string.match(s, "^(%d+)")) + local a = tonumber(string.match(s, "A:%s*(%d+)")) + local b = tonumber(string.match(s, "B:%s*(%d+)")) + local c = tonumber(string.match(s, "C:%s*(%d+)")) + if not (i and a and b and c) then + return nil, "bad *MESH_FACE at byte " .. it.at + end + if a >= nv or b >= nv or c >= nv then + return nil, "face vertex index out of range at byte " .. it.at + end + if i >= maxFaces then + return nil, "limit: face index " .. i + end + local f: Face = { a = a, b = b, c = c, mtl = 0, smoothing = nil } + out[i + 1] = f + last = f + elseif it.key == "MESH_MTLID" and last then + last.mtl = math.max(0, math.floor(num(it) or 0)) + elseif it.key == "MESH_SMOOTHING" and last then + last.smoothing = it.args[1] + end + end + for i = 1, #out do + if out[i] == nil then + out[i] = { a = 0, b = 0, c = 0, mtl = 0, smoothing = nil } + end + end + return out, nil +end + +type Channel = { verts: { number }, tf: { number }, comps: number } + +local function channel(kids: { Item }?, numKey: string, listKey: string, vertKey: string, tfKey: string, tfListKey: string, nf: number, maxV: number): Channel? + local n = get(kids, numKey) or 0 + if n <= 0 then + return nil + end + n = math.min(n, maxV) + local verts = vectors(kids, listKey, vertKey, 3, n) + local tf = corners(kids, tfListKey, tfKey, nf) + return { verts = verts, tf = tf, comps = 3 } +end + +local function writeVec(acc: Types.Accessor, i: number, x: number, y: number, z: number) + local d = acc.data + buffer.writef32(d, i * 12, x) + buffer.writef32(d, i * 12 + 4, y) + buffer.writef32(d, i * 12 + 8, z) +end + +local function mesh(scene: Types.Scene, obj: Item, matMap: { { number } }, world: { number }, opts: any): (number?, string?) + local m = first(obj.kids, "MESH") + if not m or not m.kids then + return nil, nil + end + local k = m.kids + local maxV = opts.maxVertices or 2 ^ 24 + local nv = get(k, "MESH_NUMVERTEX") or 0 + local nf = get(k, "MESH_NUMFACES") or 0 + if nv < 0 or nf < 0 or nv % 1 ~= 0 or nf % 1 ~= 0 then + return nil, "bad vertex or face count" + end + if nv > maxV or nf * 3 > maxV then + return nil, "limit: " .. nv .. " vertices, " .. nf .. " faces" + end + local pos = vectors(k, "MESH_VERTEX_LIST", "MESH_VERTEX", 3, nv) + local fl, ferr = faces(first(k, "MESH_FACE_LIST"), nv, nf) + if not fl then + return nil, ferr + end + if #fl == 0 then + return nil, nil + end + local uvs: { Channel } = {} + local ch0 = channel(k, "MESH_NUMTVERTEX", "MESH_TVERTLIST", "MESH_TVERT", "MESH_TFACE", "MESH_TFACELIST", #fl, maxV) + if ch0 then + uvs[1] = ch0 + end + for _, it in k do + if it.key == "MESH_MAPPINGCHANNEL" and it.kids then + local idx = num(it) or 0 + local ch = channel(it.kids, "MESH_NUMTVERTEX", "MESH_TVERTLIST", "MESH_TVERT", "MESH_TFACE", "MESH_TFACELIST", #fl, maxV) + if ch and idx >= 2 and idx <= 8 then + uvs[idx] = ch + end + end + end + local colors = channel(k, "MESH_NUMCVERTEX", "MESH_CVERTLIST", "MESH_VERTCOL", "MESH_CFACE", "MESH_CFACELIST", #fl, maxV) + -- *MESH_NORMALS: *MESH_FACENORMAL f, then *MESH_VERTEXNORMAL v x y z for each of its corners + local normals: { number }? = nil + local nlist = first(k, "MESH_NORMALS") + if nlist and nlist.kids then + local nn: { number } = {} + local face = -1 + for _, it in nlist.kids do + if it.key == "MESH_FACENORMAL" then + face = num(it) or -1 + elseif it.key == "MESH_VERTEXNORMAL" and face >= 0 and face < #fl then + local f = fl[face + 1] + local v = num(it) + local corner = if v == f.a then 0 elseif v == f.b then 1 elseif v == f.c then 2 else nil + if corner then + local o = (face * 3 + corner) * 3 + nn[o + 1], nn[o + 2], nn[o + 3] = num(it, 2) or 0, num(it, 3) or 0, num(it, 4) or 0 + end + end + end + normals = nn + end + -- faces by scene material (sub-material = *MESH_MTLID, the last one when out of range) + local ref = get(obj.kids, "MATERIAL_REF") + local subs: { number }? = if ref and ref >= 0 then matMap[math.min(ref, #matMap - 1) + 1] else nil + local groups: { [number]: { number } } = {} + local order: { number } = {} + for i, f in fl do + local key = 0 + if subs and #subs > 0 then + key = subs[math.min(f.mtl, #subs - 1) + 1] + end + local g = groups[key] + if not g then + g = {} + groups[key] = g + table.insert(order, key) + end + table.insert(g, i) + end + table.sort(order) + local inv = Mat4.inverse(world) + local local_ = inv or S.IDENTITY + local nmat = Mat4.normalMatrix(local_) + local out: Types.Mesh = { name = str(obj.kids, "NODE_NAME"), primitives = {} } + for _, key in order do + local list = groups[key] + local count = #list * 3 + local P = S.accessor(nil, "f32", 3, count) + local N = if normals then S.accessor(nil, "f32", 3, count) else nil + local UV: { [number]: Types.Accessor } = {} + for idx in uvs do + UV[idx] = S.accessor(nil, "f32", 2, count) + end + local C = if colors then S.accessor(nil, "f32", 4, count) else nil + local I = S.accessor(nil, "u32", 1, count) + local w = 0 + for _, fi in list do + local f = fl[fi] + local fc = { f.a, f.b, f.c } + for corner = 0, 2 do + local vi = fc[corner + 1] + local x, y, z = Mat4.point(local_, pos[vi * 3 + 1] or 0, pos[vi * 3 + 2] or 0, pos[vi * 3 + 3] or 0) + writeVec(P, w, x, y, z) + if N and normals then + local o = ((fi - 1) * 3 + corner) * 3 + local nx, ny, nz = normals[o + 1] or 0, normals[o + 2] or 0, normals[o + 3] or 0 + local tx = nmat[1] * nx + nmat[5] * ny + nmat[9] * nz + local ty = nmat[2] * nx + nmat[6] * ny + nmat[10] * nz + local tz = nmat[3] * nx + nmat[7] * ny + nmat[11] * nz + local len = math.sqrt(tx * tx + ty * ty + tz * tz) + if len > 0 then + tx, ty, tz = tx / len, ty / len, tz / len + end + writeVec(N, w, tx, ty, tz) + end + for idx, ch in uvs do + local ti = ch.tf[(fi - 1) * 3 + corner + 1] or 0 + local u, v = ch.verts[ti * 3 + 1] or 0, ch.verts[ti * 3 + 2] or 0 + buffer.writef32(UV[idx].data, w * 8, u) + buffer.writef32(UV[idx].data, w * 8 + 4, 1 - v) -- 3ds Max v goes up + end + if C and colors then + local ci = colors.tf[(fi - 1) * 3 + corner + 1] or 0 + local d = C.data + buffer.writef32(d, w * 16, colors.verts[ci * 3 + 1] or 1) + buffer.writef32(d, w * 16 + 4, colors.verts[ci * 3 + 2] or 1) + buffer.writef32(d, w * 16 + 8, colors.verts[ci * 3 + 3] or 1) + buffer.writef32(d, w * 16 + 12, 1) + end + buffer.writeu32(I.data, w * 4, w) + w += 1 + end + end + local attrs: { [string]: Types.Accessor } = { POSITION = P } + if N then + attrs.NORMAL = N + end + for idx, acc in UV do + attrs["TEXCOORD_" .. (idx - 1)] = acc + end + if C then + attrs.COLOR_0 = C + end + local smoothing: { string } = {} + for j, fi in list do + smoothing[j] = fl[fi].smoothing or "" + end + local prim: Types.Primitive = { + attributes = attrs, + indices = I, + mode = "triangles", + material = if key > 0 then key else nil, + extras = { smoothing = smoothing }, + } + table.insert(out.primitives, prim) + end + table.insert(scene.meshes, out) + return #scene.meshes, nil +end + +-- ------------------------------------------------------------------------------------------------ objects +local LIGHTS: { [string]: "directional" | "point" | "spot" } = { Omni = "point", Target = "spot", Free = "spot", Directional = "directional", TargetDirectional = "directional" } + +local function camera(scene: Types.Scene, obj: Item): number + local st = first(obj.kids, "CAMERA_SETTINGS") + local fov = get(st and st.kids, "CAMERA_FOV") or math.rad(45) + local cam: Types.Camera = { + name = str(obj.kids, "NODE_NAME"), + type = "perspective", + yfov = fov, -- 3ds Max stores the horizontal field of view (radians), kept as it is + znear = get(st and st.kids, "CAMERA_NEAR") or 0, + zfar = get(st and st.kids, "CAMERA_FAR"), + } + table.insert(scene.cameras, cam) + return #scene.cameras +end + +local function light(scene: Types.Scene, obj: Item): number + local st = first(obj.kids, "LIGHT_SETTINGS") + local sk = st and st.kids + local typ = LIGHTS[str(obj.kids, "LIGHT_TYPE") or "Omni"] or "point" + local l: Types.Light = { + name = str(obj.kids, "NODE_NAME"), + type = typ, + color = triple(sk, "LIGHT_COLOR") or { 1, 1, 1 }, + intensity = get(sk, "LIGHT_INTENS") or 1, + } + if typ == "spot" then + l.innerCone = math.rad((get(sk, "LIGHT_HOTSPOT") or 43) / 2) + l.outerCone = math.rad((get(sk, "LIGHT_FALLOFF") or 45) / 2) + end + table.insert(scene.lights, l) + return #scene.lights +end + +local KINDS = { GEOMOBJECT = true, HELPEROBJECT = true, CAMERAOBJECT = true, LIGHTOBJECT = true, SHAPEOBJECT = true } + +local function collect(kids: { Item }, into: { Item }, depth: number) + for _, it in kids do + if KINDS[it.key] then + table.insert(into, it) + elseif it.key == "GROUP" and it.kids and depth < 32 then + collect(it.kids, into, depth + 1) + end + end +end + +function Build.scene(root: { Item }, opts: any): (Types.Scene?, string?) + local o = opts or {} + local scene = S.new() + local version = get(root, "3DSMAX_ASCIIEXPORT") + local sk = (first(root, "SCENE") or { kids = nil } :: any).kids + scene.meta.up = "z" + scene.meta.source = { + format = "ase", + version = version, + comment = str(root, "COMMENT"), + firstFrame = get(sk, "SCENE_FIRSTFRAME"), + lastFrame = get(sk, "SCENE_LASTFRAME"), + frameSpeed = get(sk, "SCENE_FRAMESPEED"), + ticksPerFrame = get(sk, "SCENE_TICKSPERFRAME"), + background = triple(sk, "SCENE_BACKGROUND_STATIC"), + ambient = triple(sk, "SCENE_AMBIENT_STATIC"), + } + local matMap = materials(scene, first(root, "MATERIAL_LIST"), o) + local objs: { Item } = {} + collect(root, objs, 0) + local byName: { [string]: number } = {} + local worlds: { { number } } = {} + local parents: { string? } = {} + local animated = false + for i, obj in objs do + local name = str(obj.kids, "NODE_NAME") + local world = nodeTm(obj.kids) + local node: Types.Node = { name = name, children = {} } + local extras: { [string]: any } = { class = string.lower((string.gsub(obj.key, "OBJECT$", ""))) } + if obj.key == "GEOMOBJECT" then + local mi, merr = mesh(scene, obj, matMap, world, o) + if merr then + return nil, merr + end + node.mesh = mi + elseif obj.key == "CAMERAOBJECT" then + node.camera = camera(scene, obj) + elseif obj.key == "LIGHTOBJECT" then + node.light = light(scene, obj) + elseif obj.key == "HELPEROBJECT" then + extras.helperClass = str(obj.kids, "HELPER_CLASS") + end + if first(obj.kids, "TM_ANIMATION") then + animated = true + end + node.extras = { ase = extras } + scene.nodes[i] = node + worlds[i] = world + parents[i] = str(obj.kids, "NODE_PARENT") + if name and byName[name] == nil then + byName[name] = i + end + end + for i, node in scene.nodes do + local pname = parents[i] + local p = if pname then byName[pname] else nil + if p and p ~= i then + -- a parent cycle (or a parent listed later naming this node) falls back to a root + local q, steps = p, 0 + while q and q ~= i and steps < #objs do + local pn = parents[q] + q = if pn then byName[pn] else nil + steps += 1 + end + if q == i then + p = nil + end + else + p = nil + end + local inv = if p then Mat4.inverse(worlds[p :: number]) else nil + node.matrix = if inv then S.mul(inv, worlds[i]) else worlds[i] + if p then + table.insert(scene.nodes[p :: number].children, i) + else + table.insert(scene.roots, i) + end + end + if animated then + (scene.meta.source :: any).animated = true + end + return scene, nil +end + +return Build +end +__FILES["model/ase/Parse"] = function() + +-- model/ase/Parse: ASE text into a tree of items (*KEY args { children }). Quoted strings carry no escapes (3ds Max +-- ASCII export). Several items may share a line (*MESH_FACE ... *MESH_SMOOTHING 1 *MESH_MTLID 0). +local Parse = {} + +type Item = { key: string, args: { string }, kids: { Item }?, at: number } + +function Parse.tree(text: string, maxItems: number): ({ Item }?, string?) + local root: { Item } = {} + local stack: { { Item } } = { root } + local cur: Item? = nil + local p, n = 1, #text + local count = 0 + local find, sub, byte = string.find, string.sub, string.byte + while p <= n do + local s = find(text, "[^ \t\r\n]", p) + if not s then + break + end + local c = byte(text, s) + if c == 34 then -- '"' + local e = find(text, "\"", s + 1, true) + local stop = e or (n + 1) + if cur then + table.insert(cur.args, sub(text, s + 1, stop - 1)) + end + p = stop + 1 + elseif c == 123 then -- '{' + if not cur then + return nil, "'{' without an item at byte " .. s - 1 + end + if #stack > 64 then + return nil, "limit: nesting too deep" + end + local kids: { Item } = {} + cur.kids = kids + table.insert(stack, kids) + cur = nil + p = s + 1 + elseif c == 125 then -- '}' + if #stack == 1 then + return nil, "unbalanced '}' at byte " .. s - 1 + end + table.remove(stack) + cur = nil + p = s + 1 + else + local e = find(text, "[ \t\r\n{}\"]", s) or (n + 1) + local word = sub(text, s, e - 1) + if c == 42 then -- '*' + count += 1 + if count > maxItems then + return nil, "limit: over " .. maxItems .. " items" + end + local it: Item = { key = sub(word, 2), args = {}, kids = nil, at = s - 1 } + table.insert(stack[#stack], it) + cur = it + elseif cur then + table.insert(cur.args, word) + end + p = e + end + end + return root, nil +end + +return Parse +end +__FILES["model/ase/Write"] = function() + +-- model/ase/Write: a Scene as ASE text (3DSMAX_ASCIIEXPORT 200). Vertices are written in world space with each node's +-- world NODE_TM; every scene material is a sub-material of one Multi/Sub-Object material (faces pick it by +-- *MESH_MTLID). Triangles, strips, fans and polygons (fanned) are written; points and lines are skipped. +local Types = __include("Types") +local Mat4 = __include("codecs/model/Mat4") + +local Write = {} + +local S = Types.Scene + +local function f(v: number): string + if v ~= v or v == math.huge or v == -math.huge then + return "0.0000" + end + if v == math.floor(v) and math.abs(v) < 1e15 then + return string.format("%.4f", v) + end + return string.format("%.9g", v) +end + +local function q(s: string): string + return "\"" .. string.gsub(s, "\"", "'") .. "\"" +end + +type Out = { lines: { string } } + +local function put(out: Out, depth: number, s: string) + table.insert(out.lines, string.rep("\t", depth) .. s) +end + +local function tri(prim: any): { number }? + local pos = prim.attributes and prim.attributes.POSITION + if type(pos) ~= "table" then + return nil + end + local n = pos.count + local idx: { number } = {} + if prim.indices then + local rd = S.reader(prim.indices) + if not rd then + return nil + end + for i = 0, prim.indices.count - 1 do + idx[i + 1] = rd(i, 0) + end + else + for i = 0, n - 1 do + idx[i + 1] = i + end + end + local mode = prim.mode or "triangles" + local out: { number } = {} + if mode == "triangles" then + for i = 1, #idx - 2, 3 do + table.insert(out, idx[i]) + table.insert(out, idx[i + 1]) + table.insert(out, idx[i + 2]) + end + elseif mode == "triangle_strip" then + for i = 1, #idx - 2 do + if i % 2 == 1 then + table.insert(out, idx[i]) + table.insert(out, idx[i + 1]) + else + table.insert(out, idx[i + 1]) + table.insert(out, idx[i]) + end + table.insert(out, idx[i + 2]) + end + elseif mode == "triangle_fan" then + for i = 2, #idx - 1 do + table.insert(out, idx[1]) + table.insert(out, idx[i]) + table.insert(out, idx[i + 1]) + end + elseif mode == "polygons" and prim.faces then + local rd = S.reader(prim.faces) + local at = 1 + if rd then + for fi = 0, prim.faces.count - 1 do + local size = rd(fi, 0) + for k = 1, size - 2 do + table.insert(out, idx[at]) + table.insert(out, idx[at + k]) + table.insert(out, idx[at + k + 1]) + end + at += size + end + end + else + return nil + end + for _, v in out do + if v < 0 or v >= n then + return nil + end + end + return out +end + +local function material(out: Out, d: number, key: string, index: number, m: any) + put(out, d, "*" .. key .. " " .. index .. " {") + local c = if type(m.baseColor) == "table" then m.baseColor else { 1, 1, 1, 1 } + local x = if type(m.extras) == "table" then m.extras else {} + local amb = if type(x.ambient) == "table" then x.ambient else { c[1] or 1, c[2] or 1, c[3] or 1 } + local spec = if type(x.specular) == "table" then x.specular else { 0.9, 0.9, 0.9 } + put(out, d + 1, "*MATERIAL_NAME " .. q(if type(m.name) == "string" then m.name else "Material #" .. index)) + put(out, d + 1, "*MATERIAL_CLASS \"Standard\"") + put(out, d + 1, "*MATERIAL_AMBIENT " .. f(amb[1] or 0) .. "\t" .. f(amb[2] or 0) .. "\t" .. f(amb[3] or 0)) + put(out, d + 1, "*MATERIAL_DIFFUSE " .. f(c[1] or 1) .. "\t" .. f(c[2] or 1) .. "\t" .. f(c[3] or 1)) + put(out, d + 1, "*MATERIAL_SPECULAR " .. f(spec[1] or 0) .. "\t" .. f(spec[2] or 0) .. "\t" .. f(spec[3] or 0)) + put(out, d + 1, "*MATERIAL_SHINE " .. f(if type(x.shininess) == "number" then x.shininess else 1 - (m.roughness or 1))) + put(out, d + 1, "*MATERIAL_SHINESTRENGTH " .. f(if type(x.shineStrength) == "number" then x.shineStrength else 0)) + put(out, d + 1, "*MATERIAL_TRANSPARENCY " .. f(1 - (c[4] or 1))) + put(out, d + 1, "*MATERIAL_WIRESIZE 1.0000") + if m.doubleSided then + put(out, d + 1, "*MATERIAL_TWOSIDED") + end + put(out, d + 1, "*MATERIAL_SHADING Blinn") + put(out, d + 1, "*MATERIAL_SELFILLUM " .. f(if type(x.selfIllum) == "number" then x.selfIllum else 0)) + local ref = m.baseColorTexture + local tex = if type(ref) == "table" and type(m._textures) == "table" then m._textures[ref.texture] else nil + if tex and type(tex.uri) == "string" then + local tr = if type(ref.transform) == "table" then ref.transform else {} + local off = if type(tr.offset) == "table" then tr.offset else { 0, 0 } + local sc = if type(tr.scale) == "table" then tr.scale else { 1, 1 } + put(out, d + 1, "*MAP_DIFFUSE {") + put(out, d + 2, "*MAP_NAME " .. q(tex.name or tex.uri)) + put(out, d + 2, "*MAP_CLASS \"Bitmap\"") + put(out, d + 2, "*MAP_SUBNO 1") + put(out, d + 2, "*MAP_AMOUNT 1.0000") + put(out, d + 2, "*BITMAP " .. q(tex.uri)) + put(out, d + 2, "*MAP_TYPE Screen") + put(out, d + 2, "*UVW_U_OFFSET " .. f(off[1] or 0)) + put(out, d + 2, "*UVW_V_OFFSET " .. f(off[2] or 0)) + put(out, d + 2, "*UVW_U_TILING " .. f(sc[1] or 1)) + put(out, d + 2, "*UVW_V_TILING " .. f(sc[2] or 1)) + put(out, d + 2, "*UVW_ANGLE " .. f(tr.rotation or 0)) + put(out, d + 1, "}") + end + put(out, d, "}") +end + +local function nodeTm(out: Out, name: string, m: { number }) + put(out, 1, "*NODE_TM {") + put(out, 2, "*NODE_NAME " .. q(name)) + put(out, 2, "*INHERIT_POS 0 0 0") + put(out, 2, "*INHERIT_ROT 0 0 0") + put(out, 2, "*INHERIT_SCL 0 0 0") + for r = 0, 3 do + put(out, 2, "*TM_ROW" .. r .. " " .. f(m[r * 4 + 1]) .. "\t" .. f(m[r * 4 + 2]) .. "\t" .. f(m[r * 4 + 3])) + end + local t, r, s = Mat4.decompose(m) + local w = math.clamp(r[4], -1, 1) + local angle = 2 * math.acos(w) + local sn = math.sqrt(math.max(0, 1 - w * w)) + local ax = if sn > 1e-9 then { r[1] / sn, r[2] / sn, r[3] / sn } else { 0, 0, 0 } + put(out, 2, "*TM_POS " .. f(t[1]) .. "\t" .. f(t[2]) .. "\t" .. f(t[3])) + put(out, 2, "*TM_ROTAXIS " .. f(ax[1]) .. "\t" .. f(ax[2]) .. "\t" .. f(ax[3])) + put(out, 2, "*TM_ROTANGLE " .. f(angle)) + put(out, 2, "*TM_SCALE " .. f(s[1]) .. "\t" .. f(s[2]) .. "\t" .. f(s[3])) + put(out, 2, "*TM_SCALEAXIS 0.0000\t0.0000\t0.0000") + put(out, 2, "*TM_SCALEAXISANG 0.0000") + put(out, 1, "}") +end + +local function vec(rd: ((number, number) -> number)?, i: number, n: number, default: number): { number } + local v = {} + for c = 0, n - 1 do + v[c + 1] = if rd then rd(i, c) else default + end + return v +end + +local function geom(out: Out, scene: any, mesh: any, world: { number }, matBase: { [number]: number }, hasMulti: boolean): boolean + local P: { number } = {} + local N: { number } = {} + local T: { [number]: { number } } = {} + local C: { number } = {} + local F: { number } = {} + local M: { number } = {} + local hasN, hasC = false, false + local uvSets: { [number]: boolean } = {} + for _, prim in mesh.primitives or {} do + for name in prim.attributes or {} do + local k = string.match(name, "^TEXCOORD_(%d)$") + if k then + uvSets[tonumber(k) :: number] = true + end + end + end + local nm = Mat4.normalMatrix(world) + for _, prim in mesh.primitives or {} do + local idx = tri(prim) + if idx then + local a = prim.attributes + local base = #P // 3 + local rp = S.reader(a.POSITION) + local rn = if a.NORMAL then S.reader(a.NORMAL) else nil + local rc = if a.COLOR_0 then S.reader(a.COLOR_0) else nil + local cc = if a.COLOR_0 then a.COLOR_0.components else 0 + if rp then + for i = 0, a.POSITION.count - 1 do + local x, y, z = Mat4.point(world, rp(i, 0), rp(i, 1), rp(i, 2)) + table.insert(P, x) + table.insert(P, y) + table.insert(P, z) + local nv = vec(rn, i, 3, 0) + local tx = nm[1] * nv[1] + nm[5] * nv[2] + nm[9] * nv[3] + local ty = nm[2] * nv[1] + nm[6] * nv[2] + nm[10] * nv[3] + local tz = nm[3] * nv[1] + nm[7] * nv[2] + nm[11] * nv[3] + local len = math.sqrt(tx * tx + ty * ty + tz * tz) + if len > 0 then + tx, ty, tz = tx / len, ty / len, tz / len + end + table.insert(N, tx) + table.insert(N, ty) + table.insert(N, tz) + for k in uvSets do + local acc = a["TEXCOORD_" .. k] + local rt = if acc then S.reader(acc) else nil + local list = T[k] or {} + T[k] = list + table.insert(list, if rt then rt(i, 0) else 0) + table.insert(list, if rt then 1 - rt(i, 1) else 0) + end + local col = vec(rc, i, math.max(cc, 3), 1) + table.insert(C, col[1]) + table.insert(C, col[2]) + table.insert(C, col[3]) + end + hasN = hasN or rn ~= nil + hasC = hasC or rc ~= nil + local mid = if prim.material and matBase[prim.material] then matBase[prim.material] else (if hasMulti then #scene.materials else 0) + for i = 1, #idx, 3 do + table.insert(F, base + idx[i]) + table.insert(F, base + idx[i + 1]) + table.insert(F, base + idx[i + 2]) + table.insert(M, mid) + end + end + end + end + if #F == 0 then + return false + end + local nv, nf = #P // 3, #F // 3 + put(out, 1, "*MESH {") + put(out, 2, "*TIMEVALUE 0") + put(out, 2, "*MESH_NUMVERTEX " .. nv) + put(out, 2, "*MESH_NUMFACES " .. nf) + put(out, 2, "*MESH_VERTEX_LIST {") + for i = 0, nv - 1 do + put(out, 3, "*MESH_VERTEX " .. i .. "\t" .. f(P[i * 3 + 1]) .. "\t" .. f(P[i * 3 + 2]) .. "\t" .. f(P[i * 3 + 3])) + end + put(out, 2, "}") + put(out, 2, "*MESH_FACE_LIST {") + for i = 0, nf - 1 do + put(out, 3, string.format("*MESH_FACE %d: A: %d B: %d C: %d AB: 1 BC: 1 CA: 1\t*MESH_SMOOTHING 1\t*MESH_MTLID %d", i, F[i * 3 + 1], F[i * 3 + 2], F[i * 3 + 3], M[i + 1])) + end + put(out, 2, "}") + local function uvBlock(d: number, list: { number }) + put(out, d, "*MESH_NUMTVERTEX " .. nv) + put(out, d, "*MESH_TVERTLIST {") + for i = 0, nv - 1 do + put(out, d + 1, "*MESH_TVERT " .. i .. "\t" .. f(list[i * 2 + 1] or 0) .. "\t" .. f(list[i * 2 + 2] or 0) .. "\t0.0000") + end + put(out, d, "}") + put(out, d, "*MESH_NUMTVFACES " .. nf) + put(out, d, "*MESH_TFACELIST {") + for i = 0, nf - 1 do + put(out, d + 1, "*MESH_TFACE " .. i .. "\t" .. F[i * 3 + 1] .. "\t" .. F[i * 3 + 2] .. "\t" .. F[i * 3 + 3]) + end + put(out, d, "}") + end + if T[0] then + uvBlock(2, T[0]) + end + for k = 1, 7 do + if T[k] then + put(out, 2, "*MESH_MAPPINGCHANNEL " .. (k + 1) .. " {") + uvBlock(3, T[k]) + put(out, 2, "}") + end + end + if hasC then + put(out, 2, "*MESH_NUMCVERTEX " .. nv) + put(out, 2, "*MESH_CVERTLIST {") + for i = 0, nv - 1 do + put(out, 3, "*MESH_VERTCOL " .. i .. "\t" .. f(C[i * 3 + 1]) .. "\t" .. f(C[i * 3 + 2]) .. "\t" .. f(C[i * 3 + 3])) + end + put(out, 2, "}") + put(out, 2, "*MESH_NUMCVFACES " .. nf) + put(out, 2, "*MESH_CFACELIST {") + for i = 0, nf - 1 do + put(out, 3, "*MESH_CFACE " .. i .. "\t" .. F[i * 3 + 1] .. "\t" .. F[i * 3 + 2] .. "\t" .. F[i * 3 + 3]) + end + put(out, 2, "}") + end + if hasN then + put(out, 2, "*MESH_NORMALS {") + for i = 0, nf - 1 do + local a, b, c = F[i * 3 + 1], F[i * 3 + 2], F[i * 3 + 3] + local ux, uy, uz = P[b * 3 + 1] - P[a * 3 + 1], P[b * 3 + 2] - P[a * 3 + 2], P[b * 3 + 3] - P[a * 3 + 3] + local vx, vy, vz = P[c * 3 + 1] - P[a * 3 + 1], P[c * 3 + 2] - P[a * 3 + 2], P[c * 3 + 3] - P[a * 3 + 3] + local nx, ny, nz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + local len = math.sqrt(nx * nx + ny * ny + nz * nz) + if len > 0 then + nx, ny, nz = nx / len, ny / len, nz / len + end + put(out, 3, "*MESH_FACENORMAL " .. i .. "\t" .. f(nx) .. "\t" .. f(ny) .. "\t" .. f(nz)) + for _, v in { a, b, c } do + put(out, 4, "*MESH_VERTEXNORMAL " .. v .. "\t" .. f(N[v * 3 + 1]) .. "\t" .. f(N[v * 3 + 2]) .. "\t" .. f(N[v * 3 + 3])) + end + end + put(out, 2, "}") + end + put(out, 1, "}") + return true +end + +function Write.scene(scene: any, opts: any): (string?, string?) + local out: Out = { lines = {} } + local src = if type(scene.meta) == "table" and type(scene.meta.source) == "table" then scene.meta.source else {} + put(out, 0, "*3DSMAX_ASCIIEXPORT\t200") + put(out, 0, "*COMMENT " .. q(if opts and type(opts.comment) == "string" then opts.comment else "AsciiExport-Version 2,00 - rosetta")) + put(out, 0, "*SCENE {") + put(out, 1, "*SCENE_FILENAME \"\"") + put(out, 1, "*SCENE_FIRSTFRAME " .. math.floor(tonumber(src.firstFrame) or 0)) + put(out, 1, "*SCENE_LASTFRAME " .. math.floor(tonumber(src.lastFrame) or 100)) + put(out, 1, "*SCENE_FRAMESPEED " .. math.floor(tonumber(src.frameSpeed) or 30)) + put(out, 1, "*SCENE_TICKSPERFRAME " .. math.floor(tonumber(src.ticksPerFrame) or 160)) + put(out, 1, "*SCENE_BACKGROUND_STATIC 0.0000\t0.0000\t0.0000") + put(out, 1, "*SCENE_AMBIENT_STATIC 0.0000\t0.0000\t0.0000") + put(out, 0, "}") + local mats = scene.materials or {} + local nmat = #mats + local matBase: { [number]: number } = {} + -- a default sub-material for primitives without one, when other primitives have one + local needDefault = false + for _, mesh in scene.meshes or {} do + for _, prim in mesh.primitives or {} do + if not (prim.material and mats[prim.material]) then + needDefault = true + end + end + end + put(out, 0, "*MATERIAL_LIST {") + if nmat > 0 then + put(out, 1, "*MATERIAL_COUNT 1") + put(out, 1, "*MATERIAL 0 {") + put(out, 2, "*MATERIAL_NAME \"Multimaterial\"") + put(out, 2, "*MATERIAL_CLASS \"Multi/Sub-Object\"") + put(out, 2, "*NUMSUBMTLS " .. (nmat + (if needDefault then 1 else 0))) + for i, m in mats do + matBase[i] = i - 1 + local mm = table.clone(m) + mm._textures = scene.textures + material(out, 2, "SUBMATERIAL", i - 1, mm) + end + if needDefault then + material(out, 2, "SUBMATERIAL", nmat, S.material("Default")) + end + put(out, 1, "}") + else + put(out, 1, "*MATERIAL_COUNT 0") + end + put(out, 0, "}") + -- world matrices and unique names + local nodes = scene.nodes or {} + local worlds: { [number]: { number } } = {} + local parentOf: { [number]: number } = {} + local order: { number } = {} + local function walk(i: number, parent: { number }, depth: number) + local node = nodes[i] + if not node or worlds[i] or depth > 256 then + return + end + worlds[i] = S.mul(parent, S.nodeMatrix(node)) + table.insert(order, i) + for _, c in node.children or {} do + if nodes[c] and not worlds[c] then + parentOf[c] = i + walk(c, worlds[i], depth + 1) + end + end + end + local roots = scene.roots or {} + if #roots == 0 then + for i in nodes do + table.insert(roots, i) + end + end + for _, r in roots do + walk(r, S.IDENTITY, 0) + end + local names: { [number]: string } = {} + local used: { [string]: boolean } = {} + for _, i in order do + local base = if type(nodes[i].name) == "string" and nodes[i].name ~= "" then nodes[i].name else "Object" .. i + local name, k = base, 1 + while used[name] do + k += 1 + name = base .. "_" .. k + end + used[name] = true + names[i] = name + end + for _, i in order do + local node = nodes[i] + local w = worlds[i] + local mesh = if node.mesh then (scene.meshes or {})[node.mesh] else nil + local cam = if node.camera then (scene.cameras or {})[node.camera] else nil + local li = if node.light then (scene.lights or {})[node.light] else nil + local key = if mesh then "GEOMOBJECT" elseif cam then "CAMERAOBJECT" elseif li then "LIGHTOBJECT" else "HELPEROBJECT" + put(out, 0, "*" .. key .. " {") + put(out, 1, "*NODE_NAME " .. q(names[i])) + if parentOf[i] then + put(out, 1, "*NODE_PARENT " .. q(names[parentOf[i]])) + end + if key == "HELPEROBJECT" then + put(out, 1, "*HELPER_CLASS \"Dummy\"") + elseif key == "CAMERAOBJECT" then + put(out, 1, "*CAMERA_TYPE Free") + elseif key == "LIGHTOBJECT" then + put(out, 1, "*LIGHT_TYPE " .. (if li.type == "spot" then "Free" elseif li.type == "directional" then "Directional" else "Omni")) + end + nodeTm(out, names[i], w) + if mesh then + geom(out, scene, mesh, w, matBase, nmat > 0) + put(out, 1, "*PROP_MOTIONBLUR 0") + put(out, 1, "*PROP_CASTSHADOW 1") + put(out, 1, "*PROP_RECVSHADOW 1") + if nmat > 0 then + put(out, 1, "*MATERIAL_REF 0") + end + elseif cam then + put(out, 1, "*CAMERA_SETTINGS {") + put(out, 2, "*TIMEVALUE 0") + put(out, 2, "*CAMERA_NEAR " .. f(cam.znear or 0)) + put(out, 2, "*CAMERA_FAR " .. f(cam.zfar or 1000)) + put(out, 2, "*CAMERA_FOV " .. f(cam.yfov or math.rad(45))) + put(out, 2, "*CAMERA_TDIST 100.0000") + put(out, 1, "}") + elseif li then + local c = if type(li.color) == "table" then li.color else { 1, 1, 1 } + put(out, 1, "*LIGHT_SETTINGS {") + put(out, 2, "*TIMEVALUE 0") + put(out, 2, "*LIGHT_COLOR " .. f(c[1] or 1) .. "\t" .. f(c[2] or 1) .. "\t" .. f(c[3] or 1)) + put(out, 2, "*LIGHT_INTENS " .. f(li.intensity or 1)) + put(out, 2, "*LIGHT_HOTSPOT " .. f(math.deg(li.innerCone or 0) * 2)) + put(out, 2, "*LIGHT_FALLOFF " .. f(math.deg(li.outerCone or math.pi / 4) * 2)) + put(out, 1, "}") + end + put(out, 0, "}") + end + return table.concat(out.lines, "\n") .. "\n", nil +end + return Write end __FILES["model/b3d"] = function() diff --git a/build/Rosetta.luau.linemap.json b/build/Rosetta.luau.linemap.json index f0d926f..cdbb126 100644 --- a/build/Rosetta.luau.linemap.json +++ b/build/Rosetta.luau.linemap.json @@ -1,539 +1,544 @@ [ [27, "src/Rosetta/init.luau"], [871, "src/Rosetta/Registry.luau"], -[2980, "src/Rosetta/Types.luau"], -[4063, "src/Rosetta/archive/7z/init.luau"], -[4448, "src/Rosetta/archive/7z/Header.luau"], -[4975, "src/Rosetta/archive/adf/init.luau"], -[5257, "src/Rosetta/archive/applesingle/init.luau"], -[5443, "src/Rosetta/archive/ar/init.luau"], -[5846, "src/Rosetta/archive/arj/init.luau"], -[6056, "src/Rosetta/archive/binhex/init.luau"], -[6305, "src/Rosetta/archive/br/init.luau"], -[6380, "src/Rosetta/archive/bz2/init.luau"], -[6444, "src/Rosetta/archive/cab/init.luau"], -[6857, "src/Rosetta/archive/cab/Sum.luau"], -[6898, "src/Rosetta/archive/cpio/init.luau"], -[7066, "src/Rosetta/archive/d64/init.luau"], -[7480, "src/Rosetta/archive/fat/init.luau"], -[7602, "src/Rosetta/archive/grp/init.luau"], -[7716, "src/Rosetta/archive/gzip/init.luau"], -[7901, "src/Rosetta/archive/iso/init.luau"], -[7973, "src/Rosetta/archive/lha/init.luau"], -[8398, "src/Rosetta/archive/lz4/init.luau"], -[8742, "src/Rosetta/archive/macbinary/init.luau"], -[8940, "src/Rosetta/archive/mpq/init.luau"], -[9346, "src/Rosetta/archive/mpq/Crypt.luau"], -[9411, "src/Rosetta/archive/pak/init.luau"], -[9545, "src/Rosetta/archive/rpm/init.luau"], -[9869, "src/Rosetta/archive/tar/init.luau"], -[9987, "src/Rosetta/archive/uu/init.luau"], -[10257, "src/Rosetta/archive/vpk/init.luau"], -[10568, "src/Rosetta/archive/wad/init.luau"], -[11018, "src/Rosetta/archive/wad/Map.luau"], -[11448, "src/Rosetta/archive/wad/Picture.luau"], -[11550, "src/Rosetta/archive/xz/init.luau"], -[11650, "src/Rosetta/archive/yenc/init.luau"], -[11922, "src/Rosetta/archive/z/init.luau"], -[12018, "src/Rosetta/archive/zip/init.luau"], -[12237, "src/Rosetta/archive/zoo/init.luau"], -[12433, "src/Rosetta/archive/zst/init.luau"], -[12497, "src/Rosetta/audio/aac/init.luau"], -[12703, "src/Rosetta/audio/ac3/init.luau"], -[12849, "src/Rosetta/audio/adpcm/init.luau"], -[12994, "src/Rosetta/audio/adx/init.luau"], -[13225, "src/Rosetta/audio/aiff/init.luau"], -[13616, "src/Rosetta/audio/ape/init.luau"], -[13744, "src/Rosetta/audio/au/init.luau"], -[13905, "src/Rosetta/audio/brstm/init.luau"], -[14196, "src/Rosetta/audio/caf/init.luau"], -[14858, "src/Rosetta/audio/flac/init.luau"], -[15006, "src/Rosetta/audio/flac/Meta.luau"], -[15228, "src/Rosetta/audio/flac/Stream.luau"], -[15598, "src/Rosetta/audio/m4a/init.luau"], -[15932, "src/Rosetta/audio/mp3/init.luau"], -[16192, "src/Rosetta/audio/mp3/Index.luau"], -[16383, "src/Rosetta/audio/mp3/Stream.luau"], -[16610, "src/Rosetta/audio/mp3/Tags.luau"], -[16922, "src/Rosetta/audio/mpc/init.luau"], -[17016, "src/Rosetta/audio/opus/init.luau"], -[17394, "src/Rosetta/audio/opus/Encode.luau"], -[17505, "src/Rosetta/audio/qoa/init.luau"], -[17685, "src/Rosetta/audio/tta/init.luau"], -[17803, "src/Rosetta/audio/vag/init.luau"], -[18026, "src/Rosetta/audio/voc/init.luau"], -[18301, "src/Rosetta/audio/vorbis/init.luau"], -[18755, "src/Rosetta/audio/vorbis/Encode.luau"], -[19568, "src/Rosetta/audio/wav/init.luau"], -[20189, "src/Rosetta/audio/wav/Codecs.luau"], -[20355, "src/Rosetta/audio/wavpack/init.luau"], -[20562, "src/Rosetta/cad/step/init.luau"], -[20944, "src/Rosetta/cad/step/Brep.luau"], -[21179, "src/Rosetta/cad/step/Parse.luau"], -[21736, "src/Rosetta/cad/step/Write.luau"], -[21984, "src/Rosetta/codecs/audio/Aac/init.luau"], -[22303, "src/Rosetta/codecs/audio/Aac/Decode.luau"], -[23186, "src/Rosetta/codecs/audio/Aac/Tables.luau"], -[23521, "src/Rosetta/codecs/audio/Ac3/init.luau"], -[23680, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], -[24565, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], -[24666, "src/Rosetta/codecs/audio/Adpcm/init.luau"], -[25420, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], -[25722, "src/Rosetta/codecs/audio/Alac/init.luau"], -[25956, "src/Rosetta/codecs/audio/Alac/Decode.luau"], -[26375, "src/Rosetta/codecs/audio/Alac/Encode.luau"], -[26787, "src/Rosetta/codecs/audio/Ape/init.luau"], -[27002, "src/Rosetta/codecs/audio/Ape/Decode.luau"], -[27763, "src/Rosetta/codecs/audio/ApeTag.luau"], -[27860, "src/Rosetta/codecs/audio/Flac/init.luau"], -[27871, "src/Rosetta/codecs/audio/Flac/Encode.luau"], -[28820, "src/Rosetta/codecs/audio/Flac/Frame.luau"], -[29417, "src/Rosetta/codecs/audio/Hively/init.luau"], -[29613, "src/Rosetta/codecs/audio/Hively/Load.luau"], -[29862, "src/Rosetta/codecs/audio/Hively/Player.luau"], -[30820, "src/Rosetta/codecs/audio/Hively/Tables.luau"], -[31039, "src/Rosetta/codecs/audio/Mdct/init.luau"], -[31223, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], -[31432, "src/Rosetta/codecs/audio/MidiRender.luau"], -[31778, "src/Rosetta/codecs/audio/Mpa/init.luau"], -[31792, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], -[31851, "src/Rosetta/codecs/audio/Mpa/Core.luau"], -[33454, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], -[33746, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], -[34131, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], -[34772, "src/Rosetta/codecs/audio/Mpa/Header.luau"], -[34913, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], -[35139, "src/Rosetta/codecs/audio/Musepack/init.luau"], -[35484, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], -[36365, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], -[36743, "src/Rosetta/codecs/audio/Opus/init.luau"], -[36757, "src/Rosetta/codecs/audio/Opus/Celt.luau"], -[38604, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], -[39669, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], -[39729, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], -[40189, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], -[40526, "src/Rosetta/codecs/audio/Opus/Packet.luau"], -[40759, "src/Rosetta/codecs/audio/Opus/Silk.luau"], -[42795, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], -[43169, "src/Rosetta/codecs/audio/Pcm/init.luau"], -[43432, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], -[43729, "src/Rosetta/codecs/audio/Qoa/init.luau"], -[44011, "src/Rosetta/codecs/audio/Resample/init.luau"], -[44370, "src/Rosetta/codecs/audio/SoundFont/init.luau"], -[44424, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], -[44567, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], -[45080, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], -[45861, "src/Rosetta/codecs/audio/Stream.luau"], -[46022, "src/Rosetta/codecs/audio/Tracker/init.luau"], -[46504, "src/Rosetta/codecs/audio/Tracker/Load.luau"], -[46782, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], -[46951, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], -[47079, "src/Rosetta/codecs/audio/Tracker/Player.luau"], -[49067, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], -[49183, "src/Rosetta/codecs/audio/Tta/init.luau"], -[49300, "src/Rosetta/codecs/audio/Tta/Decode.luau"], -[49552, "src/Rosetta/codecs/audio/Vorbis/init.luau"], -[49565, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], -[49949, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], -[50515, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], -[50936, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], -[50975, "src/Rosetta/codecs/audio/VorbisComment.luau"], -[51027, "src/Rosetta/codecs/audio/WavPack/init.luau"], -[51249, "src/Rosetta/codecs/audio/WavPack/Block.luau"], -[52704, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], -[52767, "src/Rosetta/codecs/compress/Brotli/init.luau"], -[52854, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], -[53823, "src/Rosetta/codecs/compress/Brotli/Static.luau"], -[54691, "src/Rosetta/codecs/compress/Bzip2/init.luau"], -[54739, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], -[55255, "src/Rosetta/codecs/compress/Deflate/init.luau"], -[55581, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], -[56001, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], -[56436, "src/Rosetta/codecs/compress/Explode.luau"], -[56632, "src/Rosetta/codecs/compress/Lz4.luau"], -[56901, "src/Rosetta/codecs/compress/Lzh/init.luau"], -[57505, "src/Rosetta/codecs/compress/Lzma/init.luau"], -[58045, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], -[58083, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], -[58556, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], -[58732, "src/Rosetta/codecs/compress/Lzw/init.luau"], -[59000, "src/Rosetta/codecs/compress/Lzx.luau"], -[59434, "src/Rosetta/codecs/compress/PackBits.luau"], -[59524, "src/Rosetta/codecs/compress/Quantum.luau"], -[59761, "src/Rosetta/codecs/compress/UnixCompress.luau"], -[60065, "src/Rosetta/codecs/compress/Xxh32.luau"], -[60134, "src/Rosetta/codecs/compress/Zstd/init.luau"], -[60191, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], -[61149, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], -[61301, "src/Rosetta/codecs/entropy/Huffman.luau"], -[61583, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], -[61594, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], -[61808, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], -[62052, "src/Rosetta/codecs/font/Bitmap.luau"], -[62253, "src/Rosetta/codecs/font/Cff/init.luau"], -[62894, "src/Rosetta/codecs/font/GlyphNames.luau"], -[63044, "src/Rosetta/codecs/font/TrueType/init.luau"], -[63358, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], -[63750, "src/Rosetta/codecs/font/TrueType/Tables.luau"], -[64252, "src/Rosetta/codecs/image/Bcn/init.luau"], -[64359, "src/Rosetta/codecs/image/Bcn/Decode.luau"], -[64848, "src/Rosetta/codecs/image/Bcn/Encode.luau"], -[65277, "src/Rosetta/codecs/image/Blend.luau"], -[65656, "src/Rosetta/codecs/image/Dct/init.luau"], -[66037, "src/Rosetta/codecs/image/Etc.luau"], -[66335, "src/Rosetta/codecs/image/Half.luau"], -[66404, "src/Rosetta/codecs/image/Jpeg/init.luau"], -[66758, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], -[67166, "src/Rosetta/codecs/image/Jpeg/Color.luau"], -[67403, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], -[68163, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], -[69044, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], -[69490, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], -[69568, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], -[69635, "src/Rosetta/codecs/image/Pixels.luau"], -[69899, "src/Rosetta/codecs/image/Quantize/init.luau"], -[70358, "src/Rosetta/codecs/image/Raster.luau"], -[71055, "src/Rosetta/codecs/image/Texel.luau"], -[71428, "src/Rosetta/codecs/image/Texture.luau"], -[71573, "src/Rosetta/codecs/image/Vp8/init.luau"], -[71703, "src/Rosetta/codecs/image/Vp8/Decode.luau"], -[73659, "src/Rosetta/codecs/image/Vp8/Predict.luau"], -[73918, "src/Rosetta/codecs/image/Vp8/Tables.luau"], -[74167, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], -[74286, "src/Rosetta/codecs/image/Vp8L/init.luau"], -[74390, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], -[75243, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], -[76195, "src/Rosetta/codecs/image/Yuv.luau"], -[76463, "src/Rosetta/codecs/model/Draco/init.luau"], -[76795, "src/Rosetta/codecs/model/Draco/Attributes.luau"], -[77264, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], -[78453, "src/Rosetta/codecs/model/Draco/Int64.luau"], -[78602, "src/Rosetta/codecs/model/Draco/KdTree.luau"], -[78961, "src/Rosetta/codecs/model/Draco/Predict.luau"], -[79923, "src/Rosetta/codecs/model/Draco/Reader.luau"], -[80397, "src/Rosetta/codecs/model/Mat4.luau"], -[80656, "src/Rosetta/codecs/model/MeshFlatten.luau"], -[81184, "src/Rosetta/codecs/model/Minecraft/init.luau"], -[81736, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], -[81815, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], -[81922, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], -[82128, "src/Rosetta/codecs/model/Polygon.luau"], -[82362, "src/Rosetta/codecs/model/Rbx/init.luau"], -[82599, "src/Rosetta/codecs/model/Rbx/Binary.luau"], -[83353, "src/Rosetta/codecs/model/Rig.luau"], -[83596, "src/Rosetta/codecs/model/Sampler.luau"], -[83756, "src/Rosetta/codecs/model/Vrml/init.luau"], -[83904, "src/Rosetta/codecs/model/Vrml/Build.luau"], -[84478, "src/Rosetta/codecs/model/Vrml/Fields.luau"], -[84641, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], -[85390, "src/Rosetta/codecs/model/Vrml/Parse.luau"], -[85912, "src/Rosetta/codecs/model/Vrml/Write.luau"], -[86639, "src/Rosetta/codecs/model/Vrml/Xml.luau"], -[86871, "src/Rosetta/codecs/text/Json/init.luau"], -[87140, "src/Rosetta/codecs/text/Json/Decode.luau"], -[87554, "src/Rosetta/codecs/text/Json/Encode.luau"], -[87856, "src/Rosetta/codecs/text/Nbt/init.luau"], -[88209, "src/Rosetta/codecs/text/Nbt/Binary.luau"], -[88901, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], -[89541, "src/Rosetta/codecs/text/Nbt/Value.luau"], -[89779, "src/Rosetta/codecs/text/Text/init.luau"], -[89870, "src/Rosetta/codecs/text/Url/init.luau"], -[90075, "src/Rosetta/codecs/text/Xml/init.luau"], -[90478, "src/Rosetta/codecs/text/Xml/Parse.luau"], -[91218, "src/Rosetta/codecs/video/Dsp.luau"], -[91941, "src/Rosetta/codecs/video/H263/init.luau"], -[92097, "src/Rosetta/codecs/video/H263/Decoder.luau"], -[92955, "src/Rosetta/codecs/video/H263/Tables.luau"], -[93158, "src/Rosetta/codecs/video/H264/init.luau"], -[93531, "src/Rosetta/codecs/video/H264/Bitstream.luau"], -[93806, "src/Rosetta/codecs/video/H264/Cabac.luau"], -[94937, "src/Rosetta/codecs/video/H264/Cavlc.luau"], -[95705, "src/Rosetta/codecs/video/H264/Deblock.luau"], -[95963, "src/Rosetta/codecs/video/H264/Decoder.luau"], -[96972, "src/Rosetta/codecs/video/H264/Inter.luau"], -[97226, "src/Rosetta/codecs/video/H264/Intra.luau"], -[97633, "src/Rosetta/codecs/video/H264/Mb.luau"], -[98539, "src/Rosetta/codecs/video/H264/Params.luau"], -[98986, "src/Rosetta/codecs/video/H264/Slice.luau"], -[99237, "src/Rosetta/codecs/video/H264/Tables.luau"], -[99278, "src/Rosetta/codecs/video/H264/Transform.luau"], -[99443, "src/Rosetta/codecs/video/Legacy/init.luau"], -[99641, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], -[99938, "src/Rosetta/codecs/video/Legacy/Flic.luau"], -[100305, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], -[100423, "src/Rosetta/codecs/video/Legacy/Picture.luau"], -[100531, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], -[100804, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], -[101199, "src/Rosetta/codecs/video/Legacy/Smc.luau"], -[101376, "src/Rosetta/codecs/video/Mpeg1/init.luau"], -[101388, "src/Rosetta/codecs/video/Mpeg2/init.luau"], -[101755, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], -[103262, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], -[103401, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], -[103539, "src/Rosetta/codecs/video/Theora/init.luau"], -[103802, "src/Rosetta/codecs/video/Theora/Decoder.luau"], -[105066, "src/Rosetta/codecs/video/Theora/Header.luau"], -[105429, "src/Rosetta/codecs/video/Video/init.luau"], -[105986, "src/Rosetta/codecs/video/Video/Source.luau"], -[106271, "src/Rosetta/containers/Archive.luau"], -[106538, "src/Rosetta/containers/AudioWrap.luau"], -[107041, "src/Rosetta/containers/Avi/init.luau"], -[107593, "src/Rosetta/containers/Chunks.luau"], -[107728, "src/Rosetta/containers/Cpio.luau"], -[108156, "src/Rosetta/containers/Demux.luau"], -[108431, "src/Rosetta/containers/Ebml/init.luau"], -[108744, "src/Rosetta/containers/Fat.luau"], -[109432, "src/Rosetta/containers/Iso9660.luau"], -[109937, "src/Rosetta/containers/IsoBmff/init.luau"], -[110107, "src/Rosetta/containers/IsoBmff/Box.luau"], -[110295, "src/Rosetta/containers/IsoBmff/Demux.luau"], -[111140, "src/Rosetta/containers/IsoBmff/Meta.luau"], -[111661, "src/Rosetta/containers/IsoBmff/Mux.luau"], -[112177, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], -[112294, "src/Rosetta/containers/MacFile.luau"], -[112443, "src/Rosetta/containers/MpegEs.luau"], -[112609, "src/Rosetta/containers/MpegPs/init.luau"], -[112829, "src/Rosetta/containers/MpegTs/init.luau"], -[113621, "src/Rosetta/containers/Ogg/init.luau"], -[114046, "src/Rosetta/containers/Ogg/Mux.luau"], -[114241, "src/Rosetta/containers/Ogg/Page.luau"], -[114410, "src/Rosetta/containers/Riff/init.luau"], -[114727, "src/Rosetta/containers/Tar.luau"], -[115141, "src/Rosetta/containers/Zip/init.luau"], -[115773, "src/Rosetta/core/Adler32.luau"], -[115819, "src/Rosetta/core/Base64.luau"], -[115978, "src/Rosetta/core/Bits.luau"], -[116271, "src/Rosetta/core/Bytes.luau"], -[116798, "src/Rosetta/core/Crc16.luau"], -[116850, "src/Rosetta/core/Crc32.luau"], -[116962, "src/Rosetta/core/Err.luau"], -[117044, "src/Rosetta/core/Input.luau"], -[117120, "src/Rosetta/core/Md5.luau"], -[117279, "src/Rosetta/core/Sniff.luau"], -[117308, "src/Rosetta/data/cbor/init.luau"], -[117407, "src/Rosetta/data/cbor/Codec.luau"], -[117976, "src/Rosetta/data/csv/init.luau"], -[118288, "src/Rosetta/data/ini/init.luau"], -[118534, "src/Rosetta/data/json/init.luau"], -[118626, "src/Rosetta/data/msgpack/init.luau"], -[118715, "src/Rosetta/data/msgpack/Codec.luau"], -[119157, "src/Rosetta/data/nbt/init.luau"], -[119216, "src/Rosetta/data/plist/init.luau"], -[119522, "src/Rosetta/data/plist/Binary.luau"], -[119789, "src/Rosetta/data/snbt/init.luau"], -[119852, "src/Rosetta/data/toml/init.luau"], -[119919, "src/Rosetta/data/toml/Decode.luau"], -[120547, "src/Rosetta/data/toml/Encode.luau"], -[120756, "src/Rosetta/data/xml/init.luau"], -[120812, "src/Rosetta/data/yaml/init.luau"], -[120885, "src/Rosetta/data/yaml/Emit.luau"], -[121175, "src/Rosetta/data/yaml/Parse.luau"], -[122468, "src/Rosetta/font/bdf/init.luau"], -[122757, "src/Rosetta/font/bmfont/init.luau"], -[123184, "src/Rosetta/font/bmfont/Parse.luau"], -[123637, "src/Rosetta/font/eot/init.luau"], -[123869, "src/Rosetta/font/fon/init.luau"], -[124152, "src/Rosetta/font/hershey/init.luau"], -[124347, "src/Rosetta/font/pcf/init.luau"], -[124627, "src/Rosetta/font/psf/init.luau"], -[124947, "src/Rosetta/font/ttf/init.luau"], -[124998, "src/Rosetta/font/type1/init.luau"], -[125357, "src/Rosetta/font/type1/Charstring.luau"], -[125635, "src/Rosetta/font/woff/init.luau"], -[125767, "src/Rosetta/font/woff2/init.luau"], -[125824, "src/Rosetta/font/woff2/Rebuild.luau"], -[126364, "src/Rosetta/host/init.luau"], -[126409, "src/Rosetta/host/Love.luau"], -[126552, "src/Rosetta/host/LuaJIT.luau"], -[126602, "src/Rosetta/host/Luau.luau"], -[126625, "src/Rosetta/host/Roblox.luau"], -[126984, "src/Rosetta/image/ani/init.luau"], -[127164, "src/Rosetta/image/blp/init.luau"], -[127422, "src/Rosetta/image/bmp/init.luau"], -[127837, "src/Rosetta/image/dds/init.luau"], -[128320, "src/Rosetta/image/exr/init.luau"], -[129080, "src/Rosetta/image/exr/Codec.luau"], -[129191, "src/Rosetta/image/exr/Piz.luau"], -[129548, "src/Rosetta/image/gif/init.luau"], -[130064, "src/Rosetta/image/gif/Decode.luau"], -[130127, "src/Rosetta/image/hdr/init.luau"], -[130356, "src/Rosetta/image/hdr/Codec.luau"], -[130567, "src/Rosetta/image/icns/init.luau"], -[130898, "src/Rosetta/image/ico/init.luau"], -[131175, "src/Rosetta/image/ico/Dib.luau"], -[131270, "src/Rosetta/image/ilbm/init.luau"], -[131589, "src/Rosetta/image/jpeg/init.luau"], -[131725, "src/Rosetta/image/ktx/init.luau"], -[132385, "src/Rosetta/image/pcx/init.luau"], -[132649, "src/Rosetta/image/png/init.luau"], -[133229, "src/Rosetta/image/png/Apng.luau"], -[133309, "src/Rosetta/image/png/Decode.luau"], -[133549, "src/Rosetta/image/png/Encode.luau"], -[133704, "src/Rosetta/image/pnm/init.luau"], -[134082, "src/Rosetta/image/pnm/Codec.luau"], -[134359, "src/Rosetta/image/qoi/init.luau"], -[134481, "src/Rosetta/image/qoi/Codec.luau"], -[134631, "src/Rosetta/image/sgi/init.luau"], -[134916, "src/Rosetta/image/sunras/init.luau"], -[135162, "src/Rosetta/image/tga/init.luau"], -[135432, "src/Rosetta/image/tga/Codec.luau"], -[135584, "src/Rosetta/image/tiff/init.luau"], -[136411, "src/Rosetta/image/tiff/Pixels.luau"], -[136801, "src/Rosetta/image/tim/init.luau"], -[137043, "src/Rosetta/image/vtf/init.luau"], -[137278, "src/Rosetta/image/webp/init.luau"], -[137888, "src/Rosetta/image/webp/Alpha.luau"], -[137964, "src/Rosetta/image/webp/Anim.luau"], -[138119, "src/Rosetta/image/xbm/init.luau"], -[138280, "src/Rosetta/image/xpm/init.luau"], -[138548, "src/Rosetta/image/xpm/Names.luau"], -[138604, "src/Rosetta/layered/aseprite/init.luau"], -[139342, "src/Rosetta/layered/ora/init.luau"], -[139629, "src/Rosetta/layered/psd/init.luau"], -[140364, "src/Rosetta/layered/psd/Channels.luau"], -[140716, "src/Rosetta/model/3ds/init.luau"], -[140799, "src/Rosetta/model/3ds/Build.luau"], -[141446, "src/Rosetta/model/3ds/Read.luau"], -[141942, "src/Rosetta/model/3ds/Write.luau"], -[142747, "src/Rosetta/model/3mf/init.luau"], -[142829, "src/Rosetta/model/3mf/Read.luau"], -[143417, "src/Rosetta/model/3mf/Write.luau"], -[143822, "src/Rosetta/model/b3d/init.luau"], -[143877, "src/Rosetta/model/b3d/Read.luau"], -[144448, "src/Rosetta/model/bsp/init.luau"], -[144593, "src/Rosetta/model/bsp/Brush.luau"], -[144871, "src/Rosetta/model/bsp/Quake3.luau"], -[145126, "src/Rosetta/model/dae/init.luau"], -[145315, "src/Rosetta/model/dae/Math.luau"], -[145362, "src/Rosetta/model/dae/Read.luau"], -[147212, "src/Rosetta/model/dae/Write.luau"], -[147581, "src/Rosetta/model/fbx/init.luau"], -[147729, "src/Rosetta/model/fbx/Ascii.luau"], -[147999, "src/Rosetta/model/fbx/Binary.luau"], -[148454, "src/Rosetta/model/fbx/Read.luau"], -[149816, "src/Rosetta/model/fbx/Write.luau"], -[150801, "src/Rosetta/model/fbx/Xform.luau"], -[150842, "src/Rosetta/model/gltf/init.luau"], -[151079, "src/Rosetta/model/gltf/Pack.luau"], -[151148, "src/Rosetta/model/gltf/Read.luau"], -[151879, "src/Rosetta/model/gltf/Write.luau"], -[152559, "src/Rosetta/model/iqm/init.luau"], -[152635, "src/Rosetta/model/iqm/Read.luau"], -[152990, "src/Rosetta/model/iqm/Write.luau"], -[153677, "src/Rosetta/model/ldraw/init.luau"], -[153755, "src/Rosetta/model/ldraw/Colors.luau"], -[154073, "src/Rosetta/model/ldraw/Read.luau"], -[154650, "src/Rosetta/model/lwo/init.luau"], -[154726, "src/Rosetta/model/lwo/Build.luau"], -[155188, "src/Rosetta/model/lwo/Parse.luau"], -[155731, "src/Rosetta/model/mca/init.luau"], -[156073, "src/Rosetta/model/mca/Chunk.luau"], -[156206, "src/Rosetta/model/mca/Lz4Block.luau"], -[156276, "src/Rosetta/model/md2/init.luau"], -[156475, "src/Rosetta/model/md3/init.luau"], -[156703, "src/Rosetta/model/md5/init.luau"], -[156784, "src/Rosetta/model/md5/Read.luau"], -[157217, "src/Rosetta/model/mdl/init.luau"], -[157299, "src/Rosetta/model/mdl/HalfLife.luau"], -[157627, "src/Rosetta/model/mdl/Quake.luau"], -[157845, "src/Rosetta/model/ms3d/init.luau"], -[157917, "src/Rosetta/model/ms3d/Read.luau"], -[158363, "src/Rosetta/model/ms3d/Write.luau"], -[158832, "src/Rosetta/model/obj/init.luau"], -[159574, "src/Rosetta/model/obj/Mtl.luau"], -[159861, "src/Rosetta/model/off/init.luau"], -[160323, "src/Rosetta/model/ply/init.luau"], -[161428, "src/Rosetta/model/ply/Binary.luau"], -[161629, "src/Rosetta/model/pmx/init.luau"], -[161698, "src/Rosetta/model/pmx/Build.luau"], -[161994, "src/Rosetta/model/pmx/Pmd.luau"], -[162329, "src/Rosetta/model/pmx/Read.luau"], -[162733, "src/Rosetta/model/qb/init.luau"], -[163126, "src/Rosetta/model/rbxm/init.luau"], -[163718, "src/Rosetta/model/rbxmx/init.luau"], -[164371, "src/Rosetta/model/robloxmesh/init.luau"], -[165030, "src/Rosetta/model/robloxmesh/Parse.luau"], -[165487, "src/Rosetta/model/robloxmesh/Write.luau"], -[165596, "src/Rosetta/model/schematic/init.luau"], -[165917, "src/Rosetta/model/schematic/Common.luau"], -[166037, "src/Rosetta/model/schematic/Litematic.luau"], -[166248, "src/Rosetta/model/schematic/Mcedit.luau"], -[166492, "src/Rosetta/model/schematic/Sponge.luau"], -[166621, "src/Rosetta/model/smd/init.luau"], -[166688, "src/Rosetta/model/smd/Read.luau"], -[166957, "src/Rosetta/model/smd/Write.luau"], -[167200, "src/Rosetta/model/stl/init.luau"], -[167650, "src/Rosetta/model/stl/Decode.luau"], -[167724, "src/Rosetta/model/usda/init.luau"], -[167933, "src/Rosetta/model/usda/Build.luau"], -[169211, "src/Rosetta/model/usda/Parse.luau"], -[170009, "src/Rosetta/model/usda/Write.luau"], -[170826, "src/Rosetta/model/vox/init.luau"], -[171712, "src/Rosetta/model/vox/Grid.luau"], -[171769, "src/Rosetta/model/vrml/init.luau"], -[171835, "src/Rosetta/model/x/init.luau"], -[171965, "src/Rosetta/model/x/Build.luau"], -[172528, "src/Rosetta/model/x/Parse.luau"], -[172825, "src/Rosetta/model/x3d/init.luau"], -[172903, "src/Rosetta/music/669/init.luau"], -[173109, "src/Rosetta/music/ahx/init.luau"], -[173160, "src/Rosetta/music/far/init.luau"], -[173389, "src/Rosetta/music/hmp/init.luau"], -[173653, "src/Rosetta/music/hvl/init.luau"], -[173704, "src/Rosetta/music/it/init.luau"], -[174122, "src/Rosetta/music/it/Itsex.luau"], -[174238, "src/Rosetta/music/med/init.luau"], -[174885, "src/Rosetta/music/midi/init.luau"], -[175028, "src/Rosetta/music/midi/Smf.luau"], -[175439, "src/Rosetta/music/mod/init.luau"], -[175792, "src/Rosetta/music/mtm/init.luau"], -[176014, "src/Rosetta/music/mus/init.luau"], -[176171, "src/Rosetta/music/okt/init.luau"], -[176452, "src/Rosetta/music/ptm/init.luau"], -[176674, "src/Rosetta/music/s3m/init.luau"], -[176910, "src/Rosetta/music/sf2/init.luau"], -[176953, "src/Rosetta/music/stm/init.luau"], -[177184, "src/Rosetta/music/ult/init.luau"], -[177488, "src/Rosetta/music/umx/init.luau"], -[177704, "src/Rosetta/music/xm/init.luau"], -[178265, "src/Rosetta/music/xmi/init.luau"], -[178473, "src/Rosetta/ops/AudioOps.luau"], -[178922, "src/Rosetta/ops/ImageOps/init.luau"], -[179566, "src/Rosetta/ops/ImageOps/Kernels.luau"], -[180076, "src/Rosetta/ops/LayerOps.luau"], -[180169, "src/Rosetta/ops/MeshOps/init.luau"], -[181205, "src/Rosetta/ops/MeshOps/Greedy.luau"], -[181372, "src/Rosetta/ops/MusicOps.luau"], -[181720, "src/Rosetta/playlist/m3u/init.luau"], -[182073, "src/Rosetta/playlist/pls/init.luau"], -[182251, "src/Rosetta/playlist/xspf/init.luau"], -[182454, "src/Rosetta/subtitle/ass/init.luau"], -[182898, "src/Rosetta/subtitle/srt/init.luau"], -[183071, "src/Rosetta/subtitle/vtt/init.luau"], -[183274, "src/Rosetta/vector/svg/init.luau"], -[183360, "src/Rosetta/vector/svg/Parse.luau"], -[184106, "src/Rosetta/vector/svg/PathData.luau"], -[184474, "src/Rosetta/vector/svg/Render.luau"], -[184891, "src/Rosetta/vector/svg/Style.luau"], -[185263, "src/Rosetta/vector/svg/Write.luau"], -[185463, "src/Rosetta/vector/tiled/init.luau"], -[185643, "src/Rosetta/vector/tiled/Data.luau"], -[185794, "src/Rosetta/vector/tiled/Tmj.luau"], -[186425, "src/Rosetta/vector/tiled/Tmx.luau"], -[187037, "src/Rosetta/video/avi/init.luau"], -[187331, "src/Rosetta/video/fli/init.luau"], -[187482, "src/Rosetta/video/flv/init.luau"], -[187866, "src/Rosetta/video/flv/Amf.luau"], -[188024, "src/Rosetta/video/flv/Mux.luau"], -[188305, "src/Rosetta/video/h264/init.luau"], -[188444, "src/Rosetta/video/mkv/init.luau"], -[188600, "src/Rosetta/video/mkv/Mux.luau"], -[188879, "src/Rosetta/video/mkv/Parse.luau"], -[189600, "src/Rosetta/video/mp4/init.luau"], -[189928, "src/Rosetta/video/mpegps/init.luau"], -[190115, "src/Rosetta/video/mpegts/init.luau"], -[190353, "src/Rosetta/video/ogv/init.luau"], -[190748, "src/Rosetta/video/smk/init.luau"], -[191057, "src/Rosetta/video/smk/Audio.luau"], -[191177, "src/Rosetta/video/y4m/init.luau"] +[3004, "src/Rosetta/Types.luau"], +[4087, "src/Rosetta/archive/7z/init.luau"], +[4472, "src/Rosetta/archive/7z/Header.luau"], +[4999, "src/Rosetta/archive/adf/init.luau"], +[5281, "src/Rosetta/archive/applesingle/init.luau"], +[5467, "src/Rosetta/archive/ar/init.luau"], +[5870, "src/Rosetta/archive/arj/init.luau"], +[6080, "src/Rosetta/archive/binhex/init.luau"], +[6329, "src/Rosetta/archive/br/init.luau"], +[6404, "src/Rosetta/archive/bz2/init.luau"], +[6468, "src/Rosetta/archive/cab/init.luau"], +[6881, "src/Rosetta/archive/cab/Sum.luau"], +[6922, "src/Rosetta/archive/cpio/init.luau"], +[7090, "src/Rosetta/archive/d64/init.luau"], +[7504, "src/Rosetta/archive/fat/init.luau"], +[7626, "src/Rosetta/archive/grp/init.luau"], +[7740, "src/Rosetta/archive/gzip/init.luau"], +[7925, "src/Rosetta/archive/iso/init.luau"], +[7997, "src/Rosetta/archive/lha/init.luau"], +[8422, "src/Rosetta/archive/lz4/init.luau"], +[8766, "src/Rosetta/archive/macbinary/init.luau"], +[8964, "src/Rosetta/archive/mpq/init.luau"], +[9370, "src/Rosetta/archive/mpq/Crypt.luau"], +[9435, "src/Rosetta/archive/pak/init.luau"], +[9569, "src/Rosetta/archive/rpm/init.luau"], +[9893, "src/Rosetta/archive/tar/init.luau"], +[10011, "src/Rosetta/archive/unitypackage/init.luau"], +[10248, "src/Rosetta/archive/uu/init.luau"], +[10518, "src/Rosetta/archive/vpk/init.luau"], +[10829, "src/Rosetta/archive/wad/init.luau"], +[11279, "src/Rosetta/archive/wad/Map.luau"], +[11709, "src/Rosetta/archive/wad/Picture.luau"], +[11811, "src/Rosetta/archive/xz/init.luau"], +[11911, "src/Rosetta/archive/yenc/init.luau"], +[12183, "src/Rosetta/archive/z/init.luau"], +[12279, "src/Rosetta/archive/zip/init.luau"], +[12498, "src/Rosetta/archive/zoo/init.luau"], +[12694, "src/Rosetta/archive/zst/init.luau"], +[12758, "src/Rosetta/audio/aac/init.luau"], +[12964, "src/Rosetta/audio/ac3/init.luau"], +[13110, "src/Rosetta/audio/adpcm/init.luau"], +[13255, "src/Rosetta/audio/adx/init.luau"], +[13486, "src/Rosetta/audio/aiff/init.luau"], +[13877, "src/Rosetta/audio/ape/init.luau"], +[14005, "src/Rosetta/audio/au/init.luau"], +[14166, "src/Rosetta/audio/brstm/init.luau"], +[14457, "src/Rosetta/audio/caf/init.luau"], +[15119, "src/Rosetta/audio/flac/init.luau"], +[15267, "src/Rosetta/audio/flac/Meta.luau"], +[15489, "src/Rosetta/audio/flac/Stream.luau"], +[15859, "src/Rosetta/audio/m4a/init.luau"], +[16193, "src/Rosetta/audio/mp3/init.luau"], +[16453, "src/Rosetta/audio/mp3/Index.luau"], +[16644, "src/Rosetta/audio/mp3/Stream.luau"], +[16871, "src/Rosetta/audio/mp3/Tags.luau"], +[17183, "src/Rosetta/audio/mpc/init.luau"], +[17277, "src/Rosetta/audio/opus/init.luau"], +[17655, "src/Rosetta/audio/opus/Encode.luau"], +[17766, "src/Rosetta/audio/qoa/init.luau"], +[17946, "src/Rosetta/audio/tta/init.luau"], +[18064, "src/Rosetta/audio/vag/init.luau"], +[18287, "src/Rosetta/audio/voc/init.luau"], +[18562, "src/Rosetta/audio/vorbis/init.luau"], +[19016, "src/Rosetta/audio/vorbis/Encode.luau"], +[19829, "src/Rosetta/audio/wav/init.luau"], +[20450, "src/Rosetta/audio/wav/Codecs.luau"], +[20616, "src/Rosetta/audio/wavpack/init.luau"], +[20823, "src/Rosetta/cad/step/init.luau"], +[21205, "src/Rosetta/cad/step/Brep.luau"], +[21440, "src/Rosetta/cad/step/Parse.luau"], +[21997, "src/Rosetta/cad/step/Write.luau"], +[22245, "src/Rosetta/codecs/audio/Aac/init.luau"], +[22564, "src/Rosetta/codecs/audio/Aac/Decode.luau"], +[23447, "src/Rosetta/codecs/audio/Aac/Tables.luau"], +[23782, "src/Rosetta/codecs/audio/Ac3/init.luau"], +[23941, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], +[24826, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], +[24927, "src/Rosetta/codecs/audio/Adpcm/init.luau"], +[25681, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], +[25983, "src/Rosetta/codecs/audio/Alac/init.luau"], +[26217, "src/Rosetta/codecs/audio/Alac/Decode.luau"], +[26636, "src/Rosetta/codecs/audio/Alac/Encode.luau"], +[27048, "src/Rosetta/codecs/audio/Ape/init.luau"], +[27263, "src/Rosetta/codecs/audio/Ape/Decode.luau"], +[28024, "src/Rosetta/codecs/audio/ApeTag.luau"], +[28121, "src/Rosetta/codecs/audio/Flac/init.luau"], +[28132, "src/Rosetta/codecs/audio/Flac/Encode.luau"], +[29081, "src/Rosetta/codecs/audio/Flac/Frame.luau"], +[29678, "src/Rosetta/codecs/audio/Hively/init.luau"], +[29874, "src/Rosetta/codecs/audio/Hively/Load.luau"], +[30123, "src/Rosetta/codecs/audio/Hively/Player.luau"], +[31081, "src/Rosetta/codecs/audio/Hively/Tables.luau"], +[31300, "src/Rosetta/codecs/audio/Mdct/init.luau"], +[31484, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], +[31693, "src/Rosetta/codecs/audio/MidiRender.luau"], +[32039, "src/Rosetta/codecs/audio/Mpa/init.luau"], +[32053, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], +[32112, "src/Rosetta/codecs/audio/Mpa/Core.luau"], +[33715, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], +[34007, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], +[34392, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], +[35033, "src/Rosetta/codecs/audio/Mpa/Header.luau"], +[35174, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], +[35400, "src/Rosetta/codecs/audio/Musepack/init.luau"], +[35745, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], +[36626, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], +[37004, "src/Rosetta/codecs/audio/Opus/init.luau"], +[37018, "src/Rosetta/codecs/audio/Opus/Celt.luau"], +[38865, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], +[39930, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], +[39990, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], +[40450, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], +[40787, "src/Rosetta/codecs/audio/Opus/Packet.luau"], +[41020, "src/Rosetta/codecs/audio/Opus/Silk.luau"], +[43056, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], +[43430, "src/Rosetta/codecs/audio/Pcm/init.luau"], +[43693, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], +[43990, "src/Rosetta/codecs/audio/Qoa/init.luau"], +[44272, "src/Rosetta/codecs/audio/Resample/init.luau"], +[44631, "src/Rosetta/codecs/audio/SoundFont/init.luau"], +[44685, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], +[44828, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], +[45341, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], +[46122, "src/Rosetta/codecs/audio/Stream.luau"], +[46283, "src/Rosetta/codecs/audio/Tracker/init.luau"], +[46765, "src/Rosetta/codecs/audio/Tracker/Load.luau"], +[47043, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], +[47212, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], +[47340, "src/Rosetta/codecs/audio/Tracker/Player.luau"], +[49328, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], +[49444, "src/Rosetta/codecs/audio/Tta/init.luau"], +[49561, "src/Rosetta/codecs/audio/Tta/Decode.luau"], +[49813, "src/Rosetta/codecs/audio/Vorbis/init.luau"], +[49826, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], +[50210, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], +[50776, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], +[51197, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], +[51236, "src/Rosetta/codecs/audio/VorbisComment.luau"], +[51288, "src/Rosetta/codecs/audio/WavPack/init.luau"], +[51510, "src/Rosetta/codecs/audio/WavPack/Block.luau"], +[52965, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], +[53028, "src/Rosetta/codecs/compress/Brotli/init.luau"], +[53115, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], +[54084, "src/Rosetta/codecs/compress/Brotli/Static.luau"], +[54952, "src/Rosetta/codecs/compress/Bzip2/init.luau"], +[55000, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], +[55516, "src/Rosetta/codecs/compress/Deflate/init.luau"], +[55842, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], +[56262, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], +[56697, "src/Rosetta/codecs/compress/Explode.luau"], +[56893, "src/Rosetta/codecs/compress/Lz4.luau"], +[57162, "src/Rosetta/codecs/compress/Lzh/init.luau"], +[57766, "src/Rosetta/codecs/compress/Lzma/init.luau"], +[58306, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], +[58344, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], +[58817, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], +[58993, "src/Rosetta/codecs/compress/Lzw/init.luau"], +[59261, "src/Rosetta/codecs/compress/Lzx.luau"], +[59695, "src/Rosetta/codecs/compress/PackBits.luau"], +[59785, "src/Rosetta/codecs/compress/Quantum.luau"], +[60022, "src/Rosetta/codecs/compress/UnixCompress.luau"], +[60326, "src/Rosetta/codecs/compress/Xxh32.luau"], +[60395, "src/Rosetta/codecs/compress/Zstd/init.luau"], +[60452, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], +[61410, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], +[61562, "src/Rosetta/codecs/entropy/Huffman.luau"], +[61844, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], +[61855, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], +[62069, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], +[62313, "src/Rosetta/codecs/font/Bitmap.luau"], +[62514, "src/Rosetta/codecs/font/Cff/init.luau"], +[63155, "src/Rosetta/codecs/font/GlyphNames.luau"], +[63305, "src/Rosetta/codecs/font/TrueType/init.luau"], +[63619, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], +[64011, "src/Rosetta/codecs/font/TrueType/Tables.luau"], +[64513, "src/Rosetta/codecs/image/Bcn/init.luau"], +[64620, "src/Rosetta/codecs/image/Bcn/Decode.luau"], +[65109, "src/Rosetta/codecs/image/Bcn/Encode.luau"], +[65538, "src/Rosetta/codecs/image/Blend.luau"], +[65917, "src/Rosetta/codecs/image/Dct/init.luau"], +[66298, "src/Rosetta/codecs/image/Etc.luau"], +[66596, "src/Rosetta/codecs/image/Half.luau"], +[66665, "src/Rosetta/codecs/image/Jpeg/init.luau"], +[67019, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], +[67427, "src/Rosetta/codecs/image/Jpeg/Color.luau"], +[67664, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], +[68424, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], +[69305, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], +[69751, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], +[69829, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], +[69896, "src/Rosetta/codecs/image/Pixels.luau"], +[70160, "src/Rosetta/codecs/image/Quantize/init.luau"], +[70619, "src/Rosetta/codecs/image/Raster.luau"], +[71316, "src/Rosetta/codecs/image/Texel.luau"], +[71689, "src/Rosetta/codecs/image/Texture.luau"], +[71834, "src/Rosetta/codecs/image/Vp8/init.luau"], +[71964, "src/Rosetta/codecs/image/Vp8/Decode.luau"], +[73920, "src/Rosetta/codecs/image/Vp8/Predict.luau"], +[74179, "src/Rosetta/codecs/image/Vp8/Tables.luau"], +[74428, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], +[74547, "src/Rosetta/codecs/image/Vp8L/init.luau"], +[74651, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], +[75504, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], +[76456, "src/Rosetta/codecs/image/Yuv.luau"], +[76724, "src/Rosetta/codecs/model/Draco/init.luau"], +[77056, "src/Rosetta/codecs/model/Draco/Attributes.luau"], +[77525, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], +[78714, "src/Rosetta/codecs/model/Draco/Int64.luau"], +[78863, "src/Rosetta/codecs/model/Draco/KdTree.luau"], +[79222, "src/Rosetta/codecs/model/Draco/Predict.luau"], +[80184, "src/Rosetta/codecs/model/Draco/Reader.luau"], +[80658, "src/Rosetta/codecs/model/Mat4.luau"], +[80917, "src/Rosetta/codecs/model/MeshFlatten.luau"], +[81445, "src/Rosetta/codecs/model/Minecraft/init.luau"], +[81997, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], +[82076, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], +[82183, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], +[82389, "src/Rosetta/codecs/model/Polygon.luau"], +[82623, "src/Rosetta/codecs/model/Rbx/init.luau"], +[82860, "src/Rosetta/codecs/model/Rbx/Binary.luau"], +[83614, "src/Rosetta/codecs/model/Rig.luau"], +[83857, "src/Rosetta/codecs/model/Sampler.luau"], +[84017, "src/Rosetta/codecs/model/Vrml/init.luau"], +[84165, "src/Rosetta/codecs/model/Vrml/Build.luau"], +[84739, "src/Rosetta/codecs/model/Vrml/Fields.luau"], +[84902, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], +[85651, "src/Rosetta/codecs/model/Vrml/Parse.luau"], +[86173, "src/Rosetta/codecs/model/Vrml/Write.luau"], +[86900, "src/Rosetta/codecs/model/Vrml/Xml.luau"], +[87132, "src/Rosetta/codecs/text/Json/init.luau"], +[87401, "src/Rosetta/codecs/text/Json/Decode.luau"], +[87815, "src/Rosetta/codecs/text/Json/Encode.luau"], +[88117, "src/Rosetta/codecs/text/Nbt/init.luau"], +[88470, "src/Rosetta/codecs/text/Nbt/Binary.luau"], +[89162, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], +[89802, "src/Rosetta/codecs/text/Nbt/Value.luau"], +[90040, "src/Rosetta/codecs/text/Text/init.luau"], +[90131, "src/Rosetta/codecs/text/Url/init.luau"], +[90336, "src/Rosetta/codecs/text/Xml/init.luau"], +[90739, "src/Rosetta/codecs/text/Xml/Parse.luau"], +[91479, "src/Rosetta/codecs/video/Dsp.luau"], +[92202, "src/Rosetta/codecs/video/H263/init.luau"], +[92358, "src/Rosetta/codecs/video/H263/Decoder.luau"], +[93216, "src/Rosetta/codecs/video/H263/Tables.luau"], +[93419, "src/Rosetta/codecs/video/H264/init.luau"], +[93792, "src/Rosetta/codecs/video/H264/Bitstream.luau"], +[94067, "src/Rosetta/codecs/video/H264/Cabac.luau"], +[95198, "src/Rosetta/codecs/video/H264/Cavlc.luau"], +[95966, "src/Rosetta/codecs/video/H264/Deblock.luau"], +[96224, "src/Rosetta/codecs/video/H264/Decoder.luau"], +[97233, "src/Rosetta/codecs/video/H264/Inter.luau"], +[97487, "src/Rosetta/codecs/video/H264/Intra.luau"], +[97894, "src/Rosetta/codecs/video/H264/Mb.luau"], +[98800, "src/Rosetta/codecs/video/H264/Params.luau"], +[99247, "src/Rosetta/codecs/video/H264/Slice.luau"], +[99498, "src/Rosetta/codecs/video/H264/Tables.luau"], +[99539, "src/Rosetta/codecs/video/H264/Transform.luau"], +[99704, "src/Rosetta/codecs/video/Legacy/init.luau"], +[99902, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], +[100199, "src/Rosetta/codecs/video/Legacy/Flic.luau"], +[100566, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], +[100684, "src/Rosetta/codecs/video/Legacy/Picture.luau"], +[100792, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], +[101065, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], +[101460, "src/Rosetta/codecs/video/Legacy/Smc.luau"], +[101637, "src/Rosetta/codecs/video/Mpeg1/init.luau"], +[101649, "src/Rosetta/codecs/video/Mpeg2/init.luau"], +[102016, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], +[103523, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], +[103662, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], +[103800, "src/Rosetta/codecs/video/Theora/init.luau"], +[104063, "src/Rosetta/codecs/video/Theora/Decoder.luau"], +[105327, "src/Rosetta/codecs/video/Theora/Header.luau"], +[105690, "src/Rosetta/codecs/video/Video/init.luau"], +[106247, "src/Rosetta/codecs/video/Video/Source.luau"], +[106532, "src/Rosetta/containers/Archive.luau"], +[106799, "src/Rosetta/containers/AudioWrap.luau"], +[107302, "src/Rosetta/containers/Avi/init.luau"], +[107854, "src/Rosetta/containers/Chunks.luau"], +[107989, "src/Rosetta/containers/Cpio.luau"], +[108417, "src/Rosetta/containers/Demux.luau"], +[108692, "src/Rosetta/containers/Ebml/init.luau"], +[109005, "src/Rosetta/containers/Fat.luau"], +[109693, "src/Rosetta/containers/Iso9660.luau"], +[110198, "src/Rosetta/containers/IsoBmff/init.luau"], +[110368, "src/Rosetta/containers/IsoBmff/Box.luau"], +[110556, "src/Rosetta/containers/IsoBmff/Demux.luau"], +[111401, "src/Rosetta/containers/IsoBmff/Meta.luau"], +[111922, "src/Rosetta/containers/IsoBmff/Mux.luau"], +[112438, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], +[112555, "src/Rosetta/containers/MacFile.luau"], +[112704, "src/Rosetta/containers/MpegEs.luau"], +[112870, "src/Rosetta/containers/MpegPs/init.luau"], +[113090, "src/Rosetta/containers/MpegTs/init.luau"], +[113882, "src/Rosetta/containers/Ogg/init.luau"], +[114307, "src/Rosetta/containers/Ogg/Mux.luau"], +[114502, "src/Rosetta/containers/Ogg/Page.luau"], +[114671, "src/Rosetta/containers/Riff/init.luau"], +[114988, "src/Rosetta/containers/Tar.luau"], +[115402, "src/Rosetta/containers/Zip/init.luau"], +[116034, "src/Rosetta/core/Adler32.luau"], +[116080, "src/Rosetta/core/Base64.luau"], +[116239, "src/Rosetta/core/Bits.luau"], +[116532, "src/Rosetta/core/Bytes.luau"], +[117059, "src/Rosetta/core/Crc16.luau"], +[117111, "src/Rosetta/core/Crc32.luau"], +[117223, "src/Rosetta/core/Err.luau"], +[117305, "src/Rosetta/core/Input.luau"], +[117381, "src/Rosetta/core/Md5.luau"], +[117540, "src/Rosetta/core/Sniff.luau"], +[117569, "src/Rosetta/data/cbor/init.luau"], +[117668, "src/Rosetta/data/cbor/Codec.luau"], +[118237, "src/Rosetta/data/csv/init.luau"], +[118549, "src/Rosetta/data/ini/init.luau"], +[118795, "src/Rosetta/data/json/init.luau"], +[118887, "src/Rosetta/data/msgpack/init.luau"], +[118976, "src/Rosetta/data/msgpack/Codec.luau"], +[119418, "src/Rosetta/data/nbt/init.luau"], +[119477, "src/Rosetta/data/plist/init.luau"], +[119783, "src/Rosetta/data/plist/Binary.luau"], +[120050, "src/Rosetta/data/snbt/init.luau"], +[120113, "src/Rosetta/data/toml/init.luau"], +[120180, "src/Rosetta/data/toml/Decode.luau"], +[120808, "src/Rosetta/data/toml/Encode.luau"], +[121017, "src/Rosetta/data/xml/init.luau"], +[121073, "src/Rosetta/data/yaml/init.luau"], +[121146, "src/Rosetta/data/yaml/Emit.luau"], +[121436, "src/Rosetta/data/yaml/Parse.luau"], +[122729, "src/Rosetta/font/bdf/init.luau"], +[123018, "src/Rosetta/font/bmfont/init.luau"], +[123445, "src/Rosetta/font/bmfont/Parse.luau"], +[123898, "src/Rosetta/font/eot/init.luau"], +[124130, "src/Rosetta/font/fon/init.luau"], +[124413, "src/Rosetta/font/hershey/init.luau"], +[124608, "src/Rosetta/font/pcf/init.luau"], +[124888, "src/Rosetta/font/psf/init.luau"], +[125208, "src/Rosetta/font/ttf/init.luau"], +[125259, "src/Rosetta/font/type1/init.luau"], +[125618, "src/Rosetta/font/type1/Charstring.luau"], +[125896, "src/Rosetta/font/woff/init.luau"], +[126028, "src/Rosetta/font/woff2/init.luau"], +[126085, "src/Rosetta/font/woff2/Rebuild.luau"], +[126625, "src/Rosetta/host/init.luau"], +[126670, "src/Rosetta/host/Love.luau"], +[126813, "src/Rosetta/host/LuaJIT.luau"], +[126863, "src/Rosetta/host/Luau.luau"], +[126886, "src/Rosetta/host/Roblox.luau"], +[127245, "src/Rosetta/image/ani/init.luau"], +[127425, "src/Rosetta/image/blp/init.luau"], +[127683, "src/Rosetta/image/bmp/init.luau"], +[128098, "src/Rosetta/image/dds/init.luau"], +[128581, "src/Rosetta/image/exr/init.luau"], +[129341, "src/Rosetta/image/exr/Codec.luau"], +[129452, "src/Rosetta/image/exr/Piz.luau"], +[129809, "src/Rosetta/image/gif/init.luau"], +[130325, "src/Rosetta/image/gif/Decode.luau"], +[130388, "src/Rosetta/image/hdr/init.luau"], +[130617, "src/Rosetta/image/hdr/Codec.luau"], +[130828, "src/Rosetta/image/icns/init.luau"], +[131159, "src/Rosetta/image/ico/init.luau"], +[131436, "src/Rosetta/image/ico/Dib.luau"], +[131531, "src/Rosetta/image/ilbm/init.luau"], +[131850, "src/Rosetta/image/jpeg/init.luau"], +[131986, "src/Rosetta/image/ktx/init.luau"], +[132646, "src/Rosetta/image/pcx/init.luau"], +[132910, "src/Rosetta/image/png/init.luau"], +[133490, "src/Rosetta/image/png/Apng.luau"], +[133570, "src/Rosetta/image/png/Decode.luau"], +[133810, "src/Rosetta/image/png/Encode.luau"], +[133965, "src/Rosetta/image/pnm/init.luau"], +[134343, "src/Rosetta/image/pnm/Codec.luau"], +[134620, "src/Rosetta/image/qoi/init.luau"], +[134742, "src/Rosetta/image/qoi/Codec.luau"], +[134892, "src/Rosetta/image/sgi/init.luau"], +[135177, "src/Rosetta/image/sunras/init.luau"], +[135423, "src/Rosetta/image/tga/init.luau"], +[135693, "src/Rosetta/image/tga/Codec.luau"], +[135845, "src/Rosetta/image/tiff/init.luau"], +[136672, "src/Rosetta/image/tiff/Pixels.luau"], +[137062, "src/Rosetta/image/tim/init.luau"], +[137304, "src/Rosetta/image/vtf/init.luau"], +[137539, "src/Rosetta/image/webp/init.luau"], +[138149, "src/Rosetta/image/webp/Alpha.luau"], +[138225, "src/Rosetta/image/webp/Anim.luau"], +[138380, "src/Rosetta/image/xbm/init.luau"], +[138541, "src/Rosetta/image/xpm/init.luau"], +[138809, "src/Rosetta/image/xpm/Names.luau"], +[138865, "src/Rosetta/layered/aseprite/init.luau"], +[139603, "src/Rosetta/layered/ora/init.luau"], +[139890, "src/Rosetta/layered/psd/init.luau"], +[140625, "src/Rosetta/layered/psd/Channels.luau"], +[140977, "src/Rosetta/model/3ds/init.luau"], +[141060, "src/Rosetta/model/3ds/Build.luau"], +[141707, "src/Rosetta/model/3ds/Read.luau"], +[142203, "src/Rosetta/model/3ds/Write.luau"], +[143008, "src/Rosetta/model/3mf/init.luau"], +[143090, "src/Rosetta/model/3mf/Read.luau"], +[143678, "src/Rosetta/model/3mf/Write.luau"], +[144083, "src/Rosetta/model/ase/init.luau"], +[144206, "src/Rosetta/model/ase/Build.luau"], +[144780, "src/Rosetta/model/ase/Parse.luau"], +[144849, "src/Rosetta/model/ase/Write.luau"], +[145312, "src/Rosetta/model/b3d/init.luau"], +[145367, "src/Rosetta/model/b3d/Read.luau"], +[145938, "src/Rosetta/model/bsp/init.luau"], +[146083, "src/Rosetta/model/bsp/Brush.luau"], +[146361, "src/Rosetta/model/bsp/Quake3.luau"], +[146616, "src/Rosetta/model/dae/init.luau"], +[146805, "src/Rosetta/model/dae/Math.luau"], +[146852, "src/Rosetta/model/dae/Read.luau"], +[148702, "src/Rosetta/model/dae/Write.luau"], +[149071, "src/Rosetta/model/fbx/init.luau"], +[149219, "src/Rosetta/model/fbx/Ascii.luau"], +[149489, "src/Rosetta/model/fbx/Binary.luau"], +[149944, "src/Rosetta/model/fbx/Read.luau"], +[151306, "src/Rosetta/model/fbx/Write.luau"], +[152291, "src/Rosetta/model/fbx/Xform.luau"], +[152332, "src/Rosetta/model/gltf/init.luau"], +[152569, "src/Rosetta/model/gltf/Pack.luau"], +[152638, "src/Rosetta/model/gltf/Read.luau"], +[153369, "src/Rosetta/model/gltf/Write.luau"], +[154049, "src/Rosetta/model/iqm/init.luau"], +[154125, "src/Rosetta/model/iqm/Read.luau"], +[154480, "src/Rosetta/model/iqm/Write.luau"], +[155167, "src/Rosetta/model/ldraw/init.luau"], +[155245, "src/Rosetta/model/ldraw/Colors.luau"], +[155563, "src/Rosetta/model/ldraw/Read.luau"], +[156140, "src/Rosetta/model/lwo/init.luau"], +[156216, "src/Rosetta/model/lwo/Build.luau"], +[156678, "src/Rosetta/model/lwo/Parse.luau"], +[157221, "src/Rosetta/model/mca/init.luau"], +[157563, "src/Rosetta/model/mca/Chunk.luau"], +[157696, "src/Rosetta/model/mca/Lz4Block.luau"], +[157766, "src/Rosetta/model/md2/init.luau"], +[157965, "src/Rosetta/model/md3/init.luau"], +[158193, "src/Rosetta/model/md5/init.luau"], +[158274, "src/Rosetta/model/md5/Read.luau"], +[158707, "src/Rosetta/model/mdl/init.luau"], +[158789, "src/Rosetta/model/mdl/HalfLife.luau"], +[159117, "src/Rosetta/model/mdl/Quake.luau"], +[159335, "src/Rosetta/model/ms3d/init.luau"], +[159407, "src/Rosetta/model/ms3d/Read.luau"], +[159853, "src/Rosetta/model/ms3d/Write.luau"], +[160322, "src/Rosetta/model/obj/init.luau"], +[161064, "src/Rosetta/model/obj/Mtl.luau"], +[161351, "src/Rosetta/model/off/init.luau"], +[161813, "src/Rosetta/model/ply/init.luau"], +[162918, "src/Rosetta/model/ply/Binary.luau"], +[163119, "src/Rosetta/model/pmx/init.luau"], +[163188, "src/Rosetta/model/pmx/Build.luau"], +[163484, "src/Rosetta/model/pmx/Pmd.luau"], +[163819, "src/Rosetta/model/pmx/Read.luau"], +[164223, "src/Rosetta/model/qb/init.luau"], +[164616, "src/Rosetta/model/rbxm/init.luau"], +[165208, "src/Rosetta/model/rbxmx/init.luau"], +[165861, "src/Rosetta/model/robloxmesh/init.luau"], +[166520, "src/Rosetta/model/robloxmesh/Parse.luau"], +[166977, "src/Rosetta/model/robloxmesh/Write.luau"], +[167086, "src/Rosetta/model/schematic/init.luau"], +[167407, "src/Rosetta/model/schematic/Common.luau"], +[167527, "src/Rosetta/model/schematic/Litematic.luau"], +[167738, "src/Rosetta/model/schematic/Mcedit.luau"], +[167982, "src/Rosetta/model/schematic/Sponge.luau"], +[168111, "src/Rosetta/model/smd/init.luau"], +[168178, "src/Rosetta/model/smd/Read.luau"], +[168447, "src/Rosetta/model/smd/Write.luau"], +[168690, "src/Rosetta/model/stl/init.luau"], +[169140, "src/Rosetta/model/stl/Decode.luau"], +[169214, "src/Rosetta/model/usda/init.luau"], +[169423, "src/Rosetta/model/usda/Build.luau"], +[170701, "src/Rosetta/model/usda/Parse.luau"], +[171499, "src/Rosetta/model/usda/Write.luau"], +[172316, "src/Rosetta/model/vox/init.luau"], +[173202, "src/Rosetta/model/vox/Grid.luau"], +[173259, "src/Rosetta/model/vrml/init.luau"], +[173325, "src/Rosetta/model/x/init.luau"], +[173455, "src/Rosetta/model/x/Build.luau"], +[174018, "src/Rosetta/model/x/Parse.luau"], +[174315, "src/Rosetta/model/x3d/init.luau"], +[174393, "src/Rosetta/music/669/init.luau"], +[174599, "src/Rosetta/music/ahx/init.luau"], +[174650, "src/Rosetta/music/far/init.luau"], +[174879, "src/Rosetta/music/hmp/init.luau"], +[175143, "src/Rosetta/music/hvl/init.luau"], +[175194, "src/Rosetta/music/it/init.luau"], +[175612, "src/Rosetta/music/it/Itsex.luau"], +[175728, "src/Rosetta/music/med/init.luau"], +[176375, "src/Rosetta/music/midi/init.luau"], +[176518, "src/Rosetta/music/midi/Smf.luau"], +[176929, "src/Rosetta/music/mod/init.luau"], +[177282, "src/Rosetta/music/mtm/init.luau"], +[177504, "src/Rosetta/music/mus/init.luau"], +[177661, "src/Rosetta/music/okt/init.luau"], +[177942, "src/Rosetta/music/ptm/init.luau"], +[178164, "src/Rosetta/music/s3m/init.luau"], +[178400, "src/Rosetta/music/sf2/init.luau"], +[178443, "src/Rosetta/music/stm/init.luau"], +[178674, "src/Rosetta/music/ult/init.luau"], +[178978, "src/Rosetta/music/umx/init.luau"], +[179194, "src/Rosetta/music/xm/init.luau"], +[179755, "src/Rosetta/music/xmi/init.luau"], +[179963, "src/Rosetta/ops/AudioOps.luau"], +[180412, "src/Rosetta/ops/ImageOps/init.luau"], +[181056, "src/Rosetta/ops/ImageOps/Kernels.luau"], +[181566, "src/Rosetta/ops/LayerOps.luau"], +[181659, "src/Rosetta/ops/MeshOps/init.luau"], +[182695, "src/Rosetta/ops/MeshOps/Greedy.luau"], +[182862, "src/Rosetta/ops/MusicOps.luau"], +[183210, "src/Rosetta/playlist/m3u/init.luau"], +[183563, "src/Rosetta/playlist/pls/init.luau"], +[183741, "src/Rosetta/playlist/xspf/init.luau"], +[183944, "src/Rosetta/subtitle/ass/init.luau"], +[184388, "src/Rosetta/subtitle/srt/init.luau"], +[184561, "src/Rosetta/subtitle/vtt/init.luau"], +[184764, "src/Rosetta/vector/svg/init.luau"], +[184850, "src/Rosetta/vector/svg/Parse.luau"], +[185596, "src/Rosetta/vector/svg/PathData.luau"], +[185964, "src/Rosetta/vector/svg/Render.luau"], +[186381, "src/Rosetta/vector/svg/Style.luau"], +[186753, "src/Rosetta/vector/svg/Write.luau"], +[186953, "src/Rosetta/vector/tiled/init.luau"], +[187133, "src/Rosetta/vector/tiled/Data.luau"], +[187284, "src/Rosetta/vector/tiled/Tmj.luau"], +[187915, "src/Rosetta/vector/tiled/Tmx.luau"], +[188527, "src/Rosetta/video/avi/init.luau"], +[188821, "src/Rosetta/video/fli/init.luau"], +[188972, "src/Rosetta/video/flv/init.luau"], +[189356, "src/Rosetta/video/flv/Amf.luau"], +[189514, "src/Rosetta/video/flv/Mux.luau"], +[189795, "src/Rosetta/video/h264/init.luau"], +[189934, "src/Rosetta/video/mkv/init.luau"], +[190090, "src/Rosetta/video/mkv/Mux.luau"], +[190369, "src/Rosetta/video/mkv/Parse.luau"], +[191090, "src/Rosetta/video/mp4/init.luau"], +[191418, "src/Rosetta/video/mpegps/init.luau"], +[191605, "src/Rosetta/video/mpegts/init.luau"], +[191843, "src/Rosetta/video/ogv/init.luau"], +[192238, "src/Rosetta/video/smk/init.luau"], +[192547, "src/Rosetta/video/smk/Audio.luau"], +[192667, "src/Rosetta/video/y4m/init.luau"] ] diff --git a/build/rosetta.lua b/build/rosetta.lua index 18bac8a..5135f32 100644 --- a/build/rosetta.lua +++ b/build/rosetta.lua @@ -2225,6 +2225,18 @@ local list= { return __include("model/3mf") end, }, + { + name = "ase", + category = "model", + path = "model/ase", + extensions = { "ase", "ask" }, + mime = { "model/x-ase", "text/plain" }, + deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Text", "codecs/model/Mat4" }, + caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, vertexColors = true }, + load = function() + return __include("model/ase") + end, + }, { name = "b3d", category = "model", @@ -2993,6 +3005,18 @@ local list= { return __include("archive/tar") end, }, + { + name = "unitypackage", + category = "archive", + path = "archive/unitypackage", + extensions = { "unitypackage" }, + mime = { "application/x-unitypackage" }, + deps = { "core/Err", "core/Bytes", "core/Md5", "codecs/compress/Deflate", "containers/Archive", "containers/Tar" }, + caps = { decode = true, encode = true }, + load = function() + return __include("archive/unitypackage") + end, + }, { name = "uu", category = "archive", @@ -10616,6 +10640,243 @@ end return TarFormat end +__FILES["archive/unitypackage"] = function() +local __compat = __compat local buffer, type, __iter = __compat.buffer, __compat.type, __compat.__iter --!strict +-- archive/unitypackage: Unity asset packages, a gzip'd tar of /asset, /asset.meta, /pathname +-- (+ preview.png), read + write as an Archive keyed by the asset paths (Assets/...), each .meta next to its asset as +-- in a Unity project. Supports: folders (meta only), lazy entries, guids kept (entry.guid) or made from the path. +-- Not supported: pre-5.x packages without pathname files. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Md5 = __include("core/Md5") +local Deflate = __include("codecs/compress/Deflate") +local Archive = __include("containers/Archive") +local Tar = __include("containers/Tar") + +-- ------------------------------------------------------------------------------------------------ contract +local UnityPackage = { + name = "unitypackage", + category = "archive", + extensions = { "unitypackage" }, + mime = { "application/x-unitypackage" }, + deps = { "core/Err", "core/Bytes", "core/Md5", "codecs/compress/Deflate", "containers/Archive", "containers/Tar" }, + caps = { decode = true, encode = true }, +} + +-- ------------------------------------------------------------------------------------------------ sniff + + + + + + + + + +local function guidOf(name) +local n = string.gsub(name, "^%./", "") + local guid, rest = string.match(n, "^(%x+)/?(.*)$") + if guid and #guid == 32 then + return string.lower(guid), rest + end + return nil, nil +end + +function UnityPackage.sniff(r) +if r:peek(3) ~= "\31\139\8" then + return 0 + end + local head = Deflate.peek(r.buf, r.pos, r.limit - r.pos, 512) + if not head or buffer.len(head) < 512 or not Tar.valid(head, 0) then + return 0 + end + local z = 0 + while z < 100 and buffer.readu8(head, z) ~= 0 do + z =z+ 1 + end + return guidOf(buffer.readstring(head, 0, z)) and 1 or 0 -- ties with archive/gzip go to the extension +end + +-- ------------------------------------------------------------------------------------------------ decode +local function encode(archive, opts) +return UnityPackage.encode(archive, opts) +end + + + +local function text(b, e) +return buffer.readstring(b, e.offset, e.size) +end + +function UnityPackage.decode(r, opts) +local o = opts or {} + local tar, err = Deflate.gunzip(r.buf, r.base, r.limit - r.base) + if not tar then + return nil, err + end + if buffer.len(tar) > (o.maxBytes or 2 ^ 31) then + return nil, Err.new(Err.LIMIT, "inflated size over the byte limit") + end + local list, terr = Tar.read(tar, 0, buffer.len(tar), { maxEntries = o.maxEntries }) + if not list then + return nil, terr + end + local byGuid= {} + local order= {} + for _, e in __iter(list) do + local guid, rest = guidOf(e.name) + if guid and not e.dir then + local a = byGuid[guid] + if not a then + a = {} + byGuid[guid] = a + table.insert(order, guid) + end + if rest == "asset" then + a.asset = e + elseif rest == "asset.meta" then + a.meta = e + elseif rest == "pathname" then + a.pathname = e + elseif rest == "preview.png" then + a.preview = e + end + end + end + local arc = Archive.new("unitypackage", encode) + local skipped = 0 + for _, guid in __iter(order) do + local a = byGuid[guid] + local pn = a.pathname + if not pn then + skipped =skipped+ 1 + else + -- the first line is the path (Unity 5+ may add a second line, e.g. "00") + local path = string.match(text(tar, pn), "^[^\r\n]*") or "" + path = string.gsub(path, "\\", "/") + if path ~= "" then + local asset, meta = a.asset, a.meta + local isDir = asset == nil + Archive.put(arc, { + name = path, + size = (asset and{asset.size }or{0})[1], + dir = isDir, + mtime = (asset and{asset.mtime }or{(meta and{meta.mtime }or{nil})[1]})[1], + method = "deflate", + guid = guid, + load = (asset and asset.size > 0 and{(Archive.slice(tar, asset.offset, asset.size) )}or{nil})[1], + preview = (a.preview and{(Archive.slice(tar, a.preview.offset, a.preview.size) )}or{nil})[1], + }) + if meta then + Archive.put(arc, { + name = path .. ".meta", + size = meta.size, + dir = false, + mtime = meta.mtime, + method = "deflate", + guid = guid, + load = (meta.size > 0 and{(Archive.slice(tar, meta.offset, meta.size) )}or{nil})[1], + }) + end + end + end + end + arc.meta.source = { format = "unitypackage", assets = #order - skipped, skipped = (skipped > 0 and{skipped }or{nil })[1]} + return arc, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +local function metaGuid(b) +local s = buffer.readstring(b, 0, math.min(buffer.len(b), 4096)) + local g = string.match(s, "\nguid:%s*(%x+)") or string.match(s, "^guid:%s*(%x+)") + if g and #g == 32 then + return string.lower(g) + end + return nil +end + +local function defaultMeta(guid, dir) +if dir then + return "fileFormatVersion: 2\nguid: " .. guid .. "\nfolderAsset: yes\nDefaultImporter:\n externalObjects: {}\n userData: \n assetBundleName: \n assetBundleVariant: \n" + end + return "fileFormatVersion: 2\nguid: " .. guid .. "\nDefaultImporter:\n externalObjects: {}\n userData: \n assetBundleName: \n assetBundleVariant: \n" +end + +function UnityPackage.encode(archive, opts) +local o = opts or {} + local items = Archive.entries(archive) + if not items then + return nil, Err.new(Err.ARG, "expected an Archive") + end + local byName= {} + for _, it in __iter(items) do + byName[string.gsub(it.entry.name, "\\", "/")] = it + end + local mtime = o.mtime or 0 + local list= {} + local used= {} + for _, it in __iter(items) do + local e= it.entry + local path = string.gsub((string.gsub(e.name, "\\", "/")), "/+$", "") + local metaIt = byName[path .. ".meta"] + local isMeta = string.sub(path, -5) == ".meta" and byName[string.sub(path, 1, -6)] ~= nil + if path ~= "" and not isMeta then + local data= nil + if not e.dir then + local b, rerr = it.read() + if not b then + return nil, rerr + end + data = b + end + local metaData= nil + if metaIt then + local mb, merr = metaIt.read() + if not mb then + return nil, merr + end + metaData = mb + end + local guid = (type(e.guid) == "string" and #e.guid == 32 and string.match(e.guid, "^%x+$") and{(string.lower(e.guid) )}or{nil +})[1] guid = guid or ((metaData and{(metaGuid(metaData) )}or{nil})[1]) or Md5.of(buffer.fromstring(path)) + if used[guid ] then + guid = Md5.of(buffer.fromstring(path .. "\0" .. guid)) + end + used[guid ] = true + local g = guid +metaData = metaData or buffer.fromstring(defaultMeta(g, e.dir == true)) + table.insert(list, { name = g .. "/", dir = true, mtime = mtime }) + if data then + table.insert(list, { name = g .. "/asset", data = data, mtime = mtime }) + end + table.insert(list, { name = g .. "/asset.meta", data = metaData, mtime = mtime }) + table.insert(list, { name = g .. "/pathname", data = buffer.fromstring(path), mtime = mtime }) + if type(e.preview) == "function" then + local ok, pb = pcall(e.preview) + if ok and type(pb) == "buffer" then + table.insert(list, { name = g .. "/preview.png", data = pb, mtime = mtime }) + end + end + end + end + local tar, terr = Tar.write(list, { format = "ustar" }) + if not tar then + return nil, terr + end + return Deflate.gzip(tar, { level = o.level or 6 }) +end + +-- ------------------------------------------------------------------------------------------------ extras +function UnityPackage.new() +local a = Archive.new("unitypackage", encode) + a.meta.source = { format = "unitypackage" } + return a +end + +return UnityPackage +end __FILES["archive/uu"] = function() local __compat = __compat local buffer, bit32, type, __iter = __compat.buffer, __compat.bit32, __compat.type, __compat.__iter --!strict -- archive/uu: uuencode (POSIX), xxencode and GNU "begin-base64" blocks, one entry each (variant detected per block); @@ -144449,6 +144710,1235 @@ if not exts[e] then return w:finish() end +return Write +end +__FILES["model/ase"] = function() +local __compat = __compat local buffer, type = __compat.buffer, __compat.type --!strict +-- model/ase: 3ds Max ASCII Scene Export (*3DSMAX_ASCIIEXPORT 200), read + write; checked against assimp's ASE loader. +-- Supports: geometry objects (texture channels, vertex colours, explicit normals, Multi/Sub-Object materials by +-- *MESH_MTLID), NODE_TM hierarchies, helpers, cameras, lights, material maps (paths; data through opts.resolve), +-- UTF-16 files. Not supported: *TM_ANIMATION tracks (meta.source.animated is set), shapes (nodes only), bones. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Types = __include("Types") +local Text = __include("codecs/text/Text") +local Parse = __include("model/ase/Parse") +local Build = __include("model/ase/Build") +local Write = __include("model/ase/Write") + +-- ------------------------------------------------------------------------------------------------ contract +local Ase = { + name = "ase", + category = "model", + extensions = { "ase", "ask" }, + mime = { "model/x-ase", "text/plain" }, + deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Text", "codecs/model/Mat4" }, + caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, vertexColors = true }, +} +-- ------------------------------------------------------------------------------------------------ types +-- ------------------------------------------------------------------------------------------------ constants + + + + + + + + + + + +local MAGIC = "*3DSMAX_ASCIIEXPORT" + +-- ------------------------------------------------------------------------------------------------ sniff +local function utf16(r) +local h = r:peek(2) + if h == "\255\254" then + return true, false + elseif h == "\254\255" then + return true, true + elseif #h == 2 and string.byte(h, 2) == 0 and string.byte(h, 1) == 42 then + return true, false + elseif #h == 2 and string.byte(h, 1) == 0 and string.byte(h, 2) == 42 then + return true, true + end + return nil, false +end + +local function text(r, n) +local wide, be = utf16(r) + local len = r.limit - r.pos + if n then + len = math.min(len, n) + end + if wide then + local skip = (r:peek(2) == "\255\254" or r:peek(2) == "\254\255" )and 2 or 0 + return Text.utf16(r.buf, r.pos + skip, len - skip, be) + end + return Text.toUtf8(buffer.readstring(r.buf, r.pos, len)) +end + +function Ase.sniff(r) +local h = string.match(text(r, 256), "^%s*(%*[%w_]+)") + if h == MAGIC then + return 1 + end + return 0 +end + +-- ------------------------------------------------------------------------------------------------ decode +function Ase.decode(r, opts) +local o= opts or {} + if r.limit - r.pos > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local s = text(r) + if not string.match(s, "^%s*%*") then + return nil, Err.new(Err.CORRUPT, "not an ASE file") + end + local ok, root, msg = pcall(Parse.tree, s, o.maxItems or 2 ^ 24) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad data: " .. tostring(root)) + end + if not root then + return nil, Err.from(msg) + end + local ok2, scene, msg2 = pcall(Build.scene, root, o) + if not ok2 then + return nil, Err.from(tostring(scene)) + end + if not scene then + return nil, Err.from(msg2) + end + if #scene.nodes == 0 and (scene.meta.source ).version == nil then + return nil, Err.new(Err.CORRUPT, "no *3DSMAX_ASCIIEXPORT header and no objects") + end + return scene, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +function Ase.encode(scene, opts) +if type(scene) ~= "table" or type(scene.nodes) ~= "table" then + return nil, Err.new(Err.ARG, "needs a Scene") + end + local ok, s, msg = pcall(Write.scene, scene, opts) + if not ok then + return nil, Err.new(Err.ARG, "bad scene: " .. tostring(s)) + end + if not s then + return nil, Err.new(Err.ARG, msg or "bad scene") + end + return buffer.fromstring(s), nil +end + +return Ase +end +__FILES["model/ase/Build"] = function() +local __compat = __compat local buffer, type, __iter = __compat.buffer, __compat.type, __compat.__iter --!strict +-- model/ase/Build: the parsed ASE tree into a Scene. Mesh vertices are stored in world space (3ds Max ASCII export): +-- they are moved into the node's frame by the inverse NODE_TM, and node matrices are made relative to *NODE_PARENT. +local Types = __include("Types") +local Mat4 = __include("codecs/model/Mat4") +local Parse = __include("model/ase/Parse") + + + +local Build = {} + +local S = Types.Scene + +local function first(kids, key) +if kids then + for _, it in __iter(kids) do + if it.key == key then + return it + end + end + end + return nil +end + +local function num(it, i) +if not it then + return nil + end + local v = tonumber(it.args[i or 1]) + if v and v == v and v ~= math.huge and v ~= -math.huge then + return v + end + return nil +end + +local function get(kids, key, i) +return num(first(kids, key), i) +end + +local function str(kids, key) +local it = first(kids, key) + return (it and{it.args[1] }or{nil +})[1]end + +local function triple(kids, key) +local it = first(kids, key) + if not it then + return nil + end + local a, b, c = num(it, 1), num(it, 2), num(it, 3) + if a and b and c then + return { a, b, c } + end + return nil +end + +-- *TM_ROW0..2 are the axes, *TM_ROW3 the translation (row vectors): the columns of a column-major matrix +local function nodeTm(kids) +local tm = first(kids, "NODE_TM") + local m = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } + if not tm then + return m + end + for r = 0, 3 do + local row = triple(tm.kids, "TM_ROW" .. r) + if row then + m[r * 4 + 1], m[r * 4 + 2], m[r * 4 + 3] = row[1], row[2], row[3] + end + end + return m +end + +-- ------------------------------------------------------------------------------------------------ materials +local MAPS = { "MAP_DIFFUSE", "MAP_BUMP", "MAP_OPACITY", "MAP_SELFILLUM", "MAP_SPECULAR", "MAP_SHINE", "MAP_AMBIENT", "MAP_REFLECT", "MAP_REFRACT", "MAP_SHINESTRENGTH", "MAP_FILTERCOLOR" } + +local function textureRef(scene, map, opts) +local k = map.kids + local info= { + name = str(k, "MAP_NAME"), + class = str(k, "MAP_CLASS"), + amount = get(k, "MAP_AMOUNT"), + bitmap = str(k, "BITMAP"), + uOffset = get(k, "UVW_U_OFFSET"), + vOffset = get(k, "UVW_V_OFFSET"), + uTiling = get(k, "UVW_U_TILING"), + vTiling = get(k, "UVW_V_TILING"), + angle = get(k, "UVW_ANGLE"), + } + local path = info.bitmap + if type(path) ~= "string" or path == "" then + return nil, info + end + local tex= { name = path, uri = path } + if opts and type(opts.resolve) == "function" then + local ok, data = pcall(opts.resolve, path) + if ok and type(data) == "buffer" then + tex.data = data + end + end + table.insert(scene.textures, tex) + local ref= { texture = #scene.textures } + local su, sv = info.uTiling or 1, info.vTiling or 1 + local ou, ov = info.uOffset or 0, info.vOffset or 0 + local ang = info.angle or 0 + if su ~= 1 or sv ~= 1 or ou ~= 0 or ov ~= 0 or ang ~= 0 then + ref.transform = { offset = { ou, ov }, scale = { su, sv }, rotation = ang } + end + return ref, info +end + +local function material(scene, it, opts) +local k = it.kids + local m = S.material(str(k, "MATERIAL_NAME")) + local diffuse = triple(k, "MATERIAL_DIFFUSE") or { 0.8, 0.8, 0.8 } + local transparency = get(k, "MATERIAL_TRANSPARENCY") or 0 + local shine = get(k, "MATERIAL_SHINE") or 0 + local selfIllum = get(k, "MATERIAL_SELFILLUM") or 0 + m.baseColor = { diffuse[1], diffuse[2], diffuse[3], 1 - transparency } + m.metallic = 0 + m.roughness = math.clamp(1 - shine, 0, 1) + m.emissive = { diffuse[1] * selfIllum, diffuse[2] * selfIllum, diffuse[3] * selfIllum } + if transparency > 0 then + m.alphaMode = "blend" + end + m.doubleSided = first(k, "MATERIAL_TWOSIDED") ~= nil + local maps= {} + for _, key in __iter(MAPS) do + local map = first(k, key) + if map then + local ref, info = textureRef(scene, map, opts) + maps[string.lower(string.sub(key, 5))] = info + if ref then + if key == "MAP_DIFFUSE" then + m.baseColorTexture = ref + elseif key == "MAP_BUMP" then + m.normalTexture = ref + elseif key == "MAP_SELFILLUM" then + m.emissiveTexture = ref + m.emissive = { 1, 1, 1 } + end + end + end + end + m.extras = { + ambient = triple(k, "MATERIAL_AMBIENT"), + diffuse = diffuse, + specular = triple(k, "MATERIAL_SPECULAR"), + shininess = shine, + shineStrength = get(k, "MATERIAL_SHINESTRENGTH"), + transparency = transparency, + selfIllum = selfIllum, + ase = { class = str(k, "MATERIAL_CLASS"), shading = str(k, "MATERIAL_SHADING"), maps = maps }, + } + return m +end + +-- ASE material index (0-based) -> { scene material per sub-material } (one entry when it has none) +local function materials(scene, list, opts) +local out= {} + if not list or not list.kids then + return out + end + for _, it in __iter(list.kids) do + if it.key == "MATERIAL" then + local subs= {} + for _, sub in __iter(it.kids or {}) do + if sub.key == "SUBMATERIAL" then + table.insert(scene.materials, material(scene, sub, opts)) + table.insert(subs, #scene.materials) + end + end + if #subs == 0 then + table.insert(scene.materials, material(scene, it, opts)) + subs[1] = #scene.materials + end + table.insert(out, subs) + end + end + return out +end +-- ------------------------------------------------------------------------------------------------ meshes + + + +local function vectors(kids, listKey, itemKey, comps, max) +local out= {} + local list = first(kids, listKey) + if not list or not list.kids then + return out + end + for _, it in __iter(list.kids) do + if it.key == itemKey then + local i = num(it, 1) + if i and i >= 0 and i < max and i % 1 == 0 then + for c = 1, comps do + out[i * comps + c] = num(it, c + 1) or 0 + end + end + end + end + return out +end + +local function corners(kids, listKey, itemKey, max) +local out= {} + local list = first(kids, listKey) + if not list or not list.kids then + return out + end + for _, it in __iter(list.kids) do + if it.key == itemKey then + local i = num(it, 1) + if i and i >= 0 and i < max and i % 1 == 0 then + out[i * 3 + 1], out[i * 3 + 2], out[i * 3 + 3] = num(it, 2) or 0, num(it, 3) or 0, num(it, 4) or 0 + end + end + end + return out +end + +-- *MESH_FACE i: A: a B: b C: c AB: e BC: e CA: e, then its *MESH_SMOOTHING / *MESH_MTLID siblings + + +local function faces(list, nv, maxFaces) +local out= {} + if not list or not list.kids then + return out, nil + end + local last= nil + for _, it in __iter(list.kids) do + if it.key == "MESH_FACE" then + local s = table.concat(it.args, " ") + local i = tonumber(string.match(s, "^(%d+)")) + local a = tonumber(string.match(s, "A:%s*(%d+)")) + local b = tonumber(string.match(s, "B:%s*(%d+)")) + local c = tonumber(string.match(s, "C:%s*(%d+)")) + if not (i and a and b and c) then + return nil, "bad *MESH_FACE at byte " .. it.at + end + if a >= nv or b >= nv or c >= nv then + return nil, "face vertex index out of range at byte " .. it.at + end + if i >= maxFaces then + return nil, "limit: face index " .. i + end + local f= { a = a, b = b, c = c, mtl = 0, smoothing = nil } + out[i + 1] = f + last = f + elseif it.key == "MESH_MTLID" and last then + last.mtl = math.max(0, math.floor(num(it) or 0)) + elseif it.key == "MESH_SMOOTHING" and last then + last.smoothing = it.args[1] + end + end + for i = 1, #out do + if out[i] == nil then + out[i] = { a = 0, b = 0, c = 0, mtl = 0, smoothing = nil } + end + end + return out, nil +end + + + +local function channel(kids, numKey, listKey, vertKey, tfKey, tfListKey, nf, maxV) +local n = get(kids, numKey) or 0 + if n <= 0 then + return nil + end + n = math.min(n, maxV) + local verts = vectors(kids, listKey, vertKey, 3, n) + local tf = corners(kids, tfListKey, tfKey, nf) + return { verts = verts, tf = tf, comps = 3 } +end + +local function writeVec(acc, i, x, y, z) + local d = acc.data + buffer.writef32(d, i * 12, x) + buffer.writef32(d, i * 12 + 4, y) + buffer.writef32(d, i * 12 + 8, z) +end + +local function mesh(scene, obj, matMap, world, opts) +local m = first(obj.kids, "MESH") + if not m or not m.kids then + return nil, nil + end + local k = m.kids + local maxV = opts.maxVertices or 2 ^ 24 + local nv = get(k, "MESH_NUMVERTEX") or 0 + local nf = get(k, "MESH_NUMFACES") or 0 + if nv < 0 or nf < 0 or nv % 1 ~= 0 or nf % 1 ~= 0 then + return nil, "bad vertex or face count" + end + if nv > maxV or nf * 3 > maxV then + return nil, "limit: " .. nv .. " vertices, " .. nf .. " faces" + end + local pos = vectors(k, "MESH_VERTEX_LIST", "MESH_VERTEX", 3, nv) + local fl, ferr = faces(first(k, "MESH_FACE_LIST"), nv, nf) + if not fl then + return nil, ferr + end + if #fl == 0 then + return nil, nil + end + local uvs= {} + local ch0 = channel(k, "MESH_NUMTVERTEX", "MESH_TVERTLIST", "MESH_TVERT", "MESH_TFACE", "MESH_TFACELIST", #fl, maxV) + if ch0 then + uvs[1] = ch0 + end + for _, it in __iter(k) do + if it.key == "MESH_MAPPINGCHANNEL" and it.kids then + local idx = num(it) or 0 + local ch = channel(it.kids, "MESH_NUMTVERTEX", "MESH_TVERTLIST", "MESH_TVERT", "MESH_TFACE", "MESH_TFACELIST", #fl, maxV) + if ch and idx >= 2 and idx <= 8 then + uvs[idx] = ch + end + end + end + local colors = channel(k, "MESH_NUMCVERTEX", "MESH_CVERTLIST", "MESH_VERTCOL", "MESH_CFACE", "MESH_CFACELIST", #fl, maxV) + -- *MESH_NORMALS: *MESH_FACENORMAL f, then *MESH_VERTEXNORMAL v x y z for each of its corners + local normals= nil + local nlist = first(k, "MESH_NORMALS") + if nlist and nlist.kids then + local nn= {} + local face = -1 + for _, it in __iter(nlist.kids) do + if it.key == "MESH_FACENORMAL" then + face = num(it) or -1 + elseif it.key == "MESH_VERTEXNORMAL" and face >= 0 and face < #fl then + local f = fl[face + 1] + local v = num(it) + local corner = v == f.a and 0 or(v == f.b and 1 or(v == f.c and 2 or nil +)) if corner then + local o = (face * 3 + corner) * 3 + nn[o + 1], nn[o + 2], nn[o + 3] = num(it, 2) or 0, num(it, 3) or 0, num(it, 4) or 0 + end + end + end + normals = nn + end + -- faces by scene material (sub-material = *MESH_MTLID, the last one when out of range) + local ref = get(obj.kids, "MATERIAL_REF") + local subs= (ref and ref >= 0 and{matMap[math.min(ref, #matMap - 1) + 1] }or{nil +})[1] local groups= {} + local order= {} + for i, f in __iter(fl) do + local key = 0 + if subs and #subs > 0 then + key = subs[math.min(f.mtl, #subs - 1) + 1] + end + local g = groups[key] + if not g then + g = {} + groups[key] = g + table.insert(order, key) + end + table.insert(g, i) + end + table.sort(order) + local inv = Mat4.inverse(world) + local local_ = inv or S.IDENTITY + local nmat = Mat4.normalMatrix(local_) + local out= { name = str(obj.kids, "NODE_NAME"), primitives = {} } + for _, key in __iter(order) do + local list = groups[key] + local count = #list * 3 + local P = S.accessor(nil, "f32", 3, count) + local N = (normals and{(S.accessor(nil, "f32", 3, count) )}or{nil +})[1] local UV= {} + for idx in __iter(uvs) do + UV[idx] = S.accessor(nil, "f32", 2, count) + end + local C = (colors and{(S.accessor(nil, "f32", 4, count) )}or{nil +})[1] local I = S.accessor(nil, "u32", 1, count) + local w = 0 + for _, fi in __iter(list) do + local f = fl[fi] + local fc = { f.a, f.b, f.c } + for corner = 0, 2 do + local vi = fc[corner + 1] + local x, y, z = Mat4.point(local_, pos[vi * 3 + 1] or 0, pos[vi * 3 + 2] or 0, pos[vi * 3 + 3] or 0) + writeVec(P, w, x, y, z) + if N and normals then + local o = ((fi - 1) * 3 + corner) * 3 + local nx, ny, nz = normals[o + 1] or 0, normals[o + 2] or 0, normals[o + 3] or 0 + local tx = nmat[1] * nx + nmat[5] * ny + nmat[9] * nz + local ty = nmat[2] * nx + nmat[6] * ny + nmat[10] * nz + local tz = nmat[3] * nx + nmat[7] * ny + nmat[11] * nz + local len = math.sqrt(tx * tx + ty * ty + tz * tz) + if len > 0 then + tx, ty, tz = tx / len, ty / len, tz / len + end + writeVec(N, w, tx, ty, tz) + end + for idx, ch in __iter(uvs) do + local ti = ch.tf[(fi - 1) * 3 + corner + 1] or 0 + local u, v = ch.verts[ti * 3 + 1] or 0, ch.verts[ti * 3 + 2] or 0 + buffer.writef32(UV[idx].data, w * 8, u) + buffer.writef32(UV[idx].data, w * 8 + 4, 1 - v) -- 3ds Max v goes up + end + if C and colors then + local ci = colors.tf[(fi - 1) * 3 + corner + 1] or 0 + local d = C.data + buffer.writef32(d, w * 16, colors.verts[ci * 3 + 1] or 1) + buffer.writef32(d, w * 16 + 4, colors.verts[ci * 3 + 2] or 1) + buffer.writef32(d, w * 16 + 8, colors.verts[ci * 3 + 3] or 1) + buffer.writef32(d, w * 16 + 12, 1) + end + buffer.writeu32(I.data, w * 4, w) + w =w+ 1 + end + end + local attrs= { POSITION = P } + if N then + attrs.NORMAL = N + end + for idx, acc in __iter(UV) do + attrs["TEXCOORD_" .. (idx - 1)] = acc + end + if C then + attrs.COLOR_0 = C + end + local smoothing= {} + for j, fi in __iter(list) do + smoothing[j] = fl[fi].smoothing or "" + end + local prim= { + attributes = attrs, + indices = I, + mode = "triangles", + material = (key > 0 and{key }or{nil})[1], + extras = { smoothing = smoothing }, + } + table.insert(out.primitives, prim) + end + table.insert(scene.meshes, out) + return #scene.meshes, nil +end + +-- ------------------------------------------------------------------------------------------------ objects +local LIGHTS= { Omni = "point", Target = "spot", Free = "spot", Directional = "directional", TargetDirectional = "directional" } + +local function camera(scene, obj) +local st = first(obj.kids, "CAMERA_SETTINGS") + local fov = get(st and st.kids, "CAMERA_FOV") or math.rad(45) + local cam= { + name = str(obj.kids, "NODE_NAME"), + type = "perspective", + yfov = fov, -- 3ds Max stores the horizontal field of view (radians), kept as it is + znear = get(st and st.kids, "CAMERA_NEAR") or 0, + zfar = get(st and st.kids, "CAMERA_FAR"), + } + table.insert(scene.cameras, cam) + return #scene.cameras +end + +local function light(scene, obj) +local st = first(obj.kids, "LIGHT_SETTINGS") + local sk = st and st.kids + local typ = LIGHTS[str(obj.kids, "LIGHT_TYPE") or "Omni"] or "point" + local l= { + name = str(obj.kids, "NODE_NAME"), + type = typ, + color = triple(sk, "LIGHT_COLOR") or { 1, 1, 1 }, + intensity = get(sk, "LIGHT_INTENS") or 1, + } + if typ == "spot" then + l.innerCone = math.rad((get(sk, "LIGHT_HOTSPOT") or 43) / 2) + l.outerCone = math.rad((get(sk, "LIGHT_FALLOFF") or 45) / 2) + end + table.insert(scene.lights, l) + return #scene.lights +end + +local KINDS = { GEOMOBJECT = true, HELPEROBJECT = true, CAMERAOBJECT = true, LIGHTOBJECT = true, SHAPEOBJECT = true } + +local function collect(kids, into, depth) + for _, it in __iter(kids) do + if KINDS[it.key] then + table.insert(into, it) + elseif it.key == "GROUP" and it.kids and depth < 32 then + collect(it.kids, into, depth + 1) + end + end +end + +function Build.scene(root, opts) +local o = opts or {} + local scene = S.new() + local version = get(root, "3DSMAX_ASCIIEXPORT") + local sk = (first(root, "SCENE") or { kids = nil } ).kids + scene.meta.up = "z" + scene.meta.source = { + format = "ase", + version = version, + comment = str(root, "COMMENT"), + firstFrame = get(sk, "SCENE_FIRSTFRAME"), + lastFrame = get(sk, "SCENE_LASTFRAME"), + frameSpeed = get(sk, "SCENE_FRAMESPEED"), + ticksPerFrame = get(sk, "SCENE_TICKSPERFRAME"), + background = triple(sk, "SCENE_BACKGROUND_STATIC"), + ambient = triple(sk, "SCENE_AMBIENT_STATIC"), + } + local matMap = materials(scene, first(root, "MATERIAL_LIST"), o) + local objs= {} + collect(root, objs, 0) + local byName= {} + local worlds= {} + local parents= {} + local animated = false + for i, obj in __iter(objs) do + local name = str(obj.kids, "NODE_NAME") + local world = nodeTm(obj.kids) + local node= { name = name, children = {} } + local extras= { class = string.lower((string.gsub(obj.key, "OBJECT$", ""))) } + if obj.key == "GEOMOBJECT" then + local mi, merr = mesh(scene, obj, matMap, world, o) + if merr then + return nil, merr + end + node.mesh = mi + elseif obj.key == "CAMERAOBJECT" then + node.camera = camera(scene, obj) + elseif obj.key == "LIGHTOBJECT" then + node.light = light(scene, obj) + elseif obj.key == "HELPEROBJECT" then + extras.helperClass = str(obj.kids, "HELPER_CLASS") + end + if first(obj.kids, "TM_ANIMATION") then + animated = true + end + node.extras = { ase = extras } + scene.nodes[i] = node + worlds[i] = world + parents[i] = str(obj.kids, "NODE_PARENT") + if name and byName[name] == nil then + byName[name] = i + end + end + for i, node in __iter(scene.nodes) do + local pname = parents[i] + local p = (pname and{byName[pname] }or{nil +})[1] if p and p ~= i then + -- a parent cycle (or a parent listed later naming this node) falls back to a root + local q, steps = p, 0 + while q and q ~= i and steps < #objs do + local pn = parents[q] + q = (pn and{byName[pn] }or{nil +})[1] steps =steps+ 1 + end + if q == i then + p = nil + end + else + p = nil + end + local inv = (p and{(Mat4.inverse(worlds[p ]) )}or{nil +})[1] node.matrix = (inv and{(S.mul(inv, worlds[i]) )}or{worlds[i] +})[1] if p then + table.insert(scene.nodes[p ].children, i) + else + table.insert(scene.roots, i) + end + end + if animated then + (scene.meta.source ).animated = true + end + return scene, nil +end + +return Build +end +__FILES["model/ase/Parse"] = function() +--!strict +-- model/ase/Parse: ASE text into a tree of items (*KEY args { children }). Quoted strings carry no escapes (3ds Max +-- ASCII export). Several items may share a line (*MESH_FACE ... *MESH_SMOOTHING 1 *MESH_MTLID 0). +local Parse = {} + + + +function Parse.tree(text, maxItems) +local root= {} + local stack= { root } + local cur= nil + local p, n = 1, #text + local count = 0 + local find, sub, byte = string.find, string.sub, string.byte + while p <= n do + local s = find(text, "[^ \t\r\n]", p) + if not s then + break + end + local c = byte(text, s) + if c == 34 then -- '"' + local e = find(text, "\"", s + 1, true) + local stop = e or (n + 1) + if cur then + table.insert(cur.args, sub(text, s + 1, stop - 1)) + end + p = stop + 1 + elseif c == 123 then -- '{' + if not cur then + return nil, "'{' without an item at byte " .. s - 1 + end + if #stack > 64 then + return nil, "limit: nesting too deep" + end + local kids= {} + cur.kids = kids + table.insert(stack, kids) + cur = nil + p = s + 1 + elseif c == 125 then -- '}' + if #stack == 1 then + return nil, "unbalanced '}' at byte " .. s - 1 + end + table.remove(stack) + cur = nil + p = s + 1 + else + local e = find(text, "[ \t\r\n{}\"]", s) or (n + 1) + local word = sub(text, s, e - 1) + if c == 42 then -- '*' + count =count+ 1 + if count > maxItems then + return nil, "limit: over " .. maxItems .. " items" + end + local it= { key = sub(word, 2), args = {}, kids = nil, at = s - 1 } + table.insert(stack[#stack], it) + cur = it + elseif cur then + table.insert(cur.args, word) + end + p = e + end + end + return root, nil +end + +return Parse +end +__FILES["model/ase/Write"] = function() +local __compat = __compat local type, __iter = __compat.type, __compat.__iter --!strict +-- model/ase/Write: a Scene as ASE text (3DSMAX_ASCIIEXPORT 200). Vertices are written in world space with each node's +-- world NODE_TM; every scene material is a sub-material of one Multi/Sub-Object material (faces pick it by +-- *MESH_MTLID). Triangles, strips, fans and polygons (fanned) are written; points and lines are skipped. +local Types = __include("Types") +local Mat4 = __include("codecs/model/Mat4") + +local Write = {} + +local S = Types.Scene + +local function f(v) +if v ~= v or v == math.huge or v == -math.huge then + return "0.0000" + end + if v == math.floor(v) and math.abs(v) < 1e15 then + return string.format("%.4f", v) + end + return string.format("%.9g", v) +end + +local function q(s) +return "\"" .. string.gsub(s, "\"", "'") .. "\"" +end + + + +local function put(out, depth, s) + table.insert(out.lines, string.rep("\t", depth) .. s) +end + +local function tri(prim) +local pos = prim.attributes and prim.attributes.POSITION + if type(pos) ~= "table" then + return nil + end + local n = pos.count + local idx= {} + if prim.indices then + local rd = S.reader(prim.indices) + if not rd then + return nil + end + for i = 0, prim.indices.count - 1 do + idx[i + 1] = rd(i, 0) + end + else + for i = 0, n - 1 do + idx[i + 1] = i + end + end + local mode = prim.mode or "triangles" + local out= {} + if mode == "triangles" then + for i = 1, #idx - 2, 3 do + table.insert(out, idx[i]) + table.insert(out, idx[i + 1]) + table.insert(out, idx[i + 2]) + end + elseif mode == "triangle_strip" then + for i = 1, #idx - 2 do + if i % 2 == 1 then + table.insert(out, idx[i]) + table.insert(out, idx[i + 1]) + else + table.insert(out, idx[i + 1]) + table.insert(out, idx[i]) + end + table.insert(out, idx[i + 2]) + end + elseif mode == "triangle_fan" then + for i = 2, #idx - 1 do + table.insert(out, idx[1]) + table.insert(out, idx[i]) + table.insert(out, idx[i + 1]) + end + elseif mode == "polygons" and prim.faces then + local rd = S.reader(prim.faces) + local at = 1 + if rd then + for fi = 0, prim.faces.count - 1 do + local size = rd(fi, 0) + for k = 1, size - 2 do + table.insert(out, idx[at]) + table.insert(out, idx[at + k]) + table.insert(out, idx[at + k + 1]) + end + at =at+ size + end + end + else + return nil + end + for _, v in __iter(out) do + if v < 0 or v >= n then + return nil + end + end + return out +end + +local function material(out, d, key, index, m) + put(out, d, "*" .. key .. " " .. index .. " {") + local c = (type(m.baseColor) == "table" and{m.baseColor }or{{ 1, 1, 1, 1 } +})[1] local x = (type(m.extras) == "table" and{m.extras }or{{} +})[1] local amb = (type(x.ambient) == "table" and{x.ambient }or{{ c[1] or 1, c[2] or 1, c[3] or 1 } +})[1] local spec = (type(x.specular) == "table" and{x.specular }or{{ 0.9, 0.9, 0.9 } +})[1] put(out, d + 1, "*MATERIAL_NAME " .. q((type(m.name) == "string" and{m.name }or{("Material #" .. index)})[1])) + put(out, d + 1, "*MATERIAL_CLASS \"Standard\"") + put(out, d + 1, "*MATERIAL_AMBIENT " .. f(amb[1] or 0) .. "\t" .. f(amb[2] or 0) .. "\t" .. f(amb[3] or 0)) + put(out, d + 1, "*MATERIAL_DIFFUSE " .. f(c[1] or 1) .. "\t" .. f(c[2] or 1) .. "\t" .. f(c[3] or 1)) + put(out, d + 1, "*MATERIAL_SPECULAR " .. f(spec[1] or 0) .. "\t" .. f(spec[2] or 0) .. "\t" .. f(spec[3] or 0)) + put(out, d + 1, "*MATERIAL_SHINE " .. f((type(x.shininess) == "number" and{x.shininess }or{(1 - (m.roughness or 1))})[1])) + put(out, d + 1, "*MATERIAL_SHINESTRENGTH " .. f((type(x.shineStrength) == "number" and{x.shineStrength }or{0})[1])) + put(out, d + 1, "*MATERIAL_TRANSPARENCY " .. f(1 - (c[4] or 1))) + put(out, d + 1, "*MATERIAL_WIRESIZE 1.0000") + if m.doubleSided then + put(out, d + 1, "*MATERIAL_TWOSIDED") + end + put(out, d + 1, "*MATERIAL_SHADING Blinn") + put(out, d + 1, "*MATERIAL_SELFILLUM " .. f((type(x.selfIllum) == "number" and{x.selfIllum }or{0})[1])) + local ref = m.baseColorTexture + local tex = (type(ref) == "table" and type(m._textures) == "table" and{m._textures[ref.texture] }or{nil +})[1] if tex and type(tex.uri) == "string" then + local tr = (type(ref.transform) == "table" and{ref.transform }or{{} +})[1] local off = (type(tr.offset) == "table" and{tr.offset }or{{ 0, 0 } +})[1] local sc = (type(tr.scale) == "table" and{tr.scale }or{{ 1, 1 } +})[1] put(out, d + 1, "*MAP_DIFFUSE {") + put(out, d + 2, "*MAP_NAME " .. q(tex.name or tex.uri)) + put(out, d + 2, "*MAP_CLASS \"Bitmap\"") + put(out, d + 2, "*MAP_SUBNO 1") + put(out, d + 2, "*MAP_AMOUNT 1.0000") + put(out, d + 2, "*BITMAP " .. q(tex.uri)) + put(out, d + 2, "*MAP_TYPE Screen") + put(out, d + 2, "*UVW_U_OFFSET " .. f(off[1] or 0)) + put(out, d + 2, "*UVW_V_OFFSET " .. f(off[2] or 0)) + put(out, d + 2, "*UVW_U_TILING " .. f(sc[1] or 1)) + put(out, d + 2, "*UVW_V_TILING " .. f(sc[2] or 1)) + put(out, d + 2, "*UVW_ANGLE " .. f(tr.rotation or 0)) + put(out, d + 1, "}") + end + put(out, d, "}") +end + +local function nodeTm(out, name, m) + put(out, 1, "*NODE_TM {") + put(out, 2, "*NODE_NAME " .. q(name)) + put(out, 2, "*INHERIT_POS 0 0 0") + put(out, 2, "*INHERIT_ROT 0 0 0") + put(out, 2, "*INHERIT_SCL 0 0 0") + for r = 0, 3 do + put(out, 2, "*TM_ROW" .. r .. " " .. f(m[r * 4 + 1]) .. "\t" .. f(m[r * 4 + 2]) .. "\t" .. f(m[r * 4 + 3])) + end + local t, r, s = Mat4.decompose(m) + local w = math.clamp(r[4], -1, 1) + local angle = 2 * math.acos(w) + local sn = math.sqrt(math.max(0, 1 - w * w)) + local ax = sn > 1e-9 and{ r[1] / sn, r[2] / sn, r[3] / sn } or{ 0, 0, 0 } + put(out, 2, "*TM_POS " .. f(t[1]) .. "\t" .. f(t[2]) .. "\t" .. f(t[3])) + put(out, 2, "*TM_ROTAXIS " .. f(ax[1]) .. "\t" .. f(ax[2]) .. "\t" .. f(ax[3])) + put(out, 2, "*TM_ROTANGLE " .. f(angle)) + put(out, 2, "*TM_SCALE " .. f(s[1]) .. "\t" .. f(s[2]) .. "\t" .. f(s[3])) + put(out, 2, "*TM_SCALEAXIS 0.0000\t0.0000\t0.0000") + put(out, 2, "*TM_SCALEAXISANG 0.0000") + put(out, 1, "}") +end + +local function vec(rd, i, n, default) +local v = {} + for c = 0, n - 1 do + v[c + 1] = (rd and{(rd(i, c) )}or{default +})[1] end + return v +end + +local function geom(out, scene, mesh, world, matBase, hasMulti) +local P= {} + local N= {} + local T= {} + local C= {} + local F= {} + local M= {} + local hasN, hasC = false, false + local uvSets= {} + for _, prim in __iter(mesh.primitives or {}) do + for name in __iter(prim.attributes or {}) do + local k = string.match(name, "^TEXCOORD_(%d)$") + if k then + uvSets[(tonumber(k) )] = true + end + end + end + local nm = Mat4.normalMatrix(world) + for _, prim in __iter(mesh.primitives or {}) do + local idx = tri(prim) + if idx then + local a = prim.attributes + local base = math.floor(#P / 3 +) local rp = S.reader(a.POSITION) + local rn = (a.NORMAL and{(S.reader(a.NORMAL) )}or{nil +})[1] local rc = (a.COLOR_0 and{(S.reader(a.COLOR_0) )}or{nil +})[1] local cc = (a.COLOR_0 and{a.COLOR_0.components }or{0 +})[1] if rp then + for i = 0, a.POSITION.count - 1 do + local x, y, z = Mat4.point(world, rp(i, 0), rp(i, 1), rp(i, 2)) + table.insert(P, x) + table.insert(P, y) + table.insert(P, z) + local nv = vec(rn, i, 3, 0) + local tx = nm[1] * nv[1] + nm[5] * nv[2] + nm[9] * nv[3] + local ty = nm[2] * nv[1] + nm[6] * nv[2] + nm[10] * nv[3] + local tz = nm[3] * nv[1] + nm[7] * nv[2] + nm[11] * nv[3] + local len = math.sqrt(tx * tx + ty * ty + tz * tz) + if len > 0 then + tx, ty, tz = tx / len, ty / len, tz / len + end + table.insert(N, tx) + table.insert(N, ty) + table.insert(N, tz) + for k in __iter(uvSets) do + local acc = a["TEXCOORD_" .. k] + local rt = (acc and{(S.reader(acc) )}or{nil +})[1] local list = T[k] or {} + T[k] = list + table.insert(list, (rt and{(rt(i, 0) )}or{0})[1]) + table.insert(list, (rt and{(1 - rt(i, 1) )}or{0})[1]) + end + local col = vec(rc, i, math.max(cc, 3), 1) + table.insert(C, col[1]) + table.insert(C, col[2]) + table.insert(C, col[3]) + end + hasN = hasN or rn ~= nil + hasC = hasC or rc ~= nil + local mid = (prim.material and matBase[prim.material] and{matBase[prim.material] }or{((hasMulti and((#scene.materials ))or(0))) +})[1] for i = 1, #idx, 3 do + table.insert(F, base + idx[i]) + table.insert(F, base + idx[i + 1]) + table.insert(F, base + idx[i + 2]) + table.insert(M, mid) + end + end + end + end + if #F == 0 then + return false + end + local nv, nf = math.floor(#P / 3), math.floor(#F / 3 +) put(out, 1, "*MESH {") + put(out, 2, "*TIMEVALUE 0") + put(out, 2, "*MESH_NUMVERTEX " .. nv) + put(out, 2, "*MESH_NUMFACES " .. nf) + put(out, 2, "*MESH_VERTEX_LIST {") + for i = 0, nv - 1 do + put(out, 3, "*MESH_VERTEX " .. i .. "\t" .. f(P[i * 3 + 1]) .. "\t" .. f(P[i * 3 + 2]) .. "\t" .. f(P[i * 3 + 3])) + end + put(out, 2, "}") + put(out, 2, "*MESH_FACE_LIST {") + for i = 0, nf - 1 do + put(out, 3, string.format("*MESH_FACE %d: A: %d B: %d C: %d AB: 1 BC: 1 CA: 1\t*MESH_SMOOTHING 1\t*MESH_MTLID %d", i, F[i * 3 + 1], F[i * 3 + 2], F[i * 3 + 3], M[i + 1])) + end + put(out, 2, "}") + local function uvBlock(d, list) + put(out, d, "*MESH_NUMTVERTEX " .. nv) + put(out, d, "*MESH_TVERTLIST {") + for i = 0, nv - 1 do + put(out, d + 1, "*MESH_TVERT " .. i .. "\t" .. f(list[i * 2 + 1] or 0) .. "\t" .. f(list[i * 2 + 2] or 0) .. "\t0.0000") + end + put(out, d, "}") + put(out, d, "*MESH_NUMTVFACES " .. nf) + put(out, d, "*MESH_TFACELIST {") + for i = 0, nf - 1 do + put(out, d + 1, "*MESH_TFACE " .. i .. "\t" .. F[i * 3 + 1] .. "\t" .. F[i * 3 + 2] .. "\t" .. F[i * 3 + 3]) + end + put(out, d, "}") + end + if T[0] then + uvBlock(2, T[0]) + end + for k = 1, 7 do + if T[k] then + put(out, 2, "*MESH_MAPPINGCHANNEL " .. (k + 1) .. " {") + uvBlock(3, T[k]) + put(out, 2, "}") + end + end + if hasC then + put(out, 2, "*MESH_NUMCVERTEX " .. nv) + put(out, 2, "*MESH_CVERTLIST {") + for i = 0, nv - 1 do + put(out, 3, "*MESH_VERTCOL " .. i .. "\t" .. f(C[i * 3 + 1]) .. "\t" .. f(C[i * 3 + 2]) .. "\t" .. f(C[i * 3 + 3])) + end + put(out, 2, "}") + put(out, 2, "*MESH_NUMCVFACES " .. nf) + put(out, 2, "*MESH_CFACELIST {") + for i = 0, nf - 1 do + put(out, 3, "*MESH_CFACE " .. i .. "\t" .. F[i * 3 + 1] .. "\t" .. F[i * 3 + 2] .. "\t" .. F[i * 3 + 3]) + end + put(out, 2, "}") + end + if hasN then + put(out, 2, "*MESH_NORMALS {") + for i = 0, nf - 1 do + local a, b, c = F[i * 3 + 1], F[i * 3 + 2], F[i * 3 + 3] + local ux, uy, uz = P[b * 3 + 1] - P[a * 3 + 1], P[b * 3 + 2] - P[a * 3 + 2], P[b * 3 + 3] - P[a * 3 + 3] + local vx, vy, vz = P[c * 3 + 1] - P[a * 3 + 1], P[c * 3 + 2] - P[a * 3 + 2], P[c * 3 + 3] - P[a * 3 + 3] + local nx, ny, nz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + local len = math.sqrt(nx * nx + ny * ny + nz * nz) + if len > 0 then + nx, ny, nz = nx / len, ny / len, nz / len + end + put(out, 3, "*MESH_FACENORMAL " .. i .. "\t" .. f(nx) .. "\t" .. f(ny) .. "\t" .. f(nz)) + for _, v in __iter({ a, b, c }) do + put(out, 4, "*MESH_VERTEXNORMAL " .. v .. "\t" .. f(N[v * 3 + 1]) .. "\t" .. f(N[v * 3 + 2]) .. "\t" .. f(N[v * 3 + 3])) + end + end + put(out, 2, "}") + end + put(out, 1, "}") + return true +end + +function Write.scene(scene, opts) +local out= { lines = {} } + local src = (type(scene.meta) == "table" and type(scene.meta.source) == "table" and{scene.meta.source }or{{} +})[1] put(out, 0, "*3DSMAX_ASCIIEXPORT\t200") + put(out, 0, "*COMMENT " .. q((opts and type(opts.comment) == "string" and{opts.comment }or{"AsciiExport-Version 2,00 - rosetta"})[1])) + put(out, 0, "*SCENE {") + put(out, 1, "*SCENE_FILENAME \"\"") + put(out, 1, "*SCENE_FIRSTFRAME " .. math.floor(tonumber(src.firstFrame) or 0)) + put(out, 1, "*SCENE_LASTFRAME " .. math.floor(tonumber(src.lastFrame) or 100)) + put(out, 1, "*SCENE_FRAMESPEED " .. math.floor(tonumber(src.frameSpeed) or 30)) + put(out, 1, "*SCENE_TICKSPERFRAME " .. math.floor(tonumber(src.ticksPerFrame) or 160)) + put(out, 1, "*SCENE_BACKGROUND_STATIC 0.0000\t0.0000\t0.0000") + put(out, 1, "*SCENE_AMBIENT_STATIC 0.0000\t0.0000\t0.0000") + put(out, 0, "}") + local mats = scene.materials or {} + local nmat = #mats + local matBase= {} + -- a default sub-material for primitives without one, when other primitives have one + local needDefault = false + for _, mesh in __iter(scene.meshes or {}) do + for _, prim in __iter(mesh.primitives or {}) do + if not (prim.material and mats[prim.material]) then + needDefault = true + end + end + end + put(out, 0, "*MATERIAL_LIST {") + if nmat > 0 then + put(out, 1, "*MATERIAL_COUNT 1") + put(out, 1, "*MATERIAL 0 {") + put(out, 2, "*MATERIAL_NAME \"Multimaterial\"") + put(out, 2, "*MATERIAL_CLASS \"Multi/Sub-Object\"") + put(out, 2, "*NUMSUBMTLS " .. (nmat + (needDefault and 1 or 0))) + for i, m in __iter(mats) do + matBase[i] = i - 1 + local mm = table.clone(m) + mm._textures = scene.textures + material(out, 2, "SUBMATERIAL", i - 1, mm) + end + if needDefault then + material(out, 2, "SUBMATERIAL", nmat, S.material("Default")) + end + put(out, 1, "}") + else + put(out, 1, "*MATERIAL_COUNT 0") + end + put(out, 0, "}") + -- world matrices and unique names + local nodes = scene.nodes or {} + local worlds= {} + local parentOf= {} + local order= {} + local function walk(i, parent, depth) + local node = nodes[i] + if not node or worlds[i] or depth > 256 then + return + end + worlds[i] = S.mul(parent, S.nodeMatrix(node)) + table.insert(order, i) + for _, c in __iter(node.children or {}) do + if nodes[c] and not worlds[c] then + parentOf[c] = i + walk(c, worlds[i], depth + 1) + end + end + end + local roots = scene.roots or {} + if #roots == 0 then + for i in __iter(nodes) do + table.insert(roots, i) + end + end + for _, r in __iter(roots) do + walk(r, S.IDENTITY, 0) + end + local names= {} + local used= {} + for _, i in __iter(order) do + local base = (type(nodes[i].name) == "string" and nodes[i].name ~= "" and{nodes[i].name }or{("Object" .. i +)})[1] local name, k = base, 1 + while used[name] do + k =k+ 1 + name = base .. "_" .. k + end + used[name] = true + names[i] = name + end + for _, i in __iter(order) do + local node = nodes[i] + local w = worlds[i] + local mesh = (node.mesh and{(scene.meshes or {})[node.mesh] }or{nil +})[1] local cam = (node.camera and{(scene.cameras or {})[node.camera] }or{nil +})[1] local li = (node.light and{(scene.lights or {})[node.light] }or{nil +})[1] local key = mesh and"GEOMOBJECT" or(cam and"CAMERAOBJECT" or(li and"LIGHTOBJECT" or"HELPEROBJECT" +)) put(out, 0, "*" .. key .. " {") + put(out, 1, "*NODE_NAME " .. q(names[i])) + if parentOf[i] then + put(out, 1, "*NODE_PARENT " .. q(names[parentOf[i] ])) + end + if key == "HELPEROBJECT" then + put(out, 1, "*HELPER_CLASS \"Dummy\"") + elseif key == "CAMERAOBJECT" then + put(out, 1, "*CAMERA_TYPE Free") + elseif key == "LIGHTOBJECT" then + put(out, 1, "*LIGHT_TYPE " .. (li.type == "spot" and"Free" or(li.type == "directional" and"Directional" or"Omni"))) + end + nodeTm(out, names[i], w) + if mesh then + geom(out, scene, mesh, w, matBase, nmat > 0) + put(out, 1, "*PROP_MOTIONBLUR 0") + put(out, 1, "*PROP_CASTSHADOW 1") + put(out, 1, "*PROP_RECVSHADOW 1") + if nmat > 0 then + put(out, 1, "*MATERIAL_REF 0") + end + elseif cam then + put(out, 1, "*CAMERA_SETTINGS {") + put(out, 2, "*TIMEVALUE 0") + put(out, 2, "*CAMERA_NEAR " .. f(cam.znear or 0)) + put(out, 2, "*CAMERA_FAR " .. f(cam.zfar or 1000)) + put(out, 2, "*CAMERA_FOV " .. f(cam.yfov or math.rad(45))) + put(out, 2, "*CAMERA_TDIST 100.0000") + put(out, 1, "}") + elseif li then + local c = (type(li.color) == "table" and{li.color }or{{ 1, 1, 1 } +})[1] put(out, 1, "*LIGHT_SETTINGS {") + put(out, 2, "*TIMEVALUE 0") + put(out, 2, "*LIGHT_COLOR " .. f(c[1] or 1) .. "\t" .. f(c[2] or 1) .. "\t" .. f(c[3] or 1)) + put(out, 2, "*LIGHT_INTENS " .. f(li.intensity or 1)) + put(out, 2, "*LIGHT_HOTSPOT " .. f(math.deg(li.innerCone or 0) * 2)) + put(out, 2, "*LIGHT_FALLOFF " .. f(math.deg(li.outerCone or math.pi / 4) * 2)) + put(out, 1, "}") + end + put(out, 0, "}") + end + return table.concat(out.lines, "\n") .. "\n", nil +end + return Write end __FILES["model/b3d"] = function() diff --git a/build/rosetta.lua.linemap.json b/build/rosetta.lua.linemap.json index 45c4801..23ac1bb 100644 --- a/build/rosetta.lua.linemap.json +++ b/build/rosetta.lua.linemap.json @@ -1,539 +1,544 @@ [ [660, "src/Rosetta/init.luau"], [1504, "src/Rosetta/Registry.luau"], -[3613, "src/Rosetta/Types.luau"], -[4696, "src/Rosetta/archive/7z/init.luau"], -[5081, "src/Rosetta/archive/7z/Header.luau"], -[5608, "src/Rosetta/archive/adf/init.luau"], -[5890, "src/Rosetta/archive/applesingle/init.luau"], -[6076, "src/Rosetta/archive/ar/init.luau"], -[6479, "src/Rosetta/archive/arj/init.luau"], -[6689, "src/Rosetta/archive/binhex/init.luau"], -[6938, "src/Rosetta/archive/br/init.luau"], -[7013, "src/Rosetta/archive/bz2/init.luau"], -[7077, "src/Rosetta/archive/cab/init.luau"], -[7490, "src/Rosetta/archive/cab/Sum.luau"], -[7531, "src/Rosetta/archive/cpio/init.luau"], -[7699, "src/Rosetta/archive/d64/init.luau"], -[8113, "src/Rosetta/archive/fat/init.luau"], -[8235, "src/Rosetta/archive/grp/init.luau"], -[8349, "src/Rosetta/archive/gzip/init.luau"], -[8534, "src/Rosetta/archive/iso/init.luau"], -[8606, "src/Rosetta/archive/lha/init.luau"], -[9031, "src/Rosetta/archive/lz4/init.luau"], -[9375, "src/Rosetta/archive/macbinary/init.luau"], -[9573, "src/Rosetta/archive/mpq/init.luau"], -[9979, "src/Rosetta/archive/mpq/Crypt.luau"], -[10044, "src/Rosetta/archive/pak/init.luau"], -[10178, "src/Rosetta/archive/rpm/init.luau"], -[10502, "src/Rosetta/archive/tar/init.luau"], -[10620, "src/Rosetta/archive/uu/init.luau"], -[10890, "src/Rosetta/archive/vpk/init.luau"], -[11201, "src/Rosetta/archive/wad/init.luau"], -[11651, "src/Rosetta/archive/wad/Map.luau"], -[12081, "src/Rosetta/archive/wad/Picture.luau"], -[12183, "src/Rosetta/archive/xz/init.luau"], -[12283, "src/Rosetta/archive/yenc/init.luau"], -[12555, "src/Rosetta/archive/z/init.luau"], -[12651, "src/Rosetta/archive/zip/init.luau"], -[12870, "src/Rosetta/archive/zoo/init.luau"], -[13066, "src/Rosetta/archive/zst/init.luau"], -[13130, "src/Rosetta/audio/aac/init.luau"], -[13336, "src/Rosetta/audio/ac3/init.luau"], -[13482, "src/Rosetta/audio/adpcm/init.luau"], -[13627, "src/Rosetta/audio/adx/init.luau"], -[13858, "src/Rosetta/audio/aiff/init.luau"], -[14249, "src/Rosetta/audio/ape/init.luau"], -[14377, "src/Rosetta/audio/au/init.luau"], -[14538, "src/Rosetta/audio/brstm/init.luau"], -[14829, "src/Rosetta/audio/caf/init.luau"], -[15491, "src/Rosetta/audio/flac/init.luau"], -[15639, "src/Rosetta/audio/flac/Meta.luau"], -[15861, "src/Rosetta/audio/flac/Stream.luau"], -[16231, "src/Rosetta/audio/m4a/init.luau"], -[16565, "src/Rosetta/audio/mp3/init.luau"], -[16825, "src/Rosetta/audio/mp3/Index.luau"], -[17016, "src/Rosetta/audio/mp3/Stream.luau"], -[17243, "src/Rosetta/audio/mp3/Tags.luau"], -[17555, "src/Rosetta/audio/mpc/init.luau"], -[17649, "src/Rosetta/audio/opus/init.luau"], -[18027, "src/Rosetta/audio/opus/Encode.luau"], -[18138, "src/Rosetta/audio/qoa/init.luau"], -[18318, "src/Rosetta/audio/tta/init.luau"], -[18436, "src/Rosetta/audio/vag/init.luau"], -[18659, "src/Rosetta/audio/voc/init.luau"], -[18934, "src/Rosetta/audio/vorbis/init.luau"], -[19388, "src/Rosetta/audio/vorbis/Encode.luau"], -[20201, "src/Rosetta/audio/wav/init.luau"], -[20822, "src/Rosetta/audio/wav/Codecs.luau"], -[20988, "src/Rosetta/audio/wavpack/init.luau"], -[21195, "src/Rosetta/cad/step/init.luau"], -[21577, "src/Rosetta/cad/step/Brep.luau"], -[21812, "src/Rosetta/cad/step/Parse.luau"], -[22369, "src/Rosetta/cad/step/Write.luau"], -[22617, "src/Rosetta/codecs/audio/Aac/init.luau"], -[22936, "src/Rosetta/codecs/audio/Aac/Decode.luau"], -[23819, "src/Rosetta/codecs/audio/Aac/Tables.luau"], -[24154, "src/Rosetta/codecs/audio/Ac3/init.luau"], -[24313, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], -[25198, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], -[25299, "src/Rosetta/codecs/audio/Adpcm/init.luau"], -[26053, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], -[26355, "src/Rosetta/codecs/audio/Alac/init.luau"], -[26589, "src/Rosetta/codecs/audio/Alac/Decode.luau"], -[27008, "src/Rosetta/codecs/audio/Alac/Encode.luau"], -[27420, "src/Rosetta/codecs/audio/Ape/init.luau"], -[27635, "src/Rosetta/codecs/audio/Ape/Decode.luau"], -[28396, "src/Rosetta/codecs/audio/ApeTag.luau"], -[28493, "src/Rosetta/codecs/audio/Flac/init.luau"], -[28504, "src/Rosetta/codecs/audio/Flac/Encode.luau"], -[29453, "src/Rosetta/codecs/audio/Flac/Frame.luau"], -[30050, "src/Rosetta/codecs/audio/Hively/init.luau"], -[30246, "src/Rosetta/codecs/audio/Hively/Load.luau"], -[30495, "src/Rosetta/codecs/audio/Hively/Player.luau"], -[31453, "src/Rosetta/codecs/audio/Hively/Tables.luau"], -[31672, "src/Rosetta/codecs/audio/Mdct/init.luau"], -[31856, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], -[32065, "src/Rosetta/codecs/audio/MidiRender.luau"], -[32411, "src/Rosetta/codecs/audio/Mpa/init.luau"], -[32425, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], -[32484, "src/Rosetta/codecs/audio/Mpa/Core.luau"], -[34087, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], -[34379, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], -[34764, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], -[35405, "src/Rosetta/codecs/audio/Mpa/Header.luau"], -[35546, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], -[35772, "src/Rosetta/codecs/audio/Musepack/init.luau"], -[36117, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], -[36998, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], -[37376, "src/Rosetta/codecs/audio/Opus/init.luau"], -[37390, "src/Rosetta/codecs/audio/Opus/Celt.luau"], -[39237, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], -[40302, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], -[40362, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], -[40822, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], -[41159, "src/Rosetta/codecs/audio/Opus/Packet.luau"], -[41392, "src/Rosetta/codecs/audio/Opus/Silk.luau"], -[43428, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], -[43802, "src/Rosetta/codecs/audio/Pcm/init.luau"], -[44065, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], -[44362, "src/Rosetta/codecs/audio/Qoa/init.luau"], -[44644, "src/Rosetta/codecs/audio/Resample/init.luau"], -[45003, "src/Rosetta/codecs/audio/SoundFont/init.luau"], -[45057, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], -[45200, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], -[45713, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], -[46494, "src/Rosetta/codecs/audio/Stream.luau"], -[46655, "src/Rosetta/codecs/audio/Tracker/init.luau"], -[47137, "src/Rosetta/codecs/audio/Tracker/Load.luau"], -[47415, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], -[47584, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], -[47712, "src/Rosetta/codecs/audio/Tracker/Player.luau"], -[49700, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], -[49816, "src/Rosetta/codecs/audio/Tta/init.luau"], -[49933, "src/Rosetta/codecs/audio/Tta/Decode.luau"], -[50185, "src/Rosetta/codecs/audio/Vorbis/init.luau"], -[50198, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], -[50582, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], -[51148, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], -[51569, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], -[51608, "src/Rosetta/codecs/audio/VorbisComment.luau"], -[51660, "src/Rosetta/codecs/audio/WavPack/init.luau"], -[51882, "src/Rosetta/codecs/audio/WavPack/Block.luau"], -[53337, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], -[53400, "src/Rosetta/codecs/compress/Brotli/init.luau"], -[53487, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], -[54456, "src/Rosetta/codecs/compress/Brotli/Static.luau"], -[55324, "src/Rosetta/codecs/compress/Bzip2/init.luau"], -[55372, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], -[55888, "src/Rosetta/codecs/compress/Deflate/init.luau"], -[56214, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], -[56634, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], -[57069, "src/Rosetta/codecs/compress/Explode.luau"], -[57265, "src/Rosetta/codecs/compress/Lz4.luau"], -[57534, "src/Rosetta/codecs/compress/Lzh/init.luau"], -[58138, "src/Rosetta/codecs/compress/Lzma/init.luau"], -[58678, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], -[58716, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], -[59189, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], -[59365, "src/Rosetta/codecs/compress/Lzw/init.luau"], -[59633, "src/Rosetta/codecs/compress/Lzx.luau"], -[60067, "src/Rosetta/codecs/compress/PackBits.luau"], -[60157, "src/Rosetta/codecs/compress/Quantum.luau"], -[60394, "src/Rosetta/codecs/compress/UnixCompress.luau"], -[60698, "src/Rosetta/codecs/compress/Xxh32.luau"], -[60767, "src/Rosetta/codecs/compress/Zstd/init.luau"], -[60824, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], -[61782, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], -[61934, "src/Rosetta/codecs/entropy/Huffman.luau"], -[62216, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], -[62227, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], -[62441, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], -[62685, "src/Rosetta/codecs/font/Bitmap.luau"], -[62886, "src/Rosetta/codecs/font/Cff/init.luau"], -[63527, "src/Rosetta/codecs/font/GlyphNames.luau"], -[63677, "src/Rosetta/codecs/font/TrueType/init.luau"], -[63991, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], -[64383, "src/Rosetta/codecs/font/TrueType/Tables.luau"], -[64885, "src/Rosetta/codecs/image/Bcn/init.luau"], -[64992, "src/Rosetta/codecs/image/Bcn/Decode.luau"], -[65481, "src/Rosetta/codecs/image/Bcn/Encode.luau"], -[65910, "src/Rosetta/codecs/image/Blend.luau"], -[66289, "src/Rosetta/codecs/image/Dct/init.luau"], -[66670, "src/Rosetta/codecs/image/Etc.luau"], -[66968, "src/Rosetta/codecs/image/Half.luau"], -[67037, "src/Rosetta/codecs/image/Jpeg/init.luau"], -[67391, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], -[67799, "src/Rosetta/codecs/image/Jpeg/Color.luau"], -[68036, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], -[68796, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], -[69677, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], -[70123, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], -[70201, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], -[70268, "src/Rosetta/codecs/image/Pixels.luau"], -[70532, "src/Rosetta/codecs/image/Quantize/init.luau"], -[70991, "src/Rosetta/codecs/image/Raster.luau"], -[71688, "src/Rosetta/codecs/image/Texel.luau"], -[72061, "src/Rosetta/codecs/image/Texture.luau"], -[72206, "src/Rosetta/codecs/image/Vp8/init.luau"], -[72336, "src/Rosetta/codecs/image/Vp8/Decode.luau"], -[74292, "src/Rosetta/codecs/image/Vp8/Predict.luau"], -[74551, "src/Rosetta/codecs/image/Vp8/Tables.luau"], -[74800, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], -[74919, "src/Rosetta/codecs/image/Vp8L/init.luau"], -[75023, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], -[75876, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], -[76828, "src/Rosetta/codecs/image/Yuv.luau"], -[77096, "src/Rosetta/codecs/model/Draco/init.luau"], -[77428, "src/Rosetta/codecs/model/Draco/Attributes.luau"], -[77897, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], -[79086, "src/Rosetta/codecs/model/Draco/Int64.luau"], -[79235, "src/Rosetta/codecs/model/Draco/KdTree.luau"], -[79594, "src/Rosetta/codecs/model/Draco/Predict.luau"], -[80556, "src/Rosetta/codecs/model/Draco/Reader.luau"], -[81030, "src/Rosetta/codecs/model/Mat4.luau"], -[81289, "src/Rosetta/codecs/model/MeshFlatten.luau"], -[81817, "src/Rosetta/codecs/model/Minecraft/init.luau"], -[82369, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], -[82448, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], -[82555, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], -[82761, "src/Rosetta/codecs/model/Polygon.luau"], -[82995, "src/Rosetta/codecs/model/Rbx/init.luau"], -[83232, "src/Rosetta/codecs/model/Rbx/Binary.luau"], -[83986, "src/Rosetta/codecs/model/Rig.luau"], -[84229, "src/Rosetta/codecs/model/Sampler.luau"], -[84389, "src/Rosetta/codecs/model/Vrml/init.luau"], -[84537, "src/Rosetta/codecs/model/Vrml/Build.luau"], -[85111, "src/Rosetta/codecs/model/Vrml/Fields.luau"], -[85274, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], -[86023, "src/Rosetta/codecs/model/Vrml/Parse.luau"], -[86545, "src/Rosetta/codecs/model/Vrml/Write.luau"], -[87272, "src/Rosetta/codecs/model/Vrml/Xml.luau"], -[87504, "src/Rosetta/codecs/text/Json/init.luau"], -[87773, "src/Rosetta/codecs/text/Json/Decode.luau"], -[88187, "src/Rosetta/codecs/text/Json/Encode.luau"], -[88489, "src/Rosetta/codecs/text/Nbt/init.luau"], -[88842, "src/Rosetta/codecs/text/Nbt/Binary.luau"], -[89534, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], -[90174, "src/Rosetta/codecs/text/Nbt/Value.luau"], -[90412, "src/Rosetta/codecs/text/Text/init.luau"], -[90503, "src/Rosetta/codecs/text/Url/init.luau"], -[90708, "src/Rosetta/codecs/text/Xml/init.luau"], -[91111, "src/Rosetta/codecs/text/Xml/Parse.luau"], -[91851, "src/Rosetta/codecs/video/Dsp.luau"], -[92574, "src/Rosetta/codecs/video/H263/init.luau"], -[92730, "src/Rosetta/codecs/video/H263/Decoder.luau"], -[93588, "src/Rosetta/codecs/video/H263/Tables.luau"], -[93791, "src/Rosetta/codecs/video/H264/init.luau"], -[94164, "src/Rosetta/codecs/video/H264/Bitstream.luau"], -[94439, "src/Rosetta/codecs/video/H264/Cabac.luau"], -[95570, "src/Rosetta/codecs/video/H264/Cavlc.luau"], -[96338, "src/Rosetta/codecs/video/H264/Deblock.luau"], -[96596, "src/Rosetta/codecs/video/H264/Decoder.luau"], -[97605, "src/Rosetta/codecs/video/H264/Inter.luau"], -[97859, "src/Rosetta/codecs/video/H264/Intra.luau"], -[98266, "src/Rosetta/codecs/video/H264/Mb.luau"], -[99172, "src/Rosetta/codecs/video/H264/Params.luau"], -[99619, "src/Rosetta/codecs/video/H264/Slice.luau"], -[99870, "src/Rosetta/codecs/video/H264/Tables.luau"], -[99911, "src/Rosetta/codecs/video/H264/Transform.luau"], -[100076, "src/Rosetta/codecs/video/Legacy/init.luau"], -[100274, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], -[100571, "src/Rosetta/codecs/video/Legacy/Flic.luau"], -[100938, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], -[101056, "src/Rosetta/codecs/video/Legacy/Picture.luau"], -[101164, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], -[101437, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], -[101832, "src/Rosetta/codecs/video/Legacy/Smc.luau"], -[102009, "src/Rosetta/codecs/video/Mpeg1/init.luau"], -[102021, "src/Rosetta/codecs/video/Mpeg2/init.luau"], -[102388, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], -[103895, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], -[104034, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], -[104172, "src/Rosetta/codecs/video/Theora/init.luau"], -[104435, "src/Rosetta/codecs/video/Theora/Decoder.luau"], -[105699, "src/Rosetta/codecs/video/Theora/Header.luau"], -[106062, "src/Rosetta/codecs/video/Video/init.luau"], -[106619, "src/Rosetta/codecs/video/Video/Source.luau"], -[106904, "src/Rosetta/containers/Archive.luau"], -[107171, "src/Rosetta/containers/AudioWrap.luau"], -[107674, "src/Rosetta/containers/Avi/init.luau"], -[108226, "src/Rosetta/containers/Chunks.luau"], -[108361, "src/Rosetta/containers/Cpio.luau"], -[108789, "src/Rosetta/containers/Demux.luau"], -[109064, "src/Rosetta/containers/Ebml/init.luau"], -[109377, "src/Rosetta/containers/Fat.luau"], -[110065, "src/Rosetta/containers/Iso9660.luau"], -[110570, "src/Rosetta/containers/IsoBmff/init.luau"], -[110740, "src/Rosetta/containers/IsoBmff/Box.luau"], -[110928, "src/Rosetta/containers/IsoBmff/Demux.luau"], -[111773, "src/Rosetta/containers/IsoBmff/Meta.luau"], -[112294, "src/Rosetta/containers/IsoBmff/Mux.luau"], -[112810, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], -[112927, "src/Rosetta/containers/MacFile.luau"], -[113076, "src/Rosetta/containers/MpegEs.luau"], -[113242, "src/Rosetta/containers/MpegPs/init.luau"], -[113462, "src/Rosetta/containers/MpegTs/init.luau"], -[114254, "src/Rosetta/containers/Ogg/init.luau"], -[114679, "src/Rosetta/containers/Ogg/Mux.luau"], -[114874, "src/Rosetta/containers/Ogg/Page.luau"], -[115043, "src/Rosetta/containers/Riff/init.luau"], -[115360, "src/Rosetta/containers/Tar.luau"], -[115774, "src/Rosetta/containers/Zip/init.luau"], -[116406, "src/Rosetta/core/Adler32.luau"], -[116452, "src/Rosetta/core/Base64.luau"], -[116611, "src/Rosetta/core/Bits.luau"], -[116904, "src/Rosetta/core/Bytes.luau"], -[117431, "src/Rosetta/core/Crc16.luau"], -[117483, "src/Rosetta/core/Crc32.luau"], -[117595, "src/Rosetta/core/Err.luau"], -[117677, "src/Rosetta/core/Input.luau"], -[117753, "src/Rosetta/core/Md5.luau"], -[117912, "src/Rosetta/core/Sniff.luau"], -[117941, "src/Rosetta/data/cbor/init.luau"], -[118040, "src/Rosetta/data/cbor/Codec.luau"], -[118609, "src/Rosetta/data/csv/init.luau"], -[118921, "src/Rosetta/data/ini/init.luau"], -[119167, "src/Rosetta/data/json/init.luau"], -[119259, "src/Rosetta/data/msgpack/init.luau"], -[119348, "src/Rosetta/data/msgpack/Codec.luau"], -[119790, "src/Rosetta/data/nbt/init.luau"], -[119849, "src/Rosetta/data/plist/init.luau"], -[120155, "src/Rosetta/data/plist/Binary.luau"], -[120422, "src/Rosetta/data/snbt/init.luau"], -[120485, "src/Rosetta/data/toml/init.luau"], -[120552, "src/Rosetta/data/toml/Decode.luau"], -[121180, "src/Rosetta/data/toml/Encode.luau"], -[121389, "src/Rosetta/data/xml/init.luau"], -[121445, "src/Rosetta/data/yaml/init.luau"], -[121518, "src/Rosetta/data/yaml/Emit.luau"], -[121808, "src/Rosetta/data/yaml/Parse.luau"], -[123101, "src/Rosetta/font/bdf/init.luau"], -[123390, "src/Rosetta/font/bmfont/init.luau"], -[123817, "src/Rosetta/font/bmfont/Parse.luau"], -[124270, "src/Rosetta/font/eot/init.luau"], -[124502, "src/Rosetta/font/fon/init.luau"], -[124785, "src/Rosetta/font/hershey/init.luau"], -[124980, "src/Rosetta/font/pcf/init.luau"], -[125260, "src/Rosetta/font/psf/init.luau"], -[125580, "src/Rosetta/font/ttf/init.luau"], -[125631, "src/Rosetta/font/type1/init.luau"], -[125990, "src/Rosetta/font/type1/Charstring.luau"], -[126268, "src/Rosetta/font/woff/init.luau"], -[126400, "src/Rosetta/font/woff2/init.luau"], -[126457, "src/Rosetta/font/woff2/Rebuild.luau"], -[126997, "src/Rosetta/host/init.luau"], -[127042, "src/Rosetta/host/Love.luau"], -[127185, "src/Rosetta/host/LuaJIT.luau"], -[127235, "src/Rosetta/host/Luau.luau"], -[127258, "src/Rosetta/host/Roblox.luau"], -[127617, "src/Rosetta/image/ani/init.luau"], -[127797, "src/Rosetta/image/blp/init.luau"], -[128055, "src/Rosetta/image/bmp/init.luau"], -[128470, "src/Rosetta/image/dds/init.luau"], -[128953, "src/Rosetta/image/exr/init.luau"], -[129713, "src/Rosetta/image/exr/Codec.luau"], -[129824, "src/Rosetta/image/exr/Piz.luau"], -[130181, "src/Rosetta/image/gif/init.luau"], -[130697, "src/Rosetta/image/gif/Decode.luau"], -[130760, "src/Rosetta/image/hdr/init.luau"], -[130989, "src/Rosetta/image/hdr/Codec.luau"], -[131200, "src/Rosetta/image/icns/init.luau"], -[131531, "src/Rosetta/image/ico/init.luau"], -[131808, "src/Rosetta/image/ico/Dib.luau"], -[131903, "src/Rosetta/image/ilbm/init.luau"], -[132222, "src/Rosetta/image/jpeg/init.luau"], -[132358, "src/Rosetta/image/ktx/init.luau"], -[133018, "src/Rosetta/image/pcx/init.luau"], -[133282, "src/Rosetta/image/png/init.luau"], -[133862, "src/Rosetta/image/png/Apng.luau"], -[133942, "src/Rosetta/image/png/Decode.luau"], -[134182, "src/Rosetta/image/png/Encode.luau"], -[134337, "src/Rosetta/image/pnm/init.luau"], -[134715, "src/Rosetta/image/pnm/Codec.luau"], -[134992, "src/Rosetta/image/qoi/init.luau"], -[135114, "src/Rosetta/image/qoi/Codec.luau"], -[135264, "src/Rosetta/image/sgi/init.luau"], -[135549, "src/Rosetta/image/sunras/init.luau"], -[135795, "src/Rosetta/image/tga/init.luau"], -[136065, "src/Rosetta/image/tga/Codec.luau"], -[136217, "src/Rosetta/image/tiff/init.luau"], -[137044, "src/Rosetta/image/tiff/Pixels.luau"], -[137434, "src/Rosetta/image/tim/init.luau"], -[137676, "src/Rosetta/image/vtf/init.luau"], -[137911, "src/Rosetta/image/webp/init.luau"], -[138521, "src/Rosetta/image/webp/Alpha.luau"], -[138597, "src/Rosetta/image/webp/Anim.luau"], -[138752, "src/Rosetta/image/xbm/init.luau"], -[138913, "src/Rosetta/image/xpm/init.luau"], -[139181, "src/Rosetta/image/xpm/Names.luau"], -[139237, "src/Rosetta/layered/aseprite/init.luau"], -[139975, "src/Rosetta/layered/ora/init.luau"], -[140262, "src/Rosetta/layered/psd/init.luau"], -[140997, "src/Rosetta/layered/psd/Channels.luau"], -[141349, "src/Rosetta/model/3ds/init.luau"], -[141432, "src/Rosetta/model/3ds/Build.luau"], -[142079, "src/Rosetta/model/3ds/Read.luau"], -[142575, "src/Rosetta/model/3ds/Write.luau"], -[143380, "src/Rosetta/model/3mf/init.luau"], -[143462, "src/Rosetta/model/3mf/Read.luau"], -[144050, "src/Rosetta/model/3mf/Write.luau"], -[144455, "src/Rosetta/model/b3d/init.luau"], -[144510, "src/Rosetta/model/b3d/Read.luau"], -[145081, "src/Rosetta/model/bsp/init.luau"], -[145226, "src/Rosetta/model/bsp/Brush.luau"], -[145504, "src/Rosetta/model/bsp/Quake3.luau"], -[145759, "src/Rosetta/model/dae/init.luau"], -[145948, "src/Rosetta/model/dae/Math.luau"], -[145995, "src/Rosetta/model/dae/Read.luau"], -[147845, "src/Rosetta/model/dae/Write.luau"], -[148214, "src/Rosetta/model/fbx/init.luau"], -[148362, "src/Rosetta/model/fbx/Ascii.luau"], -[148632, "src/Rosetta/model/fbx/Binary.luau"], -[149087, "src/Rosetta/model/fbx/Read.luau"], -[150449, "src/Rosetta/model/fbx/Write.luau"], -[151434, "src/Rosetta/model/fbx/Xform.luau"], -[151475, "src/Rosetta/model/gltf/init.luau"], -[151712, "src/Rosetta/model/gltf/Pack.luau"], -[151781, "src/Rosetta/model/gltf/Read.luau"], -[152512, "src/Rosetta/model/gltf/Write.luau"], -[153192, "src/Rosetta/model/iqm/init.luau"], -[153268, "src/Rosetta/model/iqm/Read.luau"], -[153623, "src/Rosetta/model/iqm/Write.luau"], -[154310, "src/Rosetta/model/ldraw/init.luau"], -[154388, "src/Rosetta/model/ldraw/Colors.luau"], -[154706, "src/Rosetta/model/ldraw/Read.luau"], -[155283, "src/Rosetta/model/lwo/init.luau"], -[155359, "src/Rosetta/model/lwo/Build.luau"], -[155821, "src/Rosetta/model/lwo/Parse.luau"], -[156364, "src/Rosetta/model/mca/init.luau"], -[156706, "src/Rosetta/model/mca/Chunk.luau"], -[156839, "src/Rosetta/model/mca/Lz4Block.luau"], -[156909, "src/Rosetta/model/md2/init.luau"], -[157108, "src/Rosetta/model/md3/init.luau"], -[157336, "src/Rosetta/model/md5/init.luau"], -[157417, "src/Rosetta/model/md5/Read.luau"], -[157850, "src/Rosetta/model/mdl/init.luau"], -[157932, "src/Rosetta/model/mdl/HalfLife.luau"], -[158260, "src/Rosetta/model/mdl/Quake.luau"], -[158478, "src/Rosetta/model/ms3d/init.luau"], -[158550, "src/Rosetta/model/ms3d/Read.luau"], -[158996, "src/Rosetta/model/ms3d/Write.luau"], -[159465, "src/Rosetta/model/obj/init.luau"], -[160207, "src/Rosetta/model/obj/Mtl.luau"], -[160494, "src/Rosetta/model/off/init.luau"], -[160956, "src/Rosetta/model/ply/init.luau"], -[162061, "src/Rosetta/model/ply/Binary.luau"], -[162262, "src/Rosetta/model/pmx/init.luau"], -[162331, "src/Rosetta/model/pmx/Build.luau"], -[162627, "src/Rosetta/model/pmx/Pmd.luau"], -[162962, "src/Rosetta/model/pmx/Read.luau"], -[163366, "src/Rosetta/model/qb/init.luau"], -[163759, "src/Rosetta/model/rbxm/init.luau"], -[164351, "src/Rosetta/model/rbxmx/init.luau"], -[165004, "src/Rosetta/model/robloxmesh/init.luau"], -[165663, "src/Rosetta/model/robloxmesh/Parse.luau"], -[166120, "src/Rosetta/model/robloxmesh/Write.luau"], -[166229, "src/Rosetta/model/schematic/init.luau"], -[166550, "src/Rosetta/model/schematic/Common.luau"], -[166670, "src/Rosetta/model/schematic/Litematic.luau"], -[166881, "src/Rosetta/model/schematic/Mcedit.luau"], -[167125, "src/Rosetta/model/schematic/Sponge.luau"], -[167254, "src/Rosetta/model/smd/init.luau"], -[167321, "src/Rosetta/model/smd/Read.luau"], -[167590, "src/Rosetta/model/smd/Write.luau"], -[167833, "src/Rosetta/model/stl/init.luau"], -[168283, "src/Rosetta/model/stl/Decode.luau"], -[168357, "src/Rosetta/model/usda/init.luau"], -[168566, "src/Rosetta/model/usda/Build.luau"], -[169844, "src/Rosetta/model/usda/Parse.luau"], -[170642, "src/Rosetta/model/usda/Write.luau"], -[171459, "src/Rosetta/model/vox/init.luau"], -[172345, "src/Rosetta/model/vox/Grid.luau"], -[172402, "src/Rosetta/model/vrml/init.luau"], -[172468, "src/Rosetta/model/x/init.luau"], -[172598, "src/Rosetta/model/x/Build.luau"], -[173161, "src/Rosetta/model/x/Parse.luau"], -[173458, "src/Rosetta/model/x3d/init.luau"], -[173536, "src/Rosetta/music/669/init.luau"], -[173742, "src/Rosetta/music/ahx/init.luau"], -[173793, "src/Rosetta/music/far/init.luau"], -[174022, "src/Rosetta/music/hmp/init.luau"], -[174286, "src/Rosetta/music/hvl/init.luau"], -[174337, "src/Rosetta/music/it/init.luau"], -[174755, "src/Rosetta/music/it/Itsex.luau"], -[174871, "src/Rosetta/music/med/init.luau"], -[175518, "src/Rosetta/music/midi/init.luau"], -[175661, "src/Rosetta/music/midi/Smf.luau"], -[176072, "src/Rosetta/music/mod/init.luau"], -[176425, "src/Rosetta/music/mtm/init.luau"], -[176647, "src/Rosetta/music/mus/init.luau"], -[176804, "src/Rosetta/music/okt/init.luau"], -[177085, "src/Rosetta/music/ptm/init.luau"], -[177307, "src/Rosetta/music/s3m/init.luau"], -[177543, "src/Rosetta/music/sf2/init.luau"], -[177586, "src/Rosetta/music/stm/init.luau"], -[177817, "src/Rosetta/music/ult/init.luau"], -[178121, "src/Rosetta/music/umx/init.luau"], -[178337, "src/Rosetta/music/xm/init.luau"], -[178898, "src/Rosetta/music/xmi/init.luau"], -[179106, "src/Rosetta/ops/AudioOps.luau"], -[179555, "src/Rosetta/ops/ImageOps/init.luau"], -[180199, "src/Rosetta/ops/ImageOps/Kernels.luau"], -[180709, "src/Rosetta/ops/LayerOps.luau"], -[180802, "src/Rosetta/ops/MeshOps/init.luau"], -[181838, "src/Rosetta/ops/MeshOps/Greedy.luau"], -[182005, "src/Rosetta/ops/MusicOps.luau"], -[182353, "src/Rosetta/playlist/m3u/init.luau"], -[182706, "src/Rosetta/playlist/pls/init.luau"], -[182884, "src/Rosetta/playlist/xspf/init.luau"], -[183087, "src/Rosetta/subtitle/ass/init.luau"], -[183531, "src/Rosetta/subtitle/srt/init.luau"], -[183704, "src/Rosetta/subtitle/vtt/init.luau"], -[183907, "src/Rosetta/vector/svg/init.luau"], -[183993, "src/Rosetta/vector/svg/Parse.luau"], -[184739, "src/Rosetta/vector/svg/PathData.luau"], -[185107, "src/Rosetta/vector/svg/Render.luau"], -[185524, "src/Rosetta/vector/svg/Style.luau"], -[185896, "src/Rosetta/vector/svg/Write.luau"], -[186096, "src/Rosetta/vector/tiled/init.luau"], -[186276, "src/Rosetta/vector/tiled/Data.luau"], -[186427, "src/Rosetta/vector/tiled/Tmj.luau"], -[187058, "src/Rosetta/vector/tiled/Tmx.luau"], -[187670, "src/Rosetta/video/avi/init.luau"], -[187964, "src/Rosetta/video/fli/init.luau"], -[188115, "src/Rosetta/video/flv/init.luau"], -[188499, "src/Rosetta/video/flv/Amf.luau"], -[188657, "src/Rosetta/video/flv/Mux.luau"], -[188938, "src/Rosetta/video/h264/init.luau"], -[189077, "src/Rosetta/video/mkv/init.luau"], -[189233, "src/Rosetta/video/mkv/Mux.luau"], -[189512, "src/Rosetta/video/mkv/Parse.luau"], -[190233, "src/Rosetta/video/mp4/init.luau"], -[190561, "src/Rosetta/video/mpegps/init.luau"], -[190748, "src/Rosetta/video/mpegts/init.luau"], -[190986, "src/Rosetta/video/ogv/init.luau"], -[191381, "src/Rosetta/video/smk/init.luau"], -[191690, "src/Rosetta/video/smk/Audio.luau"], -[191810, "src/Rosetta/video/y4m/init.luau"] +[3637, "src/Rosetta/Types.luau"], +[4720, "src/Rosetta/archive/7z/init.luau"], +[5105, "src/Rosetta/archive/7z/Header.luau"], +[5632, "src/Rosetta/archive/adf/init.luau"], +[5914, "src/Rosetta/archive/applesingle/init.luau"], +[6100, "src/Rosetta/archive/ar/init.luau"], +[6503, "src/Rosetta/archive/arj/init.luau"], +[6713, "src/Rosetta/archive/binhex/init.luau"], +[6962, "src/Rosetta/archive/br/init.luau"], +[7037, "src/Rosetta/archive/bz2/init.luau"], +[7101, "src/Rosetta/archive/cab/init.luau"], +[7514, "src/Rosetta/archive/cab/Sum.luau"], +[7555, "src/Rosetta/archive/cpio/init.luau"], +[7723, "src/Rosetta/archive/d64/init.luau"], +[8137, "src/Rosetta/archive/fat/init.luau"], +[8259, "src/Rosetta/archive/grp/init.luau"], +[8373, "src/Rosetta/archive/gzip/init.luau"], +[8558, "src/Rosetta/archive/iso/init.luau"], +[8630, "src/Rosetta/archive/lha/init.luau"], +[9055, "src/Rosetta/archive/lz4/init.luau"], +[9399, "src/Rosetta/archive/macbinary/init.luau"], +[9597, "src/Rosetta/archive/mpq/init.luau"], +[10003, "src/Rosetta/archive/mpq/Crypt.luau"], +[10068, "src/Rosetta/archive/pak/init.luau"], +[10202, "src/Rosetta/archive/rpm/init.luau"], +[10526, "src/Rosetta/archive/tar/init.luau"], +[10644, "src/Rosetta/archive/unitypackage/init.luau"], +[10881, "src/Rosetta/archive/uu/init.luau"], +[11151, "src/Rosetta/archive/vpk/init.luau"], +[11462, "src/Rosetta/archive/wad/init.luau"], +[11912, "src/Rosetta/archive/wad/Map.luau"], +[12342, "src/Rosetta/archive/wad/Picture.luau"], +[12444, "src/Rosetta/archive/xz/init.luau"], +[12544, "src/Rosetta/archive/yenc/init.luau"], +[12816, "src/Rosetta/archive/z/init.luau"], +[12912, "src/Rosetta/archive/zip/init.luau"], +[13131, "src/Rosetta/archive/zoo/init.luau"], +[13327, "src/Rosetta/archive/zst/init.luau"], +[13391, "src/Rosetta/audio/aac/init.luau"], +[13597, "src/Rosetta/audio/ac3/init.luau"], +[13743, "src/Rosetta/audio/adpcm/init.luau"], +[13888, "src/Rosetta/audio/adx/init.luau"], +[14119, "src/Rosetta/audio/aiff/init.luau"], +[14510, "src/Rosetta/audio/ape/init.luau"], +[14638, "src/Rosetta/audio/au/init.luau"], +[14799, "src/Rosetta/audio/brstm/init.luau"], +[15090, "src/Rosetta/audio/caf/init.luau"], +[15752, "src/Rosetta/audio/flac/init.luau"], +[15900, "src/Rosetta/audio/flac/Meta.luau"], +[16122, "src/Rosetta/audio/flac/Stream.luau"], +[16492, "src/Rosetta/audio/m4a/init.luau"], +[16826, "src/Rosetta/audio/mp3/init.luau"], +[17086, "src/Rosetta/audio/mp3/Index.luau"], +[17277, "src/Rosetta/audio/mp3/Stream.luau"], +[17504, "src/Rosetta/audio/mp3/Tags.luau"], +[17816, "src/Rosetta/audio/mpc/init.luau"], +[17910, "src/Rosetta/audio/opus/init.luau"], +[18288, "src/Rosetta/audio/opus/Encode.luau"], +[18399, "src/Rosetta/audio/qoa/init.luau"], +[18579, "src/Rosetta/audio/tta/init.luau"], +[18697, "src/Rosetta/audio/vag/init.luau"], +[18920, "src/Rosetta/audio/voc/init.luau"], +[19195, "src/Rosetta/audio/vorbis/init.luau"], +[19649, "src/Rosetta/audio/vorbis/Encode.luau"], +[20462, "src/Rosetta/audio/wav/init.luau"], +[21083, "src/Rosetta/audio/wav/Codecs.luau"], +[21249, "src/Rosetta/audio/wavpack/init.luau"], +[21456, "src/Rosetta/cad/step/init.luau"], +[21838, "src/Rosetta/cad/step/Brep.luau"], +[22073, "src/Rosetta/cad/step/Parse.luau"], +[22630, "src/Rosetta/cad/step/Write.luau"], +[22878, "src/Rosetta/codecs/audio/Aac/init.luau"], +[23197, "src/Rosetta/codecs/audio/Aac/Decode.luau"], +[24080, "src/Rosetta/codecs/audio/Aac/Tables.luau"], +[24415, "src/Rosetta/codecs/audio/Ac3/init.luau"], +[24574, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], +[25459, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], +[25560, "src/Rosetta/codecs/audio/Adpcm/init.luau"], +[26314, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], +[26616, "src/Rosetta/codecs/audio/Alac/init.luau"], +[26850, "src/Rosetta/codecs/audio/Alac/Decode.luau"], +[27269, "src/Rosetta/codecs/audio/Alac/Encode.luau"], +[27681, "src/Rosetta/codecs/audio/Ape/init.luau"], +[27896, "src/Rosetta/codecs/audio/Ape/Decode.luau"], +[28657, "src/Rosetta/codecs/audio/ApeTag.luau"], +[28754, "src/Rosetta/codecs/audio/Flac/init.luau"], +[28765, "src/Rosetta/codecs/audio/Flac/Encode.luau"], +[29714, "src/Rosetta/codecs/audio/Flac/Frame.luau"], +[30311, "src/Rosetta/codecs/audio/Hively/init.luau"], +[30507, "src/Rosetta/codecs/audio/Hively/Load.luau"], +[30756, "src/Rosetta/codecs/audio/Hively/Player.luau"], +[31714, "src/Rosetta/codecs/audio/Hively/Tables.luau"], +[31933, "src/Rosetta/codecs/audio/Mdct/init.luau"], +[32117, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], +[32326, "src/Rosetta/codecs/audio/MidiRender.luau"], +[32672, "src/Rosetta/codecs/audio/Mpa/init.luau"], +[32686, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], +[32745, "src/Rosetta/codecs/audio/Mpa/Core.luau"], +[34348, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], +[34640, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], +[35025, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], +[35666, "src/Rosetta/codecs/audio/Mpa/Header.luau"], +[35807, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], +[36033, "src/Rosetta/codecs/audio/Musepack/init.luau"], +[36378, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], +[37259, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], +[37637, "src/Rosetta/codecs/audio/Opus/init.luau"], +[37651, "src/Rosetta/codecs/audio/Opus/Celt.luau"], +[39498, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], +[40563, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], +[40623, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], +[41083, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], +[41420, "src/Rosetta/codecs/audio/Opus/Packet.luau"], +[41653, "src/Rosetta/codecs/audio/Opus/Silk.luau"], +[43689, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], +[44063, "src/Rosetta/codecs/audio/Pcm/init.luau"], +[44326, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], +[44623, "src/Rosetta/codecs/audio/Qoa/init.luau"], +[44905, "src/Rosetta/codecs/audio/Resample/init.luau"], +[45264, "src/Rosetta/codecs/audio/SoundFont/init.luau"], +[45318, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], +[45461, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], +[45974, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], +[46755, "src/Rosetta/codecs/audio/Stream.luau"], +[46916, "src/Rosetta/codecs/audio/Tracker/init.luau"], +[47398, "src/Rosetta/codecs/audio/Tracker/Load.luau"], +[47676, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], +[47845, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], +[47973, "src/Rosetta/codecs/audio/Tracker/Player.luau"], +[49961, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], +[50077, "src/Rosetta/codecs/audio/Tta/init.luau"], +[50194, "src/Rosetta/codecs/audio/Tta/Decode.luau"], +[50446, "src/Rosetta/codecs/audio/Vorbis/init.luau"], +[50459, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], +[50843, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], +[51409, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], +[51830, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], +[51869, "src/Rosetta/codecs/audio/VorbisComment.luau"], +[51921, "src/Rosetta/codecs/audio/WavPack/init.luau"], +[52143, "src/Rosetta/codecs/audio/WavPack/Block.luau"], +[53598, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], +[53661, "src/Rosetta/codecs/compress/Brotli/init.luau"], +[53748, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], +[54717, "src/Rosetta/codecs/compress/Brotli/Static.luau"], +[55585, "src/Rosetta/codecs/compress/Bzip2/init.luau"], +[55633, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], +[56149, "src/Rosetta/codecs/compress/Deflate/init.luau"], +[56475, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], +[56895, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], +[57330, "src/Rosetta/codecs/compress/Explode.luau"], +[57526, "src/Rosetta/codecs/compress/Lz4.luau"], +[57795, "src/Rosetta/codecs/compress/Lzh/init.luau"], +[58399, "src/Rosetta/codecs/compress/Lzma/init.luau"], +[58939, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], +[58977, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], +[59450, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], +[59626, "src/Rosetta/codecs/compress/Lzw/init.luau"], +[59894, "src/Rosetta/codecs/compress/Lzx.luau"], +[60328, "src/Rosetta/codecs/compress/PackBits.luau"], +[60418, "src/Rosetta/codecs/compress/Quantum.luau"], +[60655, "src/Rosetta/codecs/compress/UnixCompress.luau"], +[60959, "src/Rosetta/codecs/compress/Xxh32.luau"], +[61028, "src/Rosetta/codecs/compress/Zstd/init.luau"], +[61085, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], +[62043, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], +[62195, "src/Rosetta/codecs/entropy/Huffman.luau"], +[62477, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], +[62488, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], +[62702, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], +[62946, "src/Rosetta/codecs/font/Bitmap.luau"], +[63147, "src/Rosetta/codecs/font/Cff/init.luau"], +[63788, "src/Rosetta/codecs/font/GlyphNames.luau"], +[63938, "src/Rosetta/codecs/font/TrueType/init.luau"], +[64252, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], +[64644, "src/Rosetta/codecs/font/TrueType/Tables.luau"], +[65146, "src/Rosetta/codecs/image/Bcn/init.luau"], +[65253, "src/Rosetta/codecs/image/Bcn/Decode.luau"], +[65742, "src/Rosetta/codecs/image/Bcn/Encode.luau"], +[66171, "src/Rosetta/codecs/image/Blend.luau"], +[66550, "src/Rosetta/codecs/image/Dct/init.luau"], +[66931, "src/Rosetta/codecs/image/Etc.luau"], +[67229, "src/Rosetta/codecs/image/Half.luau"], +[67298, "src/Rosetta/codecs/image/Jpeg/init.luau"], +[67652, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], +[68060, "src/Rosetta/codecs/image/Jpeg/Color.luau"], +[68297, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], +[69057, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], +[69938, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], +[70384, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], +[70462, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], +[70529, "src/Rosetta/codecs/image/Pixels.luau"], +[70793, "src/Rosetta/codecs/image/Quantize/init.luau"], +[71252, "src/Rosetta/codecs/image/Raster.luau"], +[71949, "src/Rosetta/codecs/image/Texel.luau"], +[72322, "src/Rosetta/codecs/image/Texture.luau"], +[72467, "src/Rosetta/codecs/image/Vp8/init.luau"], +[72597, "src/Rosetta/codecs/image/Vp8/Decode.luau"], +[74553, "src/Rosetta/codecs/image/Vp8/Predict.luau"], +[74812, "src/Rosetta/codecs/image/Vp8/Tables.luau"], +[75061, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], +[75180, "src/Rosetta/codecs/image/Vp8L/init.luau"], +[75284, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], +[76137, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], +[77089, "src/Rosetta/codecs/image/Yuv.luau"], +[77357, "src/Rosetta/codecs/model/Draco/init.luau"], +[77689, "src/Rosetta/codecs/model/Draco/Attributes.luau"], +[78158, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], +[79347, "src/Rosetta/codecs/model/Draco/Int64.luau"], +[79496, "src/Rosetta/codecs/model/Draco/KdTree.luau"], +[79855, "src/Rosetta/codecs/model/Draco/Predict.luau"], +[80817, "src/Rosetta/codecs/model/Draco/Reader.luau"], +[81291, "src/Rosetta/codecs/model/Mat4.luau"], +[81550, "src/Rosetta/codecs/model/MeshFlatten.luau"], +[82078, "src/Rosetta/codecs/model/Minecraft/init.luau"], +[82630, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], +[82709, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], +[82816, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], +[83022, "src/Rosetta/codecs/model/Polygon.luau"], +[83256, "src/Rosetta/codecs/model/Rbx/init.luau"], +[83493, "src/Rosetta/codecs/model/Rbx/Binary.luau"], +[84247, "src/Rosetta/codecs/model/Rig.luau"], +[84490, "src/Rosetta/codecs/model/Sampler.luau"], +[84650, "src/Rosetta/codecs/model/Vrml/init.luau"], +[84798, "src/Rosetta/codecs/model/Vrml/Build.luau"], +[85372, "src/Rosetta/codecs/model/Vrml/Fields.luau"], +[85535, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], +[86284, "src/Rosetta/codecs/model/Vrml/Parse.luau"], +[86806, "src/Rosetta/codecs/model/Vrml/Write.luau"], +[87533, "src/Rosetta/codecs/model/Vrml/Xml.luau"], +[87765, "src/Rosetta/codecs/text/Json/init.luau"], +[88034, "src/Rosetta/codecs/text/Json/Decode.luau"], +[88448, "src/Rosetta/codecs/text/Json/Encode.luau"], +[88750, "src/Rosetta/codecs/text/Nbt/init.luau"], +[89103, "src/Rosetta/codecs/text/Nbt/Binary.luau"], +[89795, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], +[90435, "src/Rosetta/codecs/text/Nbt/Value.luau"], +[90673, "src/Rosetta/codecs/text/Text/init.luau"], +[90764, "src/Rosetta/codecs/text/Url/init.luau"], +[90969, "src/Rosetta/codecs/text/Xml/init.luau"], +[91372, "src/Rosetta/codecs/text/Xml/Parse.luau"], +[92112, "src/Rosetta/codecs/video/Dsp.luau"], +[92835, "src/Rosetta/codecs/video/H263/init.luau"], +[92991, "src/Rosetta/codecs/video/H263/Decoder.luau"], +[93849, "src/Rosetta/codecs/video/H263/Tables.luau"], +[94052, "src/Rosetta/codecs/video/H264/init.luau"], +[94425, "src/Rosetta/codecs/video/H264/Bitstream.luau"], +[94700, "src/Rosetta/codecs/video/H264/Cabac.luau"], +[95831, "src/Rosetta/codecs/video/H264/Cavlc.luau"], +[96599, "src/Rosetta/codecs/video/H264/Deblock.luau"], +[96857, "src/Rosetta/codecs/video/H264/Decoder.luau"], +[97866, "src/Rosetta/codecs/video/H264/Inter.luau"], +[98120, "src/Rosetta/codecs/video/H264/Intra.luau"], +[98527, "src/Rosetta/codecs/video/H264/Mb.luau"], +[99433, "src/Rosetta/codecs/video/H264/Params.luau"], +[99880, "src/Rosetta/codecs/video/H264/Slice.luau"], +[100131, "src/Rosetta/codecs/video/H264/Tables.luau"], +[100172, "src/Rosetta/codecs/video/H264/Transform.luau"], +[100337, "src/Rosetta/codecs/video/Legacy/init.luau"], +[100535, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], +[100832, "src/Rosetta/codecs/video/Legacy/Flic.luau"], +[101199, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], +[101317, "src/Rosetta/codecs/video/Legacy/Picture.luau"], +[101425, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], +[101698, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], +[102093, "src/Rosetta/codecs/video/Legacy/Smc.luau"], +[102270, "src/Rosetta/codecs/video/Mpeg1/init.luau"], +[102282, "src/Rosetta/codecs/video/Mpeg2/init.luau"], +[102649, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], +[104156, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], +[104295, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], +[104433, "src/Rosetta/codecs/video/Theora/init.luau"], +[104696, "src/Rosetta/codecs/video/Theora/Decoder.luau"], +[105960, "src/Rosetta/codecs/video/Theora/Header.luau"], +[106323, "src/Rosetta/codecs/video/Video/init.luau"], +[106880, "src/Rosetta/codecs/video/Video/Source.luau"], +[107165, "src/Rosetta/containers/Archive.luau"], +[107432, "src/Rosetta/containers/AudioWrap.luau"], +[107935, "src/Rosetta/containers/Avi/init.luau"], +[108487, "src/Rosetta/containers/Chunks.luau"], +[108622, "src/Rosetta/containers/Cpio.luau"], +[109050, "src/Rosetta/containers/Demux.luau"], +[109325, "src/Rosetta/containers/Ebml/init.luau"], +[109638, "src/Rosetta/containers/Fat.luau"], +[110326, "src/Rosetta/containers/Iso9660.luau"], +[110831, "src/Rosetta/containers/IsoBmff/init.luau"], +[111001, "src/Rosetta/containers/IsoBmff/Box.luau"], +[111189, "src/Rosetta/containers/IsoBmff/Demux.luau"], +[112034, "src/Rosetta/containers/IsoBmff/Meta.luau"], +[112555, "src/Rosetta/containers/IsoBmff/Mux.luau"], +[113071, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], +[113188, "src/Rosetta/containers/MacFile.luau"], +[113337, "src/Rosetta/containers/MpegEs.luau"], +[113503, "src/Rosetta/containers/MpegPs/init.luau"], +[113723, "src/Rosetta/containers/MpegTs/init.luau"], +[114515, "src/Rosetta/containers/Ogg/init.luau"], +[114940, "src/Rosetta/containers/Ogg/Mux.luau"], +[115135, "src/Rosetta/containers/Ogg/Page.luau"], +[115304, "src/Rosetta/containers/Riff/init.luau"], +[115621, "src/Rosetta/containers/Tar.luau"], +[116035, "src/Rosetta/containers/Zip/init.luau"], +[116667, "src/Rosetta/core/Adler32.luau"], +[116713, "src/Rosetta/core/Base64.luau"], +[116872, "src/Rosetta/core/Bits.luau"], +[117165, "src/Rosetta/core/Bytes.luau"], +[117692, "src/Rosetta/core/Crc16.luau"], +[117744, "src/Rosetta/core/Crc32.luau"], +[117856, "src/Rosetta/core/Err.luau"], +[117938, "src/Rosetta/core/Input.luau"], +[118014, "src/Rosetta/core/Md5.luau"], +[118173, "src/Rosetta/core/Sniff.luau"], +[118202, "src/Rosetta/data/cbor/init.luau"], +[118301, "src/Rosetta/data/cbor/Codec.luau"], +[118870, "src/Rosetta/data/csv/init.luau"], +[119182, "src/Rosetta/data/ini/init.luau"], +[119428, "src/Rosetta/data/json/init.luau"], +[119520, "src/Rosetta/data/msgpack/init.luau"], +[119609, "src/Rosetta/data/msgpack/Codec.luau"], +[120051, "src/Rosetta/data/nbt/init.luau"], +[120110, "src/Rosetta/data/plist/init.luau"], +[120416, "src/Rosetta/data/plist/Binary.luau"], +[120683, "src/Rosetta/data/snbt/init.luau"], +[120746, "src/Rosetta/data/toml/init.luau"], +[120813, "src/Rosetta/data/toml/Decode.luau"], +[121441, "src/Rosetta/data/toml/Encode.luau"], +[121650, "src/Rosetta/data/xml/init.luau"], +[121706, "src/Rosetta/data/yaml/init.luau"], +[121779, "src/Rosetta/data/yaml/Emit.luau"], +[122069, "src/Rosetta/data/yaml/Parse.luau"], +[123362, "src/Rosetta/font/bdf/init.luau"], +[123651, "src/Rosetta/font/bmfont/init.luau"], +[124078, "src/Rosetta/font/bmfont/Parse.luau"], +[124531, "src/Rosetta/font/eot/init.luau"], +[124763, "src/Rosetta/font/fon/init.luau"], +[125046, "src/Rosetta/font/hershey/init.luau"], +[125241, "src/Rosetta/font/pcf/init.luau"], +[125521, "src/Rosetta/font/psf/init.luau"], +[125841, "src/Rosetta/font/ttf/init.luau"], +[125892, "src/Rosetta/font/type1/init.luau"], +[126251, "src/Rosetta/font/type1/Charstring.luau"], +[126529, "src/Rosetta/font/woff/init.luau"], +[126661, "src/Rosetta/font/woff2/init.luau"], +[126718, "src/Rosetta/font/woff2/Rebuild.luau"], +[127258, "src/Rosetta/host/init.luau"], +[127303, "src/Rosetta/host/Love.luau"], +[127446, "src/Rosetta/host/LuaJIT.luau"], +[127496, "src/Rosetta/host/Luau.luau"], +[127519, "src/Rosetta/host/Roblox.luau"], +[127878, "src/Rosetta/image/ani/init.luau"], +[128058, "src/Rosetta/image/blp/init.luau"], +[128316, "src/Rosetta/image/bmp/init.luau"], +[128731, "src/Rosetta/image/dds/init.luau"], +[129214, "src/Rosetta/image/exr/init.luau"], +[129974, "src/Rosetta/image/exr/Codec.luau"], +[130085, "src/Rosetta/image/exr/Piz.luau"], +[130442, "src/Rosetta/image/gif/init.luau"], +[130958, "src/Rosetta/image/gif/Decode.luau"], +[131021, "src/Rosetta/image/hdr/init.luau"], +[131250, "src/Rosetta/image/hdr/Codec.luau"], +[131461, "src/Rosetta/image/icns/init.luau"], +[131792, "src/Rosetta/image/ico/init.luau"], +[132069, "src/Rosetta/image/ico/Dib.luau"], +[132164, "src/Rosetta/image/ilbm/init.luau"], +[132483, "src/Rosetta/image/jpeg/init.luau"], +[132619, "src/Rosetta/image/ktx/init.luau"], +[133279, "src/Rosetta/image/pcx/init.luau"], +[133543, "src/Rosetta/image/png/init.luau"], +[134123, "src/Rosetta/image/png/Apng.luau"], +[134203, "src/Rosetta/image/png/Decode.luau"], +[134443, "src/Rosetta/image/png/Encode.luau"], +[134598, "src/Rosetta/image/pnm/init.luau"], +[134976, "src/Rosetta/image/pnm/Codec.luau"], +[135253, "src/Rosetta/image/qoi/init.luau"], +[135375, "src/Rosetta/image/qoi/Codec.luau"], +[135525, "src/Rosetta/image/sgi/init.luau"], +[135810, "src/Rosetta/image/sunras/init.luau"], +[136056, "src/Rosetta/image/tga/init.luau"], +[136326, "src/Rosetta/image/tga/Codec.luau"], +[136478, "src/Rosetta/image/tiff/init.luau"], +[137305, "src/Rosetta/image/tiff/Pixels.luau"], +[137695, "src/Rosetta/image/tim/init.luau"], +[137937, "src/Rosetta/image/vtf/init.luau"], +[138172, "src/Rosetta/image/webp/init.luau"], +[138782, "src/Rosetta/image/webp/Alpha.luau"], +[138858, "src/Rosetta/image/webp/Anim.luau"], +[139013, "src/Rosetta/image/xbm/init.luau"], +[139174, "src/Rosetta/image/xpm/init.luau"], +[139442, "src/Rosetta/image/xpm/Names.luau"], +[139498, "src/Rosetta/layered/aseprite/init.luau"], +[140236, "src/Rosetta/layered/ora/init.luau"], +[140523, "src/Rosetta/layered/psd/init.luau"], +[141258, "src/Rosetta/layered/psd/Channels.luau"], +[141610, "src/Rosetta/model/3ds/init.luau"], +[141693, "src/Rosetta/model/3ds/Build.luau"], +[142340, "src/Rosetta/model/3ds/Read.luau"], +[142836, "src/Rosetta/model/3ds/Write.luau"], +[143641, "src/Rosetta/model/3mf/init.luau"], +[143723, "src/Rosetta/model/3mf/Read.luau"], +[144311, "src/Rosetta/model/3mf/Write.luau"], +[144716, "src/Rosetta/model/ase/init.luau"], +[144839, "src/Rosetta/model/ase/Build.luau"], +[145413, "src/Rosetta/model/ase/Parse.luau"], +[145482, "src/Rosetta/model/ase/Write.luau"], +[145945, "src/Rosetta/model/b3d/init.luau"], +[146000, "src/Rosetta/model/b3d/Read.luau"], +[146571, "src/Rosetta/model/bsp/init.luau"], +[146716, "src/Rosetta/model/bsp/Brush.luau"], +[146994, "src/Rosetta/model/bsp/Quake3.luau"], +[147249, "src/Rosetta/model/dae/init.luau"], +[147438, "src/Rosetta/model/dae/Math.luau"], +[147485, "src/Rosetta/model/dae/Read.luau"], +[149335, "src/Rosetta/model/dae/Write.luau"], +[149704, "src/Rosetta/model/fbx/init.luau"], +[149852, "src/Rosetta/model/fbx/Ascii.luau"], +[150122, "src/Rosetta/model/fbx/Binary.luau"], +[150577, "src/Rosetta/model/fbx/Read.luau"], +[151939, "src/Rosetta/model/fbx/Write.luau"], +[152924, "src/Rosetta/model/fbx/Xform.luau"], +[152965, "src/Rosetta/model/gltf/init.luau"], +[153202, "src/Rosetta/model/gltf/Pack.luau"], +[153271, "src/Rosetta/model/gltf/Read.luau"], +[154002, "src/Rosetta/model/gltf/Write.luau"], +[154682, "src/Rosetta/model/iqm/init.luau"], +[154758, "src/Rosetta/model/iqm/Read.luau"], +[155113, "src/Rosetta/model/iqm/Write.luau"], +[155800, "src/Rosetta/model/ldraw/init.luau"], +[155878, "src/Rosetta/model/ldraw/Colors.luau"], +[156196, "src/Rosetta/model/ldraw/Read.luau"], +[156773, "src/Rosetta/model/lwo/init.luau"], +[156849, "src/Rosetta/model/lwo/Build.luau"], +[157311, "src/Rosetta/model/lwo/Parse.luau"], +[157854, "src/Rosetta/model/mca/init.luau"], +[158196, "src/Rosetta/model/mca/Chunk.luau"], +[158329, "src/Rosetta/model/mca/Lz4Block.luau"], +[158399, "src/Rosetta/model/md2/init.luau"], +[158598, "src/Rosetta/model/md3/init.luau"], +[158826, "src/Rosetta/model/md5/init.luau"], +[158907, "src/Rosetta/model/md5/Read.luau"], +[159340, "src/Rosetta/model/mdl/init.luau"], +[159422, "src/Rosetta/model/mdl/HalfLife.luau"], +[159750, "src/Rosetta/model/mdl/Quake.luau"], +[159968, "src/Rosetta/model/ms3d/init.luau"], +[160040, "src/Rosetta/model/ms3d/Read.luau"], +[160486, "src/Rosetta/model/ms3d/Write.luau"], +[160955, "src/Rosetta/model/obj/init.luau"], +[161697, "src/Rosetta/model/obj/Mtl.luau"], +[161984, "src/Rosetta/model/off/init.luau"], +[162446, "src/Rosetta/model/ply/init.luau"], +[163551, "src/Rosetta/model/ply/Binary.luau"], +[163752, "src/Rosetta/model/pmx/init.luau"], +[163821, "src/Rosetta/model/pmx/Build.luau"], +[164117, "src/Rosetta/model/pmx/Pmd.luau"], +[164452, "src/Rosetta/model/pmx/Read.luau"], +[164856, "src/Rosetta/model/qb/init.luau"], +[165249, "src/Rosetta/model/rbxm/init.luau"], +[165841, "src/Rosetta/model/rbxmx/init.luau"], +[166494, "src/Rosetta/model/robloxmesh/init.luau"], +[167153, "src/Rosetta/model/robloxmesh/Parse.luau"], +[167610, "src/Rosetta/model/robloxmesh/Write.luau"], +[167719, "src/Rosetta/model/schematic/init.luau"], +[168040, "src/Rosetta/model/schematic/Common.luau"], +[168160, "src/Rosetta/model/schematic/Litematic.luau"], +[168371, "src/Rosetta/model/schematic/Mcedit.luau"], +[168615, "src/Rosetta/model/schematic/Sponge.luau"], +[168744, "src/Rosetta/model/smd/init.luau"], +[168811, "src/Rosetta/model/smd/Read.luau"], +[169080, "src/Rosetta/model/smd/Write.luau"], +[169323, "src/Rosetta/model/stl/init.luau"], +[169773, "src/Rosetta/model/stl/Decode.luau"], +[169847, "src/Rosetta/model/usda/init.luau"], +[170056, "src/Rosetta/model/usda/Build.luau"], +[171334, "src/Rosetta/model/usda/Parse.luau"], +[172132, "src/Rosetta/model/usda/Write.luau"], +[172949, "src/Rosetta/model/vox/init.luau"], +[173835, "src/Rosetta/model/vox/Grid.luau"], +[173892, "src/Rosetta/model/vrml/init.luau"], +[173958, "src/Rosetta/model/x/init.luau"], +[174088, "src/Rosetta/model/x/Build.luau"], +[174651, "src/Rosetta/model/x/Parse.luau"], +[174948, "src/Rosetta/model/x3d/init.luau"], +[175026, "src/Rosetta/music/669/init.luau"], +[175232, "src/Rosetta/music/ahx/init.luau"], +[175283, "src/Rosetta/music/far/init.luau"], +[175512, "src/Rosetta/music/hmp/init.luau"], +[175776, "src/Rosetta/music/hvl/init.luau"], +[175827, "src/Rosetta/music/it/init.luau"], +[176245, "src/Rosetta/music/it/Itsex.luau"], +[176361, "src/Rosetta/music/med/init.luau"], +[177008, "src/Rosetta/music/midi/init.luau"], +[177151, "src/Rosetta/music/midi/Smf.luau"], +[177562, "src/Rosetta/music/mod/init.luau"], +[177915, "src/Rosetta/music/mtm/init.luau"], +[178137, "src/Rosetta/music/mus/init.luau"], +[178294, "src/Rosetta/music/okt/init.luau"], +[178575, "src/Rosetta/music/ptm/init.luau"], +[178797, "src/Rosetta/music/s3m/init.luau"], +[179033, "src/Rosetta/music/sf2/init.luau"], +[179076, "src/Rosetta/music/stm/init.luau"], +[179307, "src/Rosetta/music/ult/init.luau"], +[179611, "src/Rosetta/music/umx/init.luau"], +[179827, "src/Rosetta/music/xm/init.luau"], +[180388, "src/Rosetta/music/xmi/init.luau"], +[180596, "src/Rosetta/ops/AudioOps.luau"], +[181045, "src/Rosetta/ops/ImageOps/init.luau"], +[181689, "src/Rosetta/ops/ImageOps/Kernels.luau"], +[182199, "src/Rosetta/ops/LayerOps.luau"], +[182292, "src/Rosetta/ops/MeshOps/init.luau"], +[183328, "src/Rosetta/ops/MeshOps/Greedy.luau"], +[183495, "src/Rosetta/ops/MusicOps.luau"], +[183843, "src/Rosetta/playlist/m3u/init.luau"], +[184196, "src/Rosetta/playlist/pls/init.luau"], +[184374, "src/Rosetta/playlist/xspf/init.luau"], +[184577, "src/Rosetta/subtitle/ass/init.luau"], +[185021, "src/Rosetta/subtitle/srt/init.luau"], +[185194, "src/Rosetta/subtitle/vtt/init.luau"], +[185397, "src/Rosetta/vector/svg/init.luau"], +[185483, "src/Rosetta/vector/svg/Parse.luau"], +[186229, "src/Rosetta/vector/svg/PathData.luau"], +[186597, "src/Rosetta/vector/svg/Render.luau"], +[187014, "src/Rosetta/vector/svg/Style.luau"], +[187386, "src/Rosetta/vector/svg/Write.luau"], +[187586, "src/Rosetta/vector/tiled/init.luau"], +[187766, "src/Rosetta/vector/tiled/Data.luau"], +[187917, "src/Rosetta/vector/tiled/Tmj.luau"], +[188548, "src/Rosetta/vector/tiled/Tmx.luau"], +[189160, "src/Rosetta/video/avi/init.luau"], +[189454, "src/Rosetta/video/fli/init.luau"], +[189605, "src/Rosetta/video/flv/init.luau"], +[189989, "src/Rosetta/video/flv/Amf.luau"], +[190147, "src/Rosetta/video/flv/Mux.luau"], +[190428, "src/Rosetta/video/h264/init.luau"], +[190567, "src/Rosetta/video/mkv/init.luau"], +[190723, "src/Rosetta/video/mkv/Mux.luau"], +[191002, "src/Rosetta/video/mkv/Parse.luau"], +[191723, "src/Rosetta/video/mp4/init.luau"], +[192051, "src/Rosetta/video/mpegps/init.luau"], +[192238, "src/Rosetta/video/mpegts/init.luau"], +[192476, "src/Rosetta/video/ogv/init.luau"], +[192871, "src/Rosetta/video/smk/init.luau"], +[193180, "src/Rosetta/video/smk/Audio.luau"], +[193300, "src/Rosetta/video/y4m/init.luau"] ] diff --git a/src/Rosetta/archive/unitypackage/init.luau b/src/Rosetta/archive/unitypackage/init.luau index 89aa2d8..442464a 100644 --- a/src/Rosetta/archive/unitypackage/init.luau +++ b/src/Rosetta/archive/unitypackage/init.luau @@ -61,14 +61,14 @@ local function encode(archive: any, opts: any?): (buffer?, Err.Err?) return UnityPackage.encode(archive, opts) end -type Asset = { asset: Tar.Entry?, meta: Tar.Entry?, pathname: Tar.Entry?, preview: Tar.Entry? } +type Asset = { asset: Tar.Entry?, meta: Tar.Entry?, pathname: Tar.Entry?, preview: Tar.Entry?, [string]: any } local function text(b: buffer, e: Tar.Entry): string return buffer.readstring(b, e.offset, e.size) end function UnityPackage.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) - local o = opts or {} + local o: DecodeOptions = opts or {} local tar, err = Deflate.gunzip(r.buf, r.base, r.limit - r.base) if not tar then return nil, err @@ -87,7 +87,7 @@ function UnityPackage.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.E if guid and not e.dir then local a = byGuid[guid] if not a then - a = {} + a = {} :: Asset byGuid[guid] = a table.insert(order, guid) end @@ -162,7 +162,7 @@ local function defaultMeta(guid: string, dir: boolean): string end function UnityPackage.encode(archive: any, opts: EncodeOptions?): (buffer?, Err.Err?) - local o = opts or {} + local o: EncodeOptions = opts or {} local items = Archive.entries(archive) if not items then return nil, Err.new(Err.ARG, "expected an Archive") @@ -196,13 +196,12 @@ function UnityPackage.encode(archive: any, opts: EncodeOptions?): (buffer?, Err. end metaData = mb end - local guid = if type(e.guid) == "string" and #e.guid == 32 and string.match(e.guid, "^%x+$") then string.lower(e.guid) else nil - guid = guid or (if metaData then metaGuid(metaData) else nil) or Md5.of(buffer.fromstring(path)) - if used[guid :: string] then - guid = Md5.of(buffer.fromstring(path .. "\0" .. guid)) + local given: string? = if type(e.guid) == "string" and #e.guid == 32 and string.match(e.guid, "^%x+$") then string.lower(e.guid) else nil + local g: string = given or (if metaData then metaGuid(metaData) else nil) or Md5.of(buffer.fromstring(path)) + if used[g] then + g = Md5.of(buffer.fromstring(path .. "\0" .. g)) end - used[guid :: string] = true - local g = guid :: string + used[g] = true metaData = metaData or buffer.fromstring(defaultMeta(g, e.dir == true)) table.insert(list, { name = g .. "/", dir = true, mtime = mtime }) if data then diff --git a/tests/archive/unitypackage.luau b/tests/archive/unitypackage.luau index 61f1b42..872acb2 100644 --- a/tests/archive/unitypackage.luau +++ b/tests/archive/unitypackage.luau @@ -57,7 +57,7 @@ for _, c in Fx.cases do e = x end end - local pv = e and e.preview and e.preview() + local pv: any = e and (e :: any).preview and (e :: any).preview() t:check(pv and buffer.readstring(pv, 8, 7) == "preview", c.name .. ": preview.png") -- round trip through our writer local out, werr = UnityPackage.encode(a) From 1f74419ccf7ac6a44734799561ea5dfa55222817 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 18:49:26 -0600 Subject: [PATCH 04/10] vector/ldtk: LDtk projects read + write as a TileMap (levels as groups, worlds, IntGrid / auto / tile / entity layers, fields, external levels through resolve) --- README.md | 3 +- docs/FORMATS.md | 1 + docs/guide/tilemap.md | 51 ++- src/Rosetta/Registry.luau | 12 + src/Rosetta/vector/ldtk/Read.luau | 334 +++++++++++++++ src/Rosetta/vector/ldtk/Write.luau | 646 +++++++++++++++++++++++++++++ src/Rosetta/vector/ldtk/init.luau | 90 ++++ tests/vector/ldtk.luau | 278 +++++++++++++ tools/fixtures/_ldtk_encode.luau | 30 ++ tools/fixtures/docs_engines.py | 7 +- tools/fixtures/ldtk.py | 111 +++++ 11 files changed, 1557 insertions(+), 6 deletions(-) create mode 100644 src/Rosetta/vector/ldtk/Read.luau create mode 100644 src/Rosetta/vector/ldtk/Write.luau create mode 100644 src/Rosetta/vector/ldtk/init.luau create mode 100644 tests/vector/ldtk.luau create mode 100644 tools/fixtures/_ldtk_encode.luau create mode 100644 tools/fixtures/ldtk.py diff --git a/README.md b/README.md index dc23830..8809bb7 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ print(F.detect(webp), #F.formats()) -- "webp", the format list ## Formats -176 formats. Generated from the format contracts by `tools/gen_registry.py`; [docs/FORMATS.md](docs/FORMATS.md) +177 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 | @@ -194,6 +194,7 @@ adds each format's capabilities. | Data | toml | .toml | yes | yes | | Data | xml | .xml .xsd .xsl .xslt .rss .atom .xhtml | yes | yes | | Data | yaml | .yaml .yml | yes | yes | +| Vector graphics and tile maps | ldtk | .ldtk | yes | yes | | Vector graphics and tile maps | svg | .svg | yes | yes | | Vector graphics and tile maps | tiled | .tmx .tmj .tsx .tsj | yes | yes | | Layered images | aseprite | .aseprite .ase | yes | yes | diff --git a/docs/FORMATS.md b/docs/FORMATS.md index 2b96ec4..4259416 100644 --- a/docs/FORMATS.md +++ b/docs/FORMATS.md @@ -150,6 +150,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build | data | toml | .toml | yes | yes | ordered: true, dates: true | `tests/data/toml.luau` | | data | xml | .xml .xsd .xsl .xslt .rss .atom .xhtml | yes | yes | namespaces: true, streaming: true | `tests/data/xml.luau` | | data | yaml | .yaml .yml | yes | yes | ordered: true, multiDocument: true, anchors: true | `tests/data/yaml.luau` | +| vector | ldtk | .ldtk | yes | yes | levels: true, worlds: true, intGrid: true, entities: true | `tests/vector/ldtk.luau` | | vector | svg | .svg | yes | yes | rasterize: true, text: false | `tests/vector/svg.luau` | | vector | tiled | .tmx .tmj .tsx .tsj | yes | yes | tilesets: true, infinite: true | `tests/vector/tiled.luau` | | layered | aseprite | .aseprite .ase | yes | yes | layers: true, groups: true, animation: true, depths: 8, 16, 32 | `tests/layered/aseprite.luau` | diff --git a/docs/guide/tilemap.md b/docs/guide/tilemap.md index bb86cd0..8b04fcc 100644 --- a/docs/guide/tilemap.md +++ b/docs/guide/tilemap.md @@ -1,4 +1,4 @@ -# Tile maps (Tiled TMX / TMJ) +# Tile maps (Tiled, LDtk, Ogmo) [Tiled](https://www.mapeditor.org) maps load as a `TileMap`: the map grid, its tilesets, and a list of layers (tile layers, object layers, image layers and groups) with Tiled's custom properties. The XML flavour (TMX) and the @@ -194,14 +194,61 @@ local back = assert(F.load(tmx)) assert(back.layers[1].data[6] == 0x80000009) ``` +## LDtk + +[LDtk](https://ldtk.io) projects (`.ldtk`) load as a `TileMap` whose top layers are the **levels**: one `"group"` +layer per level (`level = true`, `offsetX` / `offsetY` = its world position in pixels, `pxWidth` / `pxHeight`, the +level fields as `properties`), holding the level's layers bottom first. Multi-world projects add one group per +world (`world = true`) around its levels. External levels (`.ldtkl`) load through `opts.resolve(relPath)`; without +it the level group has `unresolved = true` and no layers. + +| LDtk layer | `TileLayer` | +|---|---| +| Tiles, AutoLayer | `type = "tiles"`, `tiles` (every tile: `x`, `y` pixels, `tile` id, `flip` bits, `srcX` / `srcY`, `alpha`), `data` (a gid grid of the top tile per cell), `tileset` | +| IntGrid | the same plus `intGrid` (one value per cell, 0 = empty) and `intGridValues` (`{ value, identifier, color }`) | +| Entities | `type = "objects"`: `class` = the entity identifier, `x` / `y` top-left (pixel position minus `pivot` x size), `width`, `height`, `pivot`, `tags`, `tile`, the fields as `properties` / `propertyTypes` (LDtk type names) | + +Every layer also has `ldtkType` and `gridSize` (LDtk layers have their own cell size), and the raw LDtk tables +(definitions, iids, uids, rules) ride along in `.ldtk` fields so a save keeps them. Gids are the tileset's +`firstGid` plus the LDtk tile id, with LDtk's X / Y flips as Tiled's flip bits. + +```luau +local map = assert(F.load(ldtkText)) +assert(map.meta.source.format == "ldtk") +local level = map.layers[1] +assert(level.level and level.name == "Stamps" and level.pxWidth == 272) +local walls = level.layers[1] +assert(walls.ldtkType == "IntGrid" and walls.intGridValues[1].identifier == "walls") +assert(#walls.tiles == 118 and map.tilesets[1].imageSource == "atlas/Inca_front_by_Kronbits-extended.png") +local cx, cy = walls.tiles[1].x // walls.gridSize, walls.tiles[1].y // walls.gridSize +assert(walls.data[1 + cx + cy * walls.width] ~= 0) +``` + +Saving writes an LDtk project: maps read from LDtk keep their definitions and raw fields (changed `properties` get +new `realEditorValues`, so the editor sees them); other maps (a Tiled map, a new `TileMap`) get layer, tileset and +entity definitions made from their content, their loose layers forming one level. A tile layer writes its `tiles` +list when it has one, else its `data` grid; set `tiles = nil` after editing `data`. Levels are always embedded. + +```luau +local map = F.Types.TileMap.new(2, 1, 16, 16) +table.insert(map.tilesets, { name = "t", firstGid = 1, tileWidth = 16, tileHeight = 16, columns = 2, count = 4, + imageSource = "t.png", imageWidth = 32, imageHeight = 32 }) +table.insert(map.layers, { type = "tiles", name = "Floor", width = 2, height = 1, visible = true, opacity = 1, + properties = {}, data = { 1, 4 } }) +local ldtk = assert(F.save(map, nil, { format = "ldtk" })) +local back = assert(F.load(ldtk)) +assert(back.layers[1].layers[1].tiles[2].tile == 3) +``` + ## Formats | Format | Read | Write | Notes | |---|---|---|---| | TMX / TSX | yes | yes | CSV, base64 (raw, zlib, gzip) and `` data; zstd data returns `UNSUPPORTED` | | TMJ / TSJ | yes | yes | | +| LDtk (`.ldtk`) | yes | yes | levels as groups, worlds, IntGrid / auto / tile / entity layers, fields; `.ldtkl` through `resolve`; writes embedded levels | -Both are the `tiled` format in [FORMATS.md](../FORMATS.md). Wang sets and terrains are dropped. +TMX and TMJ are both the `tiled` format in [FORMATS.md](../FORMATS.md) (Wang sets and terrains are dropped). ## Gotchas diff --git a/src/Rosetta/Registry.luau b/src/Rosetta/Registry.luau index 10fd987..5805e93 100644 --- a/src/Rosetta/Registry.luau +++ b/src/Rosetta/Registry.luau @@ -1754,6 +1754,18 @@ local list: { Entry } = { return require("@rosetta/data/yaml") end, }, + { + name = "ldtk", + category = "vector", + path = "vector/ldtk", + extensions = { "ldtk" }, + mime = { "application/x-ldtk+json" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Json" }, + caps = { decode = true, encode = true, levels = true, worlds = true, intGrid = true, entities = true }, + load = function() + return require("@rosetta/vector/ldtk") + end, + }, { name = "svg", category = "vector", diff --git a/src/Rosetta/vector/ldtk/Read.luau b/src/Rosetta/vector/ldtk/Read.luau new file mode 100644 index 0000000..f985ef3 --- /dev/null +++ b/src/Rosetta/vector/ldtk/Read.luau @@ -0,0 +1,334 @@ +--!strict +-- vector/ldtk/Read: an LDtk project (JSON, ldtk.io/json 1.5) into a Types.TileMap: one group layer per level (inside +-- one group per world for multi-world projects), the level's layers bottom first. Tile gids are firstGid + the +-- LDtk tile id with the f bits as Tiled's flip flags (bit 0 X -> 0x80000000, bit 1 Y -> 0x40000000). +local Types = require("@rosetta/Types") +local Json = require("@rosetta/codecs/text/Json") + +local Read = {} + +local FLIP_X, FLIP_Y = 0x80000000, 0x40000000 + +local function n(v: any, default: number): number + return if type(v) == "number" then v else default +end +local function s(v: any): string? + return if type(v) == "string" then v else nil +end +local NULL = Json.null +local function tab(v: any): boolean + return type(v) == "table" and v ~= NULL +end +local function list(v: any): { any } + return if tab(v) then v else {} +end + +-- every key but the ones listed (the raw part kept for the writer) +local function rest(t: any, skip: { [string]: boolean }): { [string]: any } + local keys = Json.keys(t) + local out: { [string]: any } = {} + local order = {} + for _, k in keys do + if not skip[k] then + out[k] = t[k] + table.insert(order, k) + end + end + return Json.object(out, order) +end + +function Read.fields(v: any): ({ [string]: any }, { [string]: string }?) + local props: { [string]: any } = {} + local types: { [string]: string }? = nil + for _, f in list(v) do + if type(f) == "table" and type(f.__identifier) == "string" then + props[f.__identifier] = f.__value + if type(f.__type) == "string" then + types = types or {} + ;(types :: any)[f.__identifier] = f.__type + end + end + end + return props, types +end + +type Ctx = { tilesets: { [number]: Types.Tileset }, maxCells: number, layerDefs: { [number]: any } } + +local function tiles(ctx: Ctx, raw: { any }, ts: Types.Tileset?, grid: number, cw: number, ch: number): ({ any }, { number }?) + local out = table.create(#raw) + local data: { number }? = nil + if cw > 0 and ch > 0 then + data = table.create(cw * ch, 0) + end + for i, t in raw do + if type(t) == "table" then + local px, src = list(t.px), list(t.src) + local tile = { + x = n(px[1], 0), + y = n(px[2], 0), + tile = n(t.t, 0), + flip = n(t.f, 0), + srcX = n(src[1], 0), + srcY = n(src[2], 0), + alpha = n(t.a, 1), + d = t.d, + } + out[i] = tile + if data and ts then + local cx, cy = tile.x // grid, tile.y // grid + if cx >= 0 and cy >= 0 and cx < cw and cy < ch then + local gid = ts.firstGid + tile.tile + if bit32.btest(tile.flip, 1) then + gid += FLIP_X + end + if bit32.btest(tile.flip, 2) then + gid += FLIP_Y + end + -- later tiles are drawn over earlier ones + data[1 + cx + cy * cw] = gid + end + end + end + end + return out, data +end + +local LAYER_SKIP = { __identifier = true, __type = true, __cWid = true, __cHei = true, __gridSize = true, __opacity = true, __pxTotalOffsetX = true, __pxTotalOffsetY = true, __tilesetDefUid = true, __tilesetRelPath = true, visible = true, intGridCsv = true, autoLayerTiles = true, gridTiles = true, entityInstances = true } +local ENTITY_SKIP = { __identifier = true, __grid = true, __pivot = true, __tags = true, __tile = true, __smartColor = true, __worldX = true, __worldY = true, width = true, height = true, px = true, fieldInstances = true } + +local function layer(ctx: Ctx, li: any): (Types.TileLayer?, string?) + local kind = s(li.__type) or "Tiles" + local cw, ch = n(li.__cWid, 0), n(li.__cHei, 0) + if cw < 0 or ch < 0 or cw * ch > ctx.maxCells then + return nil, "limit: layer of " .. cw .. " x " .. ch .. " cells" + end + local grid = math.max(1, n(li.__gridSize, 16)) + local out: Types.TileLayer = { + name = s(li.__identifier) or "", + type = if kind == "Entities" then "objects" else "tiles", + visible = li.visible ~= false, + opacity = n(li.__opacity, 1), + properties = {}, + offsetX = n(li.__pxTotalOffsetX, 0), + offsetY = n(li.__pxTotalOffsetY, 0), + ldtkType = kind, + gridSize = grid, + ldtk = rest(li, LAYER_SKIP), + } + if kind == "Entities" then + local objs = {} + for _, e in list(li.entityInstances) do + if type(e) == "table" then + local w, h = n(e.width, 0), n(e.height, 0) + local pv, px = list(e.__pivot), list(e.px) + local pX, pY = n(pv[1], 0), n(pv[2], 0) + local props, types = Read.fields(e.fieldInstances) + local o: { [string]: any } = { + id = s(e.iid), + name = s(e.__identifier) or "", + class = s(e.__identifier) or "", + x = n(px[1], 0) - pX * w, + y = n(px[2], 0) - pY * h, + width = w, + height = h, + rotation = 0, + visible = true, + shape = "rectangle", + pivot = { pX, pY }, + tags = e.__tags, + tile = if tab(e.__tile) then e.__tile else nil, + color = s(e.__smartColor), + properties = props, + propertyTypes = types, + ldtk = rest(e, ENTITY_SKIP), + fieldInstances = e.fieldInstances, + } + table.insert(objs, o) + end + end + out.objects = objs + return out, nil + end + out.width, out.height = cw, ch + local tsUid = li.__tilesetDefUid + local ts = if type(tsUid) == "number" then ctx.tilesets[tsUid] else nil + if ts then + out.tileset = ts.name + end + out.tilesetPath = s(li.__tilesetRelPath) + local raw = if kind == "Tiles" then list(li.gridTiles) else list(li.autoLayerTiles) + local tl, data = tiles(ctx, raw, ts, grid, cw, ch) + out.tiles = tl + out.data = data or {} + if kind == "IntGrid" then + local csv = list(li.intGridCsv) + local grid2 = table.create(cw * ch, 0) + for i = 1, math.min(#csv, cw * ch) do + grid2[i] = n(csv[i], 0) + end + out.intGrid = grid2 + local def = if type(li.layerDefUid) == "number" then ctx.layerDefs[li.layerDefUid] else nil + if def then + local values = {} + for _, v in list(def.intGridValues) do + if type(v) == "table" then + table.insert(values, { value = n(v.value, 0), identifier = s(v.identifier), color = s(v.color) }) + end + end + out.intGridValues = values + end + end + return out, nil +end + +local LEVEL_SKIP = { identifier = true, worldX = true, worldY = true, pxWid = true, pxHei = true, __bgColor = true, fieldInstances = true, layerInstances = true } + +local function level(ctx: Ctx, lv: any, resolve: ((string) -> buffer?)?): (Types.TileLayer?, string?) + local layers = lv.layerInstances + local external = s(lv.externalRelPath) + local unresolved = false + if not tab(layers) and external then + local data: any = nil + if resolve then + local ok, b = pcall(resolve, external) + data = if ok and type(b) == "buffer" then b else nil + end + if data then + local v, err = Json.decode(data, { ordered = true }) + if not tab(v) then + return nil, "external level " .. external .. ": " .. tostring(err) + end + lv = v + layers = v.layerInstances + else + unresolved = true + end + end + local props, types = Read.fields(lv.fieldInstances) + local g: Types.TileLayer = { + name = s(lv.identifier) or "", + type = "group", + visible = true, + opacity = 1, + properties = props, + propertyTypes = types, + offsetX = n(lv.worldX, 0), + offsetY = n(lv.worldY, 0), + layers = {}, + level = true, + pxWidth = n(lv.pxWid, 0), + pxHeight = n(lv.pxHei, 0), + backgroundColor = s(lv.__bgColor), + external = external, + unresolved = if unresolved then true else nil, + ldtk = rest(lv, LEVEL_SKIP), + } + local ls = list(layers) + for i = #ls, 1, -1 do + local l, err = layer(ctx, ls[i]) + if not l then + return nil, err + end + table.insert(g.layers :: { any }, l) + end + return g, nil +end + +local PROJECT_SKIP = { levels = true, worlds = true } + +function Read.project(v: any, opts: any): (Types.TileMap?, string?) + if not tab(v) or not tab(v.defs) then + return nil, "no defs: not an LDtk project" + end + local grid = math.max(1, n(v.defaultGridSize, 16)) + local map = Types.TileMap.new(0, 0, grid, grid) + local ctx: Ctx = { tilesets = {}, maxCells = opts.maxCells or 2 ^ 26, layerDefs = {} } + local gid = 1 + for _, t in list(v.defs.tilesets) do + if type(t) == "table" then + local cw, ch = n(t.__cWid, 0), n(t.__cHei, 0) + local size = n(t.tileGridSize, grid) + local ts: Types.Tileset = { + name = s(t.identifier) or ("tileset" .. #map.tilesets), + firstGid = gid, + tileWidth = size, + tileHeight = size, + columns = cw, + count = cw * ch, + imageSource = s(t.relPath), + imageWidth = n(t.pxWid, 0), + imageHeight = n(t.pxHei, 0), + spacing = n(t.spacing, 0), + margin = n(t.padding, 0), + uid = t.uid, + embedAtlas = s(t.embedAtlas), + properties = {}, + } + gid += math.max(1, cw * ch) + table.insert(map.tilesets, ts) + if type(t.uid) == "number" then + ctx.tilesets[t.uid] = ts + end + end + end + for _, d in list(v.defs.layers) do + if type(d) == "table" and type(d.uid) == "number" then + ctx.layerDefs[d.uid] = d + end + end + local resolve = opts.resolve + local worlds = list(v.worlds) + local minX, minY, maxX, maxY = math.huge, math.huge, -math.huge, -math.huge + local function addLevels(into: { any }, levels: any): string? + for _, lv in list(levels) do + if type(lv) == "table" then + local g, err = level(ctx, lv, resolve) + if not g then + return err + end + local x, y = g.offsetX :: number, g.offsetY :: number + minX, minY = math.min(minX, x), math.min(minY, y) + maxX, maxY = math.max(maxX, x + (g.pxWidth :: number)), math.max(maxY, y + (g.pxHeight :: number)) + table.insert(into, g) + end + end + return nil + end + if #worlds > 0 then + for _, w in worlds do + if type(w) == "table" then + local wg: Types.TileLayer = { + name = s(w.identifier) or "", + type = "group", + visible = true, + opacity = 1, + properties = {}, + layers = {}, + world = true, + ldtk = rest(w, { levels = true, identifier = true }), + } + local err = addLevels(wg.layers :: { any }, w.levels) + if err then + return nil, err + end + table.insert(map.layers, wg) + end + end + else + local err = addLevels(map.layers, v.levels) + if err then + return nil, err + end + end + if minX <= maxX then + map.width = math.ceil((maxX - math.min(minX, 0)) / grid) + map.height = math.ceil((maxY - math.min(minY, 0)) / grid) + end + map.backgroundColor = s(v.bgColor) + map.worldLayout = s(v.worldLayout) + map.ldtk = rest(v, PROJECT_SKIP) + map.meta.source = { format = "ldtk", version = s(v.jsonVersion), externalLevels = v.externalLevels == true, multiWorld = #worlds > 0 } + return map, nil +end + +return Read diff --git a/src/Rosetta/vector/ldtk/Write.luau b/src/Rosetta/vector/ldtk/Write.luau new file mode 100644 index 0000000..472773a --- /dev/null +++ b/src/Rosetta/vector/ldtk/Write.luau @@ -0,0 +1,646 @@ +--!strict +-- vector/ldtk/Write: a Types.TileMap as an LDtk project (JSON 1.5). Maps read from LDtk keep their raw defs, project, +-- level, layer and entity fields (the .ldtk tables); other maps get definitions made from their layers, tilesets and +-- object classes. A tile layer writes its `tiles` list when present, else its gid `data`. Levels are always embedded. +local Types = require("@rosetta/Types") +local Json = require("@rosetta/codecs/text/Json") + +local Write = {} + +local NULL = Json.null +local FLAGS = 0xF0000000 + +local function tab(v: any): boolean + return type(v) == "table" and v ~= NULL +end +local function list(v: any): { any } + return if tab(v) then v else {} +end +local function n(v: any, default: number): number + return if type(v) == "number" and v == v then v else default +end + +type Ctx = { + uid: number, + iid: number, + defs: any, + tilesetByName: { [string]: any }, + tilesetByUid: { [number]: any }, + layerDefs: { [string]: any }, + entityDefs: { [string]: any }, + levelFields: { [string]: any }, + map: Types.TileMap, +} + +local function clone(t: any): any + if not tab(t) then + return Json.object({}) + end + local keys = Json.keys(t) + local out = {} + for _, k in keys do + out[k] = t[k] + end + return Json.object(out, keys) +end + +local function obj(pairs_: { any }): any + local out, keys = {}, {} + for i = 1, #pairs_, 2 do + local k, v = pairs_[i], pairs_[i + 1] + table.insert(keys, k) + out[k] = v + end + return Json.object(out, keys) +end + +local function set(t: any, k: string, v: any) + Json.set(t, k, if v == nil then NULL else v) +end + +local function nextUid(ctx: Ctx): number + ctx.uid += 1 + return ctx.uid +end + +local function newIid(ctx: Ctx): string + ctx.iid += 1 + return string.format("%08x-0000-4000-8000-%012x", 0x5ce7a000 + ctx.iid // 0x1000000, ctx.iid) +end + +-- ------------------------------------------------------------------------------------------------ fields +local function hexColor(v: any): number? + if type(v) ~= "string" then + return nil + end + local h = string.match(v, "^#(%x%x%x%x%x%x)$") or string.match(v, "^#%x%x(%x%x%x%x%x%x)$") + return if h then tonumber(h, 16) else nil +end + +local function wrap(typ: string, v: any): any + if v == nil or v == NULL then + return NULL + end + if typ == "Int" then + return obj({ "id", "V_Int", "params", { v } }) + elseif typ == "Float" then + return obj({ "id", "V_Float", "params", { v } }) + elseif typ == "Bool" then + return obj({ "id", "V_Bool", "params", { v == true } }) + elseif typ == "Color" then + local c = hexColor(v) + return if c then obj({ "id", "V_Int", "params", { c } }) else NULL + elseif typ == "Point" and tab(v) then + return obj({ "id", "V_String", "params", { tostring(v.cx) .. "," .. tostring(v.cy) } }) + elseif type(v) == "string" then + return obj({ "id", "V_String", "params", { v } }) + end + return nil +end + +local function editorValues(typ: string, v: any): any + local inner = string.match(typ, "^Array<(.+)>$") + if inner then + local out = {} + for i, x in list(v) do + local w = wrap(inner, x) + if w == nil then + return nil + end + out[i] = w + end + return out + end + local w = wrap(typ, v) + return if w == nil then nil else { w } +end + +local function same(a: any, b: any): boolean + if a == b then + return true + end + if tab(a) and tab(b) then + for k, x in a do + if not same(x, b[k]) then + return false + end + end + for k in b do + if a[k] == nil then + return false + end + end + return true + end + return false +end + +local LDTK_TYPE: { [string]: string } = { int = "Int", float = "Float", bool = "Bool", string = "String", color = "Color", file = "FilePath" } + +local function valueType(v: any): string + if type(v) == "number" then + return if v % 1 == 0 then "Int" else "Float" + elseif type(v) == "boolean" then + return "Bool" + end + return "String" +end + +local function fieldDef(ctx: Ctx, name: string, typ: string): any + local isArray = string.match(typ, "^Array<") ~= nil + local base = string.match(typ, "^Array<(.+)>$") or typ + return obj({ + "identifier", name, "doc", NULL, "__type", typ, "uid", nextUid(ctx), "type", "F_" .. base, "isArray", isArray, + "canBeNull", true, "arrayMinLength", NULL, "arrayMaxLength", NULL, "editorDisplayMode", "Hidden", + "editorDisplayScale", 1, "editorDisplayPos", "Above", "editorLinkStyle", "StraightArrow", "editorDisplayColor", NULL, + "editorAlwaysShow", false, "editorShowInWorld", true, "editorCutLongValues", true, "editorTextSuffix", NULL, + "editorTextPrefix", NULL, "useForSmartColor", false, "exportToToc", false, "searchable", false, "min", NULL, + "max", NULL, "regex", NULL, "acceptFileTypes", NULL, "defaultOverride", NULL, "textLanguageMode", NULL, + "symmetricalRef", false, "autoChainRef", true, "allowOutOfLevelRef", true, "allowedRefs", "OnlySame", + "allowedRefsEntityUid", NULL, "allowedRefTags", {}, "tilesetUid", NULL, + }) +end + +-- raw field instances updated from the properties; properties without an instance get one when a definition exists +-- (or is made: makeDefs) +local function fieldInstances(ctx: Ctx, raw: any, props: any, types: any, defs: { [string]: any }?, makeDefs: { any }?): { any } + local out = {} + local seen: { [string]: boolean } = {} + props = if tab(props) then props else {} + types = if tab(types) then types else {} + for _, fi in list(raw) do + if tab(fi) and type(fi.__identifier) == "string" then + local id = fi.__identifier + seen[id] = true + local f = clone(fi) + local v = props[id] + if v ~= nil and not same(v, fi.__value) then + set(f, "__value", v) + local ev = editorValues(if type(fi.__type) == "string" then fi.__type else valueType(v), v) + if ev then + set(f, "realEditorValues", ev) + end + end + table.insert(out, f) + end + end + local names = {} + for k in props do + if type(k) == "string" and not seen[k] then + table.insert(names, k) + end + end + table.sort(names) + for _, k in names do + local v = props[k] + local def = defs and defs[k] + if not def and makeDefs and defs then + local typ = if type(types[k]) == "string" then (LDTK_TYPE[types[k]] or types[k]) else valueType(v) + def = fieldDef(ctx, k, typ) + defs[k] = def + table.insert(makeDefs, def) + end + if def then + local typ = if type(def.__type) == "string" then def.__type else valueType(v) + table.insert(out, obj({ "__identifier", k, "__type", typ, "__value", v, "__tile", NULL, "defUid", def.uid, "realEditorValues", editorValues(typ, v) or {} })) + end + end + return out +end + +-- ------------------------------------------------------------------------------------------------ defs +local function tilesetOf(ctx: Ctx, gid: number): any + local best: any = nil + for _, ts in ctx.map.tilesets do + if ts.firstGid <= gid and (best == nil or ts.firstGid > best.firstGid) then + best = ts + end + end + return best +end + +local function defsFor(ctx: Ctx, raw: any) + local defs = if tab(raw) then clone(raw) else obj({ "layers", {}, "entities", {}, "tilesets", {}, "enums", {}, "externalEnums", {}, "levelFields", {} }) + for _, k in { "layers", "entities", "tilesets", "enums", "externalEnums", "levelFields" } do + if not tab(defs[k]) then + set(defs, k, {}) + end + end + ctx.defs = defs + for _, d in list(defs.tilesets) do + if tab(d) and type(d.uid) == "number" then + ctx.uid = math.max(ctx.uid, d.uid) + ctx.tilesetByUid[d.uid] = d + if type(d.identifier) == "string" then + ctx.tilesetByName[d.identifier] = d + end + end + end + for _, d in list(defs.layers) do + if tab(d) and type(d.identifier) == "string" then + ctx.uid = math.max(ctx.uid, n(d.uid, 0)) + ctx.layerDefs[d.identifier] = d + end + end + for _, d in list(defs.entities) do + if tab(d) and type(d.identifier) == "string" then + ctx.uid = math.max(ctx.uid, n(d.uid, 0)) + ctx.entityDefs[d.identifier] = d + for _, f in list(d.fieldDefs) do + ctx.uid = math.max(ctx.uid, n(tab(f) and f.uid, 0)) + end + end + end + for _, f in list(defs.levelFields) do + if tab(f) and type(f.identifier) == "string" then + ctx.uid = math.max(ctx.uid, n(f.uid, 0)) + ctx.levelFields[f.identifier] = f + end + end + for _, d in list(defs.enums) do + ctx.uid = math.max(ctx.uid, n(tab(d) and d.uid, 0)) + end + -- tilesets of the map the defs lack + for _, ts in ctx.map.tilesets do + if type(ts.name) == "string" and not ctx.tilesetByName[ts.name] then + local size = n(ts.tileWidth, 16) + local cols = math.max(1, n(ts.columns, 1)) + local d = obj({ + "__cWid", cols, "__cHei", math.ceil(n(ts.count, cols) / cols), "identifier", ts.name, "uid", nextUid(ctx), + "relPath", ts.imageSource or NULL, "embedAtlas", NULL, "pxWid", n(ts.imageWidth, cols * size), + "pxHei", n(ts.imageHeight, math.ceil(n(ts.count, cols) / cols) * size), "tileGridSize", size, + "spacing", n(ts.spacing, 0), "padding", n(ts.margin, 0), "tags", {}, "tagsSourceEnumUid", NULL, + "enumTags", {}, "customData", {}, "savedSelections", {}, "cachedPixelData", NULL, + }) + table.insert(defs.tilesets, d) + ctx.tilesetByName[ts.name] = d + ctx.tilesetByUid[d.uid] = d + end + end +end + +local function layerDef(ctx: Ctx, l: any, kind: string, grid: number, tsUid: number?): any + local d = ctx.layerDefs[l.name] + if d then + return d + end + local values = {} + for _, v in list(l.intGridValues) do + table.insert(values, obj({ "value", n(v.value, 1), "identifier", v.identifier or NULL, "color", v.color or "#FFFFFF", "tile", NULL, "groupUid", 0 })) + end + if kind == "IntGrid" and #values == 0 then + local maxV = 0 + for _, v in list(l.intGrid) do + maxV = math.max(maxV, n(v, 0)) + end + for v = 1, maxV do + table.insert(values, obj({ "value", v, "identifier", NULL, "color", "#FFFFFF", "tile", NULL, "groupUid", 0 })) + end + end + d = obj({ + "__type", kind, "identifier", l.name, "type", kind, "uid", nextUid(ctx), "doc", NULL, "uiColor", NULL, + "gridSize", grid, "guideGridWid", 0, "guideGridHei", 0, "displayOpacity", n(l.opacity, 1), "inactiveOpacity", 1, + "hideInList", false, "hideFieldsWhenInactive", true, "canSelectWhenInactive", true, "renderInWorldView", true, + "pxOffsetX", 0, "pxOffsetY", 0, "parallaxFactorX", 0, "parallaxFactorY", 0, "parallaxScaling", true, + "requiredTags", {}, "excludedTags", {}, "autoTilesKilledByOtherLayerUid", NULL, "uiFilterTags", {}, + "useAsyncRender", false, "intGridValues", values, "intGridValuesGroups", {}, "autoRuleGroups", {}, + "autoSourceLayerDefUid", NULL, "tilesetDefUid", tsUid or NULL, "tilePivotX", 0, "tilePivotY", 0, "biomeFieldUid", NULL, + }) + table.insert(ctx.defs.layers, d) + ctx.layerDefs[l.name] = d + return d +end + +local function entityDef(ctx: Ctx, o: any): any + local name = if type(o.class) == "string" and o.class ~= "" then o.class elseif type(o.name) == "string" and o.name ~= "" then o.name else "Entity" + local d = ctx.entityDefs[name] + if d then + return d + end + local pv = if tab(o.pivot) then o.pivot else { 0, 0 } + d = obj({ + "identifier", name, "uid", nextUid(ctx), "tags", {}, "exportToToc", false, "allowOutOfBounds", false, "doc", NULL, + "width", math.max(1, n(o.width, 16)), "height", math.max(1, n(o.height, 16)), "resizableX", false, + "resizableY", false, "minWidth", NULL, "maxWidth", NULL, "minHeight", NULL, "maxHeight", NULL, + "keepAspectRatio", false, "tileOpacity", 1, "fillOpacity", 0.08, "lineOpacity", 0, "hollow", false, + "color", if type(o.color) == "string" then o.color else "#94D9B3", "renderMode", "Rectangle", "showName", true, + "tilesetId", NULL, "tileRenderMode", "FitInside", "tileRect", NULL, "uiTileRect", NULL, "nineSliceBorders", {}, + "maxCount", 0, "limitScope", "PerLevel", "limitBehavior", "MoveLastOne", "pivotX", n(pv[1], 0), "pivotY", n(pv[2], 0), + "fieldDefs", {}, + }) + table.insert(ctx.defs.entities, d) + ctx.entityDefs[name] = d + return d +end + +-- ------------------------------------------------------------------------------------------------ layers +local function gridTiles(ctx: Ctx, l: any, grid: number, ts: any): { any } + local out = {} + if tab(l.tiles) then + for _, t in l.tiles do + local o = obj({ "px", { n(t.x, 0), n(t.y, 0) }, "src", { n(t.srcX, 0), n(t.srcY, 0) }, "f", n(t.flip, 0), "t", n(t.tile, 0) }) + if tab(t.d) then + set(o, "d", t.d) + end + set(o, "a", n(t.alpha, 1)) + table.insert(out, o) + end + return out + end + local w = n(l.width, 0) + for i, raw in list(l.data) do + local gid = bit32.band(n(raw, 0), bit32.bnot(FLAGS)) + if gid ~= 0 then + local tset = tilesetOf(ctx, gid) + if tset and (ts == nil or ctx.tilesetByName[tset.name] == ts) then + local id = gid - tset.firstGid + local cols = math.max(1, n(tset.columns, 1)) + local tw, th = n(tset.tileWidth, grid), n(tset.tileHeight, grid) + local sp, mg = n(tset.spacing, 0), n(tset.margin, 0) + local f = (if bit32.btest(raw, 0x80000000) then 1 else 0) + (if bit32.btest(raw, 0x40000000) then 2 else 0) + local cx, cy = (i - 1) % math.max(w, 1), (i - 1) // math.max(w, 1) + table.insert(out, obj({ + "px", { cx * grid, cy * grid }, "src", { mg + (id % cols) * (tw + sp), mg + (id // cols) * (th + sp) }, + "f", f, "t", id, "d", { cx + cy * w }, "a", 1, + })) + end + end + end + return out +end + +local function layerTileset(ctx: Ctx, l: any): any + if type(l.tileset) == "string" and ctx.tilesetByName[l.tileset] then + return ctx.tilesetByName[l.tileset] + end + if tab(l.ldtk) and type(l.ldtk.overrideTilesetUid) == "number" and ctx.tilesetByUid[l.ldtk.overrideTilesetUid] then + return ctx.tilesetByUid[l.ldtk.overrideTilesetUid] + end + for _, raw in list(l.data) do + local gid = bit32.band(n(raw, 0), bit32.bnot(FLAGS)) + if gid ~= 0 then + local tset = tilesetOf(ctx, gid) + return if tset then ctx.tilesetByName[tset.name] else nil + end + end + return nil +end + +local function entities(ctx: Ctx, l: any, levelIid: string, lx: number, ly: number, grid: number): { any } + local out = {} + for _, o in list(l.objects) do + if tab(o) then + local d = entityDef(ctx, o) + local w, h = n(o.width, n(d.width, 16)), n(o.height, n(d.height, 16)) + local pv = if tab(o.pivot) then o.pivot else { n(d.pivotX, 0), n(d.pivotY, 0) } + local px, py = n(o.x, 0) + n(pv[1], 0) * w, n(o.y, 0) + n(pv[2], 0) * h + local e = clone(o.ldtk) + set(e, "__identifier", d.identifier) + set(e, "__grid", { px // grid, py // grid }) + set(e, "__pivot", { n(pv[1], 0), n(pv[2], 0) }) + set(e, "__tags", if tab(o.tags) then o.tags else {}) + set(e, "__tile", if tab(o.tile) then o.tile else NULL) + set(e, "__smartColor", if type(o.color) == "string" then o.color else d.color) + if type(e.iid) ~= "string" then + set(e, "iid", if type(o.id) == "string" then o.id else newIid(ctx)) + end + set(e, "width", w) + set(e, "height", h) + set(e, "defUid", d.uid) + set(e, "px", { px, py }) + local fdefs: { [string]: any } = {} + for _, f in list(d.fieldDefs) do + if tab(f) and type(f.identifier) == "string" then + fdefs[f.identifier] = f + end + end + set(e, "fieldInstances", fieldInstances(ctx, o.fieldInstances, o.properties, o.propertyTypes, fdefs, d.fieldDefs)) + set(e, "__worldX", lx + px) + set(e, "__worldY", ly + py) + table.insert(out, e) + end + end + return out +end + +local function layerInstance(ctx: Ctx, l: any, levelUid: number, levelIid: string, lx: number, ly: number, pxW: number, pxH: number): any + local kind = if type(l.ldtkType) == "string" then l.ldtkType + elseif l.type == "objects" then "Entities" + elseif tab(l.intGrid) then "IntGrid" + else "Tiles" + local grid = math.max(1, n(l.gridSize, ctx.map.tileWidth)) + local ts = if kind ~= "Entities" then layerTileset(ctx, l) else nil + local d = layerDef(ctx, l, kind, grid, if ts then ts.uid else nil) + local cw = n(l.width, math.ceil(pxW / grid)) + local ch = n(l.height, math.ceil(pxH / grid)) + local li = clone(l.ldtk) + set(li, "__identifier", l.name) + set(li, "__type", kind) + set(li, "__cWid", cw) + set(li, "__cHei", ch) + set(li, "__gridSize", grid) + set(li, "__opacity", n(l.opacity, 1)) + set(li, "__pxTotalOffsetX", n(l.offsetX, 0)) + set(li, "__pxTotalOffsetY", n(l.offsetY, 0)) + set(li, "__tilesetDefUid", if ts then ts.uid else NULL) + set(li, "__tilesetRelPath", if ts and type(ts.relPath) == "string" then ts.relPath else NULL) + if type(li.iid) ~= "string" then + set(li, "iid", newIid(ctx)) + end + set(li, "levelId", levelUid) + set(li, "layerDefUid", d.uid) + if li.pxOffsetX == nil then + set(li, "pxOffsetX", n(l.offsetX, 0) - n(d.pxOffsetX, 0)) + set(li, "pxOffsetY", n(l.offsetY, 0) - n(d.pxOffsetY, 0)) + end + set(li, "visible", l.visible ~= false) + if li.optionalRules == nil then + set(li, "optionalRules", {}) + end + local csv = {} + if kind == "IntGrid" then + local g = list(l.intGrid) + for i = 1, cw * ch do + csv[i] = n(g[i], 0) + end + end + set(li, "intGridCsv", csv) + local tl = if kind ~= "Entities" then gridTiles(ctx, l, grid, ts) else {} + set(li, "autoLayerTiles", if kind == "IntGrid" or kind == "AutoLayer" then tl else {}) + if li.seed == nil then + set(li, "seed", 0) + end + if li.overrideTilesetUid == nil then + set(li, "overrideTilesetUid", NULL) + end + set(li, "gridTiles", if kind == "Tiles" then tl else {}) + set(li, "entityInstances", if kind == "Entities" then entities(ctx, l, levelIid, lx, ly, grid) else {}) + return li +end + +-- ------------------------------------------------------------------------------------------------ levels +local function flat(layers: { any }, into: { any }) + for _, l in layers do + if l.type == "group" and not l.level and not l.world then + flat(list(l.layers), into) + elseif l.type ~= "group" and l.type ~= "image" then + table.insert(into, l) + end + end +end + +local function levelValue(ctx: Ctx, g: any, layers: { any }, index: number): any + local lv = clone(g.ldtk) + local grid = ctx.map.tileWidth + local pxW = n(g.pxWidth, 0) + local pxH = n(g.pxHeight, 0) + if pxW <= 0 or pxH <= 0 then + for _, l in layers do + local gs = n(l.gridSize, grid) + pxW = math.max(pxW, n(l.width, 0) * gs) + pxH = math.max(pxH, n(l.height, 0) * gs) + end + pxW = if pxW > 0 then pxW else ctx.map.width * grid + pxH = if pxH > 0 then pxH else ctx.map.height * grid + end + local uid = if type(lv.uid) == "number" then lv.uid else nextUid(ctx) + local iid = if type(lv.iid) == "string" then lv.iid else newIid(ctx) + local lx, ly = n(g.offsetX, 0), n(g.offsetY, 0) + set(lv, "identifier", if type(g.name) == "string" and g.name ~= "" then g.name else "Level_" .. index) + set(lv, "iid", iid) + set(lv, "uid", uid) + set(lv, "worldX", lx) + set(lv, "worldY", ly) + if lv.worldDepth == nil then + set(lv, "worldDepth", 0) + end + set(lv, "pxWid", pxW) + set(lv, "pxHei", pxH) + set(lv, "__bgColor", if type(g.backgroundColor) == "string" then g.backgroundColor elseif type(ctx.map.backgroundColor) == "string" then ctx.map.backgroundColor else "#696A79") + for _, k in { "bgColor", "bgRelPath", "bgPos", "__smartColor", "__bgPos" } do + if lv[k] == nil then + set(lv, k, if k == "__smartColor" then "#ADADB5ff" else NULL) + end + end + if lv.useAutoIdentifier == nil then + set(lv, "useAutoIdentifier", false) + end + if lv.bgPivotX == nil then + set(lv, "bgPivotX", 0.5) + set(lv, "bgPivotY", 0.5) + end + set(lv, "externalRelPath", NULL) + set(lv, "fieldInstances", fieldInstances(ctx, lv.fieldInstances, g.properties, g.propertyTypes, ctx.levelFields, ctx.defs.levelFields)) + local out = {} + for i = #layers, 1, -1 do + table.insert(out, layerInstance(ctx, layers[i], uid, iid, lx, ly, pxW, pxH)) + end + set(lv, "layerInstances", out) + if lv.__neighbours == nil then + set(lv, "__neighbours", {}) + end + return lv +end + +local function levels(ctx: Ctx, layers: { any }): { any } + local out = {} + local loose = {} + for _, l in layers do + if l.type == "group" and not l.world then + local ls = {} + flat(list(l.layers), ls) + table.insert(out, levelValue(ctx, l, ls, #out)) + elseif l.type ~= "group" and l.type ~= "image" then + table.insert(loose, l) + end + end + if #loose > 0 then + table.insert(out, 1, levelValue(ctx, { name = "Level_0", properties = {}, offsetX = 0, offsetY = 0 }, loose, 0)) + end + return out +end + +local PROJECT: { any } = { + "__header__", NULL, "iid", NULL, "jsonVersion", "1.5.3", "appBuildId", 473703, "nextUid", 0, "identifierStyle", "Capitalize", + "toc", {}, "worldLayout", "Free", "worldGridWidth", 256, "worldGridHeight", 256, "defaultLevelWidth", 256, + "defaultLevelHeight", 256, "defaultPivotX", 0, "defaultPivotY", 0, "defaultGridSize", 16, "defaultEntityWidth", 16, + "defaultEntityHeight", 16, "bgColor", "#40465B", "defaultLevelBgColor", "#696A79", "minifyJson", false, + "externalLevels", false, "exportTiled", false, "simplifiedExport", false, "imageExportMode", "None", + "exportLevelBg", true, "pngFilePattern", NULL, "backupOnSave", false, "backupLimit", 10, "backupRelPath", NULL, + "levelNamePattern", "Level_%idx", "tutorialDesc", NULL, "customCommands", {}, "flags", {}, "defs", NULL, + "levels", NULL, "worlds", NULL, "dummyWorldIid", NULL, +} + +function Write.project(map: Types.TileMap, opts: any): (any, string?) + local ctx: Ctx = { + uid = 0, + iid = 0, + defs = nil, + tilesetByName = {}, + tilesetByUid = {}, + layerDefs = {}, + entityDefs = {}, + levelFields = {}, + map = map, + } + local raw = if tab(map.ldtk) then map.ldtk else nil + local p = if raw then clone(raw) else Json.object({}) + if not raw then + for i = 1, #PROJECT, 2 do + set(p, PROJECT[i], PROJECT[i + 1]) + end + set(p, "__header__", obj({ "fileType", "LDtk Project JSON", "app", "LDtk", "doc", "https://ldtk.io/json", "schema", "https://ldtk.io/files/JSON_SCHEMA.json", "appAuthor", "Sebastien 'deepnight' Benard", "appVersion", "1.5.3", "url", "https://ldtk.io" })) + set(p, "iid", newIid(ctx)) + set(p, "defaultGridSize", map.tileWidth) + end + ctx.uid = math.max(ctx.uid, n(p.nextUid, 1) - 1) + defsFor(ctx, p.defs) + local worlds = {} + local hasWorlds = false + for _, l in map.layers do + if l.type == "group" and l.world then + hasWorlds = true + end + end + local lvls: { any } = {} + if hasWorlds then + for _, l in map.layers do + if l.type == "group" and l.world then + local w = clone(l.ldtk) + set(w, "identifier", l.name) + if type(w.iid) ~= "string" then + set(w, "iid", newIid(ctx)) + end + for _, k in { "worldGridWidth", "worldGridHeight" } do + if w[k] == nil then + set(w, k, 256) + end + end + if w.worldLayout == nil then + set(w, "worldLayout", "Free") + end + set(w, "levels", levels(ctx, list(l.layers))) + table.insert(worlds, w) + end + end + else + lvls = levels(ctx, map.layers) + end + if type(map.backgroundColor) == "string" then + set(p, "bgColor", map.backgroundColor) + end + if type(map.worldLayout) == "string" and not hasWorlds then + set(p, "worldLayout", map.worldLayout) + end + set(p, "externalLevels", false) + set(p, "defs", ctx.defs) + set(p, "levels", lvls) + set(p, "worlds", worlds) + if type(p.dummyWorldIid) ~= "string" then + set(p, "dummyWorldIid", newIid(ctx)) + end + set(p, "nextUid", ctx.uid + 1) + return p, nil +end + +return Write diff --git a/src/Rosetta/vector/ldtk/init.luau b/src/Rosetta/vector/ldtk/init.luau new file mode 100644 index 0000000..cdc139e --- /dev/null +++ b/src/Rosetta/vector/ldtk/init.luau @@ -0,0 +1,90 @@ +--!strict +-- vector/ldtk: LDtk projects (.ldtk JSON, ldtk.io/json, 1.x) as a TileMap, read + write. Supports: IntGrid, +-- AutoLayer, Tiles and Entities layers, tilesets as image paths, typed fields (properties), multi-world projects, +-- external levels (.ldtkl through opts.resolve). Not supported: auto-layer rules are kept, never run; writing +-- external level files (levels are embedded); standalone .ldtkl files. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = require("@rosetta/core/Err") +local Bytes = require("@rosetta/core/Bytes") +local Sniff = require("@rosetta/core/Sniff") +local Types = require("@rosetta/Types") +local Json = require("@rosetta/codecs/text/Json") +local Read = require("@rosetta/vector/ldtk/Read") +local Write = require("@rosetta/vector/ldtk/Write") + +-- ------------------------------------------------------------------------------------------------ contract +local Ldtk = { + name = "ldtk", + category = "vector", + extensions = { "ldtk" }, + mime = { "application/x-ldtk+json" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Json" }, + caps = { decode = true, encode = true, levels = true, worlds = true, intGrid = true, entities = true }, +} + +export type DecodeOptions = { + maxBytes: number?, -- default 2^28 + maxCells: number?, -- per layer, default 2^26 + resolve: ((string) -> buffer?)?, -- external .ldtkl level files by their relative path +} +export type EncodeOptions = { + indent: number?, -- default 2; 0 = compact +} + +-- ------------------------------------------------------------------------------------------------ sniff +function Ldtk.sniff(r: Bytes.Reader): number + local h = Sniff.text(r, 1024) + if not string.match(h, "^%s*{") then + return 0 + end + if string.find(h, "\"fileType\"%s*:%s*\"LDtk Project JSON\"") then + return 1 + end + if string.find(h, "\"jsonVersion\"", 1, true) and string.find(h, "\"worldLayout\"", 1, true) then + return 0.8 + end + return 0 +end + +-- ------------------------------------------------------------------------------------------------ decode +function Ldtk.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.TileMap?, Err.Err?) + local o: any = opts or {} + if r.limit - r.base > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local v, jerr = Json.decode(buffer.readstring(r.buf, r.base, r.limit - r.base), { ordered = true }) + if v == nil then + return nil, jerr + end + local ok, map, msg = pcall(Read.project, v, o) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad project: " .. tostring(map)) + end + if not map then + return nil, Err.from(msg) + end + return map, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +function Ldtk.encode(map: Types.TileMap, opts: EncodeOptions?): (buffer?, Err.Err?) + if type(map) ~= "table" or type(map.layers) ~= "table" or type(map.tilesets) ~= "table" then + return nil, Err.new(Err.ARG, "needs a TileMap value") + end + local ok, v, msg = pcall(Write.project, map, opts) + if not ok then + return nil, Err.new(Err.ARG, "bad map: " .. tostring(v)) + end + if v == nil then + return nil, Err.new(Err.ARG, msg or "bad map") + end + local indent = if opts and opts.indent == 0 then nil else (opts and opts.indent or 2) + local s, jerr = Json.encode(v, { indent = indent }) + if not s then + return nil, jerr + end + return buffer.fromstring(s), nil +end + +return Ldtk diff --git a/tests/vector/ldtk.luau b/tests/vector/ldtk.luau new file mode 100644 index 0000000..2971c61 --- /dev/null +++ b/tests/vector/ldtk.luau @@ -0,0 +1,278 @@ +-- vector/ldtk tests: LDtk's sample projects (and a multi-world one) against the editor's own JSON (levels, layers, +-- tile lists, IntGrid values, entities), external levels through resolve; our writer's output summarised by Python; +-- round trips; a TileMap from Tiled written as LDtk; errors; fuzz. Fixtures: tools/fixtures/ldtk.py. +local T = require("@tests/T") +local F = require("@rosetta") +local Ldtk = require("@rosetta/vector/ldtk") +local Bytes = require("@rosetta/core/Bytes") +local Err = require("@rosetta/core/Err") +local Types = require("@rosetta/Types") +local Fx = require("@tests/gen/ldtk") +local Ours = require("@tests/gen/ldtk_ours") + +local t = T.suite("ldtk") + +local function decode(s: string | buffer, opts: any?): (any, any) + local b = if type(s) == "string" then buffer.fromstring(s) else s + return Ldtk.decode(Bytes.reader(b), opts) +end + +t:eq(Ldtk.name, "ldtk", "name") +t:eq(Ldtk.category, "vector", "category") +t:check(Ldtk.caps.decode and Ldtk.caps.encode, "caps") + +local function levelsOf(map: any): { { group: any, world: string } } + local out = {} + for _, l in map.layers do + if l.world then + for _, lv in l.layers do + table.insert(out, { group = lv, world = l.name }) + end + else + table.insert(out, { group = l, world = "" }) + end + end + return out +end + +-- our TileMap summarised like tools/fixtures/ldtk.py summarises the JSON +local function stats(map: any): any + local levels = {} + for _, it in levelsOf(map) do + local g = it.group + local layers = {} + for _, l in g.layers do + local tl = l.tiles or {} + local sum, flips = 0, 0 + for i, x in tl do + sum += x.tile * ((i - 1) % 7 + 1) + if x.flip ~= 0 then + flips += 1 + end + end + local ic, is = 0, 0 + for _, v in l.intGrid or {} do + if v ~= 0 then + ic += 1 + end + is += v + end + local names, epx = {}, 0 + for _, o in l.objects or {} do + table.insert(names, o.class) + epx += (o.x + o.pivot[1] * o.width) * 3 + (o.y + o.pivot[2] * o.height) + end + table.insert(layers, { + identifier = l.name, + type = l.ldtkType, + cWid = l.width or 0, + cHei = l.height or 0, + grid = l.gridSize, + tiles = #tl, + tileSum = sum, + flips = flips, + intCount = ic, + intSum = is, + entities = #(l.objects or {}), + entityNames = table.concat(names, ","), + entityPx = epx, + }) + end + local nf = 0 + for _ in g.properties do + nf += 1 + end + table.insert(levels, { identifier = g.name, worldX = g.offsetX, worldY = g.offsetY, pxWid = g.pxWidth, pxHei = g.pxHeight, world = it.world, fields = nf, layers = layers }) + end + local ts = {} + for i, x in map.tilesets do + ts[i] = x.name + end + return { levels = levels, tilesets = ts } +end + +local function diff(a: any, b: any, path: string, out: { string }) + if #out > 6 then + return + end + if type(a) == "table" and type(b) == "table" then + for k, v in a do + diff(v, b[k], path .. "." .. tostring(k), out) + end + for k, v in b do + if a[k] == nil then + diff(nil, v, path .. "." .. tostring(k), out) + end + end + elseif a ~= b then + table.insert(out, path .. ": " .. tostring(a) .. " vs " .. tostring(b)) + end +end + +local function sameStats(got: any, want: any, label: string) + local out = {} + -- entity-less layers report cWid 0 in ours when unknown: compare only layers' known widths + for _, lv in got.levels do + for _, l in lv.layers do + if l.type == "Entities" then + l.cWid, l.cHei = nil, nil + end + end + end + for _, lv in want.levels do + for _, l in lv.layers do + if l.type == "Entities" then + l.cWid, l.cHei = nil, nil + end + end + end + diff(got, want, "", out) + t:check(#out == 0, label .. ": " .. table.concat(out, "; ")) +end + +local maps: { [string]: any } = {} +local samples = {} +for _, c in Fx.cases do + local function resolve(p: string): buffer? + local f = c.files[p] + return if f then buffer.fromstring(f) else nil + end + local map, err = decode(c.data, { resolve = resolve }) + t:check(map, c.name .. ": decode: " .. tostring(err)) + if map then + maps[c.name] = map + t:eq(map.kind, "tilemap", c.name .. ": kind") + sameStats(stats(map), c.stats, c.name .. ": = LDtk's JSON") + end + t:check(Ldtk.sniff(Bytes.reader(buffer.fromstring(c.data))) >= 0.8, c.name .. ": sniff") + if #c.data < 200000 then + table.insert(samples, c.data) + end +end + +-- Python's summary of our output = LDtk's +for _, o in Ours do + local want + for _, c in Fx.cases do + if c.name == o.name then + want = c.stats + end + end + sameStats(o.stats, want, o.name .. ": our LDtk output (Python)") +end + +-- details of the API sample +do + local m = maps["Test_file_for_API_showing_all_features.ldtk"] + t:eq(m.meta.source.version, "1.5.3", "json version") + local lv = m.layers[1] + t:check(lv.type == "group" and lv.level == true and lv.name ~= "", "level group") + local ents + for _, l in lv.layers do + if l.type == "objects" then + ents = l + end + end + t:check(ents and #ents.objects > 0, "entities layer") + local e = ents.objects[1] + t:eq(e.class, "EntityFieldsTest", "entity identifier") + t:eq(e.properties.Integer, 1, "Int field") + t:eq(e.properties.Float, 1.5, "Float field") + t:eq(e.properties.String_singleLine, "foo", "String field") + t:eq(e.propertyTypes.Enum, "LocalEnum.SomeEnum", "enum field type") + t:eq(e.properties.Color, "#D181E8", "Color field") + t:eq(e.x, 152 - 16, "entity x = px - pivot * width") + local top = lv.layers[#lv.layers] + t:eq(top.ldtkType, "Entities", "LDtk's first layer is drawn last") + local tiles + for _, l in lv.layers do + if l.ldtkType == "Tiles" then + tiles = l + end + end + local ts = m.tilesets[1] + t:eq(ts.imageSource, "atlas/Inca_front_by_Kronbits-extended.png", "tileset image path") + local first = tiles.tiles[1] + local cell = tiles.data[1 + first.x // 16 + (first.y // 16) * tiles.width] + t:check(bit32.band(cell, 0x0FFFFFFF) - ts.firstGid >= 0, "gid grid from the tile list") +end + +do + local m = maps["SeparateLevelFiles.ldtk"] + t:check(m.meta.source.externalLevels, "external levels flag") + t:check(m.layers[1].external and #m.layers[1].layers > 0, "external level loaded through resolve") + local c + for _, x in Fx.cases do + if x.name == "SeparateLevelFiles.ldtk" then + c = x + end + end + local nores = decode(c.data) + t:check(nores and nores.layers[1].unresolved and #nores.layers[1].layers == 0, "external level without resolve") +end + +do + local m = maps["multiworld.ldtk"] + t:check(m.meta.source.multiWorld and #m.layers == 2 and m.layers[1].world and m.layers[2].name == "Caves", "worlds") +end + +-- edits survive a save +do + local m = maps["Test_file_for_API_showing_all_features.ldtk"] + local lv = m.layers[1] + lv.properties = lv.properties or {} + local ents + for _, l in lv.layers do + if l.type == "objects" then + ents = l + end + end + ents.objects[1].properties.Integer = 42 + ents.objects[1].x += 16 + local out = assert(Ldtk.encode(m)) + local back = assert(decode(out)) + local e2 + for _, l in back.layers[1].layers do + if l.type == "objects" then + e2 = l.objects[1] + end + end + t:eq(e2.properties.Integer, 42, "edited field") + t:eq(e2.x, 152, "moved entity") + local s = buffer.tostring(out) + t:check(string.find(s, "\"V_Int\",%s*\"params\":%s*%[%s*42%s*%]") ~= nil, "realEditorValues updated") + t:check(F.detect(out) == "ldtk", "F.detect") +end + +-- a Tiled map as LDtk: a tile layer and objects +do + local map = Types.TileMap.new(3, 2, 16, 16) + table.insert(map.tilesets, { name = "terrain", firstGid = 1, tileWidth = 16, tileHeight = 16, columns = 4, count = 8, imageSource = "terrain.png", imageWidth = 64, imageHeight = 32 }) + table.insert(map.layers, { type = "tiles", name = "Ground", width = 3, height = 2, visible = true, opacity = 1, properties = {}, data = { 1, 2, 0, 0, 6, bit32.bor(8, 0x80000000) } }) + table.insert(map.layers, { type = "objects", name = "Things", visible = true, opacity = 1, properties = {}, objects = { { name = "spawn", class = "Spawn", x = 16, y = 0, width = 16, height = 16, properties = { hp = 3 } } } }) + local out = assert(F.save(map, nil, { format = "ldtk" })) + local back = assert(decode(out)) + local lv = back.layers[1] + t:eq(#lv.layers, 2, "tiled -> ldtk: one level, two layers") + local g = lv.layers[1] + t:eq(g.ldtkType, "Tiles", "tile layer") + t:eq(#g.tiles, 4, "tiles") + t:eq(g.data[6], bit32.bor(8, 0x80000000), "gid + flip") + t:eq(g.tiles[4].srcX, 48, "src x from the tileset columns") + local o = lv.layers[2].objects[1] + t:check(o.class == "Spawn" and o.x == 16 and o.properties.hp == 3, "entity with a made field definition") +end + +do + local _, e = decode("{\"jsonVersion\": \"1.5.3\"}") + t:check(e and e.code == Err.CORRUPT, "no defs") + local _, e2 = decode("{") + t:check(e2 ~= nil, "bad JSON") + local _, e3 = Ldtk.encode({} :: any) + t:check(e3 and e3.code == Err.ARG, "encode arg") +end + +t:fuzz("decode", function(b: buffer) + return decode(b) +end, samples, { mutations = 60, garbage = 20 }) +t:done() diff --git a/tools/fixtures/_ldtk_encode.luau b/tools/fixtures/_ldtk_encode.luau new file mode 100644 index 0000000..1dff7dd --- /dev/null +++ b/tools/fixtures/_ldtk_encode.luau @@ -0,0 +1,30 @@ +-- tools/fixtures/_ldtk_encode: run by tools/fixtures/ldtk.py (luau CLI, repo root): decodes every LDtk case (external +-- levels through resolve) and writes it with our encoder, printing "\t" lines for Python to summarise. +local Ldtk = require("@rosetta/vector/ldtk") +local Bytes = require("@rosetta/core/Bytes") +local Fx = require("@tests/gen/ldtk") + +local HEX = {} +for i = 0, 255 do + HEX[i] = string.format("%02x", i) +end +local function hex(s: string): string + return (string.gsub(s, ".", function(c: string): string + return HEX[string.byte(c)] + end)) +end + +for _, c in Fx.cases do + local map = Ldtk.decode(Bytes.reader(buffer.fromstring(c.data)), { + resolve = function(p: string): buffer? + local f = c.files[p] + return if f then buffer.fromstring(f) else nil + end, + }) + if map then + local out = Ldtk.encode(map) + if out then + print(c.name .. "\t" .. hex(buffer.tostring(out))) + end + end +end diff --git a/tools/fixtures/docs_engines.py b/tools/fixtures/docs_engines.py index 4a998f0..ad8ae97 100644 --- a/tools/fixtures/docs_engines.py +++ b/tools/fixtures/docs_engines.py @@ -1,9 +1,9 @@ # Docs inputs for the engine / level-editor sections of the scene, tile map, archive and data pages (tools/fixtures.py, -# tools/docs_check.py): the hand-written ASE of tools/fixtures/ase.py. +# tools/docs_check.py): the hand-written ASE of tools/fixtures/ase.py, LDtk's AutoLayers_2_stamps sample (tools/fixtures/ldtk.py). # tests/gen/docs_engines.luau { files = { [name] = bytes }, vars = { aseText = "hand.ase", ... } } import importlib.util, os -INPUTS = ["tools/docs_check.py", "tools/fixtures/ase.py"] +INPUTS = ["tools/docs_check.py", "tools/fixtures/ase.py", "tools/fixtures/ldtk.py"] def mod(ctx, name): @@ -16,5 +16,6 @@ def mod(ctx, name): def generate(ctx): check = mod(ctx, "../docs_check") files = {"hand.ase": mod(ctx, "ase").HAND.encode()} - vars = {"aseText": "hand.ase"} + files["stamps.ldtk"] = open(os.path.join(mod(ctx, "ldtk").samples_dir(ctx), "AutoLayers_2_stamps.ldtk"), "rb").read() + vars = {"aseText": "hand.ase", "ldtkText": "stamps.ldtk"} check.emit_inputs(ctx, files, vars) diff --git a/tools/fixtures/ldtk.py b/tools/fixtures/ldtk.py new file mode 100644 index 0000000..fce702e --- /dev/null +++ b/tools/fixtures/ldtk.py @@ -0,0 +1,111 @@ +# LDtk fixtures (tools/fixtures.py): the sample projects shipped with LDtk 1.5.3 (MIT; extraFiles/samples inside +# the nixpkgs ldtk AppImage, read there and never committed), including SeparateLevelFiles (.ldtkl external levels), +# plus a multi-world project made here from Typical_TopDown_example (its levels split over two worlds). Reference +# values are read from the LDtk JSON by Python (the editor's own export: __cWid / __identifier / tile and entity +# lists). Then our encoder's output (tools/fixtures/_ldtk_encode.luau) is summarised the same way. +# tests/gen/ldtk.luau { cases = { { name, data, files = { [relPath] = bytes }, stats } } } +# tests/gen/ldtk_ours.luau { { name, stats } } +# stats: { levels = { { identifier, worldX, worldY, pxWid, pxHei, world, fields, layers = { { identifier, type, cWid, +# cHei, grid, tiles, tileSum, flips, intCount, intSum, entities, entityNames, entityPx } } } }, tilesets = { names } } +import copy, importlib.util, json, os, subprocess, tempfile, zlib + +INPUTS = ["src/Rosetta/vector/ldtk", "tools/fixtures/_ldtk_encode.luau", "tools/fixtures/_model_ref.py"] + +SAMPLES = ["Test_file_for_API_showing_all_features.ldtk", "Typical_2D_platformer_example.ldtk", "Typical_TopDown_example.ldtk", + "Entities.ldtk", "AutoLayers_1_basic.ldtk", "AutoLayers_2_stamps.ldtk", "AutoLayers_4_Assistant.ldtk", + "AutoLayers_5_Advanced.ldtk", "SeparateLevelFiles.ldtk", "WorldMap_Free_layout.ldtk"] + + +def samples_dir(ctx): + store = subprocess.run(["nix", "build", "nixpkgs#ldtk", "--no-link", "--print-out-paths"], capture_output=True, check=True).stdout.decode().split()[-1] + image = os.path.join(store, "share", "ldtk.AppImage") + out = os.path.join(tempfile.gettempdir(), "rosetta-ldtk-" + os.path.basename(store)) + target = os.path.join(out, "sq", "extraFiles", "samples") + if os.path.isdir(target): + return target + os.makedirs(out, exist_ok=True) + data = open(image, "rb").read() + at = 0 + while True: + at = data.find(b"hsqs", at + 1) + if at < 0: + raise RuntimeError("no squashfs in the LDtk AppImage") + try: + ctx.nix("squashfsTools", ["unsquashfs", "-q", "-f", "-o", str(at), "-d", os.path.join(out, "sq"), image, "extraFiles/samples"]) + if os.path.isdir(target): + return target + except subprocess.CalledProcessError: + pass + + +def stats(project, files): + def levels_of(p): + if p.get("worlds"): + for w in p["worlds"]: + for lv in w["levels"]: + yield w["identifier"], lv + else: + for lv in p["levels"]: + yield "", lv + + out = [] + for world, lv in levels_of(project): + if lv.get("layerInstances") is None and lv.get("externalRelPath"): + lv = json.loads(files[lv["externalRelPath"]]) + layers = [] + for li in reversed(lv["layerInstances"] or []): + tl = li["gridTiles"] if li["__type"] == "Tiles" else li["autoLayerTiles"] + ents = li["entityInstances"] + ints = li["intGridCsv"] + layers.append({ + "identifier": li["__identifier"], "type": li["__type"], "cWid": li["__cWid"], "cHei": li["__cHei"], + "grid": li["__gridSize"], "tiles": len(tl), "tileSum": sum(t["t"] * (i % 7 + 1) for i, t in enumerate(tl)), + "flips": sum(1 for t in tl if t["f"]), "intCount": sum(1 for v in ints if v), "intSum": sum(ints), + "entities": len(ents), "entityNames": ",".join(e["__identifier"] for e in ents), + "entityPx": sum(e["px"][0] * 3 + e["px"][1] for e in ents), + }) + out.append({"identifier": lv["identifier"], "worldX": lv["worldX"], "worldY": lv["worldY"], "pxWid": lv["pxWid"], + "pxHei": lv["pxHei"], "world": world, "fields": len(lv["fieldInstances"]), "layers": layers}) + return {"levels": out, "tilesets": [t["identifier"] for t in project["defs"]["tilesets"]]} + + +def multiworld(project): + p = copy.deepcopy(project) + lv = p["levels"] + half = max(1, len(lv) // 2) + p["worlds"] = [ + {"iid": "a0000000-0000-4000-8000-000000000001", "identifier": "Overworld", "worldGridWidth": 256, "worldGridHeight": 256, + "worldLayout": "Free", "levels": lv[:half]}, + {"iid": "a0000000-0000-4000-8000-000000000002", "identifier": "Caves", "worldGridWidth": 256, "worldGridHeight": 256, + "worldLayout": "Free", "levels": lv[half:]}, + ] + p["levels"] = [] + p["flags"] = sorted(set(p.get("flags", [])) | {"MultiWorlds"}) + p["worldLayout"] = None + return p + + +def generate(ctx): + d = samples_dir(ctx) + cases = [] + for name in SAMPLES: + raw = open(os.path.join(d, name), "rb").read() + project = json.loads(raw) + files = {} + for lv in project["levels"]: + rel = lv.get("externalRelPath") + if rel: + files[rel] = open(os.path.join(d, rel), "rb").read() + cases.append({"name": name, "data": raw, "files": files, "stats": stats(project, files)}) + top = json.loads(open(os.path.join(d, "Typical_TopDown_example.ldtk"), "rb").read()) + mw = multiworld(top) + cases.append({"name": "multiworld.ldtk", "data": json.dumps(mw, indent=1).encode(), "files": {}, "stats": stats(mw, {})}) + ctx.emit("ldtk", {"cases": cases}) + spec = importlib.util.spec_from_file_location("_model_ref", os.path.join(ctx.root, "tools", "fixtures", "_model_ref.py")) + M = importlib.util.module_from_spec(spec) + spec.loader.exec_module(M) + ours = [] + for name, data in sorted(M.luau_encode(ctx, "tools/fixtures/_ldtk_encode.luau").items()): + p = json.loads(data) + ours.append({"name": name, "stats": stats(p, {})}) + ctx.emit("ldtk_ours", ours) From 9c02ebdee5be68027c6a096ac4c29cbe1bf7c3e2 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 19:00:07 -0600 Subject: [PATCH 05/10] vector/ogmo: Ogmo Editor 3 levels and projects read + write as a TileMap (tile / grid / entity / decal layers, every save layout, values; HaxeFlixel TurnBasedRPG sample, MIT) --- README.md | 3 +- docs/FORMATS.md | 1 + docs/guide/tilemap.md | 32 ++ licenses/NOTICE.md | 1 + licenses/flixel-demos-LICENSE.txt | 20 ++ src/Rosetta/Registry.luau | 12 + src/Rosetta/vector/ogmo/Read.luau | 403 ++++++++++++++++++++++++++ src/Rosetta/vector/ogmo/Write.luau | 352 ++++++++++++++++++++++ src/Rosetta/vector/ogmo/init.luau | 117 ++++++++ tests/fixtures/ogmo/room-001.json | 58 ++++ tests/fixtures/ogmo/turnBasedRPG.ogmo | 187 ++++++++++++ tests/vector/ogmo.luau | 212 ++++++++++++++ tools/fixtures/_ogmo_encode.luau | 28 ++ tools/fixtures/docs_engines.py | 9 +- tools/fixtures/ogmo.py | 165 +++++++++++ 15 files changed, 1596 insertions(+), 4 deletions(-) create mode 100644 licenses/flixel-demos-LICENSE.txt create mode 100644 src/Rosetta/vector/ogmo/Read.luau create mode 100644 src/Rosetta/vector/ogmo/Write.luau create mode 100644 src/Rosetta/vector/ogmo/init.luau create mode 100644 tests/fixtures/ogmo/room-001.json create mode 100644 tests/fixtures/ogmo/turnBasedRPG.ogmo create mode 100644 tests/vector/ogmo.luau create mode 100644 tools/fixtures/_ogmo_encode.luau create mode 100644 tools/fixtures/ogmo.py diff --git a/README.md b/README.md index 8809bb7..2cb925b 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ print(F.detect(webp), #F.formats()) -- "webp", the format list ## Formats -177 formats. Generated from the format contracts by `tools/gen_registry.py`; [docs/FORMATS.md](docs/FORMATS.md) +178 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 | @@ -195,6 +195,7 @@ adds each format's capabilities. | Data | xml | .xml .xsd .xsl .xslt .rss .atom .xhtml | yes | yes | | Data | yaml | .yaml .yml | yes | yes | | Vector graphics and tile maps | ldtk | .ldtk | yes | yes | +| Vector graphics and tile maps | ogmo | .ogmo | yes | yes | | Vector graphics and tile maps | svg | .svg | yes | yes | | Vector graphics and tile maps | tiled | .tmx .tmj .tsx .tsj | yes | yes | | Layered images | aseprite | .aseprite .ase | yes | yes | diff --git a/docs/FORMATS.md b/docs/FORMATS.md index 4259416..245e1dd 100644 --- a/docs/FORMATS.md +++ b/docs/FORMATS.md @@ -151,6 +151,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build | data | xml | .xml .xsd .xsl .xslt .rss .atom .xhtml | yes | yes | namespaces: true, streaming: true | `tests/data/xml.luau` | | data | yaml | .yaml .yml | yes | yes | ordered: true, multiDocument: true, anchors: true | `tests/data/yaml.luau` | | vector | ldtk | .ldtk | yes | yes | levels: true, worlds: true, intGrid: true, entities: true | `tests/vector/ldtk.luau` | +| vector | ogmo | .ogmo | yes | yes | projects: true, entities: true, decals: true | `tests/vector/ogmo.luau` | | vector | svg | .svg | yes | yes | rasterize: true, text: false | `tests/vector/svg.luau` | | vector | tiled | .tmx .tmj .tsx .tsj | yes | yes | tilesets: true, infinite: true | `tests/vector/tiled.luau` | | layered | aseprite | .aseprite .ase | yes | yes | layers: true, groups: true, animation: true, depths: 8, 16, 32 | `tests/layered/aseprite.luau` | diff --git a/docs/guide/tilemap.md b/docs/guide/tilemap.md index 8b04fcc..9146de3 100644 --- a/docs/guide/tilemap.md +++ b/docs/guide/tilemap.md @@ -240,6 +240,37 @@ local back = assert(F.load(ldtk)) assert(back.layers[1].layers[1].tiles[2].tile == 3) ``` +## Ogmo Editor 3 + +[Ogmo Editor 3](https://ogmo-editor-3.github.io) keeps a project (`.ogmo`: layer definitions, entity templates, +tilesets with their images embedded) and one JSON file per level. A level loads as a `TileMap`; pass its project as +`opts.project` (bytes or decoded JSON) to get the tilesets (gids), the map grid, entity template sizes and value +types. Without it tile layers keep `id + 1` as their gids. A project alone loads with `meta.project = true`, its +tilesets and one empty layer per definition. + +| Ogmo layer | `TileLayer` (`ogmoType`) | +|---|---| +| tile (ids or coords, 1D or 2D) | `"tiles"` (`"tile"`): `data` gids, `tileset`, the tile flags as Tiled flip bits | +| grid | `"tiles"` (`"grid"`): `grid` (the cell strings, `"0"` empty), `data` (their numbers), `legend` | +| entity | `"objects"` (`"entity"`): `x` / `y` top-left (position minus `originX` / `originY`), `width`, `height`, `rotation` in degrees, `flippedX` / `flippedY`, `nodes` (`{ { x, y } }`), values as `properties` | +| decal | `"objects"` (`"decal"`): `texture`, `x` / `y`, `scaleX` / `scaleY`, `rotation` in degrees, `originX` / `originY` | + +Ogmo's first layer is drawn on top, so the layers are reversed (bottom first, as everywhere in `TileMap`). Layers keep +their cell size (`cellWidth`, `cellHeight`) and save layout (`exportMode`, `arrayMode`). Tileset images stay bytes +(`tileset.imageData`, a PNG) next to their `imageSource` path. + +```luau +local map = assert(F.load(ogmoLevelText, { format = "ogmo", project = ogmoProjectText })) +assert(map.pxWidth == 640 and map.tileWidth == 8) -- the project's grid +local walls = map.layers[1] +assert(walls.ogmoType == "tile" and walls.tileset == "tiles" and walls.width == 40) +local things = map.layers[2] +assert(things.objects[1].class == "player" and things.objects[1].x == 128) +local level = assert(F.save(map, nil, { format = "ogmo" })) -- a level +local project = assert(F.save(map, nil, { format = "ogmo", kind = "project" })) -- a project for any map +assert(F.detect(project) == "ogmo") +``` + ## Formats | Format | Read | Write | Notes | @@ -247,6 +278,7 @@ assert(back.layers[1].layers[1].tiles[2].tile == 3) | TMX / TSX | yes | yes | CSV, base64 (raw, zlib, gzip) and `` data; zstd data returns `UNSUPPORTED` | | TMJ / TSJ | yes | yes | | | LDtk (`.ldtk`) | yes | yes | levels as groups, worlds, IntGrid / auto / tile / entity layers, fields; `.ldtkl` through `resolve`; writes embedded levels | +| Ogmo Editor 3 (`.ogmo`, level `.json`) | yes | yes | tile / grid / entity / decal layers, values; the project through `opts.project` | TMX and TMJ are both the `tiled` format in [FORMATS.md](../FORMATS.md) (Wang sets and terrains are dropped). diff --git a/licenses/NOTICE.md b/licenses/NOTICE.md index fb5e437..f3d8a08 100644 --- a/licenses/NOTICE.md +++ b/licenses/NOTICE.md @@ -29,6 +29,7 @@ | `tests/fixtures/pngsuite/` | PngSuite by Willem van Schaik | [PngSuite-LICENSE.txt](PngSuite-LICENSE.txt) | | `tests/fixtures/vox/{chr_knight,chr_sword,deer,maze}.vox`, `tests/fixtures/vox/MagicaVoxel-file-format-vox*.txt` (the format spec) | ephtracy/voxel-model (MagicaVoxel sample models) | MIT: [voxel-model-LICENSE.txt](voxel-model-LICENSE.txt) | | `tests/fixtures/vox/ogt_*.vox` | jpaver/opengametools `demo/vox/` (files saved by MagicaVoxel 0.99.x) | MIT: [opengametools-LICENSE.txt](opengametools-LICENSE.txt) | +| `tests/fixtures/ogmo/{turnBasedRPG.ogmo,room-001.json}` | HaxeFlixel/flixel-demos `Tutorials/TurnBasedRPG/assets/data/` (an Ogmo Editor 3.3 project and level) | MIT: [flixel-demos-LICENSE.txt](flixel-demos-LICENSE.txt) | | `tests/fixtures/gltf/` | KhronosGroup/glTF-Sample-Assets `Models/` (one LICENSE.md per model folder; `UnicodeTest` is `Unicode❤♻Test` renamed) | CC-BY-4.0 or CC0-1.0 per model, see each folder's LICENSE.md | | `src/Rosetta/codecs/Vp8/` (Decode, Yuv, Tables), `src/Rosetta/codecs/Vp8L/Decode.luau`, `src/Rosetta/image/webp/` (Alpha unfilters, Anim.coalesce) | ports of libwebp 1.6.0 (Google): src/dec, src/dsp, src/utils, src/demux/anim_decode.c | BSD-3-Clause + patent grant: [libwebp-LICENSE.txt](libwebp-LICENSE.txt) | | `src/Rosetta/codecs/Tracker/`, `src/Rosetta/music/{mod,s3m,xm,it}/` | written for this library from the format documents: ProTracker 2.3 effect docs, the XM specification (Mr.H / Triton) and FT2 behaviour notes, ST3 TECH.DOC (Sami Tammilehto / Future Crew), ITTECH.TXT (Jeffrey Lim); OpenMPT (libopenmpt, BSD) was used only as the reference player in the tests, and its documented playback quirks (mix levels, MOD panning, FT2 E6x / tremor / instrument behaviour) are matched | no third-party code | diff --git a/licenses/flixel-demos-LICENSE.txt b/licenses/flixel-demos-LICENSE.txt new file mode 100644 index 0000000..6308e93 --- /dev/null +++ b/licenses/flixel-demos-LICENSE.txt @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013 + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/src/Rosetta/Registry.luau b/src/Rosetta/Registry.luau index 5805e93..999cca5 100644 --- a/src/Rosetta/Registry.luau +++ b/src/Rosetta/Registry.luau @@ -1766,6 +1766,18 @@ local list: { Entry } = { return require("@rosetta/vector/ldtk") end, }, + { + name = "ogmo", + category = "vector", + path = "vector/ogmo", + extensions = { "ogmo" }, + mime = { "application/x-ogmo+json" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "core/Base64", "Types", "codecs/text/Json" }, + caps = { decode = true, encode = true, projects = true, entities = true, decals = true }, + load = function() + return require("@rosetta/vector/ogmo") + end, + }, { name = "svg", category = "vector", diff --git a/src/Rosetta/vector/ogmo/Read.luau b/src/Rosetta/vector/ogmo/Read.luau new file mode 100644 index 0000000..8d296d4 --- /dev/null +++ b/src/Rosetta/vector/ogmo/Read.luau @@ -0,0 +1,403 @@ +--!strict +-- vector/ogmo/Read: Ogmo Editor 3 projects (.ogmo) and levels (.json) into a Types.TileMap (layer save / load as in +-- OgmoEditor3-CE src/modules/*/ *Layer.hx). Ogmo's first layer is drawn on top: layers are reversed (bottom first). +-- Tile ids -1 are empty; tileFlags 4 / 2 / 1 (flip H / V / diagonal) become Tiled's 0x80000000 / 0x40000000 / +-- 0x20000000. +local Types = require("@rosetta/Types") +local Json = require("@rosetta/codecs/text/Json") +local Base64 = require("@rosetta/core/Base64") + +local Read = {} + +local NULL = Json.null +local FLIP_H, FLIP_V, FLIP_D = 0x80000000, 0x40000000, 0x20000000 + +local function tab(v: any): boolean + return type(v) == "table" and v ~= NULL +end +local function list(v: any): { any } + return if tab(v) then v else {} +end +local function n(v: any, default: number): number + return if type(v) == "number" and v == v then v else default +end +local function s(v: any): string? + return if type(v) == "string" then v else nil +end +local function vec(v: any, dx: number, dy: number): (number, number) + if tab(v) then + return n(v.x, dx), n(v.y, dy) + end + return dx, dy +end + +-- PNG IHDR width / height of an embedded tileset image (data: URI) +local function pngSize(b: buffer): (number?, number?) + if buffer.len(b) >= 24 and buffer.readstring(b, 0, 8) == "\137PNG\r\n\26\n" and buffer.readstring(b, 12, 4) == "IHDR" then + local function be(o: number): number + return buffer.readu8(b, o) * 16777216 + buffer.readu8(b, o + 1) * 65536 + buffer.readu8(b, o + 2) * 256 + buffer.readu8(b, o + 3) + end + return be(16), be(20) + end + return nil, nil +end + +local VALUE_TYPES: { [string]: string } = { Integer = "int", Float = "float", Boolean = "bool", Color = "color", Filepath = "file", String = "string", Text = "string", Enum = "string" } + +function Read.tilesets(project: any): { Types.Tileset } + local out: { Types.Tileset } = {} + local gid = 1 + for _, t in list(project and project.tilesets) do + if tab(t) then + local tw, th = math.max(1, n(t.tileWidth, 16)), math.max(1, n(t.tileHeight, 16)) + local sx, sy = n(t.tileSeparationX, 0), n(t.tileSeparationY, 0) + local mx, my = n(t.tileMarginX, 0), n(t.tileMarginY, 0) + local data: buffer? = nil + local iw, ih = nil, nil + if type(t.image) == "string" and string.sub(t.image, 1, 5) == "data:" then + data = Base64.decodeDataUri(t.image) + if data then + iw, ih = pngSize(data) + end + end + local cols = if iw then math.max(1, (iw - 2 * mx + sx) // (tw + sx)) else 1 + local rows = if ih then math.max(1, (ih - 2 * my + sy) // (th + sy)) else 1 + local ts: Types.Tileset = { + name = s(t.label) or ("tileset" .. #out), + firstGid = gid, + tileWidth = tw, + tileHeight = th, + columns = cols, + count = cols * rows, + imageSource = s(t.path), + imageWidth = iw, + imageHeight = ih, + imageData = data, + spacing = sx, + spacingY = if sy ~= sx then sy else nil, + margin = mx, + marginY = if my ~= mx then my else nil, + } + gid += ts.count + table.insert(out, ts) + end + end + return out +end + +local function valueTypes(defs: any): { [string]: string }? + local out: { [string]: string }? = nil + for _, d in list(defs) do + if tab(d) and type(d.name) == "string" and type(d.definition) == "string" then + local typ = VALUE_TYPES[d.definition] + if typ and typ ~= "string" then + out = out or {} + ;(out :: any)[d.name] = typ + end + end + end + return out +end + +local function values(v: any): { [string]: any } + local out: { [string]: any } = {} + if tab(v) then + for k, x in v do + if type(k) == "string" then + out[k] = x + end + end + end + return out +end + +type Ctx = { project: any, tilesets: { Types.Tileset }, byName: { [string]: Types.Tileset }, layerDefs: { [string]: any }, entityDefs: { [string]: any }, radians: boolean, maxCells: number } + +local function cells2D(v: any, w: number, h: number): { any } + local out = table.create(w * h) + for y, row in list(v) do + for x, c in list(row) do + if x <= w and y <= h then + out[(y - 1) * w + x] = c + end + end + end + return out +end + +local function tileLayer(ctx: Ctx, li: any, l: Types.TileLayer, w: number, h: number) + local ts = ctx.byName[s(li.tileset) or ""] or ctx.tilesets[1] + l.tileset = s(li.tileset) + local exportMode, arrayMode = n(li.exportMode, 0), n(li.arrayMode, 0) + local raw: { any } + if exportMode == 1 then + raw = if arrayMode == 1 then cells2D(li.dataCoords2D, w, h) else list(li.dataCoords) + else + raw = if arrayMode == 1 then cells2D(li.data2D, w, h) else list(li.data) + end + local flags = if arrayMode == 1 then cells2D(li.tileFlags2D, w, h) else list(li.tileFlags) + local data = table.create(w * h, 0) + for i = 1, w * h do + local c = raw[i] + local id = -1 + if exportMode == 1 then + if tab(c) and n(c[1], -1) >= 0 then + id = n(c[2], 0) * (if ts then ts.columns else 1) + n(c[1], 0) + end + else + id = n(c, -1) + end + if id >= 0 and ts then + local gid = ts.firstGid + id + local f = n(flags[i], 0) + if bit32.btest(f, 4) then + gid += FLIP_H + end + if bit32.btest(f, 2) then + gid += FLIP_V + end + if bit32.btest(f, 1) then + gid += FLIP_D + end + data[i] = gid + elseif id >= 0 then + data[i] = id + 1 + end + end + l.data = data +end + +local function entity(ctx: Ctx, e: any): { [string]: any } + local def = ctx.entityDefs[s(e.name) or ""] + local dw, dh = vec(def and def.size, 16, 16) + local dox, doy = vec(def and def.origin, 0, 0) + local w, h = n(e.width, dw), n(e.height, dh) + local ox, oy = n(e.originX, dox), n(e.originY, doy) + local rot = n(e.rotation, 0) + if ctx.radians then + rot = math.deg(rot) + end + local nodes = nil + if tab(e.nodes) then + nodes = {} + for i, p in e.nodes do + nodes[i] = { n(tab(p) and p.x, 0), n(tab(p) and p.y, 0) } + end + end + return { + id = e.id, + name = s(e.name) or "", + class = s(e.name) or "", + x = n(e.x, 0) - ox, + y = n(e.y, 0) - oy, + width = w, + height = h, + rotation = rot, + visible = true, + shape = "rectangle", + originX = ox, + originY = oy, + flippedX = if type(e.flippedX) == "boolean" then e.flippedX else nil, + flippedY = if type(e.flippedY) == "boolean" then e.flippedY else nil, + color = s(e.color), + nodes = nodes, + eid = s(e._eid), + properties = values(e.values), + propertyTypes = if def then valueTypes(def.values) else nil, + } +end + +local function decal(ctx: Ctx, d: any): { [string]: any } + local rot = n(d.rotation, 0) + if ctx.radians then + rot = math.deg(rot) + end + return { + name = s(d.texture) or "", + class = "decal", + shape = "decal", + texture = s(d.texture), + x = n(d.x, 0), + y = n(d.y, 0), + width = 0, + height = 0, + originX = n(d.originX, 0.5), + originY = n(d.originY, 0.5), + scaleX = n(d.scaleX, 1), + scaleY = n(d.scaleY, 1), + rotation = rot, + visible = true, + properties = values(d.values), + } +end + +local function layer(ctx: Ctx, li: any): (Types.TileLayer?, string?) + local name = s(li.name) or "" + local def = ctx.layerDefs[name] + local kind = (def and s(def.definition)) or (if li.entities ~= nil then "entity" + elseif li.decals ~= nil then "decal" + elseif li.grid ~= nil or li.grid2D ~= nil then "grid" + else "tile") + local w, h = n(li.gridCellsX, 0), n(li.gridCellsY, 0) + if w < 0 or h < 0 or w * h > ctx.maxCells then + return nil, "limit: layer of " .. w .. " x " .. h .. " cells" + end + local l: Types.TileLayer = { + name = name, + type = if kind == "entity" or kind == "decal" then "objects" else "tiles", + visible = true, + opacity = 1, + properties = {}, + offsetX = n(li.offsetX, 0), + offsetY = n(li.offsetY, 0), + ogmoType = kind, + cellWidth = n(li.gridCellWidth, 0), + cellHeight = n(li.gridCellHeight, 0), + eid = s(li._eid), + exportMode = if type(li.exportMode) == "number" then li.exportMode else nil, + arrayMode = if type(li.arrayMode) == "number" then li.arrayMode else nil, + } + if kind == "entity" then + local objs = {} + for _, e in list(li.entities) do + if tab(e) then + table.insert(objs, entity(ctx, e)) + end + end + l.objects = objs + elseif kind == "decal" then + local objs = {} + for _, d in list(li.decals) do + if tab(d) then + table.insert(objs, decal(ctx, d)) + end + end + l.objects = objs + l.folder = s(li.folder) + elseif kind == "grid" then + l.width, l.height = w, h + local raw = if n(li.arrayMode, 0) == 1 then cells2D(li.grid2D, w, h) else list(li.grid) + local grid = table.create(w * h, "0") + local data = table.create(w * h, 0) + for i = 1, w * h do + local c = raw[i] + local v = if type(c) == "string" then c elseif type(c) == "number" then tostring(c) else "0" + grid[i] = v + data[i] = tonumber(v) or 0 + end + l.grid = grid + l.data = data + if def and tab(def.legend) then + l.legend = values(def.legend) + end + else + l.width, l.height = w, h + tileLayer(ctx, li, l, w, h) + end + return l, nil +end + +local function context(project: any, opts: any): Ctx + local ts = Read.tilesets(project) + local ctx: Ctx = { project = project, tilesets = ts, byName = {}, layerDefs = {}, entityDefs = {}, radians = true, maxCells = opts.maxCells or 2 ^ 26 } + for _, t in ts do + ctx.byName[t.name] = t + end + if tab(project) then + ctx.radians = project.anglesRadians ~= false + for _, d in list(project.layers) do + if tab(d) and type(d.name) == "string" then + ctx.layerDefs[d.name] = d + end + end + for _, d in list(project.entities) do + if tab(d) and type(d.name) == "string" then + ctx.entityDefs[d.name] = d + end + end + end + return ctx +end + +local function gridSize(project: any, layers: { any }): (number, number) + if tab(project) and tab(project.layerGridDefaultSize) then + local x, y = vec(project.layerGridDefaultSize, 16, 16) + return math.max(1, x), math.max(1, y) + end + for _, l in layers do + if tab(l) and type(l.gridCellWidth) == "number" then + return math.max(1, l.gridCellWidth), math.max(1, n(l.gridCellHeight, l.gridCellWidth)) + end + end + return 16, 16 +end + +function Read.level(v: any, project: any, opts: any): (Types.TileMap?, string?) + if not tab(v) or not tab(v.layers) then + return nil, "no layers: not an Ogmo level" + end + local ctx = context(project, opts) + local tw, th = gridSize(project, v.layers) + local pw, ph = n(v.width, 0), n(v.height, 0) + local map = Types.TileMap.new(math.ceil(pw / tw), math.ceil(ph / th), tw, th) + map.tilesets = ctx.tilesets + map.pxWidth, map.pxHeight = pw, ph + map.offsetX, map.offsetY = n(v.offsetX, 0), n(v.offsetY, 0) + map.properties = values(v.values) + if tab(project) then + map.propertyTypes = valueTypes(project.levelValues) + end + local ls = v.layers + for i = #ls, 1, -1 do + if tab(ls[i]) then + local l, err = layer(ctx, ls[i]) + if not l then + return nil, err + end + table.insert(map.layers, l) + end + end + map.meta.source = { format = "ogmo", version = s(v.ogmoVersion), level = true, anglesRadians = ctx.radians } + if tab(project) then + map.ogmo = project + end + return map, nil +end + +function Read.project(v: any, opts: any): (Types.TileMap?, string?) + local ctx = context(v, opts) + local tw, th = gridSize(v, {}) + local lw, lh = vec(v.levelDefaultSize, 0, 0) + local map = Types.TileMap.new(math.ceil(lw / tw), math.ceil(lh / th), tw, th) + map.tilesets = ctx.tilesets + map.name = s(v.name) + map.backgroundColor = s(v.backgroundColor) + local defs = list(v.layers) + for i = #defs, 1, -1 do + local d = defs[i] + if tab(d) and type(d.name) == "string" then + local kind = s(d.definition) or "tile" + local gx, gy = vec(d.gridSize, tw, th) + local l: Types.TileLayer = { + name = d.name, + type = if kind == "entity" or kind == "decal" then "objects" else "tiles", + visible = true, + opacity = 1, + properties = {}, + ogmoType = kind, + cellWidth = gx, + cellHeight = gy, + eid = s(d.exportID), + tileset = s(d.defaultTileset), + } + table.insert(map.layers, l) + end + end + map.entities = list(v.entities) + map.ogmo = v + map.meta.source = { format = "ogmo", version = s(v.ogmoVersion), project = true, anglesRadians = ctx.radians } + map.meta.project = true + return map, nil +end + +return Read diff --git a/src/Rosetta/vector/ogmo/Write.luau b/src/Rosetta/vector/ogmo/Write.luau new file mode 100644 index 0000000..7677b38 --- /dev/null +++ b/src/Rosetta/vector/ogmo/Write.luau @@ -0,0 +1,352 @@ +--!strict +-- vector/ogmo/Write: a Types.TileMap as an Ogmo Editor 3 level (.json) or project (.ogmo), in the shapes Ogmo 3.4 +-- saves (Layer.save / TileLayer.save / GridLayer.save / Entity.save / Decal.save). A project read from Ogmo is +-- written back with its own definitions; otherwise layers, tilesets and entity templates are made from the map. +local Types = require("@rosetta/Types") +local Json = require("@rosetta/codecs/text/Json") +local Base64 = require("@rosetta/core/Base64") + +local Write = {} + +local NULL = Json.null +local FLAGS = 0xF0000000 +local VERSION = "3.4.0" + +local function tab(v: any): boolean + return type(v) == "table" and v ~= NULL +end +local function list(v: any): { any } + return if tab(v) then v else {} +end +local function n(v: any, default: number): number + return if type(v) == "number" and v == v then v else default +end + +-- key / value pairs; a nil value (an absent optional field) is skipped +local function obj(pairs_: { any }): any + local out, keys = {}, {} + local i = 1 + while pairs_[i] ~= nil do + if pairs_[i + 1] ~= nil then + table.insert(keys, pairs_[i]) + out[pairs_[i]] = pairs_[i + 1] + end + i += 2 + end + return Json.object(out, keys) +end + +local function values(props: any): any + local out = {} + local keys = {} + if tab(props) then + for k, v in props do + if type(k) == "string" then + out[k] = v + table.insert(keys, k) + end + end + end + table.sort(keys) + return Json.object(out, keys) +end + +local function eid(l: any, i: number): string + return if type(l.eid) == "string" then l.eid else tostring(10000000 + i) +end + +local function flat(layers: { any }, into: { any }) + for _, l in layers do + if l.type == "group" then + flat(list(l.layers), into) + elseif l.type == "tiles" or l.type == "objects" then + table.insert(into, l) + end + end +end + +local function tilesetOf(map: Types.TileMap, gid: number): Types.Tileset? + local best: Types.Tileset? = nil + for _, ts in map.tilesets do + if ts.firstGid <= gid and (best == nil or ts.firstGid > (best :: Types.Tileset).firstGid) then + best = ts + end + end + return best +end + +local function layerTileset(map: Types.TileMap, l: any): Types.Tileset? + if type(l.tileset) == "string" then + for _, ts in map.tilesets do + if ts.name == l.tileset then + return ts + end + end + end + for _, raw in list(l.data) do + local gid = bit32.band(n(raw, 0), bit32.bnot(FLAGS)) + if gid ~= 0 then + return tilesetOf(map, gid) + end + end + return map.tilesets[1] +end + +local function kindOf(l: any): string + if type(l.ogmoType) == "string" then + return l.ogmoType + elseif l.type == "objects" then + for _, o in list(l.objects) do + if o.shape == "decal" then + return "decal" + end + end + return "entity" + elseif tab(l.grid) then + return "grid" + end + return "tile" +end + +-- ------------------------------------------------------------------------------------------------ level +local function rows2D(flatList: { any }, w: number, h: number): { any } + local out = {} + for y = 1, h do + local row = {} + for x = 1, w do + row[x] = flatList[(y - 1) * w + x] + end + out[y] = row + end + return out +end + +local function tileLayer(map: Types.TileMap, l: any, i: number, gw: number, gh: number): any + local ts = layerTileset(map, l) + local w, h = n(l.width, math.ceil(n(map.pxWidth, map.width * map.tileWidth) / gw)), n(l.height, math.ceil(n(map.pxHeight, map.height * map.tileHeight) / gh)) + local ids, coords, flags = table.create(w * h, -1), table.create(w * h), table.create(w * h, 0) + local anyFlag = false + local data = list(l.data) + for k = 1, w * h do + local raw = n(data[k], 0) + local gid = bit32.band(raw, bit32.bnot(FLAGS)) + local id = -1 + if gid ~= 0 then + id = if ts then gid - ts.firstGid else gid - 1 + if ts and (id < 0 or id >= math.max(ts.count, 1)) then + id = -1 + end + end + ids[k] = id + if id >= 0 then + local cols = if ts then math.max(1, ts.columns) else 1 + coords[k] = { id % cols, id // cols } + local f = (if bit32.btest(raw, 0x80000000) then 4 else 0) + (if bit32.btest(raw, 0x40000000) then 2 else 0) + (if bit32.btest(raw, 0x20000000) then 1 else 0) + flags[k] = f + anyFlag = anyFlag or f ~= 0 + else + coords[k] = { -1 } + end + end + local exportMode, arrayMode = n(l.exportMode, 0), n(l.arrayMode, 0) + local fields: { any } = { + "name", l.name, "_eid", eid(l, i), "offsetX", n(l.offsetX, 0), "offsetY", n(l.offsetY, 0), "gridCellWidth", gw, + "gridCellHeight", gh, "gridCellsX", w, "gridCellsY", h, "tileset", if ts then ts.name else "", + } + local key = if exportMode == 1 then (if arrayMode == 1 then "dataCoords2D" else "dataCoords") else (if arrayMode == 1 then "data2D" else "data") + local body = if exportMode == 1 then coords else ids + table.insert(fields, key) + table.insert(fields, if arrayMode == 1 then rows2D(body, w, h) else body) + if anyFlag then + table.insert(fields, if arrayMode == 1 then "tileFlags2D" else "tileFlags") + table.insert(fields, if arrayMode == 1 then rows2D(flags, w, h) else flags) + end + table.insert(fields, "exportMode") + table.insert(fields, exportMode) + table.insert(fields, "arrayMode") + table.insert(fields, arrayMode) + return obj(fields) +end + +local function gridLayer(map: Types.TileMap, l: any, i: number, gw: number, gh: number): any + local w, h = n(l.width, map.width), n(l.height, map.height) + local cells = table.create(w * h, "0") + local grid, data = list(l.grid), list(l.data) + for k = 1, w * h do + local g = grid[k] + cells[k] = if type(g) == "string" then g else tostring(math.floor(n(data[k], 0))) + end + local arrayMode = n(l.arrayMode, 0) + return obj({ + "name", l.name, "_eid", eid(l, i), "offsetX", n(l.offsetX, 0), "offsetY", n(l.offsetY, 0), "gridCellWidth", gw, + "gridCellHeight", gh, "gridCellsX", w, "gridCellsY", h, + if arrayMode == 1 then "grid2D" else "grid", if arrayMode == 1 then rows2D(cells, w, h) else cells, + "arrayMode", arrayMode, + }) +end + +local function entities(l: any, i: number, gw: number, gh: number, w: number, h: number, radians: boolean): any + local out = {} + for k, o in list(l.objects) do + local ox, oy = n(o.originX, 0), n(o.originY, 0) + local nodes = nil + if tab(o.nodes) then + nodes = {} + for j, p in o.nodes do + nodes[j] = obj({ "x", n(p[1], 0), "y", n(p[2], 0) }) + end + end + local rot = n(o.rotation, 0) + table.insert(out, obj({ + "name", if type(o.class) == "string" and o.class ~= "" then o.class else (o.name or "entity"), + "id", if type(o.id) == "number" then o.id else k - 1, + "_eid", if type(o.eid) == "string" then o.eid else tostring(20000000 + k), + "x", n(o.x, 0) + ox, "y", n(o.y, 0) + oy, "width", n(o.width, gw), "height", n(o.height, gh), + "originX", ox, "originY", oy, "rotation", if radians then math.rad(rot) else rot, + "flippedX", o.flippedX, "flippedY", o.flippedY, "color", o.color, "nodes", nodes, + "values", if tab(o.properties) and next(o.properties) then values(o.properties) else nil, + })) + end + return obj({ + "name", l.name, "_eid", eid(l, i), "offsetX", n(l.offsetX, 0), "offsetY", n(l.offsetY, 0), "gridCellWidth", gw, + "gridCellHeight", gh, "gridCellsX", w, "gridCellsY", h, "entities", out, + }) +end + +local function decals(l: any, i: number, gw: number, gh: number, w: number, h: number, radians: boolean): any + local out = {} + for _, o in list(l.objects) do + local rot = n(o.rotation, 0) + table.insert(out, obj({ + "x", n(o.x, 0), "y", n(o.y, 0), "scaleX", n(o.scaleX, 1), "scaleY", n(o.scaleY, 1), + "rotation", if radians then math.rad(rot) else rot, "texture", o.texture or o.name or "", + "originX", n(o.originX, 0.5), "originY", n(o.originY, 0.5), + "values", if tab(o.properties) and next(o.properties) then values(o.properties) else nil, + })) + end + return obj({ + "name", l.name, "_eid", eid(l, i), "offsetX", n(l.offsetX, 0), "offsetY", n(l.offsetY, 0), "gridCellWidth", gw, + "gridCellHeight", gh, "gridCellsX", w, "gridCellsY", h, "decals", out, "folder", l.folder or "", + }) +end + +local function radiansOf(map: any): boolean + local src = if tab(map.meta) and tab(map.meta.source) then map.meta.source else {} + if type(src.anglesRadians) == "boolean" then + return src.anglesRadians + end + return true +end + +function Write.level(map: Types.TileMap): (any, string?) + local layers = {} + flat(map.layers, layers) + local radians = radiansOf(map) + local pw = n(map.pxWidth, map.width * map.tileWidth) + local ph = n(map.pxHeight, map.height * map.tileHeight) + local out = {} + for i = #layers, 1, -1 do + local l = layers[i] + local gw = n(l.cellWidth, map.tileWidth) + local gh = n(l.cellHeight, map.tileHeight) + local cw, ch = math.ceil(pw / math.max(gw, 1)), math.ceil(ph / math.max(gh, 1)) + local kind = kindOf(l) + local li + if kind == "entity" then + li = entities(l, i, gw, gh, cw, ch, radians) + elseif kind == "decal" then + li = decals(l, i, gw, gh, cw, ch, radians) + elseif kind == "grid" then + li = gridLayer(map, l, i, gw, gh) + else + li = tileLayer(map, l, i, gw, gh) + end + table.insert(out, li) + end + return obj({ + "ogmoVersion", if tab(map.meta) and tab(map.meta.source) and type(map.meta.source.version) == "string" then map.meta.source.version else VERSION, + "width", pw, "height", ph, "offsetX", n(map.offsetX, 0), "offsetY", n(map.offsetY, 0), + "values", if tab(map.properties) and next(map.properties) then values(map.properties) else nil, + "layers", out, + }), nil +end + +-- ------------------------------------------------------------------------------------------------ project +local function tileset(ts: any): any + local image = "" + if type(ts.imageData) == "buffer" then + image = Base64.dataUri(ts.imageData, "image/png") + end + return obj({ + "label", ts.name, "path", ts.imageSource or "", "image", image, "tileWidth", n(ts.tileWidth, 16), + "tileHeight", n(ts.tileHeight, 16), "tileSeparationX", n(ts.spacing, 0), "tileSeparationY", n(ts.spacingY, n(ts.spacing, 0)), + "tileMarginX", n(ts.margin, 0), "tileMarginY", n(ts.marginY, n(ts.margin, 0)), + }) +end + +local function entityTemplate(name: string, o: any, i: number): any + local w, h = math.max(1, n(o.width, 16)), math.max(1, n(o.height, 16)) + return obj({ + "exportID", tostring(30000000 + i), "name", name, "limit", -1, "size", obj({ "x", w, "y", h }), + "origin", obj({ "x", n(o.originX, 0), "y", n(o.originY, 0) }), "originAnchored", true, + "shape", obj({ "label", "Rectangle", "points", { + obj({ "x", -1, "y", -1 }), obj({ "x", 1, "y", -1 }), obj({ "x", -1, "y", 1 }), + obj({ "x", 1, "y", -1 }), obj({ "x", -1, "y", 1 }), obj({ "x", 1, "y", 1 }), + } }), + "color", if type(o.color) == "string" then o.color else "#ff0000ff", "tileX", false, "tileY", false, + "tileSize", obj({ "x", 16, "y", 16 }), "resizeableX", true, "resizeableY", true, "rotatable", true, + "rotationDegrees", 360, "canFlipX", true, "canFlipY", true, "canSetColor", false, "hasNodes", true, + "nodeLimit", 0, "nodeDisplay", 0, "nodeGhost", true, "tags", {}, "values", {}, + }) +end + +function Write.project(map: any): (any, string?) + if tab(map.ogmo) and map.meta and map.meta.project then + return map.ogmo, nil + end + local layers = {} + flat(map.layers, layers) + local defs = {} + local ents, seen = {}, {} + for i = #layers, 1, -1 do + local l = layers[i] + local kind = kindOf(l) + local gs = obj({ "x", n(l.cellWidth, map.tileWidth), "y", n(l.cellHeight, map.tileHeight) }) + local d: any + if kind == "tile" then + local ts = layerTileset(map, l) + d = obj({ "definition", "tile", "name", l.name, "gridSize", gs, "exportID", eid(l, i), "exportMode", n(l.exportMode, 0), "arrayMode", n(l.arrayMode, 0), "defaultTileset", if ts then ts.name else "" }) + elseif kind == "grid" then + local legend = if tab(l.legend) then values(l.legend) else obj({ "0", "#00000000", "1", "#000000ff" }) + d = obj({ "definition", "grid", "name", l.name, "gridSize", gs, "exportID", eid(l, i), "arrayMode", n(l.arrayMode, 0), "legend", legend }) + elseif kind == "decal" then + d = obj({ "definition", "decal", "name", l.name, "gridSize", gs, "exportID", eid(l, i), "folder", l.folder or "", "includeImageSequence", true, "scaleable", true, "rotatable", true, "values", {} }) + else + d = obj({ "definition", "entity", "name", l.name, "gridSize", gs, "exportID", eid(l, i), "requiredTags", {}, "excludedTags", {} }) + for _, o in list(l.objects) do + local name = if type(o.class) == "string" and o.class ~= "" then o.class else (o.name or "entity") + if not seen[name] then + seen[name] = true + table.insert(ents, entityTemplate(name, o, #ents)) + end + end + end + table.insert(defs, d) + end + local tss = {} + for _, ts in map.tilesets do + table.insert(tss, tileset(ts)) + end + local grid = obj({ "x", map.tileWidth, "y", map.tileHeight }) + local size = obj({ "x", n(map.pxWidth, map.width * map.tileWidth), "y", n(map.pxHeight, map.height * map.tileHeight) }) + return obj({ + "name", if type(map.name) == "string" then map.name else "Project", "ogmoVersion", VERSION, "levelPaths", { "." }, + "backgroundColor", if type(map.backgroundColor) == "string" then map.backgroundColor else "#282c34ff", + "gridColor", "#3c4049cc", "anglesRadians", radiansOf(map), "directoryDepth", 5, "layerGridDefaultSize", grid, + "levelDefaultSize", size, "levelMinSize", obj({ "x", 128, "y", 128 }), "levelMaxSize", obj({ "x", 4096, "y", 4096 }), + "levelValues", {}, "defaultExportMode", ".json", "compactExport", false, "externalScript", "", "playCommand", "", + "entityTags", {}, "layers", defs, "entities", ents, "tilesets", tss, + }), nil +end + +return Write diff --git a/src/Rosetta/vector/ogmo/init.luau b/src/Rosetta/vector/ogmo/init.luau new file mode 100644 index 0000000..5355dce --- /dev/null +++ b/src/Rosetta/vector/ogmo/init.luau @@ -0,0 +1,117 @@ +--!strict +-- vector/ogmo: Ogmo Editor 3 levels (.json) and projects (.ogmo) as a TileMap, read + write (OgmoEditor3-CE 3.x +-- save format). Supports: tile layers (ids / coords, 1D / 2D arrays, tile flags), grid layers, entity layers (origin, +-- rotation, flips, nodes, values), decal layers, level values; the project through opts.project for tilesets and +-- entity templates. Not supported: loading tileset images (embedded PNGs stay bytes: tileset.imageData). + +-- ------------------------------------------------------------------------------------------------ requires +local Err = require("@rosetta/core/Err") +local Bytes = require("@rosetta/core/Bytes") +local Sniff = require("@rosetta/core/Sniff") +local Types = require("@rosetta/Types") +local Json = require("@rosetta/codecs/text/Json") +local Read = require("@rosetta/vector/ogmo/Read") +local Write = require("@rosetta/vector/ogmo/Write") + +-- ------------------------------------------------------------------------------------------------ contract +local Ogmo = { + name = "ogmo", + category = "vector", + extensions = { "ogmo" }, + mime = { "application/x-ogmo+json" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "core/Base64", "Types", "codecs/text/Json" }, + caps = { decode = true, encode = true, projects = true, entities = true, decals = true }, +} + +export type DecodeOptions = { + maxBytes: number?, -- default 2^28 + maxCells: number?, -- per layer, default 2^26 + project: (string | buffer | { [string]: any })?, -- the .ogmo project of a level (bytes or decoded JSON) +} +export type EncodeOptions = { + kind: ("level" | "project")?, -- default: "project" for a map read from a .ogmo, else "level" + indent: number?, -- default 2; 0 = compact +} + +-- ------------------------------------------------------------------------------------------------ sniff +function Ogmo.sniff(r: Bytes.Reader): number + local h = Sniff.text(r, 2048) + if not string.match(h, "^%s*{") or not string.find(h, "\"ogmoVersion\"", 1, true) then + return 0 + end + if string.find(h, "\"layerGridDefaultSize\"", 1, true) or string.find(h, "\"levelPaths\"", 1, true) then + return 1 + end + return 0.9 +end + +-- ------------------------------------------------------------------------------------------------ decode +local function json(src: any): (any, Err.Err?) + if type(src) == "table" then + return src, nil + end + if type(src) ~= "string" and type(src) ~= "buffer" then + return nil, Err.new(Err.ARG, "project must be bytes or a table") + end + return Json.decode(src, { ordered = true }) +end + +function Ogmo.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.TileMap?, Err.Err?) + local o: any = opts or {} + if r.limit - r.base > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local v, jerr = Json.decode(buffer.readstring(r.buf, r.base, r.limit - r.base), { ordered = true }) + if v == nil then + return nil, jerr + end + if type(v) ~= "table" then + return nil, Err.new(Err.CORRUPT, "not a JSON object") + end + local isProject = v.layerGridDefaultSize ~= nil or v.levelPaths ~= nil or v.tilesets ~= nil and v.layers ~= nil and v.width == nil + local project: any = nil + if not isProject and o.project ~= nil then + local p, perr = json(o.project) + if p == nil then + return nil, perr + end + project = p + end + local run: (any, any) -> (any, string?) = if isProject then Read.project else function(x: any, oo: any): (any, string?) + return Read.level(x, project, oo) + end + local ok, map, msg = pcall(run, v, o) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad data: " .. tostring(map)) + end + if not map then + return nil, Err.from(msg) + end + return map, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +function Ogmo.encode(map: Types.TileMap, opts: EncodeOptions?): (buffer?, Err.Err?) + if type(map) ~= "table" or type(map.layers) ~= "table" or type(map.tilesets) ~= "table" then + return nil, Err.new(Err.ARG, "needs a TileMap value") + end + local kind = opts and opts.kind or (if type(map.meta) == "table" and map.meta.project then "project" else "level") + if kind ~= "level" and kind ~= "project" then + return nil, Err.new(Err.ARG, "kind must be level or project") + end + local ok, v, msg = pcall(if kind == "project" then Write.project else Write.level, map) + if not ok then + return nil, Err.new(Err.ARG, "bad map: " .. tostring(v)) + end + if v == nil then + return nil, Err.new(Err.ARG, msg or "bad map") + end + local indent = if opts and opts.indent == 0 then nil else (opts and opts.indent or 2) + local s, jerr = Json.encode(v, { indent = indent }) + if not s then + return nil, jerr + end + return buffer.fromstring(s), nil +end + +return Ogmo diff --git a/tests/fixtures/ogmo/room-001.json b/tests/fixtures/ogmo/room-001.json new file mode 100644 index 0000000..b99e25a --- /dev/null +++ b/tests/fixtures/ogmo/room-001.json @@ -0,0 +1,58 @@ +{ + "ogmoVersion": "3.3.0", + "width": 640, + "height": 480, + "offsetX": 0, + "offsetY": 0, + "layers": [ + { + "name": "entities", + "_eid": "40110095", + "offsetX": 0, + "offsetY": 0, + "gridCellWidth": 16, + "gridCellHeight": 16, + "gridCellsX": 40, + "gridCellsY": 30, + "entities": [ + {"name": "player", "id": 0, "_eid": "40117707", "x": 128, "y": 144, "originX": 0, "originY": 0}, + {"name": "coin", "id": 1, "_eid": "40304284", "x": 320, "y": 96, "originX": 0, "originY": 0}, + {"name": "coin", "id": 2, "_eid": "40304284", "x": 352, "y": 80, "originX": 0, "originY": 0}, + {"name": "coin", "id": 3, "_eid": "40304284", "x": 192, "y": 144, "originX": 0, "originY": 0}, + {"name": "coin", "id": 4, "_eid": "40304284", "x": 224, "y": 144, "originX": 0, "originY": 0}, + {"name": "coin", "id": 5, "_eid": "40304284", "x": 256, "y": 144, "originX": 0, "originY": 0}, + {"name": "coin", "id": 6, "_eid": "40304284", "x": 288, "y": 144, "originX": 0, "originY": 0}, + {"name": "coin", "id": 7, "_eid": "40304284", "x": 304, "y": 160, "originX": 0, "originY": 0}, + {"name": "coin", "id": 8, "_eid": "40304284", "x": 304, "y": 192, "originX": 0, "originY": 0}, + {"name": "coin", "id": 9, "_eid": "40304284", "x": 304, "y": 224, "originX": 0, "originY": 0}, + {"name": "coin", "id": 10, "_eid": "40304284", "x": 304, "y": 256, "originX": 0, "originY": 0}, + {"name": "coin", "id": 11, "_eid": "40304284", "x": 304, "y": 304, "originX": 0, "originY": 0}, + {"name": "coin", "id": 12, "_eid": "40304284", "x": 320, "y": 288, "originX": 0, "originY": 0}, + {"name": "coin", "id": 13, "_eid": "40304284", "x": 336, "y": 304, "originX": 0, "originY": 0}, + {"name": "coin", "id": 14, "_eid": "40304284", "x": 288, "y": 288, "originX": 0, "originY": 0}, + {"name": "coin", "id": 15, "_eid": "40304284", "x": 272, "y": 304, "originX": 0, "originY": 0}, + {"name": "coin", "id": 16, "_eid": "40304284", "x": 256, "y": 224, "originX": 0, "originY": 0}, + {"name": "coin", "id": 17, "_eid": "40304284", "x": 256, "y": 192, "originX": 0, "originY": 0}, + {"name": "coin", "id": 18, "_eid": "40304284", "x": 208, "y": 192, "originX": 0, "originY": 0}, + {"name": "coin", "id": 19, "_eid": "40304284", "x": 208, "y": 224, "originX": 0, "originY": 0}, + {"name": "enemy", "id": 20, "_eid": "40444291", "x": 304, "y": 112, "originX": 0, "originY": 0}, + {"name": "enemy", "id": 21, "_eid": "40444291", "x": 272, "y": 208, "originX": 0, "originY": 0}, + {"name": "boss", "id": 22, "_eid": "40444462", "x": 304, "y": 288, "originX": 0, "originY": 0} + ] + }, + { + "name": "walls", + "_eid": "40116503", + "offsetX": 0, + "offsetY": 0, + "gridCellWidth": 16, + "gridCellHeight": 16, + "gridCellsX": 40, + "gridCellsY": 30, + "tileset": "tiles", + "data": [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 1, 1, 1, 1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], + "exportMode": 0, + "arrayMode": 0 + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/ogmo/turnBasedRPG.ogmo b/tests/fixtures/ogmo/turnBasedRPG.ogmo new file mode 100644 index 0000000..ee52ccb --- /dev/null +++ b/tests/fixtures/ogmo/turnBasedRPG.ogmo @@ -0,0 +1,187 @@ +{ + "name": "HaxeFlixel Tutorial", + "ogmoVersion": "3.3.0", + "levelPaths": ["."], + "backgroundColor": "#282c34ff", + "gridColor": "#3c4049cc", + "anglesRadians": true, + "directoryDepth": 5, + "layerGridDefaultSize": {"x": 8, "y": 8}, + "levelDefaultSize": {"x": 320, "y": 240}, + "levelMinSize": {"x": 640, "y": 480}, + "levelMaxSize": {"x": 640, "y": 480}, + "levelValues": [], + "defaultExportMode": ".json", + "compactExport": false, + "externalScript": "", + "playCommand": "", + "entityTags": [], + "layers": [ + { + "definition": "entity", + "name": "entities", + "gridSize": {"x": 16, "y": 16}, + "exportID": "40110095", + "requiredTags": [], + "excludedTags": [] + }, + { + "definition": "tile", + "name": "walls", + "gridSize": {"x": 16, "y": 16}, + "exportID": "40116503", + "exportMode": 0, + "arrayMode": 0, + "defaultTileset": "tiles" + } + ], + "entities": [ + { + "exportID": "40117707", + "name": "player", + "limit": -1, + "size": {"x": 16, "y": 16}, + "origin": {"x": 0, "y": 0}, + "originAnchored": true, + "shape": { + "label": "Rectangle", + "points": [ + {"x": -1, "y": -1}, + {"x": 1, "y": -1}, + {"x": -1, "y": 1}, + {"x": 1, "y": -1}, + {"x": -1, "y": 1}, + {"x": 1, "y": 1} + ] + }, + "color": "#ff0000ff", + "tileX": false, + "tileY": false, + "tileSize": {"x": 16, "y": 16}, + "resizeableX": false, + "resizeableY": false, + "rotatable": false, + "rotationDegrees": 360, + "canFlipX": false, + "canFlipY": false, + "canSetColor": false, + "hasNodes": false, + "nodeLimit": 0, + "nodeDisplay": 0, + "nodeGhost": true, + "tags": [], + "values": [] + }, + { + "exportID": "40304284", + "name": "coin", + "limit": -1, + "size": {"x": 16, "y": 16}, + "origin": {"x": 0, "y": 0}, + "originAnchored": true, + "shape": { + "label": "Rectangle", + "points": [ + {"x": -1, "y": -1}, + {"x": 1, "y": -1}, + {"x": -1, "y": 1}, + {"x": 1, "y": -1}, + {"x": -1, "y": 1}, + {"x": 1, "y": 1} + ] + }, + "color": "#ffcc00ff", + "tileX": false, + "tileY": false, + "tileSize": {"x": 16, "y": 16}, + "resizeableX": false, + "resizeableY": false, + "rotatable": false, + "rotationDegrees": 360, + "canFlipX": false, + "canFlipY": false, + "canSetColor": false, + "hasNodes": false, + "nodeLimit": 0, + "nodeDisplay": 0, + "nodeGhost": true, + "tags": [], + "values": [] + }, + { + "exportID": "40444291", + "name": "enemy", + "limit": -1, + "size": {"x": 16, "y": 16}, + "origin": {"x": 0, "y": 0}, + "originAnchored": true, + "shape": { + "label": "Rectangle", + "points": [ + {"x": -1, "y": -1}, + {"x": 1, "y": -1}, + {"x": -1, "y": 1}, + {"x": 1, "y": -1}, + {"x": -1, "y": 1}, + {"x": 1, "y": 1} + ] + }, + "color": "#0dbc0aff", + "tileX": false, + "tileY": false, + "tileSize": {"x": 16, "y": 16}, + "resizeableX": false, + "resizeableY": false, + "rotatable": false, + "rotationDegrees": 360, + "canFlipX": false, + "canFlipY": false, + "canSetColor": false, + "hasNodes": false, + "nodeLimit": 0, + "nodeDisplay": 0, + "nodeGhost": true, + "tags": [], + "values": [] + }, + { + "exportID": "40444462", + "name": "boss", + "limit": -1, + "size": {"x": 16, "y": 16}, + "origin": {"x": 0, "y": 0}, + "originAnchored": true, + "shape": { + "label": "Rectangle", + "points": [ + {"x": -1, "y": -1}, + {"x": 1, "y": -1}, + {"x": -1, "y": 1}, + {"x": 1, "y": -1}, + {"x": -1, "y": 1}, + {"x": 1, "y": 1} + ] + }, + "color": "#00e3ffff", + "tileX": false, + "tileY": false, + "tileSize": {"x": 16, "y": 16}, + "resizeableX": false, + "resizeableY": false, + "rotatable": false, + "rotationDegrees": 360, + "canFlipX": false, + "canFlipY": false, + "canSetColor": false, + "hasNodes": false, + "nodeLimit": 0, + "nodeDisplay": 0, + "nodeGhost": true, + "tags": [], + "values": [] + } + ], + "tilesets": [ + {"label": "tiles", "path": "../images/tiles.png", "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAQCAYAAABQrvyxAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoV2luZG93cykiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6ODRBQjNDODZENDhCMTFFMzk5N0RDMzAxQTc5NEM5RkMiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6ODRBQjNDODdENDhCMTFFMzk5N0RDMzAxQTc5NEM5RkMiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4NEFCM0M4NEQ0OEIxMUUzOTk3REMzMDFBNzk0QzlGQyIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4NEFCM0M4NUQ0OEIxMUUzOTk3REMzMDFBNzk0QzlGQyIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PrOLMN8AAACUSURBVHja7JWhDoAgEEBPRrERbVYCX+If8Z8Eqo2IyYi7wOYYTncYuI3XD94bDKaUErSwWZtWY0izu3NAnc3zEhpBAVyIQvAeWuKPEEAAQ7I8IjjLswso5RHZq2iNUp7lFRoBI2AEQN+vEL5A+EM/MSvV7wm8ySNnjH0GfJGvRQhu8mWE/GPz2g/5hUVrkvw94hJgALO2Vr1s43dIAAAAAElFTkSuQmCC", "tileWidth": 16, "tileHeight": 16, "tileSeparationX": 0, "tileSeparationY": 0} + ] +} \ No newline at end of file diff --git a/tests/vector/ogmo.luau b/tests/vector/ogmo.luau new file mode 100644 index 0000000..d087a38 --- /dev/null +++ b/tests/vector/ogmo.luau @@ -0,0 +1,212 @@ +-- vector/ogmo tests: Ogmo Editor 3 levels (HaxeFlixel's TurnBasedRPG and levels made in every save layout) against a +-- Python reading of the editor's format; projects; our writer's output (level + project) read by the same Python; +-- round trips; errors; fuzz. Fixtures: tools/fixtures/ogmo.py. +local T = require("@tests/T") +local F = require("@rosetta") +local Ogmo = require("@rosetta/vector/ogmo") +local Bytes = require("@rosetta/core/Bytes") +local Err = require("@rosetta/core/Err") +local Types = require("@rosetta/Types") +local Fx = require("@tests/gen/ogmo") +local Ours = require("@tests/gen/ogmo_ours") + +local t = T.suite("ogmo") + +local function decode(s: string | buffer, opts: any?): (any, any) + local b = if type(s) == "string" then buffer.fromstring(s) else s + return Ogmo.decode(Bytes.reader(b), opts) +end + +t:eq(Ogmo.name, "ogmo", "name") +t:eq(Ogmo.category, "vector", "category") +t:check(Ogmo.caps.decode and Ogmo.caps.encode, "caps") + +local function fmt(v: number): string + if v == math.floor(v) then + return string.format("%d", v) + end + return string.format("%.6g", v) +end + +local function jsonValue(v: any): string + if type(v) == "string" then + return "\"" .. v .. "\"" + elseif type(v) == "boolean" then + return tostring(v) + end + return if v == math.floor(v) then string.format("%d", v) else string.format("%.17g", v) +end + +local function valuesStr(props: any): string + local keys = {} + for k in props do + table.insert(keys, k) + end + table.sort(keys) + local out = {} + for _, k in keys do + table.insert(out, k .. "=" .. jsonValue(props[k])) + end + return table.concat(out, ",") +end + +-- our TileMap summarised like tools/fixtures/ogmo.py summarises a level +local function stats(map: any): any + local layers = {} + for _, l in map.layers do + local d: any = { name = l.name, kind = l.ogmoType } + if l.ogmoType == "entity" then + d.items = {} + for _, o in l.objects do + table.insert(d.items, string.format("%s@%s,%s %sx%s r%d n%d %s", o.class, fmt(o.x), fmt(o.y), fmt(o.width), fmt(o.height), math.floor(o.rotation + 0.5), if o.nodes then #o.nodes else 0, valuesStr(o.properties))) + end + elseif l.ogmoType == "decal" then + d.items = {} + for _, o in l.objects do + table.insert(d.items, string.format("%s@%s,%s s%s,%s r%d", o.texture, fmt(o.x), fmt(o.y), fmt(o.scaleX), fmt(o.scaleY), math.floor(o.rotation + 0.5))) + end + elseif l.ogmoType == "grid" then + d.cells = table.concat(l.grid) + else + local ts + for _, x in map.tilesets do + if x.name == l.tileset then + ts = x + end + end + local ne, ids, fl = 0, 0, 0 + for k, g in l.data do + local gid = bit32.band(g, 0x0FFFFFFF) + local id = if gid == 0 then -1 else gid - (if ts then ts.firstGid else 1) + if id >= 0 then + ne += 1 + end + ids += (id + 1) * ((k - 1) % 7 + 1) + local f = (if bit32.btest(g, 0x80000000) then 4 else 0) + (if bit32.btest(g, 0x40000000) then 2 else 0) + (if bit32.btest(g, 0x20000000) then 1 else 0) + fl += f * ((k - 1) % 5 + 1) + end + d.tileset, d.nonEmpty, d.idSum, d.flagSum = l.tileset or "", ne, ids, fl + end + table.insert(layers, d) + end + return { width = map.pxWidth, height = map.pxHeight, values = valuesStr(map.properties), layers = layers } +end + +local function diff(a: any, b: any, path: string, out: { string }) + if #out > 6 then + return + end + if type(a) == "table" and type(b) == "table" then + for k, v in a do + diff(v, b[k], path .. "." .. tostring(k), out) + end + for k, v in b do + if a[k] == nil then + diff(nil, v, path .. "." .. tostring(k), out) + end + end + elseif a ~= b then + table.insert(out, path .. ": " .. tostring(a) .. " vs " .. tostring(b)) + end +end + +local function same(got: any, want: any, label: string) + -- w / h are compared through the layer data sizes + for _, x in { got, want } do + for _, l in x.layers do + l.w, l.h = nil, nil + end + end + local out = {} + diff(got, want, "", out) + t:check(#out == 0, label .. ": " .. table.concat(out, "; ")) +end + +local samples = {} +local maps = {} +for _, c in Fx.cases do + local map, err = decode(c.data, { project = c.project }) + t:check(map, c.name .. ": decode: " .. tostring(err)) + if map then + maps[c.name] = map + same(stats(map), c.stats, c.name .. ": = the editor's layout (Python)") + local out = assert(Ogmo.encode(map)) + local back = assert(decode(out, { project = c.project })) + same(stats(back), c.stats, c.name .. ": round trip") + end + t:eq(Ogmo.sniff(Bytes.reader(buffer.fromstring(c.data))), 0.9, c.name .. ": sniff level") + table.insert(samples, c.data) +end +for _, o in Ours do + local want + for _, c in Fx.cases do + if c.name == o.name then + want = c.stats + end + end + same(o.stats, want, o.name .. ": our level + project (Python)") +end +t:eq(#Ours, #Fx.cases, "every level written") + +for _, p in Fx.projects do + local m, err = decode(p.data) + t:check(m and m.meta.project, p.name .. ": project: " .. tostring(err)) + t:eq(Ogmo.sniff(Bytes.reader(buffer.fromstring(p.data))), 1, p.name .. ": sniff project") + if m then + local back = assert(decode(assert(Ogmo.encode(m)))) + t:check(back.meta.project and #back.layers == #m.layers and #back.tilesets == #m.tilesets, p.name .. ": project round trip") + end + table.insert(samples, p.data) +end + +do + local m = maps["made/level0"] + local ents + for _, l in m.layers do + if l.ogmoType == "entity" then + ents = l + end + end + local p = ents.objects[1] + t:check(p.class == "player" and p.x == 16 and p.y == 16 and p.width == 8 and p.height == 16, "entity: origin, template size") + t:check(math.abs(p.rotation - 90) < 1e-9 and p.flippedX == true and #p.nodes == 2, "entity: radians -> degrees, flip, nodes") + t:eq(p.propertyTypes.hp, "int", "entity value types from the template") + t:eq(m.propertyTypes.gravity, "float", "level value types") + t:eq(m.layers[#m.layers].ogmoType, "entity", "Ogmo's first layer is on top") + local small = m.tilesets[2] + t:check(small.columns == 3 and small.imageWidth == 36 and type(small.imageData) == "buffer", "tileset from the embedded PNG") + local rpg = maps["turnBasedRPG/room-001"] + t:check(rpg.width == 80 and rpg.tileWidth == 8 and rpg.pxWidth == 640, "map size from the project grid") + -- without the project: tiles keep their ids + local c = Fx.cases[1] + local bare = assert(decode(c.data)) + t:check(#bare.tilesets == 0 and bare.layers[1].data ~= nil, "level without a project") +end + +-- a Tiled-style map as an Ogmo level +do + local map = Types.TileMap.new(2, 2, 16, 16) + table.insert(map.tilesets, { name = "t", firstGid = 1, tileWidth = 16, tileHeight = 16, columns = 2, count = 4 }) + table.insert(map.layers, { type = "tiles", name = "ground", width = 2, height = 2, visible = true, opacity = 1, properties = {}, data = { 1, 0, bit32.bor(4, 0x80000000), 2 } }) + table.insert(map.layers, { type = "objects", name = "things", visible = true, opacity = 1, properties = {}, objects = { { class = "coin", x = 4, y = 6, width = 8, height = 8, properties = { value = 10 } } } }) + local out = assert(F.save(map, nil, { format = "ogmo" })) + local back = assert(decode(out, { project = assert(Ogmo.encode(map, { kind = "project" })) })) + t:eq(back.layers[1].data[3], bit32.bor(4, 0x80000000), "tile + flip") + t:check(back.layers[2].objects[1].properties.value == 10 and back.layers[2].objects[1].x == 4, "object") +end + +do + local _, e = decode("{\"ogmoVersion\": \"3.4.0\"}") + t:check(e and e.code == Err.CORRUPT, "no layers") + local _, e2 = decode("[1]") + t:check(e2 and e2.code == Err.CORRUPT, "not an object") + local _, e3 = Ogmo.encode({} :: any) + t:check(e3 and e3.code == Err.ARG, "encode arg") + local _, e4 = Ogmo.encode(maps["made/level0"], { kind = "x" :: any }) + t:check(e4 and e4.code == Err.ARG, "bad kind") +end + +t:fuzz("decode", function(b: buffer) + return decode(b, { project = Fx.projects[2].data }) +end, samples, { mutations = 60, garbage = 20 }) +t:done() diff --git a/tools/fixtures/_ogmo_encode.luau b/tools/fixtures/_ogmo_encode.luau new file mode 100644 index 0000000..ab33be7 --- /dev/null +++ b/tools/fixtures/_ogmo_encode.luau @@ -0,0 +1,28 @@ +-- tools/fixtures/_ogmo_encode: run by tools/fixtures/ogmo.py (luau CLI, repo root): decodes every Ogmo level with its +-- project and writes the level and a project made from the map with our encoder, printing ".json\t" and +-- ".ogmo\t" lines for Python to read. +local Ogmo = require("@rosetta/vector/ogmo") +local Bytes = require("@rosetta/core/Bytes") +local Fx = require("@tests/gen/ogmo") + +local HEX = {} +for i = 0, 255 do + HEX[i] = string.format("%02x", i) +end +local function hex(s: string): string + return (string.gsub(s, ".", function(c: string): string + return HEX[string.byte(c)] + end)) +end + +for _, c in Fx.cases do + local map = Ogmo.decode(Bytes.reader(buffer.fromstring(c.data)), { project = c.project }) + if map then + local lv = Ogmo.encode(map) + local pj = Ogmo.encode(map, { kind = "project" }) + if lv and pj then + print(c.name .. ".json\t" .. hex(buffer.tostring(lv))) + print(c.name .. ".ogmo\t" .. hex(buffer.tostring(pj))) + end + end +end diff --git a/tools/fixtures/docs_engines.py b/tools/fixtures/docs_engines.py index ad8ae97..9ea2794 100644 --- a/tools/fixtures/docs_engines.py +++ b/tools/fixtures/docs_engines.py @@ -1,9 +1,10 @@ # Docs inputs for the engine / level-editor sections of the scene, tile map, archive and data pages (tools/fixtures.py, -# tools/docs_check.py): the hand-written ASE of tools/fixtures/ase.py, LDtk's AutoLayers_2_stamps sample (tools/fixtures/ldtk.py). +# tools/docs_check.py): the hand-written ASE of tools/fixtures/ase.py, LDtk's AutoLayers_2_stamps sample (tools/fixtures/ldtk.py), +# HaxeFlixel's TurnBasedRPG Ogmo project and level (tests/fixtures/ogmo). # tests/gen/docs_engines.luau { files = { [name] = bytes }, vars = { aseText = "hand.ase", ... } } import importlib.util, os -INPUTS = ["tools/docs_check.py", "tools/fixtures/ase.py", "tools/fixtures/ldtk.py"] +INPUTS = ["tools/docs_check.py", "tools/fixtures/ase.py", "tools/fixtures/ldtk.py", "tests/fixtures/ogmo"] def mod(ctx, name): @@ -17,5 +18,7 @@ def generate(ctx): check = mod(ctx, "../docs_check") files = {"hand.ase": mod(ctx, "ase").HAND.encode()} files["stamps.ldtk"] = open(os.path.join(mod(ctx, "ldtk").samples_dir(ctx), "AutoLayers_2_stamps.ldtk"), "rb").read() - vars = {"aseText": "hand.ase", "ldtkText": "stamps.ldtk"} + for f in ("turnBasedRPG.ogmo", "room-001.json"): + files[f] = ctx.read("tests/fixtures/ogmo/" + f) + vars = {"aseText": "hand.ase", "ldtkText": "stamps.ldtk", "ogmoProjectText": "turnBasedRPG.ogmo", "ogmoLevelText": "room-001.json"} check.emit_inputs(ctx, files, vars) diff --git a/tools/fixtures/ogmo.py b/tools/fixtures/ogmo.py new file mode 100644 index 0000000..aeaa09f --- /dev/null +++ b/tools/fixtures/ogmo.py @@ -0,0 +1,165 @@ +# Ogmo Editor 3 fixtures (tools/fixtures.py): the HaxeFlixel TurnBasedRPG project + level (tests/fixtures/ogmo, MIT, +# saved by Ogmo 3.3), and a project + levels written here in the shapes OgmoEditor3-CE 3.4 saves (src/modules/*/ +# *Layer.hx save(): tile layers as ids / coords in 1D / 2D arrays with tileFlags, grid layers 1D / 2D, entities with +# origin, rotation (radians), flips, nodes and values, decals). Reference values come from a Python reading of the +# same layouts (what the editor's load() does). Then our encoder's output (tools/fixtures/_ogmo_encode.luau) is read +# by the same Python reader. +# tests/gen/ogmo.luau { cases = { { name, data, project, stats } }, projects = { { name, data } } } +# tests/gen/ogmo_ours.luau { { name, stats } } +import base64, importlib.util, json, math, os, struct, zlib + +INPUTS = ["tests/fixtures/ogmo", "src/Rosetta/vector/ogmo", "tools/fixtures/_ogmo_encode.luau", "tools/fixtures/_model_ref.py"] + + +def png(w, h): + def chunk(t, d): + return struct.pack(">I", len(d)) + t + d + struct.pack(">I", zlib.crc32(t + d) & 0xffffffff) + raw = b"".join(b"\0" + bytes((x * 7 + y * 3) & 255 for x in range(w * 3)) for y in range(h)) + return b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", w, h, 8, 2, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(raw)) + chunk(b"IEND", b"") + + +def project(): + uri = "data:image/png;base64," + base64.b64encode(png(64, 32)).decode() + uri2 = "data:image/png;base64," + base64.b64encode(png(36, 20)).decode() + return { + "name": "Rosetta test", "ogmoVersion": "3.4.0", "levelPaths": ["."], "backgroundColor": "#282c34ff", + "gridColor": "#3c4049cc", "anglesRadians": True, "directoryDepth": 5, "layerGridDefaultSize": {"x": 8, "y": 8}, + "levelDefaultSize": {"x": 64, "y": 48}, "levelMinSize": {"x": 8, "y": 8}, "levelMaxSize": {"x": 4096, "y": 4096}, + "levelValues": [{"name": "music", "definition": "String", "display": 0, "defaults": ""}, + {"name": "gravity", "definition": "Float", "display": 0, "defaults": 1, "bounded": False, "min": 0, "max": 100}], + "defaultExportMode": ".json", "compactExport": False, "externalScript": "", "playCommand": "", "entityTags": [], + "layers": [ + {"definition": "entity", "name": "things", "gridSize": {"x": 8, "y": 8}, "exportID": "11", "requiredTags": [], "excludedTags": []}, + {"definition": "decal", "name": "decor", "gridSize": {"x": 8, "y": 8}, "exportID": "12", "folder": "decals", "includeImageSequence": True, "scaleable": True, "rotatable": True, "values": []}, + {"definition": "tile", "name": "front", "gridSize": {"x": 8, "y": 8}, "exportID": "13", "exportMode": 1, "arrayMode": 1, "defaultTileset": "small"}, + {"definition": "grid", "name": "solid", "gridSize": {"x": 16, "y": 16}, "exportID": "14", "arrayMode": 1, "legend": {"0": "#00000000", "1": "#ffffffff", "w": "#0000ffff"}}, + {"definition": "grid", "name": "zones", "gridSize": {"x": 8, "y": 8}, "exportID": "15", "arrayMode": 0, "legend": {"0": "#00000000", "1": "#ff0000ff"}}, + {"definition": "tile", "name": "back", "gridSize": {"x": 8, "y": 8}, "exportID": "16", "exportMode": 0, "arrayMode": 0, "defaultTileset": "main"}, + ], + "entities": [ + {"exportID": "21", "name": "player", "limit": 1, "size": {"x": 8, "y": 16}, "origin": {"x": 4, "y": 16}, "originAnchored": True, + "shape": {"label": "Rectangle", "points": []}, "color": "#ff0000ff", "tileX": False, "tileY": False, "tileSize": {"x": 8, "y": 8}, + "resizeableX": False, "resizeableY": False, "rotatable": True, "rotationDegrees": 360, "canFlipX": True, "canFlipY": False, + "canSetColor": False, "hasNodes": True, "nodeLimit": 0, "nodeDisplay": 0, "nodeGhost": True, "tags": [], + "values": [{"name": "hp", "definition": "Integer", "display": 0, "defaults": 3, "bounded": False, "min": 0, "max": 100}, + {"name": "boss", "definition": "Boolean", "display": 0, "defaults": False}]}, + {"exportID": "22", "name": "door", "limit": -1, "size": {"x": 8, "y": 8}, "origin": {"x": 0, "y": 0}, "originAnchored": True, + "shape": {"label": "Rectangle", "points": []}, "color": "#00ff00ff", "tileX": False, "tileY": False, "tileSize": {"x": 8, "y": 8}, + "resizeableX": True, "resizeableY": True, "rotatable": False, "rotationDegrees": 360, "canFlipX": False, "canFlipY": False, + "canSetColor": False, "hasNodes": False, "nodeLimit": 0, "nodeDisplay": 0, "nodeGhost": True, "tags": [], "values": []}, + ], + "tilesets": [ + {"label": "main", "path": "tiles/main.png", "image": uri, "tileWidth": 8, "tileHeight": 8, "tileSeparationX": 0, "tileSeparationY": 0, "tileMarginX": 0, "tileMarginY": 0}, + {"label": "small", "path": "tiles/small.png", "image": uri2, "tileWidth": 8, "tileHeight": 8, "tileSeparationX": 1, "tileSeparationY": 1, "tileMarginX": 1, "tileMarginY": 1}, + ], + } + + +def level(rng, w, h): + cx, cy = w // 8, h // 8 + ids = [(-1 if rng.random() < 0.3 else rng.randrange(32)) for _ in range(cx * cy)] + flags = [(rng.choice([0, 0, 0, 4, 2, 1, 6]) if t >= 0 else 0) for t in ids] + # "small": (36 - 2 + 1) // 9 = 3 columns, 2 rows + coords = [[-1] if rng.random() < 0.5 else [rng.randrange(3), rng.randrange(2)] for _ in range(cx * cy)] + rows = lambda flat, n: [flat[i * n:(i + 1) * n] for i in range(len(flat) // n)] + gx, gy = w // 16, h // 16 + solid = [rng.choice("001w") for _ in range(gx * gy)] + zones = [rng.choice("0001") for _ in range(cx * cy)] + base = {"offsetX": 0, "offsetY": 0} + return { + "ogmoVersion": "3.4.0", "width": w, "height": h, "offsetX": 0, "offsetY": 0, + "values": {"music": "cave.ogg", "gravity": 9.5}, + "layers": [ + dict(name="things", _eid="11", gridCellWidth=8, gridCellHeight=8, gridCellsX=cx, gridCellsY=cy, **base, entities=[ + {"name": "player", "id": 0, "_eid": "21", "x": 20, "y": 32, "originX": 4, "originY": 16, "rotation": math.pi / 2, + "flippedX": True, "nodes": [{"x": 40, "y": 32}, {"x": 48, "y": 8}], "values": {"hp": 5, "boss": False}}, + {"name": "door", "id": 1, "_eid": "22", "x": 8, "y": 0, "width": 16, "height": 24, "originX": 0, "originY": 0}, + ]), + dict(name="decor", _eid="12", gridCellWidth=8, gridCellHeight=8, gridCellsX=cx, gridCellsY=cy, **base, decals=[ + {"x": 12, "y": 14, "scaleX": 2, "scaleY": 1, "rotation": math.pi, "texture": "tree.png", "originX": 0.5, "originY": 1}, + ], folder="decals"), + dict(name="front", _eid="13", gridCellWidth=8, gridCellHeight=8, gridCellsX=cx, gridCellsY=cy, **base, tileset="small", + dataCoords2D=rows(coords, cx), exportMode=1, arrayMode=1), + dict(name="solid", _eid="14", gridCellWidth=16, gridCellHeight=16, gridCellsX=gx, gridCellsY=gy, **base, grid2D=rows(solid, gx), arrayMode=1), + dict(name="zones", _eid="15", gridCellWidth=8, gridCellHeight=8, gridCellsX=cx, gridCellsY=cy, **base, grid=zones, arrayMode=0), + dict(name="back", _eid="16", gridCellWidth=8, gridCellHeight=8, gridCellsX=cx, gridCellsY=cy, **base, tileset="main", data=ids, + tileFlags=flags, exportMode=0, arrayMode=0), + ], + } + + +def flat(v2): + return [c for row in v2 for c in row] + + +def stats(lv, proj): + """what Ogmo's load() reads, summarised; layers bottom first""" + radians = proj.get("anglesRadians", True) if proj else True + tsets = {t["label"]: t for t in (proj or {}).get("tilesets", [])} + defs = {e["name"]: e for e in (proj or {}).get("entities", [])} + out = [] + for li in reversed(lv["layers"]): + d = {"name": li["name"], "w": li["gridCellsX"], "h": li["gridCellsY"]} + if "entities" in li: + ents = [] + for e in li["entities"]: + t = defs.get(e["name"], {}) + rot = e.get("rotation", 0) + ents.append("%s@%g,%g %gx%g r%d n%d %s" % (e["name"], e["x"] - e.get("originX", 0), e["y"] - e.get("originY", 0), + e.get("width", t.get("size", {}).get("x", 16)), e.get("height", t.get("size", {}).get("y", 16)), + round(math.degrees(rot) if radians else rot), len(e.get("nodes", [])), + ",".join("%s=%s" % (k, json.dumps(v)) for k, v in sorted(e.get("values", {}).items())))) + d["kind"], d["items"] = "entity", ents + elif "decals" in li: + d["kind"] = "decal" + d["items"] = ["%s@%g,%g s%g,%g r%d" % (x["texture"], x["x"], x["y"], x.get("scaleX", 1), x.get("scaleY", 1), + round(math.degrees(x.get("rotation", 0)) if radians else x.get("rotation", 0))) for x in li["decals"]] + elif "grid" in li or "grid2D" in li: + d["kind"] = "grid" + d["cells"] = "".join(str(c) for c in (li["grid"] if "grid" in li else flat(li["grid2D"]))) + else: + d["kind"] = "tile" + ts = tsets.get(li.get("tileset")) + cols = 1 + if ts: + img = base64.b64decode(ts["image"].split(",", 1)[1]) + iw = struct.unpack(">I", img[16:20])[0] + sx, mx = ts.get("tileSeparationX", 0), ts.get("tileMarginX", 0) + cols = max(1, (iw - 2 * mx + sx) // (ts["tileWidth"] + sx)) + if li.get("exportMode", 0) == 1: + cells = li["dataCoords"] if li.get("arrayMode", 0) == 0 else flat(li["dataCoords2D"]) + ids = [-1 if c[0] == -1 else c[1] * cols + c[0] for c in cells] + else: + ids = li["data"] if li.get("arrayMode", 0) == 0 else flat(li["data2D"]) + fl = li.get("tileFlags") or (flat(li["tileFlags2D"]) if "tileFlags2D" in li else [0] * len(ids)) + d["tileset"] = li.get("tileset", "") + d["nonEmpty"] = sum(1 for i in ids if i >= 0) + d["idSum"] = sum((i + 1) * (k % 7 + 1) for k, i in enumerate(ids)) + d["flagSum"] = sum(f * (k % 5 + 1) for k, f in enumerate(fl)) + out.append(d) + return {"width": lv["width"], "height": lv["height"], "values": ",".join("%s=%s" % (k, json.dumps(v)) for k, v in sorted(lv.get("values", {}).items())), "layers": out} + + +def generate(ctx): + rng = ctx.rng(11) + src = os.path.join(ctx.root, "tests", "fixtures", "ogmo") + rpg_proj = open(os.path.join(src, "turnBasedRPG.ogmo"), "rb").read() + rpg_lvl = open(os.path.join(src, "room-001.json"), "rb").read() + proj = project() + proj_bytes = json.dumps(proj, indent=2).encode() + cases = [{"name": "turnBasedRPG/room-001", "data": rpg_lvl, "project": rpg_proj, "stats": stats(json.loads(rpg_lvl), json.loads(rpg_proj))}] + for i, (w, h) in enumerate([(64, 48), (128, 32)]): + lv = level(rng, w, h) + cases.append({"name": "made/level%d" % i, "data": json.dumps(lv).encode(), "project": proj_bytes, "stats": stats(lv, proj)}) + projects = [{"name": "turnBasedRPG.ogmo", "data": rpg_proj}, {"name": "made.ogmo", "data": proj_bytes}] + ctx.emit("ogmo", {"cases": cases, "projects": projects}) + spec = importlib.util.spec_from_file_location("_model_ref", os.path.join(ctx.root, "tools", "fixtures", "_model_ref.py")) + M = importlib.util.module_from_spec(spec) + spec.loader.exec_module(M) + ours = [] + out = M.luau_encode(ctx, "tools/fixtures/_ogmo_encode.luau") + for c in cases: + lv, pj = out.get(c["name"] + ".json"), out.get(c["name"] + ".ogmo") + if lv and pj: + ours.append({"name": c["name"], "stats": stats(json.loads(lv), json.loads(pj))}) + ctx.emit("ogmo_ours", ours) From 8f26e32a716eced11e9cb60e79c0da5bc514af20 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 19:25:15 -0600 Subject: [PATCH 06/10] model/godot + data/tres + codecs/text/GodotVariant: Godot text scenes (.tscn / .escn) read + write against Godot 4's loader, .tres resources as data docs/STYLE.md: the layout block lists codecs/text/GodotVariant (DOCS lint). --- README.md | 6 +- docs/FORMATS.md | 3 + docs/STYLE.md | 2 +- docs/guide/data.md | 24 + docs/guide/scene.md | 35 ++ licenses/NOTICE.md | 1 + licenses/godot-LICENSE.txt | 20 + src/Rosetta/Registry.luau | 24 + src/Rosetta/codecs/text/GodotVariant.luau | 657 ++++++++++++++++++++++ src/Rosetta/data/tres/init.luau | 143 +++++ src/Rosetta/model/godot/Build.luau | 540 ++++++++++++++++++ src/Rosetta/model/godot/Primitives.luau | 273 +++++++++ src/Rosetta/model/godot/Surface.luau | 483 ++++++++++++++++ src/Rosetta/model/godot/Write.luau | 327 +++++++++++ src/Rosetta/model/godot/init.luau | 89 +++ tests/codecs/godotvariant.luau | 47 ++ tests/data/tres.luau | 100 ++++ tests/model/godot.luau | 356 ++++++++++++ tools/fixtures/_godot_dump.gd | 80 +++ tools/fixtures/_godot_encode.luau | 45 ++ tools/fixtures/_godot_make.gd | 120 ++++ tools/fixtures/_godot_tres.gd | 15 + tools/fixtures/docs_engines.py | 40 +- tools/fixtures/godot.py | 224 ++++++++ 24 files changed, 3649 insertions(+), 5 deletions(-) create mode 100644 licenses/godot-LICENSE.txt create mode 100644 src/Rosetta/codecs/text/GodotVariant.luau create mode 100644 src/Rosetta/data/tres/init.luau create mode 100644 src/Rosetta/model/godot/Build.luau create mode 100644 src/Rosetta/model/godot/Primitives.luau create mode 100644 src/Rosetta/model/godot/Surface.luau create mode 100644 src/Rosetta/model/godot/Write.luau create mode 100644 src/Rosetta/model/godot/init.luau create mode 100644 tests/codecs/godotvariant.luau create mode 100644 tests/data/tres.luau create mode 100644 tests/model/godot.luau create mode 100644 tools/fixtures/_godot_dump.gd create mode 100644 tools/fixtures/_godot_encode.luau create mode 100644 tools/fixtures/_godot_make.gd create mode 100644 tools/fixtures/_godot_tres.gd create mode 100644 tools/fixtures/godot.py diff --git a/README.md b/README.md index 2cb925b..143cb55 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) +180 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 | @@ -114,6 +114,7 @@ adds each format's capabilities. | 3D models | dae | .dae .zae | yes | yes | | 3D models | fbx | .fbx | yes | yes | | 3D models | gltf | .gltf .glb | yes | yes | +| 3D models | godot | .tscn .escn | yes | yes | | 3D models | iqm | .iqm | yes | yes | | 3D models | ldraw | .ldr .mpd .dat | yes | - | | 3D models | lwo | .lwo .lxo | yes | - | @@ -192,6 +193,7 @@ adds each format's capabilities. | Data | plist | .plist | yes | yes | | Data | snbt | .snbt | yes | yes | | Data | toml | .toml | yes | yes | +| Data | tres | .tres | yes | yes | | Data | xml | .xml .xsd .xsl .xslt .rss .atom .xhtml | yes | yes | | Data | yaml | .yaml .yml | yes | yes | | Vector graphics and tile maps | ldtk | .ldtk | yes | yes | @@ -243,7 +245,7 @@ Shared by the formats, not loadable on their own (`src/Rosetta/codecs//` | font | Bitmap, Cff, GlyphNames, TrueType | | image | Bcn, Blend, Dct, Etc, Half, Jpeg, Pixels, Quantize, Raster, Texel, Texture, Vp8, Vp8L, Yuv | | model | Draco, Mat4, MeshFlatten, Minecraft, Polygon, Rbx, Rig, Sampler, Vrml | -| text | Json, Nbt, Text, Url, Xml | +| text | GodotVariant, Json, Nbt, Text, Url, Xml | | video | Dsp, H263, H264, Legacy, Mpeg1, Mpeg2, Theora, Video | | containers | Archive, AudioWrap, Avi, Chunks, Cpio, Demux, Ebml, Fat, Iso9660, IsoBmff, MacFile, MpegEs, MpegPs, MpegTs, Ogg, Riff, Tar, Zip | diff --git a/docs/FORMATS.md b/docs/FORMATS.md index 245e1dd..e47a002 100644 --- a/docs/FORMATS.md +++ b/docs/FORMATS.md @@ -70,6 +70,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build | model | dae | .dae .zae | yes | yes | materials: true, polygons: true, skins: true, morphTargets: true, animation: true, cameras: true, lights: true, zae: true | `tests/model/dae.luau` | | model | fbx | .fbx | yes | yes | binary: true, ascii: true, materials: true, animation: true, skins: true, morphTargets: true, cameras: true, lights: true, polygons: true | `tests/model/fbx.luau` | | model | gltf | .gltf .glb | yes | yes | binary: true, materials: true, animation: true, skins: true, morphTargets: true, cameras: true, lights: true, draco: true | `tests/model/gltf.luau` | +| model | godot | .tscn .escn | yes | yes | text: true, materials: true, cameras: true, lights: true, instances: true | `tests/model/godot.luau` | | 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` | @@ -148,6 +149,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build | data | plist | .plist | yes | yes | binary: "read", ordered: true | `tests/data/plist.luau` | | data | snbt | .snbt | yes | yes | ordered: true, typed: true | `tests/data/snbt.luau` | | data | toml | .toml | yes | yes | ordered: true, dates: true | `tests/data/toml.luau` | +| data | tres | .tres | yes | yes | ordered: true | `tests/data/tres.luau` | | data | xml | .xml .xsd .xsl .xslt .rss .atom .xhtml | yes | yes | namespaces: true, streaming: true | `tests/data/xml.luau` | | data | yaml | .yaml .yml | yes | yes | ordered: true, multiDocument: true, anchors: true | `tests/data/yaml.luau` | | vector | ldtk | .ldtk | yes | yes | levels: true, worlds: true, intGrid: true, entities: true | `tests/vector/ldtk.luau` | @@ -259,6 +261,7 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain: - codecs/model/Sampler: Scene animation sampling, STEP / LINEAR (slerp) / CUBICSPLINE as in glTF 2.0 animations. New code. - codecs/model/Vrml: VRML97 / X3D scene-graph engine (classic and XML encodings) for model/vrml and model/x3d. - **text** + - codecs/text/GodotVariant: Godot's text resource syntax (.tscn / .tres / .escn, formats 2-4; Godot's - codecs/text/Json: JSON (RFC 8259 / ECMA-404) parse and serialize, the engine data/json, glTF, TMJ, ... use. New code. - codecs/text/Nbt: Minecraft's Named Binary Tag format and SNBT (Minecraft wiki "NBT format", wiki.vg "NBT"). - codecs/text/Text: text decoding helpers: BOM stripping, Windows-1252 for text that is not UTF-8, line splitting. diff --git a/docs/STYLE.md b/docs/STYLE.md index b1a40f4..aa6f630 100644 --- a/docs/STYLE.md +++ b/docs/STYLE.md @@ -33,7 +33,7 @@ src/Rosetta/ audio/ Aac Ac3 Adpcm Alac Ape ApeTag Flac Hively Mdct MidiRender Mpa Musepack Opus Pcm Qoa Resample SoundFont Stream Tracker Tta Vorbis VorbisComment WavPack video/ Dsp H263 H264 Legacy Mpeg1 Mpeg2 Theora Video (the video codec registry) - text/ Json Nbt Text Url Xml + text/ GodotVariant Json Nbt Text Url Xml font/ Bitmap Cff GlyphNames TrueType model/ Draco Mat4 MeshFlatten Minecraft Polygon Rbx Rig Sampler Vrml host/ host (layer 2) runtime adapters; only the api uses them diff --git a/docs/guide/data.md b/docs/guide/data.md index faa0a32..de0b935 100644 --- a/docs/guide/data.md +++ b/docs/guide/data.md @@ -306,6 +306,29 @@ local xml = assert(F.saveString(p, { format = "plist" })) assert(string.find(xml, "CFBundleName\n\tDemo", 1, true)) ``` +## Godot resources (.tres) + +Godot text resources load as a table: `type` (the resource class), `format`, `uid`, `scriptClass`, `external` (the +`ext_resource` list: `id`, `type`, `path`, `uid`), `subresources` (`id`, `type`, `properties`) and `properties` (the +`[resource]` section, in file order). Godot values that Luau lacks are `{ type, args }` tables: `Vector3(1, 2, 3)` is +`{ type = "Vector3", args = { 1, 2, 3 } }`, likewise `Color`, `Transform3D`, `PackedFloat32Array`, `NodePath`, +`&"StringName"` (`type = "StringName"`), `SubResource("id")` and `ExtResource("id")`; `Object(Class, ...)` has `class` +and its properties in `args[1]`. Godot dictionaries keep their order and may have number keys. Godot tells integers +from floats, so integral floats read from a file (`1.0`) are written back as floats. +`F.format("tres")` and the codec `F._internal("codecs/text/GodotVariant")` (`value`, `format`, `isCtor`, `ctor`) +help with the values. Scenes (`.tscn`) are models: see [the scene guide](scene.md). + +```luau +local res = assert(F.data.load(tresText)) +assert(res.type == "StandardMaterial3D" and res.external[1].path == "res://brick.png") +local c = res.properties.albedo_color +assert(c.type == "Color" and c.args[1] == 0.8) +assert(res.properties.albedo_texture.type == "ExtResource") +res.properties.metallic = 0.5 +local text = assert(F.saveString(res, { format = "tres" })) +assert(string.find(text, "metallic = 0.5", 1, true) and string.find(text, "roughness = 1.0", 1, true)) +``` + ## Save and convert Data values have no `kind`, so saving needs `opts.format` or a destination extension (an `XmlNode` document too): @@ -341,6 +364,7 @@ is an error there), CSV needs rows, INI needs sections of scalars, JSON has no b | cbor (`.cbor`) | yes | yes | values, buffers, Dates, tagged values | | plist (`.plist`) | XML + binary | XML | values, buffers, Dates | | nbt (`.nbt`, `.dat`, `.mcstructure`), snbt (`.snbt`) | yes | yes | typed values: see [Minecraft and voxels](voxel.md) | +| tres (`.tres`) | yes | yes | Godot resources: sections, Variant values as `{ type, args }` | Full capability list: [FORMATS.md](../FORMATS.md). diff --git a/docs/guide/scene.md b/docs/guide/scene.md index 4650d39..145ca1b 100644 --- a/docs/guide/scene.md +++ b/docs/guide/scene.md @@ -739,6 +739,40 @@ local again = assert(F.load(F.save(scene, nil, { format = "ase" }))) assert(#again.meshes[again.nodes[2].mesh].primitives == 2) ``` +## Godot scenes (TSCN / ESCN) + +Godot text scenes load as a Y-up Scene (one node per `[node]`, the scene root first), checked against Godot 4's own +loader. Node3D transforms come from `transform = Transform3D(...)` (or `position` / `rotation` / `scale`); a +MeshInstance3D gets its ArrayMesh sub-resource (Godot 4.2+ surfaces, and the `"arrays"` surfaces of Godot 3 / Blender +`.escn` files) or its primitive mesh (Box, Plane, Quad, Sphere and Cylinder are built as Godot builds them), with +`surface_material_override/N` applied. StandardMaterial3D / SpatialMaterial become PBR materials (Godot's sRGB +albedo and emission converted to linear; the raw values in `material.extras.godot`); textures are `ExtResource` +paths (`res://` dropped) with their bytes through `opts.resolve`. Camera3D (`fov` is vertical) and Omni / Spot / +Directional lights map to cameras and lights (`intensity` = `light_energy`). Instanced scenes +(`instance=ExtResource(...)`) are read through `opts.resolve` and grafted under their node. Godot's front faces are +clockwise: indices are reversed into glTF's counter-clockwise winding (and back on save). Every node keeps its Godot +type and raw properties in `node.extras.godot`, so 2D trees (Node2D, Sprite2D, Control) are kept there too. + +```luau +local scene = assert(F.load(tscnText, { resolve = function(path) return nil end })) +assert(scene.meta.source.format == "godot" and scene.meta.up == "y") +local box = scene.nodes[2] +assert(box.name == "Box" and box.extras.godot.type == "MeshInstance3D") +assert(box.matrix[13] == 2) -- Transform3D origin x +local mat = scene.materials[scene.meshes[box.mesh].primitives[1].material] +assert(mat.extras.godot.albedo[1] == 1 and mat.metallic == 0.5) +assert(scene.cameras[1].type == "perspective" and math.abs(math.deg(scene.cameras[1].yfov) - 60) < 1e-9) +local hud = scene.nodes[4] +assert(hud.extras.godot.type == "Node2D" and hud.extras.godot.properties.position.args[1] == 10) +local tscn = assert(F.saveString(scene, { format = "godot" })) -- Godot 4 text, format 3 +assert(string.find(tscn, '[node name="Box" type="MeshInstance3D" parent="."]', 1, true)) +``` + +The writer makes Node3D / MeshInstance3D / Camera3D / light nodes, ArrayMesh sub-resources (uncompressed format 2 +surfaces with positions, normals, tangents, colours, two UV sets) and StandardMaterial3D, plus a `Texture2D` +`ext_resource` per texture with a `uri`. Skins, animations and morph targets are not written. Godot resources +(`.tres`) are data: see [data.md](data.md). + ## Formats | Format | Read | Write | Notes | @@ -769,6 +803,7 @@ assert(#again.meshes[again.nodes[2].mesh].primitives == 2) | STEP | via the CAD plug-in | | see [cad.md](cad.md) | | MD2, MD3, MDL, MD5, BSP | yes | - | game models and maps: see "Game models" above | | SMD | yes | yes | Valve studiomdl data | +| Godot `.tscn` / `.escn` | yes | yes (`.tscn`) | Node3D trees, ArrayMesh and primitive meshes, StandardMaterial3D, cameras, lights, instances; 2D nodes in extras | | ASE (3ds Max ASCII) | yes | yes | Multi/Sub-Object materials, texture channels, vertex colours, normals, helpers, cameras, lights; no animation; Z up | | Roblox `.mesh` (robloxmesh) | yes | yes | see [roblox.md](roblox.md) | | Roblox `.rbxm` / `.rbxl`, `.rbxmx` / `.rbxlx` | as an `RbxTree` | yes | instance trees with typed properties: see [roblox.md](roblox.md) | diff --git a/licenses/NOTICE.md b/licenses/NOTICE.md index f3d8a08..26dd01b 100644 --- a/licenses/NOTICE.md +++ b/licenses/NOTICE.md @@ -59,6 +59,7 @@ | `tests/gen/ldraw_*` (read at fixture time from the nix store, not committed) | LDraw.org Parts Library parts and sample models (complete.zip, as packaged for nixpkgs' LeoCAD) | CC BY 2.0 / CC BY 4.0, test data | | `src/Rosetta/codecs/image/Bcn/Decode.luau` (the BC1..BC7 block decoders and the BPTC tables; changed to follow the D3D11 rules) | Pillow 12 `src/libImaging/BcnDecode.c` | CC0 1.0: [pillow-bcn-CC0.txt](pillow-bcn-CC0.txt) | | `src/Rosetta/image/exr/Piz.luau`, `src/Rosetta/image/exr/Codec.luau` (the PIZ Huffman / wavelet / LUT steps and the ZIP / RLE byte predictor, re-implemented in Luau after the OpenEXR algorithms) | OpenEXR 3.x (ImfPizCompressor, ImfHuf, ImfWav, ImfZip, ImfRle) | BSD-3-Clause: [openexr-LICENSE.md](openexr-LICENSE.md) | +| `src/Rosetta/model/godot/Primitives.luau` (BoxMesh, PlaneMesh, QuadMesh, SphereMesh, CylinderMesh generation, ported to Luau without UV2) | Godot Engine 4.4 `scene/resources/3d/primitive_meshes.cpp` | MIT: [godot-LICENSE.txt](godot-LICENSE.txt) | Ports of third-party code (minimp3, stb_vorbis, libopus, ...) add a row here and their upstream licence text in this folder (see docs/STYLE.md, "Absorbing an existing repo"). diff --git a/licenses/godot-LICENSE.txt b/licenses/godot-LICENSE.txt new file mode 100644 index 0000000..0e3ba08 --- /dev/null +++ b/licenses/godot-LICENSE.txt @@ -0,0 +1,20 @@ +Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). +Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/Rosetta/Registry.luau b/src/Rosetta/Registry.luau index 999cca5..7be9095 100644 --- a/src/Rosetta/Registry.luau +++ b/src/Rosetta/Registry.luau @@ -794,6 +794,18 @@ local list: { Entry } = { return require("@rosetta/model/gltf") end, }, + { + name = "godot", + category = "model", + path = "model/godot", + extensions = { "tscn", "escn" }, + mime = { "application/x-godot-scene" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/GodotVariant", "codecs/model/Mat4" }, + caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, instances = true }, + load = function() + return require("@rosetta/model/godot") + end, + }, { name = "iqm", category = "model", @@ -1730,6 +1742,18 @@ local list: { Entry } = { return require("@rosetta/data/toml") end, }, + { + name = "tres", + category = "data", + path = "data/tres", + extensions = { "tres" }, + mime = { "application/x-godot-resource" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/GodotVariant" }, + caps = { decode = true, encode = true, ordered = true }, + load = function() + return require("@rosetta/data/tres") + end, + }, { name = "xml", category = "data", diff --git a/src/Rosetta/codecs/text/GodotVariant.luau b/src/Rosetta/codecs/text/GodotVariant.luau new file mode 100644 index 0000000..ed49696 --- /dev/null +++ b/src/Rosetta/codecs/text/GodotVariant.luau @@ -0,0 +1,657 @@ +--!strict +-- codecs/text/GodotVariant: Godot's text resource syntax (.tscn / .tres / .escn, formats 2-4; Godot's +-- variant_parser.cpp and resource_format_text.cpp): [section key=value ...] headers with `key = value` properties, +-- and the Variant text syntax (numbers, strings, &"StringName", ^"NodePath", arrays, dictionaries, constructors such +-- as Vector3(...), Transform3D(...), PackedFloat32Array(...), SubResource("id"), Object(Class, "k": v)). +-- Constructor values are { type, args } tables (GodotVariant.isCtor); dictionaries keep their key order. +local Types = require("@rosetta/Types") +local Base64 = require("@rosetta/core/Base64") + +local GodotVariant = {} + +GodotVariant.null = Types.null + +local CTOR = { __godot = true } + +-- integral numbers written as floats ("1.0"): Godot keeps int and float apart (Curve._data mixes them), so the keys +-- holding them are remembered per container (array, dictionary, property table) and written back with ".0" +local FLOATS: { [any]: { [any]: boolean } } = setmetatable({}, { __mode = "k" }) :: any +local lastFloat = false + +local function mark(t: any, k: any, v: any) + if lastFloat and type(v) == "number" and v == math.floor(v) then + local m = FLOATS[t] + if not m then + m = {} + FLOATS[t] = m + end + m[k] = true + end +end + +function GodotVariant.isFloat(t: any, k: any): boolean + local m = FLOATS[t] + return m ~= nil and m[k] == true +end + +function GodotVariant.markFloat(t: any, k: any) + local m = FLOATS[t] + if not m then + m = {} + FLOATS[t] = m + end + m[k] = true +end + +function GodotVariant.copyFloats(from: any, to: any) + local m = FLOATS[from] + if m then + FLOATS[to] = table.clone(m) + end +end + +export type Ctor = { type: string, args: { any }, class: string? } +export type Section = { tag: string, attrs: { [string]: any }, attrOrder: { string }, props: { [string]: any }, order: { string } } +export type Document = { sections: { Section } } + +function GodotVariant.ctor(name: string, args: { any }?): Ctor + return setmetatable({ type = name, args = args or {} }, CTOR) :: any +end + +function GodotVariant.isCtor(v: any): boolean + return type(v) == "table" and getmetatable(v) == CTOR +end + +-- the numbers of a constructor, or nil when an argument is not a number +function GodotVariant.numbers(v: any, name: string?): { number }? + if not GodotVariant.isCtor(v) or (name and v.type ~= name) then + return nil + end + for _, x in v.args do + if type(x) ~= "number" then + return nil + end + end + return v.args :: { number } +end + +-- PackedByteArray(1, 2, ...) or PackedByteArray("base64") (Godot 4.3+), PoolByteArray / ByteArray (format 2) +function GodotVariant.bytes(v: any): buffer? + if not GodotVariant.isCtor(v) then + return nil + end + local a = v.args + if #a == 1 and type(a[1]) == "string" then + return (Base64.decode(a[1])) + end + local b = buffer.create(#a) + for i, x in a do + if type(x) ~= "number" then + return nil + end + buffer.writeu8(b, i - 1, x % 256) + end + return b +end + +-- ------------------------------------------------------------------------------------------------ parse +type P = { s: string, i: number, n: number, depth: number, maxDepth: number } + +local NUMERIC_ARRAYS: { [string]: boolean } = { + PackedByteArray = true, PackedInt32Array = true, PackedInt64Array = true, PackedFloat32Array = true, + PackedFloat64Array = true, PackedVector2Array = true, PackedVector3Array = true, PackedVector4Array = true, + PackedColorArray = true, PoolByteArray = true, PoolIntArray = true, PoolRealArray = true, PoolVector2Array = true, + PoolVector3Array = true, PoolColorArray = true, ByteArray = true, IntArray = true, FloatArray = true, RealArray = true, + Vector2Array = true, Vector3Array = true, ColorArray = true, +} +local WORDS: { [string]: any } = { ["true"] = true, ["false"] = false, ["inf"] = math.huge, ["-inf"] = -math.huge, inf_neg = -math.huge, nan = 0 / 0 } + +local function skip(p: P) + local s, i = p.s, p.i + while true do + local a = string.find(s, "[^ \t\r\n]", i) + if not a then + p.i = p.n + 1 + return + end + if string.byte(s, a) == 59 then -- ';' comment to the end of the line + local e = string.find(s, "\n", a, true) + if not e then + p.i = p.n + 1 + return + end + i = e + 1 + else + p.i = a + return + end + end +end + +local ESC: { [string]: string } = { n = "\n", t = "\t", r = "\r", b = "\b", f = "\f", ["\""] = "\"", ["\\"] = "\\", ["'"] = "'", ["/"] = "/" } + +local function utf8char(c: number): string + return utf8.char(math.clamp(c, 0, 0x10FFFF)) +end + +local function str(p: P): (string?, string?) + local s = p.s + local i = p.i + 1 + local parts = {} + while true do + local a = string.find(s, "[\"\\]", i) + if not a then + return nil, "unterminated string" + end + table.insert(parts, string.sub(s, i, a - 1)) + if string.byte(s, a) == 34 then + p.i = a + 1 + return table.concat(parts), nil + end + local c = string.sub(s, a + 1, a + 1) + if c == "u" or c == "U" then + local len = if c == "u" then 4 else 6 + local h = tonumber(string.sub(s, a + 2, a + 1 + len), 16) + if not h then + return nil, "bad \\u escape" + end + -- surrogate pairs + if h >= 0xD800 and h < 0xDC00 and string.sub(s, a + 6, a + 7) == "\\u" then + local lo = tonumber(string.sub(s, a + 8, a + 11), 16) + if lo and lo >= 0xDC00 and lo < 0xE000 then + h = 0x10000 + (h - 0xD800) * 1024 + (lo - 0xDC00) + len += 6 + end + end + table.insert(parts, utf8char(h)) + i = a + 2 + len + else + table.insert(parts, ESC[c] or c) + i = a + 2 + end + end +end + +local value: (p: P) -> (any, string?) + +local function numberList(p: P, name: string): (any, string?) + local s = p.s + local close = string.find(s, ")", p.i, true) + if not close then + return nil, "unterminated " .. name + end + local body = string.sub(s, p.i, close - 1) + -- base64 PackedByteArray, or a list of plain numbers + local q = string.match(body, "^%s*\"([^\"]*)\"%s*$") + if q then + p.i = close + 1 + return GodotVariant.ctor(name, { q }), nil + end + local out = {} + local k = 0 + for tok in string.gmatch(body, "[^,%s]+") do + local v = tonumber(tok) + if v == nil then + v = WORDS[tok] + if type(v) ~= "number" then + return nil, nil -- not purely numeric: parse it generically + end + end + k += 1 + out[k] = v + end + p.i = close + 1 + return GodotVariant.ctor(name, out), nil +end + +local function list(p: P, close: number, into: { any }): string? + skip(p) + if string.byte(p.s, p.i) == close then + p.i += 1 + return nil + end + while true do + local v, err = value(p) + if err then + return err + end + table.insert(into, v) + mark(into, #into, v) + skip(p) + local c = string.byte(p.s, p.i) + if c == 44 then -- ',' + p.i += 1 + skip(p) + if string.byte(p.s, p.i) == close then + p.i += 1 + return nil + end + elseif c == close then + p.i += 1 + return nil + else + return "expected ',' or '" .. string.char(close) .. "' at byte " .. (p.i - 1) + end + end +end + +local function dict(p: P): (any, string?) + p.i += 1 + local t, keys = {}, {} + skip(p) + if string.byte(p.s, p.i) == 125 then + p.i += 1 + return Types.object(t, keys), nil + end + while true do + local k, err = value(p) + if err then + return nil, err + end + skip(p) + if string.byte(p.s, p.i) ~= 58 then + return nil, "expected ':' at byte " .. (p.i - 1) + end + p.i += 1 + local v, verr = value(p) + if verr then + return nil, verr + end + local key = if type(k) == "string" or type(k) == "number" then k else GodotVariant.format(k) + if t[key] == nil then + table.insert(keys, key) + end + t[key] = v + mark(t, key, v) + skip(p) + local c = string.byte(p.s, p.i) + if c == 44 then + p.i += 1 + skip(p) + if string.byte(p.s, p.i) == 125 then + p.i += 1 + break + end + elseif c == 125 then + p.i += 1 + break + else + return nil, "expected ',' or '}' at byte " .. (p.i - 1) + end + end + return Types.object(t, keys), nil +end + +value = function(p: P): (any, string?) + skip(p) + if p.i > p.n then + return nil, "truncated: value expected" + end + p.depth += 1 + if p.depth > p.maxDepth then + return nil, "limit: nested deeper than " .. p.maxDepth + end + local s = p.s + local c = string.byte(s, p.i) + local v: any, err: string? = nil, nil + local isFloat = false + if c == 34 then + v, err = str(p) + elseif c == 38 or c == 94 then -- &"StringName", ^"NodePath" + p.i += 1 + local x, e = str(p) + v, err = if x then GodotVariant.ctor(if c == 38 then "StringName" else "NodePath", { x }) else nil, e + elseif c == 91 then -- '[' + p.i += 1 + local out = {} + err = list(p, 93, out) + v = out + elseif c == 123 then -- '{' + v, err = dict(p) + else + local num = string.match(s, "^[-+]?%d[%w%.+-]*", p.i) or string.match(s, "^[-+]?%.%d[%w%.+-]*", p.i) + if num then + -- 1e-05, 0x1F, 1.5; a trailing "f" is not Godot's + local x = tonumber(num) + if x == nil then + local m = string.match(num, "^[-+]?[%d%.]+[eE][-+]?%d+") or string.match(num, "^[-+]?[%d%.]+") + x = if m then tonumber(m) else nil + num = m or num + end + if x == nil then + return nil, "bad number " .. num .. " at byte " .. (p.i - 1) + end + p.i += #num + v = x + isFloat = string.find(num, "[%.eE]") ~= nil and string.sub(num, 1, 2) ~= "0x" + else + local word = string.match(s, "^[%a_][%w_]*", p.i) or string.match(s, "^%-inf", p.i) + if not word then + return nil, "unexpected character at byte " .. (p.i - 1) + end + p.i += #word + if word == "null" or word == "nil" then + v = Types.null + elseif WORDS[word] ~= nil then + v = WORDS[word] + else + -- typed array: Array[int]([...]); Dictionary[String, int]({...}) + local typed = string.match(s, "^%[[%w_, ]*%]", p.i) + if typed and (word == "Array" or word == "Dictionary") then + word = word .. typed + p.i += #typed + end + skip(p) + if string.byte(s, p.i) ~= 40 then + return nil, "expected '(' after " .. word .. " at byte " .. (p.i - 1) + end + p.i += 1 + if NUMERIC_ARRAYS[word] then + local save = p.i + v, err = numberList(p, word) + if v == nil and err == nil then + p.i = save + local args = {} + err = list(p, 41, args) + v = GodotVariant.ctor(word, args) + end + elseif word == "Object" then + skip(p) + local cls = string.match(s, "^[%w_]+", p.i) + if not cls then + return nil, "Object without a class at byte " .. (p.i - 1) + end + p.i += #cls + local props, keys = {}, {} + skip(p) + while string.byte(s, p.i) == 44 do + p.i += 1 + local k, kerr = value(p) + if kerr then + return nil, kerr + end + skip(p) + if string.byte(s, p.i) ~= 58 then + return nil, "expected ':' in Object at byte " .. (p.i - 1) + end + p.i += 1 + local x, xerr = value(p) + if xerr then + return nil, xerr + end + if type(k) == "string" then + props[k] = x + table.insert(keys, k) + end + skip(p) + end + if string.byte(s, p.i) ~= 41 then + return nil, "expected ')' after Object at byte " .. (p.i - 1) + end + p.i += 1 + local o = GodotVariant.ctor("Object", { Types.object(props, keys) }) + o.class = cls + v = o + else + local args = {} + err = list(p, 41, args) + v = GodotVariant.ctor(word, args) + end + end + end + end + p.depth -= 1 + lastFloat = isFloat + return v, err +end + +function GodotVariant.value(text: string, maxDepth: number?): (any, string?) + local p: P = { s = text, i = 1, n = #text, depth = 0, maxDepth = maxDepth or 256 } + return value(p) +end + +-- a property key: up to '=' (keys hold '/', ':', '.', or are quoted) +local function key(p: P): string? + local s = p.s + if string.byte(s, p.i) == 34 then + local k = str(p) + return k + end + local k = string.match(s, "^[^=\n%[]+", p.i) + if not k then + return nil + end + p.i += #k + return (string.gsub(k, "%s+$", "")) +end + +function GodotVariant.parse(text: string, opts: { maxDepth: number?, maxSections: number? }?): (Document?, string?) + local o: { maxDepth: number?, maxSections: number? } = opts or {} + if string.sub(text, 1, 3) == "\239\187\191" then + text = string.sub(text, 4) + end + local p: P = { s = text, i = 1, n = #text, depth = 0, maxDepth = o.maxDepth or 256 } + local maxSections = o.maxSections or 2 ^ 22 + local sections: { Section } = {} + local cur: Section? = nil + local s = text + while true do + skip(p) + if p.i > p.n then + break + end + if string.byte(s, p.i) == 91 then + p.i += 1 + skip(p) + local tag = string.match(s, "^[%w_]+", p.i) + if not tag then + return nil, "bad section header at byte " .. (p.i - 1) + end + p.i += #tag + local sec: Section = { tag = tag, attrs = {}, attrOrder = {}, props = {}, order = {} } + while true do + skip(p) + local c = string.byte(s, p.i) + if c == 93 then + p.i += 1 + break + end + local k = string.match(s, "^[%w_/]+", p.i) + if not k then + return nil, "bad attribute in [" .. tag .. "] at byte " .. (p.i - 1) + end + p.i += #k + skip(p) + if string.byte(s, p.i) ~= 61 then + return nil, "expected '=' in [" .. tag .. "] at byte " .. (p.i - 1) + end + p.i += 1 + local v, err = value(p) + if err then + return nil, err + end + if sec.attrs[k] == nil then + table.insert(sec.attrOrder, k) + end + sec.attrs[k] = v + end + if #sections >= maxSections then + return nil, "limit: over " .. maxSections .. " sections" + end + table.insert(sections, sec) + cur = sec + else + local at = p.i + local k = key(p) + if not k or k == "" then + return nil, "bad property at byte " .. (at - 1) + end + skip(p) + if string.byte(s, p.i) ~= 61 then + return nil, "expected '=' after " .. k .. " at byte " .. (p.i - 1) + end + p.i += 1 + local v, err = value(p) + if err then + return nil, err + end + if not cur then + cur = { tag = "", attrs = {}, attrOrder = {}, props = {}, order = {} } + table.insert(sections, cur :: Section) + end + local c = cur :: Section + if c.props[k] == nil then + table.insert(c.order, k) + end + c.props[k] = v + mark(c.props, k, v) + end + end + return { sections = sections }, nil +end + +-- ------------------------------------------------------------------------------------------------ format +local function num(x: number): string + if x ~= x then + return "nan" + elseif x == math.huge then + return "inf" + elseif x == -math.huge then + return "-inf" + elseif x == math.floor(x) and math.abs(x) < 2 ^ 53 then + return string.format("%d", x) + end + for d = 6, 17 do + local s = string.format("%." .. d .. "g", x) + if tonumber(s) == x then + return s + end + end + return string.format("%.17g", x) +end +GodotVariant.number = num + +local function quote(s: string): string + return "\"" .. string.gsub(s, "[\\\"\n\t\r]", { ["\\"] = "\\\\", ["\""] = "\\\"", ["\n"] = "\\n", ["\t"] = "\\t", ["\r"] = "\\r" }) .. "\"" +end +GodotVariant.quote = quote + +local format: (v: any, depth: number, indent: boolean) -> string + +local function item(t: any, k: any, depth: number, indent: boolean): string + local v = t[k] + if type(v) == "number" and v == math.floor(v) and math.abs(v) < 2 ^ 53 and GodotVariant.isFloat(t, k) then + return string.format("%d", v) .. ".0" + end + return format(v, depth, indent) +end +GodotVariant.item = function(t: any, k: any): string + return item(t, k, 0, false) +end + +format = function(v: any, depth: number, indent: boolean): string + if depth > 256 then + return "null" + end + local t = type(v) + if t == "number" then + return num(v) + elseif t == "string" then + return quote(v) + elseif t == "boolean" then + return if v then "true" else "false" + elseif v == nil or v == Types.null then + return "null" + elseif t == "buffer" then + local parts = table.create(buffer.len(v)) + for i = 0, buffer.len(v) - 1 do + parts[i + 1] = tostring(buffer.readu8(v, i)) + end + return "PackedByteArray(" .. table.concat(parts, ", ") .. ")" + elseif t ~= "table" then + return "null" + end + if GodotVariant.isCtor(v) then + if v.type == "StringName" and type(v.args[1]) == "string" then + return "&" .. quote(v.args[1]) + elseif v.type == "Object" then + local props = v.args[1] + local parts = { tostring(v.class or "Object") } + if type(props) == "table" then + for _, k in Types.keys(props) do + table.insert(parts, quote(tostring(k)) .. ": " .. format(props[k], depth + 1, false)) + end + end + return "Object(" .. table.concat(parts, ",") .. ")" + end + local parts: { string } = table.create(#v.args) :: any + for i, x in v.args do + parts[i] = format(x, depth + 1, false) + end + local vt: string = tostring(v.type) + if string.match(vt, "^(%a+)%[") then + local inner: string = parts[1] or "[]" + return vt .. "(" .. inner .. ")" + end + return vt .. "(" .. table.concat(parts, ", ") .. ")" + end + if Types.isObject(v) or not Types.isArray(v) then + local keys = Types.keys(v) + if #keys == 0 then + return "{}" + end + local parts = {} + for _, k in keys do + local ks = if type(k) == "string" then quote(k) else format(k, depth + 1, false) + table.insert(parts, ks .. ": " .. item(v, k, depth + 1, false)) + end + if indent then + return "{\n" .. table.concat(parts, ",\n") .. "\n}" + end + return "{\n" .. table.concat(parts, ",\n") .. "\n}" + end + local parts = table.create(#v) + for i in v do + parts[i] = item(v, i, depth + 1, true) + end + return "[" .. table.concat(parts, ", ") .. "]" +end + +function GodotVariant.format(v: any): string + return format(v, 0, false) +end + +function GodotVariant.encode(doc: Document): string + local out = {} + for i, sec in doc.sections do + if sec.tag ~= "" then + local parts = { "[" .. sec.tag } + local order = sec.attrOrder + if #order == 0 then + order = Types.keys(sec.attrs) + end + for _, k in order do + if sec.attrs[k] ~= nil then + table.insert(parts, k .. "=" .. GodotVariant.format(sec.attrs[k])) + end + end + if i > 1 then + table.insert(out, "") + end + table.insert(out, table.concat(parts, " ") .. "]") + end + local order = sec.order + if #order == 0 then + order = Types.keys(sec.props) + end + for _, k in order do + if sec.props[k] ~= nil then + local ks = if string.find(k, "^[%w_/:%.]+$") then k else quote(k) + table.insert(out, ks .. " = " .. item(sec.props, k, 0, false)) + end + end + end + return table.concat(out, "\n") .. "\n" +end + +return GodotVariant diff --git a/src/Rosetta/data/tres/init.luau b/src/Rosetta/data/tres/init.luau new file mode 100644 index 0000000..36086e0 --- /dev/null +++ b/src/Rosetta/data/tres/init.luau @@ -0,0 +1,143 @@ +--!strict +-- data/tres: Godot text resources (.tres, formats 2-4) as data, read + write (codecs/text/GodotVariant). The value: +-- { type, format, uid?, scriptClass?, loadSteps?, external = { { id, type, path, uid? } }, subresources = { { id, +-- type, properties } }, properties } with Variant values (Vector3, Color, SubResource, ... as { type, args } tables; +-- dictionaries and property tables keep their order). Not supported: binary .res files. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = require("@rosetta/core/Err") +local Bytes = require("@rosetta/core/Bytes") +local Sniff = require("@rosetta/core/Sniff") +local Types = require("@rosetta/Types") +local GodotVariant = require("@rosetta/codecs/text/GodotVariant") + +-- ------------------------------------------------------------------------------------------------ contract +local Tres = { + name = "tres", + category = "data", + extensions = { "tres" }, + mime = { "application/x-godot-resource" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/GodotVariant" }, + caps = { decode = true, encode = true, ordered = true }, +} + +export type DecodeOptions = { + maxBytes: number?, -- default 2^28 + maxDepth: number?, -- value nesting, default 256 +} + +-- ------------------------------------------------------------------------------------------------ sniff +function Tres.sniff(r: Bytes.Reader): number + local h = Sniff.text(r, 256) + if string.match(h, "^%s*%[gd_resource[%s%]]") then + return 1 + end + return 0 +end + +-- ------------------------------------------------------------------------------------------------ decode +local function props(sec: GodotVariant.Section): { [string]: any } + local out = {} + for _, k in sec.order do + out[k] = sec.props[k] + end + GodotVariant.copyFloats(sec.props, out) + return Types.object(out, table.clone(sec.order) :: { any }) +end + +function Tres.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) + local o: DecodeOptions = opts or {} + if r.limit - r.base > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local text = buffer.readstring(r.buf, r.base, r.limit - r.base) + local ok, doc, perr = pcall(function(): (GodotVariant.Document?, string?) + return GodotVariant.parse(text, { maxDepth = o.maxDepth }) + end) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad data: " .. tostring(doc)) + end + if not doc then + return nil, Err.from(perr) + end + local head = doc.sections[1] + if not head or head.tag ~= "gd_resource" then + return nil, Err.new(if head and head.tag == "gd_scene" then Err.UNSUPPORTED else Err.CORRUPT, if head and head.tag == "gd_scene" then "a scene (model/godot), not a resource" else "no [gd_resource] header") + end + local a = head.attrs + local value: { [string]: any } = { + type = a.type, + format = a.format, + uid = a.uid, + scriptClass = a.script_class, + loadSteps = a.load_steps, + external = {}, + subresources = {}, + properties = Types.object({}), + } + for i = 2, #doc.sections do + local sec = doc.sections[i] + local sa = sec.attrs + if sec.tag == "ext_resource" then + table.insert(value.external, { id = sa.id, type = sa.type, path = sa.path, uid = sa.uid }) + elseif sec.tag == "sub_resource" then + table.insert(value.subresources, { id = sa.id, type = sa.type, properties = props(sec) }) + elseif sec.tag == "resource" then + value.properties = props(sec) + end + end + return value, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +local function section(tag: string, pairs_: { any }, properties: any?): GodotVariant.Section + local attrs, order = {}, {} + local i = 1 + while pairs_[i] ~= nil do + if pairs_[i + 1] ~= nil then + attrs[pairs_[i]] = pairs_[i + 1] + table.insert(order, pairs_[i]) + end + i += 2 + end + local p, po = {}, {} + if type(properties) == "table" then + for _, k in Types.keys(properties) do + if type(k) == "string" then + p[k] = properties[k] + table.insert(po, k) + end + end + GodotVariant.copyFloats(properties, p) + end + return { tag = tag, attrs = attrs, attrOrder = order, props = p, order = po } +end + +function Tres.encode(value: any, opts: any?): (buffer?, Err.Err?) + if type(value) ~= "table" or type(value.type) ~= "string" then + return nil, Err.new(Err.ARG, "needs a resource table with a type") + end + local ext = if type(value.external) == "table" then value.external else {} + local sub = if type(value.subresources) == "table" then value.subresources else {} + local format = if type(value.format) == "number" then value.format else 3 + local steps = if type(value.loadSteps) == "number" then value.loadSteps elseif #ext + #sub > 0 then #ext + #sub + 1 else nil + local sections = { section("gd_resource", { "type", value.type, "script_class", value.scriptClass, "load_steps", steps, "format", format, "uid", value.uid }) } + for _, e in ext do + if type(e) == "table" then + table.insert(sections, section("ext_resource", { "type", e.type, "uid", e.uid, "path", e.path, "id", e.id })) + end + end + for _, s in sub do + if type(s) == "table" then + table.insert(sections, section("sub_resource", { "type", s.type, "id", s.id }, s.properties)) + end + end + table.insert(sections, section("resource", {}, value.properties)) + local ok, s = pcall(GodotVariant.encode, { sections = sections }) + if not ok then + return nil, Err.new(Err.ARG, "cannot encode: " .. tostring(s)) + end + return buffer.fromstring(s), nil +end + +return Tres diff --git a/src/Rosetta/model/godot/Build.luau b/src/Rosetta/model/godot/Build.luau new file mode 100644 index 0000000..c49a7fa --- /dev/null +++ b/src/Rosetta/model/godot/Build.luau @@ -0,0 +1,540 @@ +--!strict +-- model/godot/Build: a parsed Godot text scene (codecs/text/GodotVariant) into a Scene. Transform3D / Transform text +-- is the basis rows then the origin; Node3D position / rotation (Euler YXZ, radians) / scale / quaternion are used when +-- there is no transform. Colours (albedo, emission, lights) are sRGB in Godot and linear in the Scene (raw values in +-- extras.godot). Non-3D nodes (Node2D trees, Control, plain Node) are nodes with their properties in extras.godot. +local Types = require("@rosetta/Types") +local Mat4 = require("@rosetta/codecs/model/Mat4") +local GodotVariant = require("@rosetta/codecs/text/GodotVariant") +local Surface = require("@rosetta/model/godot/Surface") +local Primitives = require("@rosetta/model/godot/Primitives") + +local Build = {} + +local S = Types.Scene +local isCtor = GodotVariant.isCtor + +type Ctx = { + scene: Types.Scene, + doc: GodotVariant.Document, + format: number, + ext: { [string]: any }, + sub: { [string]: any }, + meshes: { [string]: number }, + materials: { [string]: number }, + textures: { [string]: number }, + opts: any, + depth: number, + warnings: { string }, +} + +local function idOf(v: any): string? + if isCtor(v) and (v.type == "SubResource" or v.type == "ExtResource") then + local a = v.args[1] + if type(a) == "string" or type(a) == "number" then + return tostring(a) + end + end + return nil +end + +local function num(v: any, d: number): number + return if type(v) == "number" and v == v then v else d +end + +local function srgb(c: number): number + if c <= 0.04045 then + return c / 12.92 + end + return ((c + 0.055) / 1.055) ^ 2.4 +end + +local function color(v: any, d: { number }): { number } + local a = GodotVariant.numbers(v, "Color") + if a and #a >= 3 then + return { a[1], a[2], a[3], a[4] or 1 } + end + return d +end + +local function linear(c: { number }): { number } + return { srgb(c[1]), srgb(c[2]), srgb(c[3]), c[4] } +end + +-- ------------------------------------------------------------------------------------------------ transforms +function Build.transform(v: any): { number }? + local a = if isCtor(v) and (v.type == "Transform3D" or v.type == "Transform") then GodotVariant.numbers(v) else nil + if not a or #a ~= 12 then + return nil + end + return { a[1], a[4], a[7], 0, a[2], a[5], a[8], 0, a[3], a[6], a[9], 0, a[10], a[11], a[12], 1 } +end + +-- Basis::from_euler (YXZ): Ry * Rx * Rz +local function euler(x: number, y: number, z: number): { number } + local rx, ry, rz = Mat4.rotation(1, math.deg(x)), Mat4.rotation(2, math.deg(y)), Mat4.rotation(3, math.deg(z)) + return S.mul(ry, S.mul(rx, rz)) +end + +local function nodeMatrix(props: any): { number }? + local m = Build.transform(props.transform) + if m then + return m + end + local pos = GodotVariant.numbers(props.position, "Vector3") or GodotVariant.numbers(props.translation, "Vector3") + local rot = GodotVariant.numbers(props.rotation, "Vector3") + local deg = GodotVariant.numbers(props.rotation_degrees, "Vector3") + local quat = GodotVariant.numbers(props.quaternion, "Quaternion") + local sc = GodotVariant.numbers(props.scale, "Vector3") + if not (pos or rot or deg or quat or sc) then + return nil + end + local r: { number } + if quat and #quat == 4 then + r = Mat4.fromQuat(quat) + elseif rot and #rot == 3 then + r = euler(rot[1], rot[2], rot[3]) + elseif deg and #deg == 3 then + r = euler(math.rad(deg[1]), math.rad(deg[2]), math.rad(deg[3])) + else + r = Mat4.identity() + end + local s = if sc and #sc == 3 then Mat4.scaling(sc[1], sc[2], sc[3]) else Mat4.identity() + local out = S.mul(r, s) + if pos and #pos == 3 then + out[13], out[14], out[15] = pos[1], pos[2], pos[3] + end + return out +end + +-- ------------------------------------------------------------------------------------------------ resources +local function path(ext: any): string? + if type(ext) ~= "table" then + return nil + end + local p = ext.attrs.path + return if type(p) == "string" then p else nil +end + +local function texture(ctx: Ctx, v: any): Types.TextureRef? + local id = idOf(v) + if not id or not isCtor(v) or v.type ~= "ExtResource" then + return nil + end + local key = "ext:" .. id + local idx = ctx.textures[key] + if not idx then + local p = path(ctx.ext[id]) + if not p then + return nil + end + local rel = string.gsub(p, "^res://", "") + local tex: Types.Texture = { name = rel, uri = rel } + local resolve = ctx.opts.resolve + if type(resolve) == "function" then + local ok, b = pcall(resolve, rel) + if ok and type(b) == "buffer" then + tex.data = b + end + end + table.insert(ctx.scene.textures, tex) + idx = #ctx.scene.textures + ctx.textures[key] = idx + end + return { texture = idx :: number } +end + +local MATERIALS = { StandardMaterial3D = true, ORMMaterial3D = true, SpatialMaterial = true } + +local function material(ctx: Ctx, v: any): number? + local id = idOf(v) + if not id or not isCtor(v) then + return nil + end + local key = v.type .. ":" .. id + if ctx.materials[key] then + return ctx.materials[key] + end + local sec = if v.type == "SubResource" then ctx.sub[id] else nil + local typ = if sec then sec.attrs.type else (if ctx.ext[id] then ctx.ext[id].attrs.type else nil) + local p = if sec then sec.props else {} + local m = S.material(if type(p.resource_name) == "string" then p.resource_name else nil) + local albedo = color(p.albedo_color, { 1, 1, 1, 1 }) + m.baseColor = linear(albedo) + m.metallic = num(p.metallic, 0) + m.roughness = num(p.roughness, 1) + local extras: { [string]: any } = { type = typ, albedo = albedo } + if MATERIALS[typ or ""] then + m.baseColorTexture = texture(ctx, p.albedo_texture) + m.metallicRoughnessTexture = texture(ctx, p.metallic_texture) or texture(ctx, p.roughness_texture) + if p.normal_enabled == true or p.normal_enabled == nil and p.normal_texture ~= nil then + m.normalTexture = texture(ctx, p.normal_texture) + if m.normalTexture and type(p.normal_scale) == "number" then + m.normalTexture.scale = p.normal_scale + end + end + if p.ao_enabled == true then + m.occlusionTexture = texture(ctx, p.ao_texture) + end + local emission = p.emission_enabled == true or p.flags_emission == true + if emission then + local e = color(p.emission, { 0, 0, 0, 1 }) + local energy = num(p.emission_energy_multiplier, num(p.emission_energy, 1)) + local le = linear(e) + m.emissive = { le[1], le[2], le[3] } + m.emissiveTexture = texture(ctx, p.emission_texture) + extras.emission = e + if energy ~= 1 then + m.extensions = { KHR_materials_emissive_strength = { emissiveStrength = energy } } + end + end + local transparency = num(p.transparency, if p.flags_transparent == true then 1 else 0) + if transparency == 1 or transparency == 4 then + m.alphaMode = "blend" + elseif transparency == 2 or transparency == 3 then + m.alphaMode = "mask" + m.alphaCutoff = num(p.alpha_scissor_threshold, 0.5) + end + m.doubleSided = num(p.cull_mode, num(p.params_cull_mode, 0)) == 2 + if num(p.shading_mode, 1) == 0 or p.flags_unshaded == true then + m.extensions = m.extensions or {} + ;(m.extensions :: any).KHR_materials_unlit = {} + end + local uv = GodotVariant.numbers(p.uv1_scale, "Vector3") + local off = GodotVariant.numbers(p.uv1_offset, "Vector3") + if m.baseColorTexture and (uv or off) then + m.baseColorTexture.transform = { scale = if uv then { uv[1], uv[2] } else { 1, 1 }, offset = if off then { off[1], off[2] } else { 0, 0 } } + end + elseif not sec then + extras.path = path(ctx.ext[id]) + end + m.extras = { godot = extras } + table.insert(ctx.scene.materials, m) + ctx.materials[key] = #ctx.scene.materials + return #ctx.scene.materials +end + +-- a mesh resource (ArrayMesh or a primitive mesh) as a Scene mesh; overrides: surface index -> material value +local function mesh(ctx: Ctx, v: any, overrides: { [number]: any }?): (number?, string?) + local id = idOf(v) + if not id or not isCtor(v) then + return nil, nil + end + local key = v.type .. ":" .. id + if not overrides and ctx.meshes[key] then + return ctx.meshes[key], nil + end + local sec = if v.type == "SubResource" then ctx.sub[id] else nil + local out: Types.Mesh = { primitives = {} } + if not sec then + out.extras = { godot = { path = path(ctx.ext[id]) } } + else + local typ = sec.attrs.type + local p = sec.props + out.name = if type(p.resource_name) == "string" then p.resource_name else nil + local maxV = ctx.opts.maxVertices or 2 ^ 24 + if typ == "ArrayMesh" or typ == "Mesh" then + local surfaces: { any } = {} + if type(p._surfaces) == "table" then + surfaces = p._surfaces + else + for k = 0, 4096 do + local s = p["surfaces/" .. k] + if s == nil then + break + end + surfaces[k + 1] = s + end + end + local blend = 0 + for i, sd in surfaces do + local L, err = Surface.lists(sd, maxV) + if not L then + return nil, err + end + local prim = Surface.primitive(L) + local mv = if overrides and overrides[i - 1] ~= nil then overrides[i - 1] else (if type(sd) == "table" then sd.material else nil) + prim.material = material(ctx, mv) + if type(sd) == "table" and type(sd.name) == "string" then + prim.extras = { name = sd.name } + end + if type(sd) == "table" and type(sd.blend_shapes) == "table" then + blend = math.max(blend, #sd.blend_shapes) + end + table.insert(out.primitives, prim) + end + if blend > 0 then + out.extras = { godot = { blendShapes = blend } } + end + elseif Primitives.KINDS[typ] then + local a = Primitives.build(typ, p) + if a then + local prim = Surface.primitive(Surface.fromPrimitiveArrays(a)) + prim.material = material(ctx, if overrides and overrides[0] ~= nil then overrides[0] else p.material) + table.insert(out.primitives, prim) + end + out.extras = { godot = { primitive = typ } } + else + out.extras = { godot = { type = typ } } + end + end + table.insert(ctx.scene.meshes, out) + if not overrides then + ctx.meshes[key] = #ctx.scene.meshes + end + return #ctx.scene.meshes, nil +end + +-- ------------------------------------------------------------------------------------------------ nodes +local LIGHT: { [string]: "point" | "spot" | "directional" } = { + OmniLight3D = "point", SpotLight3D = "spot", DirectionalLight3D = "directional", + OmniLight = "point", SpotLight = "spot", DirectionalLight = "directional", +} +local CAMERA = { Camera3D = true, Camera = true, ClippedCamera = true, InterpolatedCamera = true, XRCamera3D = true } +local MESH = { MeshInstance3D = true, MeshInstance = true, CSGMesh3D = true, SoftBody3D = true } + +local THREE_D = { + Node3D = true, Spatial = true, MeshInstance3D = true, MeshInstance = true, Camera3D = true, Camera = true, + OmniLight3D = true, SpotLight3D = true, DirectionalLight3D = true, OmniLight = true, SpotLight = true, DirectionalLight = true, + Skeleton3D = true, Skeleton = true, BoneAttachment3D = true, Marker3D = true, Position3D = true, CollisionShape3D = true, + StaticBody3D = true, RigidBody3D = true, CharacterBody3D = true, Area3D = true, StaticBody = true, RigidBody = true, + KinematicBody = true, Area = true, CollisionShape = true, VisibleOnScreenNotifier3D = true, GPUParticles3D = true, + CPUParticles3D = true, Sprite3D = true, Label3D = true, Path3D = true, PathFollow3D = true, RemoteTransform3D = true, + CSGBox3D = true, CSGSphere3D = true, CSGCylinder3D = true, CSGMesh3D = true, CSGCombiner3D = true, XROrigin3D = true, + XRCamera3D = true, VehicleBody3D = true, VehicleWheel3D = true, NavigationRegion3D = true, ReflectionProbe = true, + GridMap = true, AnimatableBody3D = true, ClippedCamera = true, InterpolatedCamera = true, SoftBody3D = true, +} + +local function plainProps(sec: any): { [string]: any } + local out: { [string]: any } = {} + for _, k in sec.order do + out[k] = sec.props[k] + end + return out +end + +local function camera(ctx: Ctx, typ: string, p: any): number + local fmt2 = ctx.format <= 2 + local cam: Types.Camera + if num(p.projection, 0) == 1 then + local size = num(p.size, 1) + cam = { type = "orthographic", xmag = size / 2, ymag = size / 2, znear = num(p.near, 0.05), zfar = num(p.far, if fmt2 then 100 else 4000) } :: any + else + cam = { type = "perspective", yfov = math.rad(num(p.fov, if fmt2 then 70 else 75)), znear = num(p.near, 0.05), zfar = num(p.far, if fmt2 then 100 else 4000) } :: any + end + table.insert(ctx.scene.cameras, cam) + return #ctx.scene.cameras +end + +local function light(ctx: Ctx, typ: string, p: any): number + local kind = LIGHT[typ] + local c = color(p.light_color, { 1, 1, 1, 1 }) + local lc = linear(c) + local l: Types.Light = { type = kind, color = { lc[1], lc[2], lc[3] }, intensity = num(p.light_energy, 1) } + if kind == "point" then + l.range = num(p.omni_range, 5) + elseif kind == "spot" then + l.range = num(p.spot_range, 5) + l.outerCone = math.rad(num(p.spot_angle, 45)) + l.innerCone = 0 + end + table.insert(ctx.scene.lights, l) + return #ctx.scene.lights +end + +local scene: (ctx: Ctx, doc: GodotVariant.Document, into: number?) -> (number?, string?) + +-- an instanced scene (instance=ExtResource) through opts.resolve; its root becomes the instancing node +local function instance(ctx: Ctx, v: any, node: number): string? + local id = idOf(v) + local p = if id then path(ctx.ext[id]) else nil + local resolve = ctx.opts.resolve + if not p or type(resolve) ~= "function" or ctx.depth >= 8 then + return nil + end + local rel = string.gsub(p, "^res://", "") + local ok, b = pcall(resolve, rel) + if not ok or type(b) ~= "buffer" then + table.insert(ctx.warnings, "instance " .. rel .. " not resolved") + return nil + end + local doc, err = GodotVariant.parse(buffer.tostring(b), { maxDepth = ctx.opts.maxDepth }) + if not doc then + return "instance " .. rel .. ": " .. tostring(err) + end + local sub: Ctx = { + scene = ctx.scene, + doc = doc, + format = 3, + ext = {}, + sub = {}, + meshes = {}, + materials = {}, + textures = {}, + opts = ctx.opts, + depth = ctx.depth + 1, + warnings = ctx.warnings, + } + local _, serr = scene(sub, doc, node) + return serr +end + +scene = function(ctx: Ctx, doc: GodotVariant.Document, into: number?): (number?, string?) + local sc = ctx.scene + local header = doc.sections[1] + ctx.format = if header and type(header.attrs.format) == "number" then header.attrs.format else 3 + for _, sec in doc.sections do + local id = sec.attrs.id + if id ~= nil and (type(id) == "string" or type(id) == "number") then + if sec.tag == "ext_resource" then + ctx.ext[tostring(id)] = sec + elseif sec.tag == "sub_resource" then + ctx.sub[tostring(id)] = sec + end + end + end + local byPath: { [string]: number } = {} + local root: number? = nil + local connections = {} + for _, sec in doc.sections do + if sec.tag == "node" then + local a = sec.attrs + local name = if type(a.name) == "string" then a.name else "Node" + local parent = a.parent + local typ = if type(a.type) == "string" then a.type else nil + local p = sec.props + local idx: number + local isRoot = parent == nil + if isRoot and into then + idx = into + else + table.insert(sc.nodes, { name = name, children = {} }) + idx = #sc.nodes + end + local node = sc.nodes[idx] + if not (isRoot and into) then + node.name = name + end + if isRoot then + if root then + return nil, "two root nodes" + end + root = idx + byPath["."] = idx + if not into then + table.insert(sc.roots, idx) + end + else + local pp = if type(parent) == "string" then parent else "." + local pi = byPath[pp] + if not pi then + return nil, "node " .. name .. ": no parent " .. pp + end + table.insert(sc.nodes[pi].children, idx) + byPath[if pp == "." then name else pp .. "/" .. name] = idx + end + if a.instance ~= nil then + local err = instance(ctx, a.instance, idx) + if err then + return nil, err + end + end + local m = nodeMatrix(p) + if m then + node.matrix = m + end + local extras: { [string]: any } = node.extras and node.extras.godot or {} + extras.type = typ or extras.type + extras.properties = plainProps(sec) + if a.instance ~= nil then + extras.instance = path(ctx.ext[idOf(a.instance) or ""] ) + end + if type(a.groups) == "table" then + extras.groups = a.groups + end + if p.visible == false then + extras.visible = false + end + node.extras = { godot = extras } + if typ and not THREE_D[typ] then + extras.is2D = string.find(typ, "2D$") ~= nil or typ == "Node2D" or nil + end + if typ and MESH[typ] or p.mesh ~= nil then + local overrides: { [number]: any }? = nil + for k, v in p do + local si = string.match(k, "^surface_material_override/(%d+)$") or string.match(k, "^material/(%d+)$") + if si and v ~= GodotVariant.null then + overrides = overrides or {} + ;(overrides :: any)[tonumber(si) :: number] = v + end + end + if p.material_override ~= nil and p.material_override ~= GodotVariant.null then + overrides = overrides or {} + for k = 0, 63 do + if (overrides :: any)[k] == nil then + (overrides :: any)[k] = p.material_override + end + end + end + if p.mesh ~= nil then + local mi, err = mesh(ctx, p.mesh, overrides) + if err then + return nil, err + end + node.mesh = mi + end + end + if typ and CAMERA[typ] then + node.camera = camera(ctx, typ, p) + elseif typ and LIGHT[typ] then + node.light = light(ctx, typ, p) + extras.lightColor = color(p.light_color, { 1, 1, 1, 1 }) + end + elseif sec.tag == "connection" then + table.insert(connections, sec.attrs) + end + end + if #connections > 0 and not into then + (sc.meta.source :: any).connections = connections + end + return root, nil +end + +function Build.scene(doc: GodotVariant.Document, opts: any): (Types.Scene?, string?) + local sc = S.new() + sc.meta.up = "y" + sc.meta.unit = 1 + local header = doc.sections[1] + sc.meta.source = { + format = "godot", + tag = if header then header.tag else nil, + version = if header then header.attrs.format else nil, + uid = if header then header.attrs.uid else nil, + } + local ctx: Ctx = { + scene = sc, + doc = doc, + format = 3, + ext = {}, + sub = {}, + meshes = {}, + materials = {}, + textures = {}, + opts = opts or {}, + depth = 0, + warnings = {}, + } + if header and header.tag ~= "gd_scene" then + return nil, "unsupported: a " .. header.tag .. " file is a resource, not a scene (data/tres)" + end + local _, err = scene(ctx, doc, nil) + if err then + return nil, err + end + if #ctx.warnings > 0 then + (sc.meta.source :: any).warnings = ctx.warnings + end + return sc, nil +end + +return Build diff --git a/src/Rosetta/model/godot/Primitives.luau b/src/Rosetta/model/godot/Primitives.luau new file mode 100644 index 0000000..a019fb5 --- /dev/null +++ b/src/Rosetta/model/godot/Primitives.luau @@ -0,0 +1,273 @@ +--!strict +-- model/godot/Primitives: Godot's primitive meshes (BoxMesh, PlaneMesh, QuadMesh, SphereMesh, CylinderMesh) as Godot +-- builds them. Ported from Godot 4.4 scene/resources/3d/primitive_meshes.cpp (MIT, licenses/godot-LICENSE.txt): the +-- same vertex order, normals, tangents, UVs and (clockwise, Godot's front face) indices; no UV2. +local Primitives = {} + +export type Arrays = { points: { number }, normals: { number }, tangents: { number }, uvs: { number }, indices: { number } } + +local TAU = math.pi * 2 + +local function num(v: any, d: number): number + return if type(v) == "number" and v == v then v else d +end + +local function vec(v: any, n: number, d: { number }): { number } + if type(v) == "table" and type(v.args) == "table" and #v.args >= n then + local out = {} + for i = 1, n do + out[i] = num(v.args[i], d[i]) + end + return out + end + return d +end + +local function new(): Arrays + return { points = {}, normals = {}, tangents = {}, uvs = {}, indices = {} } +end + +local function add(a: Arrays, px: number, py: number, pz: number, nx: number, ny: number, nz: number, tx: number, ty: number, tz: number, u: number, v: number) + local p, nn, t, uv = a.points, a.normals, a.tangents, a.uvs + p[#p + 1], p[#p + 2], p[#p + 3] = px, py, pz + nn[#nn + 1], nn[#nn + 2], nn[#nn + 3] = nx, ny, nz + t[#t + 1], t[#t + 2], t[#t + 3], t[#t + 4] = tx, ty, tz, 1 + uv[#uv + 1], uv[#uv + 2] = u, v +end + +-- the two triangles of a grid cell: p0 p1 t0, p1 t1 t0 (prev row, this row) +local function quad(a: Arrays, p0: number, p1: number, t0: number, t1: number) + local ix = a.indices + local n = #ix + ix[n + 1], ix[n + 2], ix[n + 3], ix[n + 4], ix[n + 5], ix[n + 6] = p0, p1, t0, p1, t1, t0 +end + +-- BoxMesh::create_mesh_array +local function box(props: any): Arrays + local size = vec(props.size, 3, { 1, 1, 1 }) + local sw, sh, sd = math.max(0, num(props.subdivide_width, 0)), math.max(0, num(props.subdivide_height, 0)), math.max(0, num(props.subdivide_depth, 0)) + local a = new() + local onethird, twothirds = 1 / 3, 2 / 3 + local sx, sy, sz = -size[1] / 2, -size[2] / 2, -size[3] / 2 + local point = 0 + local function faces(rows: number, cols: number, step: (number, number) -> ()) + local thisrow, prevrow = point, 0 + for j = 0, rows + 1 do + for i = 0, cols + 1 do + step(i, j) + point += 2 + if i > 0 and j > 0 then + local i2 = i * 2 + quad(a, prevrow + i2 - 2, prevrow + i2, thisrow + i2 - 2, thisrow + i2) + quad(a, prevrow + i2 - 1, prevrow + i2 + 1, thisrow + i2 - 1, thisrow + i2 + 1) + end + end + prevrow = thisrow + thisrow = point + end + end + -- front + back + faces(sh, sw, function(i: number, j: number) + local v = j / (2 * (sh + 1)) + local u = i / (3 * (sw + 1)) + local x = sx + i * size[1] / (sw + 1) + local y = sy + j * size[2] / (sh + 1) + add(a, x, -y, -sz, 0, 0, 1, 1, 0, 0, u, v) + add(a, -x, -y, sz, 0, 0, -1, -1, 0, 0, twothirds + u, v) + end) + -- left + right + faces(sh, sd, function(i: number, j: number) + local v = j / (2 * (sh + 1)) + local u = i / (3 * (sd + 1)) + local z = sz + i * size[3] / (sd + 1) + local y = sy + j * size[2] / (sh + 1) + add(a, -sx, -y, -z, 1, 0, 0, 0, 0, -1, onethird + u, v) + add(a, sx, -y, z, -1, 0, 0, 0, 0, 1, u, 0.5 + v) + end) + -- top + bottom + faces(sd, sw, function(i: number, j: number) + local v = j / (2 * (sd + 1)) + local u = i / (3 * (sw + 1)) + local x = sx + i * size[1] / (sw + 1) + local z = sz + j * size[3] / (sd + 1) + add(a, -x, -sy, -z, 0, 1, 0, -1, 0, 0, onethird + u, 0.5 + v) + add(a, x, sy, -z, 0, -1, 0, 1, 0, 0, twothirds + u, 0.5 + v) + end) + return a +end + +-- PlaneMesh::_create_mesh_array (QuadMesh: FACE_Z, size 1 x 1) +local function plane(props: any, isQuad: boolean): Arrays + local size = vec(props.size, 2, if isQuad then { 1, 1 } else { 2, 2 }) + local sw, sd = math.max(0, num(props.subdivide_width, 0)), math.max(0, num(props.subdivide_depth, 0)) + local off = vec(props.center_offset, 3, { 0, 0, 0 }) + local orient = num(props.orientation, if isQuad then 2 else 1) + local a = new() + local nx, ny, nz = 0, 1, 0 + if orient == 0 then + nx, ny, nz = 1, 0, 0 + elseif orient == 2 then + nx, ny, nz = 0, 0, 1 + end + local point, thisrow, prevrow = 0, 0, 0 + local z = -size[2] / 2 + for j = 0, sd + 1 do + local x = -size[1] / 2 + for i = 0, sw + 1 do + local u, v = i / (sw + 1), j / (sd + 1) + local px: number, py: number, pz: number = 0, 0, 0 + if orient == 0 then + px, py, pz = 0, z, x + elseif orient == 2 then + px, py, pz = -x, z, 0 + else + px, py, pz = -x, 0, -z + end + if orient == 0 then + add(a, px + off[1], py + off[2], pz + off[3], nx, ny, nz, 0, 0, -1, 1 - u, 1 - v) + else + add(a, px + off[1], py + off[2], pz + off[3], nx, ny, nz, 1, 0, 0, 1 - u, 1 - v) + end + point += 1 + if i > 0 and j > 0 then + quad(a, prevrow + i - 1, prevrow + i, thisrow + i - 1, thisrow + i) + end + x += size[1] / (sw + 1) + end + z += size[2] / (sd + 1) + prevrow = thisrow + thisrow = point + end + return a +end + +-- SphereMesh::create_mesh_array +local function sphere(props: any): Arrays + local radius, height = num(props.radius, 0.5), num(props.height, 1) + local radial, rings = math.max(1, num(props.radial_segments, 64)), math.max(1, num(props.rings, 32)) + local hemi = props.is_hemisphere == true + local scale = height / radius * (if hemi then 1 else 0.5) + local a = new() + local point, thisrow, prevrow = 0, 0, 0 + for j = 0, rings + 1 do + local v = j / (rings + 1) + local w: number, y: number = 0, -1 + if j ~= rings + 1 then + w = math.sin(math.pi * v) + y = math.cos(math.pi * v) + end + for i = 0, radial do + local u = i / radial + local x: number, z: number = 0, 1 + if i ~= radial then + x = math.sin(u * TAU) + z = math.cos(u * TAU) + end + if hemi and y < 0 then + add(a, x * radius * w, 0, z * radius * w, 0, -1, 0, z, 0, -x, u, v) + else + local nx, ny, nz = x * w * scale, y, z * w * scale + local l = math.sqrt(nx * nx + ny * ny + nz * nz) + if l > 0 then + nx, ny, nz = nx / l, ny / l, nz / l + end + add(a, x * w * radius, y * scale * radius, z * w * radius, nx, ny, nz, z, 0, -x, u, v) + end + point += 1 + if i > 0 and j > 0 then + quad(a, prevrow + i - 1, prevrow + i, thisrow + i - 1, thisrow + i) + end + end + prevrow = thisrow + thisrow = point + end + return a +end + +-- CylinderMesh::create_mesh_array +local function cylinder(props: any): Arrays + local top, bottom, height = num(props.top_radius, 0.5), num(props.bottom_radius, 0.5), num(props.height, 2) + local radial, rings = math.max(1, num(props.radial_segments, 64)), math.max(0, num(props.rings, 4)) + local a = new() + local point, thisrow, prevrow = 0, 0, 0 + local sideY = (bottom - top) / height + for j = 0, rings + 1 do + local v = j / (rings + 1) + local radius = top + (bottom - top) * v + local y = height * 0.5 - height * v + for i = 0, radial do + local u = i / radial + local x: number, z: number = 0, 1 + if i ~= radial then + x = math.sin(u * TAU) + z = math.cos(u * TAU) + end + local l = math.sqrt(x * x + sideY * sideY + z * z) + add(a, x * radius, y, z * radius, x / l, sideY / l, z / l, z, 0, -x, u, v * 0.5) + point += 1 + if i > 0 and j > 0 then + quad(a, prevrow + i - 1, prevrow + i, thisrow + i - 1, thisrow + i) + end + end + prevrow = thisrow + thisrow = point + end + local ix = a.indices + for _, cap in { { top, height * 0.5, 1 }, { bottom, height * -0.5, -1 } } do + local r: number, y: number, ny: number = cap[1] :: number, cap[2] :: number, cap[3] :: number + local enabled = if ny > 0 then props.cap_top ~= false else props.cap_bottom ~= false + if enabled and r > 0 then + thisrow = point + add(a, 0, y, 0, 0, ny, 0, 1, 0, 0, if ny > 0 then 0.25 else 0.75, 0.75) + point += 1 + for i = 0, radial do + local t = i / radial + local x: number, z: number = 0, 1 + if i ~= radial then + x = math.sin(t * TAU) + z = math.cos(t * TAU) + end + local u = if ny > 0 then (x + 1) * 0.25 else 0.5 + (x + 1) * 0.25 + local v = if ny > 0 then 0.5 + (z + 1) * 0.25 else 1 - (z + 1) * 0.25 + add(a, x * r, y, z * r, 0, ny, 0, 1, 0, 0, u, v) + point += 1 + if i > 0 then + if ny > 0 then + ix[#ix + 1], ix[#ix + 2], ix[#ix + 3] = thisrow, point - 1, point - 2 + else + ix[#ix + 1], ix[#ix + 2], ix[#ix + 3] = thisrow, point - 2, point - 1 + end + end + end + end + end + return a +end + +Primitives.KINDS = ({ BoxMesh = true, PlaneMesh = true, QuadMesh = true, SphereMesh = true, CylinderMesh = true, CubeMesh = true }) :: { [string]: boolean } + +function Primitives.build(kind: string, props: any): Arrays? + local a: Arrays + if kind == "BoxMesh" or kind == "CubeMesh" then + a = box(props) + elseif kind == "PlaneMesh" then + a = plane(props, false) + elseif kind == "QuadMesh" then + a = plane(props, true) + elseif kind == "SphereMesh" then + a = sphere(props) + elseif kind == "CylinderMesh" then + a = cylinder(props) + else + return nil + end + if props.flip_faces == true then + local ix = a.indices + for k = 1, #ix - 2, 3 do + ix[k + 1], ix[k + 2] = ix[k + 2], ix[k + 1] + end + end + return a +end + +return Primitives diff --git a/src/Rosetta/model/godot/Surface.luau b/src/Rosetta/model/godot/Surface.luau new file mode 100644 index 0000000..8f0637d --- /dev/null +++ b/src/Rosetta/model/godot/Surface.luau @@ -0,0 +1,483 @@ +--!strict +-- model/godot/Surface: ArrayMesh surfaces <-> Scene primitives. Godot 4.2+ surfaces (format version 2: vertex_data = +-- positions then octahedral normal / tangent pairs, attribute_data = colour / UV / UV2 / custom per vertex, +-- skin_data = bones + weights, index_data u16 / u32; RenderingServer mesh_create_surface_data_from_arrays), and the +-- "arrays" surfaces of format-2 .escn files (Godot 3 ArrayType order). Godot's front faces are clockwise: triangle +-- winding is reversed both ways. Not supported: compressed attributes, format version 1 (Godot 4.0 / 4.1), Godot 3 +-- binary array_data, blend shapes (counted in extras). +local Types = require("@rosetta/Types") +local GodotVariant = require("@rosetta/codecs/text/GodotVariant") +local Primitives = require("@rosetta/model/godot/Primitives") + +local Surface = {} + +local S = Types.Scene + +local function arr(n: number): { number } + return table.create(n) :: any +end + +local function bit(f: number, i: number): boolean + return math.floor(f / 2 ^ i) % 2 == 1 +end + +-- Vector3::octahedron_decode +local function octDecode(x: number, y: number): (number, number, number) + local fx, fy = x * 2 - 1, y * 2 - 1 + local nz = 1 - math.abs(fx) - math.abs(fy) + local t = math.clamp(-nz, 0, 1) + fx += if fx >= 0 then -t else t + fy += if fy >= 0 then -t else t + local l = math.sqrt(fx * fx + fy * fy + nz * nz) + if l == 0 then + return 0, 0, 1 + end + return fx / l, fy / l, nz / l +end + +-- Vector3::octahedron_encode +local function octEncode(x: number, y: number, z: number): (number, number) + local s = math.abs(x) + math.abs(y) + math.abs(z) + if s == 0 then + return 0.5, 0.5 + end + x, y, z = x / s, y / s, z / s + local ox, oy + if z >= 0 then + ox, oy = x, y + else + ox = (1 - math.abs(y)) * (if x >= 0 then 1 else -1) + oy = (1 - math.abs(x)) * (if y >= 0 then 1 else -1) + end + return ox * 0.5 + 0.5, oy * 0.5 + 0.5 +end + +local function u16(v: number): number + return math.clamp(math.floor(v * 65535), 0, 65535) +end + +local CUSTOM_SIZE = { [0] = 4, 4, 4, 8, 4, 8, 12, 16 } + +export type Lists = { + points: { number }, + normals: { number }?, + tangents: { number }?, + colors: buffer?, + uvs: { number }?, + uv2s: { number }?, + joints: { number }?, + weights: { number }?, + jointsPer: number, + indices: { number }?, + mode: string, +} + +-- a Godot 4 surface dictionary (format version 2) into lists +local function binary(d: any, maxVertices: number): (Lists?, string?) + local f = tonumber(d.format) or 0 + local vc = tonumber(d.vertex_count) or 0 + if vc < 0 or vc > maxVertices or vc % 1 ~= 0 then + return nil, "limit: vertex count " .. tostring(d.vertex_count) + end + if bit(f, 29) then + return nil, "unsupported: compressed surface attributes" + end + if not bit(f, 35) then + return nil, "unsupported: surface format version 1 (Godot 4.0 / 4.1)" + end + local vd = GodotVariant.bytes(d.vertex_data) + if not vd then + return nil, "surface without vertex_data" + end + local is2D = bit(f, 25) + local pstride = if is2D then 8 else 12 + local hasN, hasT = bit(f, 1), bit(f, 2) + local ntStride = (if hasN then 4 else 0) + (if hasT then 4 else 0) + if buffer.len(vd) < vc * (pstride + ntStride) then + return nil, "truncated vertex_data" + end + local L: Lists = { points = arr(vc * 3), jointsPer = 4, mode = "triangles" } + local P = L.points + for i = 0, vc - 1 do + local o = i * pstride + P[i * 3 + 1] = buffer.readf32(vd, o) + P[i * 3 + 2] = buffer.readf32(vd, o + 4) + P[i * 3 + 3] = if is2D then 0 else buffer.readf32(vd, o + 8) + end + if ntStride > 0 then + local base = vc * pstride + local N, T = if hasN then arr(vc * 3) else nil, if hasT then arr(vc * 4) else nil + for i = 0, vc - 1 do + local o = base + i * ntStride + if N then + local x, y, z = octDecode(buffer.readu16(vd, o) / 65535, buffer.readu16(vd, o + 2) / 65535) + N[i * 3 + 1], N[i * 3 + 2], N[i * 3 + 3] = x, y, z + o += 4 + end + if T then + local tx = buffer.readu16(vd, o) / 65535 + local ty = buffer.readu16(vd, o + 2) / 65535 * 2 - 1 + local sign = if ty >= 0 then 1 else -1 + local x, y, z = octDecode(tx, math.abs(ty)) + T[i * 4 + 1], T[i * 4 + 2], T[i * 4 + 3], T[i * 4 + 4] = x, y, z, sign + end + end + L.normals, L.tangents = N, T + end + -- attribute stream + local hasC, hasUV, hasUV2 = bit(f, 3), bit(f, 4), bit(f, 5) + local astride = (if hasC then 4 else 0) + (if hasUV then 8 else 0) + (if hasUV2 then 8 else 0) + for k = 0, 3 do + if bit(f, 6 + k) then + astride += CUSTOM_SIZE[math.floor(f / 2 ^ (13 + 3 * k)) % 8] + end + end + if astride > 0 then + local ad = GodotVariant.bytes(d.attribute_data) + if not ad or buffer.len(ad) < vc * astride then + return nil, "truncated attribute_data" + end + local C = if hasC then buffer.create(vc * 4) else nil + local UV, UV2 = if hasUV then arr(vc * 2) else nil, if hasUV2 then arr(vc * 2) else nil + for i = 0, vc - 1 do + local o = i * astride + if C then + buffer.writeu32(C, i * 4, buffer.readu32(ad, o)) + o += 4 + end + if UV then + UV[i * 2 + 1], UV[i * 2 + 2] = buffer.readf32(ad, o), buffer.readf32(ad, o + 4) + o += 8 + end + if UV2 then + UV2[i * 2 + 1], UV2[i * 2 + 2] = buffer.readf32(ad, o), buffer.readf32(ad, o + 4) + end + end + L.colors, L.uvs, L.uv2s = C, UV, UV2 + end + -- skin stream: bones then weights per vertex + local hasB, hasW = bit(f, 10), bit(f, 11) + if hasB and hasW then + local per = if bit(f, 27) then 8 else 4 + local sd = GodotVariant.bytes(d.skin_data) + if sd and buffer.len(sd) >= vc * per * 4 then + local J, W = arr(vc * per), arr(vc * per) + for i = 0, vc - 1 do + local o = i * per * 4 + for c = 0, per - 1 do + J[i * per + c + 1] = buffer.readu16(sd, o + c * 2) + W[i * per + c + 1] = buffer.readu16(sd, o + per * 2 + c * 2) / 65535 + end + end + L.joints, L.weights, L.jointsPer = J, W, per + end + end + local ic = tonumber(d.index_count) or 0 + if bit(f, 12) and ic > 0 then + local id = GodotVariant.bytes(d.index_data) + local size = if vc <= 65536 then 2 else 4 + if not id or buffer.len(id) < ic * size then + return nil, "truncated index_data" + end + local I = arr(ic) + for i = 0, ic - 1 do + local v = if size == 2 then buffer.readu16(id, i * 2) else buffer.readu32(id, i * 4) + if v >= vc then + return nil, "index out of range" + end + I[i + 1] = v + end + L.indices = I + end + local prim = tonumber(d.primitive) or 3 + L.mode = if prim == 0 then "points" elseif prim == 1 then "lines" elseif prim == 2 then "line_strip" elseif prim == 4 then "triangle_strip" else "triangles" + return L, nil +end + +local function nums(v: any): { number }? + return GodotVariant.numbers(v) +end + +-- a format-2 "arrays" surface (Godot 3 Mesh::ArrayType: vertex, normal, tangent, color, uv, uv2, bones, weights, index) +local function arrays(d: any, maxVertices: number): (Lists?, string?) + local a = d.arrays + local P = nums(a[1]) + if not P or #P % 3 ~= 0 then + return nil, "surface without a vertex array" + end + local vc = #P // 3 + if vc > maxVertices then + return nil, "limit: vertex count " .. vc + end + local L: Lists = { points = P, jointsPer = 4, mode = "triangles" } + local N, T = nums(a[2]), nums(a[3]) + L.normals = if N and #N == vc * 3 then N else nil + L.tangents = if T and #T == vc * 4 then T else nil + local C = nums(a[4]) + if C and #C == vc * 4 then + local cb = buffer.create(vc * 4) + for i = 1, #C do + buffer.writeu8(cb, i - 1, math.clamp(math.floor(C[i] * 255 + 0.5), 0, 255)) + end + L.colors = cb + end + local UV, UV2 = nums(a[5]), nums(a[6]) + L.uvs = if UV and #UV == vc * 2 then UV else nil + L.uv2s = if UV2 and #UV2 == vc * 2 then UV2 else nil + local B, W = nums(a[7]), nums(a[8]) + if B and W and #B == vc * 4 and #W == vc * 4 then + L.joints, L.weights = B, W + end + local I = nums(a[9]) + if I and #I > 0 then + for _, v in I do + if v < 0 or v >= vc then + return nil, "index out of range" + end + end + L.indices = I + end + local prim = tonumber(d.primitive) or 4 + L.mode = if prim == 0 then "points" elseif prim == 1 then "lines" elseif prim == 2 then "line_strip" elseif prim == 3 then "line_loop" elseif prim == 5 then "triangle_strip" elseif prim == 6 then "triangle_fan" else "triangles" + return L, nil +end + +function Surface.lists(d: any, maxVertices: number): (Lists?, string?) + if type(d) ~= "table" then + return nil, "bad surface" + end + if type(d.arrays) == "table" then + return arrays(d, maxVertices) + end + if d.array_data ~= nil then + return nil, "unsupported: Godot 3 binary surface (array_data)" + end + return binary(d, maxVertices) +end + +function Surface.fromPrimitiveArrays(a: Primitives.Arrays): Lists + return { points = a.points, normals = a.normals, tangents = a.tangents, uvs = a.uvs, indices = a.indices, jointsPer = 4, mode = "triangles" } +end + +local function acc(list: { number }, comps: number, t: string?): Types.Accessor + local count = #list // comps + local typ = t or "f32" + local a = S.accessor(nil, typ :: any, comps, count) + local d = a.data + for i, v in list do + if typ == "f32" then + buffer.writef32(d, (i - 1) * 4, v) + elseif typ == "u16" then + buffer.writeu16(d, (i - 1) * 2, v) + end + end + return a +end + +-- lists into a Primitive; triangles (and strips / fans, made into triangles) get counter-clockwise winding +function Surface.primitive(L: Lists): Types.Primitive + local n = #L.points // 3 + local attrs: { [string]: Types.Accessor } = { POSITION = acc(L.points, 3) } + if L.normals then + attrs.NORMAL = acc(L.normals :: { number }, 3) + end + if L.tangents then + attrs.TANGENT = acc(L.tangents :: { number }, 4) + end + if L.colors then + attrs.COLOR_0 = S.accessor(L.colors, "unorm8", 4, n) + end + if L.uvs then + attrs.TEXCOORD_0 = acc(L.uvs :: { number }, 2) + end + if L.uv2s then + attrs.TEXCOORD_1 = acc(L.uv2s :: { number }, 2) + end + if L.joints and L.weights then + local per = L.jointsPer + for set = 0, per // 4 - 1 do + local J, W = arr(n * 4), arr(n * 4) + for i = 0, n - 1 do + for c = 0, 3 do + J[i * 4 + c + 1] = (L.joints :: { number })[i * per + set * 4 + c + 1] or 0 + W[i * 4 + c + 1] = (L.weights :: { number })[i * per + set * 4 + c + 1] or 0 + end + end + attrs["JOINTS_" .. set] = acc(J, 4, "u16") + attrs["WEIGHTS_" .. set] = acc(W, 4) + end + end + local mode = L.mode + local idx = L.indices + if mode == "triangles" or mode == "triangle_strip" or mode == "triangle_fan" then + local src: { number } + if idx then + src = idx + else + src = arr(n) + for i = 1, n do + src[i] = i - 1 + end + end + local out: { number } = {} + if mode == "triangles" then + for k = 1, #src - 2, 3 do + table.insert(out, src[k]) + table.insert(out, src[k + 2]) + table.insert(out, src[k + 1]) + end + elseif mode == "triangle_strip" then + for k = 1, #src - 2 do + local a, b, c = src[k], src[k + 1], src[k + 2] + if k % 2 == 0 then + a, b = b, a + end + table.insert(out, a) + table.insert(out, c) + table.insert(out, b) + end + else + for k = 2, #src - 1 do + table.insert(out, src[1]) + table.insert(out, src[k + 1]) + table.insert(out, src[k]) + end + end + idx = out + mode = "triangles" + end + local prim: Types.Primitive = { attributes = attrs, mode = mode :: any } + if idx then + prim.indices = acc(idx :: { number }, 1, "u32") + local d = (prim.indices :: Types.Accessor).data + for i, v in idx :: { number } do + buffer.writeu32(d, (i - 1) * 4, v) + end + end + return prim +end + +-- ------------------------------------------------------------------------------------------------ write +local function perpendicular(x: number, y: number, z: number): (number, number, number) + local ax, ay, az = if math.abs(y) < 0.9 then 0 else 1, if math.abs(y) < 0.9 then 1 else 0, 0 + local tx, ty, tz = ay * z - az * y, az * x - ax * z, ax * y - ay * x + local l = math.sqrt(tx * tx + ty * ty + tz * tz) + if l == 0 then + return 1, 0, 0 + end + return tx / l, ty / l, tz / l +end + +-- a triangle Primitive as a Godot 4 surface dictionary (format version 2, uncompressed); nil for other modes +function Surface.encode(prim: Types.Primitive, triangles: { number }): any + local a = prim.attributes + local pos = a.POSITION + local rp = S.reader(pos) + if not rp then + return nil + end + local vc = pos.count + local an: any, at: any, ac: any, a0: any, a1: any = a.NORMAL, a.TANGENT, a.COLOR_0, a.TEXCOORD_0, a.TEXCOORD_1 + local rn = if an then S.reader(an) else nil + local rt = if at then S.reader(at) else nil + local rc = if ac then S.reader(ac) else nil + local cc = if ac then ac.components else 0 + local ru = if a0 then S.reader(a0) else nil + local ru2 = if a1 then S.reader(a1) else nil + local flags = 1 + 2 ^ 35 + if rn then + flags += 2 + 4 + end + local ntStride = if rn then 8 else 0 + local vd = buffer.create(vc * (12 + ntStride)) + local lo, hi = { math.huge, math.huge, math.huge }, { -math.huge, -math.huge, -math.huge } + for i = 0, vc - 1 do + for c = 0, 2 do + local v = rp(i, c) + buffer.writef32(vd, i * 12 + c * 4, v) + lo[c + 1], hi[c + 1] = math.min(lo[c + 1], v), math.max(hi[c + 1], v) + end + if rn then + local nx, ny, nz = rn(i, 0), rn(i, 1), rn(i, 2) + local o = vc * 12 + i * 8 + local ox, oy = octEncode(nx, ny, nz) + buffer.writeu16(vd, o, u16(ox)) + buffer.writeu16(vd, o + 2, u16(oy)) + local tx, ty, tz, sign + if rt then + tx, ty, tz, sign = rt(i, 0), rt(i, 1), rt(i, 2), if at.components >= 4 then rt(i, 3) else 1 + else + tx, ty, tz = perpendicular(nx, ny, nz) + sign = 1 + end + -- Vector3::octahedron_tangent_encode + local qx, qy = octEncode(tx, ty, tz) + qy = math.max(qy, 1 / 32767) * 0.5 + 0.5 + qy = if sign >= 0 then qy else 1 - qy + buffer.writeu16(vd, o + 4, u16(qx)) + buffer.writeu16(vd, o + 6, u16(qy)) + end + end + local astride = (if rc then 4 else 0) + (if ru then 8 else 0) + (if ru2 then 8 else 0) + local ad: buffer? = nil + if astride > 0 then + flags += (if rc then 8 else 0) + (if ru then 16 else 0) + (if ru2 then 32 else 0) + local b = buffer.create(vc * astride) + for i = 0, vc - 1 do + local o = i * astride + if rc then + for c = 0, 3 do + local v = if c < cc then rc(i, c) else 1 + buffer.writeu8(b, o + c, math.clamp(math.floor(v * 255 + 0.5), 0, 255)) + end + o += 4 + end + if ru then + buffer.writef32(b, o, ru(i, 0)) + buffer.writef32(b, o + 4, ru(i, 1)) + o += 8 + end + if ru2 then + buffer.writef32(b, o, ru2(i, 0)) + buffer.writef32(b, o + 4, ru2(i, 1)) + end + end + ad = b + end + local isize = if vc <= 65536 then 2 else 4 + local id = buffer.create(#triangles * isize) + -- counter-clockwise -> Godot's clockwise + for k = 0, #triangles // 3 - 1 do + local t = { triangles[k * 3 + 1], triangles[k * 3 + 3], triangles[k * 3 + 2] } + for c = 0, 2 do + if isize == 2 then + buffer.writeu16(id, (k * 3 + c) * 2, t[c + 1]) + else + buffer.writeu32(id, (k * 3 + c) * 4, t[c + 1]) + end + end + end + flags += 4096 + if vc == 0 then + lo, hi = { 0, 0, 0 }, { 0, 0, 0 } + end + local keys = { "aabb" } + local out: { [string]: any } = { aabb = GodotVariant.ctor("AABB", { lo[1], lo[2], lo[3], hi[1] - lo[1], hi[2] - lo[2], hi[3] - lo[3] }) } + if ad then + out.attribute_data = ad + table.insert(keys, "attribute_data") + end + out.format = flags + out.index_count = #triangles + out.index_data = id + out.primitive = 3 + out.uv_scale = GodotVariant.ctor("Vector4", { 0, 0, 0, 0 }) + out.vertex_count = vc + out.vertex_data = vd + for _, k in { "format", "index_count", "index_data", "material", "primitive", "uv_scale", "vertex_count", "vertex_data" } do + table.insert(keys, k) + end + return Types.object(out, keys) +end + +return Surface diff --git a/src/Rosetta/model/godot/Write.luau b/src/Rosetta/model/godot/Write.luau new file mode 100644 index 0000000..94f9c96 --- /dev/null +++ b/src/Rosetta/model/godot/Write.luau @@ -0,0 +1,327 @@ +--!strict +-- model/godot/Write: a Scene as a Godot 4 text scene (format 3): Node3D / MeshInstance3D / Camera3D / light nodes +-- with Transform3D transforms, ArrayMesh sub-resources (model/godot/Surface), StandardMaterial3D (linear colours back +-- to sRGB) and Texture2D ext_resources for textures with a uri. Several scene roots go under a "Root" Node3D. +local Types = require("@rosetta/Types") +local GodotVariant = require("@rosetta/codecs/text/GodotVariant") +local Surface = require("@rosetta/model/godot/Surface") + +local Write = {} + +local S = Types.Scene +local ctor = GodotVariant.ctor + +type Section = GodotVariant.Section + +local function section(tag: string, attrs: { any }): Section + local a, order = {}, {} + local i = 1 + while attrs[i] ~= nil do + if attrs[i + 1] ~= nil then + a[attrs[i]] = attrs[i + 1] + table.insert(order, attrs[i]) + end + i += 2 + end + return { tag = tag, attrs = a, attrOrder = order, props = {}, order = {} } +end + +local function prop(sec: Section, k: string, v: any) + if v == nil then + return + end + if sec.props[k] == nil then + table.insert(sec.order, k) + end + sec.props[k] = v +end + +local function toSrgb(c: number): number + c = math.clamp(c, 0, 1) + if c <= 0.0031308 then + return c * 12.92 + end + return 1.055 * c ^ (1 / 2.4) - 0.055 +end + +local function srgbColor(c: { number }?, alpha: number?): any + local v = c or { 1, 1, 1 } + return ctor("Color", { toSrgb(v[1] or 1), toSrgb(v[2] or 1), toSrgb(v[3] or 1), alpha or v[4] or 1 }) +end + +local function transform(m: { number }): any + return ctor("Transform3D", { m[1], m[5], m[9], m[2], m[6], m[10], m[3], m[7], m[11], m[13], m[14], m[15] }) +end + +local function isIdentity(m: { number }): boolean + for i = 1, 16 do + if math.abs(m[i] - S.IDENTITY[i]) > 1e-12 then + return false + end + end + return true +end + +local function safeName(s: string?, fallback: string): string + local n = string.gsub(s or "", "[%.:@/\"%%]", "_") + return if n == "" then fallback else n +end + +local function triangles(prim: any): { number }? + local mode = prim.mode or "triangles" + local pos = prim.attributes and prim.attributes.POSITION + if type(pos) ~= "table" then + return nil + end + local idx: { number } = {} + if prim.indices then + local rd = S.reader(prim.indices) + if not rd then + return nil + end + for i = 0, prim.indices.count - 1 do + idx[i + 1] = rd(i, 0) + end + else + for i = 0, pos.count - 1 do + idx[i + 1] = i + end + end + local out: { number } = {} + if mode == "triangles" then + for k = 1, #idx - 2, 3 do + table.insert(out, idx[k]) + table.insert(out, idx[k + 1]) + table.insert(out, idx[k + 2]) + end + elseif mode == "triangle_strip" then + for k = 1, #idx - 2 do + local a, b = idx[k], idx[k + 1] + if k % 2 == 0 then + a, b = b, a + end + table.insert(out, a) + table.insert(out, b) + table.insert(out, idx[k + 2]) + end + elseif mode == "triangle_fan" then + for k = 2, #idx - 1 do + table.insert(out, idx[1]) + table.insert(out, idx[k]) + table.insert(out, idx[k + 1]) + end + elseif mode == "polygons" and prim.faces then + local rd = S.reader(prim.faces) + local at = 1 + if rd then + for f = 0, prim.faces.count - 1 do + local size = rd(f, 0) + for k = 1, size - 2 do + table.insert(out, idx[at]) + table.insert(out, idx[at + k]) + table.insert(out, idx[at + k + 1]) + end + at += size + end + end + else + return nil + end + for _, v in out do + if v < 0 or v >= pos.count then + return nil + end + end + return out +end + +function Write.document(scene: any): (GodotVariant.Document?, string?) + local sections: { Section } = {} + local ext: { Section } = {} + local sub: { Section } = {} + local nodes: { Section } = {} + local texId: { [number]: string } = {} + local matId: { [number]: string } = {} + local meshId: { [number]: string } = {} + local textures = scene.textures or {} + local function textureRef(ref: any): any + if type(ref) ~= "table" then + return nil + end + local i = ref.texture + local tex = textures[i] + if not tex or type(tex.uri) ~= "string" or tex.uri == "" or string.sub(tex.uri, 1, 5) == "data:" then + return nil + end + if not texId[i] then + local id = (#ext + 1) .. "_tex" + texId[i] = id + local p = if string.find(tex.uri, "^res://") then tex.uri else "res://" .. tex.uri + table.insert(ext, section("ext_resource", { "type", "Texture2D", "path", p, "id", id })) + end + return ctor("ExtResource", { texId[i] }) + end + for i, m in scene.materials or {} do + local id = "StandardMaterial3D_" .. i + matId[i] = id + local sec = section("sub_resource", { "type", "StandardMaterial3D", "id", id }) + if type(m.name) == "string" then + prop(sec, "resource_name", m.name) + end + local mode = m.alphaMode + if mode == "blend" then + prop(sec, "transparency", 1) + elseif mode == "mask" then + prop(sec, "transparency", 2) + prop(sec, "alpha_scissor_threshold", m.alphaCutoff or 0.5) + end + if m.doubleSided then + prop(sec, "cull_mode", 2) + end + local unlit = type(m.extensions) == "table" and m.extensions.KHR_materials_unlit ~= nil + if unlit then + prop(sec, "shading_mode", 0) + end + local bc = if type(m.baseColor) == "table" then m.baseColor else { 1, 1, 1, 1 } + prop(sec, "albedo_color", srgbColor(bc, bc[4] or 1)) + prop(sec, "albedo_texture", textureRef(m.baseColorTexture)) + prop(sec, "metallic", m.metallic or 0) + prop(sec, "roughness", m.roughness or 1) + local mr = textureRef(m.metallicRoughnessTexture) + if mr then + prop(sec, "metallic_texture", mr) + prop(sec, "metallic_texture_channel", 2) + prop(sec, "roughness_texture", mr) + prop(sec, "roughness_texture_channel", 1) + end + local e = m.emissive + if type(e) == "table" and ((e[1] or 0) > 0 or (e[2] or 0) > 0 or (e[3] or 0) > 0) or m.emissiveTexture then + prop(sec, "emission_enabled", true) + prop(sec, "emission", srgbColor(e, 1)) + local strength = type(m.extensions) == "table" and m.extensions.KHR_materials_emissive_strength + if type(strength) == "table" and type(strength.emissiveStrength) == "number" then + prop(sec, "emission_energy_multiplier", strength.emissiveStrength) + end + prop(sec, "emission_texture", textureRef(m.emissiveTexture)) + end + local nt = textureRef(m.normalTexture) + if nt then + prop(sec, "normal_enabled", true) + prop(sec, "normal_texture", nt) + end + local ao = textureRef(m.occlusionTexture) + if ao then + prop(sec, "ao_enabled", true) + prop(sec, "ao_texture", ao) + end + table.insert(sub, sec) + end + for i, mesh in scene.meshes or {} do + local surfaces = {} + for _, prim in mesh.primitives or {} do + local tris = triangles(prim) + if tris then + local sd = Surface.encode(prim, tris) + if sd then + if prim.material and matId[prim.material] then + Types.set(sd, "material", ctor("SubResource", { matId[prim.material] })) + end + table.insert(surfaces, sd) + end + end + end + if #surfaces > 0 then + local id = "ArrayMesh_" .. i + meshId[i] = id + local sec = section("sub_resource", { "type", "ArrayMesh", "id", id }) + if type(mesh.name) == "string" then + prop(sec, "resource_name", mesh.name) + end + prop(sec, "_surfaces", surfaces) + table.insert(sub, sec) + end + end + local all = scene.nodes or {} + local roots = scene.roots or {} + local single = #roots == 1 and all[roots[1]] ~= nil + local visited: { [number]: boolean } = {} + local function emit(i: number, parent: string?, used: { [string]: boolean }, depth: number) + local node = all[i] + if not node or visited[i] or depth > 512 then + return + end + visited[i] = true + local base = safeName(node.name, "Node" .. i) + local name, k = base, 1 + while used[name] do + k += 1 + name = base .. k + end + used[name] = true + local cam = if node.camera then (scene.cameras or {})[node.camera] else nil + local li = if node.light then (scene.lights or {})[node.light] else nil + local typ = if node.mesh and meshId[node.mesh] then "MeshInstance3D" + elseif cam then "Camera3D" + elseif li then (if li.type == "spot" then "SpotLight3D" elseif li.type == "directional" then "DirectionalLight3D" else "OmniLight3D") + else "Node3D" + local sec = section("node", { "name", name, "type", typ, "parent", parent }) + local m = S.nodeMatrix(node) + if not isIdentity(m) then + prop(sec, "transform", transform(m)) + end + if typ == "MeshInstance3D" then + prop(sec, "mesh", ctor("SubResource", { meshId[node.mesh] })) + elseif typ == "Camera3D" then + if cam.type == "orthographic" then + prop(sec, "projection", 1) + prop(sec, "size", (cam.ymag or 0.5) * 2) + else + prop(sec, "fov", math.deg(cam.yfov or math.rad(75))) + end + prop(sec, "near", cam.znear or 0.05) + prop(sec, "far", cam.zfar or 4000) + elseif li then + prop(sec, "light_color", srgbColor(li.color, 1)) + prop(sec, "light_energy", li.intensity or 1) + if li.type == "point" then + prop(sec, "omni_range", li.range or 5) + elseif li.type == "spot" then + prop(sec, "spot_range", li.range or 5) + prop(sec, "spot_angle", math.deg(li.outerCone or math.pi / 4)) + end + end + local g = type(node.extras) == "table" and node.extras.godot + if type(g) == "table" and g.visible == false then + prop(sec, "visible", false) + end + table.insert(nodes, sec) + local path = if parent == nil then "." elseif parent == "." then name else parent .. "/" .. name + local childUsed = {} + for _, c in node.children or {} do + emit(c, path, childUsed, depth + 1) + end + end + if single then + emit(roots[1], nil, {}, 0) + else + table.insert(nodes, section("node", { "name", "Root", "type", "Node3D" })) + local used = {} + for _, r in roots do + emit(r, ".", used, 1) + end + end + local steps = #ext + #sub + 1 + table.insert(sections, section("gd_scene", { "load_steps", steps, "format", 3 })) + for _, s in ext do + table.insert(sections, s) + end + for _, s in sub do + table.insert(sections, s) + end + for _, s in nodes do + table.insert(sections, s) + end + return { sections = sections }, nil +end + +return Write diff --git a/src/Rosetta/model/godot/init.luau b/src/Rosetta/model/godot/init.luau new file mode 100644 index 0000000..47fee77 --- /dev/null +++ b/src/Rosetta/model/godot/init.luau @@ -0,0 +1,89 @@ +--!strict +-- model/godot: Godot text scenes (.tscn, .escn; formats 2-4) as a Scene, read + write (format 3); checked against +-- Godot 4's own loader. Supports: Node3D trees (transforms or position / rotation / scale), MeshInstance3D with +-- ArrayMesh surfaces and primitive meshes (Box, Plane, Quad, Sphere, Cylinder), StandardMaterial3D / SpatialMaterial +-- as PBR, surface material overrides, Camera3D, Omni / Spot / Directional lights, instanced scenes through +-- opts.resolve, non-3D nodes in extras.godot. Not supported: compressed or Godot 3 binary surfaces, skeletons and +-- animations (AnimationPlayer libraries stay sub-resources), blend shapes, other mesh / material resource types. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = require("@rosetta/core/Err") +local Bytes = require("@rosetta/core/Bytes") +local Sniff = require("@rosetta/core/Sniff") +local Types = require("@rosetta/Types") +local GodotVariant = require("@rosetta/codecs/text/GodotVariant") +local Build = require("@rosetta/model/godot/Build") +local Write = require("@rosetta/model/godot/Write") + +-- ------------------------------------------------------------------------------------------------ contract +local Godot = { + name = "godot", + category = "model", + extensions = { "tscn", "escn" }, + mime = { "application/x-godot-scene" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/GodotVariant", "codecs/model/Mat4" }, + caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, instances = true }, +} + +-- ------------------------------------------------------------------------------------------------ types +export type DecodeOptions = { + maxBytes: number?, -- default 2^28 + maxVertices: number?, -- per surface, default 2^24 + maxDepth: number?, -- value nesting, default 256 + resolve: ((string) -> buffer?)?, -- res:// paths without the prefix: textures, instanced scenes +} + +-- ------------------------------------------------------------------------------------------------ sniff +function Godot.sniff(r: Bytes.Reader): number + local h = Sniff.text(r, 256) + if string.match(h, "^%s*%[gd_scene[%s%]]") then + return 1 + end + return 0 +end + +-- ------------------------------------------------------------------------------------------------ decode +function Godot.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?) + local o: any = opts or {} + if r.limit - r.base > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local text = buffer.readstring(r.buf, r.base, r.limit - r.base) + local ok, doc, perr = pcall(function(): (GodotVariant.Document?, string?) + return GodotVariant.parse(text, { maxDepth = o.maxDepth }) + end) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad data: " .. tostring(doc)) + end + if not doc then + return nil, Err.from(perr) + end + if #doc.sections == 0 then + return nil, Err.new(Err.CORRUPT, "empty file") + end + local ok2, scene, msg = pcall(Build.scene, doc, o) + if not ok2 then + return nil, Err.from(tostring(scene)) + end + if not scene then + return nil, Err.from(msg) + end + return scene, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +function Godot.encode(scene: Types.Scene, opts: any?): (buffer?, Err.Err?) + if type(scene) ~= "table" or type(scene.nodes) ~= "table" then + return nil, Err.new(Err.ARG, "needs a Scene") + end + local ok, doc, msg = pcall(Write.document, scene) + if not ok then + return nil, Err.new(Err.ARG, "bad scene: " .. tostring(doc)) + end + if not doc then + return nil, Err.new(Err.ARG, msg or "bad scene") + end + return buffer.fromstring(GodotVariant.encode(doc)), nil +end + +return Godot diff --git a/tests/codecs/godotvariant.luau b/tests/codecs/godotvariant.luau new file mode 100644 index 0000000..22c3c0b --- /dev/null +++ b/tests/codecs/godotvariant.luau @@ -0,0 +1,47 @@ +-- codecs/text/GodotVariant tests: the Variant text syntax (strings and escapes, StringName / NodePath, arrays, +-- dictionaries with non-string keys, constructors, packed arrays incl. base64 bytes, typed arrays, Object), format +-- round trips, int / float keeping, section documents, limits, fuzz. Godot's own files: tests/model/godot.luau. +local T = require("@tests/T") +local GodotVariant = require("@rosetta/codecs/text/GodotVariant") + +local t = T.suite("godotvariant") + +local v = assert(GodotVariant.value("{\"a\": [1, 2.5, \"x\\ny\", &\"sn\", ^\"np\"], 3: Vector3(1, -2, 3e-05), \"b\": PackedByteArray(\"AAEC\")}")) +t:check(v.a[2] == 2.5 and v.a[3] == "x\ny" and v.a[4].type == "StringName" and v.a[5].type == "NodePath", "array values") +t:check(v[3].type == "Vector3" and v[3].args[3] == 3e-05, "number keys, constructors") +local b = GodotVariant.bytes(v.b) +t:check(b and buffer.len(b) == 3 and buffer.readu8(b, 2) == 2, "base64 PackedByteArray") +local again = assert(GodotVariant.value(GodotVariant.format(v))) +t:eq(GodotVariant.format(again), GodotVariant.format(v), "format round trip") +local typed = assert(GodotVariant.value("Array[int]([1, 2])")) +t:check(typed.type == "Array[int]" and #typed.args[1] == 2, "typed array") +t:eq(GodotVariant.format(typed), "Array[int]([1, 2])", "typed array format") +local _, e1 = GodotVariant.value("Vector3(1, 2") +t:check(e1 ~= nil, "unterminated constructor") +local deep = string.rep("[", 300) .. string.rep("]", 300) +local _, e2 = GodotVariant.value(deep) +t:check(e2 and string.find(e2, "limit", 1, true), "depth limit") + +do + local doc = assert(GodotVariant.parse("[gd_scene format=3]\n\n; comment\n[node name=\"A\" type=\"Node3D\"]\nmetadata/x = 1.0\n\"quoted key\" = [1, 2.0]\n")) + t:eq(#doc.sections, 2, "sections") + local n = doc.sections[2] + t:check(n.attrs.name == "A" and n.props["metadata/x"] == 1 and n.props["quoted key"][2] == 2, "attributes and properties") + local text = GodotVariant.encode(doc) + t:check(string.find(text, "metadata/x = 1.0", 1, true) ~= nil and string.find(text, "[1, 2.0]", 1, true) ~= nil, "floats keep their .0") + local o = assert(GodotVariant.value("Object(Resource,\"a\":1,\"b\":\"x\")")) + t:check(o.type == "Object" and o.class == "Resource" and o.args[1].b == "x", "Object") + t:eq(GodotVariant.number(0.1), "0.1", "shortest float") + t:eq(GodotVariant.format("a\"b\\c"), "\"a\\\"b\\\\c\"", "string escapes") + local u = assert(GodotVariant.value("\"\\u00e9\\ud83d\\ude00\"")) + t:eq(u, "\u{e9}\u{1f600}", "unicode escapes and surrogate pairs") +end + +local samples = { + "[gd_scene format=3]\n[node name=\"A\" type=\"Node3D\"]\ntransform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)\n", + "[gd_resource type=\"X\" format=3]\n[resource]\nd = {\n\"k\": [1, &\"s\", NodePath(\"a\"), PackedFloat32Array(1, 2)]\n}\n", +} +t:fuzz("parse", function(b: buffer) + return GodotVariant.parse(buffer.tostring(b)) +end, samples) +t:done() diff --git a/tests/data/tres.luau b/tests/data/tres.luau new file mode 100644 index 0000000..b92a503 --- /dev/null +++ b/tests/data/tres.luau @@ -0,0 +1,100 @@ +-- data/tres tests: Godot text resources against Godot 4's loader (every stored property, var_to_str text parsed back +-- by codecs/text/GodotVariant), int / float keeping, our re-encoded files loaded by Godot with the same properties; +-- errors; fuzz. Fixtures: tools/fixtures/godot.py. +local T = require("@tests/T") +local F = require("@rosetta") +local Tres = require("@rosetta/data/tres") +local GodotVariant = require("@rosetta/codecs/text/GodotVariant") +local Bytes = require("@rosetta/core/Bytes") +local Err = require("@rosetta/core/Err") +local Fx = require("@tests/gen/godot") +local Ours = require("@tests/gen/godot_ours") + +local t = T.suite("tres") +local samples = {} + +t:eq(Tres.name, "tres", "name") +t:eq(Tres.category, "data", "category") +t:check(Tres.caps.decode and Tres.caps.encode, "caps") + +local function same(a: any, b: any): boolean + if type(a) == "number" and type(b) == "number" then + return a == b or math.abs(a - b) <= 1e-6 * math.max(1, math.abs(b)) or (a ~= a and b ~= b) + elseif type(a) == "table" and type(b) == "table" then + if GodotVariant.isCtor(a) ~= GodotVariant.isCtor(b) or (GodotVariant.isCtor(a) and a.type ~= b.type) then + return false + end + if GodotVariant.isCtor(a) and a.type == "Object" then + return a.class == b.class -- Godot lists every stored property of the object + end + local x, y = if GodotVariant.isCtor(a) then a.args else a, if GodotVariant.isCtor(b) then b.args else b + for k, v in x do + if not same(v, y[k]) then + return false + end + end + for k in y do + if x[k] == nil then + return false + end + end + return true + end + return a == b +end +for _, c in Fx.tres do + local v, err = Tres.decode(Bytes.reader(buffer.fromstring(c.data))) + t:check(v, c.name .. ": decode: " .. tostring(err)) + t:eq(Tres.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, c.name .. ": sniff") + table.insert(samples, c.data) + local g = c.godot + t:check(g.ok, c.name .. ": Godot loads it") + if v and g.ok then + local n = 0 + for k, text in g.props do + local mine = v.properties[k] + if mine ~= nil and not (GodotVariant.isCtor(mine) and (mine.type == "SubResource" or mine.type == "ExtResource")) then + local theirs, perr = GodotVariant.value(text) + t:check(perr == nil and same(mine, theirs), c.name .. ": " .. k .. " = Godot's " .. text) + n += 1 + end + end + t:note("%s: %d properties against Godot", c.name, n) + local again = assert(Tres.decode(Bytes.reader(assert(Tres.encode(v))))) + t:eq(GodotVariant.format(again.properties), GodotVariant.format(v.properties), c.name .. ": round trip") + end + local ours + for _, o in Ours do + if o.name == "ours_" .. c.name then + ours = o + end + end + t:check(ours and ours.godot.ok, c.name .. ": Godot loads our .tres") + if ours and ours.godot.ok and g.ok then + for k, text in g.props do + t:eq(ours.godot.props[k], text, c.name .. ": our .tres in Godot: " .. k) + end + end +end +local data = assert(Tres.decode(Bytes.reader(buffer.fromstring(Fx.tres[2].data)))) +t:check(data.type == "Resource" and data.scriptClass == "Stats" and data.properties.hp == 12, "tres header and values") +t:eq(data.subresources[1].properties.point_count, 2, "sub-resource properties") +t:eq(data.external[1].path, "res://stats.gd", "external resources") +local _, e = Tres.decode(Bytes.reader(buffer.fromstring(Fx.cases[1].data))) +t:check(e and e.code == Err.UNSUPPORTED, "a scene is not a resource") +t:eq(F.detect(Fx.tres[1].data), "tres", "F.detect tres") + +do + local v = assert(Tres.decode(Bytes.reader(buffer.fromstring("[gd_resource type=\"Curve\" format=3]\n[resource]\n_data = [Vector2(0, 0), 0.0, 1.0, 0, 0]\nx = 2.0\n")))) + local s = buffer.tostring(assert(Tres.encode(v))) + t:check(string.find(s, "0.0, 1.0, 0, 0", 1, true) ~= nil and string.find(s, "x = 2.0", 1, true) ~= nil, "integral floats stay floats") + local _, e = Tres.decode(Bytes.reader(buffer.fromstring("[gd_resource type=\"X\" format=3]\n[resource]\nx = [1, 2\n"))) + t:check(e ~= nil, "truncated array") + local _, e2 = Tres.encode({} :: any) + t:check(e2 and e2.code == Err.ARG, "encode arg") +end + +t:fuzz("decode", function(b: buffer) + return Tres.decode(Bytes.reader(b)) +end, samples, { mutations = 80, garbage = 20 }) +t:done() diff --git a/tests/model/godot.luau b/tests/model/godot.luau new file mode 100644 index 0000000..24151e8 --- /dev/null +++ b/tests/model/godot.luau @@ -0,0 +1,356 @@ +-- model/godot tests: scenes saved by Godot 4 against Godot's own loader (node transforms, surface arrays, materials, +-- cameras, lights, primitive meshes, instanced scenes, 2D nodes); a format-2 .escn; our .tscn writer's output loaded by +-- Godot and compared with the original; codecs/text/GodotVariant values; errors; fuzz. Fixtures: tools/fixtures/godot.py. +local T = require("@tests/T") +local F = require("@rosetta") +local Godot = require("@rosetta/model/godot") +local GodotVariant = require("@rosetta/codecs/text/GodotVariant") +local Bytes = require("@rosetta/core/Bytes") +local Err = require("@rosetta/core/Err") +local Types = require("@rosetta/Types") +local Fx = require("@tests/gen/godot") +local Ours = require("@tests/gen/godot_ours") + +local t = T.suite("godot") +local S = Types.Scene + +local function decode(s: string | buffer, files: any?, opts: any?): (any, any) + local b = if type(s) == "string" then buffer.fromstring(s) else s + local o = opts or {} + o.resolve = function(p: string): buffer? + local f = files and files[p] + return if f then buffer.fromstring(f) else nil + end + return Godot.decode(Bytes.reader(b), o) +end + +t:eq(Godot.name, "godot", "name") +t:eq(Godot.category, "model", "category") +t:check(Godot.caps.decode and Godot.caps.encode, "caps") + +local function list(acc: any): { number } + if not acc then + return {} + end + local rd = S.reader(acc) :: any + local out = {} + for i = 0, acc.count - 1 do + for c = 0, acc.components - 1 do + table.insert(out, rd(i, c)) + end + end + return out +end + +-- our Scene in the dump's shape (tools/fixtures/_godot_dump.gd): paths, local transforms as basis rows + origin, +-- surface arrays with Godot's clockwise indices +local function asDump(scene: any): { [string]: any } + local out = {} + local function visit(i: number, path: string) + local n = scene.nodes[i] + local g = n.extras and n.extras.godot or {} + local e: any = { path = path, class = g.type } + local m = S.nodeMatrix(n) + e.xf = { m[1], m[5], m[9], m[2], m[6], m[10], m[3], m[7], m[11], m[13], m[14], m[15] } + e.visible = g.visible ~= false + if n.mesh then + local surfs = {} + for _, p in scene.meshes[n.mesh].primitives do + local idx = list(p.indices) + for k = 1, #idx - 2, 3 do + idx[k + 1], idx[k + 2] = idx[k + 2], idx[k + 1] + end + local mat = p.material and scene.materials[p.material] + local md = nil + if mat then + local x = mat.extras.godot + local tex = mat.baseColorTexture and scene.textures[mat.baseColorTexture.texture] + md = { + albedo = x.albedo, + metallic = mat.metallic, + roughness = mat.roughness, + emission = if x.emission then { x.emission[1], x.emission[2], x.emission[3] } else nil, + texture = if tex then "res://" .. tex.uri else nil, + transparency = if mat.alphaMode == "blend" then 1 else 0, + cull = if mat.doubleSided then 2 else 0, + } + end + local colors = {} + for k, v in list(p.attributes.COLOR_0) do + colors[k] = v + end + table.insert(surfs, { + vertex = list(p.attributes.POSITION), + normal = list(p.attributes.NORMAL), + tangent = list(p.attributes.TANGENT), + uv = list(p.attributes.TEXCOORD_0), + uv2 = list(p.attributes.TEXCOORD_1), + color = colors, + index = idx, + material = md, + }) + end + e.surfaces = surfs + end + if n.camera then + local c = scene.cameras[n.camera] + e.camera = if c.type == "orthographic" then { projection = 1, size = c.ymag * 2, near = c.znear, far = c.zfar } else { projection = 0, fov = math.deg(c.yfov), near = c.znear, far = c.zfar } + end + if n.light then + local l = scene.lights[n.light] + local raw = g.lightColor or { 1, 1, 1 } + e.light = { color = { raw[1], raw[2], raw[3] }, energy = l.intensity, range = l.range, angle = if l.outerCone then math.deg(l.outerCone) else nil } + end + out[path] = e + for _, c in n.children do + local cn = scene.nodes[c].name + visit(c, if path == "." then cn else path .. "/" .. cn) + end + end + for _, r in scene.roots do + visit(r, ".") + end + return out +end + +local function close(a: { number }?, b: { number }?, eps: number): (boolean, string) + a, b = a or {}, b or {} + if #a ~= #b then + return false, "length " .. #a .. " vs " .. #b + end + for i = 1, #a do + if math.abs(a[i] - b[i]) > eps * math.max(1, math.abs(b[i])) then + return false, "[" .. i .. "] " .. a[i] .. " vs " .. b[i] + end + end + return true, "" +end + +-- the 3D facts of a dump node `got` against the reference `want` +local function compare(got: any, want: any, label: string, eps: number) + if want.xf then + local ok, why = close(got.xf, want.xf, 1e-5) + t:check(ok, label .. ": transform " .. why) + t:eq(got.visible, want.visible, label .. ": visible") + end + if want.surfaces then + t:eq(#(got.surfaces or {}), #want.surfaces, label .. ": surfaces") + for k, ws in want.surfaces do + local gs = (got.surfaces or {})[k] + if gs then + for _, f in { "vertex", "uv", "uv2" } do + local ok, why = close(gs[f], ws[f], 1e-5) + t:check(ok, label .. ": surface " .. k .. " " .. f .. " " .. why) + end + for _, f in { "normal", "tangent" } do + local ok, why = close(gs[f], ws[f], eps) + t:check(ok, label .. ": surface " .. k .. " " .. f .. " " .. why) + end + local ok, why = close(gs.color, ws.color, 1 / 255 + 1e-6) + t:check(ok, label .. ": surface " .. k .. " color " .. why) + local wi = ws.index + if #wi == 0 then + for i = 0, #ws.vertex // 3 - 1 do + wi[i + 1] = i + end + end + local gi = gs.index + if #gi == 0 then + for i = 0, #gs.vertex // 3 - 1 do + gi[i + 1] = i + end + end + local iok, iwhy = close(gi, wi, 0) + t:check(iok, label .. ": surface " .. k .. " index " .. iwhy) + local wm, gm = ws.material, gs.material + if wm then + t:check(gm ~= nil, label .. ": surface " .. k .. " material") + if gm then + local aok, awhy = close(gm.albedo, wm.albedo, 1e-5) + t:check(aok, label .. ": albedo " .. awhy) + t:check(math.abs(gm.metallic - wm.metallic) < 1e-5 and math.abs(gm.roughness - wm.roughness) < 1e-5, label .. ": metallic / roughness") + local eok, ewhy = close(gm.emission, wm.emission, 1e-5) + t:check(eok, label .. ": emission " .. ewhy) + t:eq(gm.texture, wm.texture, label .. ": albedo texture") + t:eq(gm.transparency, wm.transparency, label .. ": transparency") + t:eq(gm.cull, wm.cull, label .. ": cull") + end + end + end + end + end + if want.camera then + local gc, wc = got.camera or {}, want.camera + t:eq(gc.projection, wc.projection, label .. ": projection") + if wc.projection == 1 then + t:check(math.abs(gc.size - wc.size) < 1e-5, label .. ": ortho size") + else + t:check(math.abs(gc.fov - wc.fov) < 1e-5, label .. ": fov") + end + t:check(math.abs(gc.near - wc.near) < 1e-6 and math.abs(gc.far - wc.far) < 1e-3, label .. ": near / far") + end + if want.light then + local gl, wl = got.light or {}, want.light + local ok, why = close(gl.color, wl.color, 1e-5) + t:check(ok, label .. ": light colour " .. why) + t:check(math.abs((gl.energy or -1) - wl.energy) < 1e-5, label .. ": light energy") + if wl.range then + t:check(math.abs((gl.range or -1) - wl.range) < 1e-5, label .. ": light range") + end + if wl.angle then + t:check(math.abs((gl.angle or -1) - wl.angle) < 1e-4, label .. ": spot angle") + end + end +end + +local scenes = {} +local samples = {} +for _, c in Fx.cases do + local scene, err = decode(c.data, c.files) + t:check(scene, c.name .. ": decode: " .. tostring(err)) + t:eq(Godot.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, c.name .. ": sniff") + scenes[c.name] = scene + table.insert(samples, c.data) + if scene and c.dump then + t:check(c.dump.ok, c.name .. ": Godot loads it") + local mine = asDump(scene) + local n = 0 + for _, want in c.dump.nodes do + local got = mine[want.path] + t:check(got, c.name .. ": node " .. want.path) + if got then + t:eq(got.class, want.class, c.name .. ": " .. want.path .. " class") + compare(got, want, c.name .. ": " .. want.path, 3e-4) + n += 1 + end + end + t:note("%s: %d nodes against Godot", c.name, n) + end +end + +-- Godot reads what we write +for _, o in Ours do + if not o.dump then + continue + end + t:check(o.dump.ok, o.name .. ": Godot loads our .tscn") + local base = string.match(o.name, "^ours_(.*)%.tscn$") + local ref + for _, c in Fx.cases do + if string.gsub(c.name, "%.%w+$", "") == base then + ref = c + end + end + if ref and ref.dump and o.dump.ok then + local byPath = {} + for _, nd in o.dump.nodes do + byPath[nd.path] = nd + end + local n = 0 + for _, want in ref.dump.nodes do + if want.xf then + local got = byPath[want.path] + t:check(got, o.name .. ": node " .. want.path) + if got then + compare(got, want, o.name .. ": " .. want.path, 5e-4) + n += 1 + end + end + end + t:note("%s: %d 3D nodes after our writer", o.name, n) + elseif o.dump.ok and base == "hand" then + -- the escn has no Godot reference: compare Godot's reading of ours with our reading of the escn + local mine = asDump(scenes["hand.escn"]) + for _, got in o.dump.nodes do + local want = mine[got.path] + t:check(want, o.name .. ": node " .. got.path) + if want and want.xf then + compare(got, want, o.name .. ": " .. got.path, 5e-4) + end + end + end +end + +-- details +do + local s = scenes["main.tscn"] + t:eq(s.meta.source.version, 4, "header format") + t:eq(s.meta.up, "y", "up axis") + local shape + for _, n in s.nodes do + if n.name == "Shape" then + shape = n + end + end + local m = s.materials[s.meshes[shape.mesh].primitives[1].material] + t:eq(m.name, "Painted", "material name") + t:check(math.abs(m.baseColor[1] - ((0.8 + 0.055) / 1.055) ^ 2.4) < 1e-6, "albedo sRGB -> linear") + t:eq(m.extensions.KHR_materials_emissive_strength.emissiveStrength, 2, "emission energy") + t:eq(s.textures[m.baseColorTexture.texture].uri, "checker.png", "texture path") + t:check(s.textures[m.baseColorTexture.texture].data ~= nil, "texture bytes through resolve") + local hud + for _, n in s.nodes do + if n.name == "Hud" then + hud = n + end + end + t:check(hud.extras.godot.is2D and hud.extras.godot.properties.rotation == 0.5, "2D node kept in extras") + local pos = hud.extras.godot.properties.position + t:check(GodotVariant.isCtor(pos) and pos.type == "Vector2" and pos.args[2] == 20, "2D position as a Vector2") + -- without resolve: the instance stays an empty node + local bare = assert(decode(Fx.cases[2].data)) + local inst + for _, n in bare.nodes do + if n.name == "PartInstance" then + inst = n + end + end + t:check(inst and #inst.children == 0, "unresolved instance") + local e = scenes["hand.escn"] + t:eq(e.meta.source.version, 2, "escn format 2") + t:eq(#e.cameras, 1, "escn camera") + t:check(math.abs(math.deg(e.cameras[1].yfov) - 60) < 1e-9 and e.cameras[1].zfar == 250, "escn camera fov / far") + t:eq(e.lights[1].range, 9, "escn light range") + local cube = e.nodes[2] + local p = e.meshes[cube.mesh].primitives[1] + t:eq(p.indices.count, 6, "escn arrays surface") + t:check(e.materials[1].doubleSided and e.materials[1].metallic == 0.5, "SpatialMaterial") + local strip = e.meshes[e.nodes[3].mesh].primitives[1] + t:check(strip.mode == "triangles" and strip.indices.count == 6 and strip.attributes.COLOR_0 ~= nil, "escn triangle strip -> triangles") + t:check(cube.matrix[14] == 3 and cube.matrix[7] == 1, "Transform (format 2) rows") +end + +-- any Scene: through F.save +do + local s = S.new() + local P = S.accessor(nil, "f32", 3, 3) + for i, v in { 0, 0, 0, 1, 0, 0, 0, 1, 0 } do + buffer.writef32(P.data, (i - 1) * 4, v) + end + s.meshes[1] = { primitives = { { attributes = { POSITION = P }, mode = "triangles" } } } + s.nodes = { { name = "a/b", children = {}, mesh = 1, translation = { 1, 2, 3 } }, { name = "a/b", children = {} } } + s.roots = { 1, 2 } + local out = assert(F.save(s, nil, { format = "godot" })) + local back = assert(decode(out)) + t:eq(back.nodes[1].name, "Root", "two roots under Root") + t:check(back.nodes[2].name == "a_b" and back.nodes[3].name == "a_b2", "names sanitised and unique") + t:eq(back.nodes[2].matrix[14], 2, "transform") + t:eq(back.meshes[1].primitives[1].indices.count, 3, "triangle") + t:eq(F.detect(out), "godot", "F.detect") +end + +do + local _, e = decode("[gd_resource type=\"Resource\" format=3]\n[resource]\nx = 1\n") + t:check(e and e.code == Err.UNSUPPORTED, "a .tres is not a scene") + local _, e2 = decode("[gd_scene format=3]\n[node name=\"A\" parent=\"missing\"]\n") + t:check(e2 and e2.code == Err.CORRUPT, "missing parent") + local _, e3 = decode("[gd_scene format=3]\nx = Vector3(1,\n") + t:check(e3 ~= nil, "truncated value") + local _, e4 = Godot.encode({} :: any) + t:check(e4 and e4.code == Err.ARG, "encode arg") +end + +t:fuzz("decode", function(b: buffer) + return Godot.decode(Bytes.reader(b)) +end, samples, { mutations = 80, garbage = 20 }) +t:done() diff --git a/tools/fixtures/_godot_dump.gd b/tools/fixtures/_godot_dump.gd new file mode 100644 index 0000000..61d565b --- /dev/null +++ b/tools/fixtures/_godot_dump.gd @@ -0,0 +1,80 @@ +# tools/fixtures/_godot_dump.gd: run by tools/fixtures/godot.py (godot --headless -s ... -- ...): loads +# each scene with Godot's own loader and prints one JSON line per scene: every node (path, class, global transform as +# 12 numbers: basis rows then origin, visibility), every MeshInstance3D's surfaces (mesh.surface_get_arrays: vertex, +# normal, tangent, uv, uv2, color, index; the active material's albedo / metallic / roughness / emission / texture +# path / transparency / cull mode), cameras and lights. +extends SceneTree + +func xf(t): + var b = t.basis + return [b.x.x, b.y.x, b.z.x, b.x.y, b.y.y, b.z.y, b.x.z, b.y.z, b.z.z, t.origin.x, t.origin.y, t.origin.z] + +func flat(a): + var out = [] + if a == null: + return out + for v in a: + if v is Vector3: + out.append_array([v.x, v.y, v.z]) + elif v is Vector2: + out.append_array([v.x, v.y]) + elif v is Color: + out.append_array([v.r, v.g, v.b, v.a]) + else: + out.append(v) + return out + +func mat(m): + if m == null: + return null + var d = {"class": m.get_class(), "name": m.resource_name} + if m is BaseMaterial3D: + d["albedo"] = [m.albedo_color.r, m.albedo_color.g, m.albedo_color.b, m.albedo_color.a] + d["metallic"] = m.metallic + d["roughness"] = m.roughness + d["emission"] = [m.emission.r, m.emission.g, m.emission.b] if m.emission_enabled else null + d["emission_energy"] = m.emission_energy_multiplier + d["texture"] = m.albedo_texture.resource_path if m.albedo_texture else null + d["transparency"] = m.transparency + d["cull"] = m.cull_mode + return d + +func walk(n, root, out): + var e = {"path": str(root.get_path_to(n)), "class": n.get_class()} + if n is Node3D: + e["xf"] = xf(n.transform) + e["visible"] = n.visible + if n is MeshInstance3D and n.mesh: + var surfs = [] + for s in n.mesh.get_surface_count(): + var a = n.mesh.surface_get_arrays(s) + surfs.append({ + "vertex": flat(a[Mesh.ARRAY_VERTEX]), "normal": flat(a[Mesh.ARRAY_NORMAL]), "tangent": flat(a[Mesh.ARRAY_TANGENT]), + "uv": flat(a[Mesh.ARRAY_TEX_UV]), "uv2": flat(a[Mesh.ARRAY_TEX_UV2]), "color": flat(a[Mesh.ARRAY_COLOR]), + "index": flat(a[Mesh.ARRAY_INDEX]), "material": mat(n.get_active_material(s)), + }) + e["surfaces"] = surfs + e["mesh_class"] = n.mesh.get_class() + if n is Camera3D: + e["camera"] = {"fov": n.fov, "near": n.near, "far": n.far, "projection": n.projection, "size": n.size} + if n is Light3D: + var l = {"color": [n.light_color.r, n.light_color.g, n.light_color.b], "energy": n.light_energy} + if n is OmniLight3D: + l["range"] = n.omni_range + if n is SpotLight3D: + l["range"] = n.spot_range + l["angle"] = n.spot_angle + e["light"] = l + out.append(e) + for c in n.get_children(): + walk(c, root, out) + +func _init(): + for path in OS.get_cmdline_user_args(): + var ps = load(path) + var res = {"file": path, "ok": ps != null, "nodes": []} + if ps: + var root = ps.instantiate() + walk(root, root, res["nodes"]) + print("JSON:" + JSON.stringify(res)) + quit() diff --git a/tools/fixtures/_godot_encode.luau b/tools/fixtures/_godot_encode.luau new file mode 100644 index 0000000..0587d8a --- /dev/null +++ b/tools/fixtures/_godot_encode.luau @@ -0,0 +1,45 @@ +-- tools/fixtures/_godot_encode: run by tools/fixtures/godot.py (luau CLI, repo root): decodes every Godot scene case +-- (files through resolve) and writes it with our .tscn writer, printing "ours_.tscn\t" lines for Godot to +-- load, and every .tres case through data/tres ("ours_.tres"). +local Godot = require("@rosetta/model/godot") +local Bytes = require("@rosetta/core/Bytes") +local Fx = require("@tests/gen/godot") + +local HEX = {} +for i = 0, 255 do + HEX[i] = string.format("%02x", i) +end +local function hex(s: string): string + return (string.gsub(s, ".", function(c: string): string + return HEX[string.byte(c)] + end)) +end + +for _, c in Fx.cases do + local scene, err = Godot.decode(Bytes.reader(buffer.fromstring(c.data)), { + resolve = function(p: string): buffer? + local f = c.files[p] + return if f then buffer.fromstring(f) else nil + end, + }) + if scene then + local out = Godot.encode(scene) + if out then + local base = string.gsub(c.name, "%.%w+$", "") + print("ours_" .. base .. ".tscn\t" .. hex(buffer.tostring(out))) + end + else + print("decode failed " .. c.name .. ": " .. tostring(err)) + end +end + +local Tres = require("@rosetta/data/tres") +for _, c in Fx.tres do + local v = Tres.decode(Bytes.reader(buffer.fromstring(c.data))) + if v then + local out = Tres.encode(v) + if out then + print("ours_" .. c.name .. "\t" .. hex(buffer.tostring(out))) + end + end +end diff --git a/tools/fixtures/_godot_make.gd b/tools/fixtures/_godot_make.gd new file mode 100644 index 0000000..536adc2 --- /dev/null +++ b/tools/fixtures/_godot_make.gd @@ -0,0 +1,120 @@ +# tools/fixtures/_godot_make.gd: run by tools/fixtures/godot.py (godot --headless -s): builds test scenes in Godot and +# saves them as .tscn (Godot's own writer) into the project folder: meshes from SurfaceTool (normals, tangents, UVs, +# UV2, colours, two surfaces, indexed and not), materials (sRGB albedo, metallic, roughness, emission, a texture, +# transparency, culling), nested transforms, cameras, lights, primitive meshes, a Node2D subtree, a material override +# and an instanced sub-scene. +extends SceneTree + +func tri_mesh(mat_a, mat_b): + var st = SurfaceTool.new() + st.begin(Mesh.PRIMITIVE_TRIANGLES) + var pts = [Vector3(0, 0, 0), Vector3(1, 0, 0), Vector3(0, 1, 0), Vector3(1, 1, 0.5)] + var uvs = [Vector2(0, 0), Vector2(1, 0), Vector2(0, 1), Vector2(1, 1)] + for i in [0, 1, 2, 2, 1, 3]: + st.set_normal(Vector3(0.1 * i, 0.2, 1).normalized()) + st.set_tangent(Plane(Vector3(1, 0, -0.1 * i).normalized(), -1.0 if i == 3 else 1.0)) + st.set_uv(uvs[i]) + st.set_uv2(uvs[i] * 0.5) + st.set_color(Color(i / 3.0, 1.0 - i / 3.0, 0.25, 1.0)) + st.add_vertex(pts[i]) + st.index() + st.set_material(mat_a) + var mesh = st.commit() + var st2 = SurfaceTool.new() + st2.begin(Mesh.PRIMITIVE_TRIANGLES) + for p in [Vector3(0, 0, 1), Vector3(0, 2, 1), Vector3(2, 0, 1)]: + st2.set_normal(Vector3(0, 0, -1)) + st2.add_vertex(p) + st2.set_material(mat_b) + st2.commit(mesh) + return mesh + +func scene_main(): + var root = Node3D.new() + root.name = "Root" + var tex = load("res://checker.png") + var a = StandardMaterial3D.new() + a.resource_name = "Painted" + a.albedo_color = Color(0.8, 0.4, 0.2, 1.0) + a.metallic = 0.25 + a.roughness = 0.6 + a.albedo_texture = tex + a.emission_enabled = true + a.emission = Color(0.1, 0.2, 0.3) + a.emission_energy_multiplier = 2.0 + var b = StandardMaterial3D.new() + b.resource_name = "Glass" + b.albedo_color = Color(0.2, 0.6, 1.0, 0.5) + b.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA + b.cull_mode = BaseMaterial3D.CULL_DISABLED + var pivot = Node3D.new() + pivot.name = "Pivot" + pivot.transform = Transform3D(Basis.from_euler(Vector3(0.3, -0.7, 0.2)), Vector3(1, 2, 3)) + root.add_child(pivot); pivot.owner = root + var mi = MeshInstance3D.new() + mi.name = "Shape" + mi.mesh = tri_mesh(a, b) + mi.transform = Transform3D(Basis(Vector3(0, 0, 1), 0.4).scaled(Vector3(2, 1, 0.5)), Vector3(-1, 0.5, 4)) + pivot.add_child(mi); mi.owner = root + var over = MeshInstance3D.new() + over.name = "Override" + over.mesh = mi.mesh + var red = StandardMaterial3D.new() + red.albedo_color = Color(1, 0, 0) + over.set_surface_override_material(0, red) + over.position = Vector3(5, 0, 0) + root.add_child(over); over.owner = root + var cam = Camera3D.new(); cam.name = "Cam"; cam.fov = 50; cam.near = 0.1; cam.far = 300 + cam.transform = Transform3D(Basis.looking_at(Vector3(0, -0.5, -1)), Vector3(0, 3, 8)) + root.add_child(cam); cam.owner = root + var ortho = Camera3D.new(); ortho.name = "Ortho"; ortho.projection = Camera3D.PROJECTION_ORTHOGONAL; ortho.size = 6 + root.add_child(ortho); ortho.owner = root + var omni = OmniLight3D.new(); omni.name = "Omni"; omni.light_color = Color(1, 0.5, 0.25); omni.light_energy = 2; omni.omni_range = 7 + omni.position = Vector3(0, 4, 0) + root.add_child(omni); omni.owner = root + var spot = SpotLight3D.new(); spot.name = "Spot"; spot.spot_angle = 30; spot.spot_range = 12; spot.light_energy = 3 + spot.rotation = Vector3(-1.2, 0.3, 0) + root.add_child(spot); spot.owner = root + var sun = DirectionalLight3D.new(); sun.name = "Sun"; sun.light_energy = 0.8 + sun.rotation_degrees = Vector3(-45, 30, 0) + root.add_child(sun); sun.owner = root + var prims = Node3D.new(); prims.name = "Prims"; prims.position = Vector3(0, -3, 0) + root.add_child(prims); prims.owner = root + var shapes = [BoxMesh.new(), PlaneMesh.new(), QuadMesh.new(), SphereMesh.new(), CylinderMesh.new()] + shapes[0].size = Vector3(2, 1, 3) + shapes[1].size = Vector2(4, 2) + shapes[3].radius = 0.75; shapes[3].height = 1.5 + shapes[4].top_radius = 0.25; shapes[4].height = 3 + for i in shapes.size(): + var p = MeshInstance3D.new(); p.name = "Prim%d" % i; p.mesh = shapes[i]; p.position = Vector3(i * 3, 0, 0) + prims.add_child(p); p.owner = root + var ui = Node2D.new(); ui.name = "Hud"; ui.position = Vector2(10, 20); ui.rotation = 0.5 + root.add_child(ui); ui.owner = root + var spr = Sprite2D.new(); spr.name = "Icon"; spr.texture = tex; spr.position = Vector2(3, 4) + ui.add_child(spr); spr.owner = root + var hidden = Node3D.new(); hidden.name = "Hidden"; hidden.visible = false; hidden.scale = Vector3(1, 2, 3) + root.add_child(hidden); hidden.owner = root + var sub = load("res://part.tscn").instantiate() + sub.name = "PartInstance" + sub.position = Vector3(0, 0, -6) + root.add_child(sub); sub.owner = root + return root + +func scene_part(): + var root = Node3D.new(); root.name = "Part" + var m = MeshInstance3D.new(); m.name = "Cube"; var box = BoxMesh.new(); box.size = Vector3(0.5, 0.5, 0.5); m.mesh = box + m.position = Vector3(0, 1, 0) + root.add_child(m); m.owner = root + return root + +func save(root, path): + var ps = PackedScene.new() + ps.pack(root) + var err = ResourceSaver.save(ps, path) + if err != OK: + printerr("save failed ", path, " ", err) + +func _init(): + save(scene_part(), "res://part.tscn") + save(scene_main(), "res://main.tscn") + quit() diff --git a/tools/fixtures/_godot_tres.gd b/tools/fixtures/_godot_tres.gd new file mode 100644 index 0000000..05abaf3 --- /dev/null +++ b/tools/fixtures/_godot_tres.gd @@ -0,0 +1,15 @@ +# tools/fixtures/_godot_tres.gd: run by tools/fixtures/godot.py (godot --headless -s ... -- ...): loads each +# resource with Godot's loader and prints one JSON line: its class and every stored property as var_to_str text. +extends SceneTree + +func _init(): + for path in OS.get_cmdline_user_args(): + var r = load(path) + var res = {"file": path, "ok": r != null, "props": {}} + if r: + res["class"] = r.get_class() + for p in r.get_property_list(): + if p.usage & PROPERTY_USAGE_STORAGE and p.name != "script" and p.name != "resource_path": + res["props"][p.name] = var_to_str(r.get(p.name)) + print("JSON:" + JSON.stringify(res)) + quit() diff --git a/tools/fixtures/docs_engines.py b/tools/fixtures/docs_engines.py index 9ea2794..7aa9653 100644 --- a/tools/fixtures/docs_engines.py +++ b/tools/fixtures/docs_engines.py @@ -1,9 +1,43 @@ # Docs inputs for the engine / level-editor sections of the scene, tile map, archive and data pages (tools/fixtures.py, # tools/docs_check.py): the hand-written ASE of tools/fixtures/ase.py, LDtk's AutoLayers_2_stamps sample (tools/fixtures/ldtk.py), -# HaxeFlixel's TurnBasedRPG Ogmo project and level (tests/fixtures/ogmo). +# HaxeFlixel's TurnBasedRPG Ogmo project and level (tests/fixtures/ogmo), a small Godot scene and resource. # tests/gen/docs_engines.luau { files = { [name] = bytes }, vars = { aseText = "hand.ase", ... } } import importlib.util, os +TSCN = """[gd_scene load_steps=3 format=3] + +[sub_resource type="StandardMaterial3D" id="Mat_1"] +albedo_color = Color(1, 0.5, 0, 1) +metallic = 0.5 + +[sub_resource type="BoxMesh" id="Box_1"] +material = SubResource("Mat_1") +size = Vector3(1, 2, 1) + +[node name="World" type="Node3D"] + +[node name="Box" type="MeshInstance3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0, 0) +mesh = SubResource("Box_1") + +[node name="Camera" type="Camera3D" parent="."] +fov = 60.0 + +[node name="Hud" type="Node2D" parent="."] +position = Vector2(10, 20) +""" + +TRES = """[gd_resource type="StandardMaterial3D" load_steps=2 format=3] + +[ext_resource type="Texture2D" path="res://brick.png" id="1"] + +[resource] +albedo_color = Color(0.8, 0.4, 0.2, 1) +albedo_texture = ExtResource("1") +metallic = 0.25 +roughness = 1.0 +""" + INPUTS = ["tools/docs_check.py", "tools/fixtures/ase.py", "tools/fixtures/ldtk.py", "tests/fixtures/ogmo"] @@ -20,5 +54,7 @@ def generate(ctx): files["stamps.ldtk"] = open(os.path.join(mod(ctx, "ldtk").samples_dir(ctx), "AutoLayers_2_stamps.ldtk"), "rb").read() for f in ("turnBasedRPG.ogmo", "room-001.json"): files[f] = ctx.read("tests/fixtures/ogmo/" + f) - vars = {"aseText": "hand.ase", "ldtkText": "stamps.ldtk", "ogmoProjectText": "turnBasedRPG.ogmo", "ogmoLevelText": "room-001.json"} + files["world.tscn"] = TSCN.encode() + files["brick.tres"] = TRES.encode() + vars = {"tscnText": "world.tscn", "tresText": "brick.tres", "aseText": "hand.ase", "ldtkText": "stamps.ldtk", "ogmoProjectText": "turnBasedRPG.ogmo", "ogmoLevelText": "room-001.json"} check.emit_inputs(ctx, files, vars) diff --git a/tools/fixtures/godot.py b/tools/fixtures/godot.py new file mode 100644 index 0000000..5a3d872 --- /dev/null +++ b/tools/fixtures/godot.py @@ -0,0 +1,224 @@ +# Godot fixtures (tools/fixtures.py), with Godot 4 itself (nixpkgs#godot_4, headless) as the reference: +# tools/fixtures/_godot_make.gd builds scenes in Godot and saves them with Godot's .tscn writer; +# tools/fixtures/_godot_dump.gd loads scenes with Godot's loader and prints every node, mesh surface (the arrays +# Godot decoded), material, camera and light as JSON. A hand-written format-2 .escn (the Blender exporter's layout: +# "arrays" surfaces, SpatialMaterial, Godot 3 node types) and .tres resources are added. Then our writer's .tscn output +# (tools/fixtures/_godot_encode.luau) is loaded and dumped by Godot. Resources are loaded by Godot +# (tools/fixtures/_godot_tres.gd: every stored property as var_to_str text), ours too. +# tests/gen/godot.luau { cases = { { name, data, files = { [rel] = bytes }, dump? } }, tres = { { name, data, godot } } } +# tests/gen/godot_ours.luau { { name, data, dump } }; ours_*.tres entries carry godot (the resource dump) instead +import importlib.util, json, os, shutil, struct, subprocess, tempfile, zlib + +INPUTS = ["src/Rosetta/model/godot", "src/Rosetta/data/tres", "src/Rosetta/codecs/text/GodotVariant.luau", "tools/fixtures/_godot_make.gd", + "tools/fixtures/_godot_dump.gd", "tools/fixtures/_godot_tres.gd", "tools/fixtures/_godot_encode.luau", "tools/fixtures/_model_ref.py"] + +ESCN = """[gd_scene load_steps=4 format=2] + +[sub_resource id=1 type="SpatialMaterial"] + +resource_name = "Material" +albedo_color = Color(0.8, 0.2, 0.1, 1.0) +metallic = 0.5 +roughness = 0.25 +flags_transparent = false +params_cull_mode = 2 + +[sub_resource id=2 type="ArrayMesh"] + +resource_name = "Cube" +surfaces/0 = { +\t"material":SubResource(1), +\t"primitive":4, +\t"arrays":[ +\t\tVector3Array(1.0, 1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0), +\t\tVector3Array(0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0), +\t\tFloatArray(1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0), +\t\tnull, ; no Vertex Colors, +\t\tVector2Array(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0), +\t\tnull, ; No UV2, +\t\tnull, ; No Bones, +\t\tnull, ; No Weights, +\t\tIntArray(0, 2, 1, 0, 3, 2) +\t], +\t"morph_arrays":[] +} + +[sub_resource id=3 type="ArrayMesh"] + +surfaces/0 = { +\t"primitive":5, +\t"arrays":[ +\t\tVector3Array(0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0), +\t\tnull, null, ColorArray(1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1), null, null, null, null, null +\t], +\t"morph_arrays":[] +} + +[node type="Spatial" name="Scene"] + +[node name="Cube" type="MeshInstance" parent="."] + +mesh = SubResource(2) +visible = true +transform = Transform(1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0, 2.0, 3.0, 4.0) + +[node name="Strip" type="MeshInstance" parent="Cube"] + +mesh = SubResource(3) +transform = Transform(2.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 1.0) + +[node name="Camera" type="Camera" parent="."] + +fov = 60.0 +far = 250.0 + +[node name="Lamp" type="OmniLight" parent="."] + +light_color = Color(1, 1, 0.5, 1) +light_energy = 3.0 +omni_range = 9.0 +transform = Transform(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5, 0) +""" + +TRES = [ + ("material.tres", """[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://b1x2y3z4"] + +[ext_resource type="Texture2D" path="res://checker.png" id="1_ab"] + +[resource] +resource_name = "Brick" +albedo_color = Color(0.8, 0.4, 0.2, 1) +albedo_texture = ExtResource("1_ab") +metallic = 0.25 +uv1_scale = Vector3(2, 2, 1) +"""), + ("data.tres", """[gd_resource type="Resource" script_class="Stats" load_steps=3 format=3] + +[ext_resource type="Script" path="res://stats.gd" id="1"] + +[sub_resource type="Curve" id="Curve_1"] +_data = [Vector2(0, 0), 0.0, 1.0, 0, 0, Vector2(1, 1), 1.0, 0.0, 0, 0] +point_count = 2 + +[resource] +script = ExtResource("1") +name = "Goblin \\"Grr\\"\\nline two" +hp = 12 +speed = 3.5 +tags = PackedStringArray("green", "small") +weights = PackedFloat32Array(0.5, 0.25, -1e-05, inf) +spawn = Vector3i(1, -2, 3) +rect = Rect2(0, 0, 32, 16) +curve = SubResource("Curve_1") +drops = { +"gold": 5, +"items": [&"sword", NodePath("../Path"), null, true], +3: Color(1, 0, 0, 1) +} +typed = Array[int]([1, 2, 3]) +basis = Basis(1, 0, 0, 0, 1, 0, 0, 0, 1) +quat = Quaternion(0, 0, 0, 1) +obj = Object(Resource,"resource_local_to_scene":false,"resource_name":"x") +"""), +] + + +def png(w, h): + def chunk(t, d): + return struct.pack(">I", len(d)) + t + d + struct.pack(">I", zlib.crc32(t + d) & 0xffffffff) + raw = b"".join(b"\0" + bytes(((x + y) % 2) * 255 for x in range(w) for _ in range(3)) for y in range(h)) + return b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", w, h, 8, 2, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(raw)) + chunk(b"IEND", b"") + + +def godot(ctx, project, args): + cmd = ["nix", "shell", "nixpkgs#godot_4", "-c", "godot", "--headless", "--path", project] + args + return subprocess.run(cmd, capture_output=True, timeout=600).stdout.decode("utf-8", "replace") + + +def dump(ctx, project, files): + out = godot(ctx, project, ["-s", os.path.join(ctx.root, "tools", "fixtures", "_godot_dump.gd"), "--"] + ["res://" + f for f in files]) + res = {} + for line in out.split("\n"): + if line.startswith("JSON:"): + d = json.loads(line[5:]) + res[d["file"][6:]] = d + return res + + +STATS_GD = """class_name Stats +extends Resource +@export var name: String +@export var hp: int +@export var speed: float +@export var tags: PackedStringArray +@export var weights: PackedFloat32Array +@export var spawn: Vector3i +@export var rect: Rect2 +@export var curve: Curve +@export var drops: Dictionary +@export var typed: Array[int] +@export var basis: Basis +@export var quat: Quaternion +@export var obj: Resource +""" + + +def tres_dump(ctx, project, files): + out = godot(ctx, project, ["-s", os.path.join(ctx.root, "tools", "fixtures", "_godot_tres.gd"), "--"] + ["res://" + f for f in files]) + res = {} + for line in out.split("\n"): + if line.startswith("JSON:"): + d = json.loads(line[5:]) + res[d["file"][6:]] = d + return res + + +def clean(v): + # None cannot sit in a Luau table: drop null fields + if isinstance(v, dict): + return {k: clean(x) for k, x in v.items() if x is not None} + if isinstance(v, list): + return [clean(x) for x in v if x is not None] + return v + + +def generate(ctx): + tmp = tempfile.mkdtemp(prefix="rosetta-godot-") + try: + with open(os.path.join(tmp, "project.godot"), "w") as f: + f.write('config_version=5\n[application]\nconfig/name="rosetta"\n') + checker = png(4, 4) + with open(os.path.join(tmp, "checker.png"), "wb") as f: + f.write(checker) + godot(ctx, tmp, ["--import"]) + godot(ctx, tmp, ["-s", os.path.join(ctx.root, "tools", "fixtures", "_godot_make.gd")]) + made = ["part.tscn", "main.tscn"] + dumps = dump(ctx, tmp, made) + read = lambda f: open(os.path.join(tmp, f), "rb").read() + cases = [] + for f in made: + cases.append({"name": f, "data": read(f), "files": {"part.tscn": read("part.tscn"), "checker.png": checker}, "dump": clean(dumps.get(f, {}))}) + cases.append({"name": "hand.escn", "data": ESCN.encode(), "files": {}}) + with open(os.path.join(tmp, "stats.gd"), "w") as f: + f.write(STATS_GD) + for n, t in TRES: + with open(os.path.join(tmp, n), "w") as f: + f.write(t) + td = tres_dump(ctx, tmp, [n for n, _ in TRES]) + tres = [{"name": n, "data": t.encode(), "godot": td.get(n, {"ok": False})} for n, t in TRES] + ctx.emit("godot", {"cases": cases, "tres": tres}) + spec = importlib.util.spec_from_file_location("_model_ref", os.path.join(ctx.root, "tools", "fixtures", "_model_ref.py")) + M = importlib.util.module_from_spec(spec) + spec.loader.exec_module(M) + ours = M.luau_encode(ctx, "tools/fixtures/_godot_encode.luau") + names = sorted(ours) + for n in names: + with open(os.path.join(tmp, n), "wb") as f: + f.write(ours[n]) + scenes = [n for n in names if n.endswith(".tscn")] + od = dump(ctx, tmp, scenes) + rd = tres_dump(ctx, tmp, [n for n in names if n.endswith(".tres")]) + ctx.emit("godot_ours", [{"name": n, "data": ours[n], "dump": clean(od.get(n, {"ok": False}))} for n in scenes] + + [{"name": n, "data": ours[n], "godot": rd.get(n, {"ok": False})} for n in names if n.endswith(".tres")]) + finally: + shutil.rmtree(tmp) From 8d305bb94242f11ca3678718c9da0dceb0bb425f Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 19:33:35 -0600 Subject: [PATCH 07/10] model/t3d: Unreal T3D (UE1-4) brushes through codecs/model/Brush and actors as nodes --- README.md | 3 +- docs/FORMATS.md | 1 + docs/guide/scene.md | 34 +++ src/Rosetta/Registry.luau | 12 + src/Rosetta/model/t3d/Build.luau | 403 +++++++++++++++++++++++++++++++ src/Rosetta/model/t3d/Parse.luau | 166 +++++++++++++ src/Rosetta/model/t3d/init.luau | 92 +++++++ tests/model/t3d.luau | 165 +++++++++++++ tools/fixtures/docs_engines.py | 8 +- tools/fixtures/t3d.py | 204 ++++++++++++++++ 10 files changed, 1084 insertions(+), 4 deletions(-) create mode 100644 src/Rosetta/model/t3d/Build.luau create mode 100644 src/Rosetta/model/t3d/Parse.luau create mode 100644 src/Rosetta/model/t3d/init.luau create mode 100644 tests/model/t3d.luau create mode 100644 tools/fixtures/t3d.py diff --git a/README.md b/README.md index 4da9347..24e2520 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ print(F.detect(webp), #F.formats()) -- "webp", the format list ## Formats -186 formats. Generated from the format contracts by `tools/gen_registry.py`; [docs/FORMATS.md](docs/FORMATS.md) +187 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 | @@ -138,6 +138,7 @@ adds each format's capabilities. | 3D models | schematic | .schem .schematic .litematic | yes | yes | | 3D models | smd | .smd | yes | yes | | 3D models | stl | .stl | yes | yes | +| 3D models | t3d | .t3d | yes | - | | 3D models | usda | .usda .usd .usdz | yes | yes | | 3D models | vox | .vox | yes | yes | | 3D models | vrml | .wrl .wrz .vrml | yes | yes | diff --git a/docs/FORMATS.md b/docs/FORMATS.md index 43386b5..7b2838b 100644 --- a/docs/FORMATS.md +++ b/docs/FORMATS.md @@ -94,6 +94,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build | model | schematic | .schem .schematic .litematic | yes | yes | voxels: true, blocks: true, variants: "schem", "schematic", "litematic" | `tests/model/schematic.luau` | | model | smd | .smd | yes | yes | skins: true, animation: true | `tests/model/smd.luau` | | model | stl | .stl | yes | yes | ascii: true, binary: true, colors: true, indexed: false | `tests/model/stl.luau` | +| model | t3d | .t3d | yes | - | text: true, brushes: true, actors: true | `tests/model/t3d.luau` | | model | usda | .usda .usd .usdz | yes | yes | materials: true, animation: true, cameras: true, lights: true, polygons: true, vertexColors: true, usdz: "read", usdc: false | `tests/model/usda.luau` | | model | vox | .vox | yes | yes | voxels: true, sceneGraph: true, materials: true | `tests/model/vox.luau` | | model | vrml | .wrl .wrz .vrml | yes | yes | materials: true, polygons: true, animation: true, cameras: true, lights: true, lines: true, points: true | `tests/model/vrml.luau` | diff --git a/docs/guide/scene.md b/docs/guide/scene.md index 2097fbb..4829b88 100644 --- a/docs/guide/scene.md +++ b/docs/guide/scene.md @@ -831,6 +831,39 @@ surfaces with positions, normals, tangents, colours, two UV sets) and StandardMa `ext_resource` per texture with a `uri`. Skins, animations and morph targets are not written. Godot resources (`.tres`) are data: see [data.md](data.md). +## Unreal T3D + +UnrealEd's text export (`.t3d`: `Begin Map` / `Begin Actor` / `Begin Brush` / `Begin PolyList` / `Begin Polygon`, +UE1 to UE4) loads as a Scene in Unreal's own Z-up, left-handed coordinates (`meta.handedness = "left"`; nothing is +mirrored). Every actor is a root node with its class, properties, CSG operation and components in +`node.extras.t3d`; its matrix is the brush transform (PrePivot, MainScale, Rotation, PostScale, Location; rotations +in 65536ths of a turn, or degrees in UE4 text) or the actor's Location / Rotation / DrawScale (UE4: the root +component's `Relative*`). Brush polygons become one primitive per texture through `codecs/model/Brush`, with UVs from +`TextureU` / `TextureV` / `Origin` / `Pan` divided by the texture size (`opts.textureSize`: a function or a +`{ [name] = { w, h } }` table, default 256). Triangles wind counter-clockwise about each polygon's stored normal; +subtractive brushes are turned inside out (a room is seen from within), the red builder brush is skipped unless +`builder = true`. No BSP CSG is done: overlapping brushes stay separate meshes. Lights (UE1 hue / saturation / +brightness, UE3-4 light components) and cameras map across; static mesh actors keep their mesh path in +`extras.t3d.staticMesh`. + +```luau +local level = assert(F.load(t3dText, { textureSize = { Bricks = { 128, 64 }, Floor = { 256, 256 } } })) +assert(level.meta.source.format == "t3d" and level.meta.up == "z") +local room +for _, n in level.nodes do + if n.name == "Brush0" then + room = n + end +end +assert(room.extras.t3d.csg == "CSG_Subtract" and room.mesh) +assert(room.matrix[13] == 64) -- Location X +local names = {} +for _, p in level.meshes[room.mesh].primitives do + names[level.materials[p.material].name] = true +end +assert(names.Bricks and names.Floor) +``` + ## Formats | Format | Read | Write | Notes | @@ -862,6 +895,7 @@ surfaces with positions, normals, tangents, colours, two UV sets) and StandardMa | MD2, MD3, MDL, MD5, BSP | yes | - | game models and maps: see "Game models" above; BSP lightmaps, hulls, PVS: "Quake maps" | | Quake / Half-Life / Quake II / Quake III `.map` | yes | yes | entities as nodes, brushes CSG'd, patches: see "Quake maps" | | SMD | yes | yes | Valve studiomdl data | +| Unreal T3D (`.t3d`) | yes | - | brushes as polygons per texture (no CSG), actors with properties, lights, cameras; Z up, left-handed | | Godot `.tscn` / `.escn` | yes | yes (`.tscn`) | Node3D trees, ArrayMesh and primitive meshes, StandardMaterial3D, cameras, lights, instances; 2D nodes in extras | | ASE (3ds Max ASCII) | yes | yes | Multi/Sub-Object materials, texture channels, vertex colours, normals, helpers, cameras, lights; no animation; Z up | | Roblox `.mesh` (robloxmesh) | yes | yes | see [roblox.md](roblox.md) | diff --git a/src/Rosetta/Registry.luau b/src/Rosetta/Registry.luau index 079e0ca..75a018b 100644 --- a/src/Rosetta/Registry.luau +++ b/src/Rosetta/Registry.luau @@ -1082,6 +1082,18 @@ local list: { Entry } = { return require("@rosetta/model/stl") end, }, + { + name = "t3d", + category = "model", + path = "model/t3d", + extensions = { "t3d" }, + mime = { "text/x-unreal-t3d" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Text", "codecs/model/Brush" }, + caps = { decode = true, encode = false, text = true, brushes = true, actors = true }, + load = function() + return require("@rosetta/model/t3d") + end, + }, { name = "usda", category = "model", diff --git a/src/Rosetta/model/t3d/Build.luau b/src/Rosetta/model/t3d/Build.luau new file mode 100644 index 0000000..28769ca --- /dev/null +++ b/src/Rosetta/model/t3d/Build.luau @@ -0,0 +1,403 @@ +--!strict +-- model/t3d/Build: parsed T3D blocks into a Scene: one node per actor (Unreal's own Z-up, left-handed coordinates, +-- kept as they are), brush polygons as primitives per texture (codecs/model/Brush). Brush transform as UnrealEd's +-- ABrush coords: v - PrePivot, MainScale, Rotation, PostScale, + Location. Rotation as FRotationMatrix (Pitch / Yaw / +-- Roll: 65536 units per turn, or degrees in UE4 text). Polygon winding follows the stored Normal; subtractive +-- brushes face inwards. +local Types = require("@rosetta/Types") +local Brush = require("@rosetta/codecs/model/Brush") +local Parse = require("@rosetta/model/t3d/Parse") + +type Block = Parse.Block + +local Build = {} + +local S = Types.Scene + +local function num(v: any, d: number): number + return if type(v) == "number" and v == v then v else d +end + +local function vec3(s: string?): { number }? + if type(s) ~= "string" then + return nil + end + local a, b, c = string.match(s, "^%s*([^,%s]+)%s*,%s*([^,%s]+)%s*,%s*([^,%s]+)") + if not a then + return nil + end + local x, y, z = tonumber((string.gsub(a, "^%+", ""))), tonumber((string.gsub(b :: string, "^%+", ""))), tonumber((string.gsub(c :: string, "^%+", ""))) + if x and y and z then + return { x, y, z } + end + return nil +end + +local function xyz(v: any, d: { number }): { number } + if type(v) == "table" then + return { num(v.X, d[1]), num(v.Y, d[2]), num(v.Z, d[3]) } + end + return d +end + +-- FRotationMatrix rows are the X / Y / Z axes: the columns of a column-major matrix +local function rotation(r: any, degrees: boolean): { number } + if type(r) ~= "table" then + return S.IDENTITY + end + local k = if degrees then math.pi / 180 else math.pi * 2 / 65536 + local p, y, ro = num(r.Pitch, 0) * k, num(r.Yaw, 0) * k, num(r.Roll, 0) * k + local SP, CP, SY, CY, SR, CR = math.sin(p), math.cos(p), math.sin(y), math.cos(y), math.sin(ro), math.cos(ro) + return { + CP * CY, CP * SY, SP, 0, + SR * SP * CY - CR * SY, SR * SP * SY + CR * CY, -SR * CP, 0, + -(CR * SP * CY + SR * SY), CY * SR - CR * SP * SY, CR * CP, 0, + 0, 0, 0, 1, + } +end + +local function scaling(s: { number }): { number } + return { s[1], 0, 0, 0, 0, s[2], 0, 0, 0, 0, s[3], 0, 0, 0, 0, 1 } +end + +local function translation(t: { number }): { number } + return { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, t[1], t[2], t[3], 1 } +end + +local function plain(b: Block): { [string]: any } + local out: { [string]: any } = {} + for _, k in b.order do + out[k] = b.props[k] + end + return out +end + +-- the component holding the actor's transform (UE4: RootComponent's Relative* properties) +local function component(actor: Block, objects: { [string]: { [string]: any } }): { [string]: any }? + local root = actor.props.RootComponent + if type(root) == "string" then + local name = string.match(root, "'\"?([^'\"]+)\"?'") or root + name = string.match(name, "([^%.:]+)$") or name + if objects[name] then + return objects[name] + end + end + for _, o in objects do + if o.RelativeLocation ~= nil or o.RelativeRotation ~= nil or o.RelativeScale3D ~= nil then + return o + end + end + return nil +end + +local function polygons(b: Block, out: { Block }) + for _, c in b.children do + local k = string.lower(c.kind) + if k == "polygon" then + table.insert(out, c) + elseif k == "polylist" or k == "brush" then + polygons(c, out) + end + end +end + +type Ctx = { scene: Types.Scene, materials: { [string]: number }, opts: any, polys: number } + +local function material(ctx: Ctx, name: string): number + local m = ctx.materials[name] + if m then + return m + end + local mat = S.material(if name ~= "" then name else nil) + mat.metallic = 0 + if name ~= "" then + table.insert(ctx.scene.textures, { name = name }) + mat.baseColorTexture = { texture = #ctx.scene.textures } + end + mat.extras = { t3d = { texture = name } } + table.insert(ctx.scene.materials, mat) + ctx.materials[name] = #ctx.scene.materials + return #ctx.scene.materials +end + +-- the brush's polygons as Scene primitives (local brush space) +local function brushMesh(ctx: Ctx, brush: Block, subtract: boolean): (Types.Mesh?, string?) + local list: { Block } = {} + polygons(brush, list) + if #list == 0 then + return nil, nil + end + local faces: { Brush.Face } = {} + local polys: { Brush.Polygon } = {} + local flags: { number } = {} + for _, pb in list do + local rec: { [string]: string } = {} + local verts: { number } = {} + for _, r in pb.records do + local name = string.lower(r[1]) + if name == "vertex" then + local v = vec3(r[2]) + if v then + table.insert(verts, v[1]) + table.insert(verts, v[2]) + table.insert(verts, v[3]) + end + elseif rec[name] == nil then + rec[name] = r[2] + end + end + local nv = #verts // 3 + if nv >= 3 then + ctx.polys += 1 + if ctx.polys > (ctx.opts.maxPolygons or 2 ^ 20) then + return nil, "limit: over " .. (ctx.opts.maxPolygons or 2 ^ 20) .. " polygons" + end + -- Newell normal of the vertex order + local nx, ny, nz = 0, 0, 0 + for k = 0, nv - 1 do + local j = (k + 1) % nv + local ax, ay, az = verts[k * 3 + 1], verts[k * 3 + 2], verts[k * 3 + 3] + local bx, by, bz = verts[j * 3 + 1], verts[j * 3 + 2], verts[j * 3 + 3] + nx += (ay - by) * (az + bz) + ny += (az - bz) * (ax + bx) + nz += (ax - bx) * (ay + by) + end + local stated = vec3(rec.normal) + local n = stated or { nx, ny, nz } + local l = math.sqrt(n[1] * n[1] + n[2] * n[2] + n[3] * n[3]) + if l > 0 then + n = { n[1] / l, n[2] / l, n[3] / l } + end + local reverse = nx * n[1] + ny * n[2] + nz * n[3] < 0 + if subtract then + reverse = not reverse + n = { -n[1], -n[2], -n[3] } + end + if reverse then + local r: { number } = {} + for k = nv - 1, 0, -1 do + table.insert(r, verts[k * 3 + 1]) + table.insert(r, verts[k * 3 + 2]) + table.insert(r, verts[k * 3 + 3]) + end + verts = r + end + local tex = if type(pb.attrs.Texture) == "string" then pb.attrs.Texture else (if pb.attrs.Texture ~= nil then tostring(pb.attrs.Texture) else "") + local o = vec3(rec.origin) or { 0, 0, 0 } + local u = vec3(rec.textureu) or { 1, 0, 0 } + local v = vec3(rec.texturev) or { 0, 1, 0 } + local panU, panV = 0, 0 + if rec.pan then + panU = tonumber(string.match(rec.pan, "U=%s*([-+]?[%d%.]+)")) or 0 + panV = tonumber(string.match(rec.pan, "V=%s*([-+]?[%d%.]+)")) or 0 + end + -- texel = (p - Origin) . TextureU + PanU + local face: Brush.Face = { + plane = { n[1], n[2], n[3], n[1] * o[1] + n[2] * o[2] + n[3] * o[3] }, + texture = tex, + vecs = { + { u[1], u[2], u[3], panU - (o[1] * u[1] + o[2] * u[2] + o[3] * u[3]) }, + { v[1], v[2], v[3], panV - (o[1] * v[1] + o[2] * v[2] + o[3] * v[3]) }, + }, + } + table.insert(faces, face) + table.insert(polys, { brush = 1, face = #faces, points = verts, normal = n }) + table.insert(flags, num(pb.attrs.Flags, 0)) + end + end + local size = ctx.opts.textureSize + local built = Brush.primitives(polys, { faces }, function(name: string): (number, number) + if type(size) == "function" then + local ok, w, h = pcall(size, name) + if ok and type(w) == "number" then + return w, if type(h) == "number" then h else w + end + elseif type(size) == "table" and type(size[name]) == "table" then + return num(size[name][1], 256), num(size[name][2], 256) + end + return 256, 256 + end) + local mesh: Types.Mesh = { name = if type(brush.attrs.Name) == "string" then brush.attrs.Name else nil, primitives = {} } + for _, b in built do + b.primitive.material = material(ctx, b.texture) + table.insert(mesh.primitives, b.primitive) + end + mesh.extras = { t3d = { polygons = #polys } } + return mesh, nil +end + +local LIGHTS: { [string]: "point" | "spot" | "directional" } = { + Light = "point", PointLight = "point", SpotLight = "spot", DirectionalLight = "directional", TriggerLight = "point", + SkyLight = "directional", Spotlight = "spot", SunLight = "directional", DominantDirectionalLight = "directional", + PointLightMovable = "point", SpotLightMovable = "spot", DirectionalLightMovable = "directional", +} + +-- HSV of UE1 lights: LightHue / LightSaturation (255 = white) / LightBrightness, all 0..255 +local function hsv(h: number, s: number): { number } + local hh = (h % 256) / 256 * 6 + local i = math.floor(hh) + local f = hh - i + local p, q, t = 1 - s, 1 - s * f, 1 - s * (1 - f) + local rgb = ({ { 1, t, p }, { q, 1, p }, { p, 1, t }, { p, q, 1 }, { t, p, 1 }, { 1, p, q } })[i % 6 + 1] + return rgb +end + +local function light(ctx: Ctx, class: string, p: { [string]: any }, comp: { [string]: any }?): number + local typ = LIGHTS[class] + local l: Types.Light = { type = typ, color = { 1, 1, 1 }, intensity = 1 } + if p.LightBrightness ~= nil or p.LightHue ~= nil or p.LightSaturation ~= nil then + l.color = hsv(num(p.LightHue, 0), 1 - num(p.LightSaturation, 255) / 255) + l.intensity = num(p.LightBrightness, 64) / 255 + end + local c: any = comp or {} + local col = c.LightColor or p.LightColor + if type(col) == "table" then + l.color = { num(col.R, 255) / 255, num(col.G, 255) / 255, num(col.B, 255) / 255 } + end + if c.Intensity ~= nil or c.Brightness ~= nil then + l.intensity = num(c.Intensity, num(c.Brightness, 1)) + end + local radius = c.AttenuationRadius or c.Radius + if type(radius) == "number" then + l.range = radius + end + if typ == "spot" then + l.outerCone = math.rad(num(c.OuterConeAngle, num(p.LightCone, 44))) + l.innerCone = math.rad(num(c.InnerConeAngle, 0)) + end + table.insert(ctx.scene.lights, l) + return #ctx.scene.lights +end + +local function actors(b: Block, out: { Block }) + for _, c in b.children do + local k = string.lower(c.kind) + if k == "actor" then + table.insert(out, c) + elseif k == "map" or k == "level" or k == "surface" then + actors(c, out) + end + end +end + +function Build.scene(root: Block, opts: any): (Types.Scene?, string?) + local sc = S.new() + sc.meta.up = "z" + sc.meta.handedness = "left" + local list: { Block } = {} + actors(root, list) + local ctx: Ctx = { scene = sc, materials = {}, opts = opts or {}, polys = 0 } + local ue4 = false + for _, a in list do + local rawClass = if a.attrs.Class ~= nil then tostring(a.attrs.Class) else "Actor" + local class = string.match(rawClass, "([%w_]+)$") or rawClass + if string.find(rawClass, "/Script/", 1, true) then + ue4 = true + end + local p = a.props + local objects: { [string]: { [string]: any } } = {} + local objectClass: { [string]: string } = {} + for _, c in a.children do + if string.lower(c.kind) == "object" then + local name = if c.attrs.Name ~= nil then tostring(c.attrs.Name) else ("Object" .. #a.children) + local o = objects[name] or {} + for _, k in c.order do + o[k] = c.props[k] + end + objects[name] = o + if c.attrs.Class ~= nil then + objectClass[name] = tostring(c.attrs.Class) + end + end + end + local comp = component(a, objects) + local node: Types.Node = { name = if a.attrs.Name ~= nil then tostring(a.attrs.Name) else class, children = {} } + local m: { number } + if comp and p.Location == nil then + local deg = true + local loc = xyz(comp.RelativeLocation, { 0, 0, 0 }) + local sc3 = xyz(comp.RelativeScale3D, { 1, 1, 1 }) + m = S.mul(translation(loc), S.mul(rotation(comp.RelativeRotation, deg), scaling(sc3))) + else + local loc = xyz(p.Location, { 0, 0, 0 }) + local deg = a.degrees.Rotation == true + local rot = rotation(p.Rotation, deg) + local isBrush = false + for _, c in a.children do + if string.lower(c.kind) == "brush" then + isBrush = true + end + end + if isBrush then + local pre = xyz(p.PrePivot, { 0, 0, 0 }) + local main = xyz(type(p.MainScale) == "table" and p.MainScale.Scale, { 1, 1, 1 }) + local post = xyz(type(p.PostScale) == "table" and p.PostScale.Scale, { 1, 1, 1 }) + m = S.mul(translation(loc), S.mul(scaling(post), S.mul(rot, S.mul(scaling(main), translation({ -pre[1], -pre[2], -pre[3] }))))) + else + local ds = num(p.DrawScale, 1) + local s3 = xyz(p.DrawScale3D, { 1, 1, 1 }) + m = S.mul(translation(loc), S.mul(rot, scaling({ s3[1] * ds, s3[2] * ds, s3[3] * ds }))) + end + end + node.matrix = m + local csg = if type(p.CsgOper) == "string" then p.CsgOper + elseif p.BrushType == "Brush_Subtract" then "CSG_Subtract" + elseif p.BrushType == "Brush_Add" then "CSG_Add" + else nil + local extras: { [string]: any } = { class = rawClass, properties = plain(a), csg = csg } + if next(objects) then + extras.objects = objects + extras.objectClasses = objectClass + end + for _, c in a.children do + if string.lower(c.kind) == "brush" then + local builder = csg == "CSG_Active" or (class == "Brush" and csg == nil and node.name == "Brush") + extras.builder = if builder then true else nil + if not builder or ctx.opts.builder then + local mesh, err = brushMesh(ctx, c, csg == "CSG_Subtract") + if err then + return nil, err + end + if mesh then + table.insert(sc.meshes, mesh) + node.mesh = #sc.meshes + end + end + end + end + if LIGHTS[class] then + local lc: { [string]: any }? = nil + for name, o in objects do + if string.find(objectClass[name] or name, "Light", 1, true) then + lc = o + end + end + node.light = light(ctx, class, p, lc) + elseif class == "CameraActor" or class == "Camera" then + local fov = num(p.FOVAngle, 90) + for _, o in objects do + if o.FieldOfView ~= nil then + fov = num(o.FieldOfView, fov) + end + end + table.insert(sc.cameras, { type = "perspective", yfov = math.rad(fov), znear = 1 } :: any) + node.camera = #sc.cameras + end + local sm = p.StaticMesh + for _, o in objects do + if o.StaticMesh ~= nil then + sm = o.StaticMesh + end + end + if type(sm) == "string" then + extras.staticMesh = string.match(sm, "'\"?([^'\"]+)\"?'") or sm + end + node.extras = { t3d = extras } + table.insert(sc.nodes, node) + table.insert(sc.roots, #sc.nodes) + end + sc.meta.source = { format = "t3d", engine = if ue4 then "ue4" else "ue1-3", actors = #list, polygons = ctx.polys } + return sc, nil +end + +return Build diff --git a/src/Rosetta/model/t3d/Parse.luau b/src/Rosetta/model/t3d/Parse.luau new file mode 100644 index 0000000..4b8e815 --- /dev/null +++ b/src/Rosetta/model/t3d/Parse.luau @@ -0,0 +1,166 @@ +--!strict +-- model/t3d/Parse: Unreal T3D text into nested blocks. A line `Begin Key=Value ...` opens a block, `End ` +-- closes it; other lines are `Key=Value` properties or, inside polygons, `Origin x,y,z` / `Vertex x,y,z` style +-- records. Values: numbers, quoted strings, structs `(X=1,Y=2)` as tables, object references +-- (`Model'MyLevel.Model1'`) as strings. +local Parse = {} + +export type Value = any +export type Block = { + kind: string, + attrs: { [string]: Value }, + props: { [string]: Value }, + order: { string }, + records: { { string } }, + children: { Block }, + degrees: { [string]: boolean }, +} + +-- "(X=1.0,Y=2,Z=-3)" / "(Scale=(X=1,Y=1,Z=1),SheerAxis=SHEER_ZX)"; i at '(' +local function struct(s: string, i: number, depth: number): (any, number) + local out: { [any]: any } = {} + local n = #s + i += 1 + while i <= n do + local c = string.sub(s, i, i) + if c == ")" then + return out, i + 1 + elseif c == "," or c == " " or c == "\t" then + i += 1 + else + local k, e = string.match(s, "^([^=,()]+)=()", i) + if not k then + -- an array element without a key: (1,2,3) + local v, ni = Parse.value(s, i, depth + 1) + table.insert(out, v) + i = ni + else + local key = string.gsub(k :: string, "^%s+", "") + local v, ni = Parse.value(s, e :: number, depth + 1) + out[key] = v + i = ni + end + end + end + return out, i +end + +-- a value starting at i, up to the next unbracketed ',' / ')' (inside structs) or the end +function Parse.value(s: string, i: number, depth: number): (any, number) + local n = #s + local c = string.sub(s, i, i) + if c == "(" and depth < 32 then + return struct(s, i, depth) + elseif c == "\"" then + local e = string.find(s, "\"", i + 1, true) or (n + 1) + return string.sub(s, i + 1, e - 1), e + 1 + end + -- a bare token; object references may hold quotes ('...' and "...") + local j = i + local q: string? = nil + while j <= n do + local ch = string.sub(s, j, j) + if q then + if ch == q then + q = nil + end + elseif ch == "'" or ch == "\"" then + q = ch + elseif depth > 0 and (ch == "," or ch == ")") then + break + end + j += 1 + end + local tok = string.match(string.sub(s, i, j - 1), "^%s*(.-)%s*$") :: string + local num = tonumber(tok) + if num ~= nil and string.match(tok, "^[-+]?[%d%.]+[eE]?[-+]?%d*$") then + return num, j + end + return tok, j +end + +-- Key=Value pairs of a Begin line ("Begin Actor Class=Light Name=Light0"); quoted values may hold spaces +local function attrs(rest: string): { [string]: any } + local out: { [string]: any } = {} + local i, n = 1, #rest + while i <= n do + local k, e = string.match(rest, "^%s*([%w_%.]+)=()", i) + if not k then + break + end + local v: string + if string.sub(rest, e :: number, e :: number) == "\"" then + local q = string.find(rest, "\"", (e :: number) + 1, true) or (n + 1) + v = string.sub(rest, (e :: number) + 1, q - 1) + i = q + 1 + else + local stop = string.find(rest, "%s", e :: number) or (n + 1) + v = string.sub(rest, e :: number, stop - 1) + i = stop + end + out[k :: string] = tonumber(v) or v + end + return out +end + +local function block(kind: string, a: { [string]: any }): Block + return { kind = kind, attrs = a, props = {}, order = {}, records = {}, children = {}, degrees = {} } +end + +function Parse.tree(text: string, maxBlocks: number): (Block?, string?) + local root = block("", {}) + local stack: { Block } = { root } + local count = 0 + local lineNo = 0 + for raw in string.gmatch(text, "[^\n]*") do + lineNo += 1 + local line = string.match(raw, "^%s*(.-)%s*$") :: string + if line ~= "" and string.sub(line, 1, 2) ~= "//" then + local cur = stack[#stack] + local word, rest = string.match(line, "^(%a+)%s*(.*)$") + local lw = if word then string.lower(word) else "" + if lw == "begin" then + local kind, after = string.match(rest :: string, "^(%S+)%s*(.*)$") + if not kind then + return nil, "Begin without a kind at line " .. lineNo + end + count += 1 + if count > maxBlocks then + return nil, "limit: over " .. maxBlocks .. " blocks" + end + if #stack > 64 then + return nil, "limit: blocks nested too deep" + end + local b = block(kind :: string, attrs(after :: string)) + table.insert(cur.children, b) + table.insert(stack, b) + elseif lw == "end" and #stack > 1 and (rest == "" or string.lower(string.match(rest :: string, "^(%S+)") or "") == string.lower(cur.kind)) then + table.remove(stack) + else + local k, e = string.match(line, "^([%w_%(%)%[%]%.]+)%s*=()") + if k then + local v = Parse.value(line, e :: number, 0) + if cur.props[k :: string] == nil then + table.insert(cur.order, k :: string) + end + cur.props[k :: string] = v + if string.find(string.sub(line, e :: number), "Pitch=[-+]?%d*%.") or string.find(string.sub(line, e :: number), "Yaw=[-+]?%d*%.") then + cur.degrees[k :: string] = true + end + else + -- a record: Origin / Normal / TextureU / TextureV / Vertex / Pan U=0 V=0 + local name, data = string.match(line, "^(%a+)%s+(.*)$") + if name then + table.insert(cur.records, { name :: string, data :: string }) + end + end + end + end + end + if #stack > 1 then + return nil, "truncated: " .. stack[#stack].kind .. " block not closed" + end + return root, nil +end + +return Parse diff --git a/src/Rosetta/model/t3d/init.luau b/src/Rosetta/model/t3d/init.luau new file mode 100644 index 0000000..5d43f06 --- /dev/null +++ b/src/Rosetta/model/t3d/init.luau @@ -0,0 +1,92 @@ +--!strict +-- model/t3d: Unreal T3D text (UnrealEd map / brush export: Begin Map / Level / Actor / Brush / PolyList / Polygon, +-- Begin Object components), read only. Supports: brush polygons with texture projection (TextureU / TextureV / +-- Origin / Pan; sizes through opts.textureSize, default 256) as primitives per texture, CSG operation in extras +-- (subtractive brushes face inwards; the builder brush is skipped), actors as nodes with their properties and +-- transforms (UE1-3 Location / Rotation / DrawScale, UE4 RootComponent Relative*), lights, cameras, static mesh +-- references. Not supported: BSP CSG between brushes, sheared brush scales, terrain, static mesh geometry. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = require("@rosetta/core/Err") +local Bytes = require("@rosetta/core/Bytes") +local Sniff = require("@rosetta/core/Sniff") +local Types = require("@rosetta/Types") +local Text = require("@rosetta/codecs/text/Text") +local Parse = require("@rosetta/model/t3d/Parse") +local Build = require("@rosetta/model/t3d/Build") + +-- ------------------------------------------------------------------------------------------------ contract +local T3d = { + name = "t3d", + category = "model", + extensions = { "t3d" }, + mime = { "text/x-unreal-t3d" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Text", "codecs/model/Brush" }, + caps = { decode = true, encode = false, text = true, brushes = true, actors = true }, +} + +-- ------------------------------------------------------------------------------------------------ types +export type DecodeOptions = { + maxBytes: number?, -- default 2^28 + maxBlocks: number?, -- default 2^22 + maxPolygons: number?, -- default 2^20 + textureSize: ((name: string) -> (number, number))? | { [string]: { number } }?, -- texture width, height (default 256) + builder: boolean?, -- include the builder brush's geometry (default false) +} + +-- ------------------------------------------------------------------------------------------------ sniff +function T3d.sniff(r: Bytes.Reader): number + local h = Sniff.text(r, 512) + local first = string.match(h, "^%s*(Begin%s+%a+)") + if first == nil then + return 0 + end + local kind = string.lower(string.match(first, "%a+$") or "") + if kind == "map" or kind == "actor" or kind == "level" or kind == "brush" or kind == "polylist" then + return 0.9 + end + return 0.3 +end + +-- ------------------------------------------------------------------------------------------------ decode +function T3d.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?) + local o: any = opts or {} + if r.limit - r.base > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local text = buffer.readstring(r.buf, r.base, r.limit - r.base) + if string.sub(text, 1, 2) == "\255\254" then + text = Text.utf16(r.buf, r.base + 2, r.limit - r.base - 2, false) + else + text = Text.toUtf8(text) + end + local ok, root, msg = pcall(Parse.tree, text, o.maxBlocks or 2 ^ 22) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad data: " .. tostring(root)) + end + if not root then + return nil, Err.from(msg) + end + if #root.children == 0 then + return nil, Err.new(Err.CORRUPT, "no Begin blocks") + end + -- a bare brush export (Begin PolyList / Begin Brush): wrap it in an actor + local k = string.lower(root.children[1].kind) + if k == "polylist" or k == "brush" then + local function block(kind: string, attrs: any, props: any, children: any): Parse.Block + return { kind = kind, attrs = attrs, props = props, order = { "CsgOper" }, records = {}, degrees = {}, children = children } + end + local brush = if k == "brush" then root.children else { block("Brush", { Name = "Brush0" }, {}, root.children) } + root = block("", {}, {}, { block("Actor", { Class = "Brush", Name = "Brush0" }, { CsgOper = "CSG_Add" }, brush) }) + end + local ok2, scene, msg2 = pcall(Build.scene, root, o) + if not ok2 then + return nil, Err.from(tostring(scene)) + end + if not scene then + return nil, Err.from(msg2) + end + return scene, nil +end + +return T3d diff --git a/tests/model/t3d.luau b/tests/model/t3d.luau new file mode 100644 index 0000000..1e5df2d --- /dev/null +++ b/tests/model/t3d.luau @@ -0,0 +1,165 @@ +-- model/t3d tests: UE1-3 and UE4 T3D maps against reference values computed by tools/fixtures/t3d.py (brush world +-- vertices through PrePivot / MainScale / FRotationMatrix / PostScale / Location, polygon areas per texture, bounds, +-- texel probes), actors, lights, components, static mesh references; errors; fuzz. +local T = require("@tests/T") +local F = require("@rosetta") +local T3d = require("@rosetta/model/t3d") +local MeshOps = require("@rosetta/ops/MeshOps") +local Bytes = require("@rosetta/core/Bytes") +local Err = require("@rosetta/core/Err") +local Types = require("@rosetta/Types") +local Fx = require("@tests/gen/t3d") + +local t = T.suite("t3d") +local S = Types.Scene + +local function decode(s: string | buffer, opts: any?): (any, any) + local b = if type(s) == "string" then buffer.fromstring(s) else s + return T3d.decode(Bytes.reader(b), opts) +end + +t:eq(T3d.name, "t3d", "name") +t:eq(T3d.category, "model", "category") +t:check(T3d.caps.decode and not T3d.caps.encode, "caps") + +local function near(a: number, b: number, eps: number): boolean + return math.abs(a - b) <= eps * math.max(1, math.abs(b)) +end + +local function triArea(prim: any, m: { number }): number + local P = S.reader(prim.attributes.POSITION) :: any + local I = S.reader(prim.indices) :: any + local a = 0 + local function w(i: number): (number, number, number) + local x, y, z = P(i, 0), P(i, 1), P(i, 2) + return m[1] * x + m[5] * y + m[9] * z + m[13], m[2] * x + m[6] * y + m[10] * z + m[14], m[3] * x + m[7] * y + m[11] * z + m[15] + end + for k = 0, prim.indices.count // 3 - 1 do + local ax, ay, az = w(I(k * 3, 0)) + local bx, by, bz = w(I(k * 3 + 1, 0)) + local cx, cy, cz = w(I(k * 3 + 2, 0)) + local ux, uy, uz, vx, vy, vz = bx - ax, by - ay, bz - az, cx - ax, cy - ay, cz - az + local nx, ny, nz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx + a += math.sqrt(nx * nx + ny * ny + nz * nz) / 2 + end + return a +end + +local samples = {} +for _, c in Fx.cases do + local scene, err = decode(c.data, { textureSize = c.sizes }) + t:check(scene, c.name .. ": decode: " .. tostring(err)) + t:eq(T3d.sniff(Bytes.reader(buffer.fromstring(c.data))), 0.9, c.name .. ": sniff") + table.insert(samples, c.data) + if scene then + t:eq(scene.meta.up, "z", c.name .. ": up") + local byName = {} + for _, n in scene.nodes do + byName[n.name] = n + end + for _, a in c.actors do + local n = byName[a.name] + t:check(n, c.name .. ": actor " .. a.name) + if n then + t:eq(n.extras.t3d.class, a.class, c.name .. ": " .. a.name .. " class") + local m = S.nodeMatrix(n) + if a.origin then + t:check(near(m[13], a.origin[1], 1e-9) and near(m[14], a.origin[2], 1e-9) and near(m[15], a.origin[3], 1e-9), c.name .. ": " .. a.name .. " location") + end + if a.staticMesh then + t:eq(n.extras.t3d.staticMesh, a.staticMesh, c.name .. ": static mesh reference") + end + t:eq(n.mesh ~= nil, a.mesh == true, c.name .. ": " .. a.name .. " has geometry") + if a.mesh and n.mesh then + local mesh = scene.meshes[n.mesh] + local areas, tris = {}, 0 + for _, p in mesh.primitives do + local name = scene.materials[p.material].name or "" + areas[name] = (areas[name] or 0) + triArea(p, m) + tris += p.indices.count // 3 + end + t:eq(tris, a.triangles, c.name .. ": " .. a.name .. " triangles") + for tex, want in a.area do + t:check(areas[tex] and near(areas[tex], want, 1e-6), c.name .. ": " .. a.name .. " area of " .. tex .. ": " .. tostring(areas[tex]) .. " vs " .. want) + end + local one = Types.Scene.new() + one.meshes = { mesh } + one.nodes = { { children = {}, mesh = 1, matrix = m } } + one.roots = { 1 } + local lo, hi = MeshOps.bounds(MeshOps.merge(one)) + local ok = true + for k = 1, 3 do + ok = ok and near(lo[k], a.min[k], 1e-6) and near(hi[k], a.max[k], 1e-6) + end + t:check(ok, c.name .. ": " .. a.name .. " world bounds") + -- the probe vertex (local) has the reference texel coordinates + local pr = a.probe + local found = false + for _, p in mesh.primitives do + local P = S.reader(p.attributes.POSITION) :: any + local U = S.reader(p.attributes.TEXCOORD_0) :: any + for i = 0, p.attributes.POSITION.count - 1 do + if near(P(i, 0), pr[1], 1e-6) and near(P(i, 1), pr[2], 1e-6) and near(P(i, 2), pr[3], 1e-6) and near(U(i, 0), pr[4], 1e-5) and near(U(i, 1), pr[5], 1e-5) then + found = true + end + end + end + t:check(found, c.name .. ": " .. a.name .. " texel probe") + end + end + end + end +end + +do + local s = assert(decode(Fx.cases[1].data, { textureSize = Fx.cases[1].sizes })) + local room, light + for _, n in s.nodes do + if n.name == "Brush0" then + room = n + elseif n.name == "Light0" then + light = n + end + end + t:eq(room.extras.t3d.csg, "CSG_Subtract", "csg operation") + -- a subtracted room faces inwards: the floor's normal points up (+z) in the brush frame + local prim + for _, p in s.meshes[room.mesh].primitives do + if s.materials[p.material].name == "Floor" then + prim = p + end + end + local N = S.reader(prim.attributes.NORMAL) :: any + local P = S.reader(prim.attributes.POSITION) :: any + t:check(P(0, 2) < 0 and N(0, 2) > 0.99, "subtractive brush faces inwards") + t:check(s.lights[s.nodes[table.find(s.nodes, light) :: number].light].type == "point", "UE1 light") + t:eq(s.nodes[1].extras.t3d.properties.Title, "Test Level", "actor properties") + local withBuilder = assert(decode(Fx.cases[1].data, { builder = true })) + t:eq(#withBuilder.meshes, #s.meshes + 1, "builder brush on request") + local u4 = assert(decode(Fx.cases[2].data)) + t:eq(u4.meta.source.engine, "ue4", "UE4 text") + local pl + for _, n in u4.nodes do + if n.light then + pl = u4.lights[n.light] + end + end + t:check(pl and pl.intensity == 3000 and pl.range == 500 and near(pl.color[1], 1, 1e-9), "UE4 point light component") + local bare = assert(decode("Begin PolyList\nBegin Polygon Texture=X\nVertex 0,0,0\nVertex 0,1,0\nVertex 1,0,0\nEnd Polygon\nEnd PolyList\n")) + t:eq(#bare.meshes, 1, "a bare polylist") + t:eq(F.detect(Fx.cases[1].data), "t3d", "F.detect") +end + +do + local _, e = decode("Begin Map\nBegin Actor Class=Brush Name=B\n") + t:check(e and e.code == Err.TRUNCATED, "unclosed blocks: " .. tostring(e)) + local _, e2 = decode("hello") + t:check(e2 and e2.code == Err.CORRUPT, "no blocks") + local _, e3 = decode(Fx.cases[1].data, { maxBlocks = 3 }) + t:check(e3 and e3.code == Err.LIMIT, "block limit") +end + +t:fuzz("decode", function(b: buffer) + return T3d.decode(Bytes.reader(b)) +end, samples) +t:done() diff --git a/tools/fixtures/docs_engines.py b/tools/fixtures/docs_engines.py index 7aa9653..15cc48f 100644 --- a/tools/fixtures/docs_engines.py +++ b/tools/fixtures/docs_engines.py @@ -1,6 +1,7 @@ # Docs inputs for the engine / level-editor sections of the scene, tile map, archive and data pages (tools/fixtures.py, # tools/docs_check.py): the hand-written ASE of tools/fixtures/ase.py, LDtk's AutoLayers_2_stamps sample (tools/fixtures/ldtk.py), -# HaxeFlixel's TurnBasedRPG Ogmo project and level (tests/fixtures/ogmo), a small Godot scene and resource. +# HaxeFlixel's TurnBasedRPG Ogmo project and level (tests/fixtures/ogmo), a small Godot scene and resource, the +# UE1 map of tools/fixtures/t3d.py. # tests/gen/docs_engines.luau { files = { [name] = bytes }, vars = { aseText = "hand.ase", ... } } import importlib.util, os @@ -38,7 +39,7 @@ metallic = 0.25 roughness = 1.0 """ -INPUTS = ["tools/docs_check.py", "tools/fixtures/ase.py", "tools/fixtures/ldtk.py", "tests/fixtures/ogmo"] +INPUTS = ["tools/docs_check.py", "tools/fixtures/t3d.py", "tools/fixtures/ase.py", "tools/fixtures/ldtk.py", "tests/fixtures/ogmo"] def mod(ctx, name): @@ -55,6 +56,7 @@ def generate(ctx): for f in ("turnBasedRPG.ogmo", "room-001.json"): files[f] = ctx.read("tests/fixtures/ogmo/" + f) files["world.tscn"] = TSCN.encode() + files["level.t3d"] = mod(ctx, "t3d").ue1()[0].encode() files["brick.tres"] = TRES.encode() - vars = {"tscnText": "world.tscn", "tresText": "brick.tres", "aseText": "hand.ase", "ldtkText": "stamps.ldtk", "ogmoProjectText": "turnBasedRPG.ogmo", "ogmoLevelText": "room-001.json"} + vars = {"t3dText": "level.t3d", "tscnText": "world.tscn", "tresText": "brick.tres", "aseText": "hand.ase", "ldtkText": "stamps.ldtk", "ogmoProjectText": "turnBasedRPG.ogmo", "ogmoLevelText": "room-001.json"} check.emit_inputs(ctx, files, vars) diff --git a/tools/fixtures/t3d.py b/tools/fixtures/t3d.py new file mode 100644 index 0000000..bd2e3d4 --- /dev/null +++ b/tools/fixtures/t3d.py @@ -0,0 +1,204 @@ +# Unreal T3D fixtures (tools/fixtures.py): maps written here in UnrealEd's export layout (UE1-3: Begin Map / Actor / +# Brush / PolyList / Polygon with Origin / Normal / TextureU / TextureV / Pan / Vertex records, Location / Rotation in +# 65536ths of a turn, PrePivot / MainScale / PostScale; UE4: Begin Level, components with Relative* in degrees), with +# reference values computed here independently: each brush's world vertices (ABrush coords: v - PrePivot, MainScale, +# FRotationMatrix, PostScale, + Location), polygon areas per texture, bounds, and the texel coordinates of probe +# vertices; actors, lights and static mesh references. +# tests/gen/t3d.luau { cases = { { name, data, sizes = { [texture] = { w, h } }, actors = { { name, class, mesh?, +# area = { [texture] = a }, triangles, min, max, probe = { x, y, z, u, v }, origin } } } } } +import math + +INPUTS = ["src/Rosetta/model/t3d"] + + +def box(sx, sy, sz, tex): + """an axis box centred on 0: six quads as UnrealEd's cube builder lists them (CCW about the outward normal)""" + hx, hy, hz = sx / 2, sy / 2, sz / 2 + faces = [] + for axis in range(3): + for sign in (-1, 1): + n = [0, 0, 0] + n[axis] = sign + a, b = [(1, 2), (2, 0), (0, 1)][axis] + h = [hx, hy, hz] + pts = [] + for ca, cb in ((-1, -1), (-1, 1), (1, 1), (1, -1)) if sign < 0 else ((-1, -1), (1, -1), (1, 1), (-1, 1)): + p = [0, 0, 0] + p[axis] = sign * h[axis] + p[a] = ca * h[a] + p[b] = cb * h[b] + pts.append(p) + # make it CCW about n (right-handed cross) + e1 = [pts[1][i] - pts[0][i] for i in range(3)] + e2 = [pts[2][i] - pts[0][i] for i in range(3)] + c = [e1[1] * e2[2] - e1[2] * e2[1], e1[2] * e2[0] - e1[0] * e2[2], e1[0] * e2[1] - e1[1] * e2[0]] + if sum(c[i] * n[i] for i in range(3)) < 0: + pts.reverse() + u = [0, 0, 0] + v = [0, 0, 0] + u[a] = 1 + v[b] = -1 + faces.append({"tex": tex(axis, sign), "normal": n, "origin": pts[0], "u": u, "v": v, "pan": (axis * 8, sign * 4), "verts": pts, "flags": 0}) + return faces + + +def fmt(v): + return ",".join("%+013.6f" % x for x in v) + + +def polylist(faces, ind=" "): + out = [ind + "Begin PolyList"] + for f in faces: + out.append(ind + " Begin Polygon Texture=%s Flags=%d Link=0" % (f["tex"], f["flags"])) + out.append(ind + " Origin " + fmt(f["origin"])) + out.append(ind + " Normal " + fmt(f["normal"])) + out.append(ind + " TextureU " + fmt(f["u"])) + out.append(ind + " TextureV " + fmt(f["v"])) + out.append(ind + " Pan U=%d V=%d" % f["pan"]) + for p in f["verts"]: + out.append(ind + " Vertex " + fmt(p)) + out.append(ind + " End Polygon") + out.append(ind + "End PolyList") + return out + + +def rotmat(pitch, yaw, roll, k): + p, y, r = pitch * k, yaw * k, roll * k + SP, CP, SY, CY, SR, CR = math.sin(p), math.cos(p), math.sin(y), math.cos(y), math.sin(r), math.cos(r) + # FRotationMatrix rows = axes + return [[CP * CY, CP * SY, SP], [SR * SP * CY - CR * SY, SR * SP * SY + CR * CY, -SR * CP], [-(CR * SP * CY + SR * SY), CY * SR - CR * SP * SY, CR * CP]] + + +def world(v, a): + x = [v[i] - a["prepivot"][i] for i in range(3)] + x = [x[i] * a["main"][i] for i in range(3)] + R = a["rot"] + x = [x[0] * R[0][i] + x[1] * R[1][i] + x[2] * R[2][i] for i in range(3)] + x = [x[i] * a["post"][i] for i in range(3)] + return [x[i] + a["loc"][i] for i in range(3)] + + +def area(pts): + ax = ay = az = 0 + for k in range(1, len(pts) - 1): + u = [pts[k][i] - pts[0][i] for i in range(3)] + v = [pts[k + 1][i] - pts[0][i] for i in range(3)] + ax += u[1] * v[2] - u[2] * v[1] + ay += u[2] * v[0] - u[0] * v[2] + az += u[0] * v[1] - u[1] * v[0] + return math.sqrt(ax * ax + ay * ay + az * az) / 2 + + +def reference(a, faces, sizes, builder=False): + ref = {"name": a["name"], "class": a["class"]} + if builder: + return ref + ar, tris = {}, 0 + lo, hi = [1e30] * 3, [-1e30] * 3 + for f in faces: + w = [world(p, a) for p in f["verts"]] + ar[f["tex"]] = ar.get(f["tex"], 0) + area(w) + tris += len(w) - 2 + for p in w: + lo = [min(lo[i], p[i]) for i in range(3)] + hi = [max(hi[i], p[i]) for i in range(3)] + f = faces[0] + p = f["verts"][2] + W, H = sizes.get(f["tex"], (256, 256)) + du = sum((p[i] - f["origin"][i]) * f["u"][i] for i in range(3)) + f["pan"][0] + dv = sum((p[i] - f["origin"][i]) * f["v"][i] for i in range(3)) + f["pan"][1] + ref.update({"mesh": True, "area": ar, "triangles": tris, "min": lo, "max": hi, "probe": list(p) + [du / W, dv / H]}) + return ref + + +K = math.pi * 2 / 65536 + + +def ue1(): + sizes = {"Bricks": (128, 64), "Floor": (256, 256), "Glass": (64, 64)} + lines = ["Begin Map", "Begin Actor Class=LevelInfo Name=LevelInfo0", " Title=\"Test Level\"", " Author=\"rosetta\"", "End Actor"] + actors = [] + # the builder brush (skipped) + builder = {"name": "Brush", "class": "Brush", "loc": [0, 0, 0], "rot": rotmat(0, 0, 0, K), "prepivot": [0, 0, 0], "main": [1, 1, 1], "post": [1, 1, 1]} + fb = box(256, 256, 256, lambda a, s: "Bricks") + lines += ["Begin Actor Class=Brush Name=Brush", " MainScale=(SheerAxis=SHEER_ZX)", " PostScale=(SheerAxis=SHEER_ZX)", " Begin Brush Name=Brush"] + polylist(fb) + [" End Brush", " Brush=Model'MyLevel.Brush'", "End Actor"] + actors.append(reference(builder, fb, sizes, True)) + # a subtracted room: yawed a quarter turn, pre-pivot, main scale + room = {"name": "Brush0", "class": "Brush", "loc": [64, -32, 16], "rot": rotmat(0, 16384, 0, K), "prepivot": [16, 0, 8], "main": [2, 1, 0.5], "post": [1, 1, 1]} + fr = box(512, 384, 256, lambda a, s: "Floor" if a == 2 else "Bricks") + lines += ["Begin Actor Class=Brush Name=Brush0", " CsgOper=CSG_Subtract", " MainScale=(Scale=(X=2.000000,Z=0.500000),SheerAxis=SHEER_ZX)", + " PostScale=(SheerAxis=SHEER_ZX)", " Location=(X=64.000000,Y=-32.000000,Z=16.000000)", " Rotation=(Yaw=16384)", + " PrePivot=(X=16.000000,Z=8.000000)", " Begin Brush Name=Model1"] + polylist(fr) + [" End Brush", " Brush=Model'MyLevel.Model1'", "End Actor"] + actors.append(reference(room, fr, sizes)) + # an added pillar: pitch + roll, post scale + pil = {"name": "Brush1", "class": "Brush", "loc": [-100, 50, 0], "rot": rotmat(8192, 0, 4096, K), "prepivot": [0, 0, 0], "main": [1, 1, 1], "post": [1, 1.5, 2]} + fp = box(32, 32, 200, lambda a, s: "Glass") + for f in fp[:2]: + f["flags"] = 2 + lines += ["Begin Actor Class=Brush Name=Brush1", " CsgOper=CSG_Add", " PostScale=(Scale=(Y=1.500000,Z=2.000000),SheerAxis=SHEER_ZX)", + " Location=(X=-100.000000,Y=50.000000)", " Rotation=(Pitch=8192,Roll=4096)", " Begin Brush Name=Model2"] + polylist(fp) + [" End Brush", " Brush=Model'MyLevel.Model2'", "End Actor"] + actors.append(reference(pil, fp, sizes)) + lines += ["Begin Actor Class=Light Name=Light0", " LightBrightness=128", " LightHue=40", " LightSaturation=64", " LightRadius=32", + " Location=(X=0.000000,Y=0.000000,Z=96.000000)", "End Actor"] + actors.append({"name": "Light0", "class": "Light", "origin": [0, 0, 96]}) + lines += ["Begin Actor Class=PlayerStart Name=PlayerStart0", " Location=(X=10.000000,Y=20.000000,Z=30.000000)", " Rotation=(Yaw=-16384)", " DrawScale=2.000000", "End Actor"] + actors.append({"name": "PlayerStart0", "class": "PlayerStart", "origin": [10, 20, 30]}) + lines += ["End Map", ""] + return "\r\n".join(lines), sizes, actors + + +def ue4(): + sizes = {} + lines = ["Begin Map", " Begin Level"] + actors = [] + a = {"name": "Brush_1", "class": "/Script/Engine.Brush", "loc": [100, 200, 300], "rot": rotmat(0, 45, 0, math.pi / 180), "prepivot": [0, 0, 0], "main": [1, 1, 1], "post": [1, 1, 1]} + fb = box(200, 200, 100, lambda ax, s: "/Game/Materials/M_Wall.M_Wall") + lines += [" Begin Actor Class=/Script/Engine.Brush Name=Brush_1 Archetype=/Script/Engine.Brush'/Script/Engine.Default__Brush'", + " Begin Object Class=/Script/Engine.BrushComponent Name=\"BrushComponent0\" Archetype=BrushComponent'/Script/Engine.Default__Brush:BrushComponent0'", + " End Object", + " Begin Object Name=\"BrushComponent0\"", + " Brush=Model'\"Model_1\"'", + " RelativeLocation=(X=100.000000,Y=200.000000,Z=300.000000)", + " RelativeRotation=(Pitch=0.000000,Yaw=45.000000,Roll=0.000000)", + " End Object", + " BrushType=Brush_Add", + " Begin Brush Name=Model_1"] + polylist(fb, " ") + [" End Brush", + " Brush=Model'\"Model_1\"'", " BrushComponent=BrushComponent'\"BrushComponent0\"'", " RootComponent=BrushComponent'\"BrushComponent0\"'", + " ActorLabel=\"Box Brush\"", " End Actor"] + actors.append(reference(a, fb, sizes)) + lines += [" Begin Actor Class=/Script/Engine.StaticMeshActor Name=StaticMeshActor_3", + " Begin Object Class=/Script/Engine.StaticMeshComponent Name=\"StaticMeshComponent0\"", + " End Object", + " Begin Object Name=\"StaticMeshComponent0\"", + " StaticMesh=StaticMesh'\"/Game/Meshes/SM_Chair.SM_Chair\"'", + " RelativeLocation=(X=-50.000000,Y=0.000000,Z=10.000000)", + " RelativeScale3D=(X=2.000000,Y=2.000000,Z=2.000000)", + " End Object", + " StaticMeshComponent=StaticMeshComponent0", + " RootComponent=StaticMeshComponent0", + " End Actor"] + actors.append({"name": "StaticMeshActor_3", "class": "/Script/Engine.StaticMeshActor", "origin": [-50, 0, 10], "staticMesh": "/Game/Meshes/SM_Chair.SM_Chair"}) + lines += [" Begin Actor Class=/Script/Engine.PointLight Name=PointLight_0", + " Begin Object Class=/Script/Engine.PointLightComponent Name=\"LightComponent0\"", + " End Object", + " Begin Object Name=\"LightComponent0\"", + " AttenuationRadius=500.000000", + " Intensity=3000.000000", + " LightColor=(B=64,G=128,R=255,A=255)", + " RelativeLocation=(X=0.000000,Y=0.000000,Z=250.000000)", + " End Object", + " PointLightComponent=LightComponent0", + " LightComponent=LightComponent0", + " RootComponent=LightComponent0", + " End Actor"] + actors.append({"name": "PointLight_0", "class": "/Script/Engine.PointLight", "origin": [0, 0, 250]}) + lines += [" End Level", "Begin Surface", "End Surface", "End Map", ""] + return "\n".join(lines), sizes, actors + + +def generate(ctx): + cases = [] + for name, f in (("ue1.t3d", ue1), ("ue4.t3d", ue4)): + text, sizes, actors = f() + cases.append({"name": name, "data": text.encode(), "sizes": {k: list(v) for k, v in sizes.items()}, "actors": actors}) + ctx.emit("t3d", {"cases": cases}) From 74df2ed607278aa92a873190cb7caad9b29d2135 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 19:35:11 -0600 Subject: [PATCH 08/10] bench: Godot tscn decode / encode, LDtk, ASE lines --- tools/bench.luau | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tools/bench.luau b/tools/bench.luau index cc2a2a4..1aefb2a 100644 --- a/tools/bench.luau +++ b/tools/bench.luau @@ -1923,3 +1923,39 @@ do assert(BspFmt.decode(Bytes.reader(bsp))) end) end + +-- ws-engines: text scene / level formats, MB/s of file text: Godot .tscn (Godot's own main.tscn with a 2210-vertex +-- sphere and base64 surfaces; codecs/text/GodotVariant + ArrayMesh surfaces), an LDtk sample project, 3ds Max ASE +-- (assimp's MotionCaptureROM.ase); fixtures tools/fixtures/godot.py, ldtk.py, ase.py +do + local Godot = require("@rosetta/model/godot") + local Ldtk = require("@rosetta/vector/ldtk") + local Ase = require("@rosetta/model/ase") + local Bytes = require("@rosetta/core/Bytes") + local GF = require("@tests/gen/godot") + local LF = require("@tests/gen/ldtk") + local AF = require("@tests/gen/ase_cases") + local main = buffer.fromstring(GF.cases[2].data) + local files = GF.cases[2].files + bench("godot tscn decode", 5, buffer.len(main), function() + assert(Godot.decode(Bytes.reader(main), { resolve = function(p: string): buffer? + return if files[p] then buffer.fromstring(files[p]) else nil + end })) + end) + local scene = assert(Godot.decode(Bytes.reader(main))) + bench("godot tscn encode", 5, buffer.len(main), function() + assert(Godot.encode(scene)) + end) + local ld = buffer.fromstring(LF.cases[2].data) + bench("ldtk decode (" .. LF.cases[2].name .. ")", 3, buffer.len(ld), function() + assert(Ldtk.decode(Bytes.reader(ld))) + end) + for _, c in AF do + if string.find(c.name, "MotionCaptureROM", 1, true) then + local b = buffer.fromstring(c.data) + bench("ase decode (MotionCaptureROM)", 3, buffer.len(b), function() + assert(Ase.decode(Bytes.reader(b))) + end) + end + end +end From cc4aa331ebae800c0a64ebe12d60c36be1ee3ed9 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 19:35:47 -0600 Subject: [PATCH 09/10] build: regenerate bundles --- build/Rosetta.luau | 5226 +++++++++++++++++++++++++++++- build/Rosetta.luau.linemap.json | 1119 +++---- build/rosetta.lua | 5228 ++++++++++++++++++++++++++++++- build/rosetta.lua.linemap.json | 1119 +++---- 4 files changed, 11573 insertions(+), 1119 deletions(-) diff --git a/build/Rosetta.luau b/build/Rosetta.luau index 138993c..692b357 100644 --- a/build/Rosetta.luau +++ b/build/Rosetta.luau @@ -1688,6 +1688,18 @@ local list: { Entry } = { return __include("model/gltf") end, }, + { + name = "godot", + category = "model", + path = "model/godot", + extensions = { "tscn", "escn" }, + mime = { "application/x-godot-scene" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/GodotVariant", "codecs/model/Mat4" }, + caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, instances = true }, + load = function() + return __include("model/godot") + end, + }, { name = "iqm", category = "model", @@ -1940,6 +1952,18 @@ local list: { Entry } = { return __include("model/stl") end, }, + { + name = "t3d", + category = "model", + path = "model/t3d", + extensions = { "t3d" }, + mime = { "text/x-unreal-t3d" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Text", "codecs/model/Brush" }, + caps = { decode = true, encode = false, text = true, brushes = true, actors = true }, + load = function() + return __include("model/t3d") + end, + }, { name = "usda", category = "model", @@ -2672,6 +2696,18 @@ local list: { Entry } = { return __include("data/toml") end, }, + { + name = "tres", + category = "data", + path = "data/tres", + extensions = { "tres" }, + mime = { "application/x-godot-resource" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/GodotVariant" }, + caps = { decode = true, encode = true, ordered = true }, + load = function() + return __include("data/tres") + end, + }, { name = "xml", category = "data", @@ -2696,6 +2732,30 @@ local list: { Entry } = { return __include("data/yaml") end, }, + { + name = "ldtk", + category = "vector", + path = "vector/ldtk", + extensions = { "ldtk" }, + mime = { "application/x-ldtk+json" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Json" }, + caps = { decode = true, encode = true, levels = true, worlds = true, intGrid = true, entities = true }, + load = function() + return __include("vector/ldtk") + end, + }, + { + name = "ogmo", + category = "vector", + path = "vector/ogmo", + extensions = { "ogmo" }, + mime = { "application/x-ogmo+json" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "core/Base64", "Types", "codecs/text/Json" }, + caps = { decode = true, encode = true, projects = true, entities = true, decals = true }, + load = function() + return __include("vector/ogmo") + end, + }, { name = "svg", category = "vector", @@ -10143,14 +10203,14 @@ local function encode(archive: any, opts: any?): (buffer?, Err.Err?) return UnityPackage.encode(archive, opts) end -type Asset = { asset: Tar.Entry?, meta: Tar.Entry?, pathname: Tar.Entry?, preview: Tar.Entry? } +type Asset = { asset: Tar.Entry?, meta: Tar.Entry?, pathname: Tar.Entry?, preview: Tar.Entry?, [string]: any } local function text(b: buffer, e: Tar.Entry): string return buffer.readstring(b, e.offset, e.size) end function UnityPackage.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) - local o = opts or {} + local o: DecodeOptions = opts or {} local tar, err = Deflate.gunzip(r.buf, r.base, r.limit - r.base) if not tar then return nil, err @@ -10169,7 +10229,7 @@ function UnityPackage.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.E if guid and not e.dir then local a = byGuid[guid] if not a then - a = {} + a = {} :: Asset byGuid[guid] = a table.insert(order, guid) end @@ -10244,7 +10304,7 @@ local function defaultMeta(guid: string, dir: boolean): string end function UnityPackage.encode(archive: any, opts: EncodeOptions?): (buffer?, Err.Err?) - local o = opts or {} + local o: EncodeOptions = opts or {} local items = Archive.entries(archive) if not items then return nil, Err.new(Err.ARG, "expected an Archive") @@ -10278,13 +10338,12 @@ function UnityPackage.encode(archive: any, opts: EncodeOptions?): (buffer?, Err. end metaData = mb end - local guid = if type(e.guid) == "string" and #e.guid == 32 and string.match(e.guid, "^%x+$") then string.lower(e.guid) else nil - guid = guid or (if metaData then metaGuid(metaData) else nil) or Md5.of(buffer.fromstring(path)) - if used[guid :: string] then - guid = Md5.of(buffer.fromstring(path .. "\0" .. guid)) + local given: string? = if type(e.guid) == "string" and #e.guid == 32 and string.match(e.guid, "^%x+$") then string.lower(e.guid) else nil + local g: string = given or (if metaData then metaGuid(metaData) else nil) or Md5.of(buffer.fromstring(path)) + if used[g] then + g = Md5.of(buffer.fromstring(path .. "\0" .. g)) end - used[guid :: string] = true - local g = guid :: string + used[g] = true metaData = metaData or buffer.fromstring(defaultMeta(g, e.dir == true)) table.insert(list, { name = g .. "/", dir = true, mtime = mtime }) if data then @@ -88602,6 +88661,665 @@ end return VXml end +__FILES["codecs/text/GodotVariant"] = function() + +-- codecs/text/GodotVariant: Godot's text resource syntax (.tscn / .tres / .escn, formats 2-4; Godot's +-- variant_parser.cpp and resource_format_text.cpp): [section key=value ...] headers with `key = value` properties, +-- and the Variant text syntax (numbers, strings, &"StringName", ^"NodePath", arrays, dictionaries, constructors such +-- as Vector3(...), Transform3D(...), PackedFloat32Array(...), SubResource("id"), Object(Class, "k": v)). +-- Constructor values are { type, args } tables (GodotVariant.isCtor); dictionaries keep their key order. +local Types = __include("Types") +local Base64 = __include("core/Base64") + +local GodotVariant = {} + +GodotVariant.null = Types.null + +local CTOR = { __godot = true } + +-- integral numbers written as floats ("1.0"): Godot keeps int and float apart (Curve._data mixes them), so the keys +-- holding them are remembered per container (array, dictionary, property table) and written back with ".0" +local FLOATS: { [any]: { [any]: boolean } } = setmetatable({}, { __mode = "k" }) :: any +local lastFloat = false + +local function mark(t: any, k: any, v: any) + if lastFloat and type(v) == "number" and v == math.floor(v) then + local m = FLOATS[t] + if not m then + m = {} + FLOATS[t] = m + end + m[k] = true + end +end + +function GodotVariant.isFloat(t: any, k: any): boolean + local m = FLOATS[t] + return m ~= nil and m[k] == true +end + +function GodotVariant.markFloat(t: any, k: any) + local m = FLOATS[t] + if not m then + m = {} + FLOATS[t] = m + end + m[k] = true +end + +function GodotVariant.copyFloats(from: any, to: any) + local m = FLOATS[from] + if m then + FLOATS[to] = table.clone(m) + end +end + +type Ctor = { type: string, args: { any }, class: string? } +type Section = { tag: string, attrs: { [string]: any }, attrOrder: { string }, props: { [string]: any }, order: { string } } +type Document = { sections: { Section } } + +function GodotVariant.ctor(name: string, args: { any }?): Ctor + return setmetatable({ type = name, args = args or {} }, CTOR) :: any +end + +function GodotVariant.isCtor(v: any): boolean + return type(v) == "table" and getmetatable(v) == CTOR +end + +-- the numbers of a constructor, or nil when an argument is not a number +function GodotVariant.numbers(v: any, name: string?): { number }? + if not GodotVariant.isCtor(v) or (name and v.type ~= name) then + return nil + end + for _, x in v.args do + if type(x) ~= "number" then + return nil + end + end + return v.args :: { number } +end + +-- PackedByteArray(1, 2, ...) or PackedByteArray("base64") (Godot 4.3+), PoolByteArray / ByteArray (format 2) +function GodotVariant.bytes(v: any): buffer? + if not GodotVariant.isCtor(v) then + return nil + end + local a = v.args + if #a == 1 and type(a[1]) == "string" then + return (Base64.decode(a[1])) + end + local b = buffer.create(#a) + for i, x in a do + if type(x) ~= "number" then + return nil + end + buffer.writeu8(b, i - 1, x % 256) + end + return b +end + +-- ------------------------------------------------------------------------------------------------ parse +type P = { s: string, i: number, n: number, depth: number, maxDepth: number } + +local NUMERIC_ARRAYS: { [string]: boolean } = { + PackedByteArray = true, PackedInt32Array = true, PackedInt64Array = true, PackedFloat32Array = true, + PackedFloat64Array = true, PackedVector2Array = true, PackedVector3Array = true, PackedVector4Array = true, + PackedColorArray = true, PoolByteArray = true, PoolIntArray = true, PoolRealArray = true, PoolVector2Array = true, + PoolVector3Array = true, PoolColorArray = true, ByteArray = true, IntArray = true, FloatArray = true, RealArray = true, + Vector2Array = true, Vector3Array = true, ColorArray = true, +} +local WORDS: { [string]: any } = { ["true"] = true, ["false"] = false, ["inf"] = math.huge, ["-inf"] = -math.huge, inf_neg = -math.huge, nan = 0 / 0 } + +local function skip(p: P) + local s, i = p.s, p.i + while true do + local a = string.find(s, "[^ \t\r\n]", i) + if not a then + p.i = p.n + 1 + return + end + if string.byte(s, a) == 59 then -- ';' comment to the end of the line + local e = string.find(s, "\n", a, true) + if not e then + p.i = p.n + 1 + return + end + i = e + 1 + else + p.i = a + return + end + end +end + +local ESC: { [string]: string } = { n = "\n", t = "\t", r = "\r", b = "\b", f = "\f", ["\""] = "\"", ["\\"] = "\\", ["'"] = "'", ["/"] = "/" } + +local function utf8char(c: number): string + return utf8.char(math.clamp(c, 0, 0x10FFFF)) +end + +local function str(p: P): (string?, string?) + local s = p.s + local i = p.i + 1 + local parts = {} + while true do + local a = string.find(s, "[\"\\]", i) + if not a then + return nil, "unterminated string" + end + table.insert(parts, string.sub(s, i, a - 1)) + if string.byte(s, a) == 34 then + p.i = a + 1 + return table.concat(parts), nil + end + local c = string.sub(s, a + 1, a + 1) + if c == "u" or c == "U" then + local len = if c == "u" then 4 else 6 + local h = tonumber(string.sub(s, a + 2, a + 1 + len), 16) + if not h then + return nil, "bad \\u escape" + end + -- surrogate pairs + if h >= 0xD800 and h < 0xDC00 and string.sub(s, a + 6, a + 7) == "\\u" then + local lo = tonumber(string.sub(s, a + 8, a + 11), 16) + if lo and lo >= 0xDC00 and lo < 0xE000 then + h = 0x10000 + (h - 0xD800) * 1024 + (lo - 0xDC00) + len += 6 + end + end + table.insert(parts, utf8char(h)) + i = a + 2 + len + else + table.insert(parts, ESC[c] or c) + i = a + 2 + end + end +end + +local value: (p: P) -> (any, string?) + +local function numberList(p: P, name: string): (any, string?) + local s = p.s + local close = string.find(s, ")", p.i, true) + if not close then + return nil, "unterminated " .. name + end + local body = string.sub(s, p.i, close - 1) + -- base64 PackedByteArray, or a list of plain numbers + local q = string.match(body, "^%s*\"([^\"]*)\"%s*$") + if q then + p.i = close + 1 + return GodotVariant.ctor(name, { q }), nil + end + local out = {} + local k = 0 + for tok in string.gmatch(body, "[^,%s]+") do + local v = tonumber(tok) + if v == nil then + v = WORDS[tok] + if type(v) ~= "number" then + return nil, nil -- not purely numeric: parse it generically + end + end + k += 1 + out[k] = v + end + p.i = close + 1 + return GodotVariant.ctor(name, out), nil +end + +local function list(p: P, close: number, into: { any }): string? + skip(p) + if string.byte(p.s, p.i) == close then + p.i += 1 + return nil + end + while true do + local v, err = value(p) + if err then + return err + end + table.insert(into, v) + mark(into, #into, v) + skip(p) + local c = string.byte(p.s, p.i) + if c == 44 then -- ',' + p.i += 1 + skip(p) + if string.byte(p.s, p.i) == close then + p.i += 1 + return nil + end + elseif c == close then + p.i += 1 + return nil + else + return "expected ',' or '" .. string.char(close) .. "' at byte " .. (p.i - 1) + end + end +end + +local function dict(p: P): (any, string?) + p.i += 1 + local t, keys = {}, {} + skip(p) + if string.byte(p.s, p.i) == 125 then + p.i += 1 + return Types.object(t, keys), nil + end + while true do + local k, err = value(p) + if err then + return nil, err + end + skip(p) + if string.byte(p.s, p.i) ~= 58 then + return nil, "expected ':' at byte " .. (p.i - 1) + end + p.i += 1 + local v, verr = value(p) + if verr then + return nil, verr + end + local key = if type(k) == "string" or type(k) == "number" then k else GodotVariant.format(k) + if t[key] == nil then + table.insert(keys, key) + end + t[key] = v + mark(t, key, v) + skip(p) + local c = string.byte(p.s, p.i) + if c == 44 then + p.i += 1 + skip(p) + if string.byte(p.s, p.i) == 125 then + p.i += 1 + break + end + elseif c == 125 then + p.i += 1 + break + else + return nil, "expected ',' or '}' at byte " .. (p.i - 1) + end + end + return Types.object(t, keys), nil +end + +value = function(p: P): (any, string?) + skip(p) + if p.i > p.n then + return nil, "truncated: value expected" + end + p.depth += 1 + if p.depth > p.maxDepth then + return nil, "limit: nested deeper than " .. p.maxDepth + end + local s = p.s + local c = string.byte(s, p.i) + local v: any, err: string? = nil, nil + local isFloat = false + if c == 34 then + v, err = str(p) + elseif c == 38 or c == 94 then -- &"StringName", ^"NodePath" + p.i += 1 + local x, e = str(p) + v, err = if x then GodotVariant.ctor(if c == 38 then "StringName" else "NodePath", { x }) else nil, e + elseif c == 91 then -- '[' + p.i += 1 + local out = {} + err = list(p, 93, out) + v = out + elseif c == 123 then -- '{' + v, err = dict(p) + else + local num = string.match(s, "^[-+]?%d[%w%.+-]*", p.i) or string.match(s, "^[-+]?%.%d[%w%.+-]*", p.i) + if num then + -- 1e-05, 0x1F, 1.5; a trailing "f" is not Godot's + local x = tonumber(num) + if x == nil then + local m = string.match(num, "^[-+]?[%d%.]+[eE][-+]?%d+") or string.match(num, "^[-+]?[%d%.]+") + x = if m then tonumber(m) else nil + num = m or num + end + if x == nil then + return nil, "bad number " .. num .. " at byte " .. (p.i - 1) + end + p.i += #num + v = x + isFloat = string.find(num, "[%.eE]") ~= nil and string.sub(num, 1, 2) ~= "0x" + else + local word = string.match(s, "^[%a_][%w_]*", p.i) or string.match(s, "^%-inf", p.i) + if not word then + return nil, "unexpected character at byte " .. (p.i - 1) + end + p.i += #word + if word == "null" or word == "nil" then + v = Types.null + elseif WORDS[word] ~= nil then + v = WORDS[word] + else + -- typed array: Array[int]([...]); Dictionary[String, int]({...}) + local typed = string.match(s, "^%[[%w_, ]*%]", p.i) + if typed and (word == "Array" or word == "Dictionary") then + word = word .. typed + p.i += #typed + end + skip(p) + if string.byte(s, p.i) ~= 40 then + return nil, "expected '(' after " .. word .. " at byte " .. (p.i - 1) + end + p.i += 1 + if NUMERIC_ARRAYS[word] then + local save = p.i + v, err = numberList(p, word) + if v == nil and err == nil then + p.i = save + local args = {} + err = list(p, 41, args) + v = GodotVariant.ctor(word, args) + end + elseif word == "Object" then + skip(p) + local cls = string.match(s, "^[%w_]+", p.i) + if not cls then + return nil, "Object without a class at byte " .. (p.i - 1) + end + p.i += #cls + local props, keys = {}, {} + skip(p) + while string.byte(s, p.i) == 44 do + p.i += 1 + local k, kerr = value(p) + if kerr then + return nil, kerr + end + skip(p) + if string.byte(s, p.i) ~= 58 then + return nil, "expected ':' in Object at byte " .. (p.i - 1) + end + p.i += 1 + local x, xerr = value(p) + if xerr then + return nil, xerr + end + if type(k) == "string" then + props[k] = x + table.insert(keys, k) + end + skip(p) + end + if string.byte(s, p.i) ~= 41 then + return nil, "expected ')' after Object at byte " .. (p.i - 1) + end + p.i += 1 + local o = GodotVariant.ctor("Object", { Types.object(props, keys) }) + o.class = cls + v = o + else + local args = {} + err = list(p, 41, args) + v = GodotVariant.ctor(word, args) + end + end + end + end + p.depth -= 1 + lastFloat = isFloat + return v, err +end + +function GodotVariant.value(text: string, maxDepth: number?): (any, string?) + local p: P = { s = text, i = 1, n = #text, depth = 0, maxDepth = maxDepth or 256 } + return value(p) +end + +-- a property key: up to '=' (keys hold '/', ':', '.', or are quoted) +local function key(p: P): string? + local s = p.s + if string.byte(s, p.i) == 34 then + local k = str(p) + return k + end + local k = string.match(s, "^[^=\n%[]+", p.i) + if not k then + return nil + end + p.i += #k + return (string.gsub(k, "%s+$", "")) +end + +function GodotVariant.parse(text: string, opts: { maxDepth: number?, maxSections: number? }?): (Document?, string?) + local o: { maxDepth: number?, maxSections: number? } = opts or {} + if string.sub(text, 1, 3) == "\239\187\191" then + text = string.sub(text, 4) + end + local p: P = { s = text, i = 1, n = #text, depth = 0, maxDepth = o.maxDepth or 256 } + local maxSections = o.maxSections or 2 ^ 22 + local sections: { Section } = {} + local cur: Section? = nil + local s = text + while true do + skip(p) + if p.i > p.n then + break + end + if string.byte(s, p.i) == 91 then + p.i += 1 + skip(p) + local tag = string.match(s, "^[%w_]+", p.i) + if not tag then + return nil, "bad section header at byte " .. (p.i - 1) + end + p.i += #tag + local sec: Section = { tag = tag, attrs = {}, attrOrder = {}, props = {}, order = {} } + while true do + skip(p) + local c = string.byte(s, p.i) + if c == 93 then + p.i += 1 + break + end + local k = string.match(s, "^[%w_/]+", p.i) + if not k then + return nil, "bad attribute in [" .. tag .. "] at byte " .. (p.i - 1) + end + p.i += #k + skip(p) + if string.byte(s, p.i) ~= 61 then + return nil, "expected '=' in [" .. tag .. "] at byte " .. (p.i - 1) + end + p.i += 1 + local v, err = value(p) + if err then + return nil, err + end + if sec.attrs[k] == nil then + table.insert(sec.attrOrder, k) + end + sec.attrs[k] = v + end + if #sections >= maxSections then + return nil, "limit: over " .. maxSections .. " sections" + end + table.insert(sections, sec) + cur = sec + else + local at = p.i + local k = key(p) + if not k or k == "" then + return nil, "bad property at byte " .. (at - 1) + end + skip(p) + if string.byte(s, p.i) ~= 61 then + return nil, "expected '=' after " .. k .. " at byte " .. (p.i - 1) + end + p.i += 1 + local v, err = value(p) + if err then + return nil, err + end + if not cur then + cur = { tag = "", attrs = {}, attrOrder = {}, props = {}, order = {} } + table.insert(sections, cur :: Section) + end + local c = cur :: Section + if c.props[k] == nil then + table.insert(c.order, k) + end + c.props[k] = v + mark(c.props, k, v) + end + end + return { sections = sections }, nil +end + +-- ------------------------------------------------------------------------------------------------ format +local function num(x: number): string + if x ~= x then + return "nan" + elseif x == math.huge then + return "inf" + elseif x == -math.huge then + return "-inf" + elseif x == math.floor(x) and math.abs(x) < 2 ^ 53 then + return string.format("%d", x) + end + for d = 6, 17 do + local s = string.format("%." .. d .. "g", x) + if tonumber(s) == x then + return s + end + end + return string.format("%.17g", x) +end +GodotVariant.number = num + +local function quote(s: string): string + return "\"" .. string.gsub(s, "[\\\"\n\t\r]", { ["\\"] = "\\\\", ["\""] = "\\\"", ["\n"] = "\\n", ["\t"] = "\\t", ["\r"] = "\\r" }) .. "\"" +end +GodotVariant.quote = quote + +local format: (v: any, depth: number, indent: boolean) -> string + +local function item(t: any, k: any, depth: number, indent: boolean): string + local v = t[k] + if type(v) == "number" and v == math.floor(v) and math.abs(v) < 2 ^ 53 and GodotVariant.isFloat(t, k) then + return string.format("%d", v) .. ".0" + end + return format(v, depth, indent) +end +GodotVariant.item = function(t: any, k: any): string + return item(t, k, 0, false) +end + +format = function(v: any, depth: number, indent: boolean): string + if depth > 256 then + return "null" + end + local t = type(v) + if t == "number" then + return num(v) + elseif t == "string" then + return quote(v) + elseif t == "boolean" then + return if v then "true" else "false" + elseif v == nil or v == Types.null then + return "null" + elseif t == "buffer" then + local parts = table.create(buffer.len(v)) + for i = 0, buffer.len(v) - 1 do + parts[i + 1] = tostring(buffer.readu8(v, i)) + end + return "PackedByteArray(" .. table.concat(parts, ", ") .. ")" + elseif t ~= "table" then + return "null" + end + if GodotVariant.isCtor(v) then + if v.type == "StringName" and type(v.args[1]) == "string" then + return "&" .. quote(v.args[1]) + elseif v.type == "Object" then + local props = v.args[1] + local parts = { tostring(v.class or "Object") } + if type(props) == "table" then + for _, k in Types.keys(props) do + table.insert(parts, quote(tostring(k)) .. ": " .. format(props[k], depth + 1, false)) + end + end + return "Object(" .. table.concat(parts, ",") .. ")" + end + local parts: { string } = table.create(#v.args) :: any + for i, x in v.args do + parts[i] = format(x, depth + 1, false) + end + local vt: string = tostring(v.type) + if string.match(vt, "^(%a+)%[") then + local inner: string = parts[1] or "[]" + return vt .. "(" .. inner .. ")" + end + return vt .. "(" .. table.concat(parts, ", ") .. ")" + end + if Types.isObject(v) or not Types.isArray(v) then + local keys = Types.keys(v) + if #keys == 0 then + return "{}" + end + local parts = {} + for _, k in keys do + local ks = if type(k) == "string" then quote(k) else format(k, depth + 1, false) + table.insert(parts, ks .. ": " .. item(v, k, depth + 1, false)) + end + if indent then + return "{\n" .. table.concat(parts, ",\n") .. "\n}" + end + return "{\n" .. table.concat(parts, ",\n") .. "\n}" + end + local parts = table.create(#v) + for i in v do + parts[i] = item(v, i, depth + 1, true) + end + return "[" .. table.concat(parts, ", ") .. "]" +end + +function GodotVariant.format(v: any): string + return format(v, 0, false) +end + +function GodotVariant.encode(doc: Document): string + local out = {} + for i, sec in doc.sections do + if sec.tag ~= "" then + local parts = { "[" .. sec.tag } + local order = sec.attrOrder + if #order == 0 then + order = Types.keys(sec.attrs) + end + for _, k in order do + if sec.attrs[k] ~= nil then + table.insert(parts, k .. "=" .. GodotVariant.format(sec.attrs[k])) + end + end + if i > 1 then + table.insert(out, "") + end + table.insert(out, table.concat(parts, " ") .. "]") + end + local order = sec.order + if #order == 0 then + order = Types.keys(sec.props) + end + for _, k in order do + if sec.props[k] ~= nil then + local ks = if string.find(k, "^[%w_/:%.]+$") then k else quote(k) + table.insert(out, ks .. " = " .. item(sec.props, k, 0, false)) + end + end + end + return table.concat(out, "\n") .. "\n" +end + +return GodotVariant +end __FILES["codecs/text/Json"] = function() -- codecs/text/Json: JSON (RFC 8259 / ECMA-404) parse and serialize, the engine data/json, glTF, TMJ, ... use. New code. @@ -122822,6 +123540,151 @@ end return Encode end +__FILES["data/tres"] = function() + +-- data/tres: Godot text resources (.tres, formats 2-4) as data, read + write (codecs/text/GodotVariant). The value: +-- { type, format, uid?, scriptClass?, loadSteps?, external = { { id, type, path, uid? } }, subresources = { { id, +-- type, properties } }, properties } with Variant values (Vector3, Color, SubResource, ... as { type, args } tables; +-- dictionaries and property tables keep their order). Not supported: binary .res files. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local Types = __include("Types") +local GodotVariant = __include("codecs/text/GodotVariant") + +-- ------------------------------------------------------------------------------------------------ contract +local Tres = { + name = "tres", + category = "data", + extensions = { "tres" }, + mime = { "application/x-godot-resource" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/GodotVariant" }, + caps = { decode = true, encode = true, ordered = true }, +} + +type DecodeOptions = { + maxBytes: number?, -- default 2^28 + maxDepth: number?, -- value nesting, default 256 +} + +-- ------------------------------------------------------------------------------------------------ sniff +function Tres.sniff(r: Bytes.Reader): number + local h = Sniff.text(r, 256) + if string.match(h, "^%s*%[gd_resource[%s%]]") then + return 1 + end + return 0 +end + +-- ------------------------------------------------------------------------------------------------ decode +local function props(sec: GodotVariant.Section): { [string]: any } + local out = {} + for _, k in sec.order do + out[k] = sec.props[k] + end + GodotVariant.copyFloats(sec.props, out) + return Types.object(out, table.clone(sec.order) :: { any }) +end + +function Tres.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) + local o: DecodeOptions = opts or {} + if r.limit - r.base > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local text = buffer.readstring(r.buf, r.base, r.limit - r.base) + local ok, doc, perr = pcall(function(): (GodotVariant.Document?, string?) + return GodotVariant.parse(text, { maxDepth = o.maxDepth }) + end) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad data: " .. tostring(doc)) + end + if not doc then + return nil, Err.from(perr) + end + local head = doc.sections[1] + if not head or head.tag ~= "gd_resource" then + return nil, Err.new(if head and head.tag == "gd_scene" then Err.UNSUPPORTED else Err.CORRUPT, if head and head.tag == "gd_scene" then "a scene (model/godot), not a resource" else "no [gd_resource] header") + end + local a = head.attrs + local value: { [string]: any } = { + type = a.type, + format = a.format, + uid = a.uid, + scriptClass = a.script_class, + loadSteps = a.load_steps, + external = {}, + subresources = {}, + properties = Types.object({}), + } + for i = 2, #doc.sections do + local sec = doc.sections[i] + local sa = sec.attrs + if sec.tag == "ext_resource" then + table.insert(value.external, { id = sa.id, type = sa.type, path = sa.path, uid = sa.uid }) + elseif sec.tag == "sub_resource" then + table.insert(value.subresources, { id = sa.id, type = sa.type, properties = props(sec) }) + elseif sec.tag == "resource" then + value.properties = props(sec) + end + end + return value, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +local function section(tag: string, pairs_: { any }, properties: any?): GodotVariant.Section + local attrs, order = {}, {} + local i = 1 + while pairs_[i] ~= nil do + if pairs_[i + 1] ~= nil then + attrs[pairs_[i]] = pairs_[i + 1] + table.insert(order, pairs_[i]) + end + i += 2 + end + local p, po = {}, {} + if type(properties) == "table" then + for _, k in Types.keys(properties) do + if type(k) == "string" then + p[k] = properties[k] + table.insert(po, k) + end + end + GodotVariant.copyFloats(properties, p) + end + return { tag = tag, attrs = attrs, attrOrder = order, props = p, order = po } +end + +function Tres.encode(value: any, opts: any?): (buffer?, Err.Err?) + if type(value) ~= "table" or type(value.type) ~= "string" then + return nil, Err.new(Err.ARG, "needs a resource table with a type") + end + local ext = if type(value.external) == "table" then value.external else {} + local sub = if type(value.subresources) == "table" then value.subresources else {} + local format = if type(value.format) == "number" then value.format else 3 + local steps = if type(value.loadSteps) == "number" then value.loadSteps elseif #ext + #sub > 0 then #ext + #sub + 1 else nil + local sections = { section("gd_resource", { "type", value.type, "script_class", value.scriptClass, "load_steps", steps, "format", format, "uid", value.uid }) } + for _, e in ext do + if type(e) == "table" then + table.insert(sections, section("ext_resource", { "type", e.type, "uid", e.uid, "path", e.path, "id", e.id })) + end + end + for _, s in sub do + if type(s) == "table" then + table.insert(sections, section("sub_resource", { "type", s.type, "id", s.id }, s.properties)) + end + end + table.insert(sections, section("resource", {}, value.properties)) + local ok, s = pcall(GodotVariant.encode, { sections = sections }) + if not ok then + return nil, Err.new(Err.ARG, "cannot encode: " .. tostring(s)) + end + return buffer.fromstring(s), nil +end + +return Tres +end __FILES["data/xml"] = function() -- data/xml: XML 1.0 over codecs/text/Xml. Supports: decode to a "#document" XmlNode tree, encode a document or an @@ -156880,6 +157743,1728 @@ function Write.build(scene: Types.Scene, opts: Options?): (Out?, Err.Err?) return { doc = doc, bin = bin:finish(), images = imageOut }, nil end +return Write +end +__FILES["model/godot"] = function() + +-- model/godot: Godot text scenes (.tscn, .escn; formats 2-4) as a Scene, read + write (format 3); checked against +-- Godot 4's own loader. Supports: Node3D trees (transforms or position / rotation / scale), MeshInstance3D with +-- ArrayMesh surfaces and primitive meshes (Box, Plane, Quad, Sphere, Cylinder), StandardMaterial3D / SpatialMaterial +-- as PBR, surface material overrides, Camera3D, Omni / Spot / Directional lights, instanced scenes through +-- opts.resolve, non-3D nodes in extras.godot. Not supported: compressed or Godot 3 binary surfaces, skeletons and +-- animations (AnimationPlayer libraries stay sub-resources), blend shapes, other mesh / material resource types. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local Types = __include("Types") +local GodotVariant = __include("codecs/text/GodotVariant") +local Build = __include("model/godot/Build") +local Write = __include("model/godot/Write") + +-- ------------------------------------------------------------------------------------------------ contract +local Godot = { + name = "godot", + category = "model", + extensions = { "tscn", "escn" }, + mime = { "application/x-godot-scene" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/GodotVariant", "codecs/model/Mat4" }, + caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, instances = true }, +} + +-- ------------------------------------------------------------------------------------------------ types +type DecodeOptions = { + maxBytes: number?, -- default 2^28 + maxVertices: number?, -- per surface, default 2^24 + maxDepth: number?, -- value nesting, default 256 + resolve: ((string) -> buffer?)?, -- res:// paths without the prefix: textures, instanced scenes +} + +-- ------------------------------------------------------------------------------------------------ sniff +function Godot.sniff(r: Bytes.Reader): number + local h = Sniff.text(r, 256) + if string.match(h, "^%s*%[gd_scene[%s%]]") then + return 1 + end + return 0 +end + +-- ------------------------------------------------------------------------------------------------ decode +function Godot.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?) + local o: any = opts or {} + if r.limit - r.base > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local text = buffer.readstring(r.buf, r.base, r.limit - r.base) + local ok, doc, perr = pcall(function(): (GodotVariant.Document?, string?) + return GodotVariant.parse(text, { maxDepth = o.maxDepth }) + end) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad data: " .. tostring(doc)) + end + if not doc then + return nil, Err.from(perr) + end + if #doc.sections == 0 then + return nil, Err.new(Err.CORRUPT, "empty file") + end + local ok2, scene, msg = pcall(Build.scene, doc, o) + if not ok2 then + return nil, Err.from(tostring(scene)) + end + if not scene then + return nil, Err.from(msg) + end + return scene, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +function Godot.encode(scene: Types.Scene, opts: any?): (buffer?, Err.Err?) + if type(scene) ~= "table" or type(scene.nodes) ~= "table" then + return nil, Err.new(Err.ARG, "needs a Scene") + end + local ok, doc, msg = pcall(Write.document, scene) + if not ok then + return nil, Err.new(Err.ARG, "bad scene: " .. tostring(doc)) + end + if not doc then + return nil, Err.new(Err.ARG, msg or "bad scene") + end + return buffer.fromstring(GodotVariant.encode(doc)), nil +end + +return Godot +end +__FILES["model/godot/Build"] = function() + +-- model/godot/Build: a parsed Godot text scene (codecs/text/GodotVariant) into a Scene. Transform3D / Transform text +-- is the basis rows then the origin; Node3D position / rotation (Euler YXZ, radians) / scale / quaternion are used when +-- there is no transform. Colours (albedo, emission, lights) are sRGB in Godot and linear in the Scene (raw values in +-- extras.godot). Non-3D nodes (Node2D trees, Control, plain Node) are nodes with their properties in extras.godot. +local Types = __include("Types") +local Mat4 = __include("codecs/model/Mat4") +local GodotVariant = __include("codecs/text/GodotVariant") +local Surface = __include("model/godot/Surface") +local Primitives = __include("model/godot/Primitives") + +local Build = {} + +local S = Types.Scene +local isCtor = GodotVariant.isCtor + +type Ctx = { + scene: Types.Scene, + doc: GodotVariant.Document, + format: number, + ext: { [string]: any }, + sub: { [string]: any }, + meshes: { [string]: number }, + materials: { [string]: number }, + textures: { [string]: number }, + opts: any, + depth: number, + warnings: { string }, +} + +local function idOf(v: any): string? + if isCtor(v) and (v.type == "SubResource" or v.type == "ExtResource") then + local a = v.args[1] + if type(a) == "string" or type(a) == "number" then + return tostring(a) + end + end + return nil +end + +local function num(v: any, d: number): number + return if type(v) == "number" and v == v then v else d +end + +local function srgb(c: number): number + if c <= 0.04045 then + return c / 12.92 + end + return ((c + 0.055) / 1.055) ^ 2.4 +end + +local function color(v: any, d: { number }): { number } + local a = GodotVariant.numbers(v, "Color") + if a and #a >= 3 then + return { a[1], a[2], a[3], a[4] or 1 } + end + return d +end + +local function linear(c: { number }): { number } + return { srgb(c[1]), srgb(c[2]), srgb(c[3]), c[4] } +end + +-- ------------------------------------------------------------------------------------------------ transforms +function Build.transform(v: any): { number }? + local a = if isCtor(v) and (v.type == "Transform3D" or v.type == "Transform") then GodotVariant.numbers(v) else nil + if not a or #a ~= 12 then + return nil + end + return { a[1], a[4], a[7], 0, a[2], a[5], a[8], 0, a[3], a[6], a[9], 0, a[10], a[11], a[12], 1 } +end + +-- Basis::from_euler (YXZ): Ry * Rx * Rz +local function euler(x: number, y: number, z: number): { number } + local rx, ry, rz = Mat4.rotation(1, math.deg(x)), Mat4.rotation(2, math.deg(y)), Mat4.rotation(3, math.deg(z)) + return S.mul(ry, S.mul(rx, rz)) +end + +local function nodeMatrix(props: any): { number }? + local m = Build.transform(props.transform) + if m then + return m + end + local pos = GodotVariant.numbers(props.position, "Vector3") or GodotVariant.numbers(props.translation, "Vector3") + local rot = GodotVariant.numbers(props.rotation, "Vector3") + local deg = GodotVariant.numbers(props.rotation_degrees, "Vector3") + local quat = GodotVariant.numbers(props.quaternion, "Quaternion") + local sc = GodotVariant.numbers(props.scale, "Vector3") + if not (pos or rot or deg or quat or sc) then + return nil + end + local r: { number } + if quat and #quat == 4 then + r = Mat4.fromQuat(quat) + elseif rot and #rot == 3 then + r = euler(rot[1], rot[2], rot[3]) + elseif deg and #deg == 3 then + r = euler(math.rad(deg[1]), math.rad(deg[2]), math.rad(deg[3])) + else + r = Mat4.identity() + end + local s = if sc and #sc == 3 then Mat4.scaling(sc[1], sc[2], sc[3]) else Mat4.identity() + local out = S.mul(r, s) + if pos and #pos == 3 then + out[13], out[14], out[15] = pos[1], pos[2], pos[3] + end + return out +end + +-- ------------------------------------------------------------------------------------------------ resources +local function path(ext: any): string? + if type(ext) ~= "table" then + return nil + end + local p = ext.attrs.path + return if type(p) == "string" then p else nil +end + +local function texture(ctx: Ctx, v: any): Types.TextureRef? + local id = idOf(v) + if not id or not isCtor(v) or v.type ~= "ExtResource" then + return nil + end + local key = "ext:" .. id + local idx = ctx.textures[key] + if not idx then + local p = path(ctx.ext[id]) + if not p then + return nil + end + local rel = string.gsub(p, "^res://", "") + local tex: Types.Texture = { name = rel, uri = rel } + local resolve = ctx.opts.resolve + if type(resolve) == "function" then + local ok, b = pcall(resolve, rel) + if ok and type(b) == "buffer" then + tex.data = b + end + end + table.insert(ctx.scene.textures, tex) + idx = #ctx.scene.textures + ctx.textures[key] = idx + end + return { texture = idx :: number } +end + +local MATERIALS = { StandardMaterial3D = true, ORMMaterial3D = true, SpatialMaterial = true } + +local function material(ctx: Ctx, v: any): number? + local id = idOf(v) + if not id or not isCtor(v) then + return nil + end + local key = v.type .. ":" .. id + if ctx.materials[key] then + return ctx.materials[key] + end + local sec = if v.type == "SubResource" then ctx.sub[id] else nil + local typ = if sec then sec.attrs.type else (if ctx.ext[id] then ctx.ext[id].attrs.type else nil) + local p = if sec then sec.props else {} + local m = S.material(if type(p.resource_name) == "string" then p.resource_name else nil) + local albedo = color(p.albedo_color, { 1, 1, 1, 1 }) + m.baseColor = linear(albedo) + m.metallic = num(p.metallic, 0) + m.roughness = num(p.roughness, 1) + local extras: { [string]: any } = { type = typ, albedo = albedo } + if MATERIALS[typ or ""] then + m.baseColorTexture = texture(ctx, p.albedo_texture) + m.metallicRoughnessTexture = texture(ctx, p.metallic_texture) or texture(ctx, p.roughness_texture) + if p.normal_enabled == true or p.normal_enabled == nil and p.normal_texture ~= nil then + m.normalTexture = texture(ctx, p.normal_texture) + if m.normalTexture and type(p.normal_scale) == "number" then + m.normalTexture.scale = p.normal_scale + end + end + if p.ao_enabled == true then + m.occlusionTexture = texture(ctx, p.ao_texture) + end + local emission = p.emission_enabled == true or p.flags_emission == true + if emission then + local e = color(p.emission, { 0, 0, 0, 1 }) + local energy = num(p.emission_energy_multiplier, num(p.emission_energy, 1)) + local le = linear(e) + m.emissive = { le[1], le[2], le[3] } + m.emissiveTexture = texture(ctx, p.emission_texture) + extras.emission = e + if energy ~= 1 then + m.extensions = { KHR_materials_emissive_strength = { emissiveStrength = energy } } + end + end + local transparency = num(p.transparency, if p.flags_transparent == true then 1 else 0) + if transparency == 1 or transparency == 4 then + m.alphaMode = "blend" + elseif transparency == 2 or transparency == 3 then + m.alphaMode = "mask" + m.alphaCutoff = num(p.alpha_scissor_threshold, 0.5) + end + m.doubleSided = num(p.cull_mode, num(p.params_cull_mode, 0)) == 2 + if num(p.shading_mode, 1) == 0 or p.flags_unshaded == true then + m.extensions = m.extensions or {} + ;(m.extensions :: any).KHR_materials_unlit = {} + end + local uv = GodotVariant.numbers(p.uv1_scale, "Vector3") + local off = GodotVariant.numbers(p.uv1_offset, "Vector3") + if m.baseColorTexture and (uv or off) then + m.baseColorTexture.transform = { scale = if uv then { uv[1], uv[2] } else { 1, 1 }, offset = if off then { off[1], off[2] } else { 0, 0 } } + end + elseif not sec then + extras.path = path(ctx.ext[id]) + end + m.extras = { godot = extras } + table.insert(ctx.scene.materials, m) + ctx.materials[key] = #ctx.scene.materials + return #ctx.scene.materials +end + +-- a mesh resource (ArrayMesh or a primitive mesh) as a Scene mesh; overrides: surface index -> material value +local function mesh(ctx: Ctx, v: any, overrides: { [number]: any }?): (number?, string?) + local id = idOf(v) + if not id or not isCtor(v) then + return nil, nil + end + local key = v.type .. ":" .. id + if not overrides and ctx.meshes[key] then + return ctx.meshes[key], nil + end + local sec = if v.type == "SubResource" then ctx.sub[id] else nil + local out: Types.Mesh = { primitives = {} } + if not sec then + out.extras = { godot = { path = path(ctx.ext[id]) } } + else + local typ = sec.attrs.type + local p = sec.props + out.name = if type(p.resource_name) == "string" then p.resource_name else nil + local maxV = ctx.opts.maxVertices or 2 ^ 24 + if typ == "ArrayMesh" or typ == "Mesh" then + local surfaces: { any } = {} + if type(p._surfaces) == "table" then + surfaces = p._surfaces + else + for k = 0, 4096 do + local s = p["surfaces/" .. k] + if s == nil then + break + end + surfaces[k + 1] = s + end + end + local blend = 0 + for i, sd in surfaces do + local L, err = Surface.lists(sd, maxV) + if not L then + return nil, err + end + local prim = Surface.primitive(L) + local mv = if overrides and overrides[i - 1] ~= nil then overrides[i - 1] else (if type(sd) == "table" then sd.material else nil) + prim.material = material(ctx, mv) + if type(sd) == "table" and type(sd.name) == "string" then + prim.extras = { name = sd.name } + end + if type(sd) == "table" and type(sd.blend_shapes) == "table" then + blend = math.max(blend, #sd.blend_shapes) + end + table.insert(out.primitives, prim) + end + if blend > 0 then + out.extras = { godot = { blendShapes = blend } } + end + elseif Primitives.KINDS[typ] then + local a = Primitives.build(typ, p) + if a then + local prim = Surface.primitive(Surface.fromPrimitiveArrays(a)) + prim.material = material(ctx, if overrides and overrides[0] ~= nil then overrides[0] else p.material) + table.insert(out.primitives, prim) + end + out.extras = { godot = { primitive = typ } } + else + out.extras = { godot = { type = typ } } + end + end + table.insert(ctx.scene.meshes, out) + if not overrides then + ctx.meshes[key] = #ctx.scene.meshes + end + return #ctx.scene.meshes, nil +end + +-- ------------------------------------------------------------------------------------------------ nodes +local LIGHT: { [string]: "point" | "spot" | "directional" } = { + OmniLight3D = "point", SpotLight3D = "spot", DirectionalLight3D = "directional", + OmniLight = "point", SpotLight = "spot", DirectionalLight = "directional", +} +local CAMERA = { Camera3D = true, Camera = true, ClippedCamera = true, InterpolatedCamera = true, XRCamera3D = true } +local MESH = { MeshInstance3D = true, MeshInstance = true, CSGMesh3D = true, SoftBody3D = true } + +local THREE_D = { + Node3D = true, Spatial = true, MeshInstance3D = true, MeshInstance = true, Camera3D = true, Camera = true, + OmniLight3D = true, SpotLight3D = true, DirectionalLight3D = true, OmniLight = true, SpotLight = true, DirectionalLight = true, + Skeleton3D = true, Skeleton = true, BoneAttachment3D = true, Marker3D = true, Position3D = true, CollisionShape3D = true, + StaticBody3D = true, RigidBody3D = true, CharacterBody3D = true, Area3D = true, StaticBody = true, RigidBody = true, + KinematicBody = true, Area = true, CollisionShape = true, VisibleOnScreenNotifier3D = true, GPUParticles3D = true, + CPUParticles3D = true, Sprite3D = true, Label3D = true, Path3D = true, PathFollow3D = true, RemoteTransform3D = true, + CSGBox3D = true, CSGSphere3D = true, CSGCylinder3D = true, CSGMesh3D = true, CSGCombiner3D = true, XROrigin3D = true, + XRCamera3D = true, VehicleBody3D = true, VehicleWheel3D = true, NavigationRegion3D = true, ReflectionProbe = true, + GridMap = true, AnimatableBody3D = true, ClippedCamera = true, InterpolatedCamera = true, SoftBody3D = true, +} + +local function plainProps(sec: any): { [string]: any } + local out: { [string]: any } = {} + for _, k in sec.order do + out[k] = sec.props[k] + end + return out +end + +local function camera(ctx: Ctx, typ: string, p: any): number + local fmt2 = ctx.format <= 2 + local cam: Types.Camera + if num(p.projection, 0) == 1 then + local size = num(p.size, 1) + cam = { type = "orthographic", xmag = size / 2, ymag = size / 2, znear = num(p.near, 0.05), zfar = num(p.far, if fmt2 then 100 else 4000) } :: any + else + cam = { type = "perspective", yfov = math.rad(num(p.fov, if fmt2 then 70 else 75)), znear = num(p.near, 0.05), zfar = num(p.far, if fmt2 then 100 else 4000) } :: any + end + table.insert(ctx.scene.cameras, cam) + return #ctx.scene.cameras +end + +local function light(ctx: Ctx, typ: string, p: any): number + local kind = LIGHT[typ] + local c = color(p.light_color, { 1, 1, 1, 1 }) + local lc = linear(c) + local l: Types.Light = { type = kind, color = { lc[1], lc[2], lc[3] }, intensity = num(p.light_energy, 1) } + if kind == "point" then + l.range = num(p.omni_range, 5) + elseif kind == "spot" then + l.range = num(p.spot_range, 5) + l.outerCone = math.rad(num(p.spot_angle, 45)) + l.innerCone = 0 + end + table.insert(ctx.scene.lights, l) + return #ctx.scene.lights +end + +local scene: (ctx: Ctx, doc: GodotVariant.Document, into: number?) -> (number?, string?) + +-- an instanced scene (instance=ExtResource) through opts.resolve; its root becomes the instancing node +local function instance(ctx: Ctx, v: any, node: number): string? + local id = idOf(v) + local p = if id then path(ctx.ext[id]) else nil + local resolve = ctx.opts.resolve + if not p or type(resolve) ~= "function" or ctx.depth >= 8 then + return nil + end + local rel = string.gsub(p, "^res://", "") + local ok, b = pcall(resolve, rel) + if not ok or type(b) ~= "buffer" then + table.insert(ctx.warnings, "instance " .. rel .. " not resolved") + return nil + end + local doc, err = GodotVariant.parse(buffer.tostring(b), { maxDepth = ctx.opts.maxDepth }) + if not doc then + return "instance " .. rel .. ": " .. tostring(err) + end + local sub: Ctx = { + scene = ctx.scene, + doc = doc, + format = 3, + ext = {}, + sub = {}, + meshes = {}, + materials = {}, + textures = {}, + opts = ctx.opts, + depth = ctx.depth + 1, + warnings = ctx.warnings, + } + local _, serr = scene(sub, doc, node) + return serr +end + +scene = function(ctx: Ctx, doc: GodotVariant.Document, into: number?): (number?, string?) + local sc = ctx.scene + local header = doc.sections[1] + ctx.format = if header and type(header.attrs.format) == "number" then header.attrs.format else 3 + for _, sec in doc.sections do + local id = sec.attrs.id + if id ~= nil and (type(id) == "string" or type(id) == "number") then + if sec.tag == "ext_resource" then + ctx.ext[tostring(id)] = sec + elseif sec.tag == "sub_resource" then + ctx.sub[tostring(id)] = sec + end + end + end + local byPath: { [string]: number } = {} + local root: number? = nil + local connections = {} + for _, sec in doc.sections do + if sec.tag == "node" then + local a = sec.attrs + local name = if type(a.name) == "string" then a.name else "Node" + local parent = a.parent + local typ = if type(a.type) == "string" then a.type else nil + local p = sec.props + local idx: number + local isRoot = parent == nil + if isRoot and into then + idx = into + else + table.insert(sc.nodes, { name = name, children = {} }) + idx = #sc.nodes + end + local node = sc.nodes[idx] + if not (isRoot and into) then + node.name = name + end + if isRoot then + if root then + return nil, "two root nodes" + end + root = idx + byPath["."] = idx + if not into then + table.insert(sc.roots, idx) + end + else + local pp = if type(parent) == "string" then parent else "." + local pi = byPath[pp] + if not pi then + return nil, "node " .. name .. ": no parent " .. pp + end + table.insert(sc.nodes[pi].children, idx) + byPath[if pp == "." then name else pp .. "/" .. name] = idx + end + if a.instance ~= nil then + local err = instance(ctx, a.instance, idx) + if err then + return nil, err + end + end + local m = nodeMatrix(p) + if m then + node.matrix = m + end + local extras: { [string]: any } = node.extras and node.extras.godot or {} + extras.type = typ or extras.type + extras.properties = plainProps(sec) + if a.instance ~= nil then + extras.instance = path(ctx.ext[idOf(a.instance) or ""] ) + end + if type(a.groups) == "table" then + extras.groups = a.groups + end + if p.visible == false then + extras.visible = false + end + node.extras = { godot = extras } + if typ and not THREE_D[typ] then + extras.is2D = string.find(typ, "2D$") ~= nil or typ == "Node2D" or nil + end + if typ and MESH[typ] or p.mesh ~= nil then + local overrides: { [number]: any }? = nil + for k, v in p do + local si = string.match(k, "^surface_material_override/(%d+)$") or string.match(k, "^material/(%d+)$") + if si and v ~= GodotVariant.null then + overrides = overrides or {} + ;(overrides :: any)[tonumber(si) :: number] = v + end + end + if p.material_override ~= nil and p.material_override ~= GodotVariant.null then + overrides = overrides or {} + for k = 0, 63 do + if (overrides :: any)[k] == nil then + (overrides :: any)[k] = p.material_override + end + end + end + if p.mesh ~= nil then + local mi, err = mesh(ctx, p.mesh, overrides) + if err then + return nil, err + end + node.mesh = mi + end + end + if typ and CAMERA[typ] then + node.camera = camera(ctx, typ, p) + elseif typ and LIGHT[typ] then + node.light = light(ctx, typ, p) + extras.lightColor = color(p.light_color, { 1, 1, 1, 1 }) + end + elseif sec.tag == "connection" then + table.insert(connections, sec.attrs) + end + end + if #connections > 0 and not into then + (sc.meta.source :: any).connections = connections + end + return root, nil +end + +function Build.scene(doc: GodotVariant.Document, opts: any): (Types.Scene?, string?) + local sc = S.new() + sc.meta.up = "y" + sc.meta.unit = 1 + local header = doc.sections[1] + sc.meta.source = { + format = "godot", + tag = if header then header.tag else nil, + version = if header then header.attrs.format else nil, + uid = if header then header.attrs.uid else nil, + } + local ctx: Ctx = { + scene = sc, + doc = doc, + format = 3, + ext = {}, + sub = {}, + meshes = {}, + materials = {}, + textures = {}, + opts = opts or {}, + depth = 0, + warnings = {}, + } + if header and header.tag ~= "gd_scene" then + return nil, "unsupported: a " .. header.tag .. " file is a resource, not a scene (data/tres)" + end + local _, err = scene(ctx, doc, nil) + if err then + return nil, err + end + if #ctx.warnings > 0 then + (sc.meta.source :: any).warnings = ctx.warnings + end + return sc, nil +end + +return Build +end +__FILES["model/godot/Primitives"] = function() + +-- model/godot/Primitives: Godot's primitive meshes (BoxMesh, PlaneMesh, QuadMesh, SphereMesh, CylinderMesh) as Godot +-- builds them. Ported from Godot 4.4 scene/resources/3d/primitive_meshes.cpp (MIT, licenses/godot-LICENSE.txt): the +-- same vertex order, normals, tangents, UVs and (clockwise, Godot's front face) indices; no UV2. +local Primitives = {} + +type Arrays = { points: { number }, normals: { number }, tangents: { number }, uvs: { number }, indices: { number } } + +local TAU = math.pi * 2 + +local function num(v: any, d: number): number + return if type(v) == "number" and v == v then v else d +end + +local function vec(v: any, n: number, d: { number }): { number } + if type(v) == "table" and type(v.args) == "table" and #v.args >= n then + local out = {} + for i = 1, n do + out[i] = num(v.args[i], d[i]) + end + return out + end + return d +end + +local function new(): Arrays + return { points = {}, normals = {}, tangents = {}, uvs = {}, indices = {} } +end + +local function add(a: Arrays, px: number, py: number, pz: number, nx: number, ny: number, nz: number, tx: number, ty: number, tz: number, u: number, v: number) + local p, nn, t, uv = a.points, a.normals, a.tangents, a.uvs + p[#p + 1], p[#p + 2], p[#p + 3] = px, py, pz + nn[#nn + 1], nn[#nn + 2], nn[#nn + 3] = nx, ny, nz + t[#t + 1], t[#t + 2], t[#t + 3], t[#t + 4] = tx, ty, tz, 1 + uv[#uv + 1], uv[#uv + 2] = u, v +end + +-- the two triangles of a grid cell: p0 p1 t0, p1 t1 t0 (prev row, this row) +local function quad(a: Arrays, p0: number, p1: number, t0: number, t1: number) + local ix = a.indices + local n = #ix + ix[n + 1], ix[n + 2], ix[n + 3], ix[n + 4], ix[n + 5], ix[n + 6] = p0, p1, t0, p1, t1, t0 +end + +-- BoxMesh::create_mesh_array +local function box(props: any): Arrays + local size = vec(props.size, 3, { 1, 1, 1 }) + local sw, sh, sd = math.max(0, num(props.subdivide_width, 0)), math.max(0, num(props.subdivide_height, 0)), math.max(0, num(props.subdivide_depth, 0)) + local a = new() + local onethird, twothirds = 1 / 3, 2 / 3 + local sx, sy, sz = -size[1] / 2, -size[2] / 2, -size[3] / 2 + local point = 0 + local function faces(rows: number, cols: number, step: (number, number) -> ()) + local thisrow, prevrow = point, 0 + for j = 0, rows + 1 do + for i = 0, cols + 1 do + step(i, j) + point += 2 + if i > 0 and j > 0 then + local i2 = i * 2 + quad(a, prevrow + i2 - 2, prevrow + i2, thisrow + i2 - 2, thisrow + i2) + quad(a, prevrow + i2 - 1, prevrow + i2 + 1, thisrow + i2 - 1, thisrow + i2 + 1) + end + end + prevrow = thisrow + thisrow = point + end + end + -- front + back + faces(sh, sw, function(i: number, j: number) + local v = j / (2 * (sh + 1)) + local u = i / (3 * (sw + 1)) + local x = sx + i * size[1] / (sw + 1) + local y = sy + j * size[2] / (sh + 1) + add(a, x, -y, -sz, 0, 0, 1, 1, 0, 0, u, v) + add(a, -x, -y, sz, 0, 0, -1, -1, 0, 0, twothirds + u, v) + end) + -- left + right + faces(sh, sd, function(i: number, j: number) + local v = j / (2 * (sh + 1)) + local u = i / (3 * (sd + 1)) + local z = sz + i * size[3] / (sd + 1) + local y = sy + j * size[2] / (sh + 1) + add(a, -sx, -y, -z, 1, 0, 0, 0, 0, -1, onethird + u, v) + add(a, sx, -y, z, -1, 0, 0, 0, 0, 1, u, 0.5 + v) + end) + -- top + bottom + faces(sd, sw, function(i: number, j: number) + local v = j / (2 * (sd + 1)) + local u = i / (3 * (sw + 1)) + local x = sx + i * size[1] / (sw + 1) + local z = sz + j * size[3] / (sd + 1) + add(a, -x, -sy, -z, 0, 1, 0, -1, 0, 0, onethird + u, 0.5 + v) + add(a, x, sy, -z, 0, -1, 0, 1, 0, 0, twothirds + u, 0.5 + v) + end) + return a +end + +-- PlaneMesh::_create_mesh_array (QuadMesh: FACE_Z, size 1 x 1) +local function plane(props: any, isQuad: boolean): Arrays + local size = vec(props.size, 2, if isQuad then { 1, 1 } else { 2, 2 }) + local sw, sd = math.max(0, num(props.subdivide_width, 0)), math.max(0, num(props.subdivide_depth, 0)) + local off = vec(props.center_offset, 3, { 0, 0, 0 }) + local orient = num(props.orientation, if isQuad then 2 else 1) + local a = new() + local nx, ny, nz = 0, 1, 0 + if orient == 0 then + nx, ny, nz = 1, 0, 0 + elseif orient == 2 then + nx, ny, nz = 0, 0, 1 + end + local point, thisrow, prevrow = 0, 0, 0 + local z = -size[2] / 2 + for j = 0, sd + 1 do + local x = -size[1] / 2 + for i = 0, sw + 1 do + local u, v = i / (sw + 1), j / (sd + 1) + local px: number, py: number, pz: number = 0, 0, 0 + if orient == 0 then + px, py, pz = 0, z, x + elseif orient == 2 then + px, py, pz = -x, z, 0 + else + px, py, pz = -x, 0, -z + end + if orient == 0 then + add(a, px + off[1], py + off[2], pz + off[3], nx, ny, nz, 0, 0, -1, 1 - u, 1 - v) + else + add(a, px + off[1], py + off[2], pz + off[3], nx, ny, nz, 1, 0, 0, 1 - u, 1 - v) + end + point += 1 + if i > 0 and j > 0 then + quad(a, prevrow + i - 1, prevrow + i, thisrow + i - 1, thisrow + i) + end + x += size[1] / (sw + 1) + end + z += size[2] / (sd + 1) + prevrow = thisrow + thisrow = point + end + return a +end + +-- SphereMesh::create_mesh_array +local function sphere(props: any): Arrays + local radius, height = num(props.radius, 0.5), num(props.height, 1) + local radial, rings = math.max(1, num(props.radial_segments, 64)), math.max(1, num(props.rings, 32)) + local hemi = props.is_hemisphere == true + local scale = height / radius * (if hemi then 1 else 0.5) + local a = new() + local point, thisrow, prevrow = 0, 0, 0 + for j = 0, rings + 1 do + local v = j / (rings + 1) + local w: number, y: number = 0, -1 + if j ~= rings + 1 then + w = math.sin(math.pi * v) + y = math.cos(math.pi * v) + end + for i = 0, radial do + local u = i / radial + local x: number, z: number = 0, 1 + if i ~= radial then + x = math.sin(u * TAU) + z = math.cos(u * TAU) + end + if hemi and y < 0 then + add(a, x * radius * w, 0, z * radius * w, 0, -1, 0, z, 0, -x, u, v) + else + local nx, ny, nz = x * w * scale, y, z * w * scale + local l = math.sqrt(nx * nx + ny * ny + nz * nz) + if l > 0 then + nx, ny, nz = nx / l, ny / l, nz / l + end + add(a, x * w * radius, y * scale * radius, z * w * radius, nx, ny, nz, z, 0, -x, u, v) + end + point += 1 + if i > 0 and j > 0 then + quad(a, prevrow + i - 1, prevrow + i, thisrow + i - 1, thisrow + i) + end + end + prevrow = thisrow + thisrow = point + end + return a +end + +-- CylinderMesh::create_mesh_array +local function cylinder(props: any): Arrays + local top, bottom, height = num(props.top_radius, 0.5), num(props.bottom_radius, 0.5), num(props.height, 2) + local radial, rings = math.max(1, num(props.radial_segments, 64)), math.max(0, num(props.rings, 4)) + local a = new() + local point, thisrow, prevrow = 0, 0, 0 + local sideY = (bottom - top) / height + for j = 0, rings + 1 do + local v = j / (rings + 1) + local radius = top + (bottom - top) * v + local y = height * 0.5 - height * v + for i = 0, radial do + local u = i / radial + local x: number, z: number = 0, 1 + if i ~= radial then + x = math.sin(u * TAU) + z = math.cos(u * TAU) + end + local l = math.sqrt(x * x + sideY * sideY + z * z) + add(a, x * radius, y, z * radius, x / l, sideY / l, z / l, z, 0, -x, u, v * 0.5) + point += 1 + if i > 0 and j > 0 then + quad(a, prevrow + i - 1, prevrow + i, thisrow + i - 1, thisrow + i) + end + end + prevrow = thisrow + thisrow = point + end + local ix = a.indices + for _, cap in { { top, height * 0.5, 1 }, { bottom, height * -0.5, -1 } } do + local r: number, y: number, ny: number = cap[1] :: number, cap[2] :: number, cap[3] :: number + local enabled = if ny > 0 then props.cap_top ~= false else props.cap_bottom ~= false + if enabled and r > 0 then + thisrow = point + add(a, 0, y, 0, 0, ny, 0, 1, 0, 0, if ny > 0 then 0.25 else 0.75, 0.75) + point += 1 + for i = 0, radial do + local t = i / radial + local x: number, z: number = 0, 1 + if i ~= radial then + x = math.sin(t * TAU) + z = math.cos(t * TAU) + end + local u = if ny > 0 then (x + 1) * 0.25 else 0.5 + (x + 1) * 0.25 + local v = if ny > 0 then 0.5 + (z + 1) * 0.25 else 1 - (z + 1) * 0.25 + add(a, x * r, y, z * r, 0, ny, 0, 1, 0, 0, u, v) + point += 1 + if i > 0 then + if ny > 0 then + ix[#ix + 1], ix[#ix + 2], ix[#ix + 3] = thisrow, point - 1, point - 2 + else + ix[#ix + 1], ix[#ix + 2], ix[#ix + 3] = thisrow, point - 2, point - 1 + end + end + end + end + end + return a +end + +Primitives.KINDS = ({ BoxMesh = true, PlaneMesh = true, QuadMesh = true, SphereMesh = true, CylinderMesh = true, CubeMesh = true }) :: { [string]: boolean } + +function Primitives.build(kind: string, props: any): Arrays? + local a: Arrays + if kind == "BoxMesh" or kind == "CubeMesh" then + a = box(props) + elseif kind == "PlaneMesh" then + a = plane(props, false) + elseif kind == "QuadMesh" then + a = plane(props, true) + elseif kind == "SphereMesh" then + a = sphere(props) + elseif kind == "CylinderMesh" then + a = cylinder(props) + else + return nil + end + if props.flip_faces == true then + local ix = a.indices + for k = 1, #ix - 2, 3 do + ix[k + 1], ix[k + 2] = ix[k + 2], ix[k + 1] + end + end + return a +end + +return Primitives +end +__FILES["model/godot/Surface"] = function() + +-- model/godot/Surface: ArrayMesh surfaces <-> Scene primitives. Godot 4.2+ surfaces (format version 2: vertex_data = +-- positions then octahedral normal / tangent pairs, attribute_data = colour / UV / UV2 / custom per vertex, +-- skin_data = bones + weights, index_data u16 / u32; RenderingServer mesh_create_surface_data_from_arrays), and the +-- "arrays" surfaces of format-2 .escn files (Godot 3 ArrayType order). Godot's front faces are clockwise: triangle +-- winding is reversed both ways. Not supported: compressed attributes, format version 1 (Godot 4.0 / 4.1), Godot 3 +-- binary array_data, blend shapes (counted in extras). +local Types = __include("Types") +local GodotVariant = __include("codecs/text/GodotVariant") +local Primitives = __include("model/godot/Primitives") + +local Surface = {} + +local S = Types.Scene + +local function arr(n: number): { number } + return table.create(n) :: any +end + +local function bit(f: number, i: number): boolean + return math.floor(f / 2 ^ i) % 2 == 1 +end + +-- Vector3::octahedron_decode +local function octDecode(x: number, y: number): (number, number, number) + local fx, fy = x * 2 - 1, y * 2 - 1 + local nz = 1 - math.abs(fx) - math.abs(fy) + local t = math.clamp(-nz, 0, 1) + fx += if fx >= 0 then -t else t + fy += if fy >= 0 then -t else t + local l = math.sqrt(fx * fx + fy * fy + nz * nz) + if l == 0 then + return 0, 0, 1 + end + return fx / l, fy / l, nz / l +end + +-- Vector3::octahedron_encode +local function octEncode(x: number, y: number, z: number): (number, number) + local s = math.abs(x) + math.abs(y) + math.abs(z) + if s == 0 then + return 0.5, 0.5 + end + x, y, z = x / s, y / s, z / s + local ox, oy + if z >= 0 then + ox, oy = x, y + else + ox = (1 - math.abs(y)) * (if x >= 0 then 1 else -1) + oy = (1 - math.abs(x)) * (if y >= 0 then 1 else -1) + end + return ox * 0.5 + 0.5, oy * 0.5 + 0.5 +end + +local function u16(v: number): number + return math.clamp(math.floor(v * 65535), 0, 65535) +end + +local CUSTOM_SIZE = { [0] = 4, 4, 4, 8, 4, 8, 12, 16 } + +type Lists = { + points: { number }, + normals: { number }?, + tangents: { number }?, + colors: buffer?, + uvs: { number }?, + uv2s: { number }?, + joints: { number }?, + weights: { number }?, + jointsPer: number, + indices: { number }?, + mode: string, +} + +-- a Godot 4 surface dictionary (format version 2) into lists +local function binary(d: any, maxVertices: number): (Lists?, string?) + local f = tonumber(d.format) or 0 + local vc = tonumber(d.vertex_count) or 0 + if vc < 0 or vc > maxVertices or vc % 1 ~= 0 then + return nil, "limit: vertex count " .. tostring(d.vertex_count) + end + if bit(f, 29) then + return nil, "unsupported: compressed surface attributes" + end + if not bit(f, 35) then + return nil, "unsupported: surface format version 1 (Godot 4.0 / 4.1)" + end + local vd = GodotVariant.bytes(d.vertex_data) + if not vd then + return nil, "surface without vertex_data" + end + local is2D = bit(f, 25) + local pstride = if is2D then 8 else 12 + local hasN, hasT = bit(f, 1), bit(f, 2) + local ntStride = (if hasN then 4 else 0) + (if hasT then 4 else 0) + if buffer.len(vd) < vc * (pstride + ntStride) then + return nil, "truncated vertex_data" + end + local L: Lists = { points = arr(vc * 3), jointsPer = 4, mode = "triangles" } + local P = L.points + for i = 0, vc - 1 do + local o = i * pstride + P[i * 3 + 1] = buffer.readf32(vd, o) + P[i * 3 + 2] = buffer.readf32(vd, o + 4) + P[i * 3 + 3] = if is2D then 0 else buffer.readf32(vd, o + 8) + end + if ntStride > 0 then + local base = vc * pstride + local N, T = if hasN then arr(vc * 3) else nil, if hasT then arr(vc * 4) else nil + for i = 0, vc - 1 do + local o = base + i * ntStride + if N then + local x, y, z = octDecode(buffer.readu16(vd, o) / 65535, buffer.readu16(vd, o + 2) / 65535) + N[i * 3 + 1], N[i * 3 + 2], N[i * 3 + 3] = x, y, z + o += 4 + end + if T then + local tx = buffer.readu16(vd, o) / 65535 + local ty = buffer.readu16(vd, o + 2) / 65535 * 2 - 1 + local sign = if ty >= 0 then 1 else -1 + local x, y, z = octDecode(tx, math.abs(ty)) + T[i * 4 + 1], T[i * 4 + 2], T[i * 4 + 3], T[i * 4 + 4] = x, y, z, sign + end + end + L.normals, L.tangents = N, T + end + -- attribute stream + local hasC, hasUV, hasUV2 = bit(f, 3), bit(f, 4), bit(f, 5) + local astride = (if hasC then 4 else 0) + (if hasUV then 8 else 0) + (if hasUV2 then 8 else 0) + for k = 0, 3 do + if bit(f, 6 + k) then + astride += CUSTOM_SIZE[math.floor(f / 2 ^ (13 + 3 * k)) % 8] + end + end + if astride > 0 then + local ad = GodotVariant.bytes(d.attribute_data) + if not ad or buffer.len(ad) < vc * astride then + return nil, "truncated attribute_data" + end + local C = if hasC then buffer.create(vc * 4) else nil + local UV, UV2 = if hasUV then arr(vc * 2) else nil, if hasUV2 then arr(vc * 2) else nil + for i = 0, vc - 1 do + local o = i * astride + if C then + buffer.writeu32(C, i * 4, buffer.readu32(ad, o)) + o += 4 + end + if UV then + UV[i * 2 + 1], UV[i * 2 + 2] = buffer.readf32(ad, o), buffer.readf32(ad, o + 4) + o += 8 + end + if UV2 then + UV2[i * 2 + 1], UV2[i * 2 + 2] = buffer.readf32(ad, o), buffer.readf32(ad, o + 4) + end + end + L.colors, L.uvs, L.uv2s = C, UV, UV2 + end + -- skin stream: bones then weights per vertex + local hasB, hasW = bit(f, 10), bit(f, 11) + if hasB and hasW then + local per = if bit(f, 27) then 8 else 4 + local sd = GodotVariant.bytes(d.skin_data) + if sd and buffer.len(sd) >= vc * per * 4 then + local J, W = arr(vc * per), arr(vc * per) + for i = 0, vc - 1 do + local o = i * per * 4 + for c = 0, per - 1 do + J[i * per + c + 1] = buffer.readu16(sd, o + c * 2) + W[i * per + c + 1] = buffer.readu16(sd, o + per * 2 + c * 2) / 65535 + end + end + L.joints, L.weights, L.jointsPer = J, W, per + end + end + local ic = tonumber(d.index_count) or 0 + if bit(f, 12) and ic > 0 then + local id = GodotVariant.bytes(d.index_data) + local size = if vc <= 65536 then 2 else 4 + if not id or buffer.len(id) < ic * size then + return nil, "truncated index_data" + end + local I = arr(ic) + for i = 0, ic - 1 do + local v = if size == 2 then buffer.readu16(id, i * 2) else buffer.readu32(id, i * 4) + if v >= vc then + return nil, "index out of range" + end + I[i + 1] = v + end + L.indices = I + end + local prim = tonumber(d.primitive) or 3 + L.mode = if prim == 0 then "points" elseif prim == 1 then "lines" elseif prim == 2 then "line_strip" elseif prim == 4 then "triangle_strip" else "triangles" + return L, nil +end + +local function nums(v: any): { number }? + return GodotVariant.numbers(v) +end + +-- a format-2 "arrays" surface (Godot 3 Mesh::ArrayType: vertex, normal, tangent, color, uv, uv2, bones, weights, index) +local function arrays(d: any, maxVertices: number): (Lists?, string?) + local a = d.arrays + local P = nums(a[1]) + if not P or #P % 3 ~= 0 then + return nil, "surface without a vertex array" + end + local vc = #P // 3 + if vc > maxVertices then + return nil, "limit: vertex count " .. vc + end + local L: Lists = { points = P, jointsPer = 4, mode = "triangles" } + local N, T = nums(a[2]), nums(a[3]) + L.normals = if N and #N == vc * 3 then N else nil + L.tangents = if T and #T == vc * 4 then T else nil + local C = nums(a[4]) + if C and #C == vc * 4 then + local cb = buffer.create(vc * 4) + for i = 1, #C do + buffer.writeu8(cb, i - 1, math.clamp(math.floor(C[i] * 255 + 0.5), 0, 255)) + end + L.colors = cb + end + local UV, UV2 = nums(a[5]), nums(a[6]) + L.uvs = if UV and #UV == vc * 2 then UV else nil + L.uv2s = if UV2 and #UV2 == vc * 2 then UV2 else nil + local B, W = nums(a[7]), nums(a[8]) + if B and W and #B == vc * 4 and #W == vc * 4 then + L.joints, L.weights = B, W + end + local I = nums(a[9]) + if I and #I > 0 then + for _, v in I do + if v < 0 or v >= vc then + return nil, "index out of range" + end + end + L.indices = I + end + local prim = tonumber(d.primitive) or 4 + L.mode = if prim == 0 then "points" elseif prim == 1 then "lines" elseif prim == 2 then "line_strip" elseif prim == 3 then "line_loop" elseif prim == 5 then "triangle_strip" elseif prim == 6 then "triangle_fan" else "triangles" + return L, nil +end + +function Surface.lists(d: any, maxVertices: number): (Lists?, string?) + if type(d) ~= "table" then + return nil, "bad surface" + end + if type(d.arrays) == "table" then + return arrays(d, maxVertices) + end + if d.array_data ~= nil then + return nil, "unsupported: Godot 3 binary surface (array_data)" + end + return binary(d, maxVertices) +end + +function Surface.fromPrimitiveArrays(a: Primitives.Arrays): Lists + return { points = a.points, normals = a.normals, tangents = a.tangents, uvs = a.uvs, indices = a.indices, jointsPer = 4, mode = "triangles" } +end + +local function acc(list: { number }, comps: number, t: string?): Types.Accessor + local count = #list // comps + local typ = t or "f32" + local a = S.accessor(nil, typ :: any, comps, count) + local d = a.data + for i, v in list do + if typ == "f32" then + buffer.writef32(d, (i - 1) * 4, v) + elseif typ == "u16" then + buffer.writeu16(d, (i - 1) * 2, v) + end + end + return a +end + +-- lists into a Primitive; triangles (and strips / fans, made into triangles) get counter-clockwise winding +function Surface.primitive(L: Lists): Types.Primitive + local n = #L.points // 3 + local attrs: { [string]: Types.Accessor } = { POSITION = acc(L.points, 3) } + if L.normals then + attrs.NORMAL = acc(L.normals :: { number }, 3) + end + if L.tangents then + attrs.TANGENT = acc(L.tangents :: { number }, 4) + end + if L.colors then + attrs.COLOR_0 = S.accessor(L.colors, "unorm8", 4, n) + end + if L.uvs then + attrs.TEXCOORD_0 = acc(L.uvs :: { number }, 2) + end + if L.uv2s then + attrs.TEXCOORD_1 = acc(L.uv2s :: { number }, 2) + end + if L.joints and L.weights then + local per = L.jointsPer + for set = 0, per // 4 - 1 do + local J, W = arr(n * 4), arr(n * 4) + for i = 0, n - 1 do + for c = 0, 3 do + J[i * 4 + c + 1] = (L.joints :: { number })[i * per + set * 4 + c + 1] or 0 + W[i * 4 + c + 1] = (L.weights :: { number })[i * per + set * 4 + c + 1] or 0 + end + end + attrs["JOINTS_" .. set] = acc(J, 4, "u16") + attrs["WEIGHTS_" .. set] = acc(W, 4) + end + end + local mode = L.mode + local idx = L.indices + if mode == "triangles" or mode == "triangle_strip" or mode == "triangle_fan" then + local src: { number } + if idx then + src = idx + else + src = arr(n) + for i = 1, n do + src[i] = i - 1 + end + end + local out: { number } = {} + if mode == "triangles" then + for k = 1, #src - 2, 3 do + table.insert(out, src[k]) + table.insert(out, src[k + 2]) + table.insert(out, src[k + 1]) + end + elseif mode == "triangle_strip" then + for k = 1, #src - 2 do + local a, b, c = src[k], src[k + 1], src[k + 2] + if k % 2 == 0 then + a, b = b, a + end + table.insert(out, a) + table.insert(out, c) + table.insert(out, b) + end + else + for k = 2, #src - 1 do + table.insert(out, src[1]) + table.insert(out, src[k + 1]) + table.insert(out, src[k]) + end + end + idx = out + mode = "triangles" + end + local prim: Types.Primitive = { attributes = attrs, mode = mode :: any } + if idx then + prim.indices = acc(idx :: { number }, 1, "u32") + local d = (prim.indices :: Types.Accessor).data + for i, v in idx :: { number } do + buffer.writeu32(d, (i - 1) * 4, v) + end + end + return prim +end + +-- ------------------------------------------------------------------------------------------------ write +local function perpendicular(x: number, y: number, z: number): (number, number, number) + local ax, ay, az = if math.abs(y) < 0.9 then 0 else 1, if math.abs(y) < 0.9 then 1 else 0, 0 + local tx, ty, tz = ay * z - az * y, az * x - ax * z, ax * y - ay * x + local l = math.sqrt(tx * tx + ty * ty + tz * tz) + if l == 0 then + return 1, 0, 0 + end + return tx / l, ty / l, tz / l +end + +-- a triangle Primitive as a Godot 4 surface dictionary (format version 2, uncompressed); nil for other modes +function Surface.encode(prim: Types.Primitive, triangles: { number }): any + local a = prim.attributes + local pos = a.POSITION + local rp = S.reader(pos) + if not rp then + return nil + end + local vc = pos.count + local an: any, at: any, ac: any, a0: any, a1: any = a.NORMAL, a.TANGENT, a.COLOR_0, a.TEXCOORD_0, a.TEXCOORD_1 + local rn = if an then S.reader(an) else nil + local rt = if at then S.reader(at) else nil + local rc = if ac then S.reader(ac) else nil + local cc = if ac then ac.components else 0 + local ru = if a0 then S.reader(a0) else nil + local ru2 = if a1 then S.reader(a1) else nil + local flags = 1 + 2 ^ 35 + if rn then + flags += 2 + 4 + end + local ntStride = if rn then 8 else 0 + local vd = buffer.create(vc * (12 + ntStride)) + local lo, hi = { math.huge, math.huge, math.huge }, { -math.huge, -math.huge, -math.huge } + for i = 0, vc - 1 do + for c = 0, 2 do + local v = rp(i, c) + buffer.writef32(vd, i * 12 + c * 4, v) + lo[c + 1], hi[c + 1] = math.min(lo[c + 1], v), math.max(hi[c + 1], v) + end + if rn then + local nx, ny, nz = rn(i, 0), rn(i, 1), rn(i, 2) + local o = vc * 12 + i * 8 + local ox, oy = octEncode(nx, ny, nz) + buffer.writeu16(vd, o, u16(ox)) + buffer.writeu16(vd, o + 2, u16(oy)) + local tx, ty, tz, sign + if rt then + tx, ty, tz, sign = rt(i, 0), rt(i, 1), rt(i, 2), if at.components >= 4 then rt(i, 3) else 1 + else + tx, ty, tz = perpendicular(nx, ny, nz) + sign = 1 + end + -- Vector3::octahedron_tangent_encode + local qx, qy = octEncode(tx, ty, tz) + qy = math.max(qy, 1 / 32767) * 0.5 + 0.5 + qy = if sign >= 0 then qy else 1 - qy + buffer.writeu16(vd, o + 4, u16(qx)) + buffer.writeu16(vd, o + 6, u16(qy)) + end + end + local astride = (if rc then 4 else 0) + (if ru then 8 else 0) + (if ru2 then 8 else 0) + local ad: buffer? = nil + if astride > 0 then + flags += (if rc then 8 else 0) + (if ru then 16 else 0) + (if ru2 then 32 else 0) + local b = buffer.create(vc * astride) + for i = 0, vc - 1 do + local o = i * astride + if rc then + for c = 0, 3 do + local v = if c < cc then rc(i, c) else 1 + buffer.writeu8(b, o + c, math.clamp(math.floor(v * 255 + 0.5), 0, 255)) + end + o += 4 + end + if ru then + buffer.writef32(b, o, ru(i, 0)) + buffer.writef32(b, o + 4, ru(i, 1)) + o += 8 + end + if ru2 then + buffer.writef32(b, o, ru2(i, 0)) + buffer.writef32(b, o + 4, ru2(i, 1)) + end + end + ad = b + end + local isize = if vc <= 65536 then 2 else 4 + local id = buffer.create(#triangles * isize) + -- counter-clockwise -> Godot's clockwise + for k = 0, #triangles // 3 - 1 do + local t = { triangles[k * 3 + 1], triangles[k * 3 + 3], triangles[k * 3 + 2] } + for c = 0, 2 do + if isize == 2 then + buffer.writeu16(id, (k * 3 + c) * 2, t[c + 1]) + else + buffer.writeu32(id, (k * 3 + c) * 4, t[c + 1]) + end + end + end + flags += 4096 + if vc == 0 then + lo, hi = { 0, 0, 0 }, { 0, 0, 0 } + end + local keys = { "aabb" } + local out: { [string]: any } = { aabb = GodotVariant.ctor("AABB", { lo[1], lo[2], lo[3], hi[1] - lo[1], hi[2] - lo[2], hi[3] - lo[3] }) } + if ad then + out.attribute_data = ad + table.insert(keys, "attribute_data") + end + out.format = flags + out.index_count = #triangles + out.index_data = id + out.primitive = 3 + out.uv_scale = GodotVariant.ctor("Vector4", { 0, 0, 0, 0 }) + out.vertex_count = vc + out.vertex_data = vd + for _, k in { "format", "index_count", "index_data", "material", "primitive", "uv_scale", "vertex_count", "vertex_data" } do + table.insert(keys, k) + end + return Types.object(out, keys) +end + +return Surface +end +__FILES["model/godot/Write"] = function() + +-- model/godot/Write: a Scene as a Godot 4 text scene (format 3): Node3D / MeshInstance3D / Camera3D / light nodes +-- with Transform3D transforms, ArrayMesh sub-resources (model/godot/Surface), StandardMaterial3D (linear colours back +-- to sRGB) and Texture2D ext_resources for textures with a uri. Several scene roots go under a "Root" Node3D. +local Types = __include("Types") +local GodotVariant = __include("codecs/text/GodotVariant") +local Surface = __include("model/godot/Surface") + +local Write = {} + +local S = Types.Scene +local ctor = GodotVariant.ctor + +type Section = GodotVariant.Section + +local function section(tag: string, attrs: { any }): Section + local a, order = {}, {} + local i = 1 + while attrs[i] ~= nil do + if attrs[i + 1] ~= nil then + a[attrs[i]] = attrs[i + 1] + table.insert(order, attrs[i]) + end + i += 2 + end + return { tag = tag, attrs = a, attrOrder = order, props = {}, order = {} } +end + +local function prop(sec: Section, k: string, v: any) + if v == nil then + return + end + if sec.props[k] == nil then + table.insert(sec.order, k) + end + sec.props[k] = v +end + +local function toSrgb(c: number): number + c = math.clamp(c, 0, 1) + if c <= 0.0031308 then + return c * 12.92 + end + return 1.055 * c ^ (1 / 2.4) - 0.055 +end + +local function srgbColor(c: { number }?, alpha: number?): any + local v = c or { 1, 1, 1 } + return ctor("Color", { toSrgb(v[1] or 1), toSrgb(v[2] or 1), toSrgb(v[3] or 1), alpha or v[4] or 1 }) +end + +local function transform(m: { number }): any + return ctor("Transform3D", { m[1], m[5], m[9], m[2], m[6], m[10], m[3], m[7], m[11], m[13], m[14], m[15] }) +end + +local function isIdentity(m: { number }): boolean + for i = 1, 16 do + if math.abs(m[i] - S.IDENTITY[i]) > 1e-12 then + return false + end + end + return true +end + +local function safeName(s: string?, fallback: string): string + local n = string.gsub(s or "", "[%.:@/\"%%]", "_") + return if n == "" then fallback else n +end + +local function triangles(prim: any): { number }? + local mode = prim.mode or "triangles" + local pos = prim.attributes and prim.attributes.POSITION + if type(pos) ~= "table" then + return nil + end + local idx: { number } = {} + if prim.indices then + local rd = S.reader(prim.indices) + if not rd then + return nil + end + for i = 0, prim.indices.count - 1 do + idx[i + 1] = rd(i, 0) + end + else + for i = 0, pos.count - 1 do + idx[i + 1] = i + end + end + local out: { number } = {} + if mode == "triangles" then + for k = 1, #idx - 2, 3 do + table.insert(out, idx[k]) + table.insert(out, idx[k + 1]) + table.insert(out, idx[k + 2]) + end + elseif mode == "triangle_strip" then + for k = 1, #idx - 2 do + local a, b = idx[k], idx[k + 1] + if k % 2 == 0 then + a, b = b, a + end + table.insert(out, a) + table.insert(out, b) + table.insert(out, idx[k + 2]) + end + elseif mode == "triangle_fan" then + for k = 2, #idx - 1 do + table.insert(out, idx[1]) + table.insert(out, idx[k]) + table.insert(out, idx[k + 1]) + end + elseif mode == "polygons" and prim.faces then + local rd = S.reader(prim.faces) + local at = 1 + if rd then + for f = 0, prim.faces.count - 1 do + local size = rd(f, 0) + for k = 1, size - 2 do + table.insert(out, idx[at]) + table.insert(out, idx[at + k]) + table.insert(out, idx[at + k + 1]) + end + at += size + end + end + else + return nil + end + for _, v in out do + if v < 0 or v >= pos.count then + return nil + end + end + return out +end + +function Write.document(scene: any): (GodotVariant.Document?, string?) + local sections: { Section } = {} + local ext: { Section } = {} + local sub: { Section } = {} + local nodes: { Section } = {} + local texId: { [number]: string } = {} + local matId: { [number]: string } = {} + local meshId: { [number]: string } = {} + local textures = scene.textures or {} + local function textureRef(ref: any): any + if type(ref) ~= "table" then + return nil + end + local i = ref.texture + local tex = textures[i] + if not tex or type(tex.uri) ~= "string" or tex.uri == "" or string.sub(tex.uri, 1, 5) == "data:" then + return nil + end + if not texId[i] then + local id = (#ext + 1) .. "_tex" + texId[i] = id + local p = if string.find(tex.uri, "^res://") then tex.uri else "res://" .. tex.uri + table.insert(ext, section("ext_resource", { "type", "Texture2D", "path", p, "id", id })) + end + return ctor("ExtResource", { texId[i] }) + end + for i, m in scene.materials or {} do + local id = "StandardMaterial3D_" .. i + matId[i] = id + local sec = section("sub_resource", { "type", "StandardMaterial3D", "id", id }) + if type(m.name) == "string" then + prop(sec, "resource_name", m.name) + end + local mode = m.alphaMode + if mode == "blend" then + prop(sec, "transparency", 1) + elseif mode == "mask" then + prop(sec, "transparency", 2) + prop(sec, "alpha_scissor_threshold", m.alphaCutoff or 0.5) + end + if m.doubleSided then + prop(sec, "cull_mode", 2) + end + local unlit = type(m.extensions) == "table" and m.extensions.KHR_materials_unlit ~= nil + if unlit then + prop(sec, "shading_mode", 0) + end + local bc = if type(m.baseColor) == "table" then m.baseColor else { 1, 1, 1, 1 } + prop(sec, "albedo_color", srgbColor(bc, bc[4] or 1)) + prop(sec, "albedo_texture", textureRef(m.baseColorTexture)) + prop(sec, "metallic", m.metallic or 0) + prop(sec, "roughness", m.roughness or 1) + local mr = textureRef(m.metallicRoughnessTexture) + if mr then + prop(sec, "metallic_texture", mr) + prop(sec, "metallic_texture_channel", 2) + prop(sec, "roughness_texture", mr) + prop(sec, "roughness_texture_channel", 1) + end + local e = m.emissive + if type(e) == "table" and ((e[1] or 0) > 0 or (e[2] or 0) > 0 or (e[3] or 0) > 0) or m.emissiveTexture then + prop(sec, "emission_enabled", true) + prop(sec, "emission", srgbColor(e, 1)) + local strength = type(m.extensions) == "table" and m.extensions.KHR_materials_emissive_strength + if type(strength) == "table" and type(strength.emissiveStrength) == "number" then + prop(sec, "emission_energy_multiplier", strength.emissiveStrength) + end + prop(sec, "emission_texture", textureRef(m.emissiveTexture)) + end + local nt = textureRef(m.normalTexture) + if nt then + prop(sec, "normal_enabled", true) + prop(sec, "normal_texture", nt) + end + local ao = textureRef(m.occlusionTexture) + if ao then + prop(sec, "ao_enabled", true) + prop(sec, "ao_texture", ao) + end + table.insert(sub, sec) + end + for i, mesh in scene.meshes or {} do + local surfaces = {} + for _, prim in mesh.primitives or {} do + local tris = triangles(prim) + if tris then + local sd = Surface.encode(prim, tris) + if sd then + if prim.material and matId[prim.material] then + Types.set(sd, "material", ctor("SubResource", { matId[prim.material] })) + end + table.insert(surfaces, sd) + end + end + end + if #surfaces > 0 then + local id = "ArrayMesh_" .. i + meshId[i] = id + local sec = section("sub_resource", { "type", "ArrayMesh", "id", id }) + if type(mesh.name) == "string" then + prop(sec, "resource_name", mesh.name) + end + prop(sec, "_surfaces", surfaces) + table.insert(sub, sec) + end + end + local all = scene.nodes or {} + local roots = scene.roots or {} + local single = #roots == 1 and all[roots[1]] ~= nil + local visited: { [number]: boolean } = {} + local function emit(i: number, parent: string?, used: { [string]: boolean }, depth: number) + local node = all[i] + if not node or visited[i] or depth > 512 then + return + end + visited[i] = true + local base = safeName(node.name, "Node" .. i) + local name, k = base, 1 + while used[name] do + k += 1 + name = base .. k + end + used[name] = true + local cam = if node.camera then (scene.cameras or {})[node.camera] else nil + local li = if node.light then (scene.lights or {})[node.light] else nil + local typ = if node.mesh and meshId[node.mesh] then "MeshInstance3D" + elseif cam then "Camera3D" + elseif li then (if li.type == "spot" then "SpotLight3D" elseif li.type == "directional" then "DirectionalLight3D" else "OmniLight3D") + else "Node3D" + local sec = section("node", { "name", name, "type", typ, "parent", parent }) + local m = S.nodeMatrix(node) + if not isIdentity(m) then + prop(sec, "transform", transform(m)) + end + if typ == "MeshInstance3D" then + prop(sec, "mesh", ctor("SubResource", { meshId[node.mesh] })) + elseif typ == "Camera3D" then + if cam.type == "orthographic" then + prop(sec, "projection", 1) + prop(sec, "size", (cam.ymag or 0.5) * 2) + else + prop(sec, "fov", math.deg(cam.yfov or math.rad(75))) + end + prop(sec, "near", cam.znear or 0.05) + prop(sec, "far", cam.zfar or 4000) + elseif li then + prop(sec, "light_color", srgbColor(li.color, 1)) + prop(sec, "light_energy", li.intensity or 1) + if li.type == "point" then + prop(sec, "omni_range", li.range or 5) + elseif li.type == "spot" then + prop(sec, "spot_range", li.range or 5) + prop(sec, "spot_angle", math.deg(li.outerCone or math.pi / 4)) + end + end + local g = type(node.extras) == "table" and node.extras.godot + if type(g) == "table" and g.visible == false then + prop(sec, "visible", false) + end + table.insert(nodes, sec) + local path = if parent == nil then "." elseif parent == "." then name else parent .. "/" .. name + local childUsed = {} + for _, c in node.children or {} do + emit(c, path, childUsed, depth + 1) + end + end + if single then + emit(roots[1], nil, {}, 0) + else + table.insert(nodes, section("node", { "name", "Root", "type", "Node3D" })) + local used = {} + for _, r in roots do + emit(r, ".", used, 1) + end + end + local steps = #ext + #sub + 1 + table.insert(sections, section("gd_scene", { "load_steps", steps, "format", 3 })) + for _, s in ext do + table.insert(sections, s) + end + for _, s in sub do + table.insert(sections, s) + end + for _, s in nodes do + table.insert(sections, s) + end + return { sections = sections }, nil +end + return Write end __FILES["model/iqm"] = function() @@ -173138,6 +175723,673 @@ end return Decode end +__FILES["model/t3d"] = function() + +-- model/t3d: Unreal T3D text (UnrealEd map / brush export: Begin Map / Level / Actor / Brush / PolyList / Polygon, +-- Begin Object components), read only. Supports: brush polygons with texture projection (TextureU / TextureV / +-- Origin / Pan; sizes through opts.textureSize, default 256) as primitives per texture, CSG operation in extras +-- (subtractive brushes face inwards; the builder brush is skipped), actors as nodes with their properties and +-- transforms (UE1-3 Location / Rotation / DrawScale, UE4 RootComponent Relative*), lights, cameras, static mesh +-- references. Not supported: BSP CSG between brushes, sheared brush scales, terrain, static mesh geometry. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local Types = __include("Types") +local Text = __include("codecs/text/Text") +local Parse = __include("model/t3d/Parse") +local Build = __include("model/t3d/Build") + +-- ------------------------------------------------------------------------------------------------ contract +local T3d = { + name = "t3d", + category = "model", + extensions = { "t3d" }, + mime = { "text/x-unreal-t3d" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Text", "codecs/model/Brush" }, + caps = { decode = true, encode = false, text = true, brushes = true, actors = true }, +} + +-- ------------------------------------------------------------------------------------------------ types +type DecodeOptions = { + maxBytes: number?, -- default 2^28 + maxBlocks: number?, -- default 2^22 + maxPolygons: number?, -- default 2^20 + textureSize: ((name: string) -> (number, number))? | { [string]: { number } }?, -- texture width, height (default 256) + builder: boolean?, -- include the builder brush's geometry (default false) +} + +-- ------------------------------------------------------------------------------------------------ sniff +function T3d.sniff(r: Bytes.Reader): number + local h = Sniff.text(r, 512) + local first = string.match(h, "^%s*(Begin%s+%a+)") + if first == nil then + return 0 + end + local kind = string.lower(string.match(first, "%a+$") or "") + if kind == "map" or kind == "actor" or kind == "level" or kind == "brush" or kind == "polylist" then + return 0.9 + end + return 0.3 +end + +-- ------------------------------------------------------------------------------------------------ decode +function T3d.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?) + local o: any = opts or {} + if r.limit - r.base > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local text = buffer.readstring(r.buf, r.base, r.limit - r.base) + if string.sub(text, 1, 2) == "\255\254" then + text = Text.utf16(r.buf, r.base + 2, r.limit - r.base - 2, false) + else + text = Text.toUtf8(text) + end + local ok, root, msg = pcall(Parse.tree, text, o.maxBlocks or 2 ^ 22) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad data: " .. tostring(root)) + end + if not root then + return nil, Err.from(msg) + end + if #root.children == 0 then + return nil, Err.new(Err.CORRUPT, "no Begin blocks") + end + -- a bare brush export (Begin PolyList / Begin Brush): wrap it in an actor + local k = string.lower(root.children[1].kind) + if k == "polylist" or k == "brush" then + local function block(kind: string, attrs: any, props: any, children: any): Parse.Block + return { kind = kind, attrs = attrs, props = props, order = { "CsgOper" }, records = {}, degrees = {}, children = children } + end + local brush = if k == "brush" then root.children else { block("Brush", { Name = "Brush0" }, {}, root.children) } + root = block("", {}, {}, { block("Actor", { Class = "Brush", Name = "Brush0" }, { CsgOper = "CSG_Add" }, brush) }) + end + local ok2, scene, msg2 = pcall(Build.scene, root, o) + if not ok2 then + return nil, Err.from(tostring(scene)) + end + if not scene then + return nil, Err.from(msg2) + end + return scene, nil +end + +return T3d +end +__FILES["model/t3d/Build"] = function() + +-- model/t3d/Build: parsed T3D blocks into a Scene: one node per actor (Unreal's own Z-up, left-handed coordinates, +-- kept as they are), brush polygons as primitives per texture (codecs/model/Brush). Brush transform as UnrealEd's +-- ABrush coords: v - PrePivot, MainScale, Rotation, PostScale, + Location. Rotation as FRotationMatrix (Pitch / Yaw / +-- Roll: 65536 units per turn, or degrees in UE4 text). Polygon winding follows the stored Normal; subtractive +-- brushes face inwards. +local Types = __include("Types") +local Brush = __include("codecs/model/Brush") +local Parse = __include("model/t3d/Parse") + +type Block = Parse.Block + +local Build = {} + +local S = Types.Scene + +local function num(v: any, d: number): number + return if type(v) == "number" and v == v then v else d +end + +local function vec3(s: string?): { number }? + if type(s) ~= "string" then + return nil + end + local a, b, c = string.match(s, "^%s*([^,%s]+)%s*,%s*([^,%s]+)%s*,%s*([^,%s]+)") + if not a then + return nil + end + local x, y, z = tonumber((string.gsub(a, "^%+", ""))), tonumber((string.gsub(b :: string, "^%+", ""))), tonumber((string.gsub(c :: string, "^%+", ""))) + if x and y and z then + return { x, y, z } + end + return nil +end + +local function xyz(v: any, d: { number }): { number } + if type(v) == "table" then + return { num(v.X, d[1]), num(v.Y, d[2]), num(v.Z, d[3]) } + end + return d +end + +-- FRotationMatrix rows are the X / Y / Z axes: the columns of a column-major matrix +local function rotation(r: any, degrees: boolean): { number } + if type(r) ~= "table" then + return S.IDENTITY + end + local k = if degrees then math.pi / 180 else math.pi * 2 / 65536 + local p, y, ro = num(r.Pitch, 0) * k, num(r.Yaw, 0) * k, num(r.Roll, 0) * k + local SP, CP, SY, CY, SR, CR = math.sin(p), math.cos(p), math.sin(y), math.cos(y), math.sin(ro), math.cos(ro) + return { + CP * CY, CP * SY, SP, 0, + SR * SP * CY - CR * SY, SR * SP * SY + CR * CY, -SR * CP, 0, + -(CR * SP * CY + SR * SY), CY * SR - CR * SP * SY, CR * CP, 0, + 0, 0, 0, 1, + } +end + +local function scaling(s: { number }): { number } + return { s[1], 0, 0, 0, 0, s[2], 0, 0, 0, 0, s[3], 0, 0, 0, 0, 1 } +end + +local function translation(t: { number }): { number } + return { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, t[1], t[2], t[3], 1 } +end + +local function plain(b: Block): { [string]: any } + local out: { [string]: any } = {} + for _, k in b.order do + out[k] = b.props[k] + end + return out +end + +-- the component holding the actor's transform (UE4: RootComponent's Relative* properties) +local function component(actor: Block, objects: { [string]: { [string]: any } }): { [string]: any }? + local root = actor.props.RootComponent + if type(root) == "string" then + local name = string.match(root, "'\"?([^'\"]+)\"?'") or root + name = string.match(name, "([^%.:]+)$") or name + if objects[name] then + return objects[name] + end + end + for _, o in objects do + if o.RelativeLocation ~= nil or o.RelativeRotation ~= nil or o.RelativeScale3D ~= nil then + return o + end + end + return nil +end + +local function polygons(b: Block, out: { Block }) + for _, c in b.children do + local k = string.lower(c.kind) + if k == "polygon" then + table.insert(out, c) + elseif k == "polylist" or k == "brush" then + polygons(c, out) + end + end +end + +type Ctx = { scene: Types.Scene, materials: { [string]: number }, opts: any, polys: number } + +local function material(ctx: Ctx, name: string): number + local m = ctx.materials[name] + if m then + return m + end + local mat = S.material(if name ~= "" then name else nil) + mat.metallic = 0 + if name ~= "" then + table.insert(ctx.scene.textures, { name = name }) + mat.baseColorTexture = { texture = #ctx.scene.textures } + end + mat.extras = { t3d = { texture = name } } + table.insert(ctx.scene.materials, mat) + ctx.materials[name] = #ctx.scene.materials + return #ctx.scene.materials +end + +-- the brush's polygons as Scene primitives (local brush space) +local function brushMesh(ctx: Ctx, brush: Block, subtract: boolean): (Types.Mesh?, string?) + local list: { Block } = {} + polygons(brush, list) + if #list == 0 then + return nil, nil + end + local faces: { Brush.Face } = {} + local polys: { Brush.Polygon } = {} + local flags: { number } = {} + for _, pb in list do + local rec: { [string]: string } = {} + local verts: { number } = {} + for _, r in pb.records do + local name = string.lower(r[1]) + if name == "vertex" then + local v = vec3(r[2]) + if v then + table.insert(verts, v[1]) + table.insert(verts, v[2]) + table.insert(verts, v[3]) + end + elseif rec[name] == nil then + rec[name] = r[2] + end + end + local nv = #verts // 3 + if nv >= 3 then + ctx.polys += 1 + if ctx.polys > (ctx.opts.maxPolygons or 2 ^ 20) then + return nil, "limit: over " .. (ctx.opts.maxPolygons or 2 ^ 20) .. " polygons" + end + -- Newell normal of the vertex order + local nx, ny, nz = 0, 0, 0 + for k = 0, nv - 1 do + local j = (k + 1) % nv + local ax, ay, az = verts[k * 3 + 1], verts[k * 3 + 2], verts[k * 3 + 3] + local bx, by, bz = verts[j * 3 + 1], verts[j * 3 + 2], verts[j * 3 + 3] + nx += (ay - by) * (az + bz) + ny += (az - bz) * (ax + bx) + nz += (ax - bx) * (ay + by) + end + local stated = vec3(rec.normal) + local n = stated or { nx, ny, nz } + local l = math.sqrt(n[1] * n[1] + n[2] * n[2] + n[3] * n[3]) + if l > 0 then + n = { n[1] / l, n[2] / l, n[3] / l } + end + local reverse = nx * n[1] + ny * n[2] + nz * n[3] < 0 + if subtract then + reverse = not reverse + n = { -n[1], -n[2], -n[3] } + end + if reverse then + local r: { number } = {} + for k = nv - 1, 0, -1 do + table.insert(r, verts[k * 3 + 1]) + table.insert(r, verts[k * 3 + 2]) + table.insert(r, verts[k * 3 + 3]) + end + verts = r + end + local tex = if type(pb.attrs.Texture) == "string" then pb.attrs.Texture else (if pb.attrs.Texture ~= nil then tostring(pb.attrs.Texture) else "") + local o = vec3(rec.origin) or { 0, 0, 0 } + local u = vec3(rec.textureu) or { 1, 0, 0 } + local v = vec3(rec.texturev) or { 0, 1, 0 } + local panU, panV = 0, 0 + if rec.pan then + panU = tonumber(string.match(rec.pan, "U=%s*([-+]?[%d%.]+)")) or 0 + panV = tonumber(string.match(rec.pan, "V=%s*([-+]?[%d%.]+)")) or 0 + end + -- texel = (p - Origin) . TextureU + PanU + local face: Brush.Face = { + plane = { n[1], n[2], n[3], n[1] * o[1] + n[2] * o[2] + n[3] * o[3] }, + texture = tex, + vecs = { + { u[1], u[2], u[3], panU - (o[1] * u[1] + o[2] * u[2] + o[3] * u[3]) }, + { v[1], v[2], v[3], panV - (o[1] * v[1] + o[2] * v[2] + o[3] * v[3]) }, + }, + } + table.insert(faces, face) + table.insert(polys, { brush = 1, face = #faces, points = verts, normal = n }) + table.insert(flags, num(pb.attrs.Flags, 0)) + end + end + local size = ctx.opts.textureSize + local built = Brush.primitives(polys, { faces }, function(name: string): (number, number) + if type(size) == "function" then + local ok, w, h = pcall(size, name) + if ok and type(w) == "number" then + return w, if type(h) == "number" then h else w + end + elseif type(size) == "table" and type(size[name]) == "table" then + return num(size[name][1], 256), num(size[name][2], 256) + end + return 256, 256 + end) + local mesh: Types.Mesh = { name = if type(brush.attrs.Name) == "string" then brush.attrs.Name else nil, primitives = {} } + for _, b in built do + b.primitive.material = material(ctx, b.texture) + table.insert(mesh.primitives, b.primitive) + end + mesh.extras = { t3d = { polygons = #polys } } + return mesh, nil +end + +local LIGHTS: { [string]: "point" | "spot" | "directional" } = { + Light = "point", PointLight = "point", SpotLight = "spot", DirectionalLight = "directional", TriggerLight = "point", + SkyLight = "directional", Spotlight = "spot", SunLight = "directional", DominantDirectionalLight = "directional", + PointLightMovable = "point", SpotLightMovable = "spot", DirectionalLightMovable = "directional", +} + +-- HSV of UE1 lights: LightHue / LightSaturation (255 = white) / LightBrightness, all 0..255 +local function hsv(h: number, s: number): { number } + local hh = (h % 256) / 256 * 6 + local i = math.floor(hh) + local f = hh - i + local p, q, t = 1 - s, 1 - s * f, 1 - s * (1 - f) + local rgb = ({ { 1, t, p }, { q, 1, p }, { p, 1, t }, { p, q, 1 }, { t, p, 1 }, { 1, p, q } })[i % 6 + 1] + return rgb +end + +local function light(ctx: Ctx, class: string, p: { [string]: any }, comp: { [string]: any }?): number + local typ = LIGHTS[class] + local l: Types.Light = { type = typ, color = { 1, 1, 1 }, intensity = 1 } + if p.LightBrightness ~= nil or p.LightHue ~= nil or p.LightSaturation ~= nil then + l.color = hsv(num(p.LightHue, 0), 1 - num(p.LightSaturation, 255) / 255) + l.intensity = num(p.LightBrightness, 64) / 255 + end + local c: any = comp or {} + local col = c.LightColor or p.LightColor + if type(col) == "table" then + l.color = { num(col.R, 255) / 255, num(col.G, 255) / 255, num(col.B, 255) / 255 } + end + if c.Intensity ~= nil or c.Brightness ~= nil then + l.intensity = num(c.Intensity, num(c.Brightness, 1)) + end + local radius = c.AttenuationRadius or c.Radius + if type(radius) == "number" then + l.range = radius + end + if typ == "spot" then + l.outerCone = math.rad(num(c.OuterConeAngle, num(p.LightCone, 44))) + l.innerCone = math.rad(num(c.InnerConeAngle, 0)) + end + table.insert(ctx.scene.lights, l) + return #ctx.scene.lights +end + +local function actors(b: Block, out: { Block }) + for _, c in b.children do + local k = string.lower(c.kind) + if k == "actor" then + table.insert(out, c) + elseif k == "map" or k == "level" or k == "surface" then + actors(c, out) + end + end +end + +function Build.scene(root: Block, opts: any): (Types.Scene?, string?) + local sc = S.new() + sc.meta.up = "z" + sc.meta.handedness = "left" + local list: { Block } = {} + actors(root, list) + local ctx: Ctx = { scene = sc, materials = {}, opts = opts or {}, polys = 0 } + local ue4 = false + for _, a in list do + local rawClass = if a.attrs.Class ~= nil then tostring(a.attrs.Class) else "Actor" + local class = string.match(rawClass, "([%w_]+)$") or rawClass + if string.find(rawClass, "/Script/", 1, true) then + ue4 = true + end + local p = a.props + local objects: { [string]: { [string]: any } } = {} + local objectClass: { [string]: string } = {} + for _, c in a.children do + if string.lower(c.kind) == "object" then + local name = if c.attrs.Name ~= nil then tostring(c.attrs.Name) else ("Object" .. #a.children) + local o = objects[name] or {} + for _, k in c.order do + o[k] = c.props[k] + end + objects[name] = o + if c.attrs.Class ~= nil then + objectClass[name] = tostring(c.attrs.Class) + end + end + end + local comp = component(a, objects) + local node: Types.Node = { name = if a.attrs.Name ~= nil then tostring(a.attrs.Name) else class, children = {} } + local m: { number } + if comp and p.Location == nil then + local deg = true + local loc = xyz(comp.RelativeLocation, { 0, 0, 0 }) + local sc3 = xyz(comp.RelativeScale3D, { 1, 1, 1 }) + m = S.mul(translation(loc), S.mul(rotation(comp.RelativeRotation, deg), scaling(sc3))) + else + local loc = xyz(p.Location, { 0, 0, 0 }) + local deg = a.degrees.Rotation == true + local rot = rotation(p.Rotation, deg) + local isBrush = false + for _, c in a.children do + if string.lower(c.kind) == "brush" then + isBrush = true + end + end + if isBrush then + local pre = xyz(p.PrePivot, { 0, 0, 0 }) + local main = xyz(type(p.MainScale) == "table" and p.MainScale.Scale, { 1, 1, 1 }) + local post = xyz(type(p.PostScale) == "table" and p.PostScale.Scale, { 1, 1, 1 }) + m = S.mul(translation(loc), S.mul(scaling(post), S.mul(rot, S.mul(scaling(main), translation({ -pre[1], -pre[2], -pre[3] }))))) + else + local ds = num(p.DrawScale, 1) + local s3 = xyz(p.DrawScale3D, { 1, 1, 1 }) + m = S.mul(translation(loc), S.mul(rot, scaling({ s3[1] * ds, s3[2] * ds, s3[3] * ds }))) + end + end + node.matrix = m + local csg = if type(p.CsgOper) == "string" then p.CsgOper + elseif p.BrushType == "Brush_Subtract" then "CSG_Subtract" + elseif p.BrushType == "Brush_Add" then "CSG_Add" + else nil + local extras: { [string]: any } = { class = rawClass, properties = plain(a), csg = csg } + if next(objects) then + extras.objects = objects + extras.objectClasses = objectClass + end + for _, c in a.children do + if string.lower(c.kind) == "brush" then + local builder = csg == "CSG_Active" or (class == "Brush" and csg == nil and node.name == "Brush") + extras.builder = if builder then true else nil + if not builder or ctx.opts.builder then + local mesh, err = brushMesh(ctx, c, csg == "CSG_Subtract") + if err then + return nil, err + end + if mesh then + table.insert(sc.meshes, mesh) + node.mesh = #sc.meshes + end + end + end + end + if LIGHTS[class] then + local lc: { [string]: any }? = nil + for name, o in objects do + if string.find(objectClass[name] or name, "Light", 1, true) then + lc = o + end + end + node.light = light(ctx, class, p, lc) + elseif class == "CameraActor" or class == "Camera" then + local fov = num(p.FOVAngle, 90) + for _, o in objects do + if o.FieldOfView ~= nil then + fov = num(o.FieldOfView, fov) + end + end + table.insert(sc.cameras, { type = "perspective", yfov = math.rad(fov), znear = 1 } :: any) + node.camera = #sc.cameras + end + local sm = p.StaticMesh + for _, o in objects do + if o.StaticMesh ~= nil then + sm = o.StaticMesh + end + end + if type(sm) == "string" then + extras.staticMesh = string.match(sm, "'\"?([^'\"]+)\"?'") or sm + end + node.extras = { t3d = extras } + table.insert(sc.nodes, node) + table.insert(sc.roots, #sc.nodes) + end + sc.meta.source = { format = "t3d", engine = if ue4 then "ue4" else "ue1-3", actors = #list, polygons = ctx.polys } + return sc, nil +end + +return Build +end +__FILES["model/t3d/Parse"] = function() + +-- model/t3d/Parse: Unreal T3D text into nested blocks. A line `Begin Key=Value ...` opens a block, `End ` +-- closes it; other lines are `Key=Value` properties or, inside polygons, `Origin x,y,z` / `Vertex x,y,z` style +-- records. Values: numbers, quoted strings, structs `(X=1,Y=2)` as tables, object references +-- (`Model'MyLevel.Model1'`) as strings. +local Parse = {} + +type Value = any +type Block = { + kind: string, + attrs: { [string]: Value }, + props: { [string]: Value }, + order: { string }, + records: { { string } }, + children: { Block }, + degrees: { [string]: boolean }, +} + +-- "(X=1.0,Y=2,Z=-3)" / "(Scale=(X=1,Y=1,Z=1),SheerAxis=SHEER_ZX)"; i at '(' +local function struct(s: string, i: number, depth: number): (any, number) + local out: { [any]: any } = {} + local n = #s + i += 1 + while i <= n do + local c = string.sub(s, i, i) + if c == ")" then + return out, i + 1 + elseif c == "," or c == " " or c == "\t" then + i += 1 + else + local k, e = string.match(s, "^([^=,()]+)=()", i) + if not k then + -- an array element without a key: (1,2,3) + local v, ni = Parse.value(s, i, depth + 1) + table.insert(out, v) + i = ni + else + local key = string.gsub(k :: string, "^%s+", "") + local v, ni = Parse.value(s, e :: number, depth + 1) + out[key] = v + i = ni + end + end + end + return out, i +end + +-- a value starting at i, up to the next unbracketed ',' / ')' (inside structs) or the end +function Parse.value(s: string, i: number, depth: number): (any, number) + local n = #s + local c = string.sub(s, i, i) + if c == "(" and depth < 32 then + return struct(s, i, depth) + elseif c == "\"" then + local e = string.find(s, "\"", i + 1, true) or (n + 1) + return string.sub(s, i + 1, e - 1), e + 1 + end + -- a bare token; object references may hold quotes ('...' and "...") + local j = i + local q: string? = nil + while j <= n do + local ch = string.sub(s, j, j) + if q then + if ch == q then + q = nil + end + elseif ch == "'" or ch == "\"" then + q = ch + elseif depth > 0 and (ch == "," or ch == ")") then + break + end + j += 1 + end + local tok = string.match(string.sub(s, i, j - 1), "^%s*(.-)%s*$") :: string + local num = tonumber(tok) + if num ~= nil and string.match(tok, "^[-+]?[%d%.]+[eE]?[-+]?%d*$") then + return num, j + end + return tok, j +end + +-- Key=Value pairs of a Begin line ("Begin Actor Class=Light Name=Light0"); quoted values may hold spaces +local function attrs(rest: string): { [string]: any } + local out: { [string]: any } = {} + local i, n = 1, #rest + while i <= n do + local k, e = string.match(rest, "^%s*([%w_%.]+)=()", i) + if not k then + break + end + local v: string + if string.sub(rest, e :: number, e :: number) == "\"" then + local q = string.find(rest, "\"", (e :: number) + 1, true) or (n + 1) + v = string.sub(rest, (e :: number) + 1, q - 1) + i = q + 1 + else + local stop = string.find(rest, "%s", e :: number) or (n + 1) + v = string.sub(rest, e :: number, stop - 1) + i = stop + end + out[k :: string] = tonumber(v) or v + end + return out +end + +local function block(kind: string, a: { [string]: any }): Block + return { kind = kind, attrs = a, props = {}, order = {}, records = {}, children = {}, degrees = {} } +end + +function Parse.tree(text: string, maxBlocks: number): (Block?, string?) + local root = block("", {}) + local stack: { Block } = { root } + local count = 0 + local lineNo = 0 + for raw in string.gmatch(text, "[^\n]*") do + lineNo += 1 + local line = string.match(raw, "^%s*(.-)%s*$") :: string + if line ~= "" and string.sub(line, 1, 2) ~= "//" then + local cur = stack[#stack] + local word, rest = string.match(line, "^(%a+)%s*(.*)$") + local lw = if word then string.lower(word) else "" + if lw == "begin" then + local kind, after = string.match(rest :: string, "^(%S+)%s*(.*)$") + if not kind then + return nil, "Begin without a kind at line " .. lineNo + end + count += 1 + if count > maxBlocks then + return nil, "limit: over " .. maxBlocks .. " blocks" + end + if #stack > 64 then + return nil, "limit: blocks nested too deep" + end + local b = block(kind :: string, attrs(after :: string)) + table.insert(cur.children, b) + table.insert(stack, b) + elseif lw == "end" and #stack > 1 and (rest == "" or string.lower(string.match(rest :: string, "^(%S+)") or "") == string.lower(cur.kind)) then + table.remove(stack) + else + local k, e = string.match(line, "^([%w_%(%)%[%]%.]+)%s*=()") + if k then + local v = Parse.value(line, e :: number, 0) + if cur.props[k :: string] == nil then + table.insert(cur.order, k :: string) + end + cur.props[k :: string] = v + if string.find(string.sub(line, e :: number), "Pitch=[-+]?%d*%.") or string.find(string.sub(line, e :: number), "Yaw=[-+]?%d*%.") then + cur.degrees[k :: string] = true + end + else + -- a record: Origin / Normal / TextureU / TextureV / Vertex / Pan U=0 V=0 + local name, data = string.match(line, "^(%a+)%s+(.*)$") + if name then + table.insert(cur.records, { name :: string, data :: string }) + end + end + end + end + end + if #stack > 1 then + return nil, "truncated: " .. stack[#stack].kind .. " block not closed" + end + return root, nil +end + +return Parse +end __FILES["model/usda"] = function() -- model/usda: USD ASCII layers (.usda, text .usd) and USDZ packages of them, from the Sdf text format and the UsdGeom / @@ -188688,6 +191940,1960 @@ end return Vtt end +__FILES["vector/ldtk"] = function() + +-- vector/ldtk: LDtk projects (.ldtk JSON, ldtk.io/json, 1.x) as a TileMap, read + write. Supports: IntGrid, +-- AutoLayer, Tiles and Entities layers, tilesets as image paths, typed fields (properties), multi-world projects, +-- external levels (.ldtkl through opts.resolve). Not supported: auto-layer rules are kept, never run; writing +-- external level files (levels are embedded); standalone .ldtkl files. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local Types = __include("Types") +local Json = __include("codecs/text/Json") +local Read = __include("vector/ldtk/Read") +local Write = __include("vector/ldtk/Write") + +-- ------------------------------------------------------------------------------------------------ contract +local Ldtk = { + name = "ldtk", + category = "vector", + extensions = { "ldtk" }, + mime = { "application/x-ldtk+json" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Json" }, + caps = { decode = true, encode = true, levels = true, worlds = true, intGrid = true, entities = true }, +} + +type DecodeOptions = { + maxBytes: number?, -- default 2^28 + maxCells: number?, -- per layer, default 2^26 + resolve: ((string) -> buffer?)?, -- external .ldtkl level files by their relative path +} +type EncodeOptions = { + indent: number?, -- default 2; 0 = compact +} + +-- ------------------------------------------------------------------------------------------------ sniff +function Ldtk.sniff(r: Bytes.Reader): number + local h = Sniff.text(r, 1024) + if not string.match(h, "^%s*{") then + return 0 + end + if string.find(h, "\"fileType\"%s*:%s*\"LDtk Project JSON\"") then + return 1 + end + if string.find(h, "\"jsonVersion\"", 1, true) and string.find(h, "\"worldLayout\"", 1, true) then + return 0.8 + end + return 0 +end + +-- ------------------------------------------------------------------------------------------------ decode +function Ldtk.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.TileMap?, Err.Err?) + local o: any = opts or {} + if r.limit - r.base > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local v, jerr = Json.decode(buffer.readstring(r.buf, r.base, r.limit - r.base), { ordered = true }) + if v == nil then + return nil, jerr + end + local ok, map, msg = pcall(Read.project, v, o) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad project: " .. tostring(map)) + end + if not map then + return nil, Err.from(msg) + end + return map, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +function Ldtk.encode(map: Types.TileMap, opts: EncodeOptions?): (buffer?, Err.Err?) + if type(map) ~= "table" or type(map.layers) ~= "table" or type(map.tilesets) ~= "table" then + return nil, Err.new(Err.ARG, "needs a TileMap value") + end + local ok, v, msg = pcall(Write.project, map, opts) + if not ok then + return nil, Err.new(Err.ARG, "bad map: " .. tostring(v)) + end + if v == nil then + return nil, Err.new(Err.ARG, msg or "bad map") + end + local indent = if opts and opts.indent == 0 then nil else (opts and opts.indent or 2) + local s, jerr = Json.encode(v, { indent = indent }) + if not s then + return nil, jerr + end + return buffer.fromstring(s), nil +end + +return Ldtk +end +__FILES["vector/ldtk/Read"] = function() + +-- vector/ldtk/Read: an LDtk project (JSON, ldtk.io/json 1.5) into a Types.TileMap: one group layer per level (inside +-- one group per world for multi-world projects), the level's layers bottom first. Tile gids are firstGid + the +-- LDtk tile id with the f bits as Tiled's flip flags (bit 0 X -> 0x80000000, bit 1 Y -> 0x40000000). +local Types = __include("Types") +local Json = __include("codecs/text/Json") + +local Read = {} + +local FLIP_X, FLIP_Y = 0x80000000, 0x40000000 + +local function n(v: any, default: number): number + return if type(v) == "number" then v else default +end +local function s(v: any): string? + return if type(v) == "string" then v else nil +end +local NULL = Json.null +local function tab(v: any): boolean + return type(v) == "table" and v ~= NULL +end +local function list(v: any): { any } + return if tab(v) then v else {} +end + +-- every key but the ones listed (the raw part kept for the writer) +local function rest(t: any, skip: { [string]: boolean }): { [string]: any } + local keys = Json.keys(t) + local out: { [string]: any } = {} + local order = {} + for _, k in keys do + if not skip[k] then + out[k] = t[k] + table.insert(order, k) + end + end + return Json.object(out, order) +end + +function Read.fields(v: any): ({ [string]: any }, { [string]: string }?) + local props: { [string]: any } = {} + local types: { [string]: string }? = nil + for _, f in list(v) do + if type(f) == "table" and type(f.__identifier) == "string" then + props[f.__identifier] = f.__value + if type(f.__type) == "string" then + types = types or {} + ;(types :: any)[f.__identifier] = f.__type + end + end + end + return props, types +end + +type Ctx = { tilesets: { [number]: Types.Tileset }, maxCells: number, layerDefs: { [number]: any } } + +local function tiles(ctx: Ctx, raw: { any }, ts: Types.Tileset?, grid: number, cw: number, ch: number): ({ any }, { number }?) + local out = table.create(#raw) + local data: { number }? = nil + if cw > 0 and ch > 0 then + data = table.create(cw * ch, 0) + end + for i, t in raw do + if type(t) == "table" then + local px, src = list(t.px), list(t.src) + local tile = { + x = n(px[1], 0), + y = n(px[2], 0), + tile = n(t.t, 0), + flip = n(t.f, 0), + srcX = n(src[1], 0), + srcY = n(src[2], 0), + alpha = n(t.a, 1), + d = t.d, + } + out[i] = tile + if data and ts then + local cx, cy = tile.x // grid, tile.y // grid + if cx >= 0 and cy >= 0 and cx < cw and cy < ch then + local gid = ts.firstGid + tile.tile + if bit32.btest(tile.flip, 1) then + gid += FLIP_X + end + if bit32.btest(tile.flip, 2) then + gid += FLIP_Y + end + -- later tiles are drawn over earlier ones + data[1 + cx + cy * cw] = gid + end + end + end + end + return out, data +end + +local LAYER_SKIP = { __identifier = true, __type = true, __cWid = true, __cHei = true, __gridSize = true, __opacity = true, __pxTotalOffsetX = true, __pxTotalOffsetY = true, __tilesetDefUid = true, __tilesetRelPath = true, visible = true, intGridCsv = true, autoLayerTiles = true, gridTiles = true, entityInstances = true } +local ENTITY_SKIP = { __identifier = true, __grid = true, __pivot = true, __tags = true, __tile = true, __smartColor = true, __worldX = true, __worldY = true, width = true, height = true, px = true, fieldInstances = true } + +local function layer(ctx: Ctx, li: any): (Types.TileLayer?, string?) + local kind = s(li.__type) or "Tiles" + local cw, ch = n(li.__cWid, 0), n(li.__cHei, 0) + if cw < 0 or ch < 0 or cw * ch > ctx.maxCells then + return nil, "limit: layer of " .. cw .. " x " .. ch .. " cells" + end + local grid = math.max(1, n(li.__gridSize, 16)) + local out: Types.TileLayer = { + name = s(li.__identifier) or "", + type = if kind == "Entities" then "objects" else "tiles", + visible = li.visible ~= false, + opacity = n(li.__opacity, 1), + properties = {}, + offsetX = n(li.__pxTotalOffsetX, 0), + offsetY = n(li.__pxTotalOffsetY, 0), + ldtkType = kind, + gridSize = grid, + ldtk = rest(li, LAYER_SKIP), + } + if kind == "Entities" then + local objs = {} + for _, e in list(li.entityInstances) do + if type(e) == "table" then + local w, h = n(e.width, 0), n(e.height, 0) + local pv, px = list(e.__pivot), list(e.px) + local pX, pY = n(pv[1], 0), n(pv[2], 0) + local props, types = Read.fields(e.fieldInstances) + local o: { [string]: any } = { + id = s(e.iid), + name = s(e.__identifier) or "", + class = s(e.__identifier) or "", + x = n(px[1], 0) - pX * w, + y = n(px[2], 0) - pY * h, + width = w, + height = h, + rotation = 0, + visible = true, + shape = "rectangle", + pivot = { pX, pY }, + tags = e.__tags, + tile = if tab(e.__tile) then e.__tile else nil, + color = s(e.__smartColor), + properties = props, + propertyTypes = types, + ldtk = rest(e, ENTITY_SKIP), + fieldInstances = e.fieldInstances, + } + table.insert(objs, o) + end + end + out.objects = objs + return out, nil + end + out.width, out.height = cw, ch + local tsUid = li.__tilesetDefUid + local ts = if type(tsUid) == "number" then ctx.tilesets[tsUid] else nil + if ts then + out.tileset = ts.name + end + out.tilesetPath = s(li.__tilesetRelPath) + local raw = if kind == "Tiles" then list(li.gridTiles) else list(li.autoLayerTiles) + local tl, data = tiles(ctx, raw, ts, grid, cw, ch) + out.tiles = tl + out.data = data or {} + if kind == "IntGrid" then + local csv = list(li.intGridCsv) + local grid2 = table.create(cw * ch, 0) + for i = 1, math.min(#csv, cw * ch) do + grid2[i] = n(csv[i], 0) + end + out.intGrid = grid2 + local def = if type(li.layerDefUid) == "number" then ctx.layerDefs[li.layerDefUid] else nil + if def then + local values = {} + for _, v in list(def.intGridValues) do + if type(v) == "table" then + table.insert(values, { value = n(v.value, 0), identifier = s(v.identifier), color = s(v.color) }) + end + end + out.intGridValues = values + end + end + return out, nil +end + +local LEVEL_SKIP = { identifier = true, worldX = true, worldY = true, pxWid = true, pxHei = true, __bgColor = true, fieldInstances = true, layerInstances = true } + +local function level(ctx: Ctx, lv: any, resolve: ((string) -> buffer?)?): (Types.TileLayer?, string?) + local layers = lv.layerInstances + local external = s(lv.externalRelPath) + local unresolved = false + if not tab(layers) and external then + local data: any = nil + if resolve then + local ok, b = pcall(resolve, external) + data = if ok and type(b) == "buffer" then b else nil + end + if data then + local v, err = Json.decode(data, { ordered = true }) + if not tab(v) then + return nil, "external level " .. external .. ": " .. tostring(err) + end + lv = v + layers = v.layerInstances + else + unresolved = true + end + end + local props, types = Read.fields(lv.fieldInstances) + local g: Types.TileLayer = { + name = s(lv.identifier) or "", + type = "group", + visible = true, + opacity = 1, + properties = props, + propertyTypes = types, + offsetX = n(lv.worldX, 0), + offsetY = n(lv.worldY, 0), + layers = {}, + level = true, + pxWidth = n(lv.pxWid, 0), + pxHeight = n(lv.pxHei, 0), + backgroundColor = s(lv.__bgColor), + external = external, + unresolved = if unresolved then true else nil, + ldtk = rest(lv, LEVEL_SKIP), + } + local ls = list(layers) + for i = #ls, 1, -1 do + local l, err = layer(ctx, ls[i]) + if not l then + return nil, err + end + table.insert(g.layers :: { any }, l) + end + return g, nil +end + +local PROJECT_SKIP = { levels = true, worlds = true } + +function Read.project(v: any, opts: any): (Types.TileMap?, string?) + if not tab(v) or not tab(v.defs) then + return nil, "no defs: not an LDtk project" + end + local grid = math.max(1, n(v.defaultGridSize, 16)) + local map = Types.TileMap.new(0, 0, grid, grid) + local ctx: Ctx = { tilesets = {}, maxCells = opts.maxCells or 2 ^ 26, layerDefs = {} } + local gid = 1 + for _, t in list(v.defs.tilesets) do + if type(t) == "table" then + local cw, ch = n(t.__cWid, 0), n(t.__cHei, 0) + local size = n(t.tileGridSize, grid) + local ts: Types.Tileset = { + name = s(t.identifier) or ("tileset" .. #map.tilesets), + firstGid = gid, + tileWidth = size, + tileHeight = size, + columns = cw, + count = cw * ch, + imageSource = s(t.relPath), + imageWidth = n(t.pxWid, 0), + imageHeight = n(t.pxHei, 0), + spacing = n(t.spacing, 0), + margin = n(t.padding, 0), + uid = t.uid, + embedAtlas = s(t.embedAtlas), + properties = {}, + } + gid += math.max(1, cw * ch) + table.insert(map.tilesets, ts) + if type(t.uid) == "number" then + ctx.tilesets[t.uid] = ts + end + end + end + for _, d in list(v.defs.layers) do + if type(d) == "table" and type(d.uid) == "number" then + ctx.layerDefs[d.uid] = d + end + end + local resolve = opts.resolve + local worlds = list(v.worlds) + local minX, minY, maxX, maxY = math.huge, math.huge, -math.huge, -math.huge + local function addLevels(into: { any }, levels: any): string? + for _, lv in list(levels) do + if type(lv) == "table" then + local g, err = level(ctx, lv, resolve) + if not g then + return err + end + local x, y = g.offsetX :: number, g.offsetY :: number + minX, minY = math.min(minX, x), math.min(minY, y) + maxX, maxY = math.max(maxX, x + (g.pxWidth :: number)), math.max(maxY, y + (g.pxHeight :: number)) + table.insert(into, g) + end + end + return nil + end + if #worlds > 0 then + for _, w in worlds do + if type(w) == "table" then + local wg: Types.TileLayer = { + name = s(w.identifier) or "", + type = "group", + visible = true, + opacity = 1, + properties = {}, + layers = {}, + world = true, + ldtk = rest(w, { levels = true, identifier = true }), + } + local err = addLevels(wg.layers :: { any }, w.levels) + if err then + return nil, err + end + table.insert(map.layers, wg) + end + end + else + local err = addLevels(map.layers, v.levels) + if err then + return nil, err + end + end + if minX <= maxX then + map.width = math.ceil((maxX - math.min(minX, 0)) / grid) + map.height = math.ceil((maxY - math.min(minY, 0)) / grid) + end + map.backgroundColor = s(v.bgColor) + map.worldLayout = s(v.worldLayout) + map.ldtk = rest(v, PROJECT_SKIP) + map.meta.source = { format = "ldtk", version = s(v.jsonVersion), externalLevels = v.externalLevels == true, multiWorld = #worlds > 0 } + return map, nil +end + +return Read +end +__FILES["vector/ldtk/Write"] = function() + +-- vector/ldtk/Write: a Types.TileMap as an LDtk project (JSON 1.5). Maps read from LDtk keep their raw defs, project, +-- level, layer and entity fields (the .ldtk tables); other maps get definitions made from their layers, tilesets and +-- object classes. A tile layer writes its `tiles` list when present, else its gid `data`. Levels are always embedded. +local Types = __include("Types") +local Json = __include("codecs/text/Json") + +local Write = {} + +local NULL = Json.null +local FLAGS = 0xF0000000 + +local function tab(v: any): boolean + return type(v) == "table" and v ~= NULL +end +local function list(v: any): { any } + return if tab(v) then v else {} +end +local function n(v: any, default: number): number + return if type(v) == "number" and v == v then v else default +end + +type Ctx = { + uid: number, + iid: number, + defs: any, + tilesetByName: { [string]: any }, + tilesetByUid: { [number]: any }, + layerDefs: { [string]: any }, + entityDefs: { [string]: any }, + levelFields: { [string]: any }, + map: Types.TileMap, +} + +local function clone(t: any): any + if not tab(t) then + return Json.object({}) + end + local keys = Json.keys(t) + local out = {} + for _, k in keys do + out[k] = t[k] + end + return Json.object(out, keys) +end + +local function obj(pairs_: { any }): any + local out, keys = {}, {} + for i = 1, #pairs_, 2 do + local k, v = pairs_[i], pairs_[i + 1] + table.insert(keys, k) + out[k] = v + end + return Json.object(out, keys) +end + +local function set(t: any, k: string, v: any) + Json.set(t, k, if v == nil then NULL else v) +end + +local function nextUid(ctx: Ctx): number + ctx.uid += 1 + return ctx.uid +end + +local function newIid(ctx: Ctx): string + ctx.iid += 1 + return string.format("%08x-0000-4000-8000-%012x", 0x5ce7a000 + ctx.iid // 0x1000000, ctx.iid) +end + +-- ------------------------------------------------------------------------------------------------ fields +local function hexColor(v: any): number? + if type(v) ~= "string" then + return nil + end + local h = string.match(v, "^#(%x%x%x%x%x%x)$") or string.match(v, "^#%x%x(%x%x%x%x%x%x)$") + return if h then tonumber(h, 16) else nil +end + +local function wrap(typ: string, v: any): any + if v == nil or v == NULL then + return NULL + end + if typ == "Int" then + return obj({ "id", "V_Int", "params", { v } }) + elseif typ == "Float" then + return obj({ "id", "V_Float", "params", { v } }) + elseif typ == "Bool" then + return obj({ "id", "V_Bool", "params", { v == true } }) + elseif typ == "Color" then + local c = hexColor(v) + return if c then obj({ "id", "V_Int", "params", { c } }) else NULL + elseif typ == "Point" and tab(v) then + return obj({ "id", "V_String", "params", { tostring(v.cx) .. "," .. tostring(v.cy) } }) + elseif type(v) == "string" then + return obj({ "id", "V_String", "params", { v } }) + end + return nil +end + +local function editorValues(typ: string, v: any): any + local inner = string.match(typ, "^Array<(.+)>$") + if inner then + local out = {} + for i, x in list(v) do + local w = wrap(inner, x) + if w == nil then + return nil + end + out[i] = w + end + return out + end + local w = wrap(typ, v) + return if w == nil then nil else { w } +end + +local function same(a: any, b: any): boolean + if a == b then + return true + end + if tab(a) and tab(b) then + for k, x in a do + if not same(x, b[k]) then + return false + end + end + for k in b do + if a[k] == nil then + return false + end + end + return true + end + return false +end + +local LDTK_TYPE: { [string]: string } = { int = "Int", float = "Float", bool = "Bool", string = "String", color = "Color", file = "FilePath" } + +local function valueType(v: any): string + if type(v) == "number" then + return if v % 1 == 0 then "Int" else "Float" + elseif type(v) == "boolean" then + return "Bool" + end + return "String" +end + +local function fieldDef(ctx: Ctx, name: string, typ: string): any + local isArray = string.match(typ, "^Array<") ~= nil + local base = string.match(typ, "^Array<(.+)>$") or typ + return obj({ + "identifier", name, "doc", NULL, "__type", typ, "uid", nextUid(ctx), "type", "F_" .. base, "isArray", isArray, + "canBeNull", true, "arrayMinLength", NULL, "arrayMaxLength", NULL, "editorDisplayMode", "Hidden", + "editorDisplayScale", 1, "editorDisplayPos", "Above", "editorLinkStyle", "StraightArrow", "editorDisplayColor", NULL, + "editorAlwaysShow", false, "editorShowInWorld", true, "editorCutLongValues", true, "editorTextSuffix", NULL, + "editorTextPrefix", NULL, "useForSmartColor", false, "exportToToc", false, "searchable", false, "min", NULL, + "max", NULL, "regex", NULL, "acceptFileTypes", NULL, "defaultOverride", NULL, "textLanguageMode", NULL, + "symmetricalRef", false, "autoChainRef", true, "allowOutOfLevelRef", true, "allowedRefs", "OnlySame", + "allowedRefsEntityUid", NULL, "allowedRefTags", {}, "tilesetUid", NULL, + }) +end + +-- raw field instances updated from the properties; properties without an instance get one when a definition exists +-- (or is made: makeDefs) +local function fieldInstances(ctx: Ctx, raw: any, props: any, types: any, defs: { [string]: any }?, makeDefs: { any }?): { any } + local out = {} + local seen: { [string]: boolean } = {} + props = if tab(props) then props else {} + types = if tab(types) then types else {} + for _, fi in list(raw) do + if tab(fi) and type(fi.__identifier) == "string" then + local id = fi.__identifier + seen[id] = true + local f = clone(fi) + local v = props[id] + if v ~= nil and not same(v, fi.__value) then + set(f, "__value", v) + local ev = editorValues(if type(fi.__type) == "string" then fi.__type else valueType(v), v) + if ev then + set(f, "realEditorValues", ev) + end + end + table.insert(out, f) + end + end + local names = {} + for k in props do + if type(k) == "string" and not seen[k] then + table.insert(names, k) + end + end + table.sort(names) + for _, k in names do + local v = props[k] + local def = defs and defs[k] + if not def and makeDefs and defs then + local typ = if type(types[k]) == "string" then (LDTK_TYPE[types[k]] or types[k]) else valueType(v) + def = fieldDef(ctx, k, typ) + defs[k] = def + table.insert(makeDefs, def) + end + if def then + local typ = if type(def.__type) == "string" then def.__type else valueType(v) + table.insert(out, obj({ "__identifier", k, "__type", typ, "__value", v, "__tile", NULL, "defUid", def.uid, "realEditorValues", editorValues(typ, v) or {} })) + end + end + return out +end + +-- ------------------------------------------------------------------------------------------------ defs +local function tilesetOf(ctx: Ctx, gid: number): any + local best: any = nil + for _, ts in ctx.map.tilesets do + if ts.firstGid <= gid and (best == nil or ts.firstGid > best.firstGid) then + best = ts + end + end + return best +end + +local function defsFor(ctx: Ctx, raw: any) + local defs = if tab(raw) then clone(raw) else obj({ "layers", {}, "entities", {}, "tilesets", {}, "enums", {}, "externalEnums", {}, "levelFields", {} }) + for _, k in { "layers", "entities", "tilesets", "enums", "externalEnums", "levelFields" } do + if not tab(defs[k]) then + set(defs, k, {}) + end + end + ctx.defs = defs + for _, d in list(defs.tilesets) do + if tab(d) and type(d.uid) == "number" then + ctx.uid = math.max(ctx.uid, d.uid) + ctx.tilesetByUid[d.uid] = d + if type(d.identifier) == "string" then + ctx.tilesetByName[d.identifier] = d + end + end + end + for _, d in list(defs.layers) do + if tab(d) and type(d.identifier) == "string" then + ctx.uid = math.max(ctx.uid, n(d.uid, 0)) + ctx.layerDefs[d.identifier] = d + end + end + for _, d in list(defs.entities) do + if tab(d) and type(d.identifier) == "string" then + ctx.uid = math.max(ctx.uid, n(d.uid, 0)) + ctx.entityDefs[d.identifier] = d + for _, f in list(d.fieldDefs) do + ctx.uid = math.max(ctx.uid, n(tab(f) and f.uid, 0)) + end + end + end + for _, f in list(defs.levelFields) do + if tab(f) and type(f.identifier) == "string" then + ctx.uid = math.max(ctx.uid, n(f.uid, 0)) + ctx.levelFields[f.identifier] = f + end + end + for _, d in list(defs.enums) do + ctx.uid = math.max(ctx.uid, n(tab(d) and d.uid, 0)) + end + -- tilesets of the map the defs lack + for _, ts in ctx.map.tilesets do + if type(ts.name) == "string" and not ctx.tilesetByName[ts.name] then + local size = n(ts.tileWidth, 16) + local cols = math.max(1, n(ts.columns, 1)) + local d = obj({ + "__cWid", cols, "__cHei", math.ceil(n(ts.count, cols) / cols), "identifier", ts.name, "uid", nextUid(ctx), + "relPath", ts.imageSource or NULL, "embedAtlas", NULL, "pxWid", n(ts.imageWidth, cols * size), + "pxHei", n(ts.imageHeight, math.ceil(n(ts.count, cols) / cols) * size), "tileGridSize", size, + "spacing", n(ts.spacing, 0), "padding", n(ts.margin, 0), "tags", {}, "tagsSourceEnumUid", NULL, + "enumTags", {}, "customData", {}, "savedSelections", {}, "cachedPixelData", NULL, + }) + table.insert(defs.tilesets, d) + ctx.tilesetByName[ts.name] = d + ctx.tilesetByUid[d.uid] = d + end + end +end + +local function layerDef(ctx: Ctx, l: any, kind: string, grid: number, tsUid: number?): any + local d = ctx.layerDefs[l.name] + if d then + return d + end + local values = {} + for _, v in list(l.intGridValues) do + table.insert(values, obj({ "value", n(v.value, 1), "identifier", v.identifier or NULL, "color", v.color or "#FFFFFF", "tile", NULL, "groupUid", 0 })) + end + if kind == "IntGrid" and #values == 0 then + local maxV = 0 + for _, v in list(l.intGrid) do + maxV = math.max(maxV, n(v, 0)) + end + for v = 1, maxV do + table.insert(values, obj({ "value", v, "identifier", NULL, "color", "#FFFFFF", "tile", NULL, "groupUid", 0 })) + end + end + d = obj({ + "__type", kind, "identifier", l.name, "type", kind, "uid", nextUid(ctx), "doc", NULL, "uiColor", NULL, + "gridSize", grid, "guideGridWid", 0, "guideGridHei", 0, "displayOpacity", n(l.opacity, 1), "inactiveOpacity", 1, + "hideInList", false, "hideFieldsWhenInactive", true, "canSelectWhenInactive", true, "renderInWorldView", true, + "pxOffsetX", 0, "pxOffsetY", 0, "parallaxFactorX", 0, "parallaxFactorY", 0, "parallaxScaling", true, + "requiredTags", {}, "excludedTags", {}, "autoTilesKilledByOtherLayerUid", NULL, "uiFilterTags", {}, + "useAsyncRender", false, "intGridValues", values, "intGridValuesGroups", {}, "autoRuleGroups", {}, + "autoSourceLayerDefUid", NULL, "tilesetDefUid", tsUid or NULL, "tilePivotX", 0, "tilePivotY", 0, "biomeFieldUid", NULL, + }) + table.insert(ctx.defs.layers, d) + ctx.layerDefs[l.name] = d + return d +end + +local function entityDef(ctx: Ctx, o: any): any + local name = if type(o.class) == "string" and o.class ~= "" then o.class elseif type(o.name) == "string" and o.name ~= "" then o.name else "Entity" + local d = ctx.entityDefs[name] + if d then + return d + end + local pv = if tab(o.pivot) then o.pivot else { 0, 0 } + d = obj({ + "identifier", name, "uid", nextUid(ctx), "tags", {}, "exportToToc", false, "allowOutOfBounds", false, "doc", NULL, + "width", math.max(1, n(o.width, 16)), "height", math.max(1, n(o.height, 16)), "resizableX", false, + "resizableY", false, "minWidth", NULL, "maxWidth", NULL, "minHeight", NULL, "maxHeight", NULL, + "keepAspectRatio", false, "tileOpacity", 1, "fillOpacity", 0.08, "lineOpacity", 0, "hollow", false, + "color", if type(o.color) == "string" then o.color else "#94D9B3", "renderMode", "Rectangle", "showName", true, + "tilesetId", NULL, "tileRenderMode", "FitInside", "tileRect", NULL, "uiTileRect", NULL, "nineSliceBorders", {}, + "maxCount", 0, "limitScope", "PerLevel", "limitBehavior", "MoveLastOne", "pivotX", n(pv[1], 0), "pivotY", n(pv[2], 0), + "fieldDefs", {}, + }) + table.insert(ctx.defs.entities, d) + ctx.entityDefs[name] = d + return d +end + +-- ------------------------------------------------------------------------------------------------ layers +local function gridTiles(ctx: Ctx, l: any, grid: number, ts: any): { any } + local out = {} + if tab(l.tiles) then + for _, t in l.tiles do + local o = obj({ "px", { n(t.x, 0), n(t.y, 0) }, "src", { n(t.srcX, 0), n(t.srcY, 0) }, "f", n(t.flip, 0), "t", n(t.tile, 0) }) + if tab(t.d) then + set(o, "d", t.d) + end + set(o, "a", n(t.alpha, 1)) + table.insert(out, o) + end + return out + end + local w = n(l.width, 0) + for i, raw in list(l.data) do + local gid = bit32.band(n(raw, 0), bit32.bnot(FLAGS)) + if gid ~= 0 then + local tset = tilesetOf(ctx, gid) + if tset and (ts == nil or ctx.tilesetByName[tset.name] == ts) then + local id = gid - tset.firstGid + local cols = math.max(1, n(tset.columns, 1)) + local tw, th = n(tset.tileWidth, grid), n(tset.tileHeight, grid) + local sp, mg = n(tset.spacing, 0), n(tset.margin, 0) + local f = (if bit32.btest(raw, 0x80000000) then 1 else 0) + (if bit32.btest(raw, 0x40000000) then 2 else 0) + local cx, cy = (i - 1) % math.max(w, 1), (i - 1) // math.max(w, 1) + table.insert(out, obj({ + "px", { cx * grid, cy * grid }, "src", { mg + (id % cols) * (tw + sp), mg + (id // cols) * (th + sp) }, + "f", f, "t", id, "d", { cx + cy * w }, "a", 1, + })) + end + end + end + return out +end + +local function layerTileset(ctx: Ctx, l: any): any + if type(l.tileset) == "string" and ctx.tilesetByName[l.tileset] then + return ctx.tilesetByName[l.tileset] + end + if tab(l.ldtk) and type(l.ldtk.overrideTilesetUid) == "number" and ctx.tilesetByUid[l.ldtk.overrideTilesetUid] then + return ctx.tilesetByUid[l.ldtk.overrideTilesetUid] + end + for _, raw in list(l.data) do + local gid = bit32.band(n(raw, 0), bit32.bnot(FLAGS)) + if gid ~= 0 then + local tset = tilesetOf(ctx, gid) + return if tset then ctx.tilesetByName[tset.name] else nil + end + end + return nil +end + +local function entities(ctx: Ctx, l: any, levelIid: string, lx: number, ly: number, grid: number): { any } + local out = {} + for _, o in list(l.objects) do + if tab(o) then + local d = entityDef(ctx, o) + local w, h = n(o.width, n(d.width, 16)), n(o.height, n(d.height, 16)) + local pv = if tab(o.pivot) then o.pivot else { n(d.pivotX, 0), n(d.pivotY, 0) } + local px, py = n(o.x, 0) + n(pv[1], 0) * w, n(o.y, 0) + n(pv[2], 0) * h + local e = clone(o.ldtk) + set(e, "__identifier", d.identifier) + set(e, "__grid", { px // grid, py // grid }) + set(e, "__pivot", { n(pv[1], 0), n(pv[2], 0) }) + set(e, "__tags", if tab(o.tags) then o.tags else {}) + set(e, "__tile", if tab(o.tile) then o.tile else NULL) + set(e, "__smartColor", if type(o.color) == "string" then o.color else d.color) + if type(e.iid) ~= "string" then + set(e, "iid", if type(o.id) == "string" then o.id else newIid(ctx)) + end + set(e, "width", w) + set(e, "height", h) + set(e, "defUid", d.uid) + set(e, "px", { px, py }) + local fdefs: { [string]: any } = {} + for _, f in list(d.fieldDefs) do + if tab(f) and type(f.identifier) == "string" then + fdefs[f.identifier] = f + end + end + set(e, "fieldInstances", fieldInstances(ctx, o.fieldInstances, o.properties, o.propertyTypes, fdefs, d.fieldDefs)) + set(e, "__worldX", lx + px) + set(e, "__worldY", ly + py) + table.insert(out, e) + end + end + return out +end + +local function layerInstance(ctx: Ctx, l: any, levelUid: number, levelIid: string, lx: number, ly: number, pxW: number, pxH: number): any + local kind = if type(l.ldtkType) == "string" then l.ldtkType + elseif l.type == "objects" then "Entities" + elseif tab(l.intGrid) then "IntGrid" + else "Tiles" + local grid = math.max(1, n(l.gridSize, ctx.map.tileWidth)) + local ts = if kind ~= "Entities" then layerTileset(ctx, l) else nil + local d = layerDef(ctx, l, kind, grid, if ts then ts.uid else nil) + local cw = n(l.width, math.ceil(pxW / grid)) + local ch = n(l.height, math.ceil(pxH / grid)) + local li = clone(l.ldtk) + set(li, "__identifier", l.name) + set(li, "__type", kind) + set(li, "__cWid", cw) + set(li, "__cHei", ch) + set(li, "__gridSize", grid) + set(li, "__opacity", n(l.opacity, 1)) + set(li, "__pxTotalOffsetX", n(l.offsetX, 0)) + set(li, "__pxTotalOffsetY", n(l.offsetY, 0)) + set(li, "__tilesetDefUid", if ts then ts.uid else NULL) + set(li, "__tilesetRelPath", if ts and type(ts.relPath) == "string" then ts.relPath else NULL) + if type(li.iid) ~= "string" then + set(li, "iid", newIid(ctx)) + end + set(li, "levelId", levelUid) + set(li, "layerDefUid", d.uid) + if li.pxOffsetX == nil then + set(li, "pxOffsetX", n(l.offsetX, 0) - n(d.pxOffsetX, 0)) + set(li, "pxOffsetY", n(l.offsetY, 0) - n(d.pxOffsetY, 0)) + end + set(li, "visible", l.visible ~= false) + if li.optionalRules == nil then + set(li, "optionalRules", {}) + end + local csv = {} + if kind == "IntGrid" then + local g = list(l.intGrid) + for i = 1, cw * ch do + csv[i] = n(g[i], 0) + end + end + set(li, "intGridCsv", csv) + local tl = if kind ~= "Entities" then gridTiles(ctx, l, grid, ts) else {} + set(li, "autoLayerTiles", if kind == "IntGrid" or kind == "AutoLayer" then tl else {}) + if li.seed == nil then + set(li, "seed", 0) + end + if li.overrideTilesetUid == nil then + set(li, "overrideTilesetUid", NULL) + end + set(li, "gridTiles", if kind == "Tiles" then tl else {}) + set(li, "entityInstances", if kind == "Entities" then entities(ctx, l, levelIid, lx, ly, grid) else {}) + return li +end + +-- ------------------------------------------------------------------------------------------------ levels +local function flat(layers: { any }, into: { any }) + for _, l in layers do + if l.type == "group" and not l.level and not l.world then + flat(list(l.layers), into) + elseif l.type ~= "group" and l.type ~= "image" then + table.insert(into, l) + end + end +end + +local function levelValue(ctx: Ctx, g: any, layers: { any }, index: number): any + local lv = clone(g.ldtk) + local grid = ctx.map.tileWidth + local pxW = n(g.pxWidth, 0) + local pxH = n(g.pxHeight, 0) + if pxW <= 0 or pxH <= 0 then + for _, l in layers do + local gs = n(l.gridSize, grid) + pxW = math.max(pxW, n(l.width, 0) * gs) + pxH = math.max(pxH, n(l.height, 0) * gs) + end + pxW = if pxW > 0 then pxW else ctx.map.width * grid + pxH = if pxH > 0 then pxH else ctx.map.height * grid + end + local uid = if type(lv.uid) == "number" then lv.uid else nextUid(ctx) + local iid = if type(lv.iid) == "string" then lv.iid else newIid(ctx) + local lx, ly = n(g.offsetX, 0), n(g.offsetY, 0) + set(lv, "identifier", if type(g.name) == "string" and g.name ~= "" then g.name else "Level_" .. index) + set(lv, "iid", iid) + set(lv, "uid", uid) + set(lv, "worldX", lx) + set(lv, "worldY", ly) + if lv.worldDepth == nil then + set(lv, "worldDepth", 0) + end + set(lv, "pxWid", pxW) + set(lv, "pxHei", pxH) + set(lv, "__bgColor", if type(g.backgroundColor) == "string" then g.backgroundColor elseif type(ctx.map.backgroundColor) == "string" then ctx.map.backgroundColor else "#696A79") + for _, k in { "bgColor", "bgRelPath", "bgPos", "__smartColor", "__bgPos" } do + if lv[k] == nil then + set(lv, k, if k == "__smartColor" then "#ADADB5ff" else NULL) + end + end + if lv.useAutoIdentifier == nil then + set(lv, "useAutoIdentifier", false) + end + if lv.bgPivotX == nil then + set(lv, "bgPivotX", 0.5) + set(lv, "bgPivotY", 0.5) + end + set(lv, "externalRelPath", NULL) + set(lv, "fieldInstances", fieldInstances(ctx, lv.fieldInstances, g.properties, g.propertyTypes, ctx.levelFields, ctx.defs.levelFields)) + local out = {} + for i = #layers, 1, -1 do + table.insert(out, layerInstance(ctx, layers[i], uid, iid, lx, ly, pxW, pxH)) + end + set(lv, "layerInstances", out) + if lv.__neighbours == nil then + set(lv, "__neighbours", {}) + end + return lv +end + +local function levels(ctx: Ctx, layers: { any }): { any } + local out = {} + local loose = {} + for _, l in layers do + if l.type == "group" and not l.world then + local ls = {} + flat(list(l.layers), ls) + table.insert(out, levelValue(ctx, l, ls, #out)) + elseif l.type ~= "group" and l.type ~= "image" then + table.insert(loose, l) + end + end + if #loose > 0 then + table.insert(out, 1, levelValue(ctx, { name = "Level_0", properties = {}, offsetX = 0, offsetY = 0 }, loose, 0)) + end + return out +end + +local PROJECT: { any } = { + "__header__", NULL, "iid", NULL, "jsonVersion", "1.5.3", "appBuildId", 473703, "nextUid", 0, "identifierStyle", "Capitalize", + "toc", {}, "worldLayout", "Free", "worldGridWidth", 256, "worldGridHeight", 256, "defaultLevelWidth", 256, + "defaultLevelHeight", 256, "defaultPivotX", 0, "defaultPivotY", 0, "defaultGridSize", 16, "defaultEntityWidth", 16, + "defaultEntityHeight", 16, "bgColor", "#40465B", "defaultLevelBgColor", "#696A79", "minifyJson", false, + "externalLevels", false, "exportTiled", false, "simplifiedExport", false, "imageExportMode", "None", + "exportLevelBg", true, "pngFilePattern", NULL, "backupOnSave", false, "backupLimit", 10, "backupRelPath", NULL, + "levelNamePattern", "Level_%idx", "tutorialDesc", NULL, "customCommands", {}, "flags", {}, "defs", NULL, + "levels", NULL, "worlds", NULL, "dummyWorldIid", NULL, +} + +function Write.project(map: Types.TileMap, opts: any): (any, string?) + local ctx: Ctx = { + uid = 0, + iid = 0, + defs = nil, + tilesetByName = {}, + tilesetByUid = {}, + layerDefs = {}, + entityDefs = {}, + levelFields = {}, + map = map, + } + local raw = if tab(map.ldtk) then map.ldtk else nil + local p = if raw then clone(raw) else Json.object({}) + if not raw then + for i = 1, #PROJECT, 2 do + set(p, PROJECT[i], PROJECT[i + 1]) + end + set(p, "__header__", obj({ "fileType", "LDtk Project JSON", "app", "LDtk", "doc", "https://ldtk.io/json", "schema", "https://ldtk.io/files/JSON_SCHEMA.json", "appAuthor", "Sebastien 'deepnight' Benard", "appVersion", "1.5.3", "url", "https://ldtk.io" })) + set(p, "iid", newIid(ctx)) + set(p, "defaultGridSize", map.tileWidth) + end + ctx.uid = math.max(ctx.uid, n(p.nextUid, 1) - 1) + defsFor(ctx, p.defs) + local worlds = {} + local hasWorlds = false + for _, l in map.layers do + if l.type == "group" and l.world then + hasWorlds = true + end + end + local lvls: { any } = {} + if hasWorlds then + for _, l in map.layers do + if l.type == "group" and l.world then + local w = clone(l.ldtk) + set(w, "identifier", l.name) + if type(w.iid) ~= "string" then + set(w, "iid", newIid(ctx)) + end + for _, k in { "worldGridWidth", "worldGridHeight" } do + if w[k] == nil then + set(w, k, 256) + end + end + if w.worldLayout == nil then + set(w, "worldLayout", "Free") + end + set(w, "levels", levels(ctx, list(l.layers))) + table.insert(worlds, w) + end + end + else + lvls = levels(ctx, map.layers) + end + if type(map.backgroundColor) == "string" then + set(p, "bgColor", map.backgroundColor) + end + if type(map.worldLayout) == "string" and not hasWorlds then + set(p, "worldLayout", map.worldLayout) + end + set(p, "externalLevels", false) + set(p, "defs", ctx.defs) + set(p, "levels", lvls) + set(p, "worlds", worlds) + if type(p.dummyWorldIid) ~= "string" then + set(p, "dummyWorldIid", newIid(ctx)) + end + set(p, "nextUid", ctx.uid + 1) + return p, nil +end + +return Write +end +__FILES["vector/ogmo"] = function() + +-- vector/ogmo: Ogmo Editor 3 levels (.json) and projects (.ogmo) as a TileMap, read + write (OgmoEditor3-CE 3.x +-- save format). Supports: tile layers (ids / coords, 1D / 2D arrays, tile flags), grid layers, entity layers (origin, +-- rotation, flips, nodes, values), decal layers, level values; the project through opts.project for tilesets and +-- entity templates. Not supported: loading tileset images (embedded PNGs stay bytes: tileset.imageData). + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local Types = __include("Types") +local Json = __include("codecs/text/Json") +local Read = __include("vector/ogmo/Read") +local Write = __include("vector/ogmo/Write") + +-- ------------------------------------------------------------------------------------------------ contract +local Ogmo = { + name = "ogmo", + category = "vector", + extensions = { "ogmo" }, + mime = { "application/x-ogmo+json" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "core/Base64", "Types", "codecs/text/Json" }, + caps = { decode = true, encode = true, projects = true, entities = true, decals = true }, +} + +type DecodeOptions = { + maxBytes: number?, -- default 2^28 + maxCells: number?, -- per layer, default 2^26 + project: (string | buffer | { [string]: any })?, -- the .ogmo project of a level (bytes or decoded JSON) +} +type EncodeOptions = { + kind: ("level" | "project")?, -- default: "project" for a map read from a .ogmo, else "level" + indent: number?, -- default 2; 0 = compact +} + +-- ------------------------------------------------------------------------------------------------ sniff +function Ogmo.sniff(r: Bytes.Reader): number + local h = Sniff.text(r, 2048) + if not string.match(h, "^%s*{") or not string.find(h, "\"ogmoVersion\"", 1, true) then + return 0 + end + if string.find(h, "\"layerGridDefaultSize\"", 1, true) or string.find(h, "\"levelPaths\"", 1, true) then + return 1 + end + return 0.9 +end + +-- ------------------------------------------------------------------------------------------------ decode +local function json(src: any): (any, Err.Err?) + if type(src) == "table" then + return src, nil + end + if type(src) ~= "string" and type(src) ~= "buffer" then + return nil, Err.new(Err.ARG, "project must be bytes or a table") + end + return Json.decode(src, { ordered = true }) +end + +function Ogmo.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.TileMap?, Err.Err?) + local o: any = opts or {} + if r.limit - r.base > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local v, jerr = Json.decode(buffer.readstring(r.buf, r.base, r.limit - r.base), { ordered = true }) + if v == nil then + return nil, jerr + end + if type(v) ~= "table" then + return nil, Err.new(Err.CORRUPT, "not a JSON object") + end + local isProject = v.layerGridDefaultSize ~= nil or v.levelPaths ~= nil or v.tilesets ~= nil and v.layers ~= nil and v.width == nil + local project: any = nil + if not isProject and o.project ~= nil then + local p, perr = json(o.project) + if p == nil then + return nil, perr + end + project = p + end + local run: (any, any) -> (any, string?) = if isProject then Read.project else function(x: any, oo: any): (any, string?) + return Read.level(x, project, oo) + end + local ok, map, msg = pcall(run, v, o) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad data: " .. tostring(map)) + end + if not map then + return nil, Err.from(msg) + end + return map, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +function Ogmo.encode(map: Types.TileMap, opts: EncodeOptions?): (buffer?, Err.Err?) + if type(map) ~= "table" or type(map.layers) ~= "table" or type(map.tilesets) ~= "table" then + return nil, Err.new(Err.ARG, "needs a TileMap value") + end + local kind = opts and opts.kind or (if type(map.meta) == "table" and map.meta.project then "project" else "level") + if kind ~= "level" and kind ~= "project" then + return nil, Err.new(Err.ARG, "kind must be level or project") + end + local ok, v, msg = pcall(if kind == "project" then Write.project else Write.level, map) + if not ok then + return nil, Err.new(Err.ARG, "bad map: " .. tostring(v)) + end + if v == nil then + return nil, Err.new(Err.ARG, msg or "bad map") + end + local indent = if opts and opts.indent == 0 then nil else (opts and opts.indent or 2) + local s, jerr = Json.encode(v, { indent = indent }) + if not s then + return nil, jerr + end + return buffer.fromstring(s), nil +end + +return Ogmo +end +__FILES["vector/ogmo/Read"] = function() + +-- vector/ogmo/Read: Ogmo Editor 3 projects (.ogmo) and levels (.json) into a Types.TileMap (layer save / load as in +-- OgmoEditor3-CE src/modules/*/ *Layer.hx). Ogmo's first layer is drawn on top: layers are reversed (bottom first). +-- Tile ids -1 are empty; tileFlags 4 / 2 / 1 (flip H / V / diagonal) become Tiled's 0x80000000 / 0x40000000 / +-- 0x20000000. +local Types = __include("Types") +local Json = __include("codecs/text/Json") +local Base64 = __include("core/Base64") + +local Read = {} + +local NULL = Json.null +local FLIP_H, FLIP_V, FLIP_D = 0x80000000, 0x40000000, 0x20000000 + +local function tab(v: any): boolean + return type(v) == "table" and v ~= NULL +end +local function list(v: any): { any } + return if tab(v) then v else {} +end +local function n(v: any, default: number): number + return if type(v) == "number" and v == v then v else default +end +local function s(v: any): string? + return if type(v) == "string" then v else nil +end +local function vec(v: any, dx: number, dy: number): (number, number) + if tab(v) then + return n(v.x, dx), n(v.y, dy) + end + return dx, dy +end + +-- PNG IHDR width / height of an embedded tileset image (data: URI) +local function pngSize(b: buffer): (number?, number?) + if buffer.len(b) >= 24 and buffer.readstring(b, 0, 8) == "\137PNG\r\n\26\n" and buffer.readstring(b, 12, 4) == "IHDR" then + local function be(o: number): number + return buffer.readu8(b, o) * 16777216 + buffer.readu8(b, o + 1) * 65536 + buffer.readu8(b, o + 2) * 256 + buffer.readu8(b, o + 3) + end + return be(16), be(20) + end + return nil, nil +end + +local VALUE_TYPES: { [string]: string } = { Integer = "int", Float = "float", Boolean = "bool", Color = "color", Filepath = "file", String = "string", Text = "string", Enum = "string" } + +function Read.tilesets(project: any): { Types.Tileset } + local out: { Types.Tileset } = {} + local gid = 1 + for _, t in list(project and project.tilesets) do + if tab(t) then + local tw, th = math.max(1, n(t.tileWidth, 16)), math.max(1, n(t.tileHeight, 16)) + local sx, sy = n(t.tileSeparationX, 0), n(t.tileSeparationY, 0) + local mx, my = n(t.tileMarginX, 0), n(t.tileMarginY, 0) + local data: buffer? = nil + local iw, ih = nil, nil + if type(t.image) == "string" and string.sub(t.image, 1, 5) == "data:" then + data = Base64.decodeDataUri(t.image) + if data then + iw, ih = pngSize(data) + end + end + local cols = if iw then math.max(1, (iw - 2 * mx + sx) // (tw + sx)) else 1 + local rows = if ih then math.max(1, (ih - 2 * my + sy) // (th + sy)) else 1 + local ts: Types.Tileset = { + name = s(t.label) or ("tileset" .. #out), + firstGid = gid, + tileWidth = tw, + tileHeight = th, + columns = cols, + count = cols * rows, + imageSource = s(t.path), + imageWidth = iw, + imageHeight = ih, + imageData = data, + spacing = sx, + spacingY = if sy ~= sx then sy else nil, + margin = mx, + marginY = if my ~= mx then my else nil, + } + gid += ts.count + table.insert(out, ts) + end + end + return out +end + +local function valueTypes(defs: any): { [string]: string }? + local out: { [string]: string }? = nil + for _, d in list(defs) do + if tab(d) and type(d.name) == "string" and type(d.definition) == "string" then + local typ = VALUE_TYPES[d.definition] + if typ and typ ~= "string" then + out = out or {} + ;(out :: any)[d.name] = typ + end + end + end + return out +end + +local function values(v: any): { [string]: any } + local out: { [string]: any } = {} + if tab(v) then + for k, x in v do + if type(k) == "string" then + out[k] = x + end + end + end + return out +end + +type Ctx = { project: any, tilesets: { Types.Tileset }, byName: { [string]: Types.Tileset }, layerDefs: { [string]: any }, entityDefs: { [string]: any }, radians: boolean, maxCells: number } + +local function cells2D(v: any, w: number, h: number): { any } + local out = table.create(w * h) + for y, row in list(v) do + for x, c in list(row) do + if x <= w and y <= h then + out[(y - 1) * w + x] = c + end + end + end + return out +end + +local function tileLayer(ctx: Ctx, li: any, l: Types.TileLayer, w: number, h: number) + local ts = ctx.byName[s(li.tileset) or ""] or ctx.tilesets[1] + l.tileset = s(li.tileset) + local exportMode, arrayMode = n(li.exportMode, 0), n(li.arrayMode, 0) + local raw: { any } + if exportMode == 1 then + raw = if arrayMode == 1 then cells2D(li.dataCoords2D, w, h) else list(li.dataCoords) + else + raw = if arrayMode == 1 then cells2D(li.data2D, w, h) else list(li.data) + end + local flags = if arrayMode == 1 then cells2D(li.tileFlags2D, w, h) else list(li.tileFlags) + local data = table.create(w * h, 0) + for i = 1, w * h do + local c = raw[i] + local id = -1 + if exportMode == 1 then + if tab(c) and n(c[1], -1) >= 0 then + id = n(c[2], 0) * (if ts then ts.columns else 1) + n(c[1], 0) + end + else + id = n(c, -1) + end + if id >= 0 and ts then + local gid = ts.firstGid + id + local f = n(flags[i], 0) + if bit32.btest(f, 4) then + gid += FLIP_H + end + if bit32.btest(f, 2) then + gid += FLIP_V + end + if bit32.btest(f, 1) then + gid += FLIP_D + end + data[i] = gid + elseif id >= 0 then + data[i] = id + 1 + end + end + l.data = data +end + +local function entity(ctx: Ctx, e: any): { [string]: any } + local def = ctx.entityDefs[s(e.name) or ""] + local dw, dh = vec(def and def.size, 16, 16) + local dox, doy = vec(def and def.origin, 0, 0) + local w, h = n(e.width, dw), n(e.height, dh) + local ox, oy = n(e.originX, dox), n(e.originY, doy) + local rot = n(e.rotation, 0) + if ctx.radians then + rot = math.deg(rot) + end + local nodes = nil + if tab(e.nodes) then + nodes = {} + for i, p in e.nodes do + nodes[i] = { n(tab(p) and p.x, 0), n(tab(p) and p.y, 0) } + end + end + return { + id = e.id, + name = s(e.name) or "", + class = s(e.name) or "", + x = n(e.x, 0) - ox, + y = n(e.y, 0) - oy, + width = w, + height = h, + rotation = rot, + visible = true, + shape = "rectangle", + originX = ox, + originY = oy, + flippedX = if type(e.flippedX) == "boolean" then e.flippedX else nil, + flippedY = if type(e.flippedY) == "boolean" then e.flippedY else nil, + color = s(e.color), + nodes = nodes, + eid = s(e._eid), + properties = values(e.values), + propertyTypes = if def then valueTypes(def.values) else nil, + } +end + +local function decal(ctx: Ctx, d: any): { [string]: any } + local rot = n(d.rotation, 0) + if ctx.radians then + rot = math.deg(rot) + end + return { + name = s(d.texture) or "", + class = "decal", + shape = "decal", + texture = s(d.texture), + x = n(d.x, 0), + y = n(d.y, 0), + width = 0, + height = 0, + originX = n(d.originX, 0.5), + originY = n(d.originY, 0.5), + scaleX = n(d.scaleX, 1), + scaleY = n(d.scaleY, 1), + rotation = rot, + visible = true, + properties = values(d.values), + } +end + +local function layer(ctx: Ctx, li: any): (Types.TileLayer?, string?) + local name = s(li.name) or "" + local def = ctx.layerDefs[name] + local kind = (def and s(def.definition)) or (if li.entities ~= nil then "entity" + elseif li.decals ~= nil then "decal" + elseif li.grid ~= nil or li.grid2D ~= nil then "grid" + else "tile") + local w, h = n(li.gridCellsX, 0), n(li.gridCellsY, 0) + if w < 0 or h < 0 or w * h > ctx.maxCells then + return nil, "limit: layer of " .. w .. " x " .. h .. " cells" + end + local l: Types.TileLayer = { + name = name, + type = if kind == "entity" or kind == "decal" then "objects" else "tiles", + visible = true, + opacity = 1, + properties = {}, + offsetX = n(li.offsetX, 0), + offsetY = n(li.offsetY, 0), + ogmoType = kind, + cellWidth = n(li.gridCellWidth, 0), + cellHeight = n(li.gridCellHeight, 0), + eid = s(li._eid), + exportMode = if type(li.exportMode) == "number" then li.exportMode else nil, + arrayMode = if type(li.arrayMode) == "number" then li.arrayMode else nil, + } + if kind == "entity" then + local objs = {} + for _, e in list(li.entities) do + if tab(e) then + table.insert(objs, entity(ctx, e)) + end + end + l.objects = objs + elseif kind == "decal" then + local objs = {} + for _, d in list(li.decals) do + if tab(d) then + table.insert(objs, decal(ctx, d)) + end + end + l.objects = objs + l.folder = s(li.folder) + elseif kind == "grid" then + l.width, l.height = w, h + local raw = if n(li.arrayMode, 0) == 1 then cells2D(li.grid2D, w, h) else list(li.grid) + local grid = table.create(w * h, "0") + local data = table.create(w * h, 0) + for i = 1, w * h do + local c = raw[i] + local v = if type(c) == "string" then c elseif type(c) == "number" then tostring(c) else "0" + grid[i] = v + data[i] = tonumber(v) or 0 + end + l.grid = grid + l.data = data + if def and tab(def.legend) then + l.legend = values(def.legend) + end + else + l.width, l.height = w, h + tileLayer(ctx, li, l, w, h) + end + return l, nil +end + +local function context(project: any, opts: any): Ctx + local ts = Read.tilesets(project) + local ctx: Ctx = { project = project, tilesets = ts, byName = {}, layerDefs = {}, entityDefs = {}, radians = true, maxCells = opts.maxCells or 2 ^ 26 } + for _, t in ts do + ctx.byName[t.name] = t + end + if tab(project) then + ctx.radians = project.anglesRadians ~= false + for _, d in list(project.layers) do + if tab(d) and type(d.name) == "string" then + ctx.layerDefs[d.name] = d + end + end + for _, d in list(project.entities) do + if tab(d) and type(d.name) == "string" then + ctx.entityDefs[d.name] = d + end + end + end + return ctx +end + +local function gridSize(project: any, layers: { any }): (number, number) + if tab(project) and tab(project.layerGridDefaultSize) then + local x, y = vec(project.layerGridDefaultSize, 16, 16) + return math.max(1, x), math.max(1, y) + end + for _, l in layers do + if tab(l) and type(l.gridCellWidth) == "number" then + return math.max(1, l.gridCellWidth), math.max(1, n(l.gridCellHeight, l.gridCellWidth)) + end + end + return 16, 16 +end + +function Read.level(v: any, project: any, opts: any): (Types.TileMap?, string?) + if not tab(v) or not tab(v.layers) then + return nil, "no layers: not an Ogmo level" + end + local ctx = context(project, opts) + local tw, th = gridSize(project, v.layers) + local pw, ph = n(v.width, 0), n(v.height, 0) + local map = Types.TileMap.new(math.ceil(pw / tw), math.ceil(ph / th), tw, th) + map.tilesets = ctx.tilesets + map.pxWidth, map.pxHeight = pw, ph + map.offsetX, map.offsetY = n(v.offsetX, 0), n(v.offsetY, 0) + map.properties = values(v.values) + if tab(project) then + map.propertyTypes = valueTypes(project.levelValues) + end + local ls = v.layers + for i = #ls, 1, -1 do + if tab(ls[i]) then + local l, err = layer(ctx, ls[i]) + if not l then + return nil, err + end + table.insert(map.layers, l) + end + end + map.meta.source = { format = "ogmo", version = s(v.ogmoVersion), level = true, anglesRadians = ctx.radians } + if tab(project) then + map.ogmo = project + end + return map, nil +end + +function Read.project(v: any, opts: any): (Types.TileMap?, string?) + local ctx = context(v, opts) + local tw, th = gridSize(v, {}) + local lw, lh = vec(v.levelDefaultSize, 0, 0) + local map = Types.TileMap.new(math.ceil(lw / tw), math.ceil(lh / th), tw, th) + map.tilesets = ctx.tilesets + map.name = s(v.name) + map.backgroundColor = s(v.backgroundColor) + local defs = list(v.layers) + for i = #defs, 1, -1 do + local d = defs[i] + if tab(d) and type(d.name) == "string" then + local kind = s(d.definition) or "tile" + local gx, gy = vec(d.gridSize, tw, th) + local l: Types.TileLayer = { + name = d.name, + type = if kind == "entity" or kind == "decal" then "objects" else "tiles", + visible = true, + opacity = 1, + properties = {}, + ogmoType = kind, + cellWidth = gx, + cellHeight = gy, + eid = s(d.exportID), + tileset = s(d.defaultTileset), + } + table.insert(map.layers, l) + end + end + map.entities = list(v.entities) + map.ogmo = v + map.meta.source = { format = "ogmo", version = s(v.ogmoVersion), project = true, anglesRadians = ctx.radians } + map.meta.project = true + return map, nil +end + +return Read +end +__FILES["vector/ogmo/Write"] = function() + +-- vector/ogmo/Write: a Types.TileMap as an Ogmo Editor 3 level (.json) or project (.ogmo), in the shapes Ogmo 3.4 +-- saves (Layer.save / TileLayer.save / GridLayer.save / Entity.save / Decal.save). A project read from Ogmo is +-- written back with its own definitions; otherwise layers, tilesets and entity templates are made from the map. +local Types = __include("Types") +local Json = __include("codecs/text/Json") +local Base64 = __include("core/Base64") + +local Write = {} + +local NULL = Json.null +local FLAGS = 0xF0000000 +local VERSION = "3.4.0" + +local function tab(v: any): boolean + return type(v) == "table" and v ~= NULL +end +local function list(v: any): { any } + return if tab(v) then v else {} +end +local function n(v: any, default: number): number + return if type(v) == "number" and v == v then v else default +end + +-- key / value pairs; a nil value (an absent optional field) is skipped +local function obj(pairs_: { any }): any + local out, keys = {}, {} + local i = 1 + while pairs_[i] ~= nil do + if pairs_[i + 1] ~= nil then + table.insert(keys, pairs_[i]) + out[pairs_[i]] = pairs_[i + 1] + end + i += 2 + end + return Json.object(out, keys) +end + +local function values(props: any): any + local out = {} + local keys = {} + if tab(props) then + for k, v in props do + if type(k) == "string" then + out[k] = v + table.insert(keys, k) + end + end + end + table.sort(keys) + return Json.object(out, keys) +end + +local function eid(l: any, i: number): string + return if type(l.eid) == "string" then l.eid else tostring(10000000 + i) +end + +local function flat(layers: { any }, into: { any }) + for _, l in layers do + if l.type == "group" then + flat(list(l.layers), into) + elseif l.type == "tiles" or l.type == "objects" then + table.insert(into, l) + end + end +end + +local function tilesetOf(map: Types.TileMap, gid: number): Types.Tileset? + local best: Types.Tileset? = nil + for _, ts in map.tilesets do + if ts.firstGid <= gid and (best == nil or ts.firstGid > (best :: Types.Tileset).firstGid) then + best = ts + end + end + return best +end + +local function layerTileset(map: Types.TileMap, l: any): Types.Tileset? + if type(l.tileset) == "string" then + for _, ts in map.tilesets do + if ts.name == l.tileset then + return ts + end + end + end + for _, raw in list(l.data) do + local gid = bit32.band(n(raw, 0), bit32.bnot(FLAGS)) + if gid ~= 0 then + return tilesetOf(map, gid) + end + end + return map.tilesets[1] +end + +local function kindOf(l: any): string + if type(l.ogmoType) == "string" then + return l.ogmoType + elseif l.type == "objects" then + for _, o in list(l.objects) do + if o.shape == "decal" then + return "decal" + end + end + return "entity" + elseif tab(l.grid) then + return "grid" + end + return "tile" +end + +-- ------------------------------------------------------------------------------------------------ level +local function rows2D(flatList: { any }, w: number, h: number): { any } + local out = {} + for y = 1, h do + local row = {} + for x = 1, w do + row[x] = flatList[(y - 1) * w + x] + end + out[y] = row + end + return out +end + +local function tileLayer(map: Types.TileMap, l: any, i: number, gw: number, gh: number): any + local ts = layerTileset(map, l) + local w, h = n(l.width, math.ceil(n(map.pxWidth, map.width * map.tileWidth) / gw)), n(l.height, math.ceil(n(map.pxHeight, map.height * map.tileHeight) / gh)) + local ids, coords, flags = table.create(w * h, -1), table.create(w * h), table.create(w * h, 0) + local anyFlag = false + local data = list(l.data) + for k = 1, w * h do + local raw = n(data[k], 0) + local gid = bit32.band(raw, bit32.bnot(FLAGS)) + local id = -1 + if gid ~= 0 then + id = if ts then gid - ts.firstGid else gid - 1 + if ts and (id < 0 or id >= math.max(ts.count, 1)) then + id = -1 + end + end + ids[k] = id + if id >= 0 then + local cols = if ts then math.max(1, ts.columns) else 1 + coords[k] = { id % cols, id // cols } + local f = (if bit32.btest(raw, 0x80000000) then 4 else 0) + (if bit32.btest(raw, 0x40000000) then 2 else 0) + (if bit32.btest(raw, 0x20000000) then 1 else 0) + flags[k] = f + anyFlag = anyFlag or f ~= 0 + else + coords[k] = { -1 } + end + end + local exportMode, arrayMode = n(l.exportMode, 0), n(l.arrayMode, 0) + local fields: { any } = { + "name", l.name, "_eid", eid(l, i), "offsetX", n(l.offsetX, 0), "offsetY", n(l.offsetY, 0), "gridCellWidth", gw, + "gridCellHeight", gh, "gridCellsX", w, "gridCellsY", h, "tileset", if ts then ts.name else "", + } + local key = if exportMode == 1 then (if arrayMode == 1 then "dataCoords2D" else "dataCoords") else (if arrayMode == 1 then "data2D" else "data") + local body = if exportMode == 1 then coords else ids + table.insert(fields, key) + table.insert(fields, if arrayMode == 1 then rows2D(body, w, h) else body) + if anyFlag then + table.insert(fields, if arrayMode == 1 then "tileFlags2D" else "tileFlags") + table.insert(fields, if arrayMode == 1 then rows2D(flags, w, h) else flags) + end + table.insert(fields, "exportMode") + table.insert(fields, exportMode) + table.insert(fields, "arrayMode") + table.insert(fields, arrayMode) + return obj(fields) +end + +local function gridLayer(map: Types.TileMap, l: any, i: number, gw: number, gh: number): any + local w, h = n(l.width, map.width), n(l.height, map.height) + local cells = table.create(w * h, "0") + local grid, data = list(l.grid), list(l.data) + for k = 1, w * h do + local g = grid[k] + cells[k] = if type(g) == "string" then g else tostring(math.floor(n(data[k], 0))) + end + local arrayMode = n(l.arrayMode, 0) + return obj({ + "name", l.name, "_eid", eid(l, i), "offsetX", n(l.offsetX, 0), "offsetY", n(l.offsetY, 0), "gridCellWidth", gw, + "gridCellHeight", gh, "gridCellsX", w, "gridCellsY", h, + if arrayMode == 1 then "grid2D" else "grid", if arrayMode == 1 then rows2D(cells, w, h) else cells, + "arrayMode", arrayMode, + }) +end + +local function entities(l: any, i: number, gw: number, gh: number, w: number, h: number, radians: boolean): any + local out = {} + for k, o in list(l.objects) do + local ox, oy = n(o.originX, 0), n(o.originY, 0) + local nodes = nil + if tab(o.nodes) then + nodes = {} + for j, p in o.nodes do + nodes[j] = obj({ "x", n(p[1], 0), "y", n(p[2], 0) }) + end + end + local rot = n(o.rotation, 0) + table.insert(out, obj({ + "name", if type(o.class) == "string" and o.class ~= "" then o.class else (o.name or "entity"), + "id", if type(o.id) == "number" then o.id else k - 1, + "_eid", if type(o.eid) == "string" then o.eid else tostring(20000000 + k), + "x", n(o.x, 0) + ox, "y", n(o.y, 0) + oy, "width", n(o.width, gw), "height", n(o.height, gh), + "originX", ox, "originY", oy, "rotation", if radians then math.rad(rot) else rot, + "flippedX", o.flippedX, "flippedY", o.flippedY, "color", o.color, "nodes", nodes, + "values", if tab(o.properties) and next(o.properties) then values(o.properties) else nil, + })) + end + return obj({ + "name", l.name, "_eid", eid(l, i), "offsetX", n(l.offsetX, 0), "offsetY", n(l.offsetY, 0), "gridCellWidth", gw, + "gridCellHeight", gh, "gridCellsX", w, "gridCellsY", h, "entities", out, + }) +end + +local function decals(l: any, i: number, gw: number, gh: number, w: number, h: number, radians: boolean): any + local out = {} + for _, o in list(l.objects) do + local rot = n(o.rotation, 0) + table.insert(out, obj({ + "x", n(o.x, 0), "y", n(o.y, 0), "scaleX", n(o.scaleX, 1), "scaleY", n(o.scaleY, 1), + "rotation", if radians then math.rad(rot) else rot, "texture", o.texture or o.name or "", + "originX", n(o.originX, 0.5), "originY", n(o.originY, 0.5), + "values", if tab(o.properties) and next(o.properties) then values(o.properties) else nil, + })) + end + return obj({ + "name", l.name, "_eid", eid(l, i), "offsetX", n(l.offsetX, 0), "offsetY", n(l.offsetY, 0), "gridCellWidth", gw, + "gridCellHeight", gh, "gridCellsX", w, "gridCellsY", h, "decals", out, "folder", l.folder or "", + }) +end + +local function radiansOf(map: any): boolean + local src = if tab(map.meta) and tab(map.meta.source) then map.meta.source else {} + if type(src.anglesRadians) == "boolean" then + return src.anglesRadians + end + return true +end + +function Write.level(map: Types.TileMap): (any, string?) + local layers = {} + flat(map.layers, layers) + local radians = radiansOf(map) + local pw = n(map.pxWidth, map.width * map.tileWidth) + local ph = n(map.pxHeight, map.height * map.tileHeight) + local out = {} + for i = #layers, 1, -1 do + local l = layers[i] + local gw = n(l.cellWidth, map.tileWidth) + local gh = n(l.cellHeight, map.tileHeight) + local cw, ch = math.ceil(pw / math.max(gw, 1)), math.ceil(ph / math.max(gh, 1)) + local kind = kindOf(l) + local li + if kind == "entity" then + li = entities(l, i, gw, gh, cw, ch, radians) + elseif kind == "decal" then + li = decals(l, i, gw, gh, cw, ch, radians) + elseif kind == "grid" then + li = gridLayer(map, l, i, gw, gh) + else + li = tileLayer(map, l, i, gw, gh) + end + table.insert(out, li) + end + return obj({ + "ogmoVersion", if tab(map.meta) and tab(map.meta.source) and type(map.meta.source.version) == "string" then map.meta.source.version else VERSION, + "width", pw, "height", ph, "offsetX", n(map.offsetX, 0), "offsetY", n(map.offsetY, 0), + "values", if tab(map.properties) and next(map.properties) then values(map.properties) else nil, + "layers", out, + }), nil +end + +-- ------------------------------------------------------------------------------------------------ project +local function tileset(ts: any): any + local image = "" + if type(ts.imageData) == "buffer" then + image = Base64.dataUri(ts.imageData, "image/png") + end + return obj({ + "label", ts.name, "path", ts.imageSource or "", "image", image, "tileWidth", n(ts.tileWidth, 16), + "tileHeight", n(ts.tileHeight, 16), "tileSeparationX", n(ts.spacing, 0), "tileSeparationY", n(ts.spacingY, n(ts.spacing, 0)), + "tileMarginX", n(ts.margin, 0), "tileMarginY", n(ts.marginY, n(ts.margin, 0)), + }) +end + +local function entityTemplate(name: string, o: any, i: number): any + local w, h = math.max(1, n(o.width, 16)), math.max(1, n(o.height, 16)) + return obj({ + "exportID", tostring(30000000 + i), "name", name, "limit", -1, "size", obj({ "x", w, "y", h }), + "origin", obj({ "x", n(o.originX, 0), "y", n(o.originY, 0) }), "originAnchored", true, + "shape", obj({ "label", "Rectangle", "points", { + obj({ "x", -1, "y", -1 }), obj({ "x", 1, "y", -1 }), obj({ "x", -1, "y", 1 }), + obj({ "x", 1, "y", -1 }), obj({ "x", -1, "y", 1 }), obj({ "x", 1, "y", 1 }), + } }), + "color", if type(o.color) == "string" then o.color else "#ff0000ff", "tileX", false, "tileY", false, + "tileSize", obj({ "x", 16, "y", 16 }), "resizeableX", true, "resizeableY", true, "rotatable", true, + "rotationDegrees", 360, "canFlipX", true, "canFlipY", true, "canSetColor", false, "hasNodes", true, + "nodeLimit", 0, "nodeDisplay", 0, "nodeGhost", true, "tags", {}, "values", {}, + }) +end + +function Write.project(map: any): (any, string?) + if tab(map.ogmo) and map.meta and map.meta.project then + return map.ogmo, nil + end + local layers = {} + flat(map.layers, layers) + local defs = {} + local ents, seen = {}, {} + for i = #layers, 1, -1 do + local l = layers[i] + local kind = kindOf(l) + local gs = obj({ "x", n(l.cellWidth, map.tileWidth), "y", n(l.cellHeight, map.tileHeight) }) + local d: any + if kind == "tile" then + local ts = layerTileset(map, l) + d = obj({ "definition", "tile", "name", l.name, "gridSize", gs, "exportID", eid(l, i), "exportMode", n(l.exportMode, 0), "arrayMode", n(l.arrayMode, 0), "defaultTileset", if ts then ts.name else "" }) + elseif kind == "grid" then + local legend = if tab(l.legend) then values(l.legend) else obj({ "0", "#00000000", "1", "#000000ff" }) + d = obj({ "definition", "grid", "name", l.name, "gridSize", gs, "exportID", eid(l, i), "arrayMode", n(l.arrayMode, 0), "legend", legend }) + elseif kind == "decal" then + d = obj({ "definition", "decal", "name", l.name, "gridSize", gs, "exportID", eid(l, i), "folder", l.folder or "", "includeImageSequence", true, "scaleable", true, "rotatable", true, "values", {} }) + else + d = obj({ "definition", "entity", "name", l.name, "gridSize", gs, "exportID", eid(l, i), "requiredTags", {}, "excludedTags", {} }) + for _, o in list(l.objects) do + local name = if type(o.class) == "string" and o.class ~= "" then o.class else (o.name or "entity") + if not seen[name] then + seen[name] = true + table.insert(ents, entityTemplate(name, o, #ents)) + end + end + end + table.insert(defs, d) + end + local tss = {} + for _, ts in map.tilesets do + table.insert(tss, tileset(ts)) + end + local grid = obj({ "x", map.tileWidth, "y", map.tileHeight }) + local size = obj({ "x", n(map.pxWidth, map.width * map.tileWidth), "y", n(map.pxHeight, map.height * map.tileHeight) }) + return obj({ + "name", if type(map.name) == "string" then map.name else "Project", "ogmoVersion", VERSION, "levelPaths", { "." }, + "backgroundColor", if type(map.backgroundColor) == "string" then map.backgroundColor else "#282c34ff", + "gridColor", "#3c4049cc", "anglesRadians", radiansOf(map), "directoryDepth", 5, "layerGridDefaultSize", grid, + "levelDefaultSize", size, "levelMinSize", obj({ "x", 128, "y", 128 }), "levelMaxSize", obj({ "x", 4096, "y", 4096 }), + "levelValues", {}, "defaultExportMode", ".json", "compactExport", false, "externalScript", "", "playCommand", "", + "entityTags", {}, "layers", defs, "entities", ents, "tilesets", tss, + }), nil +end + +return Write +end __FILES["vector/svg"] = function() -- vector/svg: SVG 1.1 / 2 static documents (W3C SVG 1.1 2nd ed., SVG 2 CR). Supports: shapes and paths, transforms, diff --git a/build/Rosetta.luau.linemap.json b/build/Rosetta.luau.linemap.json index 40498ac..516f1f0 100644 --- a/build/Rosetta.luau.linemap.json +++ b/build/Rosetta.luau.linemap.json @@ -1,553 +1,574 @@ [ [27, "src/Rosetta/init.luau"], [871, "src/Rosetta/Registry.luau"], -[3052, "src/Rosetta/Types.luau"], -[4135, "src/Rosetta/archive/7z/init.luau"], -[4520, "src/Rosetta/archive/7z/Header.luau"], -[5047, "src/Rosetta/archive/adf/init.luau"], -[5329, "src/Rosetta/archive/applesingle/init.luau"], -[5515, "src/Rosetta/archive/ar/init.luau"], -[5918, "src/Rosetta/archive/arj/init.luau"], -[6128, "src/Rosetta/archive/binhex/init.luau"], -[6377, "src/Rosetta/archive/br/init.luau"], -[6452, "src/Rosetta/archive/bz2/init.luau"], -[6516, "src/Rosetta/archive/cab/init.luau"], -[6929, "src/Rosetta/archive/cab/Sum.luau"], -[6970, "src/Rosetta/archive/cpio/init.luau"], -[7138, "src/Rosetta/archive/d64/init.luau"], -[7552, "src/Rosetta/archive/fat/init.luau"], -[7674, "src/Rosetta/archive/grp/init.luau"], -[7788, "src/Rosetta/archive/gzip/init.luau"], -[7973, "src/Rosetta/archive/iso/init.luau"], -[8045, "src/Rosetta/archive/lha/init.luau"], -[8470, "src/Rosetta/archive/lz4/init.luau"], -[8814, "src/Rosetta/archive/macbinary/init.luau"], -[9012, "src/Rosetta/archive/mpq/init.luau"], -[9418, "src/Rosetta/archive/mpq/Crypt.luau"], -[9483, "src/Rosetta/archive/pak/init.luau"], -[9617, "src/Rosetta/archive/rpm/init.luau"], -[9941, "src/Rosetta/archive/tar/init.luau"], -[10059, "src/Rosetta/archive/uu/init.luau"], -[10329, "src/Rosetta/archive/vpk/init.luau"], -[10640, "src/Rosetta/archive/wad/init.luau"], -[11090, "src/Rosetta/archive/wad/Map.luau"], -[11520, "src/Rosetta/archive/wad/Picture.luau"], -[11622, "src/Rosetta/archive/wad2/init.luau"], -[11904, "src/Rosetta/archive/xz/init.luau"], -[12004, "src/Rosetta/archive/yenc/init.luau"], -[12276, "src/Rosetta/archive/z/init.luau"], -[12372, "src/Rosetta/archive/zip/init.luau"], -[12591, "src/Rosetta/archive/zoo/init.luau"], -[12787, "src/Rosetta/archive/zst/init.luau"], -[12851, "src/Rosetta/audio/aac/init.luau"], -[13057, "src/Rosetta/audio/ac3/init.luau"], -[13203, "src/Rosetta/audio/adpcm/init.luau"], -[13348, "src/Rosetta/audio/adx/init.luau"], -[13579, "src/Rosetta/audio/aiff/init.luau"], -[13970, "src/Rosetta/audio/ape/init.luau"], -[14098, "src/Rosetta/audio/au/init.luau"], -[14259, "src/Rosetta/audio/brstm/init.luau"], -[14550, "src/Rosetta/audio/caf/init.luau"], -[15212, "src/Rosetta/audio/flac/init.luau"], -[15360, "src/Rosetta/audio/flac/Meta.luau"], -[15582, "src/Rosetta/audio/flac/Stream.luau"], -[15952, "src/Rosetta/audio/m4a/init.luau"], -[16286, "src/Rosetta/audio/mp3/init.luau"], -[16546, "src/Rosetta/audio/mp3/Index.luau"], -[16737, "src/Rosetta/audio/mp3/Stream.luau"], -[16964, "src/Rosetta/audio/mp3/Tags.luau"], -[17276, "src/Rosetta/audio/mpc/init.luau"], -[17370, "src/Rosetta/audio/opus/init.luau"], -[17748, "src/Rosetta/audio/opus/Encode.luau"], -[17859, "src/Rosetta/audio/qoa/init.luau"], -[18039, "src/Rosetta/audio/tta/init.luau"], -[18157, "src/Rosetta/audio/vag/init.luau"], -[18380, "src/Rosetta/audio/voc/init.luau"], -[18655, "src/Rosetta/audio/vorbis/init.luau"], -[19109, "src/Rosetta/audio/vorbis/Encode.luau"], -[19922, "src/Rosetta/audio/wav/init.luau"], -[20543, "src/Rosetta/audio/wav/Codecs.luau"], -[20709, "src/Rosetta/audio/wavpack/init.luau"], -[20916, "src/Rosetta/cad/step/init.luau"], -[21298, "src/Rosetta/cad/step/Brep.luau"], -[21533, "src/Rosetta/cad/step/Parse.luau"], -[22090, "src/Rosetta/cad/step/Write.luau"], -[22338, "src/Rosetta/codecs/audio/Aac/init.luau"], -[22657, "src/Rosetta/codecs/audio/Aac/Decode.luau"], -[23540, "src/Rosetta/codecs/audio/Aac/Tables.luau"], -[23875, "src/Rosetta/codecs/audio/Ac3/init.luau"], -[24034, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], -[24919, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], -[25020, "src/Rosetta/codecs/audio/Adpcm/init.luau"], -[25774, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], -[26076, "src/Rosetta/codecs/audio/Alac/init.luau"], -[26310, "src/Rosetta/codecs/audio/Alac/Decode.luau"], -[26729, "src/Rosetta/codecs/audio/Alac/Encode.luau"], -[27141, "src/Rosetta/codecs/audio/Ape/init.luau"], -[27356, "src/Rosetta/codecs/audio/Ape/Decode.luau"], -[28117, "src/Rosetta/codecs/audio/ApeTag.luau"], -[28214, "src/Rosetta/codecs/audio/Flac/init.luau"], -[28225, "src/Rosetta/codecs/audio/Flac/Encode.luau"], -[29174, "src/Rosetta/codecs/audio/Flac/Frame.luau"], -[29771, "src/Rosetta/codecs/audio/Hively/init.luau"], -[29967, "src/Rosetta/codecs/audio/Hively/Load.luau"], -[30216, "src/Rosetta/codecs/audio/Hively/Player.luau"], -[31174, "src/Rosetta/codecs/audio/Hively/Tables.luau"], -[31393, "src/Rosetta/codecs/audio/Mdct/init.luau"], -[31577, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], -[31786, "src/Rosetta/codecs/audio/MidiRender.luau"], -[32132, "src/Rosetta/codecs/audio/Mpa/init.luau"], -[32146, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], -[32205, "src/Rosetta/codecs/audio/Mpa/Core.luau"], -[33808, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], -[34100, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], -[34485, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], -[35126, "src/Rosetta/codecs/audio/Mpa/Header.luau"], -[35267, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], -[35493, "src/Rosetta/codecs/audio/Musepack/init.luau"], -[35838, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], -[36719, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], -[37097, "src/Rosetta/codecs/audio/Opus/init.luau"], -[37111, "src/Rosetta/codecs/audio/Opus/Celt.luau"], -[38958, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], -[40023, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], -[40083, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], -[40543, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], -[40880, "src/Rosetta/codecs/audio/Opus/Packet.luau"], -[41113, "src/Rosetta/codecs/audio/Opus/Silk.luau"], -[43149, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], -[43523, "src/Rosetta/codecs/audio/Pcm/init.luau"], -[43786, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], -[44083, "src/Rosetta/codecs/audio/Qoa/init.luau"], -[44365, "src/Rosetta/codecs/audio/Resample/init.luau"], -[44724, "src/Rosetta/codecs/audio/SoundFont/init.luau"], -[44778, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], -[44921, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], -[45434, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], -[46215, "src/Rosetta/codecs/audio/Stream.luau"], -[46376, "src/Rosetta/codecs/audio/Tracker/init.luau"], -[46858, "src/Rosetta/codecs/audio/Tracker/Load.luau"], -[47136, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], -[47305, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], -[47433, "src/Rosetta/codecs/audio/Tracker/Player.luau"], -[49421, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], -[49537, "src/Rosetta/codecs/audio/Tta/init.luau"], -[49654, "src/Rosetta/codecs/audio/Tta/Decode.luau"], -[49906, "src/Rosetta/codecs/audio/Vorbis/init.luau"], -[49919, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], -[50303, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], -[50869, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], -[51290, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], -[51329, "src/Rosetta/codecs/audio/VorbisComment.luau"], -[51381, "src/Rosetta/codecs/audio/WavPack/init.luau"], -[51603, "src/Rosetta/codecs/audio/WavPack/Block.luau"], -[53058, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], -[53121, "src/Rosetta/codecs/compress/Brotli/init.luau"], -[53208, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], -[54177, "src/Rosetta/codecs/compress/Brotli/Static.luau"], -[55045, "src/Rosetta/codecs/compress/Bzip2/init.luau"], -[55093, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], -[55609, "src/Rosetta/codecs/compress/Deflate/init.luau"], -[55935, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], -[56355, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], -[56790, "src/Rosetta/codecs/compress/Explode.luau"], -[56986, "src/Rosetta/codecs/compress/Lz4.luau"], -[57255, "src/Rosetta/codecs/compress/Lzh/init.luau"], -[57859, "src/Rosetta/codecs/compress/Lzma/init.luau"], -[58399, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], -[58437, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], -[58910, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], -[59086, "src/Rosetta/codecs/compress/Lzw/init.luau"], -[59354, "src/Rosetta/codecs/compress/Lzx.luau"], -[59788, "src/Rosetta/codecs/compress/PackBits.luau"], -[59878, "src/Rosetta/codecs/compress/Quantum.luau"], -[60115, "src/Rosetta/codecs/compress/UnixCompress.luau"], -[60419, "src/Rosetta/codecs/compress/Xxh32.luau"], -[60488, "src/Rosetta/codecs/compress/Zstd/init.luau"], -[60545, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], -[61503, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], -[61655, "src/Rosetta/codecs/entropy/Huffman.luau"], -[61937, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], -[61948, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], -[62162, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], -[62406, "src/Rosetta/codecs/font/Bitmap.luau"], -[62607, "src/Rosetta/codecs/font/Cff/init.luau"], -[63248, "src/Rosetta/codecs/font/GlyphNames.luau"], -[63398, "src/Rosetta/codecs/font/TrueType/init.luau"], -[63712, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], -[64104, "src/Rosetta/codecs/font/TrueType/Tables.luau"], -[64606, "src/Rosetta/codecs/image/Bcn/init.luau"], -[64713, "src/Rosetta/codecs/image/Bcn/Decode.luau"], -[65202, "src/Rosetta/codecs/image/Bcn/Encode.luau"], -[65631, "src/Rosetta/codecs/image/Blend.luau"], -[66010, "src/Rosetta/codecs/image/Dct/init.luau"], -[66391, "src/Rosetta/codecs/image/Etc.luau"], -[66689, "src/Rosetta/codecs/image/Half.luau"], -[66758, "src/Rosetta/codecs/image/Jpeg/init.luau"], -[67112, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], -[67520, "src/Rosetta/codecs/image/Jpeg/Color.luau"], -[67757, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], -[68517, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], -[69398, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], -[69844, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], -[69922, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], -[69989, "src/Rosetta/codecs/image/Miptex.luau"], -[70289, "src/Rosetta/codecs/image/Pixels.luau"], -[70609, "src/Rosetta/codecs/image/Quantize/init.luau"], -[71068, "src/Rosetta/codecs/image/Raster.luau"], -[71765, "src/Rosetta/codecs/image/Texel.luau"], -[72138, "src/Rosetta/codecs/image/Texture.luau"], -[72283, "src/Rosetta/codecs/image/Vp8/init.luau"], -[72413, "src/Rosetta/codecs/image/Vp8/Decode.luau"], -[74369, "src/Rosetta/codecs/image/Vp8/Predict.luau"], -[74628, "src/Rosetta/codecs/image/Vp8/Tables.luau"], -[74877, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], -[74996, "src/Rosetta/codecs/image/Vp8L/init.luau"], -[75100, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], -[75953, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], -[76905, "src/Rosetta/codecs/image/Yuv.luau"], -[77173, "src/Rosetta/codecs/model/Brush.luau"], -[77813, "src/Rosetta/codecs/model/Draco/init.luau"], -[78145, "src/Rosetta/codecs/model/Draco/Attributes.luau"], -[78614, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], -[79803, "src/Rosetta/codecs/model/Draco/Int64.luau"], -[79952, "src/Rosetta/codecs/model/Draco/KdTree.luau"], -[80311, "src/Rosetta/codecs/model/Draco/Predict.luau"], -[81273, "src/Rosetta/codecs/model/Draco/Reader.luau"], -[81747, "src/Rosetta/codecs/model/Mat4.luau"], -[82006, "src/Rosetta/codecs/model/MeshFlatten.luau"], -[82534, "src/Rosetta/codecs/model/Minecraft/init.luau"], -[83086, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], -[83165, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], -[83272, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], -[83478, "src/Rosetta/codecs/model/Patch.luau"], -[83602, "src/Rosetta/codecs/model/Polygon.luau"], -[83836, "src/Rosetta/codecs/model/Rbx/init.luau"], -[84073, "src/Rosetta/codecs/model/Rbx/Binary.luau"], -[84827, "src/Rosetta/codecs/model/Rig.luau"], -[85070, "src/Rosetta/codecs/model/Sampler.luau"], -[85230, "src/Rosetta/codecs/model/Vrml/init.luau"], -[85378, "src/Rosetta/codecs/model/Vrml/Build.luau"], -[85952, "src/Rosetta/codecs/model/Vrml/Fields.luau"], -[86115, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], -[86864, "src/Rosetta/codecs/model/Vrml/Parse.luau"], -[87386, "src/Rosetta/codecs/model/Vrml/Write.luau"], -[88113, "src/Rosetta/codecs/model/Vrml/Xml.luau"], -[88345, "src/Rosetta/codecs/text/Json/init.luau"], -[88614, "src/Rosetta/codecs/text/Json/Decode.luau"], -[89028, "src/Rosetta/codecs/text/Json/Encode.luau"], -[89330, "src/Rosetta/codecs/text/Nbt/init.luau"], -[89683, "src/Rosetta/codecs/text/Nbt/Binary.luau"], -[90375, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], -[91015, "src/Rosetta/codecs/text/Nbt/Value.luau"], -[91253, "src/Rosetta/codecs/text/Text/init.luau"], -[91344, "src/Rosetta/codecs/text/Url/init.luau"], -[91549, "src/Rosetta/codecs/text/Xml/init.luau"], -[91952, "src/Rosetta/codecs/text/Xml/Parse.luau"], -[92692, "src/Rosetta/codecs/video/Dsp.luau"], -[93415, "src/Rosetta/codecs/video/H263/init.luau"], -[93571, "src/Rosetta/codecs/video/H263/Decoder.luau"], -[94429, "src/Rosetta/codecs/video/H263/Tables.luau"], -[94632, "src/Rosetta/codecs/video/H264/init.luau"], -[95005, "src/Rosetta/codecs/video/H264/Bitstream.luau"], -[95280, "src/Rosetta/codecs/video/H264/Cabac.luau"], -[96411, "src/Rosetta/codecs/video/H264/Cavlc.luau"], -[97179, "src/Rosetta/codecs/video/H264/Deblock.luau"], -[97437, "src/Rosetta/codecs/video/H264/Decoder.luau"], -[98446, "src/Rosetta/codecs/video/H264/Inter.luau"], -[98700, "src/Rosetta/codecs/video/H264/Intra.luau"], -[99107, "src/Rosetta/codecs/video/H264/Mb.luau"], -[100013, "src/Rosetta/codecs/video/H264/Params.luau"], -[100460, "src/Rosetta/codecs/video/H264/Slice.luau"], -[100711, "src/Rosetta/codecs/video/H264/Tables.luau"], -[100752, "src/Rosetta/codecs/video/H264/Transform.luau"], -[100917, "src/Rosetta/codecs/video/Legacy/init.luau"], -[101115, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], -[101412, "src/Rosetta/codecs/video/Legacy/Flic.luau"], -[101779, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], -[101897, "src/Rosetta/codecs/video/Legacy/Picture.luau"], -[102005, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], -[102278, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], -[102673, "src/Rosetta/codecs/video/Legacy/Smc.luau"], -[102850, "src/Rosetta/codecs/video/Mpeg1/init.luau"], -[102862, "src/Rosetta/codecs/video/Mpeg2/init.luau"], -[103229, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], -[104736, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], -[104875, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], -[105013, "src/Rosetta/codecs/video/Theora/init.luau"], -[105276, "src/Rosetta/codecs/video/Theora/Decoder.luau"], -[106540, "src/Rosetta/codecs/video/Theora/Header.luau"], -[106903, "src/Rosetta/codecs/video/Video/init.luau"], -[107460, "src/Rosetta/codecs/video/Video/Source.luau"], -[107745, "src/Rosetta/containers/Archive.luau"], -[108012, "src/Rosetta/containers/AudioWrap.luau"], -[108515, "src/Rosetta/containers/Avi/init.luau"], -[109067, "src/Rosetta/containers/Chunks.luau"], -[109202, "src/Rosetta/containers/Cpio.luau"], -[109630, "src/Rosetta/containers/Demux.luau"], -[109905, "src/Rosetta/containers/Ebml/init.luau"], -[110218, "src/Rosetta/containers/Fat.luau"], -[110906, "src/Rosetta/containers/Iso9660.luau"], -[111411, "src/Rosetta/containers/IsoBmff/init.luau"], -[111581, "src/Rosetta/containers/IsoBmff/Box.luau"], -[111769, "src/Rosetta/containers/IsoBmff/Demux.luau"], -[112614, "src/Rosetta/containers/IsoBmff/Meta.luau"], -[113135, "src/Rosetta/containers/IsoBmff/Mux.luau"], -[113651, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], -[113768, "src/Rosetta/containers/MacFile.luau"], -[113917, "src/Rosetta/containers/MpegEs.luau"], -[114083, "src/Rosetta/containers/MpegPs/init.luau"], -[114303, "src/Rosetta/containers/MpegTs/init.luau"], -[115095, "src/Rosetta/containers/Ogg/init.luau"], -[115520, "src/Rosetta/containers/Ogg/Mux.luau"], -[115715, "src/Rosetta/containers/Ogg/Page.luau"], -[115884, "src/Rosetta/containers/Riff/init.luau"], -[116201, "src/Rosetta/containers/Tar.luau"], -[116615, "src/Rosetta/containers/Zip/init.luau"], -[117247, "src/Rosetta/core/Adler32.luau"], -[117293, "src/Rosetta/core/Base64.luau"], -[117452, "src/Rosetta/core/Bits.luau"], -[117745, "src/Rosetta/core/Bytes.luau"], -[118272, "src/Rosetta/core/Crc16.luau"], -[118324, "src/Rosetta/core/Crc32.luau"], -[118436, "src/Rosetta/core/Err.luau"], -[118518, "src/Rosetta/core/Input.luau"], -[118594, "src/Rosetta/core/Md5.luau"], -[118753, "src/Rosetta/core/Sniff.luau"], -[118782, "src/Rosetta/data/cbor/init.luau"], -[118881, "src/Rosetta/data/cbor/Codec.luau"], -[119450, "src/Rosetta/data/csv/init.luau"], -[119762, "src/Rosetta/data/ini/init.luau"], -[120008, "src/Rosetta/data/json/init.luau"], -[120100, "src/Rosetta/data/msgpack/init.luau"], -[120189, "src/Rosetta/data/msgpack/Codec.luau"], -[120631, "src/Rosetta/data/nbt/init.luau"], -[120690, "src/Rosetta/data/plist/init.luau"], -[120996, "src/Rosetta/data/plist/Binary.luau"], -[121263, "src/Rosetta/data/q3shader/init.luau"], -[121502, "src/Rosetta/data/q3skin/init.luau"], -[121598, "src/Rosetta/data/snbt/init.luau"], -[121661, "src/Rosetta/data/toml/init.luau"], -[121728, "src/Rosetta/data/toml/Decode.luau"], -[122356, "src/Rosetta/data/toml/Encode.luau"], -[122565, "src/Rosetta/data/xml/init.luau"], -[122621, "src/Rosetta/data/yaml/init.luau"], -[122694, "src/Rosetta/data/yaml/Emit.luau"], -[122984, "src/Rosetta/data/yaml/Parse.luau"], -[124277, "src/Rosetta/font/bdf/init.luau"], -[124566, "src/Rosetta/font/bmfont/init.luau"], -[124993, "src/Rosetta/font/bmfont/Parse.luau"], -[125446, "src/Rosetta/font/eot/init.luau"], -[125678, "src/Rosetta/font/fon/init.luau"], -[125961, "src/Rosetta/font/hershey/init.luau"], -[126156, "src/Rosetta/font/pcf/init.luau"], -[126436, "src/Rosetta/font/psf/init.luau"], -[126756, "src/Rosetta/font/ttf/init.luau"], -[126807, "src/Rosetta/font/type1/init.luau"], -[127166, "src/Rosetta/font/type1/Charstring.luau"], -[127444, "src/Rosetta/font/woff/init.luau"], -[127576, "src/Rosetta/font/woff2/init.luau"], -[127633, "src/Rosetta/font/woff2/Rebuild.luau"], -[128173, "src/Rosetta/host/init.luau"], -[128218, "src/Rosetta/host/Love.luau"], -[128361, "src/Rosetta/host/LuaJIT.luau"], -[128411, "src/Rosetta/host/Luau.luau"], -[128434, "src/Rosetta/host/Roblox.luau"], -[128793, "src/Rosetta/image/ani/init.luau"], -[128973, "src/Rosetta/image/blp/init.luau"], -[129231, "src/Rosetta/image/bmp/init.luau"], -[129646, "src/Rosetta/image/dds/init.luau"], -[130129, "src/Rosetta/image/exr/init.luau"], -[130889, "src/Rosetta/image/exr/Codec.luau"], -[131000, "src/Rosetta/image/exr/Piz.luau"], -[131357, "src/Rosetta/image/gif/init.luau"], -[131873, "src/Rosetta/image/gif/Decode.luau"], -[131936, "src/Rosetta/image/hdr/init.luau"], -[132165, "src/Rosetta/image/hdr/Codec.luau"], -[132376, "src/Rosetta/image/icns/init.luau"], -[132707, "src/Rosetta/image/ico/init.luau"], -[132984, "src/Rosetta/image/ico/Dib.luau"], -[133079, "src/Rosetta/image/ilbm/init.luau"], -[133398, "src/Rosetta/image/jpeg/init.luau"], -[133534, "src/Rosetta/image/ktx/init.luau"], -[134194, "src/Rosetta/image/lmp/init.luau"], -[134327, "src/Rosetta/image/pcx/init.luau"], -[134591, "src/Rosetta/image/png/init.luau"], -[135171, "src/Rosetta/image/png/Apng.luau"], -[135251, "src/Rosetta/image/png/Decode.luau"], -[135491, "src/Rosetta/image/png/Encode.luau"], -[135646, "src/Rosetta/image/pnm/init.luau"], -[136024, "src/Rosetta/image/pnm/Codec.luau"], -[136301, "src/Rosetta/image/qoi/init.luau"], -[136423, "src/Rosetta/image/qoi/Codec.luau"], -[136573, "src/Rosetta/image/sgi/init.luau"], -[136858, "src/Rosetta/image/spr/init.luau"], -[137171, "src/Rosetta/image/sunras/init.luau"], -[137417, "src/Rosetta/image/tga/init.luau"], -[137687, "src/Rosetta/image/tga/Codec.luau"], -[137839, "src/Rosetta/image/tiff/init.luau"], -[138666, "src/Rosetta/image/tiff/Pixels.luau"], -[139056, "src/Rosetta/image/tim/init.luau"], -[139298, "src/Rosetta/image/vtf/init.luau"], -[139533, "src/Rosetta/image/webp/init.luau"], -[140143, "src/Rosetta/image/webp/Alpha.luau"], -[140219, "src/Rosetta/image/webp/Anim.luau"], -[140374, "src/Rosetta/image/xbm/init.luau"], -[140535, "src/Rosetta/image/xpm/init.luau"], -[140803, "src/Rosetta/image/xpm/Names.luau"], -[140859, "src/Rosetta/layered/aseprite/init.luau"], -[141597, "src/Rosetta/layered/ora/init.luau"], -[141884, "src/Rosetta/layered/psd/init.luau"], -[142619, "src/Rosetta/layered/psd/Channels.luau"], -[142971, "src/Rosetta/model/3ds/init.luau"], -[143054, "src/Rosetta/model/3ds/Build.luau"], -[143701, "src/Rosetta/model/3ds/Read.luau"], -[144197, "src/Rosetta/model/3ds/Write.luau"], -[145002, "src/Rosetta/model/3mf/init.luau"], -[145084, "src/Rosetta/model/3mf/Read.luau"], -[145672, "src/Rosetta/model/3mf/Write.luau"], -[146077, "src/Rosetta/model/b3d/init.luau"], -[146132, "src/Rosetta/model/b3d/Read.luau"], -[146703, "src/Rosetta/model/bsp/init.luau"], -[146894, "src/Rosetta/model/bsp/Lightmap.luau"], -[146960, "src/Rosetta/model/bsp/Quake.luau"], -[147347, "src/Rosetta/model/bsp/Quake3.luau"], -[147575, "src/Rosetta/model/bsp/Tree.luau"], -[147963, "src/Rosetta/model/dae/init.luau"], -[148152, "src/Rosetta/model/dae/Math.luau"], -[148199, "src/Rosetta/model/dae/Read.luau"], -[150049, "src/Rosetta/model/dae/Write.luau"], -[150418, "src/Rosetta/model/fbx/init.luau"], -[150566, "src/Rosetta/model/fbx/Ascii.luau"], -[150836, "src/Rosetta/model/fbx/Binary.luau"], -[151291, "src/Rosetta/model/fbx/Read.luau"], -[152653, "src/Rosetta/model/fbx/Write.luau"], -[153638, "src/Rosetta/model/fbx/Xform.luau"], -[153679, "src/Rosetta/model/gltf/init.luau"], -[153916, "src/Rosetta/model/gltf/Pack.luau"], -[153985, "src/Rosetta/model/gltf/Read.luau"], -[154716, "src/Rosetta/model/gltf/Write.luau"], -[155396, "src/Rosetta/model/iqm/init.luau"], -[155472, "src/Rosetta/model/iqm/Read.luau"], -[155827, "src/Rosetta/model/iqm/Write.luau"], -[156514, "src/Rosetta/model/ldraw/init.luau"], -[156592, "src/Rosetta/model/ldraw/Colors.luau"], -[156910, "src/Rosetta/model/ldraw/Read.luau"], -[157487, "src/Rosetta/model/lwo/init.luau"], -[157563, "src/Rosetta/model/lwo/Build.luau"], -[158025, "src/Rosetta/model/lwo/Parse.luau"], -[158568, "src/Rosetta/model/map/init.luau"], -[158885, "src/Rosetta/model/map/Build.luau"], -[159128, "src/Rosetta/model/map/Parse.luau"], -[159513, "src/Rosetta/model/map/Write.luau"], -[159659, "src/Rosetta/model/mca/init.luau"], -[160001, "src/Rosetta/model/mca/Chunk.luau"], -[160134, "src/Rosetta/model/mca/Lz4Block.luau"], -[160204, "src/Rosetta/model/md2/init.luau"], -[160403, "src/Rosetta/model/md3/init.luau"], -[160631, "src/Rosetta/model/md5/init.luau"], -[160712, "src/Rosetta/model/md5/Read.luau"], -[161145, "src/Rosetta/model/mdl/init.luau"], -[161227, "src/Rosetta/model/mdl/HalfLife.luau"], -[161555, "src/Rosetta/model/mdl/Quake.luau"], -[161773, "src/Rosetta/model/ms3d/init.luau"], -[161845, "src/Rosetta/model/ms3d/Read.luau"], -[162291, "src/Rosetta/model/ms3d/Write.luau"], -[162760, "src/Rosetta/model/obj/init.luau"], -[163502, "src/Rosetta/model/obj/Mtl.luau"], -[163789, "src/Rosetta/model/off/init.luau"], -[164251, "src/Rosetta/model/ply/init.luau"], -[165356, "src/Rosetta/model/ply/Binary.luau"], -[165557, "src/Rosetta/model/pmx/init.luau"], -[165626, "src/Rosetta/model/pmx/Build.luau"], -[165922, "src/Rosetta/model/pmx/Pmd.luau"], -[166257, "src/Rosetta/model/pmx/Read.luau"], -[166661, "src/Rosetta/model/qb/init.luau"], -[167054, "src/Rosetta/model/rbxm/init.luau"], -[167646, "src/Rosetta/model/rbxmx/init.luau"], -[168299, "src/Rosetta/model/robloxmesh/init.luau"], -[168958, "src/Rosetta/model/robloxmesh/Parse.luau"], -[169415, "src/Rosetta/model/robloxmesh/Write.luau"], -[169524, "src/Rosetta/model/schematic/init.luau"], -[169845, "src/Rosetta/model/schematic/Common.luau"], -[169965, "src/Rosetta/model/schematic/Litematic.luau"], -[170176, "src/Rosetta/model/schematic/Mcedit.luau"], -[170420, "src/Rosetta/model/schematic/Sponge.luau"], -[170549, "src/Rosetta/model/smd/init.luau"], -[170616, "src/Rosetta/model/smd/Read.luau"], -[170885, "src/Rosetta/model/smd/Write.luau"], -[171128, "src/Rosetta/model/stl/init.luau"], -[171578, "src/Rosetta/model/stl/Decode.luau"], -[171652, "src/Rosetta/model/usda/init.luau"], -[171861, "src/Rosetta/model/usda/Build.luau"], -[173139, "src/Rosetta/model/usda/Parse.luau"], -[173937, "src/Rosetta/model/usda/Write.luau"], -[174754, "src/Rosetta/model/vox/init.luau"], -[175640, "src/Rosetta/model/vox/Grid.luau"], -[175697, "src/Rosetta/model/vrml/init.luau"], -[175763, "src/Rosetta/model/x/init.luau"], -[175893, "src/Rosetta/model/x/Build.luau"], -[176456, "src/Rosetta/model/x/Parse.luau"], -[176753, "src/Rosetta/model/x3d/init.luau"], -[176831, "src/Rosetta/music/669/init.luau"], -[177037, "src/Rosetta/music/ahx/init.luau"], -[177088, "src/Rosetta/music/far/init.luau"], -[177317, "src/Rosetta/music/hmp/init.luau"], -[177581, "src/Rosetta/music/hvl/init.luau"], -[177632, "src/Rosetta/music/it/init.luau"], -[178050, "src/Rosetta/music/it/Itsex.luau"], -[178166, "src/Rosetta/music/med/init.luau"], -[178813, "src/Rosetta/music/midi/init.luau"], -[178956, "src/Rosetta/music/midi/Smf.luau"], -[179367, "src/Rosetta/music/mod/init.luau"], -[179720, "src/Rosetta/music/mtm/init.luau"], -[179942, "src/Rosetta/music/mus/init.luau"], -[180099, "src/Rosetta/music/okt/init.luau"], -[180380, "src/Rosetta/music/ptm/init.luau"], -[180602, "src/Rosetta/music/s3m/init.luau"], -[180838, "src/Rosetta/music/sf2/init.luau"], -[180881, "src/Rosetta/music/stm/init.luau"], -[181112, "src/Rosetta/music/ult/init.luau"], -[181416, "src/Rosetta/music/umx/init.luau"], -[181632, "src/Rosetta/music/xm/init.luau"], -[182193, "src/Rosetta/music/xmi/init.luau"], -[182401, "src/Rosetta/ops/AudioOps.luau"], -[182850, "src/Rosetta/ops/ImageOps/init.luau"], -[183494, "src/Rosetta/ops/ImageOps/Kernels.luau"], -[184004, "src/Rosetta/ops/LayerOps.luau"], -[184097, "src/Rosetta/ops/MeshOps/init.luau"], -[185133, "src/Rosetta/ops/MeshOps/Greedy.luau"], -[185300, "src/Rosetta/ops/MusicOps.luau"], -[185648, "src/Rosetta/playlist/m3u/init.luau"], -[186001, "src/Rosetta/playlist/pls/init.luau"], -[186179, "src/Rosetta/playlist/xspf/init.luau"], -[186382, "src/Rosetta/subtitle/ass/init.luau"], -[186826, "src/Rosetta/subtitle/srt/init.luau"], -[186999, "src/Rosetta/subtitle/vtt/init.luau"], -[187202, "src/Rosetta/vector/svg/init.luau"], -[187288, "src/Rosetta/vector/svg/Parse.luau"], -[188034, "src/Rosetta/vector/svg/PathData.luau"], -[188402, "src/Rosetta/vector/svg/Render.luau"], -[188819, "src/Rosetta/vector/svg/Style.luau"], -[189191, "src/Rosetta/vector/svg/Write.luau"], -[189391, "src/Rosetta/vector/tiled/init.luau"], -[189571, "src/Rosetta/vector/tiled/Data.luau"], -[189722, "src/Rosetta/vector/tiled/Tmj.luau"], -[190353, "src/Rosetta/vector/tiled/Tmx.luau"], -[190965, "src/Rosetta/video/avi/init.luau"], -[191259, "src/Rosetta/video/fli/init.luau"], -[191410, "src/Rosetta/video/flv/init.luau"], -[191794, "src/Rosetta/video/flv/Amf.luau"], -[191952, "src/Rosetta/video/flv/Mux.luau"], -[192233, "src/Rosetta/video/h264/init.luau"], -[192372, "src/Rosetta/video/mkv/init.luau"], -[192528, "src/Rosetta/video/mkv/Mux.luau"], -[192807, "src/Rosetta/video/mkv/Parse.luau"], -[193528, "src/Rosetta/video/mp4/init.luau"], -[193856, "src/Rosetta/video/mpegps/init.luau"], -[194043, "src/Rosetta/video/mpegts/init.luau"], -[194281, "src/Rosetta/video/ogv/init.luau"], -[194676, "src/Rosetta/video/smk/init.luau"], -[194985, "src/Rosetta/video/smk/Audio.luau"], -[195105, "src/Rosetta/video/y4m/init.luau"] +[3136, "src/Rosetta/Types.luau"], +[4219, "src/Rosetta/archive/7z/init.luau"], +[4604, "src/Rosetta/archive/7z/Header.luau"], +[5131, "src/Rosetta/archive/adf/init.luau"], +[5413, "src/Rosetta/archive/applesingle/init.luau"], +[5599, "src/Rosetta/archive/ar/init.luau"], +[6002, "src/Rosetta/archive/arj/init.luau"], +[6212, "src/Rosetta/archive/binhex/init.luau"], +[6461, "src/Rosetta/archive/br/init.luau"], +[6536, "src/Rosetta/archive/bz2/init.luau"], +[6600, "src/Rosetta/archive/cab/init.luau"], +[7013, "src/Rosetta/archive/cab/Sum.luau"], +[7054, "src/Rosetta/archive/cpio/init.luau"], +[7222, "src/Rosetta/archive/d64/init.luau"], +[7636, "src/Rosetta/archive/fat/init.luau"], +[7758, "src/Rosetta/archive/grp/init.luau"], +[7872, "src/Rosetta/archive/gzip/init.luau"], +[8057, "src/Rosetta/archive/iso/init.luau"], +[8129, "src/Rosetta/archive/lha/init.luau"], +[8554, "src/Rosetta/archive/lz4/init.luau"], +[8898, "src/Rosetta/archive/macbinary/init.luau"], +[9096, "src/Rosetta/archive/mpq/init.luau"], +[9502, "src/Rosetta/archive/mpq/Crypt.luau"], +[9567, "src/Rosetta/archive/pak/init.luau"], +[9701, "src/Rosetta/archive/rpm/init.luau"], +[10025, "src/Rosetta/archive/tar/init.luau"], +[10143, "src/Rosetta/archive/unitypackage/init.luau"], +[10379, "src/Rosetta/archive/uu/init.luau"], +[10649, "src/Rosetta/archive/vpk/init.luau"], +[10960, "src/Rosetta/archive/wad/init.luau"], +[11410, "src/Rosetta/archive/wad/Map.luau"], +[11840, "src/Rosetta/archive/wad/Picture.luau"], +[11942, "src/Rosetta/archive/wad2/init.luau"], +[12224, "src/Rosetta/archive/xz/init.luau"], +[12324, "src/Rosetta/archive/yenc/init.luau"], +[12596, "src/Rosetta/archive/z/init.luau"], +[12692, "src/Rosetta/archive/zip/init.luau"], +[12911, "src/Rosetta/archive/zoo/init.luau"], +[13107, "src/Rosetta/archive/zst/init.luau"], +[13171, "src/Rosetta/audio/aac/init.luau"], +[13377, "src/Rosetta/audio/ac3/init.luau"], +[13523, "src/Rosetta/audio/adpcm/init.luau"], +[13668, "src/Rosetta/audio/adx/init.luau"], +[13899, "src/Rosetta/audio/aiff/init.luau"], +[14290, "src/Rosetta/audio/ape/init.luau"], +[14418, "src/Rosetta/audio/au/init.luau"], +[14579, "src/Rosetta/audio/brstm/init.luau"], +[14870, "src/Rosetta/audio/caf/init.luau"], +[15532, "src/Rosetta/audio/flac/init.luau"], +[15680, "src/Rosetta/audio/flac/Meta.luau"], +[15902, "src/Rosetta/audio/flac/Stream.luau"], +[16272, "src/Rosetta/audio/m4a/init.luau"], +[16606, "src/Rosetta/audio/mp3/init.luau"], +[16866, "src/Rosetta/audio/mp3/Index.luau"], +[17057, "src/Rosetta/audio/mp3/Stream.luau"], +[17284, "src/Rosetta/audio/mp3/Tags.luau"], +[17596, "src/Rosetta/audio/mpc/init.luau"], +[17690, "src/Rosetta/audio/opus/init.luau"], +[18068, "src/Rosetta/audio/opus/Encode.luau"], +[18179, "src/Rosetta/audio/qoa/init.luau"], +[18359, "src/Rosetta/audio/tta/init.luau"], +[18477, "src/Rosetta/audio/vag/init.luau"], +[18700, "src/Rosetta/audio/voc/init.luau"], +[18975, "src/Rosetta/audio/vorbis/init.luau"], +[19429, "src/Rosetta/audio/vorbis/Encode.luau"], +[20242, "src/Rosetta/audio/wav/init.luau"], +[20863, "src/Rosetta/audio/wav/Codecs.luau"], +[21029, "src/Rosetta/audio/wavpack/init.luau"], +[21236, "src/Rosetta/cad/step/init.luau"], +[21618, "src/Rosetta/cad/step/Brep.luau"], +[21853, "src/Rosetta/cad/step/Parse.luau"], +[22410, "src/Rosetta/cad/step/Write.luau"], +[22658, "src/Rosetta/codecs/audio/Aac/init.luau"], +[22977, "src/Rosetta/codecs/audio/Aac/Decode.luau"], +[23860, "src/Rosetta/codecs/audio/Aac/Tables.luau"], +[24195, "src/Rosetta/codecs/audio/Ac3/init.luau"], +[24354, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], +[25239, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], +[25340, "src/Rosetta/codecs/audio/Adpcm/init.luau"], +[26094, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], +[26396, "src/Rosetta/codecs/audio/Alac/init.luau"], +[26630, "src/Rosetta/codecs/audio/Alac/Decode.luau"], +[27049, "src/Rosetta/codecs/audio/Alac/Encode.luau"], +[27461, "src/Rosetta/codecs/audio/Ape/init.luau"], +[27676, "src/Rosetta/codecs/audio/Ape/Decode.luau"], +[28437, "src/Rosetta/codecs/audio/ApeTag.luau"], +[28534, "src/Rosetta/codecs/audio/Flac/init.luau"], +[28545, "src/Rosetta/codecs/audio/Flac/Encode.luau"], +[29494, "src/Rosetta/codecs/audio/Flac/Frame.luau"], +[30091, "src/Rosetta/codecs/audio/Hively/init.luau"], +[30287, "src/Rosetta/codecs/audio/Hively/Load.luau"], +[30536, "src/Rosetta/codecs/audio/Hively/Player.luau"], +[31494, "src/Rosetta/codecs/audio/Hively/Tables.luau"], +[31713, "src/Rosetta/codecs/audio/Mdct/init.luau"], +[31897, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], +[32106, "src/Rosetta/codecs/audio/MidiRender.luau"], +[32452, "src/Rosetta/codecs/audio/Mpa/init.luau"], +[32466, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], +[32525, "src/Rosetta/codecs/audio/Mpa/Core.luau"], +[34128, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], +[34420, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], +[34805, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], +[35446, "src/Rosetta/codecs/audio/Mpa/Header.luau"], +[35587, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], +[35813, "src/Rosetta/codecs/audio/Musepack/init.luau"], +[36158, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], +[37039, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], +[37417, "src/Rosetta/codecs/audio/Opus/init.luau"], +[37431, "src/Rosetta/codecs/audio/Opus/Celt.luau"], +[39278, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], +[40343, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], +[40403, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], +[40863, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], +[41200, "src/Rosetta/codecs/audio/Opus/Packet.luau"], +[41433, "src/Rosetta/codecs/audio/Opus/Silk.luau"], +[43469, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], +[43843, "src/Rosetta/codecs/audio/Pcm/init.luau"], +[44106, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], +[44403, "src/Rosetta/codecs/audio/Qoa/init.luau"], +[44685, "src/Rosetta/codecs/audio/Resample/init.luau"], +[45044, "src/Rosetta/codecs/audio/SoundFont/init.luau"], +[45098, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], +[45241, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], +[45754, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], +[46535, "src/Rosetta/codecs/audio/Stream.luau"], +[46696, "src/Rosetta/codecs/audio/Tracker/init.luau"], +[47178, "src/Rosetta/codecs/audio/Tracker/Load.luau"], +[47456, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], +[47625, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], +[47753, "src/Rosetta/codecs/audio/Tracker/Player.luau"], +[49741, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], +[49857, "src/Rosetta/codecs/audio/Tta/init.luau"], +[49974, "src/Rosetta/codecs/audio/Tta/Decode.luau"], +[50226, "src/Rosetta/codecs/audio/Vorbis/init.luau"], +[50239, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], +[50623, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], +[51189, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], +[51610, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], +[51649, "src/Rosetta/codecs/audio/VorbisComment.luau"], +[51701, "src/Rosetta/codecs/audio/WavPack/init.luau"], +[51923, "src/Rosetta/codecs/audio/WavPack/Block.luau"], +[53378, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], +[53441, "src/Rosetta/codecs/compress/Brotli/init.luau"], +[53528, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], +[54497, "src/Rosetta/codecs/compress/Brotli/Static.luau"], +[55365, "src/Rosetta/codecs/compress/Bzip2/init.luau"], +[55413, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], +[55929, "src/Rosetta/codecs/compress/Deflate/init.luau"], +[56255, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], +[56675, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], +[57110, "src/Rosetta/codecs/compress/Explode.luau"], +[57306, "src/Rosetta/codecs/compress/Lz4.luau"], +[57575, "src/Rosetta/codecs/compress/Lzh/init.luau"], +[58179, "src/Rosetta/codecs/compress/Lzma/init.luau"], +[58719, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], +[58757, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], +[59230, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], +[59406, "src/Rosetta/codecs/compress/Lzw/init.luau"], +[59674, "src/Rosetta/codecs/compress/Lzx.luau"], +[60108, "src/Rosetta/codecs/compress/PackBits.luau"], +[60198, "src/Rosetta/codecs/compress/Quantum.luau"], +[60435, "src/Rosetta/codecs/compress/UnixCompress.luau"], +[60739, "src/Rosetta/codecs/compress/Xxh32.luau"], +[60808, "src/Rosetta/codecs/compress/Zstd/init.luau"], +[60865, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], +[61823, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], +[61975, "src/Rosetta/codecs/entropy/Huffman.luau"], +[62257, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], +[62268, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], +[62482, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], +[62726, "src/Rosetta/codecs/font/Bitmap.luau"], +[62927, "src/Rosetta/codecs/font/Cff/init.luau"], +[63568, "src/Rosetta/codecs/font/GlyphNames.luau"], +[63718, "src/Rosetta/codecs/font/TrueType/init.luau"], +[64032, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], +[64424, "src/Rosetta/codecs/font/TrueType/Tables.luau"], +[64926, "src/Rosetta/codecs/image/Bcn/init.luau"], +[65033, "src/Rosetta/codecs/image/Bcn/Decode.luau"], +[65522, "src/Rosetta/codecs/image/Bcn/Encode.luau"], +[65951, "src/Rosetta/codecs/image/Blend.luau"], +[66330, "src/Rosetta/codecs/image/Dct/init.luau"], +[66711, "src/Rosetta/codecs/image/Etc.luau"], +[67009, "src/Rosetta/codecs/image/Half.luau"], +[67078, "src/Rosetta/codecs/image/Jpeg/init.luau"], +[67432, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], +[67840, "src/Rosetta/codecs/image/Jpeg/Color.luau"], +[68077, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], +[68837, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], +[69718, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], +[70164, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], +[70242, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], +[70309, "src/Rosetta/codecs/image/Miptex.luau"], +[70609, "src/Rosetta/codecs/image/Pixels.luau"], +[70929, "src/Rosetta/codecs/image/Quantize/init.luau"], +[71388, "src/Rosetta/codecs/image/Raster.luau"], +[72085, "src/Rosetta/codecs/image/Texel.luau"], +[72458, "src/Rosetta/codecs/image/Texture.luau"], +[72603, "src/Rosetta/codecs/image/Vp8/init.luau"], +[72733, "src/Rosetta/codecs/image/Vp8/Decode.luau"], +[74689, "src/Rosetta/codecs/image/Vp8/Predict.luau"], +[74948, "src/Rosetta/codecs/image/Vp8/Tables.luau"], +[75197, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], +[75316, "src/Rosetta/codecs/image/Vp8L/init.luau"], +[75420, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], +[76273, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], +[77225, "src/Rosetta/codecs/image/Yuv.luau"], +[77493, "src/Rosetta/codecs/model/Brush.luau"], +[78133, "src/Rosetta/codecs/model/Draco/init.luau"], +[78465, "src/Rosetta/codecs/model/Draco/Attributes.luau"], +[78934, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], +[80123, "src/Rosetta/codecs/model/Draco/Int64.luau"], +[80272, "src/Rosetta/codecs/model/Draco/KdTree.luau"], +[80631, "src/Rosetta/codecs/model/Draco/Predict.luau"], +[81593, "src/Rosetta/codecs/model/Draco/Reader.luau"], +[82067, "src/Rosetta/codecs/model/Mat4.luau"], +[82326, "src/Rosetta/codecs/model/MeshFlatten.luau"], +[82854, "src/Rosetta/codecs/model/Minecraft/init.luau"], +[83406, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], +[83485, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], +[83592, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], +[83798, "src/Rosetta/codecs/model/Patch.luau"], +[83922, "src/Rosetta/codecs/model/Polygon.luau"], +[84156, "src/Rosetta/codecs/model/Rbx/init.luau"], +[84393, "src/Rosetta/codecs/model/Rbx/Binary.luau"], +[85147, "src/Rosetta/codecs/model/Rig.luau"], +[85390, "src/Rosetta/codecs/model/Sampler.luau"], +[85550, "src/Rosetta/codecs/model/Vrml/init.luau"], +[85698, "src/Rosetta/codecs/model/Vrml/Build.luau"], +[86272, "src/Rosetta/codecs/model/Vrml/Fields.luau"], +[86435, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], +[87184, "src/Rosetta/codecs/model/Vrml/Parse.luau"], +[87706, "src/Rosetta/codecs/model/Vrml/Write.luau"], +[88433, "src/Rosetta/codecs/model/Vrml/Xml.luau"], +[88665, "src/Rosetta/codecs/text/GodotVariant.luau"], +[89324, "src/Rosetta/codecs/text/Json/init.luau"], +[89593, "src/Rosetta/codecs/text/Json/Decode.luau"], +[90007, "src/Rosetta/codecs/text/Json/Encode.luau"], +[90309, "src/Rosetta/codecs/text/Nbt/init.luau"], +[90662, "src/Rosetta/codecs/text/Nbt/Binary.luau"], +[91354, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], +[91994, "src/Rosetta/codecs/text/Nbt/Value.luau"], +[92232, "src/Rosetta/codecs/text/Text/init.luau"], +[92323, "src/Rosetta/codecs/text/Url/init.luau"], +[92528, "src/Rosetta/codecs/text/Xml/init.luau"], +[92931, "src/Rosetta/codecs/text/Xml/Parse.luau"], +[93671, "src/Rosetta/codecs/video/Dsp.luau"], +[94394, "src/Rosetta/codecs/video/H263/init.luau"], +[94550, "src/Rosetta/codecs/video/H263/Decoder.luau"], +[95408, "src/Rosetta/codecs/video/H263/Tables.luau"], +[95611, "src/Rosetta/codecs/video/H264/init.luau"], +[95984, "src/Rosetta/codecs/video/H264/Bitstream.luau"], +[96259, "src/Rosetta/codecs/video/H264/Cabac.luau"], +[97390, "src/Rosetta/codecs/video/H264/Cavlc.luau"], +[98158, "src/Rosetta/codecs/video/H264/Deblock.luau"], +[98416, "src/Rosetta/codecs/video/H264/Decoder.luau"], +[99425, "src/Rosetta/codecs/video/H264/Inter.luau"], +[99679, "src/Rosetta/codecs/video/H264/Intra.luau"], +[100086, "src/Rosetta/codecs/video/H264/Mb.luau"], +[100992, "src/Rosetta/codecs/video/H264/Params.luau"], +[101439, "src/Rosetta/codecs/video/H264/Slice.luau"], +[101690, "src/Rosetta/codecs/video/H264/Tables.luau"], +[101731, "src/Rosetta/codecs/video/H264/Transform.luau"], +[101896, "src/Rosetta/codecs/video/Legacy/init.luau"], +[102094, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], +[102391, "src/Rosetta/codecs/video/Legacy/Flic.luau"], +[102758, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], +[102876, "src/Rosetta/codecs/video/Legacy/Picture.luau"], +[102984, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], +[103257, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], +[103652, "src/Rosetta/codecs/video/Legacy/Smc.luau"], +[103829, "src/Rosetta/codecs/video/Mpeg1/init.luau"], +[103841, "src/Rosetta/codecs/video/Mpeg2/init.luau"], +[104208, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], +[105715, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], +[105854, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], +[105992, "src/Rosetta/codecs/video/Theora/init.luau"], +[106255, "src/Rosetta/codecs/video/Theora/Decoder.luau"], +[107519, "src/Rosetta/codecs/video/Theora/Header.luau"], +[107882, "src/Rosetta/codecs/video/Video/init.luau"], +[108439, "src/Rosetta/codecs/video/Video/Source.luau"], +[108724, "src/Rosetta/containers/Archive.luau"], +[108991, "src/Rosetta/containers/AudioWrap.luau"], +[109494, "src/Rosetta/containers/Avi/init.luau"], +[110046, "src/Rosetta/containers/Chunks.luau"], +[110181, "src/Rosetta/containers/Cpio.luau"], +[110609, "src/Rosetta/containers/Demux.luau"], +[110884, "src/Rosetta/containers/Ebml/init.luau"], +[111197, "src/Rosetta/containers/Fat.luau"], +[111885, "src/Rosetta/containers/Iso9660.luau"], +[112390, "src/Rosetta/containers/IsoBmff/init.luau"], +[112560, "src/Rosetta/containers/IsoBmff/Box.luau"], +[112748, "src/Rosetta/containers/IsoBmff/Demux.luau"], +[113593, "src/Rosetta/containers/IsoBmff/Meta.luau"], +[114114, "src/Rosetta/containers/IsoBmff/Mux.luau"], +[114630, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], +[114747, "src/Rosetta/containers/MacFile.luau"], +[114896, "src/Rosetta/containers/MpegEs.luau"], +[115062, "src/Rosetta/containers/MpegPs/init.luau"], +[115282, "src/Rosetta/containers/MpegTs/init.luau"], +[116074, "src/Rosetta/containers/Ogg/init.luau"], +[116499, "src/Rosetta/containers/Ogg/Mux.luau"], +[116694, "src/Rosetta/containers/Ogg/Page.luau"], +[116863, "src/Rosetta/containers/Riff/init.luau"], +[117180, "src/Rosetta/containers/Tar.luau"], +[117594, "src/Rosetta/containers/Zip/init.luau"], +[118226, "src/Rosetta/core/Adler32.luau"], +[118272, "src/Rosetta/core/Base64.luau"], +[118431, "src/Rosetta/core/Bits.luau"], +[118724, "src/Rosetta/core/Bytes.luau"], +[119251, "src/Rosetta/core/Crc16.luau"], +[119303, "src/Rosetta/core/Crc32.luau"], +[119415, "src/Rosetta/core/Err.luau"], +[119497, "src/Rosetta/core/Input.luau"], +[119573, "src/Rosetta/core/Md5.luau"], +[119732, "src/Rosetta/core/Sniff.luau"], +[119761, "src/Rosetta/data/cbor/init.luau"], +[119860, "src/Rosetta/data/cbor/Codec.luau"], +[120429, "src/Rosetta/data/csv/init.luau"], +[120741, "src/Rosetta/data/ini/init.luau"], +[120987, "src/Rosetta/data/json/init.luau"], +[121079, "src/Rosetta/data/msgpack/init.luau"], +[121168, "src/Rosetta/data/msgpack/Codec.luau"], +[121610, "src/Rosetta/data/nbt/init.luau"], +[121669, "src/Rosetta/data/plist/init.luau"], +[121975, "src/Rosetta/data/plist/Binary.luau"], +[122242, "src/Rosetta/data/q3shader/init.luau"], +[122481, "src/Rosetta/data/q3skin/init.luau"], +[122577, "src/Rosetta/data/snbt/init.luau"], +[122640, "src/Rosetta/data/toml/init.luau"], +[122707, "src/Rosetta/data/toml/Decode.luau"], +[123335, "src/Rosetta/data/toml/Encode.luau"], +[123544, "src/Rosetta/data/tres/init.luau"], +[123689, "src/Rosetta/data/xml/init.luau"], +[123745, "src/Rosetta/data/yaml/init.luau"], +[123818, "src/Rosetta/data/yaml/Emit.luau"], +[124108, "src/Rosetta/data/yaml/Parse.luau"], +[125401, "src/Rosetta/font/bdf/init.luau"], +[125690, "src/Rosetta/font/bmfont/init.luau"], +[126117, "src/Rosetta/font/bmfont/Parse.luau"], +[126570, "src/Rosetta/font/eot/init.luau"], +[126802, "src/Rosetta/font/fon/init.luau"], +[127085, "src/Rosetta/font/hershey/init.luau"], +[127280, "src/Rosetta/font/pcf/init.luau"], +[127560, "src/Rosetta/font/psf/init.luau"], +[127880, "src/Rosetta/font/ttf/init.luau"], +[127931, "src/Rosetta/font/type1/init.luau"], +[128290, "src/Rosetta/font/type1/Charstring.luau"], +[128568, "src/Rosetta/font/woff/init.luau"], +[128700, "src/Rosetta/font/woff2/init.luau"], +[128757, "src/Rosetta/font/woff2/Rebuild.luau"], +[129297, "src/Rosetta/host/init.luau"], +[129342, "src/Rosetta/host/Love.luau"], +[129485, "src/Rosetta/host/LuaJIT.luau"], +[129535, "src/Rosetta/host/Luau.luau"], +[129558, "src/Rosetta/host/Roblox.luau"], +[129917, "src/Rosetta/image/ani/init.luau"], +[130097, "src/Rosetta/image/blp/init.luau"], +[130355, "src/Rosetta/image/bmp/init.luau"], +[130770, "src/Rosetta/image/dds/init.luau"], +[131253, "src/Rosetta/image/exr/init.luau"], +[132013, "src/Rosetta/image/exr/Codec.luau"], +[132124, "src/Rosetta/image/exr/Piz.luau"], +[132481, "src/Rosetta/image/gif/init.luau"], +[132997, "src/Rosetta/image/gif/Decode.luau"], +[133060, "src/Rosetta/image/hdr/init.luau"], +[133289, "src/Rosetta/image/hdr/Codec.luau"], +[133500, "src/Rosetta/image/icns/init.luau"], +[133831, "src/Rosetta/image/ico/init.luau"], +[134108, "src/Rosetta/image/ico/Dib.luau"], +[134203, "src/Rosetta/image/ilbm/init.luau"], +[134522, "src/Rosetta/image/jpeg/init.luau"], +[134658, "src/Rosetta/image/ktx/init.luau"], +[135318, "src/Rosetta/image/lmp/init.luau"], +[135451, "src/Rosetta/image/pcx/init.luau"], +[135715, "src/Rosetta/image/png/init.luau"], +[136295, "src/Rosetta/image/png/Apng.luau"], +[136375, "src/Rosetta/image/png/Decode.luau"], +[136615, "src/Rosetta/image/png/Encode.luau"], +[136770, "src/Rosetta/image/pnm/init.luau"], +[137148, "src/Rosetta/image/pnm/Codec.luau"], +[137425, "src/Rosetta/image/qoi/init.luau"], +[137547, "src/Rosetta/image/qoi/Codec.luau"], +[137697, "src/Rosetta/image/sgi/init.luau"], +[137982, "src/Rosetta/image/spr/init.luau"], +[138295, "src/Rosetta/image/sunras/init.luau"], +[138541, "src/Rosetta/image/tga/init.luau"], +[138811, "src/Rosetta/image/tga/Codec.luau"], +[138963, "src/Rosetta/image/tiff/init.luau"], +[139790, "src/Rosetta/image/tiff/Pixels.luau"], +[140180, "src/Rosetta/image/tim/init.luau"], +[140422, "src/Rosetta/image/vtf/init.luau"], +[140657, "src/Rosetta/image/webp/init.luau"], +[141267, "src/Rosetta/image/webp/Alpha.luau"], +[141343, "src/Rosetta/image/webp/Anim.luau"], +[141498, "src/Rosetta/image/xbm/init.luau"], +[141659, "src/Rosetta/image/xpm/init.luau"], +[141927, "src/Rosetta/image/xpm/Names.luau"], +[141983, "src/Rosetta/layered/aseprite/init.luau"], +[142721, "src/Rosetta/layered/ora/init.luau"], +[143008, "src/Rosetta/layered/psd/init.luau"], +[143743, "src/Rosetta/layered/psd/Channels.luau"], +[144095, "src/Rosetta/model/3ds/init.luau"], +[144178, "src/Rosetta/model/3ds/Build.luau"], +[144825, "src/Rosetta/model/3ds/Read.luau"], +[145321, "src/Rosetta/model/3ds/Write.luau"], +[146126, "src/Rosetta/model/3mf/init.luau"], +[146208, "src/Rosetta/model/3mf/Read.luau"], +[146796, "src/Rosetta/model/3mf/Write.luau"], +[147201, "src/Rosetta/model/ase/init.luau"], +[147324, "src/Rosetta/model/ase/Build.luau"], +[147898, "src/Rosetta/model/ase/Parse.luau"], +[147967, "src/Rosetta/model/ase/Write.luau"], +[148430, "src/Rosetta/model/b3d/init.luau"], +[148485, "src/Rosetta/model/b3d/Read.luau"], +[149056, "src/Rosetta/model/bsp/init.luau"], +[149247, "src/Rosetta/model/bsp/Lightmap.luau"], +[149313, "src/Rosetta/model/bsp/Quake.luau"], +[149700, "src/Rosetta/model/bsp/Quake3.luau"], +[149928, "src/Rosetta/model/bsp/Tree.luau"], +[150316, "src/Rosetta/model/dae/init.luau"], +[150505, "src/Rosetta/model/dae/Math.luau"], +[150552, "src/Rosetta/model/dae/Read.luau"], +[152402, "src/Rosetta/model/dae/Write.luau"], +[152771, "src/Rosetta/model/fbx/init.luau"], +[152919, "src/Rosetta/model/fbx/Ascii.luau"], +[153189, "src/Rosetta/model/fbx/Binary.luau"], +[153644, "src/Rosetta/model/fbx/Read.luau"], +[155006, "src/Rosetta/model/fbx/Write.luau"], +[155991, "src/Rosetta/model/fbx/Xform.luau"], +[156032, "src/Rosetta/model/gltf/init.luau"], +[156269, "src/Rosetta/model/gltf/Pack.luau"], +[156338, "src/Rosetta/model/gltf/Read.luau"], +[157069, "src/Rosetta/model/gltf/Write.luau"], +[157749, "src/Rosetta/model/godot/init.luau"], +[157840, "src/Rosetta/model/godot/Build.luau"], +[158382, "src/Rosetta/model/godot/Primitives.luau"], +[158657, "src/Rosetta/model/godot/Surface.luau"], +[159142, "src/Rosetta/model/godot/Write.luau"], +[159471, "src/Rosetta/model/iqm/init.luau"], +[159547, "src/Rosetta/model/iqm/Read.luau"], +[159902, "src/Rosetta/model/iqm/Write.luau"], +[160589, "src/Rosetta/model/ldraw/init.luau"], +[160667, "src/Rosetta/model/ldraw/Colors.luau"], +[160985, "src/Rosetta/model/ldraw/Read.luau"], +[161562, "src/Rosetta/model/lwo/init.luau"], +[161638, "src/Rosetta/model/lwo/Build.luau"], +[162100, "src/Rosetta/model/lwo/Parse.luau"], +[162643, "src/Rosetta/model/map/init.luau"], +[162960, "src/Rosetta/model/map/Build.luau"], +[163203, "src/Rosetta/model/map/Parse.luau"], +[163588, "src/Rosetta/model/map/Write.luau"], +[163734, "src/Rosetta/model/mca/init.luau"], +[164076, "src/Rosetta/model/mca/Chunk.luau"], +[164209, "src/Rosetta/model/mca/Lz4Block.luau"], +[164279, "src/Rosetta/model/md2/init.luau"], +[164478, "src/Rosetta/model/md3/init.luau"], +[164706, "src/Rosetta/model/md5/init.luau"], +[164787, "src/Rosetta/model/md5/Read.luau"], +[165220, "src/Rosetta/model/mdl/init.luau"], +[165302, "src/Rosetta/model/mdl/HalfLife.luau"], +[165630, "src/Rosetta/model/mdl/Quake.luau"], +[165848, "src/Rosetta/model/ms3d/init.luau"], +[165920, "src/Rosetta/model/ms3d/Read.luau"], +[166366, "src/Rosetta/model/ms3d/Write.luau"], +[166835, "src/Rosetta/model/obj/init.luau"], +[167577, "src/Rosetta/model/obj/Mtl.luau"], +[167864, "src/Rosetta/model/off/init.luau"], +[168326, "src/Rosetta/model/ply/init.luau"], +[169431, "src/Rosetta/model/ply/Binary.luau"], +[169632, "src/Rosetta/model/pmx/init.luau"], +[169701, "src/Rosetta/model/pmx/Build.luau"], +[169997, "src/Rosetta/model/pmx/Pmd.luau"], +[170332, "src/Rosetta/model/pmx/Read.luau"], +[170736, "src/Rosetta/model/qb/init.luau"], +[171129, "src/Rosetta/model/rbxm/init.luau"], +[171721, "src/Rosetta/model/rbxmx/init.luau"], +[172374, "src/Rosetta/model/robloxmesh/init.luau"], +[173033, "src/Rosetta/model/robloxmesh/Parse.luau"], +[173490, "src/Rosetta/model/robloxmesh/Write.luau"], +[173599, "src/Rosetta/model/schematic/init.luau"], +[173920, "src/Rosetta/model/schematic/Common.luau"], +[174040, "src/Rosetta/model/schematic/Litematic.luau"], +[174251, "src/Rosetta/model/schematic/Mcedit.luau"], +[174495, "src/Rosetta/model/schematic/Sponge.luau"], +[174624, "src/Rosetta/model/smd/init.luau"], +[174691, "src/Rosetta/model/smd/Read.luau"], +[174960, "src/Rosetta/model/smd/Write.luau"], +[175203, "src/Rosetta/model/stl/init.luau"], +[175653, "src/Rosetta/model/stl/Decode.luau"], +[175727, "src/Rosetta/model/t3d/init.luau"], +[175821, "src/Rosetta/model/t3d/Build.luau"], +[176226, "src/Rosetta/model/t3d/Parse.luau"], +[176394, "src/Rosetta/model/usda/init.luau"], +[176603, "src/Rosetta/model/usda/Build.luau"], +[177881, "src/Rosetta/model/usda/Parse.luau"], +[178679, "src/Rosetta/model/usda/Write.luau"], +[179496, "src/Rosetta/model/vox/init.luau"], +[180382, "src/Rosetta/model/vox/Grid.luau"], +[180439, "src/Rosetta/model/vrml/init.luau"], +[180505, "src/Rosetta/model/x/init.luau"], +[180635, "src/Rosetta/model/x/Build.luau"], +[181198, "src/Rosetta/model/x/Parse.luau"], +[181495, "src/Rosetta/model/x3d/init.luau"], +[181573, "src/Rosetta/music/669/init.luau"], +[181779, "src/Rosetta/music/ahx/init.luau"], +[181830, "src/Rosetta/music/far/init.luau"], +[182059, "src/Rosetta/music/hmp/init.luau"], +[182323, "src/Rosetta/music/hvl/init.luau"], +[182374, "src/Rosetta/music/it/init.luau"], +[182792, "src/Rosetta/music/it/Itsex.luau"], +[182908, "src/Rosetta/music/med/init.luau"], +[183555, "src/Rosetta/music/midi/init.luau"], +[183698, "src/Rosetta/music/midi/Smf.luau"], +[184109, "src/Rosetta/music/mod/init.luau"], +[184462, "src/Rosetta/music/mtm/init.luau"], +[184684, "src/Rosetta/music/mus/init.luau"], +[184841, "src/Rosetta/music/okt/init.luau"], +[185122, "src/Rosetta/music/ptm/init.luau"], +[185344, "src/Rosetta/music/s3m/init.luau"], +[185580, "src/Rosetta/music/sf2/init.luau"], +[185623, "src/Rosetta/music/stm/init.luau"], +[185854, "src/Rosetta/music/ult/init.luau"], +[186158, "src/Rosetta/music/umx/init.luau"], +[186374, "src/Rosetta/music/xm/init.luau"], +[186935, "src/Rosetta/music/xmi/init.luau"], +[187143, "src/Rosetta/ops/AudioOps.luau"], +[187592, "src/Rosetta/ops/ImageOps/init.luau"], +[188236, "src/Rosetta/ops/ImageOps/Kernels.luau"], +[188746, "src/Rosetta/ops/LayerOps.luau"], +[188839, "src/Rosetta/ops/MeshOps/init.luau"], +[189875, "src/Rosetta/ops/MeshOps/Greedy.luau"], +[190042, "src/Rosetta/ops/MusicOps.luau"], +[190390, "src/Rosetta/playlist/m3u/init.luau"], +[190743, "src/Rosetta/playlist/pls/init.luau"], +[190921, "src/Rosetta/playlist/xspf/init.luau"], +[191124, "src/Rosetta/subtitle/ass/init.luau"], +[191568, "src/Rosetta/subtitle/srt/init.luau"], +[191741, "src/Rosetta/subtitle/vtt/init.luau"], +[191944, "src/Rosetta/vector/ldtk/init.luau"], +[192036, "src/Rosetta/vector/ldtk/Read.luau"], +[192372, "src/Rosetta/vector/ldtk/Write.luau"], +[193020, "src/Rosetta/vector/ogmo/init.luau"], +[193139, "src/Rosetta/vector/ogmo/Read.luau"], +[193544, "src/Rosetta/vector/ogmo/Write.luau"], +[193898, "src/Rosetta/vector/svg/init.luau"], +[193984, "src/Rosetta/vector/svg/Parse.luau"], +[194730, "src/Rosetta/vector/svg/PathData.luau"], +[195098, "src/Rosetta/vector/svg/Render.luau"], +[195515, "src/Rosetta/vector/svg/Style.luau"], +[195887, "src/Rosetta/vector/svg/Write.luau"], +[196087, "src/Rosetta/vector/tiled/init.luau"], +[196267, "src/Rosetta/vector/tiled/Data.luau"], +[196418, "src/Rosetta/vector/tiled/Tmj.luau"], +[197049, "src/Rosetta/vector/tiled/Tmx.luau"], +[197661, "src/Rosetta/video/avi/init.luau"], +[197955, "src/Rosetta/video/fli/init.luau"], +[198106, "src/Rosetta/video/flv/init.luau"], +[198490, "src/Rosetta/video/flv/Amf.luau"], +[198648, "src/Rosetta/video/flv/Mux.luau"], +[198929, "src/Rosetta/video/h264/init.luau"], +[199068, "src/Rosetta/video/mkv/init.luau"], +[199224, "src/Rosetta/video/mkv/Mux.luau"], +[199503, "src/Rosetta/video/mkv/Parse.luau"], +[200224, "src/Rosetta/video/mp4/init.luau"], +[200552, "src/Rosetta/video/mpegps/init.luau"], +[200739, "src/Rosetta/video/mpegts/init.luau"], +[200977, "src/Rosetta/video/ogv/init.luau"], +[201372, "src/Rosetta/video/smk/init.luau"], +[201681, "src/Rosetta/video/smk/Audio.luau"], +[201801, "src/Rosetta/video/y4m/init.luau"] ] diff --git a/build/rosetta.lua b/build/rosetta.lua index ed94ec2..e9a20e7 100644 --- a/build/rosetta.lua +++ b/build/rosetta.lua @@ -2321,6 +2321,18 @@ local list= { return __include("model/gltf") end, }, + { + name = "godot", + category = "model", + path = "model/godot", + extensions = { "tscn", "escn" }, + mime = { "application/x-godot-scene" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/GodotVariant", "codecs/model/Mat4" }, + caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, instances = true }, + load = function() + return __include("model/godot") + end, + }, { name = "iqm", category = "model", @@ -2573,6 +2585,18 @@ local list= { return __include("model/stl") end, }, + { + name = "t3d", + category = "model", + path = "model/t3d", + extensions = { "t3d" }, + mime = { "text/x-unreal-t3d" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Text", "codecs/model/Brush" }, + caps = { decode = true, encode = false, text = true, brushes = true, actors = true }, + load = function() + return __include("model/t3d") + end, + }, { name = "usda", category = "model", @@ -3305,6 +3329,18 @@ local list= { return __include("data/toml") end, }, + { + name = "tres", + category = "data", + path = "data/tres", + extensions = { "tres" }, + mime = { "application/x-godot-resource" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/GodotVariant" }, + caps = { decode = true, encode = true, ordered = true }, + load = function() + return __include("data/tres") + end, + }, { name = "xml", category = "data", @@ -3329,6 +3365,30 @@ local list= { return __include("data/yaml") end, }, + { + name = "ldtk", + category = "vector", + path = "vector/ldtk", + extensions = { "ldtk" }, + mime = { "application/x-ldtk+json" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Json" }, + caps = { decode = true, encode = true, levels = true, worlds = true, intGrid = true, entities = true }, + load = function() + return __include("vector/ldtk") + end, + }, + { + name = "ogmo", + category = "vector", + path = "vector/ogmo", + extensions = { "ogmo" }, + mime = { "application/x-ogmo+json" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "core/Base64", "Types", "codecs/text/Json" }, + caps = { decode = true, encode = true, projects = true, entities = true, decals = true }, + load = function() + return __include("vector/ogmo") + end, + }, { name = "svg", category = "vector", @@ -10783,7 +10843,7 @@ return buffer.readstring(b, e.offset, e.size) end function UnityPackage.decode(r, opts) -local o = opts or {} +local o= opts or {} local tar, err = Deflate.gunzip(r.buf, r.base, r.limit - r.base) if not tar then return nil, err @@ -10802,8 +10862,8 @@ local o = opts or {} if guid and not e.dir then local a = byGuid[guid] if not a then - a = {} - byGuid[guid] = a + a = {} +byGuid[guid] = a table.insert(order, guid) end if rest == "asset" then @@ -10877,7 +10937,7 @@ if dir then end function UnityPackage.encode(archive, opts) -local o = opts or {} +local o= opts or {} local items = Archive.entries(archive) if not items then return nil, Err.new(Err.ARG, "expected an Archive") @@ -10911,14 +10971,13 @@ local o = opts or {} end metaData = mb end - local guid = (type(e.guid) == "string" and #e.guid == 32 and string.match(e.guid, "^%x+$") and{(string.lower(e.guid) )}or{nil -})[1] guid = guid or ((metaData and{(metaGuid(metaData) )}or{nil})[1]) or Md5.of(buffer.fromstring(path)) - if used[guid ] then - guid = Md5.of(buffer.fromstring(path .. "\0" .. guid)) + local given= (type(e.guid) == "string" and #e.guid == 32 and string.match(e.guid, "^%x+$") and{(string.lower(e.guid) )}or{nil +})[1] local g= given or ((metaData and{(metaGuid(metaData) )}or{nil})[1]) or Md5.of(buffer.fromstring(path)) + if used[g] then + g = Md5.of(buffer.fromstring(path .. "\0" .. g)) end - used[guid ] = true - local g = guid -metaData = metaData or buffer.fromstring(defaultMeta(g, e.dir == true)) + used[g] = true + metaData = metaData or buffer.fromstring(defaultMeta(g, e.dir == true)) table.insert(list, { name = g .. "/", dir = true, mtime = mtime }) if data then table.insert(list, { name = g .. "/asset", data = data, mtime = mtime }) @@ -89235,6 +89294,665 @@ end return VXml end +__FILES["codecs/text/GodotVariant"] = function() +local __compat = __compat local buffer, utf8, type, __iter = __compat.buffer, __compat.utf8, __compat.type, __compat.__iter --!strict +-- codecs/text/GodotVariant: Godot's text resource syntax (.tscn / .tres / .escn, formats 2-4; Godot's +-- variant_parser.cpp and resource_format_text.cpp): [section key=value ...] headers with `key = value` properties, +-- and the Variant text syntax (numbers, strings, &"StringName", ^"NodePath", arrays, dictionaries, constructors such +-- as Vector3(...), Transform3D(...), PackedFloat32Array(...), SubResource("id"), Object(Class, "k": v)). +-- Constructor values are { type, args } tables (GodotVariant.isCtor); dictionaries keep their key order. +local Types = __include("Types") +local Base64 = __include("core/Base64") + +local GodotVariant = {} + +GodotVariant.null = Types.null + +local CTOR = { __godot = true } + +-- integral numbers written as floats ("1.0"): Godot keeps int and float apart (Curve._data mixes them), so the keys +-- holding them are remembered per container (array, dictionary, property table) and written back with ".0" +local FLOATS= (setmetatable({}, { __mode = "k" }) ) +local lastFloat = false + +local function mark(t, k, v) + if lastFloat and type(v) == "number" and v == math.floor(v) then + local m = FLOATS[t] + if not m then + m = {} + FLOATS[t] = m + end + m[k] = true + end +end + +function GodotVariant.isFloat(t, k) +local m = FLOATS[t] + return m ~= nil and m[k] == true +end + +function GodotVariant.markFloat(t, k) + local m = FLOATS[t] + if not m then + m = {} + FLOATS[t] = m + end + m[k] = true +end + +function GodotVariant.copyFloats(from, to) + local m = FLOATS[from] + if m then + FLOATS[to] = table.clone(m) + end +end + + + + + +function GodotVariant.ctor(name, args) +return (setmetatable({ type = name, args = args or {} }, CTOR) ) +end + +function GodotVariant.isCtor(v) +return type(v) == "table" and getmetatable(v) == CTOR +end + +-- the numbers of a constructor, or nil when an argument is not a number +function GodotVariant.numbers(v, name) +if not GodotVariant.isCtor(v) or (name and v.type ~= name) then + return nil + end + for _, x in __iter(v.args) do + if type(x) ~= "number" then + return nil + end + end + return v.args +end + +-- PackedByteArray(1, 2, ...) or PackedByteArray("base64") (Godot 4.3+), PoolByteArray / ByteArray (format 2) +function GodotVariant.bytes(v) +if not GodotVariant.isCtor(v) then + return nil + end + local a = v.args + if #a == 1 and type(a[1]) == "string" then + return (Base64.decode(a[1])) + end + local b = buffer.create(#a) + for i, x in __iter(a) do + if type(x) ~= "number" then + return nil + end + buffer.writeu8(b, i - 1, x % 256) + end + return b +end +-- ------------------------------------------------------------------------------------------------ parse + + + +local NUMERIC_ARRAYS= { + PackedByteArray = true, PackedInt32Array = true, PackedInt64Array = true, PackedFloat32Array = true, + PackedFloat64Array = true, PackedVector2Array = true, PackedVector3Array = true, PackedVector4Array = true, + PackedColorArray = true, PoolByteArray = true, PoolIntArray = true, PoolRealArray = true, PoolVector2Array = true, + PoolVector3Array = true, PoolColorArray = true, ByteArray = true, IntArray = true, FloatArray = true, RealArray = true, + Vector2Array = true, Vector3Array = true, ColorArray = true, +} +local WORDS= { ["true"] = true, ["false"] = false, ["inf"] = math.huge, ["-inf"] = -math.huge, inf_neg = -math.huge, nan = 0 / 0 } + +local function skip(p) + local s, i = p.s, p.i + while true do + local a = string.find(s, "[^ \t\r\n]", i) + if not a then + p.i = p.n + 1 + return + end + if string.byte(s, a) == 59 then -- ';' comment to the end of the line + local e = string.find(s, "\n", a, true) + if not e then + p.i = p.n + 1 + return + end + i = e + 1 + else + p.i = a + return + end + end +end + +local ESC= { n = "\n", t = "\t", r = "\r", b = "\b", f = "\f", ["\""] = "\"", ["\\"] = "\\", ["'"] = "'", ["/"] = "/" } + +local function utf8char(c) +return utf8.char(math.clamp(c, 0, 0x10FFFF)) +end + +local function str(p) +local s = p.s + local i = p.i + 1 + local parts = {} + while true do + local a = string.find(s, "[\"\\]", i) + if not a then + return nil, "unterminated string" + end + table.insert(parts, string.sub(s, i, a - 1)) + if string.byte(s, a) == 34 then + p.i = a + 1 + return table.concat(parts), nil + end + local c = string.sub(s, a + 1, a + 1) + if c == "u" or c == "U" then + local len = c == "u" and 4 or 6 + local h = tonumber(string.sub(s, a + 2, a + 1 + len), 16) + if not h then + return nil, "bad \\u escape" + end + -- surrogate pairs + if h >= 0xD800 and h < 0xDC00 and string.sub(s, a + 6, a + 7) == "\\u" then + local lo = tonumber(string.sub(s, a + 8, a + 11), 16) + if lo and lo >= 0xDC00 and lo < 0xE000 then + h = 0x10000 + (h - 0xD800) * 1024 + (lo - 0xDC00) + len =len+ 6 + end + end + table.insert(parts, utf8char(h)) + i = a + 2 + len + else + table.insert(parts, ESC[c] or c) + i = a + 2 + end + end +end + +local value + +local function numberList(p, name) +local s = p.s + local close = string.find(s, ")", p.i, true) + if not close then + return nil, "unterminated " .. name + end + local body = string.sub(s, p.i, close - 1) + -- base64 PackedByteArray, or a list of plain numbers + local q = string.match(body, "^%s*\"([^\"]*)\"%s*$") + if q then + p.i = close + 1 + return GodotVariant.ctor(name, { q }), nil + end + local out = {} + local k = 0 + for tok in __iter(string.gmatch(body, "[^,%s]+")) do + local v = tonumber(tok) + if v == nil then + v = WORDS[tok] + if type(v) ~= "number" then + return nil, nil -- not purely numeric: parse it generically + end + end + k =k+ 1 + out[k] = v + end + p.i = close + 1 + return GodotVariant.ctor(name, out), nil +end + +local function list(p, close, into) +skip(p) + if string.byte(p.s, p.i) == close then + p.i =p.i+ 1 + return nil + end + while true do + local v, err = value(p) + if err then + return err + end + table.insert(into, v) + mark(into, #into, v) + skip(p) + local c = string.byte(p.s, p.i) + if c == 44 then -- ',' + p.i =p.i+ 1 + skip(p) + if string.byte(p.s, p.i) == close then + p.i =p.i+ 1 + return nil + end + elseif c == close then + p.i =p.i+ 1 + return nil + else + return "expected ',' or '" .. string.char(close) .. "' at byte " .. (p.i - 1) + end + end +end + +local function dict(p) +p.i =p.i+ 1 + local t, keys = {}, {} + skip(p) + if string.byte(p.s, p.i) == 125 then + p.i =p.i+ 1 + return Types.object(t, keys), nil + end + while true do + local k, err = value(p) + if err then + return nil, err + end + skip(p) + if string.byte(p.s, p.i) ~= 58 then + return nil, "expected ':' at byte " .. (p.i - 1) + end + p.i =p.i+ 1 + local v, verr = value(p) + if verr then + return nil, verr + end + local key = ((type(k) == "string" or type(k) == "number" )and{k }or{(GodotVariant.format(k) +)})[1] if t[key] == nil then + table.insert(keys, key) + end + t[key] = v + mark(t, key, v) + skip(p) + local c = string.byte(p.s, p.i) + if c == 44 then + p.i =p.i+ 1 + skip(p) + if string.byte(p.s, p.i) == 125 then + p.i =p.i+ 1 + break + end + elseif c == 125 then + p.i =p.i+ 1 + break + else + return nil, "expected ',' or '}' at byte " .. (p.i - 1) + end + end + return Types.object(t, keys), nil +end + +value = function(p) +skip(p) + if p.i > p.n then + return nil, "truncated: value expected" + end + p.depth =p.depth+ 1 + if p.depth > p.maxDepth then + return nil, "limit: nested deeper than " .. p.maxDepth + end + local s = p.s + local c = string.byte(s, p.i) + local v, err= nil, nil + local isFloat = false + if c == 34 then + v, err = str(p) + elseif c == 38 or c == 94 then -- &"StringName", ^"NodePath" + p.i =p.i+ 1 + local x, e = str(p) + v, err = (x and{(GodotVariant.ctor(c == 38 and"StringName" or"NodePath", { x }) )}or{nil})[1], e + elseif c == 91 then -- '[' + p.i =p.i+ 1 + local out = {} + err = list(p, 93, out) + v = out + elseif c == 123 then -- '{' + v, err = dict(p) + else + local num = string.match(s, "^[-+]?%d[%w%.+-]*", p.i) or string.match(s, "^[-+]?%.%d[%w%.+-]*", p.i) + if num then + -- 1e-05, 0x1F, 1.5; a trailing "f" is not Godot's + local x = tonumber(num) + if x == nil then + local m = string.match(num, "^[-+]?[%d%.]+[eE][-+]?%d+") or string.match(num, "^[-+]?[%d%.]+") + x = (m and{(tonumber(m) )}or{nil +})[1] num = m or num + end + if x == nil then + return nil, "bad number " .. num .. " at byte " .. (p.i - 1) + end + p.i =p.i+ #num + v = x + isFloat = string.find(num, "[%.eE]") ~= nil and string.sub(num, 1, 2) ~= "0x" + else + local word = string.match(s, "^[%a_][%w_]*", p.i) or string.match(s, "^%-inf", p.i) + if not word then + return nil, "unexpected character at byte " .. (p.i - 1) + end + p.i =p.i+ #word + if word == "null" or word == "nil" then + v = Types.null + elseif WORDS[word] ~= nil then + v = WORDS[word] + else + -- typed array: Array[int]([...]); Dictionary[String, int]({...}) + local typed = string.match(s, "^%[[%w_, ]*%]", p.i) + if typed and (word == "Array" or word == "Dictionary") then + word = word .. typed + p.i =p.i+ #typed + end + skip(p) + if string.byte(s, p.i) ~= 40 then + return nil, "expected '(' after " .. word .. " at byte " .. (p.i - 1) + end + p.i =p.i+ 1 + if NUMERIC_ARRAYS[word] then + local save = p.i + v, err = numberList(p, word) + if v == nil and err == nil then + p.i = save + local args = {} + err = list(p, 41, args) + v = GodotVariant.ctor(word, args) + end + elseif word == "Object" then + skip(p) + local cls = string.match(s, "^[%w_]+", p.i) + if not cls then + return nil, "Object without a class at byte " .. (p.i - 1) + end + p.i =p.i+ #cls + local props, keys = {}, {} + skip(p) + while string.byte(s, p.i) == 44 do + p.i =p.i+ 1 + local k, kerr = value(p) + if kerr then + return nil, kerr + end + skip(p) + if string.byte(s, p.i) ~= 58 then + return nil, "expected ':' in Object at byte " .. (p.i - 1) + end + p.i =p.i+ 1 + local x, xerr = value(p) + if xerr then + return nil, xerr + end + if type(k) == "string" then + props[k] = x + table.insert(keys, k) + end + skip(p) + end + if string.byte(s, p.i) ~= 41 then + return nil, "expected ')' after Object at byte " .. (p.i - 1) + end + p.i =p.i+ 1 + local o = GodotVariant.ctor("Object", { Types.object(props, keys) }) + o.class = cls + v = o + else + local args = {} + err = list(p, 41, args) + v = GodotVariant.ctor(word, args) + end + end + end + end + p.depth =p.depth- 1 + lastFloat = isFloat + return v, err +end + +function GodotVariant.value(text, maxDepth) +local p= { s = text, i = 1, n = #text, depth = 0, maxDepth = maxDepth or 256 } + return value(p) +end + +-- a property key: up to '=' (keys hold '/', ':', '.', or are quoted) +local function key(p) +local s = p.s + if string.byte(s, p.i) == 34 then + local k = str(p) + return k + end + local k = string.match(s, "^[^=\n%[]+", p.i) + if not k then + return nil + end + p.i =p.i+ #k + return (string.gsub(k, "%s+$", "")) +end + +function GodotVariant.parse(text, opts) +local o= opts or {} + if string.sub(text, 1, 3) == "\239\187\191" then + text = string.sub(text, 4) + end + local p= { s = text, i = 1, n = #text, depth = 0, maxDepth = o.maxDepth or 256 } + local maxSections = o.maxSections or 2 ^ 22 + local sections= {} + local cur= nil + local s = text + while true do + skip(p) + if p.i > p.n then + break + end + if string.byte(s, p.i) == 91 then + p.i =p.i+ 1 + skip(p) + local tag = string.match(s, "^[%w_]+", p.i) + if not tag then + return nil, "bad section header at byte " .. (p.i - 1) + end + p.i =p.i+ #tag + local sec= { tag = tag, attrs = {}, attrOrder = {}, props = {}, order = {} } + while true do + skip(p) + local c = string.byte(s, p.i) + if c == 93 then + p.i =p.i+ 1 + break + end + local k = string.match(s, "^[%w_/]+", p.i) + if not k then + return nil, "bad attribute in [" .. tag .. "] at byte " .. (p.i - 1) + end + p.i =p.i+ #k + skip(p) + if string.byte(s, p.i) ~= 61 then + return nil, "expected '=' in [" .. tag .. "] at byte " .. (p.i - 1) + end + p.i =p.i+ 1 + local v, err = value(p) + if err then + return nil, err + end + if sec.attrs[k] == nil then + table.insert(sec.attrOrder, k) + end + sec.attrs[k] = v + end + if #sections >= maxSections then + return nil, "limit: over " .. maxSections .. " sections" + end + table.insert(sections, sec) + cur = sec + else + local at = p.i + local k = key(p) + if not k or k == "" then + return nil, "bad property at byte " .. (at - 1) + end + skip(p) + if string.byte(s, p.i) ~= 61 then + return nil, "expected '=' after " .. k .. " at byte " .. (p.i - 1) + end + p.i =p.i+ 1 + local v, err = value(p) + if err then + return nil, err + end + if not cur then + cur = { tag = "", attrs = {}, attrOrder = {}, props = {}, order = {} } + table.insert(sections, cur ) + end + local c = cur +if c.props[k] == nil then + table.insert(c.order, k) + end + c.props[k] = v + mark(c.props, k, v) + end + end + return { sections = sections }, nil +end + +-- ------------------------------------------------------------------------------------------------ format +local function num(x) +if x ~= x then + return "nan" + elseif x == math.huge then + return "inf" + elseif x == -math.huge then + return "-inf" + elseif x == math.floor(x) and math.abs(x) < 2 ^ 53 then + return string.format("%d", x) + end + for d = 6, 17 do + local s = string.format("%." .. d .. "g", x) + if tonumber(s) == x then + return s + end + end + return string.format("%.17g", x) +end +GodotVariant.number = num + +local function quote(s) +return "\"" .. string.gsub(s, "[\\\"\n\t\r]", { ["\\"] = "\\\\", ["\""] = "\\\"", ["\n"] = "\\n", ["\t"] = "\\t", ["\r"] = "\\r" }) .. "\"" +end +GodotVariant.quote = quote + +local format + +local function item(t, k, depth, indent) +local v = t[k] + if type(v) == "number" and v == math.floor(v) and math.abs(v) < 2 ^ 53 and GodotVariant.isFloat(t, k) then + return string.format("%d", v) .. ".0" + end + return format(v, depth, indent) +end +GodotVariant.item = function(t, k) +return item(t, k, 0, false) +end + +format = function(v, depth, indent) +if depth > 256 then + return "null" + end + local t = type(v) + if t == "number" then + return num(v) + elseif t == "string" then + return quote(v) + elseif t == "boolean" then + return v and"true" or"false" + elseif v == nil or v == Types.null then + return "null" + elseif t == "buffer" then + local parts = table.create(buffer.len(v)) + for i = 0, buffer.len(v) - 1 do + parts[i + 1] = tostring(buffer.readu8(v, i)) + end + return "PackedByteArray(" .. table.concat(parts, ", ") .. ")" + elseif t ~= "table" then + return "null" + end + if GodotVariant.isCtor(v) then + if v.type == "StringName" and type(v.args[1]) == "string" then + return "&" .. quote(v.args[1]) + elseif v.type == "Object" then + local props = v.args[1] + local parts = { tostring(v.class or "Object") } + if type(props) == "table" then + for _, k in __iter(Types.keys(props)) do + table.insert(parts, quote(tostring(k)) .. ": " .. format(props[k], depth + 1, false)) + end + end + return "Object(" .. table.concat(parts, ",") .. ")" + end + local parts= (table.create(#v.args) ) +for i, x in __iter(v.args) do + parts[i] = format(x, depth + 1, false) + end + local vt= tostring(v.type) + if string.match(vt, "^(%a+)%[") then + local inner= parts[1] or "[]" + return vt .. "(" .. inner .. ")" + end + return vt .. "(" .. table.concat(parts, ", ") .. ")" + end + if Types.isObject(v) or not Types.isArray(v) then + local keys = Types.keys(v) + if #keys == 0 then + return "{}" + end + local parts = {} + for _, k in __iter(keys) do + local ks = (type(k) == "string" and{(quote(k) )}or{(format(k, depth + 1, false) +)})[1] table.insert(parts, ks .. ": " .. item(v, k, depth + 1, false)) + end + if indent then + return "{\n" .. table.concat(parts, ",\n") .. "\n}" + end + return "{\n" .. table.concat(parts, ",\n") .. "\n}" + end + local parts = table.create(#v) + for i in __iter(v) do + parts[i] = item(v, i, depth + 1, true) + end + return "[" .. table.concat(parts, ", ") .. "]" +end + +function GodotVariant.format(v) +return format(v, 0, false) +end + +function GodotVariant.encode(doc) +local out = {} + for i, sec in __iter(doc.sections) do + if sec.tag ~= "" then + local parts = { "[" .. sec.tag } + local order = sec.attrOrder + if #order == 0 then + order = Types.keys(sec.attrs) + end + for _, k in __iter(order) do + if sec.attrs[k] ~= nil then + table.insert(parts, k .. "=" .. GodotVariant.format(sec.attrs[k])) + end + end + if i > 1 then + table.insert(out, "") + end + table.insert(out, table.concat(parts, " ") .. "]") + end + local order = sec.order + if #order == 0 then + order = Types.keys(sec.props) + end + for _, k in __iter(order) do + if sec.props[k] ~= nil then + local ks = (string.find(k, "^[%w_/:%.]+$") and{k }or{(quote(k) +)})[1] table.insert(out, ks .. " = " .. item(sec.props, k, 0, false)) + end + end + end + return table.concat(out, "\n") .. "\n" +end + +return GodotVariant +end __FILES["codecs/text/Json"] = function() local __compat = __compat local buffer, typeof, type = __compat.buffer, __compat.typeof, __compat.type --!strict -- codecs/text/Json: JSON (RFC 8259 / ECMA-404) parse and serialize, the engine data/json, glTF, TMJ, ... use. New code. @@ -123455,6 +124173,151 @@ end return Encode end +__FILES["data/tres"] = function() +local __compat = __compat local buffer, type, __iter = __compat.buffer, __compat.type, __compat.__iter --!strict +-- data/tres: Godot text resources (.tres, formats 2-4) as data, read + write (codecs/text/GodotVariant). The value: +-- { type, format, uid?, scriptClass?, loadSteps?, external = { { id, type, path, uid? } }, subresources = { { id, +-- type, properties } }, properties } with Variant values (Vector3, Color, SubResource, ... as { type, args } tables; +-- dictionaries and property tables keep their order). Not supported: binary .res files. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local Types = __include("Types") +local GodotVariant = __include("codecs/text/GodotVariant") + +-- ------------------------------------------------------------------------------------------------ contract +local Tres = { + name = "tres", + category = "data", + extensions = { "tres" }, + mime = { "application/x-godot-resource" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/GodotVariant" }, + caps = { decode = true, encode = true, ordered = true }, +} + +-- ------------------------------------------------------------------------------------------------ sniff + + + + + +function Tres.sniff(r) +local h = Sniff.text(r, 256) + if string.match(h, "^%s*%[gd_resource[%s%]]") then + return 1 + end + return 0 +end + +-- ------------------------------------------------------------------------------------------------ decode +local function props(sec) +local out = {} + for _, k in __iter(sec.order) do + out[k] = sec.props[k] + end + GodotVariant.copyFloats(sec.props, out) + return Types.object(out, (table.clone(sec.order) )) +end + +function Tres.decode(r, opts) +local o= opts or {} + if r.limit - r.base > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local text = buffer.readstring(r.buf, r.base, r.limit - r.base) + local ok, doc, perr = pcall(function() +return GodotVariant.parse(text, { maxDepth = o.maxDepth }) + end) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad data: " .. tostring(doc)) + end + if not doc then + return nil, Err.from(perr) + end + local head = doc.sections[1] + if not head or head.tag ~= "gd_resource" then + return nil, Err.new((head and head.tag == "gd_scene" and{Err.UNSUPPORTED }or{Err.CORRUPT})[1], head and head.tag == "gd_scene" and"a scene (model/godot), not a resource" or"no [gd_resource] header") + end + local a = head.attrs + local value= { + type = a.type, + format = a.format, + uid = a.uid, + scriptClass = a.script_class, + loadSteps = a.load_steps, + external = {}, + subresources = {}, + properties = Types.object({}), + } + for i = 2, #doc.sections do + local sec = doc.sections[i] + local sa = sec.attrs + if sec.tag == "ext_resource" then + table.insert(value.external, { id = sa.id, type = sa.type, path = sa.path, uid = sa.uid }) + elseif sec.tag == "sub_resource" then + table.insert(value.subresources, { id = sa.id, type = sa.type, properties = props(sec) }) + elseif sec.tag == "resource" then + value.properties = props(sec) + end + end + return value, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +local function section(tag, pairs_, properties) +local attrs, order = {}, {} + local i = 1 + while pairs_[i] ~= nil do + if pairs_[i + 1] ~= nil then + attrs[pairs_[i] ] = pairs_[i + 1] + table.insert(order, pairs_[i]) + end + i =i+ 2 + end + local p, po = {}, {} + if type(properties) == "table" then + for _, k in __iter(Types.keys(properties)) do + if type(k) == "string" then + p[k] = properties[k] + table.insert(po, k) + end + end + GodotVariant.copyFloats(properties, p) + end + return { tag = tag, attrs = attrs, attrOrder = order, props = p, order = po } +end + +function Tres.encode(value, opts) +if type(value) ~= "table" or type(value.type) ~= "string" then + return nil, Err.new(Err.ARG, "needs a resource table with a type") + end + local ext = (type(value.external) == "table" and{value.external }or{{} +})[1] local sub = (type(value.subresources) == "table" and{value.subresources }or{{} +})[1] local format = (type(value.format) == "number" and{value.format }or{3 +})[1] local steps = (type(value.loadSteps) == "number" and{value.loadSteps }or{(#ext + #sub > 0 and((#ext + #sub + 1 ))or(nil +))})[1] local sections = { section("gd_resource", { "type", value.type, "script_class", value.scriptClass, "load_steps", steps, "format", format, "uid", value.uid }) } + for _, e in __iter(ext) do + if type(e) == "table" then + table.insert(sections, section("ext_resource", { "type", e.type, "uid", e.uid, "path", e.path, "id", e.id })) + end + end + for _, s in __iter(sub) do + if type(s) == "table" then + table.insert(sections, section("sub_resource", { "type", s.type, "id", s.id }, s.properties)) + end + end + table.insert(sections, section("resource", {}, value.properties)) + local ok, s = pcall(GodotVariant.encode, { sections = sections }) + if not ok then + return nil, Err.new(Err.ARG, "cannot encode: " .. tostring(s)) + end + return buffer.fromstring(s), nil +end + +return Tres +end __FILES["data/xml"] = function() local __compat = __compat local buffer, type = __compat.buffer, __compat.type --!strict -- data/xml: XML 1.0 over codecs/text/Xml. Supports: decode to a "#document" XmlNode tree, encode a document or an @@ -157513,6 +158376,1728 @@ local out = {} })[1] return { doc = doc, bin = bin:finish(), images = imageOut }, nil end +return Write +end +__FILES["model/godot"] = function() +local __compat = __compat local buffer, type = __compat.buffer, __compat.type --!strict +-- model/godot: Godot text scenes (.tscn, .escn; formats 2-4) as a Scene, read + write (format 3); checked against +-- Godot 4's own loader. Supports: Node3D trees (transforms or position / rotation / scale), MeshInstance3D with +-- ArrayMesh surfaces and primitive meshes (Box, Plane, Quad, Sphere, Cylinder), StandardMaterial3D / SpatialMaterial +-- as PBR, surface material overrides, Camera3D, Omni / Spot / Directional lights, instanced scenes through +-- opts.resolve, non-3D nodes in extras.godot. Not supported: compressed or Godot 3 binary surfaces, skeletons and +-- animations (AnimationPlayer libraries stay sub-resources), blend shapes, other mesh / material resource types. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local Types = __include("Types") +local GodotVariant = __include("codecs/text/GodotVariant") +local Build = __include("model/godot/Build") +local Write = __include("model/godot/Write") + +-- ------------------------------------------------------------------------------------------------ contract +local Godot = { + name = "godot", + category = "model", + extensions = { "tscn", "escn" }, + mime = { "application/x-godot-scene" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/GodotVariant", "codecs/model/Mat4" }, + caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, instances = true }, +} +-- ------------------------------------------------------------------------------------------------ types +-- ------------------------------------------------------------------------------------------------ sniff + + + + + + + + +function Godot.sniff(r) +local h = Sniff.text(r, 256) + if string.match(h, "^%s*%[gd_scene[%s%]]") then + return 1 + end + return 0 +end + +-- ------------------------------------------------------------------------------------------------ decode +function Godot.decode(r, opts) +local o= opts or {} + if r.limit - r.base > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local text = buffer.readstring(r.buf, r.base, r.limit - r.base) + local ok, doc, perr = pcall(function() +return GodotVariant.parse(text, { maxDepth = o.maxDepth }) + end) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad data: " .. tostring(doc)) + end + if not doc then + return nil, Err.from(perr) + end + if #doc.sections == 0 then + return nil, Err.new(Err.CORRUPT, "empty file") + end + local ok2, scene, msg = pcall(Build.scene, doc, o) + if not ok2 then + return nil, Err.from(tostring(scene)) + end + if not scene then + return nil, Err.from(msg) + end + return scene, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +function Godot.encode(scene, opts) +if type(scene) ~= "table" or type(scene.nodes) ~= "table" then + return nil, Err.new(Err.ARG, "needs a Scene") + end + local ok, doc, msg = pcall(Write.document, scene) + if not ok then + return nil, Err.new(Err.ARG, "bad scene: " .. tostring(doc)) + end + if not doc then + return nil, Err.new(Err.ARG, msg or "bad scene") + end + return buffer.fromstring(GodotVariant.encode(doc)), nil +end + +return Godot +end +__FILES["model/godot/Build"] = function() +local __compat = __compat local buffer, type, __iter = __compat.buffer, __compat.type, __compat.__iter --!strict +-- model/godot/Build: a parsed Godot text scene (codecs/text/GodotVariant) into a Scene. Transform3D / Transform text +-- is the basis rows then the origin; Node3D position / rotation (Euler YXZ, radians) / scale / quaternion are used when +-- there is no transform. Colours (albedo, emission, lights) are sRGB in Godot and linear in the Scene (raw values in +-- extras.godot). Non-3D nodes (Node2D trees, Control, plain Node) are nodes with their properties in extras.godot. +local Types = __include("Types") +local Mat4 = __include("codecs/model/Mat4") +local GodotVariant = __include("codecs/text/GodotVariant") +local Surface = __include("model/godot/Surface") +local Primitives = __include("model/godot/Primitives") + +local Build = {} + +local S = Types.Scene +local isCtor = GodotVariant.isCtor + + + + + + + + + + + + + + + +local function idOf(v) +if isCtor(v) and (v.type == "SubResource" or v.type == "ExtResource") then + local a = v.args[1] + if type(a) == "string" or type(a) == "number" then + return tostring(a) + end + end + return nil +end + +local function num(v, d) +return (type(v) == "number" and v == v and{v }or{d +})[1]end + +local function srgb(c) +if c <= 0.04045 then + return c / 12.92 + end + return ((c + 0.055) / 1.055) ^ 2.4 +end + +local function color(v, d) +local a = GodotVariant.numbers(v, "Color") + if a and #a >= 3 then + return { a[1], a[2], a[3], a[4] or 1 } + end + return d +end + +local function linear(c) +return { srgb(c[1]), srgb(c[2]), srgb(c[3]), c[4] } +end + +-- ------------------------------------------------------------------------------------------------ transforms +function Build.transform(v) +local a = (isCtor(v) and (v.type == "Transform3D" or v.type == "Transform") and{(GodotVariant.numbers(v) )}or{nil +})[1] if not a or #a ~= 12 then + return nil + end + return { a[1], a[4], a[7], 0, a[2], a[5], a[8], 0, a[3], a[6], a[9], 0, a[10], a[11], a[12], 1 } +end + +-- Basis::from_euler (YXZ): Ry * Rx * Rz +local function euler(x, y, z) +local rx, ry, rz = Mat4.rotation(1, math.deg(x)), Mat4.rotation(2, math.deg(y)), Mat4.rotation(3, math.deg(z)) + return S.mul(ry, S.mul(rx, rz)) +end + +local function nodeMatrix(props) +local m = Build.transform(props.transform) + if m then + return m + end + local pos = GodotVariant.numbers(props.position, "Vector3") or GodotVariant.numbers(props.translation, "Vector3") + local rot = GodotVariant.numbers(props.rotation, "Vector3") + local deg = GodotVariant.numbers(props.rotation_degrees, "Vector3") + local quat = GodotVariant.numbers(props.quaternion, "Quaternion") + local sc = GodotVariant.numbers(props.scale, "Vector3") + if not (pos or rot or deg or quat or sc) then + return nil + end + local r +if quat and #quat == 4 then + r = Mat4.fromQuat(quat) + elseif rot and #rot == 3 then + r = euler(rot[1], rot[2], rot[3]) + elseif deg and #deg == 3 then + r = euler(math.rad(deg[1]), math.rad(deg[2]), math.rad(deg[3])) + else + r = Mat4.identity() + end + local s = (sc and #sc == 3 and{(Mat4.scaling(sc[1], sc[2], sc[3]) )}or{(Mat4.identity() +)})[1] local out = S.mul(r, s) + if pos and #pos == 3 then + out[13], out[14], out[15] = pos[1], pos[2], pos[3] + end + return out +end + +-- ------------------------------------------------------------------------------------------------ resources +local function path(ext) +if type(ext) ~= "table" then + return nil + end + local p = ext.attrs.path + return (type(p) == "string" and{p }or{nil +})[1]end + +local function texture(ctx, v) +local id = idOf(v) + if not id or not isCtor(v) or v.type ~= "ExtResource" then + return nil + end + local key = "ext:" .. id + local idx = ctx.textures[key] + if not idx then + local p = path(ctx.ext[id]) + if not p then + return nil + end + local rel = string.gsub(p, "^res://", "") + local tex= { name = rel, uri = rel } + local resolve = ctx.opts.resolve + if type(resolve) == "function" then + local ok, b = pcall(resolve, rel) + if ok and type(b) == "buffer" then + tex.data = b + end + end + table.insert(ctx.scene.textures, tex) + idx = #ctx.scene.textures + ctx.textures[key] = idx + end + return { texture = idx } +end + +local MATERIALS = { StandardMaterial3D = true, ORMMaterial3D = true, SpatialMaterial = true } + +local function material(ctx, v) +local id = idOf(v) + if not id or not isCtor(v) then + return nil + end + local key = v.type .. ":" .. id + if ctx.materials[key] then + return ctx.materials[key] + end + local sec = (v.type == "SubResource" and{ctx.sub[id] }or{nil +})[1] local typ = (sec and{sec.attrs.type }or{((ctx.ext[id] and{ctx.ext[id].attrs.type }or{nil})[1]) +})[1] local p = (sec and{sec.props }or{{} +})[1] local m = S.material((type(p.resource_name) == "string" and{p.resource_name }or{nil})[1]) + local albedo = color(p.albedo_color, { 1, 1, 1, 1 }) + m.baseColor = linear(albedo) + m.metallic = num(p.metallic, 0) + m.roughness = num(p.roughness, 1) + local extras= { type = typ, albedo = albedo } + if MATERIALS[typ or ""] then + m.baseColorTexture = texture(ctx, p.albedo_texture) + m.metallicRoughnessTexture = texture(ctx, p.metallic_texture) or texture(ctx, p.roughness_texture) + if p.normal_enabled == true or p.normal_enabled == nil and p.normal_texture ~= nil then + m.normalTexture = texture(ctx, p.normal_texture) + if m.normalTexture and type(p.normal_scale) == "number" then + m.normalTexture.scale = p.normal_scale + end + end + if p.ao_enabled == true then + m.occlusionTexture = texture(ctx, p.ao_texture) + end + local emission = p.emission_enabled == true or p.flags_emission == true + if emission then + local e = color(p.emission, { 0, 0, 0, 1 }) + local energy = num(p.emission_energy_multiplier, num(p.emission_energy, 1)) + local le = linear(e) + m.emissive = { le[1], le[2], le[3] } + m.emissiveTexture = texture(ctx, p.emission_texture) + extras.emission = e + if energy ~= 1 then + m.extensions = { KHR_materials_emissive_strength = { emissiveStrength = energy } } + end + end + local transparency = num(p.transparency, p.flags_transparent == true and 1 or 0) + if transparency == 1 or transparency == 4 then + m.alphaMode = "blend" + elseif transparency == 2 or transparency == 3 then + m.alphaMode = "mask" + m.alphaCutoff = num(p.alpha_scissor_threshold, 0.5) + end + m.doubleSided = num(p.cull_mode, num(p.params_cull_mode, 0)) == 2 + if num(p.shading_mode, 1) == 0 or p.flags_unshaded == true then + m.extensions = m.extensions or {} + ;(m.extensions ).KHR_materials_unlit = {} + end + local uv = GodotVariant.numbers(p.uv1_scale, "Vector3") + local off = GodotVariant.numbers(p.uv1_offset, "Vector3") + if m.baseColorTexture and (uv or off) then + m.baseColorTexture.transform = { scale = uv and{ uv[1], uv[2] } or{ 1, 1 }, offset = off and{ off[1], off[2] } or{ 0, 0 } } + end + elseif not sec then + extras.path = path(ctx.ext[id]) + end + m.extras = { godot = extras } + table.insert(ctx.scene.materials, m) + ctx.materials[key] = #ctx.scene.materials + return #ctx.scene.materials +end + +-- a mesh resource (ArrayMesh or a primitive mesh) as a Scene mesh; overrides: surface index -> material value +local function mesh(ctx, v, overrides) +local id = idOf(v) + if not id or not isCtor(v) then + return nil, nil + end + local key = v.type .. ":" .. id + if not overrides and ctx.meshes[key] then + return ctx.meshes[key], nil + end + local sec = (v.type == "SubResource" and{ctx.sub[id] }or{nil +})[1] local out= { primitives = {} } + if not sec then + out.extras = { godot = { path = path(ctx.ext[id]) } } + else + local typ = sec.attrs.type + local p = sec.props + out.name = (type(p.resource_name) == "string" and{p.resource_name }or{nil +})[1] local maxV = ctx.opts.maxVertices or 2 ^ 24 + if typ == "ArrayMesh" or typ == "Mesh" then + local surfaces= {} + if type(p._surfaces) == "table" then + surfaces = p._surfaces + else + for k = 0, 4096 do + local s = p["surfaces/" .. k] + if s == nil then + break + end + surfaces[k + 1] = s + end + end + local blend = 0 + for i, sd in __iter(surfaces) do + local L, err = Surface.lists(sd, maxV) + if not L then + return nil, err + end + local prim = Surface.primitive(L) + local mv = (overrides and overrides[i - 1] ~= nil and{overrides[i - 1] }or{((type(sd) == "table" and{sd.material }or{nil})[1]) +})[1] prim.material = material(ctx, mv) + if type(sd) == "table" and type(sd.name) == "string" then + prim.extras = { name = sd.name } + end + if type(sd) == "table" and type(sd.blend_shapes) == "table" then + blend = math.max(blend, #sd.blend_shapes) + end + table.insert(out.primitives, prim) + end + if blend > 0 then + out.extras = { godot = { blendShapes = blend } } + end + elseif Primitives.KINDS[typ] then + local a = Primitives.build(typ, p) + if a then + local prim = Surface.primitive(Surface.fromPrimitiveArrays(a)) + prim.material = material(ctx, (overrides and overrides[0] ~= nil and{overrides[0] }or{p.material})[1]) + table.insert(out.primitives, prim) + end + out.extras = { godot = { primitive = typ } } + else + out.extras = { godot = { type = typ } } + end + end + table.insert(ctx.scene.meshes, out) + if not overrides then + ctx.meshes[key] = #ctx.scene.meshes + end + return #ctx.scene.meshes, nil +end + +-- ------------------------------------------------------------------------------------------------ nodes +local LIGHT= { + OmniLight3D = "point", SpotLight3D = "spot", DirectionalLight3D = "directional", + OmniLight = "point", SpotLight = "spot", DirectionalLight = "directional", +} +local CAMERA = { Camera3D = true, Camera = true, ClippedCamera = true, InterpolatedCamera = true, XRCamera3D = true } +local MESH = { MeshInstance3D = true, MeshInstance = true, CSGMesh3D = true, SoftBody3D = true } + +local THREE_D = { + Node3D = true, Spatial = true, MeshInstance3D = true, MeshInstance = true, Camera3D = true, Camera = true, + OmniLight3D = true, SpotLight3D = true, DirectionalLight3D = true, OmniLight = true, SpotLight = true, DirectionalLight = true, + Skeleton3D = true, Skeleton = true, BoneAttachment3D = true, Marker3D = true, Position3D = true, CollisionShape3D = true, + StaticBody3D = true, RigidBody3D = true, CharacterBody3D = true, Area3D = true, StaticBody = true, RigidBody = true, + KinematicBody = true, Area = true, CollisionShape = true, VisibleOnScreenNotifier3D = true, GPUParticles3D = true, + CPUParticles3D = true, Sprite3D = true, Label3D = true, Path3D = true, PathFollow3D = true, RemoteTransform3D = true, + CSGBox3D = true, CSGSphere3D = true, CSGCylinder3D = true, CSGMesh3D = true, CSGCombiner3D = true, XROrigin3D = true, + XRCamera3D = true, VehicleBody3D = true, VehicleWheel3D = true, NavigationRegion3D = true, ReflectionProbe = true, + GridMap = true, AnimatableBody3D = true, ClippedCamera = true, InterpolatedCamera = true, SoftBody3D = true, +} + +local function plainProps(sec) +local out= {} + for _, k in __iter(sec.order) do + out[k] = sec.props[k] + end + return out +end + +local function camera(ctx, typ, p) +local fmt2 = ctx.format <= 2 + local cam +if num(p.projection, 0) == 1 then + local size = num(p.size, 1) + cam = { type = "orthographic", xmag = size / 2, ymag = size / 2, znear = num(p.near, 0.05), zfar = num(p.far, fmt2 and 100 or 4000) } +else + cam = { type = "perspective", yfov = math.rad(num(p.fov, fmt2 and 70 or 75)), znear = num(p.near, 0.05), zfar = num(p.far, fmt2 and 100 or 4000) } +end + table.insert(ctx.scene.cameras, cam) + return #ctx.scene.cameras +end + +local function light(ctx, typ, p) +local kind = LIGHT[typ] + local c = color(p.light_color, { 1, 1, 1, 1 }) + local lc = linear(c) + local l= { type = kind, color = { lc[1], lc[2], lc[3] }, intensity = num(p.light_energy, 1) } + if kind == "point" then + l.range = num(p.omni_range, 5) + elseif kind == "spot" then + l.range = num(p.spot_range, 5) + l.outerCone = math.rad(num(p.spot_angle, 45)) + l.innerCone = 0 + end + table.insert(ctx.scene.lights, l) + return #ctx.scene.lights +end + +local scene +-- an instanced scene (instance=ExtResource) through opts.resolve; its root becomes the instancing node + +local function instance(ctx, v, node) +local id = idOf(v) + local p = (id and{(path(ctx.ext[id]) )}or{nil +})[1] local resolve = ctx.opts.resolve + if not p or type(resolve) ~= "function" or ctx.depth >= 8 then + return nil + end + local rel = string.gsub(p, "^res://", "") + local ok, b = pcall(resolve, rel) + if not ok or type(b) ~= "buffer" then + table.insert(ctx.warnings, "instance " .. rel .. " not resolved") + return nil + end + local doc, err = GodotVariant.parse(buffer.tostring(b), { maxDepth = ctx.opts.maxDepth }) + if not doc then + return "instance " .. rel .. ": " .. tostring(err) + end + local sub= { + scene = ctx.scene, + doc = doc, + format = 3, + ext = {}, + sub = {}, + meshes = {}, + materials = {}, + textures = {}, + opts = ctx.opts, + depth = ctx.depth + 1, + warnings = ctx.warnings, + } + local _, serr = scene(sub, doc, node) + return serr +end + +scene = function(ctx, doc, into) +local sc = ctx.scene + local header = doc.sections[1] + ctx.format = (header and type(header.attrs.format) == "number" and{header.attrs.format }or{3 +})[1] for _, sec in __iter(doc.sections) do + local id = sec.attrs.id + if id ~= nil and (type(id) == "string" or type(id) == "number") then + if sec.tag == "ext_resource" then + ctx.ext[tostring(id)] = sec + elseif sec.tag == "sub_resource" then + ctx.sub[tostring(id)] = sec + end + end + end + local byPath= {} + local root= nil + local connections = {} + for _, sec in __iter(doc.sections) do + if sec.tag == "node" then + local a = sec.attrs + local name = (type(a.name) == "string" and{a.name }or{"Node" +})[1] local parent = a.parent + local typ = (type(a.type) == "string" and{a.type }or{nil +})[1] local p = sec.props + local idx +local isRoot = parent == nil + if isRoot and into then + idx = into + else + table.insert(sc.nodes, { name = name, children = {} }) + idx = #sc.nodes + end + local node = sc.nodes[idx] + if not (isRoot and into) then + node.name = name + end + if isRoot then + if root then + return nil, "two root nodes" + end + root = idx + byPath["."] = idx + if not into then + table.insert(sc.roots, idx) + end + else + local pp = (type(parent) == "string" and{parent }or{"." +})[1] local pi = byPath[pp] + if not pi then + return nil, "node " .. name .. ": no parent " .. pp + end + table.insert(sc.nodes[pi].children, idx) + byPath[(pp == "." and{name }or{(pp .. "/" .. name)})[1] ] = idx + end + if a.instance ~= nil then + local err = instance(ctx, a.instance, idx) + if err then + return nil, err + end + end + local m = nodeMatrix(p) + if m then + node.matrix = m + end + local extras= node.extras and node.extras.godot or {} + extras.type = typ or extras.type + extras.properties = plainProps(sec) + if a.instance ~= nil then + extras.instance = path(ctx.ext[idOf(a.instance) or ""] ) + end + if type(a.groups) == "table" then + extras.groups = a.groups + end + if p.visible == false then + extras.visible = false + end + node.extras = { godot = extras } + if typ and not THREE_D[typ] then + extras.is2D = string.find(typ, "2D$") ~= nil or typ == "Node2D" or nil + end + if typ and MESH[typ] or p.mesh ~= nil then + local overrides= nil + for k, v in __iter(p) do + local si = string.match(k, "^surface_material_override/(%d+)$") or string.match(k, "^material/(%d+)$") + if si and v ~= GodotVariant.null then + overrides = overrides or {} + ;(overrides )[(tonumber(si) )] = v + end + end + if p.material_override ~= nil and p.material_override ~= GodotVariant.null then + overrides = overrides or {} + for k = 0, 63 do + if (overrides )[k] == nil then + (overrides )[k] = p.material_override + end + end + end + if p.mesh ~= nil then + local mi, err = mesh(ctx, p.mesh, overrides) + if err then + return nil, err + end + node.mesh = mi + end + end + if typ and CAMERA[typ] then + node.camera = camera(ctx, typ, p) + elseif typ and LIGHT[typ] then + node.light = light(ctx, typ, p) + extras.lightColor = color(p.light_color, { 1, 1, 1, 1 }) + end + elseif sec.tag == "connection" then + table.insert(connections, sec.attrs) + end + end + if #connections > 0 and not into then + (sc.meta.source ).connections = connections + end + return root, nil +end + +function Build.scene(doc, opts) +local sc = S.new() + sc.meta.up = "y" + sc.meta.unit = 1 + local header = doc.sections[1] + sc.meta.source = { + format = "godot", + tag = (header and{header.tag }or{nil})[1], + version = (header and{header.attrs.format }or{nil})[1], + uid = (header and{header.attrs.uid }or{nil})[1], + } + local ctx= { + scene = sc, + doc = doc, + format = 3, + ext = {}, + sub = {}, + meshes = {}, + materials = {}, + textures = {}, + opts = opts or {}, + depth = 0, + warnings = {}, + } + if header and header.tag ~= "gd_scene" then + return nil, "unsupported: a " .. header.tag .. " file is a resource, not a scene (data/tres)" + end + local _, err = scene(ctx, doc, nil) + if err then + return nil, err + end + if #ctx.warnings > 0 then + (sc.meta.source ).warnings = ctx.warnings + end + return sc, nil +end + +return Build +end +__FILES["model/godot/Primitives"] = function() +local __compat = __compat local type, __iter = __compat.type, __compat.__iter --!strict +-- model/godot/Primitives: Godot's primitive meshes (BoxMesh, PlaneMesh, QuadMesh, SphereMesh, CylinderMesh) as Godot +-- builds them. Ported from Godot 4.4 scene/resources/3d/primitive_meshes.cpp (MIT, licenses/godot-LICENSE.txt): the +-- same vertex order, normals, tangents, UVs and (clockwise, Godot's front face) indices; no UV2. +local Primitives = {} + + + +local TAU = math.pi * 2 + +local function num(v, d) +return (type(v) == "number" and v == v and{v }or{d +})[1]end + +local function vec(v, n, d) +if type(v) == "table" and type(v.args) == "table" and #v.args >= n then + local out = {} + for i = 1, n do + out[i] = num(v.args[i], d[i]) + end + return out + end + return d +end + +local function new() +return { points = {}, normals = {}, tangents = {}, uvs = {}, indices = {} } +end + +local function add(a, px, py, pz, nx, ny, nz, tx, ty, tz, u, v) + local p, nn, t, uv = a.points, a.normals, a.tangents, a.uvs + p[#p + 1], p[#p + 2], p[#p + 3] = px, py, pz + nn[#nn + 1], nn[#nn + 2], nn[#nn + 3] = nx, ny, nz + t[#t + 1], t[#t + 2], t[#t + 3], t[#t + 4] = tx, ty, tz, 1 + uv[#uv + 1], uv[#uv + 2] = u, v +end + +-- the two triangles of a grid cell: p0 p1 t0, p1 t1 t0 (prev row, this row) +local function quad(a, p0, p1, t0, t1) + local ix = a.indices + local n = #ix + ix[n + 1], ix[n + 2], ix[n + 3], ix[n + 4], ix[n + 5], ix[n + 6] = p0, p1, t0, p1, t1, t0 +end + +-- BoxMesh::create_mesh_array +local function box(props) +local size = vec(props.size, 3, { 1, 1, 1 }) + local sw, sh, sd = math.max(0, num(props.subdivide_width, 0)), math.max(0, num(props.subdivide_height, 0)), math.max(0, num(props.subdivide_depth, 0)) + local a = new() + local onethird, twothirds = 1 / 3, 2 / 3 + local sx, sy, sz = -size[1] / 2, -size[2] / 2, -size[3] / 2 + local point = 0 + local function faces(rows, cols, step) + local thisrow, prevrow = point, 0 + for j = 0, rows + 1 do + for i = 0, cols + 1 do + step(i, j) + point =point+ 2 + if i > 0 and j > 0 then + local i2 = i * 2 + quad(a, prevrow + i2 - 2, prevrow + i2, thisrow + i2 - 2, thisrow + i2) + quad(a, prevrow + i2 - 1, prevrow + i2 + 1, thisrow + i2 - 1, thisrow + i2 + 1) + end + end + prevrow = thisrow + thisrow = point + end + end + -- front + back + faces(sh, sw, function(i, j) + local v = j / (2 * (sh + 1)) + local u = i / (3 * (sw + 1)) + local x = sx + i * size[1] / (sw + 1) + local y = sy + j * size[2] / (sh + 1) + add(a, x, -y, -sz, 0, 0, 1, 1, 0, 0, u, v) + add(a, -x, -y, sz, 0, 0, -1, -1, 0, 0, twothirds + u, v) + end) + -- left + right + faces(sh, sd, function(i, j) + local v = j / (2 * (sh + 1)) + local u = i / (3 * (sd + 1)) + local z = sz + i * size[3] / (sd + 1) + local y = sy + j * size[2] / (sh + 1) + add(a, -sx, -y, -z, 1, 0, 0, 0, 0, -1, onethird + u, v) + add(a, sx, -y, z, -1, 0, 0, 0, 0, 1, u, 0.5 + v) + end) + -- top + bottom + faces(sd, sw, function(i, j) + local v = j / (2 * (sd + 1)) + local u = i / (3 * (sw + 1)) + local x = sx + i * size[1] / (sw + 1) + local z = sz + j * size[3] / (sd + 1) + add(a, -x, -sy, -z, 0, 1, 0, -1, 0, 0, onethird + u, 0.5 + v) + add(a, x, sy, -z, 0, -1, 0, 1, 0, 0, twothirds + u, 0.5 + v) + end) + return a +end + +-- PlaneMesh::_create_mesh_array (QuadMesh: FACE_Z, size 1 x 1) +local function plane(props, isQuad) +local size = vec(props.size, 2, isQuad and{ 1, 1 } or{ 2, 2 }) + local sw, sd = math.max(0, num(props.subdivide_width, 0)), math.max(0, num(props.subdivide_depth, 0)) + local off = vec(props.center_offset, 3, { 0, 0, 0 }) + local orient = num(props.orientation, isQuad and 2 or 1) + local a = new() + local nx, ny, nz = 0, 1, 0 + if orient == 0 then + nx, ny, nz = 1, 0, 0 + elseif orient == 2 then + nx, ny, nz = 0, 0, 1 + end + local point, thisrow, prevrow = 0, 0, 0 + local z = -size[2] / 2 + for j = 0, sd + 1 do + local x = -size[1] / 2 + for i = 0, sw + 1 do + local u, v = i / (sw + 1), j / (sd + 1) + local px, py, pz= 0, 0, 0 + if orient == 0 then + px, py, pz = 0, z, x + elseif orient == 2 then + px, py, pz = -x, z, 0 + else + px, py, pz = -x, 0, -z + end + if orient == 0 then + add(a, px + off[1], py + off[2], pz + off[3], nx, ny, nz, 0, 0, -1, 1 - u, 1 - v) + else + add(a, px + off[1], py + off[2], pz + off[3], nx, ny, nz, 1, 0, 0, 1 - u, 1 - v) + end + point =point+ 1 + if i > 0 and j > 0 then + quad(a, prevrow + i - 1, prevrow + i, thisrow + i - 1, thisrow + i) + end + x =x+ size[1] / (sw + 1) + end + z =z+ size[2] / (sd + 1) + prevrow = thisrow + thisrow = point + end + return a +end + +-- SphereMesh::create_mesh_array +local function sphere(props) +local radius, height = num(props.radius, 0.5), num(props.height, 1) + local radial, rings = math.max(1, num(props.radial_segments, 64)), math.max(1, num(props.rings, 32)) + local hemi = props.is_hemisphere == true + local scale = height / radius * (hemi and 1 or 0.5) + local a = new() + local point, thisrow, prevrow = 0, 0, 0 + for j = 0, rings + 1 do + local v = j / (rings + 1) + local w, y= 0, -1 + if j ~= rings + 1 then + w = math.sin(math.pi * v) + y = math.cos(math.pi * v) + end + for i = 0, radial do + local u = i / radial + local x, z= 0, 1 + if i ~= radial then + x = math.sin(u * TAU) + z = math.cos(u * TAU) + end + if hemi and y < 0 then + add(a, x * radius * w, 0, z * radius * w, 0, -1, 0, z, 0, -x, u, v) + else + local nx, ny, nz = x * w * scale, y, z * w * scale + local l = math.sqrt(nx * nx + ny * ny + nz * nz) + if l > 0 then + nx, ny, nz = nx / l, ny / l, nz / l + end + add(a, x * w * radius, y * scale * radius, z * w * radius, nx, ny, nz, z, 0, -x, u, v) + end + point =point+ 1 + if i > 0 and j > 0 then + quad(a, prevrow + i - 1, prevrow + i, thisrow + i - 1, thisrow + i) + end + end + prevrow = thisrow + thisrow = point + end + return a +end + +-- CylinderMesh::create_mesh_array +local function cylinder(props) +local top, bottom, height = num(props.top_radius, 0.5), num(props.bottom_radius, 0.5), num(props.height, 2) + local radial, rings = math.max(1, num(props.radial_segments, 64)), math.max(0, num(props.rings, 4)) + local a = new() + local point, thisrow, prevrow = 0, 0, 0 + local sideY = (bottom - top) / height + for j = 0, rings + 1 do + local v = j / (rings + 1) + local radius = top + (bottom - top) * v + local y = height * 0.5 - height * v + for i = 0, radial do + local u = i / radial + local x, z= 0, 1 + if i ~= radial then + x = math.sin(u * TAU) + z = math.cos(u * TAU) + end + local l = math.sqrt(x * x + sideY * sideY + z * z) + add(a, x * radius, y, z * radius, x / l, sideY / l, z / l, z, 0, -x, u, v * 0.5) + point =point+ 1 + if i > 0 and j > 0 then + quad(a, prevrow + i - 1, prevrow + i, thisrow + i - 1, thisrow + i) + end + end + prevrow = thisrow + thisrow = point + end + local ix = a.indices + for _, cap in __iter({ { top, height * 0.5, 1 }, { bottom, height * -0.5, -1 } }) do + local r, y, ny= cap[1] , cap[2] , cap[3] +local enabled = (ny > 0 and{(props.cap_top ~= false )}or{(props.cap_bottom ~= false +)})[1] if enabled and r > 0 then + thisrow = point + add(a, 0, y, 0, 0, ny, 0, 1, 0, 0, ny > 0 and 0.25 or 0.75, 0.75) + point =point+ 1 + for i = 0, radial do + local t = i / radial + local x, z= 0, 1 + if i ~= radial then + x = math.sin(t * TAU) + z = math.cos(t * TAU) + end + local u = (ny > 0 and(((x + 1) * 0.25 ))or((0.5 + (x + 1) * 0.25 +))) local v = (ny > 0 and((0.5 + (z + 1) * 0.25 ))or((1 - (z + 1) * 0.25 +))) add(a, x * r, y, z * r, 0, ny, 0, 1, 0, 0, u, v) + point =point+ 1 + if i > 0 then + if ny > 0 then + ix[#ix + 1], ix[#ix + 2], ix[#ix + 3] = thisrow, point - 1, point - 2 + else + ix[#ix + 1], ix[#ix + 2], ix[#ix + 3] = thisrow, point - 2, point - 1 + end + end + end + end + end + return a +end + +Primitives.KINDS = ({ BoxMesh = true, PlaneMesh = true, QuadMesh = true, SphereMesh = true, CylinderMesh = true, CubeMesh = true }) + +function Primitives.build(kind, props) +local a +if kind == "BoxMesh" or kind == "CubeMesh" then + a = box(props) + elseif kind == "PlaneMesh" then + a = plane(props, false) + elseif kind == "QuadMesh" then + a = plane(props, true) + elseif kind == "SphereMesh" then + a = sphere(props) + elseif kind == "CylinderMesh" then + a = cylinder(props) + else + return nil + end + if props.flip_faces == true then + local ix = a.indices + for k = 1, #ix - 2, 3 do + ix[k + 1], ix[k + 2] = ix[k + 2], ix[k + 1] + end + end + return a +end + +return Primitives +end +__FILES["model/godot/Surface"] = function() +local __compat = __compat local buffer, type, __iter = __compat.buffer, __compat.type, __compat.__iter --!strict +-- model/godot/Surface: ArrayMesh surfaces <-> Scene primitives. Godot 4.2+ surfaces (format version 2: vertex_data = +-- positions then octahedral normal / tangent pairs, attribute_data = colour / UV / UV2 / custom per vertex, +-- skin_data = bones + weights, index_data u16 / u32; RenderingServer mesh_create_surface_data_from_arrays), and the +-- "arrays" surfaces of format-2 .escn files (Godot 3 ArrayType order). Godot's front faces are clockwise: triangle +-- winding is reversed both ways. Not supported: compressed attributes, format version 1 (Godot 4.0 / 4.1), Godot 3 +-- binary array_data, blend shapes (counted in extras). +local Types = __include("Types") +local GodotVariant = __include("codecs/text/GodotVariant") +local Primitives = __include("model/godot/Primitives") + +local Surface = {} + +local S = Types.Scene + +local function arr(n) +return (table.create(n) ) +end + +local function bit(f, i) +return math.floor(f / 2 ^ i) % 2 == 1 +end + +-- Vector3::octahedron_decode +local function octDecode(x, y) +local fx, fy = x * 2 - 1, y * 2 - 1 + local nz = 1 - math.abs(fx) - math.abs(fy) + local t = math.clamp(-nz, 0, 1) + fx =fx+ (fx >= 0 and{(-t )}or{t +})[1] fy =fy+ (fy >= 0 and{(-t )}or{t +})[1] local l = math.sqrt(fx * fx + fy * fy + nz * nz) + if l == 0 then + return 0, 0, 1 + end + return fx / l, fy / l, nz / l +end + +-- Vector3::octahedron_encode +local function octEncode(x, y, z) +local s = math.abs(x) + math.abs(y) + math.abs(z) + if s == 0 then + return 0.5, 0.5 + end + x, y, z = x / s, y / s, z / s + local ox, oy + if z >= 0 then + ox, oy = x, y + else + ox = (1 - math.abs(y)) * (x >= 0 and 1 or-1) + oy = (1 - math.abs(x)) * (y >= 0 and 1 or-1) + end + return ox * 0.5 + 0.5, oy * 0.5 + 0.5 +end + +local function u16(v) +return math.clamp(math.floor(v * 65535), 0, 65535) +end + +local CUSTOM_SIZE = { [0] = 4, 4, 4, 8, 4, 8, 12, 16 } + +-- a Godot 4 surface dictionary (format version 2) into lists + + + + + + + + + + + + + + +local function binary(d, maxVertices) +local f = tonumber(d.format) or 0 + local vc = tonumber(d.vertex_count) or 0 + if vc < 0 or vc > maxVertices or vc % 1 ~= 0 then + return nil, "limit: vertex count " .. tostring(d.vertex_count) + end + if bit(f, 29) then + return nil, "unsupported: compressed surface attributes" + end + if not bit(f, 35) then + return nil, "unsupported: surface format version 1 (Godot 4.0 / 4.1)" + end + local vd = GodotVariant.bytes(d.vertex_data) + if not vd then + return nil, "surface without vertex_data" + end + local is2D = bit(f, 25) + local pstride = is2D and 8 or 12 + local hasN, hasT = bit(f, 1), bit(f, 2) + local ntStride = (hasN and 4 or 0) + (hasT and 4 or 0) + if buffer.len(vd) < vc * (pstride + ntStride) then + return nil, "truncated vertex_data" + end + local L= { points = arr(vc * 3), jointsPer = 4, mode = "triangles" } + local P = L.points + for i = 0, vc - 1 do + local o = i * pstride + P[i * 3 + 1] = buffer.readf32(vd, o) + P[i * 3 + 2] = buffer.readf32(vd, o + 4) + P[i * 3 + 3] = is2D and 0 or buffer.readf32(vd, o + 8) + end + if ntStride > 0 then + local base = vc * pstride + local N, T = (hasN and{(arr(vc * 3) )}or{nil})[1], (hasT and{(arr(vc * 4) )}or{nil +})[1] for i = 0, vc - 1 do + local o = base + i * ntStride + if N then + local x, y, z = octDecode(buffer.readu16(vd, o) / 65535, buffer.readu16(vd, o + 2) / 65535) + N[i * 3 + 1], N[i * 3 + 2], N[i * 3 + 3] = x, y, z + o =o+ 4 + end + if T then + local tx = buffer.readu16(vd, o) / 65535 + local ty = buffer.readu16(vd, o + 2) / 65535 * 2 - 1 + local sign = ty >= 0 and 1 or-1 + local x, y, z = octDecode(tx, math.abs(ty)) + T[i * 4 + 1], T[i * 4 + 2], T[i * 4 + 3], T[i * 4 + 4] = x, y, z, sign + end + end + L.normals, L.tangents = N, T + end + -- attribute stream + local hasC, hasUV, hasUV2 = bit(f, 3), bit(f, 4), bit(f, 5) + local astride = (hasC and 4 or 0) + (hasUV and 8 or 0) + (hasUV2 and 8 or 0) + for k = 0, 3 do + if bit(f, 6 + k) then + astride =astride+ CUSTOM_SIZE[math.floor(f / 2 ^ (13 + 3 * k)) % 8] + end + end + if astride > 0 then + local ad = GodotVariant.bytes(d.attribute_data) + if not ad or buffer.len(ad) < vc * astride then + return nil, "truncated attribute_data" + end + local C = (hasC and{(buffer.create(vc * 4) )}or{nil +})[1] local UV, UV2 = (hasUV and{(arr(vc * 2) )}or{nil})[1], (hasUV2 and{(arr(vc * 2) )}or{nil +})[1] for i = 0, vc - 1 do + local o = i * astride + if C then + buffer.writeu32(C, i * 4, buffer.readu32(ad, o)) + o =o+ 4 + end + if UV then + UV[i * 2 + 1], UV[i * 2 + 2] = buffer.readf32(ad, o), buffer.readf32(ad, o + 4) + o =o+ 8 + end + if UV2 then + UV2[i * 2 + 1], UV2[i * 2 + 2] = buffer.readf32(ad, o), buffer.readf32(ad, o + 4) + end + end + L.colors, L.uvs, L.uv2s = C, UV, UV2 + end + -- skin stream: bones then weights per vertex + local hasB, hasW = bit(f, 10), bit(f, 11) + if hasB and hasW then + local per = bit(f, 27) and 8 or 4 + local sd = GodotVariant.bytes(d.skin_data) + if sd and buffer.len(sd) >= vc * per * 4 then + local J, W = arr(vc * per), arr(vc * per) + for i = 0, vc - 1 do + local o = i * per * 4 + for c = 0, per - 1 do + J[i * per + c + 1] = buffer.readu16(sd, o + c * 2) + W[i * per + c + 1] = buffer.readu16(sd, o + per * 2 + c * 2) / 65535 + end + end + L.joints, L.weights, L.jointsPer = J, W, per + end + end + local ic = tonumber(d.index_count) or 0 + if bit(f, 12) and ic > 0 then + local id = GodotVariant.bytes(d.index_data) + local size = vc <= 65536 and 2 or 4 + if not id or buffer.len(id) < ic * size then + return nil, "truncated index_data" + end + local I = arr(ic) + for i = 0, ic - 1 do + local v = (size == 2 and{(buffer.readu16(id, i * 2) )}or{(buffer.readu32(id, i * 4) +)})[1] if v >= vc then + return nil, "index out of range" + end + I[i + 1] = v + end + L.indices = I + end + local prim = tonumber(d.primitive) or 3 + L.mode = prim == 0 and"points" or(prim == 1 and"lines" or(prim == 2 and"line_strip" or(prim == 4 and"triangle_strip" or"triangles" +))) return L, nil +end + +local function nums(v) +return GodotVariant.numbers(v) +end + +-- a format-2 "arrays" surface (Godot 3 Mesh::ArrayType: vertex, normal, tangent, color, uv, uv2, bones, weights, index) +local function arrays(d, maxVertices) +local a = d.arrays + local P = nums(a[1]) + if not P or #P % 3 ~= 0 then + return nil, "surface without a vertex array" + end + local vc = math.floor(#P / 3 +) if vc > maxVertices then + return nil, "limit: vertex count " .. vc + end + local L= { points = P, jointsPer = 4, mode = "triangles" } + local N, T = nums(a[2]), nums(a[3]) + L.normals = (N and #N == vc * 3 and{N }or{nil +})[1] L.tangents = (T and #T == vc * 4 and{T }or{nil +})[1] local C = nums(a[4]) + if C and #C == vc * 4 then + local cb = buffer.create(vc * 4) + for i = 1, #C do + buffer.writeu8(cb, i - 1, math.clamp(math.floor(C[i] * 255 + 0.5), 0, 255)) + end + L.colors = cb + end + local UV, UV2 = nums(a[5]), nums(a[6]) + L.uvs = (UV and #UV == vc * 2 and{UV }or{nil +})[1] L.uv2s = (UV2 and #UV2 == vc * 2 and{UV2 }or{nil +})[1] local B, W = nums(a[7]), nums(a[8]) + if B and W and #B == vc * 4 and #W == vc * 4 then + L.joints, L.weights = B, W + end + local I = nums(a[9]) + if I and #I > 0 then + for _, v in __iter(I) do + if v < 0 or v >= vc then + return nil, "index out of range" + end + end + L.indices = I + end + local prim = tonumber(d.primitive) or 4 + L.mode = prim == 0 and"points" or(prim == 1 and"lines" or(prim == 2 and"line_strip" or(prim == 3 and"line_loop" or(prim == 5 and"triangle_strip" or(prim == 6 and"triangle_fan" or"triangles" +))))) return L, nil +end + +function Surface.lists(d, maxVertices) +if type(d) ~= "table" then + return nil, "bad surface" + end + if type(d.arrays) == "table" then + return arrays(d, maxVertices) + end + if d.array_data ~= nil then + return nil, "unsupported: Godot 3 binary surface (array_data)" + end + return binary(d, maxVertices) +end + +function Surface.fromPrimitiveArrays(a) +return { points = a.points, normals = a.normals, tangents = a.tangents, uvs = a.uvs, indices = a.indices, jointsPer = 4, mode = "triangles" } +end + +local function acc(list, comps, t) +local count = math.floor(#list / comps +) local typ = t or "f32" + local a = S.accessor(nil, typ , comps, count) + local d = a.data + for i, v in __iter(list) do + if typ == "f32" then + buffer.writef32(d, (i - 1) * 4, v) + elseif typ == "u16" then + buffer.writeu16(d, (i - 1) * 2, v) + end + end + return a +end + +-- lists into a Primitive; triangles (and strips / fans, made into triangles) get counter-clockwise winding +function Surface.primitive(L) +local n = math.floor(#L.points / 3 +) local attrs= { POSITION = acc(L.points, 3) } + if L.normals then + attrs.NORMAL = acc(L.normals , 3) + end + if L.tangents then + attrs.TANGENT = acc(L.tangents , 4) + end + if L.colors then + attrs.COLOR_0 = S.accessor(L.colors, "unorm8", 4, n) + end + if L.uvs then + attrs.TEXCOORD_0 = acc(L.uvs , 2) + end + if L.uv2s then + attrs.TEXCOORD_1 = acc(L.uv2s , 2) + end + if L.joints and L.weights then + local per = L.jointsPer + for set = 0, math.floor(per / 4 )- 1 do + local J, W = arr(n * 4), arr(n * 4) + for i = 0, n - 1 do + for c = 0, 3 do + J[i * 4 + c + 1] = (L.joints )[i * per + set * 4 + c + 1] or 0 + W[i * 4 + c + 1] = (L.weights )[i * per + set * 4 + c + 1] or 0 + end + end + attrs["JOINTS_" .. set] = acc(J, 4, "u16") + attrs["WEIGHTS_" .. set] = acc(W, 4) + end + end + local mode = L.mode + local idx = L.indices + if mode == "triangles" or mode == "triangle_strip" or mode == "triangle_fan" then + local src +if idx then + src = idx + else + src = arr(n) + for i = 1, n do + src[i] = i - 1 + end + end + local out= {} + if mode == "triangles" then + for k = 1, #src - 2, 3 do + table.insert(out, src[k]) + table.insert(out, src[k + 2]) + table.insert(out, src[k + 1]) + end + elseif mode == "triangle_strip" then + for k = 1, #src - 2 do + local a, b, c = src[k], src[k + 1], src[k + 2] + if k % 2 == 0 then + a, b = b, a + end + table.insert(out, a) + table.insert(out, c) + table.insert(out, b) + end + else + for k = 2, #src - 1 do + table.insert(out, src[1]) + table.insert(out, src[k + 1]) + table.insert(out, src[k]) + end + end + idx = out + mode = "triangles" + end + local prim= { attributes = attrs, mode = mode } + if idx then + prim.indices = acc(idx , 1, "u32") + local d = (prim.indices ).data + for i, v in __iter(idx) do + buffer.writeu32(d, (i - 1) * 4, v) + end + end + return prim +end + +-- ------------------------------------------------------------------------------------------------ write +local function perpendicular(x, y, z) +local ax, ay, az = math.abs(y) < 0.9 and 0 or 1, math.abs(y) < 0.9 and 1 or 0, 0 + local tx, ty, tz = ay * z - az * y, az * x - ax * z, ax * y - ay * x + local l = math.sqrt(tx * tx + ty * ty + tz * tz) + if l == 0 then + return 1, 0, 0 + end + return tx / l, ty / l, tz / l +end + +-- a triangle Primitive as a Godot 4 surface dictionary (format version 2, uncompressed); nil for other modes +function Surface.encode(prim, triangles) +local a = prim.attributes + local pos = a.POSITION + local rp = S.reader(pos) + if not rp then + return nil + end + local vc = pos.count + local an, at, ac, a0, a1= a.NORMAL, a.TANGENT, a.COLOR_0, a.TEXCOORD_0, a.TEXCOORD_1 + local rn = (an and{(S.reader(an) )}or{nil +})[1] local rt = (at and{(S.reader(at) )}or{nil +})[1] local rc = (ac and{(S.reader(ac) )}or{nil +})[1] local cc = (ac and{ac.components }or{0 +})[1] local ru = (a0 and{(S.reader(a0) )}or{nil +})[1] local ru2 = (a1 and{(S.reader(a1) )}or{nil +})[1] local flags = 1 + 2 ^ 35 + if rn then + flags =flags+ (2 + 4 +) end + local ntStride = rn and 8 or 0 + local vd = buffer.create(vc * (12 + ntStride)) + local lo, hi = { math.huge, math.huge, math.huge }, { -math.huge, -math.huge, -math.huge } + for i = 0, vc - 1 do + for c = 0, 2 do + local v = rp(i, c) + buffer.writef32(vd, i * 12 + c * 4, v) + lo[c + 1], hi[c + 1] = math.min(lo[c + 1], v), math.max(hi[c + 1], v) + end + if rn then + local nx, ny, nz = rn(i, 0), rn(i, 1), rn(i, 2) + local o = vc * 12 + i * 8 + local ox, oy = octEncode(nx, ny, nz) + buffer.writeu16(vd, o, u16(ox)) + buffer.writeu16(vd, o + 2, u16(oy)) + local tx, ty, tz, sign + if rt then + tx, ty, tz, sign = rt(i, 0), rt(i, 1), rt(i, 2), (at.components >= 4 and{(rt(i, 3) )}or{1 +})[1] else + tx, ty, tz = perpendicular(nx, ny, nz) + sign = 1 + end + -- Vector3::octahedron_tangent_encode + local qx, qy = octEncode(tx, ty, tz) + qy = math.max(qy, 1 / 32767) * 0.5 + 0.5 + qy = (sign >= 0 and{qy }or{(1 - qy +)})[1] buffer.writeu16(vd, o + 4, u16(qx)) + buffer.writeu16(vd, o + 6, u16(qy)) + end + end + local astride = (rc and 4 or 0) + (ru and 8 or 0) + (ru2 and 8 or 0) + local ad= nil + if astride > 0 then + flags =flags+ ((rc and 8 or 0) + (ru and 16 or 0) + (ru2 and 32 or 0) +) local b = buffer.create(vc * astride) + for i = 0, vc - 1 do + local o = i * astride + if rc then + for c = 0, 3 do + local v = (c < cc and{(rc(i, c) )}or{1 +})[1] buffer.writeu8(b, o + c, math.clamp(math.floor(v * 255 + 0.5), 0, 255)) + end + o =o+ 4 + end + if ru then + buffer.writef32(b, o, ru(i, 0)) + buffer.writef32(b, o + 4, ru(i, 1)) + o =o+ 8 + end + if ru2 then + buffer.writef32(b, o, ru2(i, 0)) + buffer.writef32(b, o + 4, ru2(i, 1)) + end + end + ad = b + end + local isize = vc <= 65536 and 2 or 4 + local id = buffer.create(#triangles * isize) + -- counter-clockwise -> Godot's clockwise + for k = 0, math.floor(#triangles / 3 )- 1 do + local t = { triangles[k * 3 + 1], triangles[k * 3 + 3], triangles[k * 3 + 2] } + for c = 0, 2 do + if isize == 2 then + buffer.writeu16(id, (k * 3 + c) * 2, t[c + 1]) + else + buffer.writeu32(id, (k * 3 + c) * 4, t[c + 1]) + end + end + end + flags =flags+ 4096 + if vc == 0 then + lo, hi = { 0, 0, 0 }, { 0, 0, 0 } + end + local keys = { "aabb" } + local out= { aabb = GodotVariant.ctor("AABB", { lo[1], lo[2], lo[3], hi[1] - lo[1], hi[2] - lo[2], hi[3] - lo[3] }) } + if ad then + out.attribute_data = ad + table.insert(keys, "attribute_data") + end + out.format = flags + out.index_count = #triangles + out.index_data = id + out.primitive = 3 + out.uv_scale = GodotVariant.ctor("Vector4", { 0, 0, 0, 0 }) + out.vertex_count = vc + out.vertex_data = vd + for _, k in __iter({ "format", "index_count", "index_data", "material", "primitive", "uv_scale", "vertex_count", "vertex_data" }) do + table.insert(keys, k) + end + return Types.object(out, keys) +end + +return Surface +end +__FILES["model/godot/Write"] = function() +local __compat = __compat local type, __iter = __compat.type, __compat.__iter --!strict +-- model/godot/Write: a Scene as a Godot 4 text scene (format 3): Node3D / MeshInstance3D / Camera3D / light nodes +-- with Transform3D transforms, ArrayMesh sub-resources (model/godot/Surface), StandardMaterial3D (linear colours back +-- to sRGB) and Texture2D ext_resources for textures with a uri. Several scene roots go under a "Root" Node3D. +local Types = __include("Types") +local GodotVariant = __include("codecs/text/GodotVariant") +local Surface = __include("model/godot/Surface") + +local Write = {} + +local S = Types.Scene +local ctor = GodotVariant.ctor + + + +local function section(tag, attrs) +local a, order = {}, {} + local i = 1 + while attrs[i] ~= nil do + if attrs[i + 1] ~= nil then + a[attrs[i] ] = attrs[i + 1] + table.insert(order, attrs[i]) + end + i =i+ 2 + end + return { tag = tag, attrs = a, attrOrder = order, props = {}, order = {} } +end + +local function prop(sec, k, v) + if v == nil then + return + end + if sec.props[k] == nil then + table.insert(sec.order, k) + end + sec.props[k] = v +end + +local function toSrgb(c) +c = math.clamp(c, 0, 1) + if c <= 0.0031308 then + return c * 12.92 + end + return 1.055 * c ^ (1 / 2.4) - 0.055 +end + +local function srgbColor(c, alpha) +local v = c or { 1, 1, 1 } + return ctor("Color", { toSrgb(v[1] or 1), toSrgb(v[2] or 1), toSrgb(v[3] or 1), alpha or v[4] or 1 }) +end + +local function transform(m) +return ctor("Transform3D", { m[1], m[5], m[9], m[2], m[6], m[10], m[3], m[7], m[11], m[13], m[14], m[15] }) +end + +local function isIdentity(m) +for i = 1, 16 do + if math.abs(m[i] - S.IDENTITY[i]) > 1e-12 then + return false + end + end + return true +end + +local function safeName(s, fallback) +local n = string.gsub(s or "", "[%.:@/\"%%]", "_") + return (n == "" and{fallback }or{n +})[1]end + +local function triangles(prim) +local mode = prim.mode or "triangles" + local pos = prim.attributes and prim.attributes.POSITION + if type(pos) ~= "table" then + return nil + end + local idx= {} + if prim.indices then + local rd = S.reader(prim.indices) + if not rd then + return nil + end + for i = 0, prim.indices.count - 1 do + idx[i + 1] = rd(i, 0) + end + else + for i = 0, pos.count - 1 do + idx[i + 1] = i + end + end + local out= {} + if mode == "triangles" then + for k = 1, #idx - 2, 3 do + table.insert(out, idx[k]) + table.insert(out, idx[k + 1]) + table.insert(out, idx[k + 2]) + end + elseif mode == "triangle_strip" then + for k = 1, #idx - 2 do + local a, b = idx[k], idx[k + 1] + if k % 2 == 0 then + a, b = b, a + end + table.insert(out, a) + table.insert(out, b) + table.insert(out, idx[k + 2]) + end + elseif mode == "triangle_fan" then + for k = 2, #idx - 1 do + table.insert(out, idx[1]) + table.insert(out, idx[k]) + table.insert(out, idx[k + 1]) + end + elseif mode == "polygons" and prim.faces then + local rd = S.reader(prim.faces) + local at = 1 + if rd then + for f = 0, prim.faces.count - 1 do + local size = rd(f, 0) + for k = 1, size - 2 do + table.insert(out, idx[at]) + table.insert(out, idx[at + k]) + table.insert(out, idx[at + k + 1]) + end + at =at+ size + end + end + else + return nil + end + for _, v in __iter(out) do + if v < 0 or v >= pos.count then + return nil + end + end + return out +end + +function Write.document(scene) +local sections= {} + local ext= {} + local sub= {} + local nodes= {} + local texId= {} + local matId= {} + local meshId= {} + local textures = scene.textures or {} + local function textureRef(ref) +if type(ref) ~= "table" then + return nil + end + local i = ref.texture + local tex = textures[i] + if not tex or type(tex.uri) ~= "string" or tex.uri == "" or string.sub(tex.uri, 1, 5) == "data:" then + return nil + end + if not texId[i] then + local id = (#ext + 1) .. "_tex" + texId[i] = id + local p = (string.find(tex.uri, "^res://") and{tex.uri }or{("res://" .. tex.uri +)})[1] table.insert(ext, section("ext_resource", { "type", "Texture2D", "path", p, "id", id })) + end + return ctor("ExtResource", { texId[i] }) + end + for i, m in __iter(scene.materials or {}) do + local id = "StandardMaterial3D_" .. i + matId[i] = id + local sec = section("sub_resource", { "type", "StandardMaterial3D", "id", id }) + if type(m.name) == "string" then + prop(sec, "resource_name", m.name) + end + local mode = m.alphaMode + if mode == "blend" then + prop(sec, "transparency", 1) + elseif mode == "mask" then + prop(sec, "transparency", 2) + prop(sec, "alpha_scissor_threshold", m.alphaCutoff or 0.5) + end + if m.doubleSided then + prop(sec, "cull_mode", 2) + end + local unlit = type(m.extensions) == "table" and m.extensions.KHR_materials_unlit ~= nil + if unlit then + prop(sec, "shading_mode", 0) + end + local bc = (type(m.baseColor) == "table" and{m.baseColor }or{{ 1, 1, 1, 1 } +})[1] prop(sec, "albedo_color", srgbColor(bc, bc[4] or 1)) + prop(sec, "albedo_texture", textureRef(m.baseColorTexture)) + prop(sec, "metallic", m.metallic or 0) + prop(sec, "roughness", m.roughness or 1) + local mr = textureRef(m.metallicRoughnessTexture) + if mr then + prop(sec, "metallic_texture", mr) + prop(sec, "metallic_texture_channel", 2) + prop(sec, "roughness_texture", mr) + prop(sec, "roughness_texture_channel", 1) + end + local e = m.emissive + if type(e) == "table" and ((e[1] or 0) > 0 or (e[2] or 0) > 0 or (e[3] or 0) > 0) or m.emissiveTexture then + prop(sec, "emission_enabled", true) + prop(sec, "emission", srgbColor(e, 1)) + local strength = type(m.extensions) == "table" and m.extensions.KHR_materials_emissive_strength + if type(strength) == "table" and type(strength.emissiveStrength) == "number" then + prop(sec, "emission_energy_multiplier", strength.emissiveStrength) + end + prop(sec, "emission_texture", textureRef(m.emissiveTexture)) + end + local nt = textureRef(m.normalTexture) + if nt then + prop(sec, "normal_enabled", true) + prop(sec, "normal_texture", nt) + end + local ao = textureRef(m.occlusionTexture) + if ao then + prop(sec, "ao_enabled", true) + prop(sec, "ao_texture", ao) + end + table.insert(sub, sec) + end + for i, mesh in __iter(scene.meshes or {}) do + local surfaces = {} + for _, prim in __iter(mesh.primitives or {}) do + local tris = triangles(prim) + if tris then + local sd = Surface.encode(prim, tris) + if sd then + if prim.material and matId[prim.material] then + Types.set(sd, "material", ctor("SubResource", { matId[prim.material] })) + end + table.insert(surfaces, sd) + end + end + end + if #surfaces > 0 then + local id = "ArrayMesh_" .. i + meshId[i] = id + local sec = section("sub_resource", { "type", "ArrayMesh", "id", id }) + if type(mesh.name) == "string" then + prop(sec, "resource_name", mesh.name) + end + prop(sec, "_surfaces", surfaces) + table.insert(sub, sec) + end + end + local all = scene.nodes or {} + local roots = scene.roots or {} + local single = #roots == 1 and all[roots[1] ] ~= nil + local visited= {} + local function emit(i, parent, used, depth) + local node = all[i] + if not node or visited[i] or depth > 512 then + return + end + visited[i] = true + local base = safeName(node.name, "Node" .. i) + local name, k = base, 1 + while used[name] do + k =k+ 1 + name = base .. k + end + used[name] = true + local cam = (node.camera and{(scene.cameras or {})[node.camera] }or{nil +})[1] local li = (node.light and{(scene.lights or {})[node.light] }or{nil +})[1] local typ = node.mesh and meshId[node.mesh] and"MeshInstance3D" +or(cam and"Camera3D" +or(li and{(li.type == "spot" and"SpotLight3D" or(li.type == "directional" and"DirectionalLight3D" or"OmniLight3D")) +}or{"Node3D" +})[1]) local sec = section("node", { "name", name, "type", typ, "parent", parent }) + local m = S.nodeMatrix(node) + if not isIdentity(m) then + prop(sec, "transform", transform(m)) + end + if typ == "MeshInstance3D" then + prop(sec, "mesh", ctor("SubResource", { meshId[node.mesh] })) + elseif typ == "Camera3D" then + if cam.type == "orthographic" then + prop(sec, "projection", 1) + prop(sec, "size", (cam.ymag or 0.5) * 2) + else + prop(sec, "fov", math.deg(cam.yfov or math.rad(75))) + end + prop(sec, "near", cam.znear or 0.05) + prop(sec, "far", cam.zfar or 4000) + elseif li then + prop(sec, "light_color", srgbColor(li.color, 1)) + prop(sec, "light_energy", li.intensity or 1) + if li.type == "point" then + prop(sec, "omni_range", li.range or 5) + elseif li.type == "spot" then + prop(sec, "spot_range", li.range or 5) + prop(sec, "spot_angle", math.deg(li.outerCone or math.pi / 4)) + end + end + local g = type(node.extras) == "table" and node.extras.godot + if type(g) == "table" and g.visible == false then + prop(sec, "visible", false) + end + table.insert(nodes, sec) + local path = parent == nil and"." or(parent == "." and{name }or{(parent .. "/" .. name +)})[1] local childUsed = {} + for _, c in __iter(node.children or {}) do + emit(c, path, childUsed, depth + 1) + end + end + if single then + emit(roots[1], nil, {}, 0) + else + table.insert(nodes, section("node", { "name", "Root", "type", "Node3D" })) + local used = {} + for _, r in __iter(roots) do + emit(r, ".", used, 1) + end + end + local steps = #ext + #sub + 1 + table.insert(sections, section("gd_scene", { "load_steps", steps, "format", 3 })) + for _, s in __iter(ext) do + table.insert(sections, s) + end + for _, s in __iter(sub) do + table.insert(sections, s) + end + for _, s in __iter(nodes) do + table.insert(sections, s) + end + return { sections = sections }, nil +end + return Write end __FILES["model/iqm"] = function() @@ -173771,6 +176356,673 @@ end return Decode end +__FILES["model/t3d"] = function() +local __compat = __compat local buffer = __compat.buffer --!strict +-- model/t3d: Unreal T3D text (UnrealEd map / brush export: Begin Map / Level / Actor / Brush / PolyList / Polygon, +-- Begin Object components), read only. Supports: brush polygons with texture projection (TextureU / TextureV / +-- Origin / Pan; sizes through opts.textureSize, default 256) as primitives per texture, CSG operation in extras +-- (subtractive brushes face inwards; the builder brush is skipped), actors as nodes with their properties and +-- transforms (UE1-3 Location / Rotation / DrawScale, UE4 RootComponent Relative*), lights, cameras, static mesh +-- references. Not supported: BSP CSG between brushes, sheared brush scales, terrain, static mesh geometry. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local Types = __include("Types") +local Text = __include("codecs/text/Text") +local Parse = __include("model/t3d/Parse") +local Build = __include("model/t3d/Build") + +-- ------------------------------------------------------------------------------------------------ contract +local T3d = { + name = "t3d", + category = "model", + extensions = { "t3d" }, + mime = { "text/x-unreal-t3d" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Text", "codecs/model/Brush" }, + caps = { decode = true, encode = false, text = true, brushes = true, actors = true }, +} +-- ------------------------------------------------------------------------------------------------ types +-- ------------------------------------------------------------------------------------------------ sniff + + + + + + + + + +function T3d.sniff(r) +local h = Sniff.text(r, 512) + local first = string.match(h, "^%s*(Begin%s+%a+)") + if first == nil then + return 0 + end + local kind = string.lower(string.match(first, "%a+$") or "") + if kind == "map" or kind == "actor" or kind == "level" or kind == "brush" or kind == "polylist" then + return 0.9 + end + return 0.3 +end + +-- ------------------------------------------------------------------------------------------------ decode +function T3d.decode(r, opts) +local o= opts or {} + if r.limit - r.base > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local text = buffer.readstring(r.buf, r.base, r.limit - r.base) + if string.sub(text, 1, 2) == "\255\254" then + text = Text.utf16(r.buf, r.base + 2, r.limit - r.base - 2, false) + else + text = Text.toUtf8(text) + end + local ok, root, msg = pcall(Parse.tree, text, o.maxBlocks or 2 ^ 22) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad data: " .. tostring(root)) + end + if not root then + return nil, Err.from(msg) + end + if #root.children == 0 then + return nil, Err.new(Err.CORRUPT, "no Begin blocks") + end + -- a bare brush export (Begin PolyList / Begin Brush): wrap it in an actor + local k = string.lower(root.children[1].kind) + if k == "polylist" or k == "brush" then + local function block(kind, attrs, props, children) +return { kind = kind, attrs = attrs, props = props, order = { "CsgOper" }, records = {}, degrees = {}, children = children } + end + local brush = (k == "brush" and{root.children }or{{ block("Brush", { Name = "Brush0" }, {}, root.children) } +})[1] root = block("", {}, {}, { block("Actor", { Class = "Brush", Name = "Brush0" }, { CsgOper = "CSG_Add" }, brush) }) + end + local ok2, scene, msg2 = pcall(Build.scene, root, o) + if not ok2 then + return nil, Err.from(tostring(scene)) + end + if not scene then + return nil, Err.from(msg2) + end + return scene, nil +end + +return T3d +end +__FILES["model/t3d/Build"] = function() +local __compat = __compat local type, __iter = __compat.type, __compat.__iter --!strict +-- model/t3d/Build: parsed T3D blocks into a Scene: one node per actor (Unreal's own Z-up, left-handed coordinates, +-- kept as they are), brush polygons as primitives per texture (codecs/model/Brush). Brush transform as UnrealEd's +-- ABrush coords: v - PrePivot, MainScale, Rotation, PostScale, + Location. Rotation as FRotationMatrix (Pitch / Yaw / +-- Roll: 65536 units per turn, or degrees in UE4 text). Polygon winding follows the stored Normal; subtractive +-- brushes face inwards. +local Types = __include("Types") +local Brush = __include("codecs/model/Brush") +local Parse = __include("model/t3d/Parse") + + + +local Build = {} + +local S = Types.Scene + +local function num(v, d) +return (type(v) == "number" and v == v and{v }or{d +})[1]end + +local function vec3(s) +if type(s) ~= "string" then + return nil + end + local a, b, c = string.match(s, "^%s*([^,%s]+)%s*,%s*([^,%s]+)%s*,%s*([^,%s]+)") + if not a then + return nil + end + local x, y, z = tonumber((string.gsub(a, "^%+", ""))), tonumber((string.gsub(b , "^%+", ""))), tonumber((string.gsub(c , "^%+", ""))) + if x and y and z then + return { x, y, z } + end + return nil +end + +local function xyz(v, d) +if type(v) == "table" then + return { num(v.X, d[1]), num(v.Y, d[2]), num(v.Z, d[3]) } + end + return d +end + +-- FRotationMatrix rows are the X / Y / Z axes: the columns of a column-major matrix +local function rotation(r, degrees) +if type(r) ~= "table" then + return S.IDENTITY + end + local k = (degrees and((math.pi / 180 ))or((math.pi * 2 / 65536 +))) local p, y, ro = num(r.Pitch, 0) * k, num(r.Yaw, 0) * k, num(r.Roll, 0) * k + local SP, CP, SY, CY, SR, CR = math.sin(p), math.cos(p), math.sin(y), math.cos(y), math.sin(ro), math.cos(ro) + return { + CP * CY, CP * SY, SP, 0, + SR * SP * CY - CR * SY, SR * SP * SY + CR * CY, -SR * CP, 0, + -(CR * SP * CY + SR * SY), CY * SR - CR * SP * SY, CR * CP, 0, + 0, 0, 0, 1, + } +end + +local function scaling(s) +return { s[1], 0, 0, 0, 0, s[2], 0, 0, 0, 0, s[3], 0, 0, 0, 0, 1 } +end + +local function translation(t) +return { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, t[1], t[2], t[3], 1 } +end + +local function plain(b) +local out= {} + for _, k in __iter(b.order) do + out[k] = b.props[k] + end + return out +end + +-- the component holding the actor's transform (UE4: RootComponent's Relative* properties) +local function component(actor, objects) +local root = actor.props.RootComponent + if type(root) == "string" then + local name = string.match(root, "'\"?([^'\"]+)\"?'") or root + name = string.match(name, "([^%.:]+)$") or name + if objects[name] then + return objects[name] + end + end + for _, o in __iter(objects) do + if o.RelativeLocation ~= nil or o.RelativeRotation ~= nil or o.RelativeScale3D ~= nil then + return o + end + end + return nil +end + +local function polygons(b, out) + for _, c in __iter(b.children) do + local k = string.lower(c.kind) + if k == "polygon" then + table.insert(out, c) + elseif k == "polylist" or k == "brush" then + polygons(c, out) + end + end +end + + + +local function material(ctx, name) +local m = ctx.materials[name] + if m then + return m + end + local mat = S.material((name ~= "" and{name }or{nil})[1]) + mat.metallic = 0 + if name ~= "" then + table.insert(ctx.scene.textures, { name = name }) + mat.baseColorTexture = { texture = #ctx.scene.textures } + end + mat.extras = { t3d = { texture = name } } + table.insert(ctx.scene.materials, mat) + ctx.materials[name] = #ctx.scene.materials + return #ctx.scene.materials +end + +-- the brush's polygons as Scene primitives (local brush space) +local function brushMesh(ctx, brush, subtract) +local list= {} + polygons(brush, list) + if #list == 0 then + return nil, nil + end + local faces= {} + local polys= {} + local flags= {} + for _, pb in __iter(list) do + local rec= {} + local verts= {} + for _, r in __iter(pb.records) do + local name = string.lower(r[1]) + if name == "vertex" then + local v = vec3(r[2]) + if v then + table.insert(verts, v[1]) + table.insert(verts, v[2]) + table.insert(verts, v[3]) + end + elseif rec[name] == nil then + rec[name] = r[2] + end + end + local nv = math.floor(#verts / 3 +) if nv >= 3 then + ctx.polys =ctx.polys+ 1 + if ctx.polys > (ctx.opts.maxPolygons or 2 ^ 20) then + return nil, "limit: over " .. (ctx.opts.maxPolygons or 2 ^ 20) .. " polygons" + end + -- Newell normal of the vertex order + local nx, ny, nz = 0, 0, 0 + for k = 0, nv - 1 do + local j = (k + 1) % nv + local ax, ay, az = verts[k * 3 + 1], verts[k * 3 + 2], verts[k * 3 + 3] + local bx, by, bz = verts[j * 3 + 1], verts[j * 3 + 2], verts[j * 3 + 3] + nx =nx+ (ay - by) * (az + bz) + ny =ny+ (az - bz) * (ax + bx) + nz =nz+ (ax - bx) * (ay + by) + end + local stated = vec3(rec.normal) + local n = stated or { nx, ny, nz } + local l = math.sqrt(n[1] * n[1] + n[2] * n[2] + n[3] * n[3]) + if l > 0 then + n = { n[1] / l, n[2] / l, n[3] / l } + end + local reverse = nx * n[1] + ny * n[2] + nz * n[3] < 0 + if subtract then + reverse = not reverse + n = { -n[1], -n[2], -n[3] } + end + if reverse then + local r= {} + for k = nv - 1, 0, -1 do + table.insert(r, verts[k * 3 + 1]) + table.insert(r, verts[k * 3 + 2]) + table.insert(r, verts[k * 3 + 3]) + end + verts = r + end + local tex = (type(pb.attrs.Texture) == "string" and{pb.attrs.Texture }or{((pb.attrs.Texture ~= nil and{(tostring(pb.attrs.Texture) )}or{""})[1]) +})[1] local o = vec3(rec.origin) or { 0, 0, 0 } + local u = vec3(rec.textureu) or { 1, 0, 0 } + local v = vec3(rec.texturev) or { 0, 1, 0 } + local panU, panV = 0, 0 + if rec.pan then + panU = tonumber(string.match(rec.pan, "U=%s*([-+]?[%d%.]+)")) or 0 + panV = tonumber(string.match(rec.pan, "V=%s*([-+]?[%d%.]+)")) or 0 + end + -- texel = (p - Origin) . TextureU + PanU + local face= { + plane = { n[1], n[2], n[3], n[1] * o[1] + n[2] * o[2] + n[3] * o[3] }, + texture = tex, + vecs = { + { u[1], u[2], u[3], panU - (o[1] * u[1] + o[2] * u[2] + o[3] * u[3]) }, + { v[1], v[2], v[3], panV - (o[1] * v[1] + o[2] * v[2] + o[3] * v[3]) }, + }, + } + table.insert(faces, face) + table.insert(polys, { brush = 1, face = #faces, points = verts, normal = n }) + table.insert(flags, num(pb.attrs.Flags, 0)) + end + end + local size = ctx.opts.textureSize + local built = Brush.primitives(polys, { faces }, function(name) +if type(size) == "function" then + local ok, w, h = pcall(size, name) + if ok and type(w) == "number" then + return w, (type(h) == "number" and{h }or{w +})[1] end + elseif type(size) == "table" and type(size[name]) == "table" then + return num(size[name][1], 256), num(size[name][2], 256) + end + return 256, 256 + end) + local mesh= { name = (type(brush.attrs.Name) == "string" and{brush.attrs.Name }or{nil})[1], primitives = {} } + for _, b in __iter(built) do + b.primitive.material = material(ctx, b.texture) + table.insert(mesh.primitives, b.primitive) + end + mesh.extras = { t3d = { polygons = #polys } } + return mesh, nil +end + +local LIGHTS= { + Light = "point", PointLight = "point", SpotLight = "spot", DirectionalLight = "directional", TriggerLight = "point", + SkyLight = "directional", Spotlight = "spot", SunLight = "directional", DominantDirectionalLight = "directional", + PointLightMovable = "point", SpotLightMovable = "spot", DirectionalLightMovable = "directional", +} + +-- HSV of UE1 lights: LightHue / LightSaturation (255 = white) / LightBrightness, all 0..255 +local function hsv(h, s) +local hh = (h % 256) / 256 * 6 + local i = math.floor(hh) + local f = hh - i + local p, q, t = 1 - s, 1 - s * f, 1 - s * (1 - f) + local rgb = ({ { 1, t, p }, { q, 1, p }, { p, 1, t }, { p, q, 1 }, { t, p, 1 }, { 1, p, q } })[i % 6 + 1] + return rgb +end + +local function light(ctx, class, p, comp) +local typ = LIGHTS[class] + local l= { type = typ, color = { 1, 1, 1 }, intensity = 1 } + if p.LightBrightness ~= nil or p.LightHue ~= nil or p.LightSaturation ~= nil then + l.color = hsv(num(p.LightHue, 0), 1 - num(p.LightSaturation, 255) / 255) + l.intensity = num(p.LightBrightness, 64) / 255 + end + local c= comp or {} + local col = c.LightColor or p.LightColor + if type(col) == "table" then + l.color = { num(col.R, 255) / 255, num(col.G, 255) / 255, num(col.B, 255) / 255 } + end + if c.Intensity ~= nil or c.Brightness ~= nil then + l.intensity = num(c.Intensity, num(c.Brightness, 1)) + end + local radius = c.AttenuationRadius or c.Radius + if type(radius) == "number" then + l.range = radius + end + if typ == "spot" then + l.outerCone = math.rad(num(c.OuterConeAngle, num(p.LightCone, 44))) + l.innerCone = math.rad(num(c.InnerConeAngle, 0)) + end + table.insert(ctx.scene.lights, l) + return #ctx.scene.lights +end + +local function actors(b, out) + for _, c in __iter(b.children) do + local k = string.lower(c.kind) + if k == "actor" then + table.insert(out, c) + elseif k == "map" or k == "level" or k == "surface" then + actors(c, out) + end + end +end + +function Build.scene(root, opts) +local sc = S.new() + sc.meta.up = "z" + sc.meta.handedness = "left" + local list= {} + actors(root, list) + local ctx= { scene = sc, materials = {}, opts = opts or {}, polys = 0 } + local ue4 = false + for _, a in __iter(list) do + local rawClass = (a.attrs.Class ~= nil and{(tostring(a.attrs.Class) )}or{"Actor" +})[1] local class = string.match(rawClass, "([%w_]+)$") or rawClass + if string.find(rawClass, "/Script/", 1, true) then + ue4 = true + end + local p = a.props + local objects= {} + local objectClass= {} + for _, c in __iter(a.children) do + if string.lower(c.kind) == "object" then + local name = (c.attrs.Name ~= nil and{(tostring(c.attrs.Name) )}or{("Object" .. #a.children) +})[1] local o = objects[name] or {} + for _, k in __iter(c.order) do + o[k] = c.props[k] + end + objects[name] = o + if c.attrs.Class ~= nil then + objectClass[name] = tostring(c.attrs.Class) + end + end + end + local comp = component(a, objects) + local node= { name = (a.attrs.Name ~= nil and{(tostring(a.attrs.Name) )}or{class})[1], children = {} } + local m +if comp and p.Location == nil then + local deg = true + local loc = xyz(comp.RelativeLocation, { 0, 0, 0 }) + local sc3 = xyz(comp.RelativeScale3D, { 1, 1, 1 }) + m = S.mul(translation(loc), S.mul(rotation(comp.RelativeRotation, deg), scaling(sc3))) + else + local loc = xyz(p.Location, { 0, 0, 0 }) + local deg = a.degrees.Rotation == true + local rot = rotation(p.Rotation, deg) + local isBrush = false + for _, c in __iter(a.children) do + if string.lower(c.kind) == "brush" then + isBrush = true + end + end + if isBrush then + local pre = xyz(p.PrePivot, { 0, 0, 0 }) + local main = xyz(type(p.MainScale) == "table" and p.MainScale.Scale, { 1, 1, 1 }) + local post = xyz(type(p.PostScale) == "table" and p.PostScale.Scale, { 1, 1, 1 }) + m = S.mul(translation(loc), S.mul(scaling(post), S.mul(rot, S.mul(scaling(main), translation({ -pre[1], -pre[2], -pre[3] }))))) + else + local ds = num(p.DrawScale, 1) + local s3 = xyz(p.DrawScale3D, { 1, 1, 1 }) + m = S.mul(translation(loc), S.mul(rot, scaling({ s3[1] * ds, s3[2] * ds, s3[3] * ds }))) + end + end + node.matrix = m + local csg = (type(p.CsgOper) == "string" and{p.CsgOper +}or{p.BrushType == "Brush_Subtract" and"CSG_Subtract" +or(p.BrushType == "Brush_Add" and"CSG_Add" +or nil +)})[1] local extras= { class = rawClass, properties = plain(a), csg = csg } + if next(objects) then + extras.objects = objects + extras.objectClasses = objectClass + end + for _, c in __iter(a.children) do + if string.lower(c.kind) == "brush" then + local builder = csg == "CSG_Active" or (class == "Brush" and csg == nil and node.name == "Brush") + extras.builder = builder and true or nil + if not builder or ctx.opts.builder then + local mesh, err = brushMesh(ctx, c, csg == "CSG_Subtract") + if err then + return nil, err + end + if mesh then + table.insert(sc.meshes, mesh) + node.mesh = #sc.meshes + end + end + end + end + if LIGHTS[class] then + local lc= nil + for name, o in __iter(objects) do + if string.find(objectClass[name] or name, "Light", 1, true) then + lc = o + end + end + node.light = light(ctx, class, p, lc) + elseif class == "CameraActor" or class == "Camera" then + local fov = num(p.FOVAngle, 90) + for _, o in __iter(objects) do + if o.FieldOfView ~= nil then + fov = num(o.FieldOfView, fov) + end + end + table.insert(sc.cameras, { type = "perspective", yfov = math.rad(fov), znear = 1 } ) + node.camera = #sc.cameras + end + local sm = p.StaticMesh + for _, o in __iter(objects) do + if o.StaticMesh ~= nil then + sm = o.StaticMesh + end + end + if type(sm) == "string" then + extras.staticMesh = string.match(sm, "'\"?([^'\"]+)\"?'") or sm + end + node.extras = { t3d = extras } + table.insert(sc.nodes, node) + table.insert(sc.roots, #sc.nodes) + end + sc.meta.source = { format = "t3d", engine = ue4 and"ue4" or"ue1-3", actors = #list, polygons = ctx.polys } + return sc, nil +end + +return Build +end +__FILES["model/t3d/Parse"] = function() +local __compat = __compat local __iter = __compat.__iter --!strict +-- model/t3d/Parse: Unreal T3D text into nested blocks. A line `Begin Key=Value ...` opens a block, `End ` +-- closes it; other lines are `Key=Value` properties or, inside polygons, `Origin x,y,z` / `Vertex x,y,z` style +-- records. Values: numbers, quoted strings, structs `(X=1,Y=2)` as tables, object references +-- (`Model'MyLevel.Model1'`) as strings. +local Parse = {} + +-- "(X=1.0,Y=2,Z=-3)" / "(Scale=(X=1,Y=1,Z=1),SheerAxis=SHEER_ZX)"; i at '(' + + + + + + + + + + + +local function struct(s, i, depth) +local out= {} + local n = #s + i =i+ 1 + while i <= n do + local c = string.sub(s, i, i) + if c == ")" then + return out, i + 1 + elseif c == "," or c == " " or c == "\t" then + i =i+ 1 + else + local k, e = string.match(s, "^([^=,()]+)=()", i) + if not k then + -- an array element without a key: (1,2,3) + local v, ni = Parse.value(s, i, depth + 1) + table.insert(out, v) + i = ni + else + local key = string.gsub(k , "^%s+", "") + local v, ni = Parse.value(s, e , depth + 1) + out[key] = v + i = ni + end + end + end + return out, i +end + +-- a value starting at i, up to the next unbracketed ',' / ')' (inside structs) or the end +function Parse.value(s, i, depth) +local n = #s + local c = string.sub(s, i, i) + if c == "(" and depth < 32 then + return struct(s, i, depth) + elseif c == "\"" then + local e = string.find(s, "\"", i + 1, true) or (n + 1) + return string.sub(s, i + 1, e - 1), e + 1 + end + -- a bare token; object references may hold quotes ('...' and "...") + local j = i + local q= nil + while j <= n do + local ch = string.sub(s, j, j) + if q then + if ch == q then + q = nil + end + elseif ch == "'" or ch == "\"" then + q = ch + elseif depth > 0 and (ch == "," or ch == ")") then + break + end + j =j+ 1 + end + local tok = (string.match(string.sub(s, i, j - 1), "^%s*(.-)%s*$") ) +local num = tonumber(tok) + if num ~= nil and string.match(tok, "^[-+]?[%d%.]+[eE]?[-+]?%d*$") then + return num, j + end + return tok, j +end + +-- Key=Value pairs of a Begin line ("Begin Actor Class=Light Name=Light0"); quoted values may hold spaces +local function attrs(rest) +local out= {} + local i, n = 1, #rest + while i <= n do + local k, e = string.match(rest, "^%s*([%w_%.]+)=()", i) + if not k then + break + end + local v +if string.sub(rest, e , e ) == "\"" then + local q = string.find(rest, "\"", (e ) + 1, true) or (n + 1) + v = string.sub(rest, (e ) + 1, q - 1) + i = q + 1 + else + local stop = string.find(rest, "%s", e ) or (n + 1) + v = string.sub(rest, e , stop - 1) + i = stop + end + out[k ] = tonumber(v) or v + end + return out +end + +local function block(kind, a) +return { kind = kind, attrs = a, props = {}, order = {}, records = {}, children = {}, degrees = {} } +end + +function Parse.tree(text, maxBlocks) +local root = block("", {}) + local stack= { root } + local count = 0 + local lineNo = 0 + for raw in __iter(string.gmatch(text, "[^\n]*")) do + lineNo =lineNo+ 1 + local line = (string.match(raw, "^%s*(.-)%s*$") ) +if line ~= "" and string.sub(line, 1, 2) ~= "//" then + local cur = stack[#stack] + local word, rest = string.match(line, "^(%a+)%s*(.*)$") + local lw = (word and{(string.lower(word) )}or{"" +})[1] if lw == "begin" then + local kind, after = string.match(rest , "^(%S+)%s*(.*)$") + if not kind then + return nil, "Begin without a kind at line " .. lineNo + end + count =count+ 1 + if count > maxBlocks then + return nil, "limit: over " .. maxBlocks .. " blocks" + end + if #stack > 64 then + return nil, "limit: blocks nested too deep" + end + local b = block(kind , attrs(after )) + table.insert(cur.children, b) + table.insert(stack, b) + elseif lw == "end" and #stack > 1 and (rest == "" or string.lower(string.match(rest , "^(%S+)") or "") == string.lower(cur.kind)) then + table.remove(stack) + else + local k, e = string.match(line, "^([%w_%(%)%[%]%.]+)%s*=()") + if k then + local v = Parse.value(line, e , 0) + if cur.props[k ] == nil then + table.insert(cur.order, k ) + end + cur.props[k ] = v + if string.find(string.sub(line, e ), "Pitch=[-+]?%d*%.") or string.find(string.sub(line, e ), "Yaw=[-+]?%d*%.") then + cur.degrees[k ] = true + end + else + -- a record: Origin / Normal / TextureU / TextureV / Vertex / Pan U=0 V=0 + local name, data = string.match(line, "^(%a+)%s+(.*)$") + if name then + table.insert(cur.records, { name , data }) + end + end + end + end + end + if #stack > 1 then + return nil, "truncated: " .. stack[#stack].kind .. " block not closed" + end + return root, nil +end + +return Parse +end __FILES["model/usda"] = function() local __compat = __compat local buffer, type, __iter = __compat.buffer, __compat.type, __compat.__iter --!strict -- model/usda: USD ASCII layers (.usda, text .usd) and USDZ packages of them, from the Sdf text format and the UsdGeom / @@ -189321,6 +192573,1960 @@ end return Vtt end +__FILES["vector/ldtk"] = function() +local __compat = __compat local buffer, type = __compat.buffer, __compat.type --!strict +-- vector/ldtk: LDtk projects (.ldtk JSON, ldtk.io/json, 1.x) as a TileMap, read + write. Supports: IntGrid, +-- AutoLayer, Tiles and Entities layers, tilesets as image paths, typed fields (properties), multi-world projects, +-- external levels (.ldtkl through opts.resolve). Not supported: auto-layer rules are kept, never run; writing +-- external level files (levels are embedded); standalone .ldtkl files. + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local Types = __include("Types") +local Json = __include("codecs/text/Json") +local Read = __include("vector/ldtk/Read") +local Write = __include("vector/ldtk/Write") + +-- ------------------------------------------------------------------------------------------------ contract +local Ldtk = { + name = "ldtk", + category = "vector", + extensions = { "ldtk" }, + mime = { "application/x-ldtk+json" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Json" }, + caps = { decode = true, encode = true, levels = true, worlds = true, intGrid = true, entities = true }, +} + +-- ------------------------------------------------------------------------------------------------ sniff + + + + + + + + + +function Ldtk.sniff(r) +local h = Sniff.text(r, 1024) + if not string.match(h, "^%s*{") then + return 0 + end + if string.find(h, "\"fileType\"%s*:%s*\"LDtk Project JSON\"") then + return 1 + end + if string.find(h, "\"jsonVersion\"", 1, true) and string.find(h, "\"worldLayout\"", 1, true) then + return 0.8 + end + return 0 +end + +-- ------------------------------------------------------------------------------------------------ decode +function Ldtk.decode(r, opts) +local o= opts or {} + if r.limit - r.base > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local v, jerr = Json.decode(buffer.readstring(r.buf, r.base, r.limit - r.base), { ordered = true }) + if v == nil then + return nil, jerr + end + local ok, map, msg = pcall(Read.project, v, o) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad project: " .. tostring(map)) + end + if not map then + return nil, Err.from(msg) + end + return map, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +function Ldtk.encode(map, opts) +if type(map) ~= "table" or type(map.layers) ~= "table" or type(map.tilesets) ~= "table" then + return nil, Err.new(Err.ARG, "needs a TileMap value") + end + local ok, v, msg = pcall(Write.project, map, opts) + if not ok then + return nil, Err.new(Err.ARG, "bad map: " .. tostring(v)) + end + if v == nil then + return nil, Err.new(Err.ARG, msg or "bad map") + end + local indent = (opts and opts.indent == 0 and{nil }or{(opts and opts.indent or 2) +})[1] local s, jerr = Json.encode(v, { indent = indent }) + if not s then + return nil, jerr + end + return buffer.fromstring(s), nil +end + +return Ldtk +end +__FILES["vector/ldtk/Read"] = function() +local __compat = __compat local bit32, type, __iter = __compat.bit32, __compat.type, __compat.__iter --!strict +-- vector/ldtk/Read: an LDtk project (JSON, ldtk.io/json 1.5) into a Types.TileMap: one group layer per level (inside +-- one group per world for multi-world projects), the level's layers bottom first. Tile gids are firstGid + the +-- LDtk tile id with the f bits as Tiled's flip flags (bit 0 X -> 0x80000000, bit 1 Y -> 0x40000000). +local Types = __include("Types") +local Json = __include("codecs/text/Json") + +local Read = {} + +local FLIP_X, FLIP_Y = 0x80000000, 0x40000000 + +local function n(v, default) +return (type(v) == "number" and{v }or{default +})[1]end +local function s(v) +return (type(v) == "string" and{v }or{nil +})[1]end +local NULL = Json.null +local function tab(v) +return type(v) == "table" and v ~= NULL +end +local function list(v) +return (tab(v) and{v }or{{} +})[1]end + +-- every key but the ones listed (the raw part kept for the writer) +local function rest(t, skip) +local keys = Json.keys(t) + local out= {} + local order = {} + for _, k in __iter(keys) do + if not skip[k] then + out[k] = t[k] + table.insert(order, k) + end + end + return Json.object(out, order) +end + +function Read.fields(v) +local props= {} + local types= nil + for _, f in __iter(list(v)) do + if type(f) == "table" and type(f.__identifier) == "string" then + props[f.__identifier] = f.__value + if type(f.__type) == "string" then + types = types or {} + ;(types )[f.__identifier] = f.__type + end + end + end + return props, types +end + + + +local function tiles(ctx, raw, ts, grid, cw, ch) +local out = table.create(#raw) + local data= nil + if cw > 0 and ch > 0 then + data = table.create(cw * ch, 0) + end + for i, t in __iter(raw) do + if type(t) == "table" then + local px, src = list(t.px), list(t.src) + local tile = { + x = n(px[1], 0), + y = n(px[2], 0), + tile = n(t.t, 0), + flip = n(t.f, 0), + srcX = n(src[1], 0), + srcY = n(src[2], 0), + alpha = n(t.a, 1), + d = t.d, + } + out[i] = tile + if data and ts then + local cx, cy = math.floor(tile.x / grid), math.floor(tile.y / grid +) if cx >= 0 and cy >= 0 and cx < cw and cy < ch then + local gid = ts.firstGid + tile.tile + if bit32.btest(tile.flip, 1) then + gid =gid+ FLIP_X + end + if bit32.btest(tile.flip, 2) then + gid =gid+ FLIP_Y + end + -- later tiles are drawn over earlier ones + data[1 + cx + cy * cw] = gid + end + end + end + end + return out, data +end + +local LAYER_SKIP = { __identifier = true, __type = true, __cWid = true, __cHei = true, __gridSize = true, __opacity = true, __pxTotalOffsetX = true, __pxTotalOffsetY = true, __tilesetDefUid = true, __tilesetRelPath = true, visible = true, intGridCsv = true, autoLayerTiles = true, gridTiles = true, entityInstances = true } +local ENTITY_SKIP = { __identifier = true, __grid = true, __pivot = true, __tags = true, __tile = true, __smartColor = true, __worldX = true, __worldY = true, width = true, height = true, px = true, fieldInstances = true } + +local function layer(ctx, li) +local kind = s(li.__type) or "Tiles" + local cw, ch = n(li.__cWid, 0), n(li.__cHei, 0) + if cw < 0 or ch < 0 or cw * ch > ctx.maxCells then + return nil, "limit: layer of " .. cw .. " x " .. ch .. " cells" + end + local grid = math.max(1, n(li.__gridSize, 16)) + local out= { + name = s(li.__identifier) or "", + type = kind == "Entities" and"objects" or"tiles", + visible = li.visible ~= false, + opacity = n(li.__opacity, 1), + properties = {}, + offsetX = n(li.__pxTotalOffsetX, 0), + offsetY = n(li.__pxTotalOffsetY, 0), + ldtkType = kind, + gridSize = grid, + ldtk = rest(li, LAYER_SKIP), + } + if kind == "Entities" then + local objs = {} + for _, e in __iter(list(li.entityInstances)) do + if type(e) == "table" then + local w, h = n(e.width, 0), n(e.height, 0) + local pv, px = list(e.__pivot), list(e.px) + local pX, pY = n(pv[1], 0), n(pv[2], 0) + local props, types = Read.fields(e.fieldInstances) + local o= { + id = s(e.iid), + name = s(e.__identifier) or "", + class = s(e.__identifier) or "", + x = n(px[1], 0) - pX * w, + y = n(px[2], 0) - pY * h, + width = w, + height = h, + rotation = 0, + visible = true, + shape = "rectangle", + pivot = { pX, pY }, + tags = e.__tags, + tile = (tab(e.__tile) and{e.__tile }or{nil})[1], + color = s(e.__smartColor), + properties = props, + propertyTypes = types, + ldtk = rest(e, ENTITY_SKIP), + fieldInstances = e.fieldInstances, + } + table.insert(objs, o) + end + end + out.objects = objs + return out, nil + end + out.width, out.height = cw, ch + local tsUid = li.__tilesetDefUid + local ts = (type(tsUid) == "number" and{ctx.tilesets[tsUid] }or{nil +})[1] if ts then + out.tileset = ts.name + end + out.tilesetPath = s(li.__tilesetRelPath) + local raw = (kind == "Tiles" and{(list(li.gridTiles) )}or{(list(li.autoLayerTiles) +)})[1] local tl, data = tiles(ctx, raw, ts, grid, cw, ch) + out.tiles = tl + out.data = data or {} + if kind == "IntGrid" then + local csv = list(li.intGridCsv) + local grid2 = table.create(cw * ch, 0) + for i = 1, math.min(#csv, cw * ch) do + grid2[i] = n(csv[i], 0) + end + out.intGrid = grid2 + local def = (type(li.layerDefUid) == "number" and{ctx.layerDefs[li.layerDefUid] }or{nil +})[1] if def then + local values = {} + for _, v in __iter(list(def.intGridValues)) do + if type(v) == "table" then + table.insert(values, { value = n(v.value, 0), identifier = s(v.identifier), color = s(v.color) }) + end + end + out.intGridValues = values + end + end + return out, nil +end + +local LEVEL_SKIP = { identifier = true, worldX = true, worldY = true, pxWid = true, pxHei = true, __bgColor = true, fieldInstances = true, layerInstances = true } + +local function level(ctx, lv, resolve) +local layers = lv.layerInstances + local external = s(lv.externalRelPath) + local unresolved = false + if not tab(layers) and external then + local data= nil + if resolve then + local ok, b = pcall(resolve, external) + data = (ok and type(b) == "buffer" and{b }or{nil +})[1] end + if data then + local v, err = Json.decode(data, { ordered = true }) + if not tab(v) then + return nil, "external level " .. external .. ": " .. tostring(err) + end + lv = v + layers = v.layerInstances + else + unresolved = true + end + end + local props, types = Read.fields(lv.fieldInstances) + local g= { + name = s(lv.identifier) or "", + type = "group", + visible = true, + opacity = 1, + properties = props, + propertyTypes = types, + offsetX = n(lv.worldX, 0), + offsetY = n(lv.worldY, 0), + layers = {}, + level = true, + pxWidth = n(lv.pxWid, 0), + pxHeight = n(lv.pxHei, 0), + backgroundColor = s(lv.__bgColor), + external = external, + unresolved = unresolved and true or nil, + ldtk = rest(lv, LEVEL_SKIP), + } + local ls = list(layers) + for i = #ls, 1, -1 do + local l, err = layer(ctx, ls[i]) + if not l then + return nil, err + end + table.insert(g.layers , l) + end + return g, nil +end + +local PROJECT_SKIP = { levels = true, worlds = true } + +function Read.project(v, opts) +if not tab(v) or not tab(v.defs) then + return nil, "no defs: not an LDtk project" + end + local grid = math.max(1, n(v.defaultGridSize, 16)) + local map = Types.TileMap.new(0, 0, grid, grid) + local ctx= { tilesets = {}, maxCells = opts.maxCells or 2 ^ 26, layerDefs = {} } + local gid = 1 + for _, t in __iter(list(v.defs.tilesets)) do + if type(t) == "table" then + local cw, ch = n(t.__cWid, 0), n(t.__cHei, 0) + local size = n(t.tileGridSize, grid) + local ts= { + name = s(t.identifier) or ("tileset" .. #map.tilesets), + firstGid = gid, + tileWidth = size, + tileHeight = size, + columns = cw, + count = cw * ch, + imageSource = s(t.relPath), + imageWidth = n(t.pxWid, 0), + imageHeight = n(t.pxHei, 0), + spacing = n(t.spacing, 0), + margin = n(t.padding, 0), + uid = t.uid, + embedAtlas = s(t.embedAtlas), + properties = {}, + } + gid =gid+ math.max(1, cw * ch) + table.insert(map.tilesets, ts) + if type(t.uid) == "number" then + ctx.tilesets[t.uid] = ts + end + end + end + for _, d in __iter(list(v.defs.layers)) do + if type(d) == "table" and type(d.uid) == "number" then + ctx.layerDefs[d.uid] = d + end + end + local resolve = opts.resolve + local worlds = list(v.worlds) + local minX, minY, maxX, maxY = math.huge, math.huge, -math.huge, -math.huge + local function addLevels(into, levels) +for _, lv in __iter(list(levels)) do + if type(lv) == "table" then + local g, err = level(ctx, lv, resolve) + if not g then + return err + end + local x, y = g.offsetX , g.offsetY +minX, minY = math.min(minX, x), math.min(minY, y) + maxX, maxY = math.max(maxX, x + (g.pxWidth )), math.max(maxY, y + (g.pxHeight )) + table.insert(into, g) + end + end + return nil + end + if #worlds > 0 then + for _, w in __iter(worlds) do + if type(w) == "table" then + local wg= { + name = s(w.identifier) or "", + type = "group", + visible = true, + opacity = 1, + properties = {}, + layers = {}, + world = true, + ldtk = rest(w, { levels = true, identifier = true }), + } + local err = addLevels(wg.layers , w.levels) + if err then + return nil, err + end + table.insert(map.layers, wg) + end + end + else + local err = addLevels(map.layers, v.levels) + if err then + return nil, err + end + end + if minX <= maxX then + map.width = math.ceil((maxX - math.min(minX, 0)) / grid) + map.height = math.ceil((maxY - math.min(minY, 0)) / grid) + end + map.backgroundColor = s(v.bgColor) + map.worldLayout = s(v.worldLayout) + map.ldtk = rest(v, PROJECT_SKIP) + map.meta.source = { format = "ldtk", version = s(v.jsonVersion), externalLevels = v.externalLevels == true, multiWorld = #worlds > 0 } + return map, nil +end + +return Read +end +__FILES["vector/ldtk/Write"] = function() +local __compat = __compat local bit32, type, __iter = __compat.bit32, __compat.type, __compat.__iter --!strict +-- vector/ldtk/Write: a Types.TileMap as an LDtk project (JSON 1.5). Maps read from LDtk keep their raw defs, project, +-- level, layer and entity fields (the .ldtk tables); other maps get definitions made from their layers, tilesets and +-- object classes. A tile layer writes its `tiles` list when present, else its gid `data`. Levels are always embedded. +local Types = __include("Types") +local Json = __include("codecs/text/Json") + +local Write = {} + +local NULL = Json.null +local FLAGS = 0xF0000000 + +local function tab(v) +return type(v) == "table" and v ~= NULL +end +local function list(v) +return (tab(v) and{v }or{{} +})[1]end +local function n(v, default) +return (type(v) == "number" and v == v and{v }or{default +})[1]end + + + + + + + + + + + + + +local function clone(t) +if not tab(t) then + return Json.object({}) + end + local keys = Json.keys(t) + local out = {} + for _, k in __iter(keys) do + out[k] = t[k] + end + return Json.object(out, keys) +end + +local function obj(pairs_) +local out, keys = {}, {} + for i = 1, #pairs_, 2 do + local k, v = pairs_[i], pairs_[i + 1] + table.insert(keys, k) + out[k] = v + end + return Json.object(out, keys) +end + +local function set(t, k, v) + Json.set(t, k, (v == nil and{NULL }or{v})[1]) +end + +local function nextUid(ctx) +ctx.uid =ctx.uid+ 1 + return ctx.uid +end + +local function newIid(ctx) +ctx.iid =ctx.iid+ 1 + return string.format("%08x-0000-4000-8000-%012x", 0x5ce7a000 + math.floor(ctx.iid / 0x1000000), ctx.iid) +end + +-- ------------------------------------------------------------------------------------------------ fields +local function hexColor(v) +if type(v) ~= "string" then + return nil + end + local h = string.match(v, "^#(%x%x%x%x%x%x)$") or string.match(v, "^#%x%x(%x%x%x%x%x%x)$") + return (h and{(tonumber(h, 16) )}or{nil +})[1]end + +local function wrap(typ, v) +if v == nil or v == NULL then + return NULL + end + if typ == "Int" then + return obj({ "id", "V_Int", "params", { v } }) + elseif typ == "Float" then + return obj({ "id", "V_Float", "params", { v } }) + elseif typ == "Bool" then + return obj({ "id", "V_Bool", "params", { v == true } }) + elseif typ == "Color" then + local c = hexColor(v) + return (c and{(obj({ "id", "V_Int", "params", { c } }) )}or{NULL +})[1] elseif typ == "Point" and tab(v) then + return obj({ "id", "V_String", "params", { tostring(v.cx) .. "," .. tostring(v.cy) } }) + elseif type(v) == "string" then + return obj({ "id", "V_String", "params", { v } }) + end + return nil +end + +local function editorValues(typ, v) +local inner = string.match(typ, "^Array<(.+)>$") + if inner then + local out = {} + for i, x in __iter(list(v)) do + local w = wrap(inner, x) + if w == nil then + return nil + end + out[i] = w + end + return out + end + local w = wrap(typ, v) + return (w == nil and{nil }or{{ w } +})[1]end + +local function same(a, b) +if a == b then + return true + end + if tab(a) and tab(b) then + for k, x in __iter(a) do + if not same(x, b[k]) then + return false + end + end + for k in __iter(b) do + if a[k] == nil then + return false + end + end + return true + end + return false +end + +local LDTK_TYPE= { int = "Int", float = "Float", bool = "Bool", string = "String", color = "Color", file = "FilePath" } + +local function valueType(v) +if type(v) == "number" then + return v % 1 == 0 and"Int" or"Float" + elseif type(v) == "boolean" then + return "Bool" + end + return "String" +end + +local function fieldDef(ctx, name, typ) +local isArray = string.match(typ, "^Array<") ~= nil + local base = string.match(typ, "^Array<(.+)>$") or typ + return obj({ + "identifier", name, "doc", NULL, "__type", typ, "uid", nextUid(ctx), "type", "F_" .. base, "isArray", isArray, + "canBeNull", true, "arrayMinLength", NULL, "arrayMaxLength", NULL, "editorDisplayMode", "Hidden", + "editorDisplayScale", 1, "editorDisplayPos", "Above", "editorLinkStyle", "StraightArrow", "editorDisplayColor", NULL, + "editorAlwaysShow", false, "editorShowInWorld", true, "editorCutLongValues", true, "editorTextSuffix", NULL, + "editorTextPrefix", NULL, "useForSmartColor", false, "exportToToc", false, "searchable", false, "min", NULL, + "max", NULL, "regex", NULL, "acceptFileTypes", NULL, "defaultOverride", NULL, "textLanguageMode", NULL, + "symmetricalRef", false, "autoChainRef", true, "allowOutOfLevelRef", true, "allowedRefs", "OnlySame", + "allowedRefsEntityUid", NULL, "allowedRefTags", {}, "tilesetUid", NULL, + }) +end + +-- raw field instances updated from the properties; properties without an instance get one when a definition exists +-- (or is made: makeDefs) +local function fieldInstances(ctx, raw, props, types, defs, makeDefs) +local out = {} + local seen= {} + props = (tab(props) and{props }or{{} +})[1] types = (tab(types) and{types }or{{} +})[1] for _, fi in __iter(list(raw)) do + if tab(fi) and type(fi.__identifier) == "string" then + local id = fi.__identifier + seen[id] = true + local f = clone(fi) + local v = props[id] + if v ~= nil and not same(v, fi.__value) then + set(f, "__value", v) + local ev = editorValues((type(fi.__type) == "string" and{fi.__type }or{(valueType(v))})[1], v) + if ev then + set(f, "realEditorValues", ev) + end + end + table.insert(out, f) + end + end + local names = {} + for k in __iter(props) do + if type(k) == "string" and not seen[k] then + table.insert(names, k) + end + end + table.sort(names) + for _, k in __iter(names) do + local v = props[k] + local def = defs and defs[k] + if not def and makeDefs and defs then + local typ = (type(types[k]) == "string" and{(LDTK_TYPE[types[k] ] or types[k]) }or{(valueType(v) +)})[1] def = fieldDef(ctx, k, typ) + defs[k] = def + table.insert(makeDefs, def) + end + if def then + local typ = (type(def.__type) == "string" and{def.__type }or{(valueType(v) +)})[1] table.insert(out, obj({ "__identifier", k, "__type", typ, "__value", v, "__tile", NULL, "defUid", def.uid, "realEditorValues", editorValues(typ, v) or {} })) + end + end + return out +end + +-- ------------------------------------------------------------------------------------------------ defs +local function tilesetOf(ctx, gid) +local best= nil + for _, ts in __iter(ctx.map.tilesets) do + if ts.firstGid <= gid and (best == nil or ts.firstGid > best.firstGid) then + best = ts + end + end + return best +end + +local function defsFor(ctx, raw) + local defs = (tab(raw) and{(clone(raw) )}or{(obj({ "layers", {}, "entities", {}, "tilesets", {}, "enums", {}, "externalEnums", {}, "levelFields", {} }) +)})[1] for _, k in __iter({ "layers", "entities", "tilesets", "enums", "externalEnums", "levelFields" }) do + if not tab(defs[k]) then + set(defs, k, {}) + end + end + ctx.defs = defs + for _, d in __iter(list(defs.tilesets)) do + if tab(d) and type(d.uid) == "number" then + ctx.uid = math.max(ctx.uid, d.uid) + ctx.tilesetByUid[d.uid] = d + if type(d.identifier) == "string" then + ctx.tilesetByName[d.identifier] = d + end + end + end + for _, d in __iter(list(defs.layers)) do + if tab(d) and type(d.identifier) == "string" then + ctx.uid = math.max(ctx.uid, n(d.uid, 0)) + ctx.layerDefs[d.identifier] = d + end + end + for _, d in __iter(list(defs.entities)) do + if tab(d) and type(d.identifier) == "string" then + ctx.uid = math.max(ctx.uid, n(d.uid, 0)) + ctx.entityDefs[d.identifier] = d + for _, f in __iter(list(d.fieldDefs)) do + ctx.uid = math.max(ctx.uid, n(tab(f) and f.uid, 0)) + end + end + end + for _, f in __iter(list(defs.levelFields)) do + if tab(f) and type(f.identifier) == "string" then + ctx.uid = math.max(ctx.uid, n(f.uid, 0)) + ctx.levelFields[f.identifier] = f + end + end + for _, d in __iter(list(defs.enums)) do + ctx.uid = math.max(ctx.uid, n(tab(d) and d.uid, 0)) + end + -- tilesets of the map the defs lack + for _, ts in __iter(ctx.map.tilesets) do + if type(ts.name) == "string" and not ctx.tilesetByName[ts.name] then + local size = n(ts.tileWidth, 16) + local cols = math.max(1, n(ts.columns, 1)) + local d = obj({ + "__cWid", cols, "__cHei", math.ceil(n(ts.count, cols) / cols), "identifier", ts.name, "uid", nextUid(ctx), + "relPath", ts.imageSource or NULL, "embedAtlas", NULL, "pxWid", n(ts.imageWidth, cols * size), + "pxHei", n(ts.imageHeight, math.ceil(n(ts.count, cols) / cols) * size), "tileGridSize", size, + "spacing", n(ts.spacing, 0), "padding", n(ts.margin, 0), "tags", {}, "tagsSourceEnumUid", NULL, + "enumTags", {}, "customData", {}, "savedSelections", {}, "cachedPixelData", NULL, + }) + table.insert(defs.tilesets, d) + ctx.tilesetByName[ts.name] = d + ctx.tilesetByUid[d.uid] = d + end + end +end + +local function layerDef(ctx, l, kind, grid, tsUid) +local d = ctx.layerDefs[l.name] + if d then + return d + end + local values = {} + for _, v in __iter(list(l.intGridValues)) do + table.insert(values, obj({ "value", n(v.value, 1), "identifier", v.identifier or NULL, "color", v.color or "#FFFFFF", "tile", NULL, "groupUid", 0 })) + end + if kind == "IntGrid" and #values == 0 then + local maxV = 0 + for _, v in __iter(list(l.intGrid)) do + maxV = math.max(maxV, n(v, 0)) + end + for v = 1, maxV do + table.insert(values, obj({ "value", v, "identifier", NULL, "color", "#FFFFFF", "tile", NULL, "groupUid", 0 })) + end + end + d = obj({ + "__type", kind, "identifier", l.name, "type", kind, "uid", nextUid(ctx), "doc", NULL, "uiColor", NULL, + "gridSize", grid, "guideGridWid", 0, "guideGridHei", 0, "displayOpacity", n(l.opacity, 1), "inactiveOpacity", 1, + "hideInList", false, "hideFieldsWhenInactive", true, "canSelectWhenInactive", true, "renderInWorldView", true, + "pxOffsetX", 0, "pxOffsetY", 0, "parallaxFactorX", 0, "parallaxFactorY", 0, "parallaxScaling", true, + "requiredTags", {}, "excludedTags", {}, "autoTilesKilledByOtherLayerUid", NULL, "uiFilterTags", {}, + "useAsyncRender", false, "intGridValues", values, "intGridValuesGroups", {}, "autoRuleGroups", {}, + "autoSourceLayerDefUid", NULL, "tilesetDefUid", tsUid or NULL, "tilePivotX", 0, "tilePivotY", 0, "biomeFieldUid", NULL, + }) + table.insert(ctx.defs.layers, d) + ctx.layerDefs[l.name] = d + return d +end + +local function entityDef(ctx, o) +local name = (type(o.class) == "string" and o.class ~= "" and{o.class }or{(type(o.name) == "string" and o.name ~= "" and{o.name }or{"Entity" +})[1]})[1] local d = ctx.entityDefs[name] + if d then + return d + end + local pv = (tab(o.pivot) and{o.pivot }or{{ 0, 0 } +})[1] d = obj({ + "identifier", name, "uid", nextUid(ctx), "tags", {}, "exportToToc", false, "allowOutOfBounds", false, "doc", NULL, + "width", math.max(1, n(o.width, 16)), "height", math.max(1, n(o.height, 16)), "resizableX", false, + "resizableY", false, "minWidth", NULL, "maxWidth", NULL, "minHeight", NULL, "maxHeight", NULL, + "keepAspectRatio", false, "tileOpacity", 1, "fillOpacity", 0.08, "lineOpacity", 0, "hollow", false, + "color", (type(o.color) == "string" and{o.color }or{"#94D9B3"})[1], "renderMode", "Rectangle", "showName", true, + "tilesetId", NULL, "tileRenderMode", "FitInside", "tileRect", NULL, "uiTileRect", NULL, "nineSliceBorders", {}, + "maxCount", 0, "limitScope", "PerLevel", "limitBehavior", "MoveLastOne", "pivotX", n(pv[1], 0), "pivotY", n(pv[2], 0), + "fieldDefs", {}, + }) + table.insert(ctx.defs.entities, d) + ctx.entityDefs[name] = d + return d +end + +-- ------------------------------------------------------------------------------------------------ layers +local function gridTiles(ctx, l, grid, ts) +local out = {} + if tab(l.tiles) then + for _, t in __iter(l.tiles) do + local o = obj({ "px", { n(t.x, 0), n(t.y, 0) }, "src", { n(t.srcX, 0), n(t.srcY, 0) }, "f", n(t.flip, 0), "t", n(t.tile, 0) }) + if tab(t.d) then + set(o, "d", t.d) + end + set(o, "a", n(t.alpha, 1)) + table.insert(out, o) + end + return out + end + local w = n(l.width, 0) + for i, raw in __iter(list(l.data)) do + local gid = bit32.band(n(raw, 0), bit32.bnot(FLAGS)) + if gid ~= 0 then + local tset = tilesetOf(ctx, gid) + if tset and (ts == nil or ctx.tilesetByName[tset.name] == ts) then + local id = gid - tset.firstGid + local cols = math.max(1, n(tset.columns, 1)) + local tw, th = n(tset.tileWidth, grid), n(tset.tileHeight, grid) + local sp, mg = n(tset.spacing, 0), n(tset.margin, 0) + local f = (bit32.btest(raw, 0x80000000) and 1 or 0) + (bit32.btest(raw, 0x40000000) and 2 or 0) + local cx, cy = (i - 1) % math.max(w, 1), math.floor((i - 1) / math.max(w, 1) +) table.insert(out, obj({ + "px", { cx * grid, cy * grid }, "src", { mg + (id % cols) * (tw + sp), mg + (math.floor(id / cols)) * (th + sp) }, + "f", f, "t", id, "d", { cx + cy * w }, "a", 1, + })) + end + end + end + return out +end + +local function layerTileset(ctx, l) +if type(l.tileset) == "string" and ctx.tilesetByName[l.tileset] then + return ctx.tilesetByName[l.tileset] + end + if tab(l.ldtk) and type(l.ldtk.overrideTilesetUid) == "number" and ctx.tilesetByUid[l.ldtk.overrideTilesetUid] then + return ctx.tilesetByUid[l.ldtk.overrideTilesetUid] + end + for _, raw in __iter(list(l.data)) do + local gid = bit32.band(n(raw, 0), bit32.bnot(FLAGS)) + if gid ~= 0 then + local tset = tilesetOf(ctx, gid) + return (tset and{ctx.tilesetByName[tset.name] }or{nil +})[1] end + end + return nil +end + +local function entities(ctx, l, levelIid, lx, ly, grid) +local out = {} + for _, o in __iter(list(l.objects)) do + if tab(o) then + local d = entityDef(ctx, o) + local w, h = n(o.width, n(d.width, 16)), n(o.height, n(d.height, 16)) + local pv = (tab(o.pivot) and{o.pivot }or{{ n(d.pivotX, 0), n(d.pivotY, 0) } +})[1] local px, py = n(o.x, 0) + n(pv[1], 0) * w, n(o.y, 0) + n(pv[2], 0) * h + local e = clone(o.ldtk) + set(e, "__identifier", d.identifier) + set(e, "__grid", { math.floor(px / grid), math.floor(py / grid )}) + set(e, "__pivot", { n(pv[1], 0), n(pv[2], 0) }) + set(e, "__tags", (tab(o.tags) and{o.tags }or{{}})[1]) + set(e, "__tile", (tab(o.tile) and{o.tile }or{NULL})[1]) + set(e, "__smartColor", (type(o.color) == "string" and{o.color }or{d.color})[1]) + if type(e.iid) ~= "string" then + set(e, "iid", (type(o.id) == "string" and{o.id }or{(newIid(ctx))})[1]) + end + set(e, "width", w) + set(e, "height", h) + set(e, "defUid", d.uid) + set(e, "px", { px, py }) + local fdefs= {} + for _, f in __iter(list(d.fieldDefs)) do + if tab(f) and type(f.identifier) == "string" then + fdefs[f.identifier] = f + end + end + set(e, "fieldInstances", fieldInstances(ctx, o.fieldInstances, o.properties, o.propertyTypes, fdefs, d.fieldDefs)) + set(e, "__worldX", lx + px) + set(e, "__worldY", ly + py) + table.insert(out, e) + end + end + return out +end + +local function layerInstance(ctx, l, levelUid, levelIid, lx, ly, pxW, pxH) +local kind = (type(l.ldtkType) == "string" and{l.ldtkType +}or{l.type == "objects" and"Entities" +or(tab(l.intGrid) and"IntGrid" +or"Tiles" +)})[1] local grid = math.max(1, n(l.gridSize, ctx.map.tileWidth)) + local ts = (kind ~= "Entities" and{(layerTileset(ctx, l) )}or{nil +})[1] local d = layerDef(ctx, l, kind, grid, (ts and{ts.uid }or{nil})[1]) + local cw = n(l.width, math.ceil(pxW / grid)) + local ch = n(l.height, math.ceil(pxH / grid)) + local li = clone(l.ldtk) + set(li, "__identifier", l.name) + set(li, "__type", kind) + set(li, "__cWid", cw) + set(li, "__cHei", ch) + set(li, "__gridSize", grid) + set(li, "__opacity", n(l.opacity, 1)) + set(li, "__pxTotalOffsetX", n(l.offsetX, 0)) + set(li, "__pxTotalOffsetY", n(l.offsetY, 0)) + set(li, "__tilesetDefUid", (ts and{ts.uid }or{NULL})[1]) + set(li, "__tilesetRelPath", (ts and type(ts.relPath) == "string" and{ts.relPath }or{NULL})[1]) + if type(li.iid) ~= "string" then + set(li, "iid", newIid(ctx)) + end + set(li, "levelId", levelUid) + set(li, "layerDefUid", d.uid) + if li.pxOffsetX == nil then + set(li, "pxOffsetX", n(l.offsetX, 0) - n(d.pxOffsetX, 0)) + set(li, "pxOffsetY", n(l.offsetY, 0) - n(d.pxOffsetY, 0)) + end + set(li, "visible", l.visible ~= false) + if li.optionalRules == nil then + set(li, "optionalRules", {}) + end + local csv = {} + if kind == "IntGrid" then + local g = list(l.intGrid) + for i = 1, cw * ch do + csv[i] = n(g[i], 0) + end + end + set(li, "intGridCsv", csv) + local tl = (kind ~= "Entities" and{(gridTiles(ctx, l, grid, ts) )}or{{} +})[1] set(li, "autoLayerTiles", ((kind == "IntGrid" or kind == "AutoLayer" )and{tl }or{{}})[1]) + if li.seed == nil then + set(li, "seed", 0) + end + if li.overrideTilesetUid == nil then + set(li, "overrideTilesetUid", NULL) + end + set(li, "gridTiles", (kind == "Tiles" and{tl }or{{}})[1]) + set(li, "entityInstances", (kind == "Entities" and{(entities(ctx, l, levelIid, lx, ly, grid) )}or{{}})[1]) + return li +end + +-- ------------------------------------------------------------------------------------------------ levels +local function flat(layers, into) + for _, l in __iter(layers) do + if l.type == "group" and not l.level and not l.world then + flat(list(l.layers), into) + elseif l.type ~= "group" and l.type ~= "image" then + table.insert(into, l) + end + end +end + +local function levelValue(ctx, g, layers, index) +local lv = clone(g.ldtk) + local grid = ctx.map.tileWidth + local pxW = n(g.pxWidth, 0) + local pxH = n(g.pxHeight, 0) + if pxW <= 0 or pxH <= 0 then + for _, l in __iter(layers) do + local gs = n(l.gridSize, grid) + pxW = math.max(pxW, n(l.width, 0) * gs) + pxH = math.max(pxH, n(l.height, 0) * gs) + end + pxW = (pxW > 0 and{pxW }or{(ctx.map.width * grid +)})[1] pxH = (pxH > 0 and{pxH }or{(ctx.map.height * grid +)})[1] end + local uid = (type(lv.uid) == "number" and{lv.uid }or{(nextUid(ctx) +)})[1] local iid = (type(lv.iid) == "string" and{lv.iid }or{(newIid(ctx) +)})[1] local lx, ly = n(g.offsetX, 0), n(g.offsetY, 0) + set(lv, "identifier", (type(g.name) == "string" and g.name ~= "" and{g.name }or{("Level_" .. index)})[1]) + set(lv, "iid", iid) + set(lv, "uid", uid) + set(lv, "worldX", lx) + set(lv, "worldY", ly) + if lv.worldDepth == nil then + set(lv, "worldDepth", 0) + end + set(lv, "pxWid", pxW) + set(lv, "pxHei", pxH) + set(lv, "__bgColor", (type(g.backgroundColor) == "string" and{g.backgroundColor }or{(type(ctx.map.backgroundColor) == "string" and{ctx.map.backgroundColor }or{"#696A79"})[1]})[1]) + for _, k in __iter({ "bgColor", "bgRelPath", "bgPos", "__smartColor", "__bgPos" }) do + if lv[k] == nil then + set(lv, k, k == "__smartColor" and"#ADADB5ff" or NULL) + end + end + if lv.useAutoIdentifier == nil then + set(lv, "useAutoIdentifier", false) + end + if lv.bgPivotX == nil then + set(lv, "bgPivotX", 0.5) + set(lv, "bgPivotY", 0.5) + end + set(lv, "externalRelPath", NULL) + set(lv, "fieldInstances", fieldInstances(ctx, lv.fieldInstances, g.properties, g.propertyTypes, ctx.levelFields, ctx.defs.levelFields)) + local out = {} + for i = #layers, 1, -1 do + table.insert(out, layerInstance(ctx, layers[i], uid, iid, lx, ly, pxW, pxH)) + end + set(lv, "layerInstances", out) + if lv.__neighbours == nil then + set(lv, "__neighbours", {}) + end + return lv +end + +local function levels(ctx, layers) +local out = {} + local loose = {} + for _, l in __iter(layers) do + if l.type == "group" and not l.world then + local ls = {} + flat(list(l.layers), ls) + table.insert(out, levelValue(ctx, l, ls, #out)) + elseif l.type ~= "group" and l.type ~= "image" then + table.insert(loose, l) + end + end + if #loose > 0 then + table.insert(out, 1, levelValue(ctx, { name = "Level_0", properties = {}, offsetX = 0, offsetY = 0 }, loose, 0)) + end + return out +end + +local PROJECT= { + "__header__", NULL, "iid", NULL, "jsonVersion", "1.5.3", "appBuildId", 473703, "nextUid", 0, "identifierStyle", "Capitalize", + "toc", {}, "worldLayout", "Free", "worldGridWidth", 256, "worldGridHeight", 256, "defaultLevelWidth", 256, + "defaultLevelHeight", 256, "defaultPivotX", 0, "defaultPivotY", 0, "defaultGridSize", 16, "defaultEntityWidth", 16, + "defaultEntityHeight", 16, "bgColor", "#40465B", "defaultLevelBgColor", "#696A79", "minifyJson", false, + "externalLevels", false, "exportTiled", false, "simplifiedExport", false, "imageExportMode", "None", + "exportLevelBg", true, "pngFilePattern", NULL, "backupOnSave", false, "backupLimit", 10, "backupRelPath", NULL, + "levelNamePattern", "Level_%idx", "tutorialDesc", NULL, "customCommands", {}, "flags", {}, "defs", NULL, + "levels", NULL, "worlds", NULL, "dummyWorldIid", NULL, +} + +function Write.project(map, opts) +local ctx= { + uid = 0, + iid = 0, + defs = nil, + tilesetByName = {}, + tilesetByUid = {}, + layerDefs = {}, + entityDefs = {}, + levelFields = {}, + map = map, + } + local raw = (tab(map.ldtk) and{map.ldtk }or{nil +})[1] local p = (raw and{(clone(raw) )}or{(Json.object({}) +)})[1] if not raw then + for i = 1, #PROJECT, 2 do + set(p, PROJECT[i], PROJECT[i + 1]) + end + set(p, "__header__", obj({ "fileType", "LDtk Project JSON", "app", "LDtk", "doc", "https://ldtk.io/json", "schema", "https://ldtk.io/files/JSON_SCHEMA.json", "appAuthor", "Sebastien 'deepnight' Benard", "appVersion", "1.5.3", "url", "https://ldtk.io" })) + set(p, "iid", newIid(ctx)) + set(p, "defaultGridSize", map.tileWidth) + end + ctx.uid = math.max(ctx.uid, n(p.nextUid, 1) - 1) + defsFor(ctx, p.defs) + local worlds = {} + local hasWorlds = false + for _, l in __iter(map.layers) do + if l.type == "group" and l.world then + hasWorlds = true + end + end + local lvls= {} + if hasWorlds then + for _, l in __iter(map.layers) do + if l.type == "group" and l.world then + local w = clone(l.ldtk) + set(w, "identifier", l.name) + if type(w.iid) ~= "string" then + set(w, "iid", newIid(ctx)) + end + for _, k in __iter({ "worldGridWidth", "worldGridHeight" }) do + if w[k] == nil then + set(w, k, 256) + end + end + if w.worldLayout == nil then + set(w, "worldLayout", "Free") + end + set(w, "levels", levels(ctx, list(l.layers))) + table.insert(worlds, w) + end + end + else + lvls = levels(ctx, map.layers) + end + if type(map.backgroundColor) == "string" then + set(p, "bgColor", map.backgroundColor) + end + if type(map.worldLayout) == "string" and not hasWorlds then + set(p, "worldLayout", map.worldLayout) + end + set(p, "externalLevels", false) + set(p, "defs", ctx.defs) + set(p, "levels", lvls) + set(p, "worlds", worlds) + if type(p.dummyWorldIid) ~= "string" then + set(p, "dummyWorldIid", newIid(ctx)) + end + set(p, "nextUid", ctx.uid + 1) + return p, nil +end + +return Write +end +__FILES["vector/ogmo"] = function() +local __compat = __compat local buffer, type = __compat.buffer, __compat.type --!strict +-- vector/ogmo: Ogmo Editor 3 levels (.json) and projects (.ogmo) as a TileMap, read + write (OgmoEditor3-CE 3.x +-- save format). Supports: tile layers (ids / coords, 1D / 2D arrays, tile flags), grid layers, entity layers (origin, +-- rotation, flips, nodes, values), decal layers, level values; the project through opts.project for tilesets and +-- entity templates. Not supported: loading tileset images (embedded PNGs stay bytes: tileset.imageData). + +-- ------------------------------------------------------------------------------------------------ requires +local Err = __include("core/Err") +local Bytes = __include("core/Bytes") +local Sniff = __include("core/Sniff") +local Types = __include("Types") +local Json = __include("codecs/text/Json") +local Read = __include("vector/ogmo/Read") +local Write = __include("vector/ogmo/Write") + +-- ------------------------------------------------------------------------------------------------ contract +local Ogmo = { + name = "ogmo", + category = "vector", + extensions = { "ogmo" }, + mime = { "application/x-ogmo+json" }, + deps = { "core/Err", "core/Bytes", "core/Sniff", "core/Base64", "Types", "codecs/text/Json" }, + caps = { decode = true, encode = true, projects = true, entities = true, decals = true }, +} + +-- ------------------------------------------------------------------------------------------------ sniff + + + + + + + + + + +function Ogmo.sniff(r) +local h = Sniff.text(r, 2048) + if not string.match(h, "^%s*{") or not string.find(h, "\"ogmoVersion\"", 1, true) then + return 0 + end + if string.find(h, "\"layerGridDefaultSize\"", 1, true) or string.find(h, "\"levelPaths\"", 1, true) then + return 1 + end + return 0.9 +end + +-- ------------------------------------------------------------------------------------------------ decode +local function json(src) +if type(src) == "table" then + return src, nil + end + if type(src) ~= "string" and type(src) ~= "buffer" then + return nil, Err.new(Err.ARG, "project must be bytes or a table") + end + return Json.decode(src, { ordered = true }) +end + +function Ogmo.decode(r, opts) +local o= opts or {} + if r.limit - r.base > (o.maxBytes or 2 ^ 28) then + return nil, Err.new(Err.LIMIT, "file is over the byte limit") + end + local v, jerr = Json.decode(buffer.readstring(r.buf, r.base, r.limit - r.base), { ordered = true }) + if v == nil then + return nil, jerr + end + if type(v) ~= "table" then + return nil, Err.new(Err.CORRUPT, "not a JSON object") + end + local isProject = v.layerGridDefaultSize ~= nil or v.levelPaths ~= nil or v.tilesets ~= nil and v.layers ~= nil and v.width == nil + local project= nil + if not isProject and o.project ~= nil then + local p, perr = json(o.project) + if p == nil then + return nil, perr + end + project = p + end + local run= (isProject and{Read.project }or{function(x, oo) +return Read.level(x, project, oo) + end +})[1] local ok, map, msg = pcall(run, v, o) + if not ok then + return nil, Err.new(Err.CORRUPT, "bad data: " .. tostring(map)) + end + if not map then + return nil, Err.from(msg) + end + return map, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +function Ogmo.encode(map, opts) +if type(map) ~= "table" or type(map.layers) ~= "table" or type(map.tilesets) ~= "table" then + return nil, Err.new(Err.ARG, "needs a TileMap value") + end + local kind = opts and opts.kind or (type(map.meta) == "table" and map.meta.project and"project" or"level") + if kind ~= "level" and kind ~= "project" then + return nil, Err.new(Err.ARG, "kind must be level or project") + end + local ok, v, msg = pcall((kind == "project" and{Write.project }or{Write.level})[1], map) + if not ok then + return nil, Err.new(Err.ARG, "bad map: " .. tostring(v)) + end + if v == nil then + return nil, Err.new(Err.ARG, msg or "bad map") + end + local indent = (opts and opts.indent == 0 and{nil }or{(opts and opts.indent or 2) +})[1] local s, jerr = Json.encode(v, { indent = indent }) + if not s then + return nil, jerr + end + return buffer.fromstring(s), nil +end + +return Ogmo +end +__FILES["vector/ogmo/Read"] = function() +local __compat = __compat local buffer, bit32, type, __iter = __compat.buffer, __compat.bit32, __compat.type, __compat.__iter --!strict +-- vector/ogmo/Read: Ogmo Editor 3 projects (.ogmo) and levels (.json) into a Types.TileMap (layer save / load as in +-- OgmoEditor3-CE src/modules/*/ *Layer.hx). Ogmo's first layer is drawn on top: layers are reversed (bottom first). +-- Tile ids -1 are empty; tileFlags 4 / 2 / 1 (flip H / V / diagonal) become Tiled's 0x80000000 / 0x40000000 / +-- 0x20000000. +local Types = __include("Types") +local Json = __include("codecs/text/Json") +local Base64 = __include("core/Base64") + +local Read = {} + +local NULL = Json.null +local FLIP_H, FLIP_V, FLIP_D = 0x80000000, 0x40000000, 0x20000000 + +local function tab(v) +return type(v) == "table" and v ~= NULL +end +local function list(v) +return (tab(v) and{v }or{{} +})[1]end +local function n(v, default) +return (type(v) == "number" and v == v and{v }or{default +})[1]end +local function s(v) +return (type(v) == "string" and{v }or{nil +})[1]end +local function vec(v, dx, dy) +if tab(v) then + return n(v.x, dx), n(v.y, dy) + end + return dx, dy +end + +-- PNG IHDR width / height of an embedded tileset image (data: URI) +local function pngSize(b) +if buffer.len(b) >= 24 and buffer.readstring(b, 0, 8) == "\137PNG\r\n\26\n" and buffer.readstring(b, 12, 4) == "IHDR" then + local function be(o) +return buffer.readu8(b, o) * 16777216 + buffer.readu8(b, o + 1) * 65536 + buffer.readu8(b, o + 2) * 256 + buffer.readu8(b, o + 3) + end + return be(16), be(20) + end + return nil, nil +end + +local VALUE_TYPES= { Integer = "int", Float = "float", Boolean = "bool", Color = "color", Filepath = "file", String = "string", Text = "string", Enum = "string" } + +function Read.tilesets(project) +local out= {} + local gid = 1 + for _, t in __iter(list(project and project.tilesets)) do + if tab(t) then + local tw, th = math.max(1, n(t.tileWidth, 16)), math.max(1, n(t.tileHeight, 16)) + local sx, sy = n(t.tileSeparationX, 0), n(t.tileSeparationY, 0) + local mx, my = n(t.tileMarginX, 0), n(t.tileMarginY, 0) + local data= nil + local iw, ih = nil, nil + if type(t.image) == "string" and string.sub(t.image, 1, 5) == "data:" then + data = Base64.decodeDataUri(t.image) + if data then + iw, ih = pngSize(data) + end + end + local cols = (iw and{(math.max(1, math.floor((iw - 2 * mx + sx) / (tw + sx))) )}or{1 +})[1] local rows = (ih and{(math.max(1, math.floor((ih - 2 * my + sy) / (th + sy))) )}or{1 +})[1] local ts= { + name = s(t.label) or ("tileset" .. #out), + firstGid = gid, + tileWidth = tw, + tileHeight = th, + columns = cols, + count = cols * rows, + imageSource = s(t.path), + imageWidth = iw, + imageHeight = ih, + imageData = data, + spacing = sx, + spacingY = (sy ~= sx and{sy }or{nil})[1], + margin = mx, + marginY = (my ~= mx and{my }or{nil})[1], + } + gid =gid+ ts.count + table.insert(out, ts) + end + end + return out +end + +local function valueTypes(defs) +local out= nil + for _, d in __iter(list(defs)) do + if tab(d) and type(d.name) == "string" and type(d.definition) == "string" then + local typ = VALUE_TYPES[d.definition] + if typ and typ ~= "string" then + out = out or {} + ;(out )[d.name] = typ + end + end + end + return out +end + +local function values(v) +local out= {} + if tab(v) then + for k, x in __iter(v) do + if type(k) == "string" then + out[k] = x + end + end + end + return out +end + + + +local function cells2D(v, w, h) +local out = table.create(w * h) + for y, row in __iter(list(v)) do + for x, c in __iter(list(row)) do + if x <= w and y <= h then + out[(y - 1) * w + x] = c + end + end + end + return out +end + +local function tileLayer(ctx, li, l, w, h) + local ts = ctx.byName[s(li.tileset) or ""] or ctx.tilesets[1] + l.tileset = s(li.tileset) + local exportMode, arrayMode = n(li.exportMode, 0), n(li.arrayMode, 0) + local raw +if exportMode == 1 then + raw = (arrayMode == 1 and{(cells2D(li.dataCoords2D, w, h) )}or{(list(li.dataCoords) +)})[1] else + raw = (arrayMode == 1 and{(cells2D(li.data2D, w, h) )}or{(list(li.data) +)})[1] end + local flags = (arrayMode == 1 and{(cells2D(li.tileFlags2D, w, h) )}or{(list(li.tileFlags) +)})[1] local data = table.create(w * h, 0) + for i = 1, w * h do + local c = raw[i] + local id = -1 + if exportMode == 1 then + if tab(c) and n(c[1], -1) >= 0 then + id = n(c[2], 0) * ((ts and{ts.columns }or{1})[1]) + n(c[1], 0) + end + else + id = n(c, -1) + end + if id >= 0 and ts then + local gid = ts.firstGid + id + local f = n(flags[i], 0) + if bit32.btest(f, 4) then + gid =gid+ FLIP_H + end + if bit32.btest(f, 2) then + gid =gid+ FLIP_V + end + if bit32.btest(f, 1) then + gid =gid+ FLIP_D + end + data[i] = gid + elseif id >= 0 then + data[i] = id + 1 + end + end + l.data = data +end + +local function entity(ctx, e) +local def = ctx.entityDefs[s(e.name) or ""] + local dw, dh = vec(def and def.size, 16, 16) + local dox, doy = vec(def and def.origin, 0, 0) + local w, h = n(e.width, dw), n(e.height, dh) + local ox, oy = n(e.originX, dox), n(e.originY, doy) + local rot = n(e.rotation, 0) + if ctx.radians then + rot = math.deg(rot) + end + local nodes = nil + if tab(e.nodes) then + nodes = {} + for i, p in __iter(e.nodes) do + nodes[i] = { n(tab(p) and p.x, 0), n(tab(p) and p.y, 0) } + end + end + return { + id = e.id, + name = s(e.name) or "", + class = s(e.name) or "", + x = n(e.x, 0) - ox, + y = n(e.y, 0) - oy, + width = w, + height = h, + rotation = rot, + visible = true, + shape = "rectangle", + originX = ox, + originY = oy, + flippedX = (type(e.flippedX) == "boolean" and{e.flippedX }or{nil})[1], + flippedY = (type(e.flippedY) == "boolean" and{e.flippedY }or{nil})[1], + color = s(e.color), + nodes = nodes, + eid = s(e._eid), + properties = values(e.values), + propertyTypes = (def and{(valueTypes(def.values) )}or{nil})[1], + } +end + +local function decal(ctx, d) +local rot = n(d.rotation, 0) + if ctx.radians then + rot = math.deg(rot) + end + return { + name = s(d.texture) or "", + class = "decal", + shape = "decal", + texture = s(d.texture), + x = n(d.x, 0), + y = n(d.y, 0), + width = 0, + height = 0, + originX = n(d.originX, 0.5), + originY = n(d.originY, 0.5), + scaleX = n(d.scaleX, 1), + scaleY = n(d.scaleY, 1), + rotation = rot, + visible = true, + properties = values(d.values), + } +end + +local function layer(ctx, li) +local name = s(li.name) or "" + local def = ctx.layerDefs[name] + local kind = (def and s(def.definition)) or (li.entities ~= nil and"entity" +or(li.decals ~= nil and"decal" +or((li.grid ~= nil or li.grid2D ~= nil )and"grid" +or"tile"))) + local w, h = n(li.gridCellsX, 0), n(li.gridCellsY, 0) + if w < 0 or h < 0 or w * h > ctx.maxCells then + return nil, "limit: layer of " .. w .. " x " .. h .. " cells" + end + local l= { + name = name, + type = (kind == "entity" or kind == "decal" )and"objects" or"tiles", + visible = true, + opacity = 1, + properties = {}, + offsetX = n(li.offsetX, 0), + offsetY = n(li.offsetY, 0), + ogmoType = kind, + cellWidth = n(li.gridCellWidth, 0), + cellHeight = n(li.gridCellHeight, 0), + eid = s(li._eid), + exportMode = (type(li.exportMode) == "number" and{li.exportMode }or{nil})[1], + arrayMode = (type(li.arrayMode) == "number" and{li.arrayMode }or{nil})[1], + } + if kind == "entity" then + local objs = {} + for _, e in __iter(list(li.entities)) do + if tab(e) then + table.insert(objs, entity(ctx, e)) + end + end + l.objects = objs + elseif kind == "decal" then + local objs = {} + for _, d in __iter(list(li.decals)) do + if tab(d) then + table.insert(objs, decal(ctx, d)) + end + end + l.objects = objs + l.folder = s(li.folder) + elseif kind == "grid" then + l.width, l.height = w, h + local raw = (n(li.arrayMode, 0) == 1 and{(cells2D(li.grid2D, w, h) )}or{(list(li.grid) +)})[1] local grid = table.create(w * h, "0") + local data = table.create(w * h, 0) + for i = 1, w * h do + local c = raw[i] + local v = (type(c) == "string" and{c }or{(type(c) == "number" and{(tostring(c) )}or{"0" +})[1]})[1] grid[i] = v + data[i] = tonumber(v) or 0 + end + l.grid = grid + l.data = data + if def and tab(def.legend) then + l.legend = values(def.legend) + end + else + l.width, l.height = w, h + tileLayer(ctx, li, l, w, h) + end + return l, nil +end + +local function context(project, opts) +local ts = Read.tilesets(project) + local ctx= { project = project, tilesets = ts, byName = {}, layerDefs = {}, entityDefs = {}, radians = true, maxCells = opts.maxCells or 2 ^ 26 } + for _, t in __iter(ts) do + ctx.byName[t.name] = t + end + if tab(project) then + ctx.radians = project.anglesRadians ~= false + for _, d in __iter(list(project.layers)) do + if tab(d) and type(d.name) == "string" then + ctx.layerDefs[d.name] = d + end + end + for _, d in __iter(list(project.entities)) do + if tab(d) and type(d.name) == "string" then + ctx.entityDefs[d.name] = d + end + end + end + return ctx +end + +local function gridSize(project, layers) +if tab(project) and tab(project.layerGridDefaultSize) then + local x, y = vec(project.layerGridDefaultSize, 16, 16) + return math.max(1, x), math.max(1, y) + end + for _, l in __iter(layers) do + if tab(l) and type(l.gridCellWidth) == "number" then + return math.max(1, l.gridCellWidth), math.max(1, n(l.gridCellHeight, l.gridCellWidth)) + end + end + return 16, 16 +end + +function Read.level(v, project, opts) +if not tab(v) or not tab(v.layers) then + return nil, "no layers: not an Ogmo level" + end + local ctx = context(project, opts) + local tw, th = gridSize(project, v.layers) + local pw, ph = n(v.width, 0), n(v.height, 0) + local map = Types.TileMap.new(math.ceil(pw / tw), math.ceil(ph / th), tw, th) + map.tilesets = ctx.tilesets + map.pxWidth, map.pxHeight = pw, ph + map.offsetX, map.offsetY = n(v.offsetX, 0), n(v.offsetY, 0) + map.properties = values(v.values) + if tab(project) then + map.propertyTypes = valueTypes(project.levelValues) + end + local ls = v.layers + for i = #ls, 1, -1 do + if tab(ls[i]) then + local l, err = layer(ctx, ls[i]) + if not l then + return nil, err + end + table.insert(map.layers, l) + end + end + map.meta.source = { format = "ogmo", version = s(v.ogmoVersion), level = true, anglesRadians = ctx.radians } + if tab(project) then + map.ogmo = project + end + return map, nil +end + +function Read.project(v, opts) +local ctx = context(v, opts) + local tw, th = gridSize(v, {}) + local lw, lh = vec(v.levelDefaultSize, 0, 0) + local map = Types.TileMap.new(math.ceil(lw / tw), math.ceil(lh / th), tw, th) + map.tilesets = ctx.tilesets + map.name = s(v.name) + map.backgroundColor = s(v.backgroundColor) + local defs = list(v.layers) + for i = #defs, 1, -1 do + local d = defs[i] + if tab(d) and type(d.name) == "string" then + local kind = s(d.definition) or "tile" + local gx, gy = vec(d.gridSize, tw, th) + local l= { + name = d.name, + type = (kind == "entity" or kind == "decal" )and"objects" or"tiles", + visible = true, + opacity = 1, + properties = {}, + ogmoType = kind, + cellWidth = gx, + cellHeight = gy, + eid = s(d.exportID), + tileset = s(d.defaultTileset), + } + table.insert(map.layers, l) + end + end + map.entities = list(v.entities) + map.ogmo = v + map.meta.source = { format = "ogmo", version = s(v.ogmoVersion), project = true, anglesRadians = ctx.radians } + map.meta.project = true + return map, nil +end + +return Read +end +__FILES["vector/ogmo/Write"] = function() +local __compat = __compat local bit32, type, __iter = __compat.bit32, __compat.type, __compat.__iter --!strict +-- vector/ogmo/Write: a Types.TileMap as an Ogmo Editor 3 level (.json) or project (.ogmo), in the shapes Ogmo 3.4 +-- saves (Layer.save / TileLayer.save / GridLayer.save / Entity.save / Decal.save). A project read from Ogmo is +-- written back with its own definitions; otherwise layers, tilesets and entity templates are made from the map. +local Types = __include("Types") +local Json = __include("codecs/text/Json") +local Base64 = __include("core/Base64") + +local Write = {} + +local NULL = Json.null +local FLAGS = 0xF0000000 +local VERSION = "3.4.0" + +local function tab(v) +return type(v) == "table" and v ~= NULL +end +local function list(v) +return (tab(v) and{v }or{{} +})[1]end +local function n(v, default) +return (type(v) == "number" and v == v and{v }or{default +})[1]end + +-- key / value pairs; a nil value (an absent optional field) is skipped +local function obj(pairs_) +local out, keys = {}, {} + local i = 1 + while pairs_[i] ~= nil do + if pairs_[i + 1] ~= nil then + table.insert(keys, pairs_[i]) + out[pairs_[i] ] = pairs_[i + 1] + end + i =i+ 2 + end + return Json.object(out, keys) +end + +local function values(props) +local out = {} + local keys = {} + if tab(props) then + for k, v in __iter(props) do + if type(k) == "string" then + out[k] = v + table.insert(keys, k) + end + end + end + table.sort(keys) + return Json.object(out, keys) +end + +local function eid(l, i) +return (type(l.eid) == "string" and{l.eid }or{(tostring(10000000 + i) +)})[1]end + +local function flat(layers, into) + for _, l in __iter(layers) do + if l.type == "group" then + flat(list(l.layers), into) + elseif l.type == "tiles" or l.type == "objects" then + table.insert(into, l) + end + end +end + +local function tilesetOf(map, gid) +local best= nil + for _, ts in __iter(map.tilesets) do + if ts.firstGid <= gid and (best == nil or ts.firstGid > (best ).firstGid) then + best = ts + end + end + return best +end + +local function layerTileset(map, l) +if type(l.tileset) == "string" then + for _, ts in __iter(map.tilesets) do + if ts.name == l.tileset then + return ts + end + end + end + for _, raw in __iter(list(l.data)) do + local gid = bit32.band(n(raw, 0), bit32.bnot(FLAGS)) + if gid ~= 0 then + return tilesetOf(map, gid) + end + end + return map.tilesets[1] +end + +local function kindOf(l) +if type(l.ogmoType) == "string" then + return l.ogmoType + elseif l.type == "objects" then + for _, o in __iter(list(l.objects)) do + if o.shape == "decal" then + return "decal" + end + end + return "entity" + elseif tab(l.grid) then + return "grid" + end + return "tile" +end + +-- ------------------------------------------------------------------------------------------------ level +local function rows2D(flatList, w, h) +local out = {} + for y = 1, h do + local row = {} + for x = 1, w do + row[x] = flatList[(y - 1) * w + x] + end + out[y] = row + end + return out +end + +local function tileLayer(map, l, i, gw, gh) +local ts = layerTileset(map, l) + local w, h = n(l.width, math.ceil(n(map.pxWidth, map.width * map.tileWidth) / gw)), n(l.height, math.ceil(n(map.pxHeight, map.height * map.tileHeight) / gh)) + local ids, coords, flags = table.create(w * h, -1), table.create(w * h), table.create(w * h, 0) + local anyFlag = false + local data = list(l.data) + for k = 1, w * h do + local raw = n(data[k], 0) + local gid = bit32.band(raw, bit32.bnot(FLAGS)) + local id = -1 + if gid ~= 0 then + id = (ts and((gid - ts.firstGid ))or((gid - 1 +))) if ts and (id < 0 or id >= math.max(ts.count, 1)) then + id = -1 + end + end + ids[k] = id + if id >= 0 then + local cols = (ts and{(math.max(1, ts.columns) )}or{1 +})[1] coords[k] = { id % cols, math.floor(id / cols )} + local f = (bit32.btest(raw, 0x80000000) and 4 or 0) + (bit32.btest(raw, 0x40000000) and 2 or 0) + (bit32.btest(raw, 0x20000000) and 1 or 0) + flags[k] = f + anyFlag = anyFlag or f ~= 0 + else + coords[k] = { -1 } + end + end + local exportMode, arrayMode = n(l.exportMode, 0), n(l.arrayMode, 0) + local fields= { + "name", l.name, "_eid", eid(l, i), "offsetX", n(l.offsetX, 0), "offsetY", n(l.offsetY, 0), "gridCellWidth", gw, + "gridCellHeight", gh, "gridCellsX", w, "gridCellsY", h, "tileset", (ts and{ts.name }or{""})[1], + } + local key = (exportMode == 1 and{(arrayMode == 1 and"dataCoords2D" or"dataCoords") }or{(arrayMode == 1 and"data2D" or"data") +})[1] local body = (exportMode == 1 and{coords }or{ids +})[1] table.insert(fields, key) + table.insert(fields, (arrayMode == 1 and{(rows2D(body, w, h) )}or{body})[1]) + if anyFlag then + table.insert(fields, arrayMode == 1 and"tileFlags2D" or"tileFlags") + table.insert(fields, (arrayMode == 1 and{(rows2D(flags, w, h) )}or{flags})[1]) + end + table.insert(fields, "exportMode") + table.insert(fields, exportMode) + table.insert(fields, "arrayMode") + table.insert(fields, arrayMode) + return obj(fields) +end + +local function gridLayer(map, l, i, gw, gh) +local w, h = n(l.width, map.width), n(l.height, map.height) + local cells = table.create(w * h, "0") + local grid, data = list(l.grid), list(l.data) + for k = 1, w * h do + local g = grid[k] + cells[k] = (type(g) == "string" and{g }or{(tostring(math.floor(n(data[k], 0))) +)})[1] end + local arrayMode = n(l.arrayMode, 0) + return obj({ + "name", l.name, "_eid", eid(l, i), "offsetX", n(l.offsetX, 0), "offsetY", n(l.offsetY, 0), "gridCellWidth", gw, + "gridCellHeight", gh, "gridCellsX", w, "gridCellsY", h, +arrayMode == 1 and"grid2D" or"grid", (arrayMode == 1 and{(rows2D(cells, w, h) )}or{cells})[1], + "arrayMode", arrayMode, + }) +end + +local function entities(l, i, gw, gh, w, h, radians) +local out = {} + for k, o in __iter(list(l.objects)) do + local ox, oy = n(o.originX, 0), n(o.originY, 0) + local nodes = nil + if tab(o.nodes) then + nodes = {} + for j, p in __iter(o.nodes) do + nodes[j] = obj({ "x", n(p[1], 0), "y", n(p[2], 0) }) + end + end + local rot = n(o.rotation, 0) + table.insert(out, obj({ + "name", (type(o.class) == "string" and o.class ~= "" and{o.class }or{(o.name or "entity")})[1], + "id", (type(o.id) == "number" and{o.id }or{(k - 1)})[1], + "_eid", (type(o.eid) == "string" and{o.eid }or{(tostring(20000000 + k))})[1], + "x", n(o.x, 0) + ox, "y", n(o.y, 0) + oy, "width", n(o.width, gw), "height", n(o.height, gh), + "originX", ox, "originY", oy, "rotation", (radians and{(math.rad(rot) )}or{rot})[1], + "flippedX", o.flippedX, "flippedY", o.flippedY, "color", o.color, "nodes", nodes, + "values", (tab(o.properties) and next(o.properties) and{(values(o.properties) )}or{nil})[1], + })) + end + return obj({ + "name", l.name, "_eid", eid(l, i), "offsetX", n(l.offsetX, 0), "offsetY", n(l.offsetY, 0), "gridCellWidth", gw, + "gridCellHeight", gh, "gridCellsX", w, "gridCellsY", h, "entities", out, + }) +end + +local function decals(l, i, gw, gh, w, h, radians) +local out = {} + for _, o in __iter(list(l.objects)) do + local rot = n(o.rotation, 0) + table.insert(out, obj({ + "x", n(o.x, 0), "y", n(o.y, 0), "scaleX", n(o.scaleX, 1), "scaleY", n(o.scaleY, 1), + "rotation", (radians and{(math.rad(rot) )}or{rot})[1], "texture", o.texture or o.name or "", + "originX", n(o.originX, 0.5), "originY", n(o.originY, 0.5), + "values", (tab(o.properties) and next(o.properties) and{(values(o.properties) )}or{nil})[1], + })) + end + return obj({ + "name", l.name, "_eid", eid(l, i), "offsetX", n(l.offsetX, 0), "offsetY", n(l.offsetY, 0), "gridCellWidth", gw, + "gridCellHeight", gh, "gridCellsX", w, "gridCellsY", h, "decals", out, "folder", l.folder or "", + }) +end + +local function radiansOf(map) +local src = (tab(map.meta) and tab(map.meta.source) and{map.meta.source }or{{} +})[1] if type(src.anglesRadians) == "boolean" then + return src.anglesRadians + end + return true +end + +function Write.level(map) +local layers = {} + flat(map.layers, layers) + local radians = radiansOf(map) + local pw = n(map.pxWidth, map.width * map.tileWidth) + local ph = n(map.pxHeight, map.height * map.tileHeight) + local out = {} + for i = #layers, 1, -1 do + local l = layers[i] + local gw = n(l.cellWidth, map.tileWidth) + local gh = n(l.cellHeight, map.tileHeight) + local cw, ch = math.ceil(pw / math.max(gw, 1)), math.ceil(ph / math.max(gh, 1)) + local kind = kindOf(l) + local li + if kind == "entity" then + li = entities(l, i, gw, gh, cw, ch, radians) + elseif kind == "decal" then + li = decals(l, i, gw, gh, cw, ch, radians) + elseif kind == "grid" then + li = gridLayer(map, l, i, gw, gh) + else + li = tileLayer(map, l, i, gw, gh) + end + table.insert(out, li) + end + return obj({ + "ogmoVersion", (tab(map.meta) and tab(map.meta.source) and type(map.meta.source.version) == "string" and{map.meta.source.version }or{VERSION})[1], + "width", pw, "height", ph, "offsetX", n(map.offsetX, 0), "offsetY", n(map.offsetY, 0), + "values", (tab(map.properties) and next(map.properties) and{(values(map.properties) )}or{nil})[1], + "layers", out, + }), nil +end + +-- ------------------------------------------------------------------------------------------------ project +local function tileset(ts) +local image = "" + if type(ts.imageData) == "buffer" then + image = Base64.dataUri(ts.imageData, "image/png") + end + return obj({ + "label", ts.name, "path", ts.imageSource or "", "image", image, "tileWidth", n(ts.tileWidth, 16), + "tileHeight", n(ts.tileHeight, 16), "tileSeparationX", n(ts.spacing, 0), "tileSeparationY", n(ts.spacingY, n(ts.spacing, 0)), + "tileMarginX", n(ts.margin, 0), "tileMarginY", n(ts.marginY, n(ts.margin, 0)), + }) +end + +local function entityTemplate(name, o, i) +local w, h = math.max(1, n(o.width, 16)), math.max(1, n(o.height, 16)) + return obj({ + "exportID", tostring(30000000 + i), "name", name, "limit", -1, "size", obj({ "x", w, "y", h }), + "origin", obj({ "x", n(o.originX, 0), "y", n(o.originY, 0) }), "originAnchored", true, + "shape", obj({ "label", "Rectangle", "points", { + obj({ "x", -1, "y", -1 }), obj({ "x", 1, "y", -1 }), obj({ "x", -1, "y", 1 }), + obj({ "x", 1, "y", -1 }), obj({ "x", -1, "y", 1 }), obj({ "x", 1, "y", 1 }), + } }), + "color", (type(o.color) == "string" and{o.color }or{"#ff0000ff"})[1], "tileX", false, "tileY", false, + "tileSize", obj({ "x", 16, "y", 16 }), "resizeableX", true, "resizeableY", true, "rotatable", true, + "rotationDegrees", 360, "canFlipX", true, "canFlipY", true, "canSetColor", false, "hasNodes", true, + "nodeLimit", 0, "nodeDisplay", 0, "nodeGhost", true, "tags", {}, "values", {}, + }) +end + +function Write.project(map) +if tab(map.ogmo) and map.meta and map.meta.project then + return map.ogmo, nil + end + local layers = {} + flat(map.layers, layers) + local defs = {} + local ents, seen = {}, {} + for i = #layers, 1, -1 do + local l = layers[i] + local kind = kindOf(l) + local gs = obj({ "x", n(l.cellWidth, map.tileWidth), "y", n(l.cellHeight, map.tileHeight) }) + local d +if kind == "tile" then + local ts = layerTileset(map, l) + d = obj({ "definition", "tile", "name", l.name, "gridSize", gs, "exportID", eid(l, i), "exportMode", n(l.exportMode, 0), "arrayMode", n(l.arrayMode, 0), "defaultTileset", (ts and{ts.name }or{"" })[1]}) + elseif kind == "grid" then + local legend = (tab(l.legend) and{(values(l.legend) )}or{(obj({ "0", "#00000000", "1", "#000000ff" }) +)})[1] d = obj({ "definition", "grid", "name", l.name, "gridSize", gs, "exportID", eid(l, i), "arrayMode", n(l.arrayMode, 0), "legend", legend }) + elseif kind == "decal" then + d = obj({ "definition", "decal", "name", l.name, "gridSize", gs, "exportID", eid(l, i), "folder", l.folder or "", "includeImageSequence", true, "scaleable", true, "rotatable", true, "values", {} }) + else + d = obj({ "definition", "entity", "name", l.name, "gridSize", gs, "exportID", eid(l, i), "requiredTags", {}, "excludedTags", {} }) + for _, o in __iter(list(l.objects)) do + local name = (type(o.class) == "string" and o.class ~= "" and{o.class }or{(o.name or "entity") +})[1] if not seen[name] then + seen[name] = true + table.insert(ents, entityTemplate(name, o, #ents)) + end + end + end + table.insert(defs, d) + end + local tss = {} + for _, ts in __iter(map.tilesets) do + table.insert(tss, tileset(ts)) + end + local grid = obj({ "x", map.tileWidth, "y", map.tileHeight }) + local size = obj({ "x", n(map.pxWidth, map.width * map.tileWidth), "y", n(map.pxHeight, map.height * map.tileHeight) }) + return obj({ + "name", (type(map.name) == "string" and{map.name }or{"Project"})[1], "ogmoVersion", VERSION, "levelPaths", { "." }, + "backgroundColor", (type(map.backgroundColor) == "string" and{map.backgroundColor }or{"#282c34ff"})[1], + "gridColor", "#3c4049cc", "anglesRadians", radiansOf(map), "directoryDepth", 5, "layerGridDefaultSize", grid, + "levelDefaultSize", size, "levelMinSize", obj({ "x", 128, "y", 128 }), "levelMaxSize", obj({ "x", 4096, "y", 4096 }), + "levelValues", {}, "defaultExportMode", ".json", "compactExport", false, "externalScript", "", "playCommand", "", + "entityTags", {}, "layers", defs, "entities", ents, "tilesets", tss, + }), nil +end + +return Write +end __FILES["vector/svg"] = function() local __compat = __compat local buffer, type = __compat.buffer, __compat.type --!strict -- vector/svg: SVG 1.1 / 2 static documents (W3C SVG 1.1 2nd ed., SVG 2 CR). Supports: shapes and paths, transforms, diff --git a/build/rosetta.lua.linemap.json b/build/rosetta.lua.linemap.json index 9e8a636..c0167db 100644 --- a/build/rosetta.lua.linemap.json +++ b/build/rosetta.lua.linemap.json @@ -1,553 +1,574 @@ [ [660, "src/Rosetta/init.luau"], [1504, "src/Rosetta/Registry.luau"], -[3685, "src/Rosetta/Types.luau"], -[4768, "src/Rosetta/archive/7z/init.luau"], -[5153, "src/Rosetta/archive/7z/Header.luau"], -[5680, "src/Rosetta/archive/adf/init.luau"], -[5962, "src/Rosetta/archive/applesingle/init.luau"], -[6148, "src/Rosetta/archive/ar/init.luau"], -[6551, "src/Rosetta/archive/arj/init.luau"], -[6761, "src/Rosetta/archive/binhex/init.luau"], -[7010, "src/Rosetta/archive/br/init.luau"], -[7085, "src/Rosetta/archive/bz2/init.luau"], -[7149, "src/Rosetta/archive/cab/init.luau"], -[7562, "src/Rosetta/archive/cab/Sum.luau"], -[7603, "src/Rosetta/archive/cpio/init.luau"], -[7771, "src/Rosetta/archive/d64/init.luau"], -[8185, "src/Rosetta/archive/fat/init.luau"], -[8307, "src/Rosetta/archive/grp/init.luau"], -[8421, "src/Rosetta/archive/gzip/init.luau"], -[8606, "src/Rosetta/archive/iso/init.luau"], -[8678, "src/Rosetta/archive/lha/init.luau"], -[9103, "src/Rosetta/archive/lz4/init.luau"], -[9447, "src/Rosetta/archive/macbinary/init.luau"], -[9645, "src/Rosetta/archive/mpq/init.luau"], -[10051, "src/Rosetta/archive/mpq/Crypt.luau"], -[10116, "src/Rosetta/archive/pak/init.luau"], -[10250, "src/Rosetta/archive/rpm/init.luau"], -[10574, "src/Rosetta/archive/tar/init.luau"], -[10692, "src/Rosetta/archive/uu/init.luau"], -[10962, "src/Rosetta/archive/vpk/init.luau"], -[11273, "src/Rosetta/archive/wad/init.luau"], -[11723, "src/Rosetta/archive/wad/Map.luau"], -[12153, "src/Rosetta/archive/wad/Picture.luau"], -[12255, "src/Rosetta/archive/wad2/init.luau"], -[12537, "src/Rosetta/archive/xz/init.luau"], -[12637, "src/Rosetta/archive/yenc/init.luau"], -[12909, "src/Rosetta/archive/z/init.luau"], -[13005, "src/Rosetta/archive/zip/init.luau"], -[13224, "src/Rosetta/archive/zoo/init.luau"], -[13420, "src/Rosetta/archive/zst/init.luau"], -[13484, "src/Rosetta/audio/aac/init.luau"], -[13690, "src/Rosetta/audio/ac3/init.luau"], -[13836, "src/Rosetta/audio/adpcm/init.luau"], -[13981, "src/Rosetta/audio/adx/init.luau"], -[14212, "src/Rosetta/audio/aiff/init.luau"], -[14603, "src/Rosetta/audio/ape/init.luau"], -[14731, "src/Rosetta/audio/au/init.luau"], -[14892, "src/Rosetta/audio/brstm/init.luau"], -[15183, "src/Rosetta/audio/caf/init.luau"], -[15845, "src/Rosetta/audio/flac/init.luau"], -[15993, "src/Rosetta/audio/flac/Meta.luau"], -[16215, "src/Rosetta/audio/flac/Stream.luau"], -[16585, "src/Rosetta/audio/m4a/init.luau"], -[16919, "src/Rosetta/audio/mp3/init.luau"], -[17179, "src/Rosetta/audio/mp3/Index.luau"], -[17370, "src/Rosetta/audio/mp3/Stream.luau"], -[17597, "src/Rosetta/audio/mp3/Tags.luau"], -[17909, "src/Rosetta/audio/mpc/init.luau"], -[18003, "src/Rosetta/audio/opus/init.luau"], -[18381, "src/Rosetta/audio/opus/Encode.luau"], -[18492, "src/Rosetta/audio/qoa/init.luau"], -[18672, "src/Rosetta/audio/tta/init.luau"], -[18790, "src/Rosetta/audio/vag/init.luau"], -[19013, "src/Rosetta/audio/voc/init.luau"], -[19288, "src/Rosetta/audio/vorbis/init.luau"], -[19742, "src/Rosetta/audio/vorbis/Encode.luau"], -[20555, "src/Rosetta/audio/wav/init.luau"], -[21176, "src/Rosetta/audio/wav/Codecs.luau"], -[21342, "src/Rosetta/audio/wavpack/init.luau"], -[21549, "src/Rosetta/cad/step/init.luau"], -[21931, "src/Rosetta/cad/step/Brep.luau"], -[22166, "src/Rosetta/cad/step/Parse.luau"], -[22723, "src/Rosetta/cad/step/Write.luau"], -[22971, "src/Rosetta/codecs/audio/Aac/init.luau"], -[23290, "src/Rosetta/codecs/audio/Aac/Decode.luau"], -[24173, "src/Rosetta/codecs/audio/Aac/Tables.luau"], -[24508, "src/Rosetta/codecs/audio/Ac3/init.luau"], -[24667, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], -[25552, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], -[25653, "src/Rosetta/codecs/audio/Adpcm/init.luau"], -[26407, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], -[26709, "src/Rosetta/codecs/audio/Alac/init.luau"], -[26943, "src/Rosetta/codecs/audio/Alac/Decode.luau"], -[27362, "src/Rosetta/codecs/audio/Alac/Encode.luau"], -[27774, "src/Rosetta/codecs/audio/Ape/init.luau"], -[27989, "src/Rosetta/codecs/audio/Ape/Decode.luau"], -[28750, "src/Rosetta/codecs/audio/ApeTag.luau"], -[28847, "src/Rosetta/codecs/audio/Flac/init.luau"], -[28858, "src/Rosetta/codecs/audio/Flac/Encode.luau"], -[29807, "src/Rosetta/codecs/audio/Flac/Frame.luau"], -[30404, "src/Rosetta/codecs/audio/Hively/init.luau"], -[30600, "src/Rosetta/codecs/audio/Hively/Load.luau"], -[30849, "src/Rosetta/codecs/audio/Hively/Player.luau"], -[31807, "src/Rosetta/codecs/audio/Hively/Tables.luau"], -[32026, "src/Rosetta/codecs/audio/Mdct/init.luau"], -[32210, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], -[32419, "src/Rosetta/codecs/audio/MidiRender.luau"], -[32765, "src/Rosetta/codecs/audio/Mpa/init.luau"], -[32779, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], -[32838, "src/Rosetta/codecs/audio/Mpa/Core.luau"], -[34441, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], -[34733, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], -[35118, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], -[35759, "src/Rosetta/codecs/audio/Mpa/Header.luau"], -[35900, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], -[36126, "src/Rosetta/codecs/audio/Musepack/init.luau"], -[36471, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], -[37352, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], -[37730, "src/Rosetta/codecs/audio/Opus/init.luau"], -[37744, "src/Rosetta/codecs/audio/Opus/Celt.luau"], -[39591, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], -[40656, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], -[40716, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], -[41176, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], -[41513, "src/Rosetta/codecs/audio/Opus/Packet.luau"], -[41746, "src/Rosetta/codecs/audio/Opus/Silk.luau"], -[43782, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], -[44156, "src/Rosetta/codecs/audio/Pcm/init.luau"], -[44419, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], -[44716, "src/Rosetta/codecs/audio/Qoa/init.luau"], -[44998, "src/Rosetta/codecs/audio/Resample/init.luau"], -[45357, "src/Rosetta/codecs/audio/SoundFont/init.luau"], -[45411, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], -[45554, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], -[46067, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], -[46848, "src/Rosetta/codecs/audio/Stream.luau"], -[47009, "src/Rosetta/codecs/audio/Tracker/init.luau"], -[47491, "src/Rosetta/codecs/audio/Tracker/Load.luau"], -[47769, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], -[47938, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], -[48066, "src/Rosetta/codecs/audio/Tracker/Player.luau"], -[50054, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], -[50170, "src/Rosetta/codecs/audio/Tta/init.luau"], -[50287, "src/Rosetta/codecs/audio/Tta/Decode.luau"], -[50539, "src/Rosetta/codecs/audio/Vorbis/init.luau"], -[50552, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], -[50936, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], -[51502, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], -[51923, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], -[51962, "src/Rosetta/codecs/audio/VorbisComment.luau"], -[52014, "src/Rosetta/codecs/audio/WavPack/init.luau"], -[52236, "src/Rosetta/codecs/audio/WavPack/Block.luau"], -[53691, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], -[53754, "src/Rosetta/codecs/compress/Brotli/init.luau"], -[53841, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], -[54810, "src/Rosetta/codecs/compress/Brotli/Static.luau"], -[55678, "src/Rosetta/codecs/compress/Bzip2/init.luau"], -[55726, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], -[56242, "src/Rosetta/codecs/compress/Deflate/init.luau"], -[56568, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], -[56988, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], -[57423, "src/Rosetta/codecs/compress/Explode.luau"], -[57619, "src/Rosetta/codecs/compress/Lz4.luau"], -[57888, "src/Rosetta/codecs/compress/Lzh/init.luau"], -[58492, "src/Rosetta/codecs/compress/Lzma/init.luau"], -[59032, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], -[59070, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], -[59543, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], -[59719, "src/Rosetta/codecs/compress/Lzw/init.luau"], -[59987, "src/Rosetta/codecs/compress/Lzx.luau"], -[60421, "src/Rosetta/codecs/compress/PackBits.luau"], -[60511, "src/Rosetta/codecs/compress/Quantum.luau"], -[60748, "src/Rosetta/codecs/compress/UnixCompress.luau"], -[61052, "src/Rosetta/codecs/compress/Xxh32.luau"], -[61121, "src/Rosetta/codecs/compress/Zstd/init.luau"], -[61178, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], -[62136, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], -[62288, "src/Rosetta/codecs/entropy/Huffman.luau"], -[62570, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], -[62581, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], -[62795, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], -[63039, "src/Rosetta/codecs/font/Bitmap.luau"], -[63240, "src/Rosetta/codecs/font/Cff/init.luau"], -[63881, "src/Rosetta/codecs/font/GlyphNames.luau"], -[64031, "src/Rosetta/codecs/font/TrueType/init.luau"], -[64345, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], -[64737, "src/Rosetta/codecs/font/TrueType/Tables.luau"], -[65239, "src/Rosetta/codecs/image/Bcn/init.luau"], -[65346, "src/Rosetta/codecs/image/Bcn/Decode.luau"], -[65835, "src/Rosetta/codecs/image/Bcn/Encode.luau"], -[66264, "src/Rosetta/codecs/image/Blend.luau"], -[66643, "src/Rosetta/codecs/image/Dct/init.luau"], -[67024, "src/Rosetta/codecs/image/Etc.luau"], -[67322, "src/Rosetta/codecs/image/Half.luau"], -[67391, "src/Rosetta/codecs/image/Jpeg/init.luau"], -[67745, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], -[68153, "src/Rosetta/codecs/image/Jpeg/Color.luau"], -[68390, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], -[69150, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], -[70031, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], -[70477, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], -[70555, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], -[70622, "src/Rosetta/codecs/image/Miptex.luau"], -[70922, "src/Rosetta/codecs/image/Pixels.luau"], -[71242, "src/Rosetta/codecs/image/Quantize/init.luau"], -[71701, "src/Rosetta/codecs/image/Raster.luau"], -[72398, "src/Rosetta/codecs/image/Texel.luau"], -[72771, "src/Rosetta/codecs/image/Texture.luau"], -[72916, "src/Rosetta/codecs/image/Vp8/init.luau"], -[73046, "src/Rosetta/codecs/image/Vp8/Decode.luau"], -[75002, "src/Rosetta/codecs/image/Vp8/Predict.luau"], -[75261, "src/Rosetta/codecs/image/Vp8/Tables.luau"], -[75510, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], -[75629, "src/Rosetta/codecs/image/Vp8L/init.luau"], -[75733, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], -[76586, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], -[77538, "src/Rosetta/codecs/image/Yuv.luau"], -[77806, "src/Rosetta/codecs/model/Brush.luau"], -[78446, "src/Rosetta/codecs/model/Draco/init.luau"], -[78778, "src/Rosetta/codecs/model/Draco/Attributes.luau"], -[79247, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], -[80436, "src/Rosetta/codecs/model/Draco/Int64.luau"], -[80585, "src/Rosetta/codecs/model/Draco/KdTree.luau"], -[80944, "src/Rosetta/codecs/model/Draco/Predict.luau"], -[81906, "src/Rosetta/codecs/model/Draco/Reader.luau"], -[82380, "src/Rosetta/codecs/model/Mat4.luau"], -[82639, "src/Rosetta/codecs/model/MeshFlatten.luau"], -[83167, "src/Rosetta/codecs/model/Minecraft/init.luau"], -[83719, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], -[83798, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], -[83905, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], -[84111, "src/Rosetta/codecs/model/Patch.luau"], -[84235, "src/Rosetta/codecs/model/Polygon.luau"], -[84469, "src/Rosetta/codecs/model/Rbx/init.luau"], -[84706, "src/Rosetta/codecs/model/Rbx/Binary.luau"], -[85460, "src/Rosetta/codecs/model/Rig.luau"], -[85703, "src/Rosetta/codecs/model/Sampler.luau"], -[85863, "src/Rosetta/codecs/model/Vrml/init.luau"], -[86011, "src/Rosetta/codecs/model/Vrml/Build.luau"], -[86585, "src/Rosetta/codecs/model/Vrml/Fields.luau"], -[86748, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], -[87497, "src/Rosetta/codecs/model/Vrml/Parse.luau"], -[88019, "src/Rosetta/codecs/model/Vrml/Write.luau"], -[88746, "src/Rosetta/codecs/model/Vrml/Xml.luau"], -[88978, "src/Rosetta/codecs/text/Json/init.luau"], -[89247, "src/Rosetta/codecs/text/Json/Decode.luau"], -[89661, "src/Rosetta/codecs/text/Json/Encode.luau"], -[89963, "src/Rosetta/codecs/text/Nbt/init.luau"], -[90316, "src/Rosetta/codecs/text/Nbt/Binary.luau"], -[91008, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], -[91648, "src/Rosetta/codecs/text/Nbt/Value.luau"], -[91886, "src/Rosetta/codecs/text/Text/init.luau"], -[91977, "src/Rosetta/codecs/text/Url/init.luau"], -[92182, "src/Rosetta/codecs/text/Xml/init.luau"], -[92585, "src/Rosetta/codecs/text/Xml/Parse.luau"], -[93325, "src/Rosetta/codecs/video/Dsp.luau"], -[94048, "src/Rosetta/codecs/video/H263/init.luau"], -[94204, "src/Rosetta/codecs/video/H263/Decoder.luau"], -[95062, "src/Rosetta/codecs/video/H263/Tables.luau"], -[95265, "src/Rosetta/codecs/video/H264/init.luau"], -[95638, "src/Rosetta/codecs/video/H264/Bitstream.luau"], -[95913, "src/Rosetta/codecs/video/H264/Cabac.luau"], -[97044, "src/Rosetta/codecs/video/H264/Cavlc.luau"], -[97812, "src/Rosetta/codecs/video/H264/Deblock.luau"], -[98070, "src/Rosetta/codecs/video/H264/Decoder.luau"], -[99079, "src/Rosetta/codecs/video/H264/Inter.luau"], -[99333, "src/Rosetta/codecs/video/H264/Intra.luau"], -[99740, "src/Rosetta/codecs/video/H264/Mb.luau"], -[100646, "src/Rosetta/codecs/video/H264/Params.luau"], -[101093, "src/Rosetta/codecs/video/H264/Slice.luau"], -[101344, "src/Rosetta/codecs/video/H264/Tables.luau"], -[101385, "src/Rosetta/codecs/video/H264/Transform.luau"], -[101550, "src/Rosetta/codecs/video/Legacy/init.luau"], -[101748, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], -[102045, "src/Rosetta/codecs/video/Legacy/Flic.luau"], -[102412, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], -[102530, "src/Rosetta/codecs/video/Legacy/Picture.luau"], -[102638, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], -[102911, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], -[103306, "src/Rosetta/codecs/video/Legacy/Smc.luau"], -[103483, "src/Rosetta/codecs/video/Mpeg1/init.luau"], -[103495, "src/Rosetta/codecs/video/Mpeg2/init.luau"], -[103862, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], -[105369, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], -[105508, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], -[105646, "src/Rosetta/codecs/video/Theora/init.luau"], -[105909, "src/Rosetta/codecs/video/Theora/Decoder.luau"], -[107173, "src/Rosetta/codecs/video/Theora/Header.luau"], -[107536, "src/Rosetta/codecs/video/Video/init.luau"], -[108093, "src/Rosetta/codecs/video/Video/Source.luau"], -[108378, "src/Rosetta/containers/Archive.luau"], -[108645, "src/Rosetta/containers/AudioWrap.luau"], -[109148, "src/Rosetta/containers/Avi/init.luau"], -[109700, "src/Rosetta/containers/Chunks.luau"], -[109835, "src/Rosetta/containers/Cpio.luau"], -[110263, "src/Rosetta/containers/Demux.luau"], -[110538, "src/Rosetta/containers/Ebml/init.luau"], -[110851, "src/Rosetta/containers/Fat.luau"], -[111539, "src/Rosetta/containers/Iso9660.luau"], -[112044, "src/Rosetta/containers/IsoBmff/init.luau"], -[112214, "src/Rosetta/containers/IsoBmff/Box.luau"], -[112402, "src/Rosetta/containers/IsoBmff/Demux.luau"], -[113247, "src/Rosetta/containers/IsoBmff/Meta.luau"], -[113768, "src/Rosetta/containers/IsoBmff/Mux.luau"], -[114284, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], -[114401, "src/Rosetta/containers/MacFile.luau"], -[114550, "src/Rosetta/containers/MpegEs.luau"], -[114716, "src/Rosetta/containers/MpegPs/init.luau"], -[114936, "src/Rosetta/containers/MpegTs/init.luau"], -[115728, "src/Rosetta/containers/Ogg/init.luau"], -[116153, "src/Rosetta/containers/Ogg/Mux.luau"], -[116348, "src/Rosetta/containers/Ogg/Page.luau"], -[116517, "src/Rosetta/containers/Riff/init.luau"], -[116834, "src/Rosetta/containers/Tar.luau"], -[117248, "src/Rosetta/containers/Zip/init.luau"], -[117880, "src/Rosetta/core/Adler32.luau"], -[117926, "src/Rosetta/core/Base64.luau"], -[118085, "src/Rosetta/core/Bits.luau"], -[118378, "src/Rosetta/core/Bytes.luau"], -[118905, "src/Rosetta/core/Crc16.luau"], -[118957, "src/Rosetta/core/Crc32.luau"], -[119069, "src/Rosetta/core/Err.luau"], -[119151, "src/Rosetta/core/Input.luau"], -[119227, "src/Rosetta/core/Md5.luau"], -[119386, "src/Rosetta/core/Sniff.luau"], -[119415, "src/Rosetta/data/cbor/init.luau"], -[119514, "src/Rosetta/data/cbor/Codec.luau"], -[120083, "src/Rosetta/data/csv/init.luau"], -[120395, "src/Rosetta/data/ini/init.luau"], -[120641, "src/Rosetta/data/json/init.luau"], -[120733, "src/Rosetta/data/msgpack/init.luau"], -[120822, "src/Rosetta/data/msgpack/Codec.luau"], -[121264, "src/Rosetta/data/nbt/init.luau"], -[121323, "src/Rosetta/data/plist/init.luau"], -[121629, "src/Rosetta/data/plist/Binary.luau"], -[121896, "src/Rosetta/data/q3shader/init.luau"], -[122135, "src/Rosetta/data/q3skin/init.luau"], -[122231, "src/Rosetta/data/snbt/init.luau"], -[122294, "src/Rosetta/data/toml/init.luau"], -[122361, "src/Rosetta/data/toml/Decode.luau"], -[122989, "src/Rosetta/data/toml/Encode.luau"], -[123198, "src/Rosetta/data/xml/init.luau"], -[123254, "src/Rosetta/data/yaml/init.luau"], -[123327, "src/Rosetta/data/yaml/Emit.luau"], -[123617, "src/Rosetta/data/yaml/Parse.luau"], -[124910, "src/Rosetta/font/bdf/init.luau"], -[125199, "src/Rosetta/font/bmfont/init.luau"], -[125626, "src/Rosetta/font/bmfont/Parse.luau"], -[126079, "src/Rosetta/font/eot/init.luau"], -[126311, "src/Rosetta/font/fon/init.luau"], -[126594, "src/Rosetta/font/hershey/init.luau"], -[126789, "src/Rosetta/font/pcf/init.luau"], -[127069, "src/Rosetta/font/psf/init.luau"], -[127389, "src/Rosetta/font/ttf/init.luau"], -[127440, "src/Rosetta/font/type1/init.luau"], -[127799, "src/Rosetta/font/type1/Charstring.luau"], -[128077, "src/Rosetta/font/woff/init.luau"], -[128209, "src/Rosetta/font/woff2/init.luau"], -[128266, "src/Rosetta/font/woff2/Rebuild.luau"], -[128806, "src/Rosetta/host/init.luau"], -[128851, "src/Rosetta/host/Love.luau"], -[128994, "src/Rosetta/host/LuaJIT.luau"], -[129044, "src/Rosetta/host/Luau.luau"], -[129067, "src/Rosetta/host/Roblox.luau"], -[129426, "src/Rosetta/image/ani/init.luau"], -[129606, "src/Rosetta/image/blp/init.luau"], -[129864, "src/Rosetta/image/bmp/init.luau"], -[130279, "src/Rosetta/image/dds/init.luau"], -[130762, "src/Rosetta/image/exr/init.luau"], -[131522, "src/Rosetta/image/exr/Codec.luau"], -[131633, "src/Rosetta/image/exr/Piz.luau"], -[131990, "src/Rosetta/image/gif/init.luau"], -[132506, "src/Rosetta/image/gif/Decode.luau"], -[132569, "src/Rosetta/image/hdr/init.luau"], -[132798, "src/Rosetta/image/hdr/Codec.luau"], -[133009, "src/Rosetta/image/icns/init.luau"], -[133340, "src/Rosetta/image/ico/init.luau"], -[133617, "src/Rosetta/image/ico/Dib.luau"], -[133712, "src/Rosetta/image/ilbm/init.luau"], -[134031, "src/Rosetta/image/jpeg/init.luau"], -[134167, "src/Rosetta/image/ktx/init.luau"], -[134827, "src/Rosetta/image/lmp/init.luau"], -[134960, "src/Rosetta/image/pcx/init.luau"], -[135224, "src/Rosetta/image/png/init.luau"], -[135804, "src/Rosetta/image/png/Apng.luau"], -[135884, "src/Rosetta/image/png/Decode.luau"], -[136124, "src/Rosetta/image/png/Encode.luau"], -[136279, "src/Rosetta/image/pnm/init.luau"], -[136657, "src/Rosetta/image/pnm/Codec.luau"], -[136934, "src/Rosetta/image/qoi/init.luau"], -[137056, "src/Rosetta/image/qoi/Codec.luau"], -[137206, "src/Rosetta/image/sgi/init.luau"], -[137491, "src/Rosetta/image/spr/init.luau"], -[137804, "src/Rosetta/image/sunras/init.luau"], -[138050, "src/Rosetta/image/tga/init.luau"], -[138320, "src/Rosetta/image/tga/Codec.luau"], -[138472, "src/Rosetta/image/tiff/init.luau"], -[139299, "src/Rosetta/image/tiff/Pixels.luau"], -[139689, "src/Rosetta/image/tim/init.luau"], -[139931, "src/Rosetta/image/vtf/init.luau"], -[140166, "src/Rosetta/image/webp/init.luau"], -[140776, "src/Rosetta/image/webp/Alpha.luau"], -[140852, "src/Rosetta/image/webp/Anim.luau"], -[141007, "src/Rosetta/image/xbm/init.luau"], -[141168, "src/Rosetta/image/xpm/init.luau"], -[141436, "src/Rosetta/image/xpm/Names.luau"], -[141492, "src/Rosetta/layered/aseprite/init.luau"], -[142230, "src/Rosetta/layered/ora/init.luau"], -[142517, "src/Rosetta/layered/psd/init.luau"], -[143252, "src/Rosetta/layered/psd/Channels.luau"], -[143604, "src/Rosetta/model/3ds/init.luau"], -[143687, "src/Rosetta/model/3ds/Build.luau"], -[144334, "src/Rosetta/model/3ds/Read.luau"], -[144830, "src/Rosetta/model/3ds/Write.luau"], -[145635, "src/Rosetta/model/3mf/init.luau"], -[145717, "src/Rosetta/model/3mf/Read.luau"], -[146305, "src/Rosetta/model/3mf/Write.luau"], -[146710, "src/Rosetta/model/b3d/init.luau"], -[146765, "src/Rosetta/model/b3d/Read.luau"], -[147336, "src/Rosetta/model/bsp/init.luau"], -[147527, "src/Rosetta/model/bsp/Lightmap.luau"], -[147593, "src/Rosetta/model/bsp/Quake.luau"], -[147980, "src/Rosetta/model/bsp/Quake3.luau"], -[148208, "src/Rosetta/model/bsp/Tree.luau"], -[148596, "src/Rosetta/model/dae/init.luau"], -[148785, "src/Rosetta/model/dae/Math.luau"], -[148832, "src/Rosetta/model/dae/Read.luau"], -[150682, "src/Rosetta/model/dae/Write.luau"], -[151051, "src/Rosetta/model/fbx/init.luau"], -[151199, "src/Rosetta/model/fbx/Ascii.luau"], -[151469, "src/Rosetta/model/fbx/Binary.luau"], -[151924, "src/Rosetta/model/fbx/Read.luau"], -[153286, "src/Rosetta/model/fbx/Write.luau"], -[154271, "src/Rosetta/model/fbx/Xform.luau"], -[154312, "src/Rosetta/model/gltf/init.luau"], -[154549, "src/Rosetta/model/gltf/Pack.luau"], -[154618, "src/Rosetta/model/gltf/Read.luau"], -[155349, "src/Rosetta/model/gltf/Write.luau"], -[156029, "src/Rosetta/model/iqm/init.luau"], -[156105, "src/Rosetta/model/iqm/Read.luau"], -[156460, "src/Rosetta/model/iqm/Write.luau"], -[157147, "src/Rosetta/model/ldraw/init.luau"], -[157225, "src/Rosetta/model/ldraw/Colors.luau"], -[157543, "src/Rosetta/model/ldraw/Read.luau"], -[158120, "src/Rosetta/model/lwo/init.luau"], -[158196, "src/Rosetta/model/lwo/Build.luau"], -[158658, "src/Rosetta/model/lwo/Parse.luau"], -[159201, "src/Rosetta/model/map/init.luau"], -[159518, "src/Rosetta/model/map/Build.luau"], -[159761, "src/Rosetta/model/map/Parse.luau"], -[160146, "src/Rosetta/model/map/Write.luau"], -[160292, "src/Rosetta/model/mca/init.luau"], -[160634, "src/Rosetta/model/mca/Chunk.luau"], -[160767, "src/Rosetta/model/mca/Lz4Block.luau"], -[160837, "src/Rosetta/model/md2/init.luau"], -[161036, "src/Rosetta/model/md3/init.luau"], -[161264, "src/Rosetta/model/md5/init.luau"], -[161345, "src/Rosetta/model/md5/Read.luau"], -[161778, "src/Rosetta/model/mdl/init.luau"], -[161860, "src/Rosetta/model/mdl/HalfLife.luau"], -[162188, "src/Rosetta/model/mdl/Quake.luau"], -[162406, "src/Rosetta/model/ms3d/init.luau"], -[162478, "src/Rosetta/model/ms3d/Read.luau"], -[162924, "src/Rosetta/model/ms3d/Write.luau"], -[163393, "src/Rosetta/model/obj/init.luau"], -[164135, "src/Rosetta/model/obj/Mtl.luau"], -[164422, "src/Rosetta/model/off/init.luau"], -[164884, "src/Rosetta/model/ply/init.luau"], -[165989, "src/Rosetta/model/ply/Binary.luau"], -[166190, "src/Rosetta/model/pmx/init.luau"], -[166259, "src/Rosetta/model/pmx/Build.luau"], -[166555, "src/Rosetta/model/pmx/Pmd.luau"], -[166890, "src/Rosetta/model/pmx/Read.luau"], -[167294, "src/Rosetta/model/qb/init.luau"], -[167687, "src/Rosetta/model/rbxm/init.luau"], -[168279, "src/Rosetta/model/rbxmx/init.luau"], -[168932, "src/Rosetta/model/robloxmesh/init.luau"], -[169591, "src/Rosetta/model/robloxmesh/Parse.luau"], -[170048, "src/Rosetta/model/robloxmesh/Write.luau"], -[170157, "src/Rosetta/model/schematic/init.luau"], -[170478, "src/Rosetta/model/schematic/Common.luau"], -[170598, "src/Rosetta/model/schematic/Litematic.luau"], -[170809, "src/Rosetta/model/schematic/Mcedit.luau"], -[171053, "src/Rosetta/model/schematic/Sponge.luau"], -[171182, "src/Rosetta/model/smd/init.luau"], -[171249, "src/Rosetta/model/smd/Read.luau"], -[171518, "src/Rosetta/model/smd/Write.luau"], -[171761, "src/Rosetta/model/stl/init.luau"], -[172211, "src/Rosetta/model/stl/Decode.luau"], -[172285, "src/Rosetta/model/usda/init.luau"], -[172494, "src/Rosetta/model/usda/Build.luau"], -[173772, "src/Rosetta/model/usda/Parse.luau"], -[174570, "src/Rosetta/model/usda/Write.luau"], -[175387, "src/Rosetta/model/vox/init.luau"], -[176273, "src/Rosetta/model/vox/Grid.luau"], -[176330, "src/Rosetta/model/vrml/init.luau"], -[176396, "src/Rosetta/model/x/init.luau"], -[176526, "src/Rosetta/model/x/Build.luau"], -[177089, "src/Rosetta/model/x/Parse.luau"], -[177386, "src/Rosetta/model/x3d/init.luau"], -[177464, "src/Rosetta/music/669/init.luau"], -[177670, "src/Rosetta/music/ahx/init.luau"], -[177721, "src/Rosetta/music/far/init.luau"], -[177950, "src/Rosetta/music/hmp/init.luau"], -[178214, "src/Rosetta/music/hvl/init.luau"], -[178265, "src/Rosetta/music/it/init.luau"], -[178683, "src/Rosetta/music/it/Itsex.luau"], -[178799, "src/Rosetta/music/med/init.luau"], -[179446, "src/Rosetta/music/midi/init.luau"], -[179589, "src/Rosetta/music/midi/Smf.luau"], -[180000, "src/Rosetta/music/mod/init.luau"], -[180353, "src/Rosetta/music/mtm/init.luau"], -[180575, "src/Rosetta/music/mus/init.luau"], -[180732, "src/Rosetta/music/okt/init.luau"], -[181013, "src/Rosetta/music/ptm/init.luau"], -[181235, "src/Rosetta/music/s3m/init.luau"], -[181471, "src/Rosetta/music/sf2/init.luau"], -[181514, "src/Rosetta/music/stm/init.luau"], -[181745, "src/Rosetta/music/ult/init.luau"], -[182049, "src/Rosetta/music/umx/init.luau"], -[182265, "src/Rosetta/music/xm/init.luau"], -[182826, "src/Rosetta/music/xmi/init.luau"], -[183034, "src/Rosetta/ops/AudioOps.luau"], -[183483, "src/Rosetta/ops/ImageOps/init.luau"], -[184127, "src/Rosetta/ops/ImageOps/Kernels.luau"], -[184637, "src/Rosetta/ops/LayerOps.luau"], -[184730, "src/Rosetta/ops/MeshOps/init.luau"], -[185766, "src/Rosetta/ops/MeshOps/Greedy.luau"], -[185933, "src/Rosetta/ops/MusicOps.luau"], -[186281, "src/Rosetta/playlist/m3u/init.luau"], -[186634, "src/Rosetta/playlist/pls/init.luau"], -[186812, "src/Rosetta/playlist/xspf/init.luau"], -[187015, "src/Rosetta/subtitle/ass/init.luau"], -[187459, "src/Rosetta/subtitle/srt/init.luau"], -[187632, "src/Rosetta/subtitle/vtt/init.luau"], -[187835, "src/Rosetta/vector/svg/init.luau"], -[187921, "src/Rosetta/vector/svg/Parse.luau"], -[188667, "src/Rosetta/vector/svg/PathData.luau"], -[189035, "src/Rosetta/vector/svg/Render.luau"], -[189452, "src/Rosetta/vector/svg/Style.luau"], -[189824, "src/Rosetta/vector/svg/Write.luau"], -[190024, "src/Rosetta/vector/tiled/init.luau"], -[190204, "src/Rosetta/vector/tiled/Data.luau"], -[190355, "src/Rosetta/vector/tiled/Tmj.luau"], -[190986, "src/Rosetta/vector/tiled/Tmx.luau"], -[191598, "src/Rosetta/video/avi/init.luau"], -[191892, "src/Rosetta/video/fli/init.luau"], -[192043, "src/Rosetta/video/flv/init.luau"], -[192427, "src/Rosetta/video/flv/Amf.luau"], -[192585, "src/Rosetta/video/flv/Mux.luau"], -[192866, "src/Rosetta/video/h264/init.luau"], -[193005, "src/Rosetta/video/mkv/init.luau"], -[193161, "src/Rosetta/video/mkv/Mux.luau"], -[193440, "src/Rosetta/video/mkv/Parse.luau"], -[194161, "src/Rosetta/video/mp4/init.luau"], -[194489, "src/Rosetta/video/mpegps/init.luau"], -[194676, "src/Rosetta/video/mpegts/init.luau"], -[194914, "src/Rosetta/video/ogv/init.luau"], -[195309, "src/Rosetta/video/smk/init.luau"], -[195618, "src/Rosetta/video/smk/Audio.luau"], -[195738, "src/Rosetta/video/y4m/init.luau"] +[3769, "src/Rosetta/Types.luau"], +[4852, "src/Rosetta/archive/7z/init.luau"], +[5237, "src/Rosetta/archive/7z/Header.luau"], +[5764, "src/Rosetta/archive/adf/init.luau"], +[6046, "src/Rosetta/archive/applesingle/init.luau"], +[6232, "src/Rosetta/archive/ar/init.luau"], +[6635, "src/Rosetta/archive/arj/init.luau"], +[6845, "src/Rosetta/archive/binhex/init.luau"], +[7094, "src/Rosetta/archive/br/init.luau"], +[7169, "src/Rosetta/archive/bz2/init.luau"], +[7233, "src/Rosetta/archive/cab/init.luau"], +[7646, "src/Rosetta/archive/cab/Sum.luau"], +[7687, "src/Rosetta/archive/cpio/init.luau"], +[7855, "src/Rosetta/archive/d64/init.luau"], +[8269, "src/Rosetta/archive/fat/init.luau"], +[8391, "src/Rosetta/archive/grp/init.luau"], +[8505, "src/Rosetta/archive/gzip/init.luau"], +[8690, "src/Rosetta/archive/iso/init.luau"], +[8762, "src/Rosetta/archive/lha/init.luau"], +[9187, "src/Rosetta/archive/lz4/init.luau"], +[9531, "src/Rosetta/archive/macbinary/init.luau"], +[9729, "src/Rosetta/archive/mpq/init.luau"], +[10135, "src/Rosetta/archive/mpq/Crypt.luau"], +[10200, "src/Rosetta/archive/pak/init.luau"], +[10334, "src/Rosetta/archive/rpm/init.luau"], +[10658, "src/Rosetta/archive/tar/init.luau"], +[10776, "src/Rosetta/archive/unitypackage/init.luau"], +[11012, "src/Rosetta/archive/uu/init.luau"], +[11282, "src/Rosetta/archive/vpk/init.luau"], +[11593, "src/Rosetta/archive/wad/init.luau"], +[12043, "src/Rosetta/archive/wad/Map.luau"], +[12473, "src/Rosetta/archive/wad/Picture.luau"], +[12575, "src/Rosetta/archive/wad2/init.luau"], +[12857, "src/Rosetta/archive/xz/init.luau"], +[12957, "src/Rosetta/archive/yenc/init.luau"], +[13229, "src/Rosetta/archive/z/init.luau"], +[13325, "src/Rosetta/archive/zip/init.luau"], +[13544, "src/Rosetta/archive/zoo/init.luau"], +[13740, "src/Rosetta/archive/zst/init.luau"], +[13804, "src/Rosetta/audio/aac/init.luau"], +[14010, "src/Rosetta/audio/ac3/init.luau"], +[14156, "src/Rosetta/audio/adpcm/init.luau"], +[14301, "src/Rosetta/audio/adx/init.luau"], +[14532, "src/Rosetta/audio/aiff/init.luau"], +[14923, "src/Rosetta/audio/ape/init.luau"], +[15051, "src/Rosetta/audio/au/init.luau"], +[15212, "src/Rosetta/audio/brstm/init.luau"], +[15503, "src/Rosetta/audio/caf/init.luau"], +[16165, "src/Rosetta/audio/flac/init.luau"], +[16313, "src/Rosetta/audio/flac/Meta.luau"], +[16535, "src/Rosetta/audio/flac/Stream.luau"], +[16905, "src/Rosetta/audio/m4a/init.luau"], +[17239, "src/Rosetta/audio/mp3/init.luau"], +[17499, "src/Rosetta/audio/mp3/Index.luau"], +[17690, "src/Rosetta/audio/mp3/Stream.luau"], +[17917, "src/Rosetta/audio/mp3/Tags.luau"], +[18229, "src/Rosetta/audio/mpc/init.luau"], +[18323, "src/Rosetta/audio/opus/init.luau"], +[18701, "src/Rosetta/audio/opus/Encode.luau"], +[18812, "src/Rosetta/audio/qoa/init.luau"], +[18992, "src/Rosetta/audio/tta/init.luau"], +[19110, "src/Rosetta/audio/vag/init.luau"], +[19333, "src/Rosetta/audio/voc/init.luau"], +[19608, "src/Rosetta/audio/vorbis/init.luau"], +[20062, "src/Rosetta/audio/vorbis/Encode.luau"], +[20875, "src/Rosetta/audio/wav/init.luau"], +[21496, "src/Rosetta/audio/wav/Codecs.luau"], +[21662, "src/Rosetta/audio/wavpack/init.luau"], +[21869, "src/Rosetta/cad/step/init.luau"], +[22251, "src/Rosetta/cad/step/Brep.luau"], +[22486, "src/Rosetta/cad/step/Parse.luau"], +[23043, "src/Rosetta/cad/step/Write.luau"], +[23291, "src/Rosetta/codecs/audio/Aac/init.luau"], +[23610, "src/Rosetta/codecs/audio/Aac/Decode.luau"], +[24493, "src/Rosetta/codecs/audio/Aac/Tables.luau"], +[24828, "src/Rosetta/codecs/audio/Ac3/init.luau"], +[24987, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], +[25872, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], +[25973, "src/Rosetta/codecs/audio/Adpcm/init.luau"], +[26727, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], +[27029, "src/Rosetta/codecs/audio/Alac/init.luau"], +[27263, "src/Rosetta/codecs/audio/Alac/Decode.luau"], +[27682, "src/Rosetta/codecs/audio/Alac/Encode.luau"], +[28094, "src/Rosetta/codecs/audio/Ape/init.luau"], +[28309, "src/Rosetta/codecs/audio/Ape/Decode.luau"], +[29070, "src/Rosetta/codecs/audio/ApeTag.luau"], +[29167, "src/Rosetta/codecs/audio/Flac/init.luau"], +[29178, "src/Rosetta/codecs/audio/Flac/Encode.luau"], +[30127, "src/Rosetta/codecs/audio/Flac/Frame.luau"], +[30724, "src/Rosetta/codecs/audio/Hively/init.luau"], +[30920, "src/Rosetta/codecs/audio/Hively/Load.luau"], +[31169, "src/Rosetta/codecs/audio/Hively/Player.luau"], +[32127, "src/Rosetta/codecs/audio/Hively/Tables.luau"], +[32346, "src/Rosetta/codecs/audio/Mdct/init.luau"], +[32530, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], +[32739, "src/Rosetta/codecs/audio/MidiRender.luau"], +[33085, "src/Rosetta/codecs/audio/Mpa/init.luau"], +[33099, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], +[33158, "src/Rosetta/codecs/audio/Mpa/Core.luau"], +[34761, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], +[35053, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], +[35438, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], +[36079, "src/Rosetta/codecs/audio/Mpa/Header.luau"], +[36220, "src/Rosetta/codecs/audio/Mpa/Tables.luau"], +[36446, "src/Rosetta/codecs/audio/Musepack/init.luau"], +[36791, "src/Rosetta/codecs/audio/Musepack/Decode.luau"], +[37672, "src/Rosetta/codecs/audio/Musepack/Tables.luau"], +[38050, "src/Rosetta/codecs/audio/Opus/init.luau"], +[38064, "src/Rosetta/codecs/audio/Opus/Celt.luau"], +[39911, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], +[40976, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], +[41036, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], +[41496, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], +[41833, "src/Rosetta/codecs/audio/Opus/Packet.luau"], +[42066, "src/Rosetta/codecs/audio/Opus/Silk.luau"], +[44102, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"], +[44476, "src/Rosetta/codecs/audio/Pcm/init.luau"], +[44739, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], +[45036, "src/Rosetta/codecs/audio/Qoa/init.luau"], +[45318, "src/Rosetta/codecs/audio/Resample/init.luau"], +[45677, "src/Rosetta/codecs/audio/SoundFont/init.luau"], +[45731, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], +[45874, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], +[46387, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"], +[47168, "src/Rosetta/codecs/audio/Stream.luau"], +[47329, "src/Rosetta/codecs/audio/Tracker/init.luau"], +[47811, "src/Rosetta/codecs/audio/Tracker/Load.luau"], +[48089, "src/Rosetta/codecs/audio/Tracker/Mixer.luau"], +[48258, "src/Rosetta/codecs/audio/Tracker/Pcm.luau"], +[48386, "src/Rosetta/codecs/audio/Tracker/Player.luau"], +[50374, "src/Rosetta/codecs/audio/Tracker/Tables.luau"], +[50490, "src/Rosetta/codecs/audio/Tta/init.luau"], +[50607, "src/Rosetta/codecs/audio/Tta/Decode.luau"], +[50859, "src/Rosetta/codecs/audio/Vorbis/init.luau"], +[50872, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], +[51256, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], +[51822, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], +[52243, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"], +[52282, "src/Rosetta/codecs/audio/VorbisComment.luau"], +[52334, "src/Rosetta/codecs/audio/WavPack/init.luau"], +[52556, "src/Rosetta/codecs/audio/WavPack/Block.luau"], +[54011, "src/Rosetta/codecs/audio/WavPack/Tables.luau"], +[54074, "src/Rosetta/codecs/compress/Brotli/init.luau"], +[54161, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], +[55130, "src/Rosetta/codecs/compress/Brotli/Static.luau"], +[55998, "src/Rosetta/codecs/compress/Bzip2/init.luau"], +[56046, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], +[56562, "src/Rosetta/codecs/compress/Deflate/init.luau"], +[56888, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], +[57308, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"], +[57743, "src/Rosetta/codecs/compress/Explode.luau"], +[57939, "src/Rosetta/codecs/compress/Lz4.luau"], +[58208, "src/Rosetta/codecs/compress/Lzh/init.luau"], +[58812, "src/Rosetta/codecs/compress/Lzma/init.luau"], +[59352, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], +[59390, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], +[59863, "src/Rosetta/codecs/compress/Lzma/Filters.luau"], +[60039, "src/Rosetta/codecs/compress/Lzw/init.luau"], +[60307, "src/Rosetta/codecs/compress/Lzx.luau"], +[60741, "src/Rosetta/codecs/compress/PackBits.luau"], +[60831, "src/Rosetta/codecs/compress/Quantum.luau"], +[61068, "src/Rosetta/codecs/compress/UnixCompress.luau"], +[61372, "src/Rosetta/codecs/compress/Xxh32.luau"], +[61441, "src/Rosetta/codecs/compress/Zstd/init.luau"], +[61498, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], +[62456, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"], +[62608, "src/Rosetta/codecs/entropy/Huffman.luau"], +[62890, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], +[62901, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], +[63115, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"], +[63359, "src/Rosetta/codecs/font/Bitmap.luau"], +[63560, "src/Rosetta/codecs/font/Cff/init.luau"], +[64201, "src/Rosetta/codecs/font/GlyphNames.luau"], +[64351, "src/Rosetta/codecs/font/TrueType/init.luau"], +[64665, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], +[65057, "src/Rosetta/codecs/font/TrueType/Tables.luau"], +[65559, "src/Rosetta/codecs/image/Bcn/init.luau"], +[65666, "src/Rosetta/codecs/image/Bcn/Decode.luau"], +[66155, "src/Rosetta/codecs/image/Bcn/Encode.luau"], +[66584, "src/Rosetta/codecs/image/Blend.luau"], +[66963, "src/Rosetta/codecs/image/Dct/init.luau"], +[67344, "src/Rosetta/codecs/image/Etc.luau"], +[67642, "src/Rosetta/codecs/image/Half.luau"], +[67711, "src/Rosetta/codecs/image/Jpeg/init.luau"], +[68065, "src/Rosetta/codecs/image/Jpeg/Arith.luau"], +[68473, "src/Rosetta/codecs/image/Jpeg/Color.luau"], +[68710, "src/Rosetta/codecs/image/Jpeg/Decode.luau"], +[69470, "src/Rosetta/codecs/image/Jpeg/Encode.luau"], +[70351, "src/Rosetta/codecs/image/Jpeg/Scan.luau"], +[70797, "src/Rosetta/codecs/image/Jpeg/Tables.luau"], +[70875, "src/Rosetta/codecs/image/Jpeg/Yuv.luau"], +[70942, "src/Rosetta/codecs/image/Miptex.luau"], +[71242, "src/Rosetta/codecs/image/Pixels.luau"], +[71562, "src/Rosetta/codecs/image/Quantize/init.luau"], +[72021, "src/Rosetta/codecs/image/Raster.luau"], +[72718, "src/Rosetta/codecs/image/Texel.luau"], +[73091, "src/Rosetta/codecs/image/Texture.luau"], +[73236, "src/Rosetta/codecs/image/Vp8/init.luau"], +[73366, "src/Rosetta/codecs/image/Vp8/Decode.luau"], +[75322, "src/Rosetta/codecs/image/Vp8/Predict.luau"], +[75581, "src/Rosetta/codecs/image/Vp8/Tables.luau"], +[75830, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], +[75949, "src/Rosetta/codecs/image/Vp8L/init.luau"], +[76053, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], +[76906, "src/Rosetta/codecs/image/Vp8L/Encode.luau"], +[77858, "src/Rosetta/codecs/image/Yuv.luau"], +[78126, "src/Rosetta/codecs/model/Brush.luau"], +[78766, "src/Rosetta/codecs/model/Draco/init.luau"], +[79098, "src/Rosetta/codecs/model/Draco/Attributes.luau"], +[79567, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], +[80756, "src/Rosetta/codecs/model/Draco/Int64.luau"], +[80905, "src/Rosetta/codecs/model/Draco/KdTree.luau"], +[81264, "src/Rosetta/codecs/model/Draco/Predict.luau"], +[82226, "src/Rosetta/codecs/model/Draco/Reader.luau"], +[82700, "src/Rosetta/codecs/model/Mat4.luau"], +[82959, "src/Rosetta/codecs/model/MeshFlatten.luau"], +[83487, "src/Rosetta/codecs/model/Minecraft/init.luau"], +[84039, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], +[84118, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], +[84225, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], +[84431, "src/Rosetta/codecs/model/Patch.luau"], +[84555, "src/Rosetta/codecs/model/Polygon.luau"], +[84789, "src/Rosetta/codecs/model/Rbx/init.luau"], +[85026, "src/Rosetta/codecs/model/Rbx/Binary.luau"], +[85780, "src/Rosetta/codecs/model/Rig.luau"], +[86023, "src/Rosetta/codecs/model/Sampler.luau"], +[86183, "src/Rosetta/codecs/model/Vrml/init.luau"], +[86331, "src/Rosetta/codecs/model/Vrml/Build.luau"], +[86905, "src/Rosetta/codecs/model/Vrml/Fields.luau"], +[87068, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], +[87817, "src/Rosetta/codecs/model/Vrml/Parse.luau"], +[88339, "src/Rosetta/codecs/model/Vrml/Write.luau"], +[89066, "src/Rosetta/codecs/model/Vrml/Xml.luau"], +[89298, "src/Rosetta/codecs/text/GodotVariant.luau"], +[89957, "src/Rosetta/codecs/text/Json/init.luau"], +[90226, "src/Rosetta/codecs/text/Json/Decode.luau"], +[90640, "src/Rosetta/codecs/text/Json/Encode.luau"], +[90942, "src/Rosetta/codecs/text/Nbt/init.luau"], +[91295, "src/Rosetta/codecs/text/Nbt/Binary.luau"], +[91987, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], +[92627, "src/Rosetta/codecs/text/Nbt/Value.luau"], +[92865, "src/Rosetta/codecs/text/Text/init.luau"], +[92956, "src/Rosetta/codecs/text/Url/init.luau"], +[93161, "src/Rosetta/codecs/text/Xml/init.luau"], +[93564, "src/Rosetta/codecs/text/Xml/Parse.luau"], +[94304, "src/Rosetta/codecs/video/Dsp.luau"], +[95027, "src/Rosetta/codecs/video/H263/init.luau"], +[95183, "src/Rosetta/codecs/video/H263/Decoder.luau"], +[96041, "src/Rosetta/codecs/video/H263/Tables.luau"], +[96244, "src/Rosetta/codecs/video/H264/init.luau"], +[96617, "src/Rosetta/codecs/video/H264/Bitstream.luau"], +[96892, "src/Rosetta/codecs/video/H264/Cabac.luau"], +[98023, "src/Rosetta/codecs/video/H264/Cavlc.luau"], +[98791, "src/Rosetta/codecs/video/H264/Deblock.luau"], +[99049, "src/Rosetta/codecs/video/H264/Decoder.luau"], +[100058, "src/Rosetta/codecs/video/H264/Inter.luau"], +[100312, "src/Rosetta/codecs/video/H264/Intra.luau"], +[100719, "src/Rosetta/codecs/video/H264/Mb.luau"], +[101625, "src/Rosetta/codecs/video/H264/Params.luau"], +[102072, "src/Rosetta/codecs/video/H264/Slice.luau"], +[102323, "src/Rosetta/codecs/video/H264/Tables.luau"], +[102364, "src/Rosetta/codecs/video/H264/Transform.luau"], +[102529, "src/Rosetta/codecs/video/Legacy/init.luau"], +[102727, "src/Rosetta/codecs/video/Legacy/Cinepak.luau"], +[103024, "src/Rosetta/codecs/video/Legacy/Flic.luau"], +[103391, "src/Rosetta/codecs/video/Legacy/Msvideo1.luau"], +[103509, "src/Rosetta/codecs/video/Legacy/Picture.luau"], +[103617, "src/Rosetta/codecs/video/Legacy/QtRle.luau"], +[103890, "src/Rosetta/codecs/video/Legacy/Smacker.luau"], +[104285, "src/Rosetta/codecs/video/Legacy/Smc.luau"], +[104462, "src/Rosetta/codecs/video/Mpeg1/init.luau"], +[104474, "src/Rosetta/codecs/video/Mpeg2/init.luau"], +[104841, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], +[106348, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], +[106487, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"], +[106625, "src/Rosetta/codecs/video/Theora/init.luau"], +[106888, "src/Rosetta/codecs/video/Theora/Decoder.luau"], +[108152, "src/Rosetta/codecs/video/Theora/Header.luau"], +[108515, "src/Rosetta/codecs/video/Video/init.luau"], +[109072, "src/Rosetta/codecs/video/Video/Source.luau"], +[109357, "src/Rosetta/containers/Archive.luau"], +[109624, "src/Rosetta/containers/AudioWrap.luau"], +[110127, "src/Rosetta/containers/Avi/init.luau"], +[110679, "src/Rosetta/containers/Chunks.luau"], +[110814, "src/Rosetta/containers/Cpio.luau"], +[111242, "src/Rosetta/containers/Demux.luau"], +[111517, "src/Rosetta/containers/Ebml/init.luau"], +[111830, "src/Rosetta/containers/Fat.luau"], +[112518, "src/Rosetta/containers/Iso9660.luau"], +[113023, "src/Rosetta/containers/IsoBmff/init.luau"], +[113193, "src/Rosetta/containers/IsoBmff/Box.luau"], +[113381, "src/Rosetta/containers/IsoBmff/Demux.luau"], +[114226, "src/Rosetta/containers/IsoBmff/Meta.luau"], +[114747, "src/Rosetta/containers/IsoBmff/Mux.luau"], +[115263, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], +[115380, "src/Rosetta/containers/MacFile.luau"], +[115529, "src/Rosetta/containers/MpegEs.luau"], +[115695, "src/Rosetta/containers/MpegPs/init.luau"], +[115915, "src/Rosetta/containers/MpegTs/init.luau"], +[116707, "src/Rosetta/containers/Ogg/init.luau"], +[117132, "src/Rosetta/containers/Ogg/Mux.luau"], +[117327, "src/Rosetta/containers/Ogg/Page.luau"], +[117496, "src/Rosetta/containers/Riff/init.luau"], +[117813, "src/Rosetta/containers/Tar.luau"], +[118227, "src/Rosetta/containers/Zip/init.luau"], +[118859, "src/Rosetta/core/Adler32.luau"], +[118905, "src/Rosetta/core/Base64.luau"], +[119064, "src/Rosetta/core/Bits.luau"], +[119357, "src/Rosetta/core/Bytes.luau"], +[119884, "src/Rosetta/core/Crc16.luau"], +[119936, "src/Rosetta/core/Crc32.luau"], +[120048, "src/Rosetta/core/Err.luau"], +[120130, "src/Rosetta/core/Input.luau"], +[120206, "src/Rosetta/core/Md5.luau"], +[120365, "src/Rosetta/core/Sniff.luau"], +[120394, "src/Rosetta/data/cbor/init.luau"], +[120493, "src/Rosetta/data/cbor/Codec.luau"], +[121062, "src/Rosetta/data/csv/init.luau"], +[121374, "src/Rosetta/data/ini/init.luau"], +[121620, "src/Rosetta/data/json/init.luau"], +[121712, "src/Rosetta/data/msgpack/init.luau"], +[121801, "src/Rosetta/data/msgpack/Codec.luau"], +[122243, "src/Rosetta/data/nbt/init.luau"], +[122302, "src/Rosetta/data/plist/init.luau"], +[122608, "src/Rosetta/data/plist/Binary.luau"], +[122875, "src/Rosetta/data/q3shader/init.luau"], +[123114, "src/Rosetta/data/q3skin/init.luau"], +[123210, "src/Rosetta/data/snbt/init.luau"], +[123273, "src/Rosetta/data/toml/init.luau"], +[123340, "src/Rosetta/data/toml/Decode.luau"], +[123968, "src/Rosetta/data/toml/Encode.luau"], +[124177, "src/Rosetta/data/tres/init.luau"], +[124322, "src/Rosetta/data/xml/init.luau"], +[124378, "src/Rosetta/data/yaml/init.luau"], +[124451, "src/Rosetta/data/yaml/Emit.luau"], +[124741, "src/Rosetta/data/yaml/Parse.luau"], +[126034, "src/Rosetta/font/bdf/init.luau"], +[126323, "src/Rosetta/font/bmfont/init.luau"], +[126750, "src/Rosetta/font/bmfont/Parse.luau"], +[127203, "src/Rosetta/font/eot/init.luau"], +[127435, "src/Rosetta/font/fon/init.luau"], +[127718, "src/Rosetta/font/hershey/init.luau"], +[127913, "src/Rosetta/font/pcf/init.luau"], +[128193, "src/Rosetta/font/psf/init.luau"], +[128513, "src/Rosetta/font/ttf/init.luau"], +[128564, "src/Rosetta/font/type1/init.luau"], +[128923, "src/Rosetta/font/type1/Charstring.luau"], +[129201, "src/Rosetta/font/woff/init.luau"], +[129333, "src/Rosetta/font/woff2/init.luau"], +[129390, "src/Rosetta/font/woff2/Rebuild.luau"], +[129930, "src/Rosetta/host/init.luau"], +[129975, "src/Rosetta/host/Love.luau"], +[130118, "src/Rosetta/host/LuaJIT.luau"], +[130168, "src/Rosetta/host/Luau.luau"], +[130191, "src/Rosetta/host/Roblox.luau"], +[130550, "src/Rosetta/image/ani/init.luau"], +[130730, "src/Rosetta/image/blp/init.luau"], +[130988, "src/Rosetta/image/bmp/init.luau"], +[131403, "src/Rosetta/image/dds/init.luau"], +[131886, "src/Rosetta/image/exr/init.luau"], +[132646, "src/Rosetta/image/exr/Codec.luau"], +[132757, "src/Rosetta/image/exr/Piz.luau"], +[133114, "src/Rosetta/image/gif/init.luau"], +[133630, "src/Rosetta/image/gif/Decode.luau"], +[133693, "src/Rosetta/image/hdr/init.luau"], +[133922, "src/Rosetta/image/hdr/Codec.luau"], +[134133, "src/Rosetta/image/icns/init.luau"], +[134464, "src/Rosetta/image/ico/init.luau"], +[134741, "src/Rosetta/image/ico/Dib.luau"], +[134836, "src/Rosetta/image/ilbm/init.luau"], +[135155, "src/Rosetta/image/jpeg/init.luau"], +[135291, "src/Rosetta/image/ktx/init.luau"], +[135951, "src/Rosetta/image/lmp/init.luau"], +[136084, "src/Rosetta/image/pcx/init.luau"], +[136348, "src/Rosetta/image/png/init.luau"], +[136928, "src/Rosetta/image/png/Apng.luau"], +[137008, "src/Rosetta/image/png/Decode.luau"], +[137248, "src/Rosetta/image/png/Encode.luau"], +[137403, "src/Rosetta/image/pnm/init.luau"], +[137781, "src/Rosetta/image/pnm/Codec.luau"], +[138058, "src/Rosetta/image/qoi/init.luau"], +[138180, "src/Rosetta/image/qoi/Codec.luau"], +[138330, "src/Rosetta/image/sgi/init.luau"], +[138615, "src/Rosetta/image/spr/init.luau"], +[138928, "src/Rosetta/image/sunras/init.luau"], +[139174, "src/Rosetta/image/tga/init.luau"], +[139444, "src/Rosetta/image/tga/Codec.luau"], +[139596, "src/Rosetta/image/tiff/init.luau"], +[140423, "src/Rosetta/image/tiff/Pixels.luau"], +[140813, "src/Rosetta/image/tim/init.luau"], +[141055, "src/Rosetta/image/vtf/init.luau"], +[141290, "src/Rosetta/image/webp/init.luau"], +[141900, "src/Rosetta/image/webp/Alpha.luau"], +[141976, "src/Rosetta/image/webp/Anim.luau"], +[142131, "src/Rosetta/image/xbm/init.luau"], +[142292, "src/Rosetta/image/xpm/init.luau"], +[142560, "src/Rosetta/image/xpm/Names.luau"], +[142616, "src/Rosetta/layered/aseprite/init.luau"], +[143354, "src/Rosetta/layered/ora/init.luau"], +[143641, "src/Rosetta/layered/psd/init.luau"], +[144376, "src/Rosetta/layered/psd/Channels.luau"], +[144728, "src/Rosetta/model/3ds/init.luau"], +[144811, "src/Rosetta/model/3ds/Build.luau"], +[145458, "src/Rosetta/model/3ds/Read.luau"], +[145954, "src/Rosetta/model/3ds/Write.luau"], +[146759, "src/Rosetta/model/3mf/init.luau"], +[146841, "src/Rosetta/model/3mf/Read.luau"], +[147429, "src/Rosetta/model/3mf/Write.luau"], +[147834, "src/Rosetta/model/ase/init.luau"], +[147957, "src/Rosetta/model/ase/Build.luau"], +[148531, "src/Rosetta/model/ase/Parse.luau"], +[148600, "src/Rosetta/model/ase/Write.luau"], +[149063, "src/Rosetta/model/b3d/init.luau"], +[149118, "src/Rosetta/model/b3d/Read.luau"], +[149689, "src/Rosetta/model/bsp/init.luau"], +[149880, "src/Rosetta/model/bsp/Lightmap.luau"], +[149946, "src/Rosetta/model/bsp/Quake.luau"], +[150333, "src/Rosetta/model/bsp/Quake3.luau"], +[150561, "src/Rosetta/model/bsp/Tree.luau"], +[150949, "src/Rosetta/model/dae/init.luau"], +[151138, "src/Rosetta/model/dae/Math.luau"], +[151185, "src/Rosetta/model/dae/Read.luau"], +[153035, "src/Rosetta/model/dae/Write.luau"], +[153404, "src/Rosetta/model/fbx/init.luau"], +[153552, "src/Rosetta/model/fbx/Ascii.luau"], +[153822, "src/Rosetta/model/fbx/Binary.luau"], +[154277, "src/Rosetta/model/fbx/Read.luau"], +[155639, "src/Rosetta/model/fbx/Write.luau"], +[156624, "src/Rosetta/model/fbx/Xform.luau"], +[156665, "src/Rosetta/model/gltf/init.luau"], +[156902, "src/Rosetta/model/gltf/Pack.luau"], +[156971, "src/Rosetta/model/gltf/Read.luau"], +[157702, "src/Rosetta/model/gltf/Write.luau"], +[158382, "src/Rosetta/model/godot/init.luau"], +[158473, "src/Rosetta/model/godot/Build.luau"], +[159015, "src/Rosetta/model/godot/Primitives.luau"], +[159290, "src/Rosetta/model/godot/Surface.luau"], +[159775, "src/Rosetta/model/godot/Write.luau"], +[160104, "src/Rosetta/model/iqm/init.luau"], +[160180, "src/Rosetta/model/iqm/Read.luau"], +[160535, "src/Rosetta/model/iqm/Write.luau"], +[161222, "src/Rosetta/model/ldraw/init.luau"], +[161300, "src/Rosetta/model/ldraw/Colors.luau"], +[161618, "src/Rosetta/model/ldraw/Read.luau"], +[162195, "src/Rosetta/model/lwo/init.luau"], +[162271, "src/Rosetta/model/lwo/Build.luau"], +[162733, "src/Rosetta/model/lwo/Parse.luau"], +[163276, "src/Rosetta/model/map/init.luau"], +[163593, "src/Rosetta/model/map/Build.luau"], +[163836, "src/Rosetta/model/map/Parse.luau"], +[164221, "src/Rosetta/model/map/Write.luau"], +[164367, "src/Rosetta/model/mca/init.luau"], +[164709, "src/Rosetta/model/mca/Chunk.luau"], +[164842, "src/Rosetta/model/mca/Lz4Block.luau"], +[164912, "src/Rosetta/model/md2/init.luau"], +[165111, "src/Rosetta/model/md3/init.luau"], +[165339, "src/Rosetta/model/md5/init.luau"], +[165420, "src/Rosetta/model/md5/Read.luau"], +[165853, "src/Rosetta/model/mdl/init.luau"], +[165935, "src/Rosetta/model/mdl/HalfLife.luau"], +[166263, "src/Rosetta/model/mdl/Quake.luau"], +[166481, "src/Rosetta/model/ms3d/init.luau"], +[166553, "src/Rosetta/model/ms3d/Read.luau"], +[166999, "src/Rosetta/model/ms3d/Write.luau"], +[167468, "src/Rosetta/model/obj/init.luau"], +[168210, "src/Rosetta/model/obj/Mtl.luau"], +[168497, "src/Rosetta/model/off/init.luau"], +[168959, "src/Rosetta/model/ply/init.luau"], +[170064, "src/Rosetta/model/ply/Binary.luau"], +[170265, "src/Rosetta/model/pmx/init.luau"], +[170334, "src/Rosetta/model/pmx/Build.luau"], +[170630, "src/Rosetta/model/pmx/Pmd.luau"], +[170965, "src/Rosetta/model/pmx/Read.luau"], +[171369, "src/Rosetta/model/qb/init.luau"], +[171762, "src/Rosetta/model/rbxm/init.luau"], +[172354, "src/Rosetta/model/rbxmx/init.luau"], +[173007, "src/Rosetta/model/robloxmesh/init.luau"], +[173666, "src/Rosetta/model/robloxmesh/Parse.luau"], +[174123, "src/Rosetta/model/robloxmesh/Write.luau"], +[174232, "src/Rosetta/model/schematic/init.luau"], +[174553, "src/Rosetta/model/schematic/Common.luau"], +[174673, "src/Rosetta/model/schematic/Litematic.luau"], +[174884, "src/Rosetta/model/schematic/Mcedit.luau"], +[175128, "src/Rosetta/model/schematic/Sponge.luau"], +[175257, "src/Rosetta/model/smd/init.luau"], +[175324, "src/Rosetta/model/smd/Read.luau"], +[175593, "src/Rosetta/model/smd/Write.luau"], +[175836, "src/Rosetta/model/stl/init.luau"], +[176286, "src/Rosetta/model/stl/Decode.luau"], +[176360, "src/Rosetta/model/t3d/init.luau"], +[176454, "src/Rosetta/model/t3d/Build.luau"], +[176859, "src/Rosetta/model/t3d/Parse.luau"], +[177027, "src/Rosetta/model/usda/init.luau"], +[177236, "src/Rosetta/model/usda/Build.luau"], +[178514, "src/Rosetta/model/usda/Parse.luau"], +[179312, "src/Rosetta/model/usda/Write.luau"], +[180129, "src/Rosetta/model/vox/init.luau"], +[181015, "src/Rosetta/model/vox/Grid.luau"], +[181072, "src/Rosetta/model/vrml/init.luau"], +[181138, "src/Rosetta/model/x/init.luau"], +[181268, "src/Rosetta/model/x/Build.luau"], +[181831, "src/Rosetta/model/x/Parse.luau"], +[182128, "src/Rosetta/model/x3d/init.luau"], +[182206, "src/Rosetta/music/669/init.luau"], +[182412, "src/Rosetta/music/ahx/init.luau"], +[182463, "src/Rosetta/music/far/init.luau"], +[182692, "src/Rosetta/music/hmp/init.luau"], +[182956, "src/Rosetta/music/hvl/init.luau"], +[183007, "src/Rosetta/music/it/init.luau"], +[183425, "src/Rosetta/music/it/Itsex.luau"], +[183541, "src/Rosetta/music/med/init.luau"], +[184188, "src/Rosetta/music/midi/init.luau"], +[184331, "src/Rosetta/music/midi/Smf.luau"], +[184742, "src/Rosetta/music/mod/init.luau"], +[185095, "src/Rosetta/music/mtm/init.luau"], +[185317, "src/Rosetta/music/mus/init.luau"], +[185474, "src/Rosetta/music/okt/init.luau"], +[185755, "src/Rosetta/music/ptm/init.luau"], +[185977, "src/Rosetta/music/s3m/init.luau"], +[186213, "src/Rosetta/music/sf2/init.luau"], +[186256, "src/Rosetta/music/stm/init.luau"], +[186487, "src/Rosetta/music/ult/init.luau"], +[186791, "src/Rosetta/music/umx/init.luau"], +[187007, "src/Rosetta/music/xm/init.luau"], +[187568, "src/Rosetta/music/xmi/init.luau"], +[187776, "src/Rosetta/ops/AudioOps.luau"], +[188225, "src/Rosetta/ops/ImageOps/init.luau"], +[188869, "src/Rosetta/ops/ImageOps/Kernels.luau"], +[189379, "src/Rosetta/ops/LayerOps.luau"], +[189472, "src/Rosetta/ops/MeshOps/init.luau"], +[190508, "src/Rosetta/ops/MeshOps/Greedy.luau"], +[190675, "src/Rosetta/ops/MusicOps.luau"], +[191023, "src/Rosetta/playlist/m3u/init.luau"], +[191376, "src/Rosetta/playlist/pls/init.luau"], +[191554, "src/Rosetta/playlist/xspf/init.luau"], +[191757, "src/Rosetta/subtitle/ass/init.luau"], +[192201, "src/Rosetta/subtitle/srt/init.luau"], +[192374, "src/Rosetta/subtitle/vtt/init.luau"], +[192577, "src/Rosetta/vector/ldtk/init.luau"], +[192669, "src/Rosetta/vector/ldtk/Read.luau"], +[193005, "src/Rosetta/vector/ldtk/Write.luau"], +[193653, "src/Rosetta/vector/ogmo/init.luau"], +[193772, "src/Rosetta/vector/ogmo/Read.luau"], +[194177, "src/Rosetta/vector/ogmo/Write.luau"], +[194531, "src/Rosetta/vector/svg/init.luau"], +[194617, "src/Rosetta/vector/svg/Parse.luau"], +[195363, "src/Rosetta/vector/svg/PathData.luau"], +[195731, "src/Rosetta/vector/svg/Render.luau"], +[196148, "src/Rosetta/vector/svg/Style.luau"], +[196520, "src/Rosetta/vector/svg/Write.luau"], +[196720, "src/Rosetta/vector/tiled/init.luau"], +[196900, "src/Rosetta/vector/tiled/Data.luau"], +[197051, "src/Rosetta/vector/tiled/Tmj.luau"], +[197682, "src/Rosetta/vector/tiled/Tmx.luau"], +[198294, "src/Rosetta/video/avi/init.luau"], +[198588, "src/Rosetta/video/fli/init.luau"], +[198739, "src/Rosetta/video/flv/init.luau"], +[199123, "src/Rosetta/video/flv/Amf.luau"], +[199281, "src/Rosetta/video/flv/Mux.luau"], +[199562, "src/Rosetta/video/h264/init.luau"], +[199701, "src/Rosetta/video/mkv/init.luau"], +[199857, "src/Rosetta/video/mkv/Mux.luau"], +[200136, "src/Rosetta/video/mkv/Parse.luau"], +[200857, "src/Rosetta/video/mp4/init.luau"], +[201185, "src/Rosetta/video/mpegps/init.luau"], +[201372, "src/Rosetta/video/mpegts/init.luau"], +[201610, "src/Rosetta/video/ogv/init.luau"], +[202005, "src/Rosetta/video/smk/init.luau"], +[202314, "src/Rosetta/video/smk/Audio.luau"], +[202434, "src/Rosetta/video/y4m/init.luau"] ] From e6d78a3033d5374c12f33728174b5ae9bb873539 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 20:08:45 -0600 Subject: [PATCH 10/10] docs/guide: index lists Godot, T3D, ASE, Unity packages, .tres, LDtk, Ogmo --- docs/guide/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/guide/README.md b/docs/guide/README.md index cae0420..274acf4 100644 --- a/docs/guide/README.md +++ b/docs/guide/README.md @@ -13,16 +13,16 @@ and the host notes. Each standard type has its own page: | [Audio](audio.md) | `Audio`, `Decoder` | WAV, FLAC, MP3, Ogg Vorbis, Opus, AAC, M4A, AIFF, AU, CAF, VOC, WavPack, APE, TTA, Musepack, AC-3, QOA, ADPCM, ADX, VAG, BRSTM | | [Music](music.md) | `Module`, `Midi` | MOD, S3M, XM, IT, MTM, 669, STM, ULT, OKT, MED, PTM, FAR, UMX, AHX / HVL, MIDI, MUS, XMI, HMP, SoundFont 2 | | [Video](video.md) | `VideoDecoder`, `Demuxer`, `Track`, `Packet` | MP4 / MOV, MKV / WebM, AVI, MPEG-TS / PS, Ogg Theora, FLV, FLI / FLC, Smacker, Y4M, H.264 | -| [3D scenes](scene.md) | `Scene`, `Voxels` | glTF / GLB, OBJ, STL, PLY, FBX, Collada, 3MF, USDA, OFF, VOX, 3DS, MS3D, B3D, LDraw, LWO, .x, IQM, PMX / PMD, VRML, X3D, MD2, MD3, MDL, MD5, BSP, SMD | +| [3D scenes](scene.md) | `Scene`, `Voxels` | glTF / GLB, OBJ, STL, PLY, FBX, Collada, 3MF, USDA, OFF, VOX, 3DS, MS3D, B3D, LDraw, LWO, .x, IQM, PMX / PMD, VRML, X3D, MD2, MD3, MDL, MD5, BSP, SMD, Godot TSCN / ESCN, Unreal T3D, ASE | | [Roblox](roblox.md) | `RbxTree` (`F.Rbx`), `Scene` | rbxm / rbxl, rbxmx / rbxlx, Roblox .mesh | | [CAD](cad.md) | `Cad` (STEP) | STEP (B-rep through a plug-in) | | [Fonts](font.md) | `Font` | TTF / OTF, WOFF, WOFF2, BMFont, BDF, PCF, PSF, FON, Type 1, EOT, Hershey | -| [Archives](archive.md) | `Archive` | zip, tar, gzip, 7z, xz, zstd, Brotli, bzip2, PAK, WAD, GRP, VPK, MPQ, cpio, ar / deb, rpm, .Z, LZ4, ISO 9660, LHA, ARJ, Zoo, uu / yEnc / BinHex / MacBinary / AppleSingle, D64, ADF, FAT, CAB | -| [Data](data.md) | plain values, `XmlNode`, `Date` | JSON, XML, YAML, TOML, CSV, INI, MessagePack, CBOR, plist | +| [Archives](archive.md) | `Archive` | zip, tar, gzip, 7z, xz, zstd, Brotli, bzip2, PAK, WAD, GRP, VPK, MPQ, cpio, ar / deb, rpm, .Z, LZ4, ISO 9660, LHA, ARJ, Zoo, uu / yEnc / BinHex / MacBinary / AppleSingle, D64, ADF, FAT, CAB, Unity packages | +| [Data](data.md) | plain values, `XmlNode`, `Date` | JSON, XML, YAML, TOML, CSV, INI, MessagePack, CBOR, plist, Godot `.tres` | | [Minecraft and voxels](voxel.md) | typed values, `Scene` + `Voxels` | NBT, SNBT, `.schem` / `.schematic` / `.litematic`, Anvil `.mca`, Qubicle `.qb` | | [Vector](vector.md) | `Vector` | SVG | | [Layered images](layered.md) | `Layered` | PSD, Aseprite, OpenRaster | -| [Tile maps](tilemap.md) | `TileMap` | Tiled TMX / TMJ (+ TSX / TSJ tilesets) | +| [Tile maps](tilemap.md) | `TileMap` | Tiled TMX / TMJ (+ TSX / TSJ tilesets), LDtk, Ogmo Editor 3 | | [Subtitles](subtitles.md) | `Subtitles`, `Cue` | SRT, WebVTT, ASS / SSA | | [Playlists](playlist.md) | `Playlist` | M3U / M3U8 (HLS), PLS, XSPF |