merge ws/3d3-b (model/lwo, model/x, model/iqm, codecs/model/Sampler; brings ws/game af4488d for codecs/model/Rig)

This commit is contained in:
4DBug committed 2026-10-31 15:02:25 -05:00
commit 44cda7256c
29 files changed
+5664 -4

No files matched your search

+6
View File
@@ -40,7 +40,9 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| model | dae | .dae .zae | yes | yes | materials: true, polygons: true, skins: true, morphTargets: true, animation: true, cameras: true, lights: true, zae: true | `tests/model/dae.luau` |
| model | fbx | .fbx | yes | yes | binary: true, ascii: true, materials: true, animation: true, skins: true, morphTargets: true, cameras: true, lights: true, polygons: true | `tests/model/fbx.luau` |
| model | gltf | .gltf .glb | yes | yes | binary: true, materials: true, animation: true, skins: true, morphTargets: true, cameras: true, lights: true, draco: true | `tests/model/gltf.luau` |
| model | iqm | .iqm | yes | yes | materials: true, skins: true, animation: true, vertexColors: true | `tests/model/iqm.luau` |
| model | ldraw | .ldr .mpd .dat | yes | - | materials: true, lines: true, instancing: true | `tests/model/ldraw.luau` |
| model | lwo | .lwo .lxo | yes | - | materials: true, polygons: true, vertexColors: true, morphTargets: true | `tests/model/lwo.luau` |
| model | ms3d | .ms3d | yes | yes | materials: true, skins: true, animation: true | `tests/model/ms3d.luau` |
| model | obj | .obj | yes | yes | materials: true, polygons: true, vertexColors: true | `tests/model/obj.luau` |
| model | off | .off | yes | yes | polygons: true, points: true, colors: true, binary: false | `tests/model/off.luau` |
@@ -48,6 +50,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| model | stl | .stl | yes | yes | ascii: true, binary: true, colors: true, indexed: false | `tests/model/stl.luau` |
| model | usda | .usda .usd .usdz | yes | yes | materials: true, animation: true, cameras: true, lights: true, polygons: true, vertexColors: true, usdz: "read", usdc: false | `tests/model/usda.luau` |
| model | vox | .vox | yes | yes | voxels: true, sceneGraph: true, materials: true | `tests/model/vox.luau` |
| model | x | .x | yes | - | text: true, binary: true, compressed: true, materials: true, skins: true, animation: true, polygons: true, vertexColors: true | `tests/model/x.luau` |
| cad | step | .step .stp .p21 | yes | yes | complexEntities: true, sections: true, brep: "plugin", tessellate: "plugin" | `tests/cad/step.luau` |
| font | bmfont | .fnt | yes | yes | bitmap: true, variants: "text", "xml", "binary", extraFiles: true | `tests/font/bmfont.luau` |
| font | ttf | .ttf .otf .ttc .otc | yes | - | outlines: "truetype", "cff", collection: true, kerning: true | `tests/font/ttf.luau` |
@@ -57,6 +60,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| archive | br | .br | yes | - | stream: true | `tests/archive/br.luau` |
| archive | bz2 | .bz2 .tbz2 .tbz | yes | - | stream: true | `tests/archive/bz2.luau` |
| archive | gzip | .gz .tgz .gzip | yes | yes | stream: true | `tests/archive/gzip.luau` |
| archive | pak | .pak .sin | yes | yes | variants: "quake", "sin" | `tests/archive/pak.luau` |
| archive | tar | .tar | yes | yes | variants: "ustar", "pax", "gnu" | `tests/archive/tar.luau` |
| archive | xz | .xz .txz .lzma | yes | - | stream: true, filters: "lzma2", "lzma", "delta", "x86", "powerpc", "arm", "armthumb", "sparc", "arm64" | `tests/archive/xz.luau` |
| archive | zip | .zip .wsz | yes | yes | methods: "store", "deflate", zip64: true | `tests/archive/zip.luau` |
@@ -131,6 +135,8 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
- codecs/model/Draco: Google Draco geometry decompression (.drc; glTF KHR_draco_mesh_compression; Roblox mesh v6 / v7).
- codecs/model/Mat4: 4x4 matrix and quaternion helpers for the model formats: column-major flat arrays of 16
- codecs/model/MeshFlatten: a Scene to one world-space mesh, for the writers of mesh-only formats (STL, PLY, OFF). Walks
- codecs/model/Rig: the Scene mapping shared by game model formats (MD2 / MD3 / MDL / MD5 / SMD / ...), so each
- codecs/model/Sampler: evaluates Scene animation channels at any time (STEP, LINEAR with quaternion slerp for
- **text**
- codecs/text/Json: JSON (RFC 8259 / ECMA-404) parse and serialize, the engine data/json, glTF, TMJ, ... use. New code.
- codecs/text/Text: text decoding helpers for the text formats: a UTF-8 BOM is stripped, text that is not valid UTF-8 is
+84 -4
View File
@@ -1,9 +1,9 @@
# Scene (3D models) and Voxels
Every model format (glTF / GLB, OBJ, STL, PLY, OFF, FBX, Collada, 3MF, USDA, VOX, 3DS, MS3D, B3D, LDraw) loads as one
`Scene`, a structure shaped like glTF 2.0: a node tree, meshes made of primitives, flat attribute buffers (accessors),
PBR materials, textures, cameras, lights, skins and animations. Mesh-only formats (STL, PLY, OFF) give a one-node scene. MagicaVoxel
files also carry voxel grids (`scene.voxels`). Editing goes through `F.ops.mesh`.
Every model format (glTF / GLB, OBJ, STL, PLY, OFF, FBX, Collada, 3MF, USDA, VOX, 3DS, MS3D, B3D, LDraw, LightWave
LWO, DirectX .x, IQM) loads as one `Scene`, a structure shaped like glTF 2.0: a node tree, meshes made of primitives,
flat attribute buffers (accessors), PBR materials, textures, cameras, lights, skins and animations. Mesh-only formats
(STL, PLY, OFF) give a one-node scene. MagicaVoxel files also carry voxel grids (`scene.voxels`). Editing goes through `F.ops.mesh`.
```luau
local scene = assert(F.model.load(texturedGltfText))
@@ -529,6 +529,83 @@ assert(prim.attributes.JOINTS_0 and prim.attributes.NORMAL)
assert(back.animations[1].channels[1].path == "rotation")
```
## LightWave, DirectX and Inter-Quake models
**LightWave objects** (`.lwo`: LWO2 and the older LWOB; Modo's `.lxo`) give one node per layer (its pivot as the
translation, parents by layer index), one mesh per layer and one primitive per surface. LightWave is left-handed: z is
negated and the winding reversed on load, so the scene is glTF's right-handed y up. UV maps become `TEXCOORD_n` (one
set per map name), the colour map a surface names becomes `COLOR_0`, weight maps `_WEIGHT_n` and morph maps morph
targets (names in `prim.extras.lwo.maps` / `mesh.extras.targetNames`). Surface values and texture blocks are in
`material.extras.lwo`; image textures keep only the file name as `uri` (`F.model.loadTextures` reads them). Subdivision
cages (`PTCH` / `SUBD`) stay polygons with `prim.extras.lwo.subdivision = true`.
```luau
-- a one-triangle LWO2 file, built by hand (IFF chunks, big-endian)
local function be(n, bytes)
local s = ""
for i = bytes - 1, 0, -1 do
s ..= string.char(bit32.band(bit32.rshift(n, i * 8), 255))
end
return s
end
local function f4(x)
local b = buffer.create(4)
buffer.writef32(b, 0, x)
return be(buffer.readu32(b, 0), 4)
end
local function chunk(id, body)
return id .. be(#body, 4) .. body
end
local body = "LWO2" .. chunk("TAGS", "Red\0") .. chunk("LAYR", be(0, 4) .. f4(0) .. f4(0) .. f4(0) .. "Body\0\0")
.. chunk("PNTS", f4(0) .. f4(0) .. f4(0) .. f4(1) .. f4(0) .. f4(0) .. f4(0) .. f4(1) .. f4(0))
.. chunk("POLS", "FACE" .. be(3, 2) .. be(0, 2) .. be(1, 2) .. be(2, 2))
.. chunk("PTAG", "SURF" .. be(0, 4))
.. chunk("SURF", "Red\0\0\0" .. "COLR" .. be(14, 2) .. f4(1) .. f4(0) .. f4(0) .. be(0, 2))
local scene = assert(F.load("FORM" .. be(#body, 4) .. body))
assert(scene.nodes[1].name == "Body" and scene.meta.source.version == "LWO2")
assert(scene.materials[1].name == "Red" and scene.materials[1].baseColor[1] == 1)
assert(scene.meshes[1].primitives[1].indices.count == 3)
```
**DirectX `.x`** files (text, binary and MSZIP-compressed, 32- or 64-bit floats) give the frame hierarchy, one primitive
per material, materials with their texture file names, skins (`SkinWeights`) and animation sets. Direct3D is
left-handed too: z is negated and the winding reversed. Key times are in seconds (`AnimTicksPerSecond`, default 4800).
```luau
local text = [[xof 0303txt 0032
Material Wood { 0.8; 0.6; 0.4; 1.0;; 20.0; 0.1; 0.1; 0.1;; 0.0; 0.0; 0.0;; TextureFilename { "wood.png"; } }
Frame Root {
FrameTransformMatrix { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,5,1;; }
Mesh Tri { 3; 0;0;0;, 1;0;0;, 0;1;0;; 1; 3;0,1,2;; MeshMaterialList { 1; 1; 0;; { Wood } } }
}
]]
local scene = assert(F.load(text, { format = "x" }))
local root = scene.nodes[1]
assert(root.name == "Root" and root.translation[3] == -5) -- z negated
assert(scene.materials[1].name == "Wood")
assert(scene.textures[scene.materials[1].baseColorTexture.texture].uri == "wood.png")
local glb = assert(F.save(scene, nil, { format = "glb" }))
```
**IQM** (Inter-Quake Model, version 2) reads and writes meshes, every vertex array, the skeleton (a node per joint and
one skin), animations (dequantized frames as translation / rotation / scale channels, loop flags and frame ranges in
`meta.source.animations`) and per-frame bounds. IQM is z-up (`meta.up = "z"`); nothing is rotated either way. The
writer turns any Scene's triangles into IQM meshes, merges the skins into one skeleton and samples each animation at
its key spacing when uniform (else `opts.framerate`, default 30 frames per second).
```luau
local S = F.Types.Scene
local pos = S.accessor(nil, "f32", 3, 3)
for i, v in { 0, 0, 0, 1, 0, 0, 0, 1, 0 } do
buffer.writef32(pos.data, (i - 1) * 4, v)
end
local scene = S.fromPrimitive({ attributes = { POSITION = pos }, mode = "triangles" }, "tri")
local iqm = assert(F.save(scene, nil, { format = "iqm" }))
local back = assert(F.load(iqm))
assert(back.meta.source.format == "iqm" and back.meshes[1].name == "tri")
assert(back.meshes[1].primitives[1].indices.count == 3)
```
## Formats
| Format | Read | Write | Notes |
@@ -547,6 +624,9 @@ assert(back.animations[1].channels[1].path == "rotation")
| LDraw (LDR / DAT / MPD) | yes | | parts as shared meshes per colour, sub-models as nodes, BFC, LDConfig colours, `files` / `resolve` for the library |
| 3DS | yes | yes | keyframer hierarchy and animation, Phong materials, texture names, cameras, lights; Z up |
| MS3D (MilkShape 3D) | yes | yes | groups, materials, joints -> skin + animation, comments |
| LightWave LWO (LWO2, LWOB, Modo LXOB) | yes | | layers, vertex maps, surfaces; see below |
| DirectX .x (text, binary, MSZIP) | yes | | frames, materials, skins, animation |
| IQM (Inter-Quake Model) | yes | yes | skeleton, skin, sampled animations, bounds |
| STEP | via the CAD plug-in | | see [cad.md](cad.md) |
Capabilities per format: [FORMATS.md](../FORMATS.md).