merge master into ws/arch2 (ws/video2, ws/3d3, ws/game Archive.slice / collect)
This commit is contained in:
commit
79fd3c05dd
213 files changed
+47945
-1533
No files matched your search
+3
-1
@@ -94,7 +94,9 @@ A format never requires another format, so the api passes these to decoders / en
|
||||
## Host
|
||||
|
||||
`F.host` (`src/Formats/host`): `name` (`"roblox"`, `"love"`, `"luajit"`, `"luau"`), `hasFiles`, `readFile`,
|
||||
`writeFile`, `exists`; Roblox `toEditableImage(img)`; LÖVE `toImageData(img)`, `fromImageData(imageData)`,
|
||||
`writeFile`, `exists`; Roblox `toEditableImage(img)`, `meshPages(prim, opts?)`, `pageData(prim, page, opts?)`,
|
||||
`toEditableMesh(prim, page?, opts?)` (a triangle primitive in pages of at most 20k triangles / 60k vertices, each an
|
||||
EditableMesh; see the Hosts section of the guide); LÖVE `toImageData(img)`, `fromImageData(imageData)`,
|
||||
`toSoundData(audioOrDecoder)`.
|
||||
|
||||
On LuaJIT the host raises the trace limits at load (`jit.opt.start("maxtrace=8000", "maxmcode=65536")`): the big
|
||||
|
||||
+46
-7
@@ -5,17 +5,28 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
|
||||
| Category | Format | Extensions | Read | Write | Capabilities | Test |
|
||||
|---|---|---|---|---|---|---|
|
||||
| image | ani | .ani | yes | yes | alpha: true, animation: true, frames: true | `tests/image/ani.luau` |
|
||||
| image | bmp | .bmp .dib | yes | yes | alpha: true, depths: 1, 2, 4, 8, 16, 24, 32, rle: true | `tests/image/bmp.luau` |
|
||||
| image | dds | .dds | yes | yes | alpha: true, float: true, mipmaps: true, cubemap: true, compressed: "bc1", "bc2", "bc3", "bc4", "bc5", "bc6h", "bc7" | `tests/image/dds.luau` |
|
||||
| image | exr | .exr | yes | yes | alpha: true, float: true, hdr: true, depths: 16, 32, multipart: true, tiled: true | `tests/image/exr.luau` |
|
||||
| image | gif | .gif | yes | yes | animation: true, alpha: true, palette: true, depths: 1, 2, 4, 8 | `tests/image/gif.luau` |
|
||||
| image | hdr | .hdr .pic .rgbe | yes | yes | alpha: false, float: true, depths: 32 | `tests/image/hdr.luau` |
|
||||
| image | icns | .icns | yes | yes | alpha: true, frames: true, depths: 1, 24, 32 | `tests/image/icns.luau` |
|
||||
| image | ico | .ico .cur | yes | yes | alpha: true, frames: true, depths: 1, 4, 8, 16, 24, 32 | `tests/image/ico.luau` |
|
||||
| image | ilbm | .iff .ilbm .lbm .pbm | yes | yes | alpha: true, palette: true, depths: 1, 2, 3, 4, 5, 6, 7, 8, 24, 32 | `tests/image/ilbm.luau` |
|
||||
| image | jpeg | .jpg .jpeg .jpe .jfif | yes | yes | lossy: true, alpha: false, depths: 8, 12, progressive: true, arithmetic: true | `tests/image/jpeg.luau` |
|
||||
| image | ktx | .ktx2 .ktx | yes | yes | alpha: true, float: true, mipmaps: true, cubemap: true, compressed: "bc1", "bc2", "bc3", "bc4", "bc5", "bc6h", "bc7", "etc1", "etc2", "eac" | `tests/image/ktx.luau` |
|
||||
| image | pcx | .pcx .pcc .dcx | yes | yes | alpha: true, palette: true, depths: 1, 2, 4, 8, 24, 32 | `tests/image/pcx.luau` |
|
||||
| image | png | .png .apng | yes | yes | animation: true, alpha: true, depths: 1, 2, 4, 8, 16 | `tests/image/png.luau` |
|
||||
| image | pnm | .pnm .pbm .pgm .ppm .pam .pfm | yes | yes | alpha: true, depths: 1, 8, 16, 32, float: true | `tests/image/pnm.luau` |
|
||||
| image | qoi | .qoi | yes | yes | alpha: true, depths: 8 | `tests/image/qoi.luau` |
|
||||
| image | sgi | .sgi .rgb .rgba .bw .int .inta | yes | yes | alpha: true, depths: 8, 16 | `tests/image/sgi.luau` |
|
||||
| image | sunras | .ras .sun .rs .im1 .im8 .im24 .im32 | yes | yes | alpha: true, palette: true, depths: 1, 8, 24, 32 | `tests/image/sunras.luau` |
|
||||
| image | tga | .tga .icb .vda .vst .tpic | yes | yes | alpha: true, palette: true, depths: 8, 15, 16, 24, 32 | `tests/image/tga.luau` |
|
||||
| image | tiff | .tif .tiff | yes | yes | alpha: true, pages: true, depths: 1, 2, 4, 8, 16, 32, float: true | `tests/image/tiff.luau` |
|
||||
| image | webp | .webp | yes | yes | animation: true, alpha: true, lossy: true, lossless: true, depths: 8 | `tests/image/webp.luau` |
|
||||
| image | xbm | .xbm .bm | yes | yes | depths: 1 | `tests/image/xbm.luau` |
|
||||
| image | xpm | .xpm .pm | yes | yes | alpha: true, palette: true, depths: 8 | `tests/image/xpm.luau` |
|
||||
| audio | aac | .aac .adts | yes | - | codecs: "aac", streaming: true | `tests/audio/aac.luau` |
|
||||
| audio | aiff | .aiff .aif .aifc .afc | yes | yes | streaming: true, depths: 8, 16, 24, 32, float: true, lossy: false | `tests/audio/aiff.luau` |
|
||||
| audio | au | .au .snd | yes | yes | streaming: true, depths: 8, 16, 24, 32, float: true, lossy: false | `tests/audio/au.luau` |
|
||||
@@ -27,21 +38,31 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| audio | voc | .voc | yes | yes | streaming: true, depths: 8, 16, lossy: false | `tests/audio/voc.luau` |
|
||||
| audio | vorbis | .ogg .oga | yes | yes | streaming: true, seek: true, lossy: true, channels: 255 | `tests/audio/vorbis.luau` |
|
||||
| audio | wav | .wav .wave .rf64 .bw64 | yes | yes | streaming: true, depths: 8, 16, 24, 32, float: true, rf64: true | `tests/audio/wav.luau` |
|
||||
| video | avi | .avi | yes | yes | streaming: true, video: "mjpeg", "mpeg1", "rawvideo", audio: true, odml: true | `tests/video/avi.luau` |
|
||||
| video | avi | .avi | yes | yes | streaming: true, video: "mjpeg", "mpeg1", "mpeg2", "rawvideo", audio: true, odml: true | `tests/video/avi.luau` |
|
||||
| video | fli | .fli .flc .flx | yes | - | streaming: true, video: "flic", depths: 8, 15, 16, 24 | `tests/video/fli.luau` |
|
||||
| video | h264 | .h264 .264 .avc .jsv .26l .jvt | yes | yes | streaming: true, video: "h264", depths: 8 | `tests/video/h264.luau` |
|
||||
| video | mkv | .mkv .webm .mka .mk3d | yes | yes | streaming: true, remux: true, video: "vp8", "mjpeg", "mpeg1", "rawvideo", audio: true, subtitles: true | `tests/video/mkv.luau` |
|
||||
| video | mp4 | .mp4 .m4v .mov .qt .3gp .3g2 .mj2 | yes | yes | streaming: true, remux: true, video: "mjpeg", "mpeg1", "h264", audio: true, fragments: true | `tests/video/mp4.luau` |
|
||||
| video | mpegps | .mpg .mpeg .vob .m1v .mpv .dat | yes | - | streaming: true, video: "mpeg1", audio: true | `tests/video/mpegps.luau` |
|
||||
| video | mpegts | .ts .m2ts .mts .tsv | yes | - | streaming: true, video: "mpeg1", "h264", audio: true | `tests/video/mpegts.luau` |
|
||||
| video | mkv | .mkv .webm .mka .mk3d | yes | yes | streaming: true, remux: true, video: "vp8", "mjpeg", "mpeg1", "mpeg2", "theora", "rawvideo", audio: true, subtitles: true | `tests/video/mkv.luau` |
|
||||
| video | mp4 | .mp4 .m4v .mov .qt .3gp .3g2 .mj2 | yes | yes | streaming: true, remux: true, video: "mjpeg", "mpeg1", "mpeg2", "h264", audio: true, fragments: true | `tests/video/mp4.luau` |
|
||||
| video | mpegps | .mpg .mpeg .vob .m1v .mpv .dat | yes | - | streaming: true, video: "mpeg1", "mpeg2", audio: true | `tests/video/mpegps.luau` |
|
||||
| video | mpegts | .ts .m2ts .mts .tsv | yes | - | streaming: true, video: "mpeg1", "mpeg2", "h264", audio: true | `tests/video/mpegts.luau` |
|
||||
| video | ogv | .ogv .ogg | yes | yes | streaming: true, remux: true, video: "theora", audio: true | `tests/video/ogv.luau` |
|
||||
| video | smk | .smk | yes | - | streaming: true, video: "smackvid", audio: "smackaudio", "pcm_u8", "pcm_s16le" | `tests/video/smk.luau` |
|
||||
| video | y4m | .y4m | yes | yes | streaming: true, video: "rawvideo", depths: 8, 10, 12, 16 | `tests/video/y4m.luau` |
|
||||
| model | 3ds | .3ds | yes | yes | materials: true, textures: true, animation: true, cameras: true, lights: true, instancing: true | `tests/model/3ds.luau` |
|
||||
| model | 3mf | .3mf | yes | yes | materials: true, vertexColors: true, textures: true, units: true | `tests/model/3mf.luau` |
|
||||
| model | b3d | .b3d | yes | - | materials: true, textures: true, skins: true, animation: true, colors: true | `tests/model/b3d.luau` |
|
||||
| model | dae | .dae .zae | yes | yes | materials: true, polygons: true, skins: true, morphTargets: true, animation: true, cameras: true, lights: true, zae: true | `tests/model/dae.luau` |
|
||||
| model | fbx | .fbx | yes | yes | binary: true, ascii: true, materials: true, animation: true, skins: true, morphTargets: true, cameras: true, lights: true, polygons: true | `tests/model/fbx.luau` |
|
||||
| model | gltf | .gltf .glb | yes | yes | binary: true, materials: true, animation: true, skins: true, morphTargets: true, cameras: true, lights: true | `tests/model/gltf.luau` |
|
||||
| model | gltf | .gltf .glb | yes | yes | binary: true, materials: true, animation: true, skins: true, morphTargets: true, cameras: true, lights: true, draco: true | `tests/model/gltf.luau` |
|
||||
| model | iqm | .iqm | yes | yes | materials: true, skins: true, animation: true, vertexColors: true | `tests/model/iqm.luau` |
|
||||
| model | ldraw | .ldr .mpd .dat | yes | - | materials: true, lines: true, instancing: true | `tests/model/ldraw.luau` |
|
||||
| model | lwo | .lwo .lxo | yes | - | materials: true, polygons: true, vertexColors: true, morphTargets: true | `tests/model/lwo.luau` |
|
||||
| model | mca | .mca .mcr | yes | - | voxels: true, blocks: true | `tests/model/mca.luau` |
|
||||
| model | ms3d | .ms3d | yes | yes | materials: true, skins: true, animation: true | `tests/model/ms3d.luau` |
|
||||
| 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` |
|
||||
@@ -50,6 +71,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 | bdf | .bdf | yes | yes | bitmap: true | `tests/font/bdf.luau` |
|
||||
| font | bmfont | .fnt | yes | yes | bitmap: true, variants: "text", "xml", "binary", extraFiles: true | `tests/font/bmfont.luau` |
|
||||
@@ -78,6 +102,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| archive | lha | .lzh .lha .lzs | yes | yes | methods: "lh0", "lh1", "lh4", "lh5", "lh6", "lh7", "lhx", "lzs", "lz5", "lz4", "lhd" | `tests/archive/lha.luau` |
|
||||
| archive | lz4 | .lz4 .tlz4 | yes | yes | stream: true, legacy: true | `tests/archive/lz4.luau` |
|
||||
| archive | macbinary | .bin .macbin | yes | yes | forks: true, variants: "I", "II", "III" | `tests/archive/macbinary.luau` |
|
||||
| archive | pak | .pak .sin | yes | yes | variants: "quake", "sin" | `tests/archive/pak.luau` |
|
||||
| archive | rpm | .rpm | yes | - | compressors: "gzip", "bzip2", "xz", "lzma", "zstd" | `tests/archive/rpm.luau` |
|
||||
| archive | tar | .tar | yes | yes | variants: "ustar", "pax", "gnu" | `tests/archive/tar.luau` |
|
||||
| archive | uu | .uu .uue .xxe .b64 | yes | yes | variants: "uu", "xx", "base64" | `tests/archive/uu.luau` |
|
||||
@@ -101,6 +126,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| vector | svg | .svg | yes | yes | rasterize: true, text: false | `tests/vector/svg.luau` |
|
||||
| vector | tiled | .tmx .tmj .tsx .tsj | yes | yes | tilesets: true, infinite: true | `tests/vector/tiled.luau` |
|
||||
| layered | aseprite | .aseprite .ase | yes | yes | layers: true, groups: true, animation: true, depths: 8, 16, 32 | `tests/layered/aseprite.luau` |
|
||||
| layered | ora | .ora | yes | yes | layers: true, groups: true, depths: 8 | `tests/layered/ora.luau` |
|
||||
| layered | psd | .psd .psb | yes | yes | layers: true, groups: true, depths: 1, 8, 16, 32 | `tests/layered/psd.luau` |
|
||||
| subtitle | ass | .ass .ssa | yes | yes | styles: true | `tests/subtitle/ass.luau` |
|
||||
| subtitle | srt | .srt | yes | yes | styles: false | `tests/subtitle/srt.luau` |
|
||||
@@ -152,20 +178,29 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
|
||||
- codecs/font/GlyphNames: PostScript glyph names -> Unicode for fonts that name their glyphs (Type 1, CFF without a
|
||||
- codecs/font/TrueType: the sfnt font container (TrueType .ttf, OpenType .otf with CFF outlines, collections .ttc) parsed
|
||||
- **image**
|
||||
- codecs/image/Bcn: the BCn block-compressed texture codecs, shared by the texture formats (DDS, KTX, VTF, BLP, ...):
|
||||
- codecs/image/Blend: layer compositing on rgba8 buffers (straight alpha): source-over with the separable and non-separable
|
||||
- codecs/image/Dct: the 8x8 DCTs JPEG, Motion-JPEG and MPEG-1 share (native; never throws).
|
||||
- codecs/image/Etc: the Ericsson / Khronos block texture codecs, decode only: ETC1, ETC2 RGB (with the T, H and planar
|
||||
- codecs/image/Half: IEEE 754 binary16 ("half") <-> number, for the float texel formats (DDS / KTX R16F..., BC6H,
|
||||
- codecs/image/Jpeg: the JPEG codec (ITU T.81) on byte ranges: image/jpeg is a thin format over it, and the Motion-JPEG
|
||||
- codecs/image/Pixels: row loops between packed pixel layouts and rgba8 (native), shared by the bitmap formats (BMP,
|
||||
- codecs/image/Quantize: palette quantization of rgba8 pixels. A codec (layer 1): image/gif (and later any palette
|
||||
- codecs/image/Raster: an antialiased scanline rasterizer for paths of lines, quadratic and cubic Béziers, under an affine
|
||||
- codecs/image/Texel: uncompressed GPU texel formats -> the standard pixel formats, shared by the texture containers
|
||||
- codecs/image/Texture: one entry point over the texture pixel codecs for the texture containers (DDS, KTX, VTF, ...):
|
||||
- codecs/image/Vp8: the VP8 video codec (RFC 6386), decode only. A codec (layer 1): image/webp uses it for lossy frames, the
|
||||
- codecs/image/Vp8L: WebP lossless (VP8L, "WebP Lossless Bitstream Specification", RFC 9649 section 3). A codec (layer 1):
|
||||
- codecs/image/Yuv: planar 4:2:0 Y'CbCr <-> rgba8 for the video codecs and writers (native; never throws). BT.601 or
|
||||
- **model**
|
||||
- codecs/model/Draco: Google Draco geometry decompression (.drc; glTF KHR_draco_mesh_compression; Roblox mesh v6 / v7).
|
||||
- codecs/model/Mat4: 4x4 matrix and quaternion helpers for the model formats: column-major flat arrays of 16
|
||||
- codecs/model/MeshFlatten: a Scene to one world-space mesh, for the writers of mesh-only formats (STL, PLY, OFF). Walks
|
||||
- codecs/model/Minecraft: what Minecraft's voxel formats share (model/schematic, model/mca). New code.
|
||||
- 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,
|
||||
@@ -173,6 +208,10 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
|
||||
- codecs/text/Url: RFC 3986 reference resolution (section 5.2), the classification of a playlist / manifest location (URL,
|
||||
- codecs/text/Xml: XML 1.0 parse (DOM and pull events) and serialize, the engine data/xml, SVG, DAE, 3MF, TMX, plist, ...
|
||||
- **video**
|
||||
- codecs/video/Dsp: the 8x8 IDCT (bit-exact with ffmpeg -idct int) and half-pel motion compensation of MPEG codecs.
|
||||
- codecs/video/H264: an H.264 / AVC (ITU-T H.264 | ISO/IEC 14496-10) video decoder in pure Luau. A codec (layer 1): the
|
||||
- codecs/video/Mpeg1: an MPEG-1 video decoder (ISO/IEC 11172-2) for the MPEG-TS / MPEG-PS video formats. Absorbed from
|
||||
- codecs/video/Legacy: FLI / FLC, Cinepak, Microsoft Video 1, QuickTime RLE / SMC and Smacker video decoders.
|
||||
- codecs/video/Mpeg1: the MPEG-1 video decoder (ISO/IEC 11172-2), which is codecs/video/Mpeg2 (an MPEG-2 decoder
|
||||
- codecs/video/Mpeg2: an MPEG-1 / MPEG-2 video decoder (ISO/IEC 11172-2, ISO/IEC 13818-2 Main profile).
|
||||
- codecs/video/Theora: a Theora video decoder (the Theora I specification, Xiph.Org), for Ogg (video/ogv) and Matroska
|
||||
- codecs/video/Video: the video codec registry and the generic VideoDecoder. New in formats-luau.
|
||||
+28
-1
@@ -275,7 +275,7 @@ single-stream archive such as `.tar.gz` loads as the archive inside. A music fil
|
||||
|
||||
| Host | Files | Bridges |
|
||||
|---|---|---|
|
||||
| Roblox | none: pass buffers or strings | `F.host.toEditableImage(img)` |
|
||||
| Roblox | none: pass buffers or strings | `F.host.toEditableImage(img)`, `F.host.meshPages(prim)` / `F.host.toEditableMesh(prim, page)` |
|
||||
| LÖVE | `love.filesystem` (the game folder and the save directory), then `io` | `F.host.toImageData(img)`, `F.host.fromImageData(imageData)`, `F.host.toSoundData(audioOrDecoder)` |
|
||||
| LuaJIT | `io.open` | |
|
||||
| luau CLI | none | |
|
||||
@@ -304,6 +304,33 @@ label.ImageContent = Content.fromObject(editable)
|
||||
label.Parent = script.Parent -- a ScreenGui
|
||||
```
|
||||
|
||||
Meshes: one EditableMesh holds about 20k triangles and 60k vertices, and a client has only 8 growable ones at a time.
|
||||
`F.host.meshPages(prim, opts?)` splits a triangle primitive (`F.ops.mesh.merge` output) into runs that fit;
|
||||
`F.host.toEditableMesh(prim, page, opts?)` builds one page (positions relative to the returned centre, normals, uvs,
|
||||
sRGB vertex colours from the linear `COLOR_0`) and returns `editableMesh, centre`. Freeze each page into what you keep
|
||||
before building the next. Options: `scale` (number or `{ x, y, z }`), `doubleSided` (back faces, counted by
|
||||
`meshPages` too), `texCoord`, `flipV`, `normals` / `uvs` / `colors = false`, `yield` (called every `yieldEvery` = 2000
|
||||
triangles), `editableMesh` (append to an existing mesh). `F.host.pageData(prim, page, opts?)` is the same page as flat
|
||||
number arrays, without engine calls. Roblox is y up like glTF: put z-up scenes (STL, VOX, CAD) through
|
||||
`F.ops.mesh.setUp(scene, "y")` before merging.
|
||||
|
||||
<!-- doc:display needs Roblox -->
|
||||
```luau
|
||||
local AssetService = game:GetService("AssetService")
|
||||
local scene = assert(F.model.load(glbBytes))
|
||||
for _, prim in assert(F.ops.mesh.merge(scene, { byMaterial = true })) do
|
||||
for _, page in assert(F.host.meshPages(prim)) do
|
||||
local em, centre = assert(F.host.toEditableMesh(prim, page, { scale = 1 / 0.28 })) -- metres -> studs
|
||||
local fixed = AssetService:CreateEditableMeshAsync(Content.fromObject(em), { FixedSize = true })
|
||||
em:Destroy() -- frees the growable slot
|
||||
local part = AssetService:CreateMeshPartAsync(Content.fromObject(fixed))
|
||||
part.Position = Vector3.new(centre[1], centre[2], centre[3])
|
||||
part.Anchored = true
|
||||
part.Parent = workspace
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
**LÖVE.** `toImageData` copies an `rgba8` image into an `ImageData` (through the FFI), `fromImageData` copies back,
|
||||
and `toSoundData` turns an `Audio` or a `Decoder` (read to its end) into 16-bit `SoundData`:
|
||||
|
||||
|
||||
@@ -207,6 +207,42 @@ Read and write unless noted; see [FORMATS.md](../FORMATS.md) for depths and deta
|
||||
| TIFF | pages | yes | 1..32-bit, float |
|
||||
| BMP, TGA, QOI, ICO / CUR, PNM / PAM / PFM | ICO entries | yes | |
|
||||
| HDR | | no | float (`native` gives rgbaf32) |
|
||||
| DDS, KTX / KTX2 | faces / layers / slices | yes | GPU textures: BC1..BC7, ETC / EAC, every uncompressed layout; mips in `meta.mipmaps` |
|
||||
| OpenEXR | parts (`opts.part`) | yes | half / float / uint, NONE / RLE / ZIPS / ZIP / PIZ, tiles; writes NONE / ZIPS / ZIP |
|
||||
| PCX, SGI, Sun Raster, IFF ILBM / PBM, XPM, XBM | | yes (XBM 1-bit) | old paint / workstation formats; ILBM reads HAM and EHB |
|
||||
| ICNS, ANI | ICNS sizes / ANI steps | yes | PNG / ICO entries through the api hooks |
|
||||
|
||||
### Textures and HDR (DDS, KTX, EXR)
|
||||
|
||||
DDS and KTX files hold GPU textures: block-compressed (BC1..BC7, ETC1 / ETC2 / EAC) or plain texel layouts, with mip
|
||||
levels, cube faces and array layers. The image is the first surface; `img.frames` lists every face / layer / depth
|
||||
slice when there is more than one (`meta.layout` is `"2d"`, `"cube"`, `"array"` or `"volume"`), and with `opts.mips` the
|
||||
smaller levels of the first surface go to `meta.mipmaps`. Float and 16-bit sources keep their values with
|
||||
`opts.native` (`rgbaf32` / `rgba16`); otherwise they are clamped into `rgba8`. Writers pick the stored layout with
|
||||
`pixelFormat` (`format` is the file format): DDS writes `rgba8`, `bgra8`, `bc1`, `bc3`, `bc4`, `bc5`, `rgba16`,
|
||||
`rgba16f`, `rgba32f`; KTX2 writes the uncompressed ones.
|
||||
|
||||
```luau
|
||||
local img = assert(F.ops.image.new(64, 64))
|
||||
assert(F.ops.image.fill(img, 200, 120, 40, 255))
|
||||
local dds = assert(F.save(img, nil, { format = "dds", pixelFormat = "bc1", mips = true }))
|
||||
local tex = assert(F.load(dds, { mips = true }))
|
||||
assert(tex.meta.source.pixelFormat == "bc1" and #tex.meta.mipmaps == 6)
|
||||
local ktx = assert(F.save(img, nil, { format = "ktx", mips = true, zlib = 6 })) -- KTX2, ZLIB-supercompressed
|
||||
assert(F.detect(ktx) == "ktx")
|
||||
```
|
||||
|
||||
OpenEXR loads as linear floats with `opts.native` (`rgbaf32`); the default `rgba8` goes through the same 1 / 2.2
|
||||
display curve as Radiance HDR. `opts.part` picks a part of a multipart file, `opts.layer` reads `<layer>.R` / `.G` / ...
|
||||
|
||||
```luau
|
||||
local hdr = assert(F.ops.image.new(8, 8, "rgbaf32"))
|
||||
assert(F.ops.image.fill(hdr, 4, 2, 0.5, 1)) -- floats may exceed 1
|
||||
local exr = assert(F.save(hdr, nil, { format = "exr", compression = "zip", pixelType = "half" }))
|
||||
local linear = assert(F.load(exr, { native = true }))
|
||||
assert(linear.format == "rgbaf32" and math.abs(buffer.readf32(linear.pixels, 0) - 4) < 1e-3)
|
||||
assert(F.load(exr).format == "rgba8") -- the display conversion
|
||||
```
|
||||
|
||||
An animated image also opens as a video (`F.video.open(gifBytes)`), and saves to a video format
|
||||
(`F.convert(gifBytes, "avi")`): see [video.md](video.md).
|
||||
|
||||
+25
-3
@@ -1,8 +1,8 @@
|
||||
# Layered images (PSD, Aseprite)
|
||||
# Layered images (PSD, Aseprite, OpenRaster)
|
||||
|
||||
Photoshop documents and Aseprite sprites load as a `Layered`: a canvas size and a tree of layers, each with its own
|
||||
Photoshop documents, Aseprite sprites and OpenRaster files load as a `Layered`: a canvas size and a tree of layers, each with its own
|
||||
rgba8 [Image](image.md), position, opacity, blend mode and visibility. `F.ops.layers.flatten` composites the tree
|
||||
into one Image; `F.save` writes PSD or Aseprite, layers included. Aseprite animations also carry every frame's tree.
|
||||
into one Image; `F.save` writes PSD, Aseprite or OpenRaster, layers included. Aseprite animations also carry every frame's tree.
|
||||
|
||||
```luau
|
||||
local doc = assert(F.layered.load(psdBytes))
|
||||
@@ -230,6 +230,28 @@ assert(#back.frames == 4 and back.frames[3].layers[1].x == 3)
|
||||
|---|---|---|---|
|
||||
| PSD / PSB | 1 / 8 / 16 / 32-bit, every colour mode, layers, groups, masks, clipping | 8-bit RGB | adjustment, type and smart-object layers keep only their pixels; no layer effects |
|
||||
| Aseprite | RGBA, grayscale, indexed; frames, linked cels, tags, palette, user data | yes | tilemap layers are skipped (`meta.skipped`); slices not kept |
|
||||
| OpenRaster (ORA) | the stack tree (nested stacks = groups), offsets, opacity, visibility, svg composite-ops | yes | layers are PNGs through the api hooks; `meta.composite` = mergedimage.png |
|
||||
|
||||
### OpenRaster
|
||||
|
||||
An `.ora` file is a zip of PNG layers and a `stack.xml` tree (the format GIMP, Krita and MyPaint exchange). It loads
|
||||
like the others; nested `<stack>`s become groups (`isolation="auto"` is the `"passThrough"` blend). Saving writes every
|
||||
layer, the flattened `mergedimage.png` and a thumbnail.
|
||||
|
||||
```luau
|
||||
local doc = F.Types.Layered.new(32, 24)
|
||||
local base = assert(F.ops.image.new(32, 24))
|
||||
assert(F.ops.image.fill(base, 30, 60, 200, 255))
|
||||
local dot = assert(F.ops.image.new(8, 8))
|
||||
assert(F.ops.image.fill(dot, 255, 255, 0, 255))
|
||||
local top = F.Types.Layered.layer("dot", dot, 12, 8)
|
||||
top.blend, top.opacity = "screen", 0.5
|
||||
doc.layers = { F.Types.Layered.layer("base", base), top }
|
||||
local ora = assert(F.save(doc, nil, { format = "ora" }))
|
||||
local back = assert(F.layered.load(ora))
|
||||
assert(#back.layers == 2 and back.layers[2].blend == "screen" and back.layers[2].x == 12)
|
||||
assert(back.meta.composite.width == 32) -- mergedimage.png
|
||||
```
|
||||
|
||||
See [FORMATS.md](../FORMATS.md) for the capability matrix.
|
||||
|
||||
|
||||
+300
-6
@@ -1,9 +1,10 @@
|
||||
# Scene (3D models) and Voxels
|
||||
|
||||
Every model format (glTF / GLB, OBJ, STL, PLY, OFF, FBX, Collada, 3MF, USDA, VOX) 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`.
|
||||
Every model format (glTF / GLB, OBJ, STL, PLY, OFF, FBX, Collada, 3MF, USDA, VOX, 3DS, MS3D, B3D, LDraw, LightWave
|
||||
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))
|
||||
@@ -218,6 +219,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
|
||||
@@ -290,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 | 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`:
|
||||
@@ -317,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
|
||||
@@ -380,11 +455,220 @@ local vox = assert(F.save(grid, nil, { format = "vox" })) -- a grid alone saves
|
||||
assert(F.load(vox).voxels[1].size[1] == 4)
|
||||
```
|
||||
|
||||
## Blitz3D (B3D)
|
||||
|
||||
`.b3d` files (Blitz3D, also written by many old game tools) load read-only. The node tree keeps its names and TRS;
|
||||
each `MESH` becomes one mesh whose primitives (one per `TRIS` chunk) share the vertex accessors; brushes become
|
||||
materials (colour, alpha, shininess, the first texture as `baseColorTexture` with its position / scale / rotation as
|
||||
`transform`, the full brush in `extras.b3d`); `BONE` weights become a skin (the 4 strongest weights per vertex) and
|
||||
`KEYS` + `ANIM` one animation sampled at `frame / fps`. Texture files come through `files` / `resolve` like any other
|
||||
model's (by the stored path, then by its base name: B3D files often store absolute Windows paths).
|
||||
|
||||
Blitz3D is **left-handed**: the reader mirrors z (and turns the triangle winding and rotations to match), so the scene
|
||||
is glTF's right-handed Y-up with the model looking as it did in Blitz3D. `meta.source.handedness = "left"` records
|
||||
the origin, `meta.source.fps` / `frames` the `ANIM` chunk.
|
||||
|
||||
## LDraw
|
||||
|
||||
LDraw files (`.ldr` models, `.dat` parts, `.mpd` multi-part files) load read-only. Every reference to a **part**
|
||||
becomes a node with the reference's matrix, and each part is baked once per colour into a mesh those nodes share;
|
||||
**sub-models** (`.ldr` / `.mpd` files, MPD sections that are not parts) become nodes with children. Colour 16 takes the
|
||||
colour of the reference above it, 24 its edge colour; codes come from the LDConfig.ldr table built in (one material per
|
||||
colour, `extras.ldraw.code` / `name`), `0x2RRGGBB` is a direct colour. BFC (`CERTIFY`, `CW` / `CCW`, `INVERTNEXT`,
|
||||
`NOCLIP`) turns every face counter-clockwise; faces of uncertified parts get double-sided materials. Edge lines (type 2)
|
||||
are `"lines"` primitives (`lines = false` drops them); optional lines only on request (`optionalLines = true`).
|
||||
|
||||
```luau
|
||||
local mpd = [[
|
||||
0 FILE house.ldr
|
||||
1 4 0 0 0 1 0 0 0 1 0 0 0 1 wall.dat
|
||||
1 4 50 0 0 1 0 0 0 1 0 0 0 1 wall.dat
|
||||
1 1 0 -30 0 1 0 0 0 1 0 0 0 1 roof.dat
|
||||
0 FILE wall.dat
|
||||
0 !LDRAW_ORG Unofficial_Part
|
||||
0 BFC CERTIFY CCW
|
||||
4 16 -10 0 -10 10 0 -10 10 0 10 -10 0 10
|
||||
2 24 -10 0 -10 10 0 -10
|
||||
0 FILE roof.dat
|
||||
0 BFC CERTIFY CCW
|
||||
3 16 0 -10 0 10 0 0 -10 0 0
|
||||
]]
|
||||
local scene = assert(F.model.load(mpd, { format = "ldraw" }))
|
||||
print(#scene.meshes) -- 2: wall.dat in red (both walls share it), roof.dat in blue
|
||||
local root = scene.nodes[scene.roots[1]] -- "LDraw": turns LDraw's -Y up into Y up
|
||||
local a, b = scene.nodes[root.children[1]], scene.nodes[root.children[2]]
|
||||
assert(a.mesh == b.mesh and b.matrix[13] == 50)
|
||||
local red = scene.materials[scene.meshes[a.mesh].primitives[1].material]
|
||||
print(red.name, red.extras.ldraw.code) -- Red 4
|
||||
assert(scene.meta.up == "y" and scene.meta.unit == 0.0004) -- 1 LDU = 0.4 mm
|
||||
```
|
||||
|
||||
Parts and primitives that are not in the file come through `files` or `resolve`, asked for by their LDraw library
|
||||
path: the name as written (backslashes turned into slashes), then in lower case, under `""`, `parts/`, `p/`,
|
||||
`parts/s/` and `models/`. Point `resolve` at an LDraw library folder to load real models; missing files are skipped and
|
||||
listed in `meta.source.missing`:
|
||||
|
||||
```luau
|
||||
local library = {
|
||||
["p/box.dat"] = "0 BFC CERTIFY CCW\n4 16 -1 -1 -1 1 -1 -1 1 -1 1 -1 -1 1\n4 16 -1 1 -1 -1 1 1 1 1 1 1 1 -1\n",
|
||||
["parts/plate.dat"] = "0 !LDRAW_ORG Part\n1 16 0 4 0 20 0 0 0 4 0 0 0 10 box.dat\n",
|
||||
}
|
||||
local model = "0 two plates\n1 14 0 0 0 1 0 0 0 1 0 0 0 1 plate.dat\n1 0x2FF8000 0 -8 0 1 0 0 0 1 0 0 0 1 plate.dat\n"
|
||||
.. "1 4 0 -16 0 1 0 0 0 1 0 0 0 1 3001.dat\n"
|
||||
local scene = assert(F.model.load(model, { format = "ldraw", files = library }))
|
||||
assert(#scene.meshes == 2 and scene.meta.source.missing[1] == "3001.dat")
|
||||
local same = assert(F.model.load(model, { format = "ldraw", resolve = function(path)
|
||||
return library[path] -- or: read ldrawFolder .. "/" .. path
|
||||
end }))
|
||||
local flat = assert(F.model.load(model, { format = "ldraw", files = library, flatten = true }))
|
||||
assert(#flat.meshes == 1) -- one mesh, one primitive per colour
|
||||
```
|
||||
|
||||
`upright = false` leaves out the root node (LDraw's axes as stored, `meta.source.up = "-y"`); `ldconfig` takes the
|
||||
text of another LDConfig.ldr, and `color` the colour of code 16 at the top (default 16, "Main_Colour").
|
||||
|
||||
## 3D Studio (3DS)
|
||||
|
||||
`.3ds` files load with their keyframer: the node hierarchy, pivots, instances of one object, the first key of each
|
||||
track as the node's TRS and, when tracks have several keys, one animation (frames / `opts.fps`, default 30).
|
||||
Normals come from the smoothing groups (`normals = false` keeps the file's shared vertices); the groups stay in
|
||||
`prim.extras["3ds"].smoothing` and are written back. Materials are Phong (the raw values in `extras["3ds"]`), texture
|
||||
maps become textures with a `uri` only (`F.model.loadTextures` reads them). Cameras get `yfov` from the lens at a
|
||||
4:3 aspect and look at their target; omni lights are `point`, spotlights `spot`. The writer puts one object per mesh
|
||||
(split past 65535 vertices), its first instance's world matrix as the mesh matrix, and the scene's first animation
|
||||
into the keyframer.
|
||||
|
||||
```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", material = 1 }, "tri")
|
||||
scene.materials[1] = S.material("red")
|
||||
scene.materials[1].baseColor = { 1, 0, 0, 1 }
|
||||
scene.nodes[1].translation = { 0, 0, 2 }
|
||||
local bytes = assert(F.save(scene, nil, { format = "3ds" }))
|
||||
local back = assert(F.load(bytes)) -- detected by its 0x4D4D main chunk
|
||||
assert(back.meta.source.format == "3ds" and back.meta.up == "z")
|
||||
local prim = back.meshes[1].primitives[1]
|
||||
assert(prim.attributes.NORMAL and prim.extras["3ds"].smoothing[1] == 1)
|
||||
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")
|
||||
```
|
||||
|
||||
## LightWave, DirectX and Inter-Quake models
|
||||
|
||||
**LightWave objects** (`.lwo`: LWO2 and the older LWOB; Modo's `.lxo`) give one node per layer (its pivot as the
|
||||
translation, parents by layer index), one mesh per layer and one primitive per surface. LightWave is left-handed: z is
|
||||
negated and the winding reversed on load, so the scene is glTF's right-handed y up. UV maps become `TEXCOORD_n` (one
|
||||
set per map name), the colour map a surface names becomes `COLOR_0`, weight maps `_WEIGHT_n` and morph maps morph
|
||||
targets (names in `prim.extras.lwo.maps` / `mesh.extras.targetNames`). Surface values and texture blocks are in
|
||||
`material.extras.lwo`; image textures keep only the file name as `uri` (`F.model.loadTextures` reads them). Subdivision
|
||||
cages (`PTCH` / `SUBD`) stay polygons with `prim.extras.lwo.subdivision = true`.
|
||||
|
||||
```luau
|
||||
-- a one-triangle LWO2 file, built by hand (IFF chunks, big-endian)
|
||||
local function be(n, bytes)
|
||||
local s = ""
|
||||
for i = bytes - 1, 0, -1 do
|
||||
s ..= string.char(bit32.band(bit32.rshift(n, i * 8), 255))
|
||||
end
|
||||
return s
|
||||
end
|
||||
local function f4(x)
|
||||
local b = buffer.create(4)
|
||||
buffer.writef32(b, 0, x)
|
||||
return be(buffer.readu32(b, 0), 4)
|
||||
end
|
||||
local function chunk(id, body)
|
||||
return id .. be(#body, 4) .. body
|
||||
end
|
||||
local body = "LWO2" .. chunk("TAGS", "Red\0") .. chunk("LAYR", be(0, 4) .. f4(0) .. f4(0) .. f4(0) .. "Body\0\0")
|
||||
.. chunk("PNTS", f4(0) .. f4(0) .. f4(0) .. f4(1) .. f4(0) .. f4(0) .. f4(0) .. f4(1) .. f4(0))
|
||||
.. chunk("POLS", "FACE" .. be(3, 2) .. be(0, 2) .. be(1, 2) .. be(2, 2))
|
||||
.. chunk("PTAG", "SURF" .. be(0, 4))
|
||||
.. chunk("SURF", "Red\0\0\0" .. "COLR" .. be(14, 2) .. f4(1) .. f4(0) .. f4(0) .. be(0, 2))
|
||||
local scene = assert(F.load("FORM" .. be(#body, 4) .. body))
|
||||
assert(scene.nodes[1].name == "Body" and scene.meta.source.version == "LWO2")
|
||||
assert(scene.materials[1].name == "Red" and scene.materials[1].baseColor[1] == 1)
|
||||
assert(scene.meshes[1].primitives[1].indices.count == 3)
|
||||
```
|
||||
|
||||
**DirectX `.x`** files (text, binary and MSZIP-compressed, 32- or 64-bit floats) give the frame hierarchy, one primitive
|
||||
per material, materials with their texture file names, skins (`SkinWeights`) and animation sets. Direct3D is
|
||||
left-handed too: z is negated and the winding reversed. Key times are in seconds (`AnimTicksPerSecond`, default 4800).
|
||||
|
||||
```luau
|
||||
local text = [[xof 0303txt 0032
|
||||
Material Wood { 0.8; 0.6; 0.4; 1.0;; 20.0; 0.1; 0.1; 0.1;; 0.0; 0.0; 0.0;; TextureFilename { "wood.png"; } }
|
||||
Frame Root {
|
||||
FrameTransformMatrix { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,5,1;; }
|
||||
Mesh Tri { 3; 0;0;0;, 1;0;0;, 0;1;0;; 1; 3;0,1,2;; MeshMaterialList { 1; 1; 0;; { Wood } } }
|
||||
}
|
||||
]]
|
||||
local scene = assert(F.load(text, { format = "x" }))
|
||||
local root = scene.nodes[1]
|
||||
assert(root.name == "Root" and root.translation[3] == -5) -- z negated
|
||||
assert(scene.materials[1].name == "Wood")
|
||||
assert(scene.textures[scene.materials[1].baseColorTexture.texture].uri == "wood.png")
|
||||
local glb = assert(F.save(scene, nil, { format = "glb" }))
|
||||
```
|
||||
|
||||
**IQM** (Inter-Quake Model, version 2) reads and writes meshes, every vertex array, the skeleton (a node per joint and
|
||||
one skin), animations (dequantized frames as translation / rotation / scale channels, loop flags and frame ranges in
|
||||
`meta.source.animations`) and per-frame bounds. IQM is z-up (`meta.up = "z"`); nothing is rotated either way. The
|
||||
writer turns any Scene's triangles into IQM meshes, merges the skins into one skeleton and samples each animation at
|
||||
its key spacing when uniform (else `opts.framerate`, default 30 frames per second).
|
||||
|
||||
```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")
|
||||
local iqm = assert(F.save(scene, nil, { format = "iqm" }))
|
||||
local back = assert(F.load(iqm))
|
||||
assert(back.meta.source.format == "iqm" and back.meshes[1].name == "tri")
|
||||
assert(back.meshes[1].primitives[1].indices.count == 3)
|
||||
```
|
||||
|
||||
## Formats
|
||||
|
||||
| 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 |
|
||||
@@ -394,9 +678,19 @@ assert(F.load(vox).voxels[1].size[1] == 4)
|
||||
| 3MF | yes | yes | |
|
||||
| USDA (+ USDZ read) | yes | yes | |
|
||||
| VOX | yes | yes | voxel grids, scene graph, materials |
|
||||
| B3D (Blitz3D) | yes | | brushes, textures, skins, keyframe animation; left-handed source mirrored to glTF's frame |
|
||||
| LDraw (LDR / DAT / MPD) | yes | | parts as shared meshes per colour, sub-models as nodes, BFC, LDConfig colours, `files` / `resolve` for the library |
|
||||
| 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 |
|
||||
| LightWave LWO (LWO2, LWOB, Modo LXOB) | yes | | layers, vertex maps, surfaces; see below |
|
||||
| DirectX .x (text, binary, MSZIP) | yes | | frames, materials, skins, animation |
|
||||
| IQM (Inter-Quake Model) | yes | yes | skeleton, skin, sampled animations, bounds |
|
||||
| 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).
|
||||
|
||||
+126
-5
@@ -2,7 +2,7 @@
|
||||
|
||||
A video file opens as a **VideoDecoder**: frames come out one at a time, as Images, with their presentation time.
|
||||
Underneath sits a **Demuxer**: the container's tracks and their compressed packets. Video tracks decode through a
|
||||
codec registry (H.264, VP8, MPEG-1, Motion-JPEG, raw), and the first audio track opens as an audio
|
||||
codec registry (H.264, VP8, MPEG-1, MPEG-2, Motion-JPEG, raw), and the first audio track opens as an audio
|
||||
[Decoder](audio.md#decoder). Animated GIF, APNG and WebP open as videos too. [docs/video.md](../video.md) covers the
|
||||
internals and how to add a codec.
|
||||
|
||||
@@ -183,6 +183,7 @@ Images and animated images save as videos too.
|
||||
| Destination | Video | Audio |
|
||||
|---|---|---|
|
||||
| webm | VP8 / VP9 / AV1 copied (VP8 is decode only, so the source must be WebM-compatible) | Opus / Vorbis copied |
|
||||
| ogv | Theora copied (the source must be Theora: ogv or mkv) | Vorbis / Opus copied |
|
||||
| mkv | any codec copied, else MJPEG | copied, else PCM s16 |
|
||||
| mp4, mov | H.264 / HEVC / AV1 / MJPEG / MPEG-4 copied, else MJPEG | AAC / ALAC / Opus / FLAC / MP3 copied; PCM in MOV only |
|
||||
| avi | MJPEG copied, else MJPEG encoded (`quality`) | PCM s16 |
|
||||
@@ -263,6 +264,54 @@ assert(C.register({
|
||||
assert(C.fromFourcc("SLID") == "solid" and C.canDecode("solid"))
|
||||
```
|
||||
|
||||
## MPEG-2 (DVD, broadcast TS)
|
||||
|
||||
MPEG-1 and MPEG-2 video decode through one decoder (`codecs/video/Mpeg2`; `codecs/video/Mpeg1` is the same module):
|
||||
Main profile, progressive and interlaced, frame and field pictures, 4:2:0 and 4:2:2. It reads `.mpg` / `.vob`
|
||||
program streams, transport streams (stream type 0x02, or a private type such as 0x80 carrying a video PES), raw
|
||||
`.m2v` elementary streams, and MPEG-2 tracks of MP4 / MOV, Matroska and AVI. The output equals `ffmpeg -idct int`
|
||||
sample for sample (the integer IDCT of the IJG; ffmpeg's default IDCT differs from it by at most a level or two).
|
||||
|
||||
```luau
|
||||
local v = assert(F.video.open(tsBytes)) -- MPEG-TS: interlaced MPEG-2 + MP2
|
||||
assert(v.format == "mpegts" and v.codec == "mpeg2")
|
||||
local f = assert(v:nextFrame())
|
||||
local src = f.image.meta.source
|
||||
assert(src.format == "mpeg2" and src.interlaced and src.topFieldFirst)
|
||||
assert(f.image.format == "yuv420p") -- both fields woven: the top field on the even lines
|
||||
local a = assert(v.audio, tostring(v.audioError)) -- the MP2 track through the audio hook
|
||||
assert(a.sampleRate == 44100)
|
||||
```
|
||||
|
||||
Interlaced frames come out woven, as they were coded: deinterlace them yourself if needed (`src.interlaced`,
|
||||
`src.topFieldFirst`). 4:2:2 streams (studio / XDCAM) are converted to 4:2:0 for the frame Image, averaging chroma
|
||||
lines of the same field. A 720x576 interlaced stream decodes at about 130 frames per second in Luau on one desktop
|
||||
core (`tools/bench.luau`): real time with room to spare on a PC, less so on phones.
|
||||
|
||||
## Ogg Theora
|
||||
|
||||
Ogg video (`.ogv`, or `.ogg` with a Theora stream) opens like any other container: the `ogv` format demuxes every
|
||||
Ogg stream, Theora video decodes bit-exactly (as libtheora / ffmpeg) in all three pixel formats (4:2:2 and 4:4:4
|
||||
chroma is averaged down to yuv420p), and a Vorbis, Opus or FLAC track becomes `v.audio`. Plain Ogg Vorbis / Opus /
|
||||
FLAC files stay audio. Theora in Matroska (`V_THEORA`) decodes too, and an Ogg Theora video remuxes to ogv or mkv
|
||||
(there is no Theora encoder).
|
||||
|
||||
```luau
|
||||
local v = assert(F.video.open(ogvBytes)) -- Theora + Vorbis
|
||||
assert(v.format == "ogv" and v.codec == "theora" and v.width == 64 and v.height == 48)
|
||||
assert(v.frameRate == 10 and v.audio ~= nil)
|
||||
local n = 0
|
||||
while v:nextFrame() do n += 1 end -- dropped frames repeat the previous picture
|
||||
assert(n == 10)
|
||||
local Theora = F.format("ogv") -- the format module: sniff / demux / open / encode
|
||||
local d = assert(Theora.demux(F.Bytes.reader(ogvBytes)))
|
||||
local vt = d:track("video")
|
||||
assert(vt.codec == "theora" and vt.timescale == 10) -- packet times are frame numbers here
|
||||
v:reset()
|
||||
local mkv = assert(F.save(v, nil, { format = "mkv" })) -- Theora + Vorbis copied into Matroska
|
||||
assert(F.video.open(mkv).codec == "theora")
|
||||
```
|
||||
|
||||
## Playing in a game loop
|
||||
|
||||
Decode only the frames that are due, and stop when this frame's time budget is used up; a slow frame then makes
|
||||
@@ -306,16 +355,88 @@ editable:WritePixelsBuffer(Vector2.zero, editable.Size, v:toRGBA(frame).pixels)
|
||||
|
||||
| Format | Read | Write | Video codecs (decode) |
|
||||
|---|---|---|---|
|
||||
| mp4 / mov / m4v / 3gp | yes | yes | H.264, MJPEG, MPEG-1 |
|
||||
| mkv / webm | yes | yes | VP8, MJPEG, MPEG-1, raw (+ H.264) |
|
||||
| avi | yes | yes | MJPEG, MPEG-1, raw (+ H.264) |
|
||||
| mpegts, mpegps | yes | - | MPEG-1, H.264 |
|
||||
| mp4 / mov / m4v / 3gp | yes | yes | H.264, MJPEG, MPEG-1, MPEG-2 |
|
||||
| mkv / webm | yes | yes | VP8, MJPEG, MPEG-1, MPEG-2, raw, Theora (+ H.264) |
|
||||
| ogv (Ogg Theora) | yes | yes (Theora + Vorbis / Opus copied) | Theora |
|
||||
| avi | yes | yes | MJPEG, MPEG-1, MPEG-2, raw (+ H.264) |
|
||||
| mpegts, mpegps | yes | - | MPEG-1, MPEG-2, H.264 |
|
||||
| y4m | yes | yes | raw |
|
||||
| h264 (Annex B) | yes | yes (copy) | H.264 |
|
||||
| gif, png (APNG), webp | as video | as video via the image writers | frames |
|
||||
|
||||
See [FORMATS.md](../FORMATS.md). Subtitle tracks of Matroska files are read as cues by `F.format("mkv").subtitles`.
|
||||
|
||||
<!-- ws-video2-legacy: formats table addition -->
|
||||
| fli / flc / flx | yes | - | FLIC (8-bit palettised, 15 / 16 / 24-bit) |
|
||||
| smk | yes | - | Smacker video (SMK2 / SMK4) + Smacker audio / PCM |
|
||||
|
||||
AVI, MOV / MP4 and MKV (V_MS/VFW/FOURCC, V_QUICKTIME) also decode the legacy codecs: Cinepak, Microsoft Video 1,
|
||||
QuickTime Animation (RLE) and QuickTime Graphics (SMC). See [Legacy video](#legacy-video).
|
||||
|
||||
<!-- ws-video2-legacy: section -->
|
||||
## Legacy video
|
||||
|
||||
The 1990s formats and codecs decode to **rgba8** frames (they are palettised or RGB, not YUV), each frame painted
|
||||
over the previous one, as the codecs define. Decoding is bit-exact with ffmpeg's.
|
||||
|
||||
| Codec id | Name | Containers | Depths |
|
||||
|---|---|---|---|
|
||||
| `flic` | Autodesk FLI / FLC | fli | 8-bit palettised, 15 / 16 / 24-bit |
|
||||
| `smackvid` | Smacker video | smk | 8-bit palettised |
|
||||
| `cinepak` | Cinepak (`cvid`) | avi, mov, mkv | 24-bit, grey, 8-bit palettised |
|
||||
| `msvideo1` | Microsoft Video 1 (`CRAM`, `MSVC`, `WHAM`) | avi, mov, mkv | 16-bit (5-5-5), 8-bit palettised |
|
||||
| `qtrle` | QuickTime Animation (`rle `) | mov, mkv | 1, 2, 4, 8 (palettised or grey), 16, 24, 32 (alpha) |
|
||||
| `smc` | QuickTime Graphics (`smc `) | mov, mkv | 8-bit palettised |
|
||||
|
||||
Palettes come from the container: `track.palette` (256 entries, 4 bytes each: R, G, B, A) holds the AVI
|
||||
BITMAPINFO palette or the QuickTime colour table (or the Macintosh default table it refers to); FLIC and Smacker
|
||||
frames carry their own palette changes.
|
||||
|
||||
```luau
|
||||
local v = assert(F.video.open(cinepakBytes)) -- Cinepak in a QuickTime movie
|
||||
assert(v.format == "mov" and v.codec == "cinepak")
|
||||
local frames = 0
|
||||
while true do
|
||||
local f = v:nextFrame()
|
||||
if not f then break end
|
||||
assert(f.image.format == "rgba8" and f.image.width == 64)
|
||||
frames += 1
|
||||
end
|
||||
assert(frames == v.frames)
|
||||
```
|
||||
|
||||
FLIC files (`.fli` at 70 Hz ticks, `.flc` / `.flx` in milliseconds) open as videos; the ring frame (an extra frame
|
||||
leading back to the first, for looping) is not shown unless you ask for it.
|
||||
|
||||
```luau
|
||||
local v = assert(F.video.open(flcBytes))
|
||||
print(v.format, v.codec, v.width, v.height, v.frameRate) -- fli flic 64 48 10
|
||||
assert(v.track.bitsPerPixel == 8 and v.frames == 10)
|
||||
local f = assert(v:nextFrame())
|
||||
local r, g, b, a = F.ops.image.getPixel(f.image, 0, 0) -- palette colours, opaque
|
||||
assert(r and g and b and a == 255)
|
||||
local all = assert(F.format("fli").open(F.Bytes.reader(flcBytes), { ringFrame = true }))
|
||||
assert(all.codec == "flic")
|
||||
```
|
||||
|
||||
Smacker files carry up to seven audio tracks. The format decodes Smacker's packed audio (and raw PCM tracks) itself:
|
||||
`v.audio` is the first track, `F.format("smk").openAudio(demuxer, track)` opens any of them.
|
||||
|
||||
```luau
|
||||
local v = assert(F.video.open(smkBytes))
|
||||
assert(v.format == "smk" and v.codec == "smackvid")
|
||||
local a = assert(v.audio, tostring(v.audioError)) -- packed 16-bit stereo, 22050 Hz
|
||||
assert(a.sampleRate == 22050 and a.channels == 2)
|
||||
local Smk = F.format("smk")
|
||||
for _, t in v.demuxer.tracks do
|
||||
if t.kind == "audio" then
|
||||
local dec = assert(Smk.openAudio(v.demuxer, t)) -- smackaudio, pcm_u8 or pcm_s16le
|
||||
local pcm, n = dec:read(1000)
|
||||
assert(n == 1000 and buffer.len(pcm) == n * dec.channels * 4)
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
## Gotchas
|
||||
|
||||
- Pure-Luau decoding is CPU-bound: H.264 and VP8 are practical at low resolutions. Measure with `tools/bench.luau`
|
||||
|
||||
@@ -28,6 +28,9 @@ F.convert(gif, "avi") -- animated images become videos (un
|
||||
| `codecs/video/Video/Source` | what writers write: copied packets or frames encoded by a registry encoder, PCM from the audio |
|
||||
| `codecs/image/Yuv` | yuv420p <-> rgba8 (BT.601 / 709, limited / full range from `image.meta.yuv`), range remap |
|
||||
| `codecs/image/Vp8`, `Jpeg`, `Mpeg1` | the decoders (and the JPEG encoder) |
|
||||
| `codecs/video/Mpeg2` (`Mpeg1` is the same module), `H264` | MPEG-1 / MPEG-2 and H.264 video decoders |
|
||||
| `codecs/video/Dsp` | 8x8 IDCT (bit-exact with `ffmpeg -idct int`) and half-pel motion compensation for the MPEG-style codecs |
|
||||
| `codecs/video/Legacy` | FLIC, Smacker, Cinepak, Microsoft Video 1, QuickTime RLE / SMC: rgba8, palettes from `track.palette` |
|
||||
| `video/<fmt>` | the formats: demux into `containers/Demux`, `open` = `Video.open(demuxer, opts)`, `encode` via Source |
|
||||
|
||||
Audio tracks reach the audio formats through the api hook `opts.openAudio(demuxer, track)` (a format never requires
|
||||
|
||||
Reference in new issue
Block a user