merge ws/3d3-c (model/pmx, model/vrml, model/x3d, codecs/model/Vrml); README model list

This commit is contained in:
4DBug committed 2026-10-31 15:29:37 -05:00
commit 94783a86d1
29 files changed
+6735 -6

No files matched your search

+4
View File
@@ -48,6 +48,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| 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` |
| model | pmx | .pmx .pmd | yes | - | materials: true, skins: true, morphTargets: true, pmd: true | `tests/model/pmx.luau` |
| model | qb | .qb | yes | yes | voxels: true, truecolor: true | `tests/model/qb.luau` |
| model | rbxm | .rbxm .rbxl | yes | yes | tree: true, compression: "none", "lz4", "zstd" | `tests/model/rbxm.luau` |
| model | rbxmx | .rbxmx .rbxlx | yes | yes | tree: true | `tests/model/rbxmx.luau` |
@@ -56,7 +57,9 @@ 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 | vrml | .wrl .wrz .vrml | yes | yes | materials: true, polygons: true, animation: true, cameras: true, lights: true, lines: true, points: true | `tests/model/vrml.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` |
| model | x3d | .x3d .x3dv .x3dz .x3dvz .x3db | yes | yes | materials: true, polygons: true, animation: true, cameras: true, lights: true, lines: true, points: true, xml: true, classic: true | `tests/model/x3d.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` |
@@ -148,6 +151,7 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
- codecs/model/Rbx: the Roblox instance tree every Roblox file format maps to (model/rbxm binary rbxm / rbxl,
- 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
- codecs/model/Vrml: the VRML97 / X3D scene-graph engine shared by model/vrml (.wrl) and model/x3d (.x3d XML,
- **text**
- codecs/text/Json: JSON (RFC 8259 / ECMA-404) parse and serialize, the engine data/json, glTF, TMJ, ... use. New code.
- codecs/text/Nbt: Minecraft's Named Binary Tag format and its text form SNBT, the engine data/nbt, data/snbt,
+63 -5
View File
@@ -1,10 +1,10 @@
# Scene (3D models) and Voxels
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`.
LWO, DirectX .x, IQM, PMX / PMD, VRML, X3D) 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))
@@ -310,7 +310,8 @@ the binary container.
| glTF | `external = true` writes `<name>.bin` and the images into `opts.files` (default: embedded `data:` URIs) | `binary`, `external`, `name` |
| OBJ | `<name>.mtl` and texture files into `opts.files` | `name`, `mtlName`, `normals`, `texcoords`, `colors`, `flipV` |
| STL | | `ascii = true` (default binary), `normals = "attribute"` |
| PLY, OFF, FBX, DAE, 3MF, USDA, VOX, 3DS, MS3D | see [FORMATS.md](../FORMATS.md) and the format's options | |
| PLY, OFF, FBX, DAE, 3MF, USDA, VOX, 3DS, MS3D, IQM | see [FORMATS.md](../FORMATS.md) and the format's options | |
| VRML, X3D | texture images into `opts.files` (else `url` = the texture's uri) | `name`, `flipV`; X3D `encoding = "x3dv"` (or a `.x3dv` destination) for the classic encoding |
Mesh-only writers (STL, PLY, OFF, OBJ) bake the node transforms into the vertices. Extra files go into the
`opts.files` table you pass, named after `opts.name`:
@@ -337,6 +338,60 @@ assert(F.save(scene, "out/box.obj")) -- box.obj + box.mtl
assert(F.convert("assets/Box.glb", "stl", { out = "out/box.stl" }))
```
## MikuMikuDance (PMX / PMD)
`.pmx` (PMX 2.0 / 2.1) and `.pmd` files load as one skinned mesh with one primitive per material. MMD is left-handed,
so z is negated and the winding reversed on load; `meta.up` is `"y"` (one unit is about 8 cm). Bones become nodes (a
translation relative to the parent bone) under the model's root node and one `Skin`; every vertex carries `JOINTS_0` /
`WEIGHTS_0` (BDEF1 / 2 / 4, SDEF and QDEF all as linear weights, normalized; the SDEF C / R0 / R1 vectors as
`_SDEF_C` / `_SDEF_R0` / `_SDEF_R1` and the deform type as `_DEFORM` when a file uses them), the additional UVs as
`_UVA1` .. `_UVA4` (vec4) and the edge scale as `_EDGE_SCALE`. Vertex morphs are morph targets (`mesh.extras.targetNames`
holds their names); the other morphs (group, bone, UV, material, flip, impulse) are in `mesh.extras.pmx.morphs`.
Materials take the diffuse colour as `baseColor`, the specular power as roughness and the no-cull flag as
`doubleSided`; the MMD terms (specular, ambient, edge, sphere map and its mode, toon texture or shared toon index, memo)
are in `material.extras.pmx`, bone flags / IK / inherit settings in `node.extras.pmx`, display frames, rigid bodies and
joints in `meta.source`. Textures are referenced by their file names (`opts.files` / `opts.resolve` give the bytes).
`morphs = false` skips the morph targets.
## VRML and X3D
VRML97 (`.wrl`, gzipped `.wrz`) and X3D (XML `.x3d`, classic `.x3dv`, gzipped `.x3dz` / `.x3dvz`) share one reader: the
scene graph becomes nodes (a `Transform` with a `center` or `scaleOrientation` adds an inner node), `DEF` / `USE`
shares meshes and materials, `PROTO` / `ProtoInstance` are expanded, Box / Sphere / Cone / Cylinder are tessellated
(`opts.segments`, default 32), polygons are fan-triangulated unless `triangulate = false`, texture coordinates are
flipped to glTF's top-left origin, viewpoints become cameras, lights become lights, and ROUTEs from a `TimeSensor`
through position / orientation interpolators to a `Transform` become animations. `Inline` files and textures come
from `opts.files` / `opts.resolve`. Binary X3D (`.x3db`) is `UNSUPPORTED`.
```luau
local wrl = [[#VRML V2.0 utf8
DEF Red Transform { translation 2 0 0 children Shape {
appearance Appearance { material Material { diffuseColor 1 0 0 } }
geometry Box { size 1 2 3 } } }
DEF Cam Viewpoint { position 0 0 10 }
]]
local scene = assert(F.load(wrl)) -- detected by the #VRML header
assert(scene.meta.source.format == "vrml" and #scene.cameras == 1)
assert(scene.nodes[1].name == "Red" and scene.materials[1].baseColor[1] == 1)
local lo, hi = F.ops.mesh.bounds(scene)
assert(lo[1] == 1.5 and hi[1] == 2.5) -- the Box, moved by its Transform
```
Both write too: VRML97 text, X3D XML, or the classic X3D encoding. Shared meshes are written once and `USE`d; textures
with bytes go into `opts.files`:
```luau
local x3d = [[<X3D profile="Interchange" version="3.3"><Scene>
<Shape><IndexedFaceSet coordIndex="0 1 2 3 -1"><Coordinate point="0 0 0 1 0 0 1 1 0 0 1 0"/></IndexedFaceSet></Shape>
</Scene></X3D>]]
local quad = assert(F.load(x3d, { triangulate = false }))
assert(quad.meshes[1].primitives[1].mode == "polygons" and quad.meshes[1].primitives[1].faces.count == 1)
local out = assert(F.save(quad, nil, { format = "wrl" })) -- VRML97
assert(buffer.readstring(out, 0, 15) == "#VRML V2.0 utf8")
local classic = assert(F.save(quad, nil, { format = "x3dv" })) -- the classic X3D encoding
assert(F.load(classic, { triangulate = false }).meshes[1].primitives[1].faces.count == 1)
```
## Voxels
MagicaVoxel `.vox` files load as a Scene with `meta.up = "z"`, units of one voxel, and grids in `scene.voxels`; each
@@ -633,6 +688,9 @@ assert(back.meshes[1].primitives[1].indices.count == 3)
| Minecraft `.schem` / `.schematic` / `.litematic` | yes | yes | block grids, see [voxel.md](voxel.md) |
| Minecraft region `.mca` | yes | | block grids of chosen chunks, see [voxel.md](voxel.md) |
| Qubicle `.qb` | yes | yes | true-colour grids, see [voxel.md](voxel.md) |
| PMX / PMD (MikuMikuDance) | yes | | bones + skin, vertex morphs, MMD materials and physics in extras |
| VRML97 (WRL / WRZ) | yes | yes | primitives, PROTO, Inline, ROUTE animations, cameras, lights |
| X3D (XML / classic) | yes | yes | the VRML reader plus the X3D triangle / quad / line sets; no binary `.x3db` |
| STEP | via the CAD plug-in | | see [cad.md](cad.md) |
Capabilities per format: [FORMATS.md](../FORMATS.md).