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:
1 parent
225a9b081e
commit
e8c9a4a092
7 files changed
+183
-3
No files matched your search
+1
-1
@@ -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
@@ -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,
|
||||
|
||||
@@ -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 |
|
||||
|
||||
@@ -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.
|
||||
@@ -22,6 +22,7 @@ local Types = require("@formats/Types")
|
||||
local Registry = require("@formats/Registry")
|
||||
local Video = require("@formats/codecs/video/Video")
|
||||
local AudioWrap = require("@formats/containers/AudioWrap")
|
||||
local Rbx = require("@formats/codecs/model/Rbx")
|
||||
local ImageOps = require("@formats/ops/ImageOps")
|
||||
local host = require("@formats/host")
|
||||
|
||||
@@ -31,6 +32,7 @@ F.version = "0.1.0"
|
||||
F.Err = Err
|
||||
F.Types = Types
|
||||
F.Bytes = Bytes
|
||||
F.Rbx = Rbx -- the Roblox instance tree helpers (codecs/model/Rbx: tree, instance, add, set, get, find, descendants)
|
||||
F.null = Types.null
|
||||
F.host = host
|
||||
F.plugins = {} :: { [string]: any } -- injected optional dependencies (plugins.brep for cad/step)
|
||||
|
||||
@@ -249,6 +249,40 @@ do
|
||||
Lz4.compress(raw)
|
||||
end)
|
||||
end
|
||||
-- ws-roblox: a model of 20000 parts (built here) through model/rbxm and model/rbxmx, and a .mesh decode
|
||||
do
|
||||
local Rbx = require("@formats/codecs/model/Rbx")
|
||||
local Rbxm = require("@formats/model/rbxm")
|
||||
local Rbxmx = require("@formats/model/rbxmx")
|
||||
local RobloxMesh = require("@formats/model/robloxmesh")
|
||||
local tree = Rbx.tree()
|
||||
local folder = Rbx.add(tree, Rbx.instance("Folder", "Parts"))
|
||||
for i = 1, 20000 do
|
||||
local p = Rbx.add(folder, Rbx.instance("Part", "P" .. i))
|
||||
Rbx.set(p, "CFrame", "CFrame", { i, i % 7, -i, 1, 0, 0, 0, 1, 0, 0, 0, 1 })
|
||||
Rbx.set(p, "size", "Vector3", { 4, 1, 2 + i % 3 })
|
||||
Rbx.set(p, "Color3uint8", "Color3uint8", { i % 256, 128, 255 - i % 256 })
|
||||
Rbx.set(p, "Anchored", "Bool", i % 2 == 0)
|
||||
Rbx.set(p, "Transparency", "Float32", (i % 4) / 4)
|
||||
Rbx.set(p, "Material", "Enum", 256)
|
||||
end
|
||||
local bin = Rbxm.encode(tree) :: buffer
|
||||
local xml = Rbxmx.encode(tree) :: buffer
|
||||
bench("rbxm decode (20k parts)", 3, buffer.len(bin), function()
|
||||
Rbxm.decode(Bytes.reader(bin))
|
||||
end)
|
||||
bench("rbxm encode (20k parts)", 3, buffer.len(bin), function()
|
||||
Rbxm.encode(tree)
|
||||
end)
|
||||
bench("rbxmx decode (20k parts)", 3, buffer.len(xml), function()
|
||||
Rbxmx.decode(Bytes.reader(xml))
|
||||
end)
|
||||
local M = require("@tests/gen/robloxmesh")
|
||||
local mesh = buffer.fromstring(M.cases[#M.cases - 1].data)
|
||||
bench("robloxmesh decode (v7, skinned)", 20, buffer.len(mesh), function()
|
||||
RobloxMesh.decode(Bytes.reader(mesh))
|
||||
end)
|
||||
end
|
||||
do
|
||||
local Brotli = require("@formats/codecs/compress/Brotli")
|
||||
local BB = require("@tests/gen/brotli_bench")
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
# Docs inputs for the Roblox guide page (tools/fixtures.py, tools/docs_check.py): a small place built by rojo 7.7 as
|
||||
# .rbxl (binary) and .rbxlx (XML), and a skinned version 4.00 .mesh written by tools/fixtures/robloxmesh.py's spec
|
||||
# writer.
|
||||
# tests/gen/docs_roblox.luau { files = { [name] = bytes }, vars = { placeBytes, placeText, meshBytes } }
|
||||
import importlib.util, json, os, random, shutil, tempfile
|
||||
|
||||
INPUTS = ["tools/docs_check.py", "tools/fixtures/robloxmesh.py"]
|
||||
|
||||
PLACE = {"name": "Obby", "tree": {
|
||||
"$className": "DataModel",
|
||||
"Workspace": {"$className": "Workspace",
|
||||
"Spawn": {"$className": "SpawnLocation", "$properties": {"Size": [6, 1, 6], "Anchored": True}},
|
||||
"Course": {"$className": "Model",
|
||||
"Step1": {"$className": "Part", "$properties": {"Size": [4, 1, 4], "Position": [0, 4, 10], "Anchored": True, "Color": [1, 0, 0]}},
|
||||
"Step2": {"$className": "Part", "$properties": {"Size": [4, 1, 4], "Position": [0, 8, 20], "Anchored": True, "Color": [0, 1, 0]}}}},
|
||||
"Lighting": {"$className": "Lighting", "$properties": {"ClockTime": 14}},
|
||||
"ServerScriptService": {"$className": "ServerScriptService",
|
||||
"Main": {"$className": "Script", "$properties": {"Source": "print(\"hello from the obby\")\n"}}},
|
||||
}}
|
||||
|
||||
|
||||
def load(ctx, name):
|
||||
spec = importlib.util.spec_from_file_location("docs_roblox_" + name, os.path.join(ctx.root, "tools", *name.split("/")))
|
||||
m = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(m)
|
||||
return m
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
dc = load(ctx, "docs_check.py")
|
||||
mesh = load(ctx, "fixtures/robloxmesh.py")
|
||||
tmp = tempfile.mkdtemp(prefix="formats-docs-roblox-")
|
||||
try:
|
||||
proj = os.path.join(tmp, "place.project.json")
|
||||
with open(proj, "w") as f:
|
||||
json.dump(PLACE, f)
|
||||
files = {}
|
||||
for out in ("obby.rbxl", "obby.rbxlx"):
|
||||
ctx.nix("rojo", ["rojo", "build", proj, "-o", os.path.join(tmp, out)])
|
||||
with open(os.path.join(tmp, out), "rb") as f:
|
||||
files[out] = f.read()
|
||||
finally:
|
||||
shutil.rmtree(tmp, ignore_errors=True)
|
||||
rng = random.Random(5)
|
||||
sv, sf = mesh.sphere(rng, 6, 10)
|
||||
bones = mesh.make_bones(rng, 4)
|
||||
nv, nf, subs, env, _, _ = mesh.make_skin(rng, sv, sf, bones, segs=10)
|
||||
files["blob.mesh"], _ = mesh.write_v45("4.00", nv, nf, [0, len(nf)], bones, subs, env)
|
||||
dc.emit_inputs(ctx, files, {"placeBytes": "obby.rbxl", "placeText": "obby.rbxlx", "meshBytes": "blob.mesh"})
|
||||
Reference in new issue
Block a user