From 9fe5f8d658cdfd98b4fdbb937ea250374873519a Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sat, 31 Oct 2026 15:06:55 -0500 Subject: [PATCH] ws-roblox: docs/guide/roblox.md (tested snippets: places, building trees, meshes) + docs_roblox inputs; F.Rbx (codecs/model/Rbx) exported by the api; bench lines (rbxm / rbxmx / robloxmesh); STYLE.md codec list gains Lz4 and Rbx --- docs/API.md | 2 +- docs/STYLE.md | 4 +- docs/guide/README.md | 1 + docs/guide/roblox.md | 94 +++++++++++++++++++++++++++++++++++ src/Formats/init.luau | 2 + tools/bench.luau | 34 +++++++++++++ tools/fixtures/docs_roblox.py | 49 ++++++++++++++++++ 7 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 docs/guide/roblox.md create mode 100644 tools/fixtures/docs_roblox.py diff --git a/docs/API.md b/docs/API.md index 7077b3d..f47905e 100644 --- a/docs/API.md +++ b/docs/API.md @@ -104,4 +104,4 @@ decoders (CELT, VP8, H.264, MPEG-1) outgrow the defaults and fall back to the in ## Also exported `F.Err` (codes `TRUNCATED`, `CORRUPT`, `CHECKSUM`, `UNSUPPORTED`, `LIMIT`, `ARG`, `IO`, `UNKNOWN_FORMAT`), `F.Types` -(the standard types and their constructors), `F.Bytes` (`core/Bytes` Reader / Writer), `F.null`, `F.version`. +(the standard types and their constructors), `F.Bytes` (`core/Bytes` Reader / Writer), `F.Rbx` (the Roblox instance tree of `rbxm` / `rbxmx`: `codecs/model/Rbx`), `F.null`, `F.version`. diff --git a/docs/STYLE.md b/docs/STYLE.md index 46ba287..f720a56 100644 --- a/docs/STYLE.md +++ b/docs/STYLE.md @@ -25,11 +25,11 @@ src/Formats/ vector layered subtitle music playlist containers/ containers (layer 4) Chunks, Riff, IsoBmff, Ebml, Ogg, Zip, Tar, ... codecs// codecs (layer 3) generic algorithms, by domain: - compress/ Deflate Lzma Zstd Brotli Bzip2 Lzw entropy/ Huffman RangeCoder + compress/ Deflate Lzma Zstd Brotli Bzip2 Lzw Lz4 entropy/ Huffman RangeCoder image/ Jpeg Dct Vp8 Vp8L Pixels Yuv Quantize Raster Blend audio/ Opus Vorbis Flac Mpa Aac Alac Mdct Pcm Stream Resample VorbisComment Tracker SoundFont video/ H264 Mpeg1 Video (the video codec registry) text/ Json Xml Text Url - font/ TrueType Cff model/ Mat4 MeshFlatten + font/ TrueType Cff model/ Mat4 MeshFlatten Rbx host/ host (layer 2) runtime adapters; only the api uses them Types.luau types (layer 1) standard types + constructors core/ core (layer 0) Bytes, Bits, Err, Crc32, Adler32, Base64, Md5, diff --git a/docs/guide/README.md b/docs/guide/README.md index d1fff6c..d36c603 100644 --- a/docs/guide/README.md +++ b/docs/guide/README.md @@ -14,6 +14,7 @@ and the host notes. Each standard type has its own page: | [Music](music.md) | `Module`, `Midi` | MOD, S3M, XM, IT, MIDI, SoundFont 2 | | [Video](video.md) | `VideoDecoder`, `Demuxer`, `Track`, `Packet` | MP4 / MOV, MKV / WebM, AVI, MPEG-TS / PS, Y4M, H.264 | | [3D scenes](scene.md) | `Scene`, `Voxels` | glTF / GLB, OBJ, STL, PLY, FBX, Collada, 3MF, USDA, OFF, VOX | +| [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 | | [Archives](archive.md) | `Archive` | zip, tar, gzip, 7z, xz, zstd, Brotli, bzip2 | diff --git a/docs/guide/roblox.md b/docs/guide/roblox.md new file mode 100644 index 0000000..3b1fc85 --- /dev/null +++ b/docs/guide/roblox.md @@ -0,0 +1,94 @@ +# Roblox files + +Roblox models and places (`.rbxm` / `.rbxl` binary, `.rbxmx` / `.rbxlx` XML) load as an **`RbxTree`**: instances +with a class name, a name, typed properties and children. Roblox meshes (`.mesh`) load as an ordinary +[`Scene`](scene.md). This is a file library, not a Roblox runtime. It never creates Instances. A Roblox game that +wants Instances walks the tree itself, and the tree works the same under LuaJIT and the luau CLI. + +```luau +local place = assert(F.load(placeBytes)) -- binary .rbxl -> RbxTree +assert(place.kind == "rbxtree" and place.place) -- a place: the roots are services +for inst, depth in F.Rbx.descendants(place) do + print(string.rep(" ", depth - 1) .. inst.className .. " " .. inst.name) +end +local step = assert(F.Rbx.find(place, "Workspace/Course/Step2")) +local size = F.Rbx.get(step, "size") -- { 4, 1, 4 } (the binary name of Part.Size) +assert(size[1] == 4 and size[2] == 1) +local xml = assert(F.convert(placeBytes, "rbxlx")) -- binary -> XML: both read and write the same tree +assert(F.detect(xml) == "rbxlx" and F.detect(placeBytes) == "rbxl") +``` + +## The tree + +`F.Rbx` (`codecs/model/Rbx`) holds the type and its helpers: + +| Field / call | Meaning | +|---|---| +| `tree.roots` | the top-level instances (the services of a place) | +| `tree.place` | true for `.rbxl` / `.rbxlx` (services); saving to `rbxl` sets it | +| `tree.metadata` | the file's META entries (`ExplicitAutoJoints`, ...) | +| `inst.className`, `inst.name`, `inst.children`, `inst.parent` | the hierarchy. `Name` is `inst.name`, not a property | +| `inst.properties[name]` | `{ type = "Vector3", value = { x, y, z } }` | +| `F.Rbx.tree()`, `instance(class, name)`, `add(parent, child)` | build trees | +| `set(inst, name, type, value)`, `get(inst, name)` | properties | +| `find(root, "A/B/C")`, `descendants(root)`, `list(tree)`, `fullName(inst)` | lookups | + +Property values keep the file's type, because a number alone could be an `Int32`, a `Float32` or an `Enum`. Arrays +follow the argument order of the Roblox constructors, so `Vector3.new(table.unpack(v.value))` and +`CFrame.new(table.unpack(v.value))` rebuild them in a game. The full list is in the header of +`src/Formats/codecs/model/Rbx/init.luau`: + +- **Text and numbers:** `String`, `BinaryString`, `ProtectedString`, `ContentId`, `SharedString` are strings. + `Bool`, `Int32`, `Int64`, `Float32`, `Float64`, `Enum`, `BrickColor`, `Faces` and `Axes` are numbers and booleans. +- **Arrays:** `Vector2`, `Vector3` and `Color3` (0..1) are arrays. `CFrame` is 12 numbers: the position, then the + rotation row by row. +- **References:** `Ref` and the object form of `Content` hold the instance itself. `Content` is otherwise a URI string, + or nil. +- **Unknown data** is kept, not dropped: properties of unknown types (`Raw` in binary files, `XmlRaw` in XML) and unknown + chunks are written back unchanged. + +Property names are the ones the file stores. Binary files use a few serialized names, for example `size` for +`Part.Size` and `Color3uint8` for `Part.Color`. Without Roblox's reflection database, the library does not rename +them. + +```luau +local tree = F.Rbx.tree() +local model = F.Rbx.add(tree, F.Rbx.instance("Model", "Tower")) +for i = 1, 3 do + local part = F.Rbx.add(model, F.Rbx.instance("Part", "Floor" .. i)) + F.Rbx.set(part, "size", "Vector3", { 8, 1, 8 }) + F.Rbx.set(part, "CFrame", "CFrame", { 0, i * 4, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 }) + F.Rbx.set(part, "Anchored", "Bool", true) +end +F.Rbx.set(model, "PrimaryPart", "Ref", model.children[1]) +local rbxm = assert(F.save(tree, nil, { format = "rbxm" })) -- LZ4 chunks; { compression = "none" } writes them raw +local back = assert(F.load(rbxm)) +assert(F.Rbx.get(back.roots[1], "PrimaryPart") == back.roots[1].children[1]) +local text = buffer.tostring(assert(F.save(back, nil, { format = "rbxmx" }))) +assert(string.find(text, '