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

This commit is contained in:
4DBug committed 2026-10-31 15:06:55 -05:00
1 parent 225a9b081e
commit e8c9a4a092
7 files changed
+183 -3

No files matched your search

+1 -1
View File
@@ -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`.
+2 -2
View File
@@ -25,11 +25,11 @@ src/Formats/
vector layered subtitle music playlist
containers/ containers (layer 4) Chunks, Riff, IsoBmff, Ebml, Ogg, Zip, Tar, ...
codecs/<domain>/<Name> 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,
+1
View File
@@ -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 |
+94
View File
@@ -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, '<Item class="Part"', 1, true))
```
Binary files store one value per instance of a class. When only some Parts have a property, the writer fills in the
type's default for the rest, as Roblox does.
## Meshes
A `.mesh` of any version from 1.00 to 7.00 loads as a one-mesh `Scene`:
- **Attributes:** `POSITION`, `NORMAL`, `TEXCOORD_0`, `TANGENT` and `COLOR_0`.
- **LODs:** LOD 0 is the primitive. The other LODs are in `mesh.extras.lods`.
- **Skinning:** bones become a skin with joint nodes, and the vertices get `JOINTS_0` / `WEIGHTS_0`.
- **Not decoded yet:** Draco-compressed meshes (7.00) return `UNSUPPORTED`.
```luau
local scene = assert(F.load(meshBytes, { format = "robloxmesh" }))
local prim = scene.meshes[1].primitives[1]
assert(prim.attributes.JOINTS_0 and #scene.skins[1].joints == 4)
local glb = assert(F.save(scene, nil, { format = "glb" })) -- to glTF, skin included
local v2 = assert(F.save(scene, nil, { format = "robloxmesh" })) -- version 2.00: geometry only
local v4 = assert(F.save(scene, nil, { format = "robloxmesh", version = "4.00" })) -- bones, skinning, LODs
assert(buffer.readstring(v4, 0, 12) == "version 4.00")
```
Any scene can be saved as a mesh, for example a glTF: every primitive goes in, in world space. Version 4.00 also
writes the scene's first skin, splitting it into subsets of at most 26 bones as Roblox requires.