5.2 KiB
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. 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.
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/Rosetta/codecs/model/Rbx/init.luau:
- Text and numbers:
String,BinaryString,ProtectedString,ContentId,SharedStringare strings.Bool,Int32,Int64,Float32,Float64,Enum,BrickColor,FacesandAxesare numbers and booleans. - Arrays:
Vector2,Vector3andColor3(0..1) are arrays.CFrameis 12 numbers: the position, then the rotation row by row. - References:
Refand the object form ofContenthold the instance itself.Contentis otherwise a URI string, or nil. - Unknown data is kept, not dropped: properties of unknown types (
Rawin binary files,XmlRawin 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.
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,TANGENTandCOLOR_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. - Draco: a Draco-compressed core mesh (6.00 / 7.00) decodes through
codecs/model/Draco;meta.source.dracoistruefor those files.
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.