ws-3d3: model/ms3d (MilkShape 3D) read + write
Groups, materials (texture uri), joints -> nodes + skin + one animation, version 4 sub-versioned blocks (comments, vertex extras with up to four bones, joint colours, model extras). Writer: groups per placed primitive, the first skin plus animated nodes as joints (rigid meshes bound to them), weights in percent. Tested against assimp and through glTF skin models.
This commit is contained in:
1 parent
a43d81538e
commit
730820d1f6
9 files changed
+1620
-2
No files matched your search
+33
-2
@@ -1,6 +1,6 @@
|
||||
# Scene (3D models) and Voxels
|
||||
|
||||
Every model format (glTF / GLB, OBJ, STL, PLY, OFF, FBX, Collada, 3MF, USDA, VOX, 3DS) loads as one `Scene`, a structure
|
||||
Every model format (glTF / GLB, OBJ, STL, PLY, OFF, FBX, Collada, 3MF, USDA, VOX, 3DS, MS3D) 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`.
|
||||
@@ -290,7 +290,7 @@ 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 | see [FORMATS.md](../FORMATS.md) and the format's options | |
|
||||
| PLY, OFF, FBX, DAE, 3MF, USDA, VOX, 3DS, MS3D | see [FORMATS.md](../FORMATS.md) and the format's options | |
|
||||
|
||||
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`:
|
||||
@@ -408,6 +408,36 @@ assert(back.materials[prim.material].baseColor[1] == 1)
|
||||
assert(back.nodes[1].translation[3] == 2) -- the keyframer keeps the node transform
|
||||
```
|
||||
|
||||
## MilkShape 3D (MS3D)
|
||||
|
||||
Each group loads as a node with one mesh (per-corner normals and uvs, so vertices are split per corner); joints become
|
||||
nodes with a skin (`JOINTS_0` / `WEIGHTS_0`, up to four bones from the 1.8 vertex extras) and their keys one
|
||||
animation. Comments, joint colours and the other MilkShape fields stay in `extras.ms3d` / `meta.source`. The writer
|
||||
puts every placed primitive in a group, the first skin's joints plus every node the first animation moves (meshes
|
||||
under them are bound rigidly) into the skeleton, and the weights in percent.
|
||||
|
||||
```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")
|
||||
-- spin the node a quarter turn about z in one second
|
||||
local times = S.accessor(nil, "f32", 1, 2)
|
||||
buffer.writef32(times.data, 4, 1)
|
||||
local turns = S.accessor(nil, "f32", 4, 2)
|
||||
for i, v in { 0, 0, 0, 1, 0, 0, math.sqrt(0.5), math.sqrt(0.5) } do
|
||||
buffer.writef32(turns.data, (i - 1) * 4, v)
|
||||
end
|
||||
scene.animations[1] = { channels = { { node = 1, path = "rotation", input = times, output = turns, interpolation = "LINEAR" } } }
|
||||
local back = assert(F.load(assert(F.save(scene, nil, { format = "ms3d" }))))
|
||||
assert(back.meta.source.format == "ms3d" and #back.skins == 1) -- the animated node became a joint
|
||||
local prim = back.meshes[1].primitives[1]
|
||||
assert(prim.attributes.JOINTS_0 and prim.attributes.NORMAL)
|
||||
assert(back.animations[1].channels[1].path == "rotation")
|
||||
```
|
||||
|
||||
## Formats
|
||||
|
||||
| Format | Read | Write | Notes |
|
||||
@@ -423,6 +453,7 @@ assert(back.nodes[1].translation[3] == 2) -- the keyframer keeps the
|
||||
| USDA (+ USDZ read) | yes | yes | |
|
||||
| VOX | yes | yes | voxel grids, scene graph, materials |
|
||||
| 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 |
|
||||
| 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