ws-game: docs/guide sections (game archives, game models, game textures) with tested snippets (tools/fixtures/docs_game.py); bench lines (explode, mpq, wad map)
This commit is contained in:
1 parent
3d01293b82
commit
0b1c5ebfec
5 files changed
+267
No files matched your search
@@ -378,6 +378,57 @@ local vox = assert(F.save(grid, nil, { format = "vox" })) -- a grid alone saves
|
||||
assert(F.load(vox).voxels[1].size[1] == 4)
|
||||
```
|
||||
|
||||
## Game models
|
||||
|
||||
Game model formats load as Scenes too, with what games need: skins (joints + inverse bind matrices, `JOINTS_0` /
|
||||
`WEIGHTS_0`) and animations, vertex-animated models as morph targets. Units are as the game stores them, z up
|
||||
(`meta.up = "z"`).
|
||||
|
||||
| Format | What loads | Animations |
|
||||
|---|---|---|
|
||||
| MD2 (Quake II) | one primitive; skins as texture URIs | every frame a morph target (weight k = 1 shows frame k); one animation per frame-name group (`run1`..`run6` -> `run`) |
|
||||
| MD3 (Quake III) | a primitive per surface; shaders as URIs; tags as nodes | frames as morph targets, tag motion, one animation |
|
||||
| MDL (Quake 1, Half-Life 1) | Quake: skins decoded through the palette; Half-Life: bones, body parts, textures with their own palettes | Quake: morph targets per frame group; Half-Life: every sequence |
|
||||
| MD5 (Doom 3 `.md5mesh` / `.md5anim`) | skeleton, weighted meshes, shaders as URIs | the `.md5anim` files named in `anims` |
|
||||
| SMD (Valve, read + write) | skeleton, weight links, a primitive per material | the skeleton frames |
|
||||
| BSP (Quake 1 / 2 / 3, Half-Life) | each model a mesh, a primitive per texture (and Quake III lightmap); entities in `meta.entities` | - |
|
||||
|
||||
```luau
|
||||
local tank = assert(F.model.load(md2Bytes))
|
||||
local prim = tank.meshes[1].primitives[1]
|
||||
assert(#prim.targets == 5 and #tank.meshes[1].weights == 5) -- 5 frames
|
||||
assert(tank.animations[1].name == "stand" and tank.animations[2].name == "run")
|
||||
assert(tank.textures[1].uri == "models/tank/skin.pcx")
|
||||
assert(tank.meta.up == "z")
|
||||
```
|
||||
|
||||
MD5 animations are separate files: name them in `anims` (they are found through `files` or `resolve`, which the api
|
||||
fills in for paths), or load a `.md5anim` alone as a skeleton with its animation:
|
||||
|
||||
```luau
|
||||
local imp = assert(F.model.load(md5meshBytes, { anims = { "idle.md5anim" }, files = { ["idle.md5anim"] = md5animBytes } }))
|
||||
assert(#imp.skins == 1 and imp.animations[1].name == "idle")
|
||||
assert(imp.meshes[1].primitives[1].attributes.JOINTS_0)
|
||||
local idle = assert(F.model.load(md5animBytes, { format = "md5" }))
|
||||
assert(#idle.animations == 1)
|
||||
```
|
||||
|
||||
Quake's palette (`gfx/palette.lmp`, inside the game's PAK) is not redistributable, so Quake MDL skins and Quake 1
|
||||
BSP textures need it passed in (`palette`, or through `files` / `resolve`); without it they decode as grey ramps
|
||||
(`meta.source.palette = false`). Half-Life models and maps carry their own palettes.
|
||||
|
||||
```luau
|
||||
local map = assert(F.model.load(bspBytes)) -- a Half-Life map
|
||||
assert(map.meta.source.variant == "halflife")
|
||||
assert(map.meta.entities[1].classname == "worldspawn")
|
||||
local world = map.meshes[1] -- "world"; brush entities are "*1", "*2", ...
|
||||
assert(world.name == "world" and map.meshes[2].name == "*1")
|
||||
|
||||
local barney = assert(F.model.load(smdBytes))
|
||||
local again = assert(F.save(barney, nil, { format = "smd" })) -- SMD writes back (bind pose, weights)
|
||||
assert(F.model.load(again).skins[1])
|
||||
```
|
||||
|
||||
## Formats
|
||||
|
||||
| Format | Read | Write | Notes |
|
||||
@@ -393,6 +444,8 @@ assert(F.load(vox).voxels[1].size[1] == 4)
|
||||
| USDA (+ USDZ read) | yes | yes | |
|
||||
| VOX | yes | yes | voxel grids, scene graph, materials |
|
||||
| STEP | via the CAD plug-in | | see [cad.md](cad.md) |
|
||||
| MD2, MD3, MDL, MD5, BSP | yes | - | game models and maps: see "Game models" above |
|
||||
| SMD | yes | yes | Valve studiomdl data |
|
||||
|
||||
Capabilities per format: [FORMATS.md](../FORMATS.md).
|
||||
|
||||
|
||||
Reference in new issue
Block a user