merge ws/3d3-d (model/b3d, model/ldraw)
This commit is contained in:
commit
de2695b87d
14 files changed
+2843
-1
No files matched your search
@@ -35,9 +35,11 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| video | mpegts | .ts .m2ts .mts .tsv | yes | - | streaming: true, video: "mpeg1", "h264", audio: true | `tests/video/mpegts.luau` |
|
||||
| video | y4m | .y4m | yes | yes | streaming: true, video: "rawvideo", depths: 8, 10, 12, 16 | `tests/video/y4m.luau` |
|
||||
| model | 3mf | .3mf | yes | yes | materials: true, vertexColors: true, textures: true, units: true | `tests/model/3mf.luau` |
|
||||
| model | b3d | .b3d | yes | - | materials: true, textures: true, skins: true, animation: true, colors: true | `tests/model/b3d.luau` |
|
||||
| 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 | ldraw | .ldr .mpd .dat | yes | - | materials: true, lines: true, instancing: true | `tests/model/ldraw.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` |
|
||||
| model | ply | .ply | yes | yes | ascii: true, binary: true, polygons: true, points: true, colors: true | `tests/model/ply.luau` |
|
||||
|
||||
+75
-1
@@ -1,6 +1,6 @@
|
||||
# Scene (3D models) and Voxels
|
||||
|
||||
Every model format (glTF / GLB, OBJ, STL, PLY, OFF, FBX, Collada, 3MF, USDA, VOX) loads as one `Scene`, a structure
|
||||
Every model format (glTF / GLB, OBJ, STL, PLY, OFF, FBX, Collada, 3MF, USDA, VOX, 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`.
|
||||
@@ -397,6 +397,78 @@ local vox = assert(F.save(grid, nil, { format = "vox" })) -- a grid alone saves
|
||||
assert(F.load(vox).voxels[1].size[1] == 4)
|
||||
```
|
||||
|
||||
## Blitz3D (B3D)
|
||||
|
||||
`.b3d` files (Blitz3D, also written by many old game tools) load read-only. The node tree keeps its names and TRS;
|
||||
each `MESH` becomes one mesh whose primitives (one per `TRIS` chunk) share the vertex accessors; brushes become
|
||||
materials (colour, alpha, shininess, the first texture as `baseColorTexture` with its position / scale / rotation as
|
||||
`transform`, the full brush in `extras.b3d`); `BONE` weights become a skin (the 4 strongest weights per vertex) and
|
||||
`KEYS` + `ANIM` one animation sampled at `frame / fps`. Texture files come through `files` / `resolve` like any other
|
||||
model's (by the stored path, then by its base name: B3D files often store absolute Windows paths).
|
||||
|
||||
Blitz3D is **left-handed**: the reader mirrors z (and turns the triangle winding and rotations to match), so the scene
|
||||
is glTF's right-handed Y-up with the model looking as it did in Blitz3D. `meta.source.handedness = "left"` records
|
||||
the origin, `meta.source.fps` / `frames` the `ANIM` chunk.
|
||||
|
||||
## LDraw
|
||||
|
||||
LDraw files (`.ldr` models, `.dat` parts, `.mpd` multi-part files) load read-only. Every reference to a **part**
|
||||
becomes a node with the reference's matrix, and each part is baked once per colour into a mesh those nodes share;
|
||||
**sub-models** (`.ldr` / `.mpd` files, MPD sections that are not parts) become nodes with children. Colour 16 takes the
|
||||
colour of the reference above it, 24 its edge colour; codes come from the LDConfig.ldr table built in (one material per
|
||||
colour, `extras.ldraw.code` / `name`), `0x2RRGGBB` is a direct colour. BFC (`CERTIFY`, `CW` / `CCW`, `INVERTNEXT`,
|
||||
`NOCLIP`) turns every face counter-clockwise; faces of uncertified parts get double-sided materials. Edge lines (type 2)
|
||||
are `"lines"` primitives (`lines = false` drops them); optional lines only on request (`optionalLines = true`).
|
||||
|
||||
```luau
|
||||
local mpd = [[
|
||||
0 FILE house.ldr
|
||||
1 4 0 0 0 1 0 0 0 1 0 0 0 1 wall.dat
|
||||
1 4 50 0 0 1 0 0 0 1 0 0 0 1 wall.dat
|
||||
1 1 0 -30 0 1 0 0 0 1 0 0 0 1 roof.dat
|
||||
0 FILE wall.dat
|
||||
0 !LDRAW_ORG Unofficial_Part
|
||||
0 BFC CERTIFY CCW
|
||||
4 16 -10 0 -10 10 0 -10 10 0 10 -10 0 10
|
||||
2 24 -10 0 -10 10 0 -10
|
||||
0 FILE roof.dat
|
||||
0 BFC CERTIFY CCW
|
||||
3 16 0 -10 0 10 0 0 -10 0 0
|
||||
]]
|
||||
local scene = assert(F.model.load(mpd, { format = "ldraw" }))
|
||||
print(#scene.meshes) -- 2: wall.dat in red (both walls share it), roof.dat in blue
|
||||
local root = scene.nodes[scene.roots[1]] -- "LDraw": turns LDraw's -Y up into Y up
|
||||
local a, b = scene.nodes[root.children[1]], scene.nodes[root.children[2]]
|
||||
assert(a.mesh == b.mesh and b.matrix[13] == 50)
|
||||
local red = scene.materials[scene.meshes[a.mesh].primitives[1].material]
|
||||
print(red.name, red.extras.ldraw.code) -- Red 4
|
||||
assert(scene.meta.up == "y" and scene.meta.unit == 0.0004) -- 1 LDU = 0.4 mm
|
||||
```
|
||||
|
||||
Parts and primitives that are not in the file come through `files` or `resolve`, asked for by their LDraw library
|
||||
path: the name as written (backslashes turned into slashes), then in lower case, under `""`, `parts/`, `p/`,
|
||||
`parts/s/` and `models/`. Point `resolve` at an LDraw library folder to load real models; missing files are skipped and
|
||||
listed in `meta.source.missing`:
|
||||
|
||||
```luau
|
||||
local library = {
|
||||
["p/box.dat"] = "0 BFC CERTIFY CCW\n4 16 -1 -1 -1 1 -1 -1 1 -1 1 -1 -1 1\n4 16 -1 1 -1 -1 1 1 1 1 1 1 1 -1\n",
|
||||
["parts/plate.dat"] = "0 !LDRAW_ORG Part\n1 16 0 4 0 20 0 0 0 4 0 0 0 10 box.dat\n",
|
||||
}
|
||||
local model = "0 two plates\n1 14 0 0 0 1 0 0 0 1 0 0 0 1 plate.dat\n1 0x2FF8000 0 -8 0 1 0 0 0 1 0 0 0 1 plate.dat\n"
|
||||
.. "1 4 0 -16 0 1 0 0 0 1 0 0 0 1 3001.dat\n"
|
||||
local scene = assert(F.model.load(model, { format = "ldraw", files = library }))
|
||||
assert(#scene.meshes == 2 and scene.meta.source.missing[1] == "3001.dat")
|
||||
local same = assert(F.model.load(model, { format = "ldraw", resolve = function(path)
|
||||
return library[path] -- or: read ldrawFolder .. "/" .. path
|
||||
end }))
|
||||
local flat = assert(F.model.load(model, { format = "ldraw", files = library, flatten = true }))
|
||||
assert(#flat.meshes == 1) -- one mesh, one primitive per colour
|
||||
```
|
||||
|
||||
`upright = false` leaves out the root node (LDraw's axes as stored, `meta.source.up = "-y"`); `ldconfig` takes the
|
||||
text of another LDConfig.ldr, and `color` the colour of code 16 at the top (default 16, "Main_Colour").
|
||||
|
||||
## Formats
|
||||
|
||||
| Format | Read | Write | Notes |
|
||||
@@ -411,6 +483,8 @@ assert(F.load(vox).voxels[1].size[1] == 4)
|
||||
| 3MF | yes | yes | |
|
||||
| USDA (+ USDZ read) | yes | yes | |
|
||||
| VOX | yes | yes | voxel grids, scene graph, materials |
|
||||
| B3D (Blitz3D) | yes | | brushes, textures, skins, keyframe animation; left-handed source mirrored to glTF's frame |
|
||||
| LDraw (LDR / DAT / MPD) | yes | | parts as shared meshes per colour, sub-models as nodes, BFC, LDConfig colours, `files` / `resolve` for the library |
|
||||
| STEP | via the CAD plug-in | | see [cad.md](cad.md) |
|
||||
|
||||
Capabilities per format: [FORMATS.md](../FORMATS.md).
|
||||
|
||||
Reference in new issue
Block a user