ws-3d3: model/gltf: KHR_draco_mesh_compression through codecs/model/Draco

Draco primitives decode on load (attributes as their accessors declare them,
u32 indices), written back uncompressed without the extension; meshopt stays
UNSUPPORTED. Tests: transcoded Khronos samples (two quantizations), Draco's and
assimp's Draco glTF files, each Draco primitive byte for byte against libdraco,
against the uncompressed sources, round trips. Draco bench line; scene.md section.
This commit is contained in:
4DBug committed 2026-10-31 14:29:54 -05:00
1 parent 9a6ddd5c16
commit c3711a7ab1
10 files changed
+455 -14

No files matched your search

+20 -1
View File
@@ -218,6 +218,25 @@ assert(cube.materials[1].baseColor[1] == 0.8) -- from Kd 0.8 0.1 0.1
A missing **image** is not an error: the texture keeps its `uri` and no `data`.
### Compressed glTF (Draco)
Primitives compressed with `KHR_draco_mesh_compression` decode on load (through `codecs/model/Draco`, a port of Google's
Draco decoder: Edgebreaker and sequential connectivity, every prediction scheme, quantized attributes, bit-exact with
libdraco). The attributes come out as their accessors declare them, and the indices as `u32`. Saving writes the
geometry back uncompressed, without the extension. `EXT_meshopt_compression` is not supported.
```luau
local scene = assert(F.load(dracoGlbBytes)) -- Box.glb through draco_transcoder
local prim = scene.meshes[1].primitives[1]
assert(prim.indices.count == 36 and prim.attributes.POSITION.type == "f32")
local plain = assert(F.save(scene, nil, { format = "glb" }))
assert(not string.find(buffer.tostring(plain), "KHR_draco", 1, true))
```
Raw `.drc` files (and Draco data inside other formats) go through the codec itself:
`require(Formats.codecs.model.Draco).decode(bytes)` returns `{ kind, numPoints, numFaces, indices, attributes }` with
each attribute's values per point (`name`, `uniqueId`, `components`, `type`, `normalized`, `data`).
## Editing: `F.ops.mesh`
Every function accepts any accessor type and writes `f32` attributes and `u32` indices. Bad arguments return
@@ -382,7 +401,7 @@ assert(F.load(vox).voxels[1].size[1] == 4)
| Format | Read | Write | Notes |
|---|---|---|---|
| glTF 2.0 / GLB | yes | yes | everything above, `KHR_*` material extensions, `KHR_mesh_quantization`; no Draco / meshopt |
| glTF 2.0 / GLB | yes | yes | everything above, `KHR_*` material extensions, `KHR_mesh_quantization`, Draco (read); no meshopt |
| OBJ + MTL | yes | yes | polygons, vertex colours, Phong + PBR MTL |
| STL | yes | yes | ASCII / binary, colour conventions; a triangle soup |
| PLY | yes | yes | ASCII / binary, point clouds, custom `_` attributes |