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 3a1965486f
commit 9fe5f8d658
7 files changed
+183 -3

No files matched your search

+34
View File
@@ -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")
+49
View File
@@ -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"})