merge ws/3d3-c (model/pmx, model/vrml, model/x3d, codecs/model/Vrml); README model list
This commit is contained in:
commit
94783a86d1
29 files changed
+6735
-6
No files matched your search
+63
-5
@@ -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).
|
||||
|
||||
Reference in new issue
Block a user