merge ws/idtech: UDMF (codecs/model/DoomMap), Doom 3 / Quake 4 .map + .proc, Wolf3D VSWAP + GAMEMAPS, codecs/text/Lexer
This commit is contained in:
commit
0e0b213a80
38 files changed
+11791
-2566
No files matched your search
@@ -46,7 +46,7 @@ print(F.detect(webp), #F.formats()) -- "webp", the format list
|
||||
## Formats
|
||||
|
||||
<!-- formats:begin -->
|
||||
181 formats. Generated from the format contracts by `tools/gen_registry.py`; [docs/FORMATS.md](docs/FORMATS.md)
|
||||
186 formats. Generated from the format contracts by `tools/gen_registry.py`; [docs/FORMATS.md](docs/FORMATS.md)
|
||||
adds each format's capabilities.
|
||||
|
||||
| Category | Format | Extensions | Read | Write |
|
||||
@@ -114,6 +114,7 @@ adds each format's capabilities.
|
||||
| 3D models | b3d | .b3d | yes | - |
|
||||
| 3D models | bsp | .bsp | yes | - |
|
||||
| 3D models | buildmap | .map | yes | yes |
|
||||
| 3D models | d3map | .map | yes | - |
|
||||
| 3D models | dae | .dae .zae | yes | yes |
|
||||
| 3D models | fbx | .fbx | yes | yes |
|
||||
| 3D models | gltf | .gltf .glb | yes | yes |
|
||||
@@ -131,6 +132,7 @@ adds each format's capabilities.
|
||||
| 3D models | off | .off | yes | yes |
|
||||
| 3D models | ply | .ply | yes | yes |
|
||||
| 3D models | pmx | .pmx .pmd | yes | - |
|
||||
| 3D models | proc | .proc | yes | - |
|
||||
| 3D models | qb | .qb | yes | yes |
|
||||
| 3D models | rbxm | .rbxm .rbxl | yes | yes |
|
||||
| 3D models | rbxmx | .rbxmx .rbxlx | yes | yes |
|
||||
@@ -139,6 +141,7 @@ adds each format's capabilities.
|
||||
| 3D models | smd | .smd | yes | yes |
|
||||
| 3D models | sourcemdl | .mdl | yes | - |
|
||||
| 3D models | stl | .stl | yes | yes |
|
||||
| 3D models | udmf | .udmf .textmap | yes | - |
|
||||
| 3D models | usda | .usda .usd .usdz | yes | yes |
|
||||
| 3D models | vbsp | .bsp | yes | - |
|
||||
| 3D models | vmf | .vmf .vmx | yes | yes |
|
||||
@@ -182,6 +185,7 @@ adds each format's capabilities.
|
||||
| Archives | tar | .tar | yes | yes |
|
||||
| Archives | uu | .uu .uue .xxe .b64 | yes | yes |
|
||||
| Archives | vpk | .vpk | yes | yes |
|
||||
| Archives | vswap | .wl6 .wl1 .sod .sdm .vswap | yes | - |
|
||||
| Archives | wad | .wad | yes | yes |
|
||||
| Archives | xz | .xz .txz .lzma | yes | - |
|
||||
| Archives | yenc | .yenc .ync | yes | yes |
|
||||
@@ -201,6 +205,7 @@ adds each format's capabilities.
|
||||
| Data | vdf | .vdf .acf .res .kv | yes | yes |
|
||||
| Data | xml | .xml .xsd .xsl .xslt .rss .atom .xhtml | yes | yes |
|
||||
| Data | yaml | .yaml .yml | yes | yes |
|
||||
| Vector graphics and tile maps | gamemaps | .wl6 .wl1 .sod .sdm | yes | - |
|
||||
| Vector graphics and tile maps | svg | .svg | yes | yes |
|
||||
| Vector graphics and tile maps | tiled | .tmx .tmj .tsx .tsj | yes | yes |
|
||||
| Layered images | aseprite | .aseprite .ase | yes | yes |
|
||||
@@ -247,8 +252,8 @@ Shared by the formats, not loadable on their own (`src/Rosetta/codecs/<domain>/`
|
||||
| entropy | Huffman, RangeCoder |
|
||||
| font | Bitmap, Cff, GlyphNames, TrueType |
|
||||
| image | Bcn, Blend, Dct, Etc, Half, Jpeg, Miptex, Pixels, Quantize, Raster, Texel, Texture, Vp8, Vp8L, Yuv |
|
||||
| model | Brush, Displacement, Draco, Mat4, MeshFlatten, Minecraft, Patch, Polygon, Rbx, Rig, Sampler, SourceAnim, Vrml |
|
||||
| text | Json, KeyValues, Nbt, Text, Url, Xml |
|
||||
| model | Brush, Displacement, DoomMap, Draco, Mat4, MeshFlatten, Minecraft, Patch, Polygon, Rbx, Rig, Sampler, SourceAnim, Vrml |
|
||||
| text | Json, KeyValues, Lexer, Nbt, Text, Url, Xml |
|
||||
| video | Dsp, H263, H264, Legacy, Mpeg1, Mpeg2, Theora, Video |
|
||||
| containers | Archive, AudioWrap, Avi, Chunks, Cpio, Demux, Ebml, Fat, Iso9660, IsoBmff, MacFile, MpegEs, MpegPs, MpegTs, Ogg, Riff, Tar, Zip |
|
||||
<!-- codecs:end -->
|
||||
|
||||
+2401
-441
File diff suppressed because it is too large.
Load diff
+571
-562
File diff suppressed because it is too large.
Load diff
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"Core_1": [[8, "src/Rosetta/init.luau"], [852, "src/Rosetta/Registry.luau"], [3045, "src/Rosetta/Types.luau"], [4128, "src/Rosetta/codecs/audio/Adpcm/init.luau"], [4882, "src/Rosetta/codecs/image/Yuv.luau"], [5150, "src/Rosetta/codecs/model/Rbx/init.luau"], [5387, "src/Rosetta/codecs/video/Video/init.luau"], [5944, "src/Rosetta/containers/AudioWrap.luau"], [6447, "src/Rosetta/containers/Ogg/Mux.luau"], [6642, "src/Rosetta/containers/Ogg/Page.luau"], [6811, "src/Rosetta/core/Bytes.luau"], [7338, "src/Rosetta/core/Crc32.luau"], [7450, "src/Rosetta/core/Err.luau"], [7532, "src/Rosetta/core/Input.luau"], [7608, "src/Rosetta/host/init.luau"]],
|
||||
"Core_1": [[8, "src/Rosetta/init.luau"], [852, "src/Rosetta/Registry.luau"], [3105, "src/Rosetta/Types.luau"], [4188, "src/Rosetta/codecs/audio/Adpcm/init.luau"], [4942, "src/Rosetta/codecs/image/Yuv.luau"], [5210, "src/Rosetta/codecs/model/Rbx/init.luau"], [5447, "src/Rosetta/codecs/video/Video/init.luau"], [6004, "src/Rosetta/containers/AudioWrap.luau"], [6507, "src/Rosetta/containers/Ogg/Mux.luau"], [6702, "src/Rosetta/containers/Ogg/Page.luau"], [6871, "src/Rosetta/core/Bytes.luau"], [7398, "src/Rosetta/core/Crc32.luau"], [7510, "src/Rosetta/core/Err.luau"], [7592, "src/Rosetta/core/Input.luau"], [7668, "src/Rosetta/host/init.luau"]],
|
||||
"Core_2": [[8, "src/Rosetta/ops/ImageOps/init.luau"], [652, "src/Rosetta/ops/ImageOps/Kernels.luau"]],
|
||||
"Mpeg2": [[8, "src/Rosetta/codecs/video/Dsp.luau"], [731, "src/Rosetta/codecs/video/Mpeg1/init.luau"], [743, "src/Rosetta/codecs/video/Mpeg2/init.luau"], [1110, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], [2617, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], [2756, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"]],
|
||||
"H263": [[8, "src/Rosetta/codecs/video/H263/init.luau"], [164, "src/Rosetta/codecs/video/H263/Decoder.luau"], [1022, "src/Rosetta/codecs/video/H263/Tables.luau"]],
|
||||
@@ -27,8 +27,8 @@
|
||||
"Hively": [[8, "src/Rosetta/codecs/audio/Hively/init.luau"], [204, "src/Rosetta/codecs/audio/Hively/Load.luau"], [453, "src/Rosetta/codecs/audio/Hively/Player.luau"], [1411, "src/Rosetta/codecs/audio/Hively/Tables.luau"]],
|
||||
"SoundFont": [[8, "src/Rosetta/codecs/audio/SoundFont/init.luau"], [62, "src/Rosetta/codecs/audio/SoundFont/Fallback.luau"], [205, "src/Rosetta/codecs/audio/SoundFont/Parse.luau"], [718, "src/Rosetta/codecs/audio/SoundFont/Synth.luau"]],
|
||||
"Draco": [[8, "src/Rosetta/codecs/model/Draco/init.luau"], [340, "src/Rosetta/codecs/model/Draco/Attributes.luau"], [809, "src/Rosetta/codecs/model/Draco/Connectivity.luau"], [1998, "src/Rosetta/codecs/model/Draco/Int64.luau"], [2147, "src/Rosetta/codecs/model/Draco/KdTree.luau"], [2506, "src/Rosetta/codecs/model/Draco/Predict.luau"], [3468, "src/Rosetta/codecs/model/Draco/Reader.luau"]],
|
||||
"archive_1": [[8, "src/Rosetta/archive/7z/init.luau"], [393, "src/Rosetta/archive/7z/Header.luau"], [920, "src/Rosetta/archive/adf/init.luau"], [1202, "src/Rosetta/archive/applesingle/init.luau"], [1388, "src/Rosetta/archive/ar/init.luau"], [1791, "src/Rosetta/archive/arj/init.luau"], [2001, "src/Rosetta/archive/binhex/init.luau"], [2250, "src/Rosetta/archive/br/init.luau"], [2325, "src/Rosetta/archive/bz2/init.luau"], [2389, "src/Rosetta/archive/cab/init.luau"], [2802, "src/Rosetta/archive/cab/Sum.luau"], [2843, "src/Rosetta/archive/cpio/init.luau"], [3011, "src/Rosetta/archive/d64/init.luau"], [3425, "src/Rosetta/archive/fat/init.luau"], [3547, "src/Rosetta/archive/grp/init.luau"], [3661, "src/Rosetta/archive/gzip/init.luau"], [3846, "src/Rosetta/archive/iso/init.luau"], [3918, "src/Rosetta/archive/lha/init.luau"], [4343, "src/Rosetta/archive/lz4/init.luau"], [4687, "src/Rosetta/archive/macbinary/init.luau"], [4885, "src/Rosetta/archive/mpq/init.luau"], [5291, "src/Rosetta/archive/mpq/Crypt.luau"], [5356, "src/Rosetta/archive/pak/init.luau"], [5490, "src/Rosetta/archive/rpm/init.luau"], [5814, "src/Rosetta/archive/tar/init.luau"], [5932, "src/Rosetta/archive/uu/init.luau"], [6202, "src/Rosetta/archive/vpk/init.luau"], [6513, "src/Rosetta/archive/wad/init.luau"], [6963, "src/Rosetta/archive/wad/Map.luau"], [7393, "src/Rosetta/archive/wad/Picture.luau"], [7495, "src/Rosetta/archive/xz/init.luau"], [7595, "src/Rosetta/archive/yenc/init.luau"], [7867, "src/Rosetta/archive/z/init.luau"]],
|
||||
"archive_2": [[8, "src/Rosetta/archive/zip/init.luau"], [227, "src/Rosetta/archive/zoo/init.luau"], [423, "src/Rosetta/archive/zst/init.luau"]],
|
||||
"archive_1": [[8, "src/Rosetta/archive/7z/init.luau"], [393, "src/Rosetta/archive/7z/Header.luau"], [920, "src/Rosetta/archive/adf/init.luau"], [1202, "src/Rosetta/archive/applesingle/init.luau"], [1388, "src/Rosetta/archive/ar/init.luau"], [1791, "src/Rosetta/archive/arj/init.luau"], [2001, "src/Rosetta/archive/binhex/init.luau"], [2250, "src/Rosetta/archive/br/init.luau"], [2325, "src/Rosetta/archive/bz2/init.luau"], [2389, "src/Rosetta/archive/cab/init.luau"], [2802, "src/Rosetta/archive/cab/Sum.luau"], [2843, "src/Rosetta/archive/cpio/init.luau"], [3011, "src/Rosetta/archive/d64/init.luau"], [3425, "src/Rosetta/archive/fat/init.luau"], [3547, "src/Rosetta/archive/grp/init.luau"], [3661, "src/Rosetta/archive/gzip/init.luau"], [3846, "src/Rosetta/archive/iso/init.luau"], [3918, "src/Rosetta/archive/lha/init.luau"], [4343, "src/Rosetta/archive/lz4/init.luau"], [4687, "src/Rosetta/archive/macbinary/init.luau"], [4885, "src/Rosetta/archive/mpq/init.luau"], [5291, "src/Rosetta/archive/mpq/Crypt.luau"], [5356, "src/Rosetta/archive/pak/init.luau"], [5490, "src/Rosetta/archive/rpm/init.luau"], [5814, "src/Rosetta/archive/tar/init.luau"], [5932, "src/Rosetta/archive/uu/init.luau"], [6202, "src/Rosetta/archive/vpk/init.luau"], [6513, "src/Rosetta/archive/vswap/init.luau"], [6783, "src/Rosetta/archive/wad/init.luau"], [7237, "src/Rosetta/archive/wad/Picture.luau"], [7339, "src/Rosetta/archive/xz/init.luau"], [7439, "src/Rosetta/archive/yenc/init.luau"], [7711, "src/Rosetta/archive/z/init.luau"], [7807, "src/Rosetta/archive/zip/init.luau"]],
|
||||
"archive_2": [[8, "src/Rosetta/archive/zoo/init.luau"], [204, "src/Rosetta/archive/zst/init.luau"]],
|
||||
"audio": [[8, "src/Rosetta/audio/aac/init.luau"], [214, "src/Rosetta/audio/ac3/init.luau"], [360, "src/Rosetta/audio/adpcm/init.luau"], [505, "src/Rosetta/audio/adx/init.luau"], [736, "src/Rosetta/audio/aiff/init.luau"], [1127, "src/Rosetta/audio/ape/init.luau"], [1255, "src/Rosetta/audio/au/init.luau"], [1416, "src/Rosetta/audio/brstm/init.luau"], [1707, "src/Rosetta/audio/caf/init.luau"], [2369, "src/Rosetta/audio/flac/init.luau"], [2517, "src/Rosetta/audio/flac/Meta.luau"], [2739, "src/Rosetta/audio/flac/Stream.luau"], [3109, "src/Rosetta/audio/m4a/init.luau"], [3443, "src/Rosetta/audio/mp3/init.luau"], [3703, "src/Rosetta/audio/mp3/Index.luau"], [3894, "src/Rosetta/audio/mp3/Stream.luau"], [4121, "src/Rosetta/audio/mp3/Tags.luau"], [4433, "src/Rosetta/audio/mpc/init.luau"], [4527, "src/Rosetta/audio/opus/init.luau"], [4905, "src/Rosetta/audio/opus/Encode.luau"], [5016, "src/Rosetta/audio/qoa/init.luau"], [5196, "src/Rosetta/audio/tta/init.luau"], [5314, "src/Rosetta/audio/vag/init.luau"], [5537, "src/Rosetta/audio/voc/init.luau"], [5812, "src/Rosetta/audio/vorbis/init.luau"], [6266, "src/Rosetta/audio/vorbis/Encode.luau"], [7079, "src/Rosetta/audio/wav/init.luau"], [7700, "src/Rosetta/audio/wav/Codecs.luau"], [7866, "src/Rosetta/audio/wavpack/init.luau"]],
|
||||
"cad": [[8, "src/Rosetta/cad/step/init.luau"], [390, "src/Rosetta/cad/step/Brep.luau"], [625, "src/Rosetta/cad/step/Parse.luau"], [1182, "src/Rosetta/cad/step/Write.luau"]],
|
||||
"codecs_audio": [[8, "src/Rosetta/codecs/audio/Ac3/init.luau"], [167, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], [1052, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], [1153, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], [1455, "src/Rosetta/codecs/audio/Alac/init.luau"], [1689, "src/Rosetta/codecs/audio/Alac/Decode.luau"], [2108, "src/Rosetta/codecs/audio/Alac/Encode.luau"], [2520, "src/Rosetta/codecs/audio/Ape/init.luau"], [2735, "src/Rosetta/codecs/audio/Ape/Decode.luau"], [3496, "src/Rosetta/codecs/audio/ApeTag.luau"], [3593, "src/Rosetta/codecs/audio/Mdct/init.luau"], [3777, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], [3986, "src/Rosetta/codecs/audio/MidiRender.luau"], [4332, "src/Rosetta/codecs/audio/Pcm/init.luau"], [4595, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], [4892, "src/Rosetta/codecs/audio/Qoa/init.luau"], [5174, "src/Rosetta/codecs/audio/Resample/init.luau"], [5533, "src/Rosetta/codecs/audio/Stream.luau"], [5694, "src/Rosetta/codecs/audio/Tta/init.luau"], [5811, "src/Rosetta/codecs/audio/Tta/Decode.luau"], [6063, "src/Rosetta/codecs/audio/VorbisComment.luau"]],
|
||||
@@ -36,8 +36,8 @@
|
||||
"codecs_entropy": [[8, "src/Rosetta/codecs/entropy/Huffman.luau"], [290, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], [301, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], [515, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"]],
|
||||
"codecs_font": [[8, "src/Rosetta/codecs/font/Bitmap.luau"], [209, "src/Rosetta/codecs/font/Cff/init.luau"], [850, "src/Rosetta/codecs/font/GlyphNames.luau"], [1000, "src/Rosetta/codecs/font/TrueType/init.luau"], [1314, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], [1706, "src/Rosetta/codecs/font/TrueType/Tables.luau"]],
|
||||
"codecs_image": [[8, "src/Rosetta/codecs/image/Blend.luau"], [387, "src/Rosetta/codecs/image/Etc.luau"], [685, "src/Rosetta/codecs/image/Half.luau"], [754, "src/Rosetta/codecs/image/Miptex.luau"], [970, "src/Rosetta/codecs/image/Pixels.luau"], [1290, "src/Rosetta/codecs/image/Quantize/init.luau"], [1749, "src/Rosetta/codecs/image/Raster.luau"], [2446, "src/Rosetta/codecs/image/Texel.luau"], [2819, "src/Rosetta/codecs/image/Texture.luau"]],
|
||||
"codecs_model": [[8, "src/Rosetta/codecs/model/Brush.luau"], [648, "src/Rosetta/codecs/model/Displacement.luau"], [797, "src/Rosetta/codecs/model/Mat4.luau"], [1056, "src/Rosetta/codecs/model/MeshFlatten.luau"], [1584, "src/Rosetta/codecs/model/Minecraft/init.luau"], [2136, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], [2215, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], [2322, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], [2528, "src/Rosetta/codecs/model/Patch.luau"], [2652, "src/Rosetta/codecs/model/Polygon.luau"], [2886, "src/Rosetta/codecs/model/Rbx/Binary.luau"], [3640, "src/Rosetta/codecs/model/Rig.luau"], [3883, "src/Rosetta/codecs/model/Sampler.luau"], [4043, "src/Rosetta/codecs/model/SourceAnim.luau"], [4264, "src/Rosetta/codecs/model/Vrml/init.luau"], [4412, "src/Rosetta/codecs/model/Vrml/Build.luau"], [4986, "src/Rosetta/codecs/model/Vrml/Fields.luau"], [5149, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], [5898, "src/Rosetta/codecs/model/Vrml/Parse.luau"], [6420, "src/Rosetta/codecs/model/Vrml/Write.luau"], [7147, "src/Rosetta/codecs/model/Vrml/Xml.luau"]],
|
||||
"codecs_text": [[8, "src/Rosetta/codecs/text/Json/init.luau"], [277, "src/Rosetta/codecs/text/Json/Decode.luau"], [691, "src/Rosetta/codecs/text/Json/Encode.luau"], [993, "src/Rosetta/codecs/text/KeyValues/init.luau"], [1563, "src/Rosetta/codecs/text/KeyValues/Binary.luau"], [1869, "src/Rosetta/codecs/text/Nbt/init.luau"], [2222, "src/Rosetta/codecs/text/Nbt/Binary.luau"], [2914, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], [3554, "src/Rosetta/codecs/text/Nbt/Value.luau"], [3792, "src/Rosetta/codecs/text/Text/init.luau"], [3883, "src/Rosetta/codecs/text/Url/init.luau"], [4088, "src/Rosetta/codecs/text/Xml/init.luau"], [4491, "src/Rosetta/codecs/text/Xml/Parse.luau"]],
|
||||
"codecs_model": [[8, "src/Rosetta/codecs/model/Brush.luau"], [648, "src/Rosetta/codecs/model/Displacement.luau"], [797, "src/Rosetta/codecs/model/DoomMap/init.luau"], [1242, "src/Rosetta/codecs/model/DoomMap/Udmf.luau"], [1492, "src/Rosetta/codecs/model/Mat4.luau"], [1751, "src/Rosetta/codecs/model/MeshFlatten.luau"], [2279, "src/Rosetta/codecs/model/Minecraft/init.luau"], [2831, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], [2910, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], [3017, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], [3223, "src/Rosetta/codecs/model/Patch.luau"], [3347, "src/Rosetta/codecs/model/Polygon.luau"], [3581, "src/Rosetta/codecs/model/Rbx/Binary.luau"], [4335, "src/Rosetta/codecs/model/Rig.luau"], [4578, "src/Rosetta/codecs/model/Sampler.luau"], [4738, "src/Rosetta/codecs/model/SourceAnim.luau"], [4959, "src/Rosetta/codecs/model/Vrml/init.luau"], [5107, "src/Rosetta/codecs/model/Vrml/Build.luau"], [5681, "src/Rosetta/codecs/model/Vrml/Fields.luau"], [5844, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], [6593, "src/Rosetta/codecs/model/Vrml/Parse.luau"], [7115, "src/Rosetta/codecs/model/Vrml/Write.luau"], [7842, "src/Rosetta/codecs/model/Vrml/Xml.luau"]],
|
||||
"codecs_text": [[8, "src/Rosetta/codecs/text/Json/init.luau"], [277, "src/Rosetta/codecs/text/Json/Decode.luau"], [691, "src/Rosetta/codecs/text/Json/Encode.luau"], [993, "src/Rosetta/codecs/text/KeyValues/init.luau"], [1563, "src/Rosetta/codecs/text/KeyValues/Binary.luau"], [1869, "src/Rosetta/codecs/text/Lexer/init.luau"], [2001, "src/Rosetta/codecs/text/Nbt/init.luau"], [2354, "src/Rosetta/codecs/text/Nbt/Binary.luau"], [3046, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], [3686, "src/Rosetta/codecs/text/Nbt/Value.luau"], [3924, "src/Rosetta/codecs/text/Text/init.luau"], [4015, "src/Rosetta/codecs/text/Url/init.luau"], [4220, "src/Rosetta/codecs/text/Xml/init.luau"], [4623, "src/Rosetta/codecs/text/Xml/Parse.luau"]],
|
||||
"codecs_video": [[8, "src/Rosetta/codecs/video/Video/Source.luau"]],
|
||||
"containers": [[8, "src/Rosetta/containers/Archive.luau"], [275, "src/Rosetta/containers/Avi/init.luau"], [827, "src/Rosetta/containers/Chunks.luau"], [962, "src/Rosetta/containers/Cpio.luau"], [1390, "src/Rosetta/containers/Demux.luau"], [1665, "src/Rosetta/containers/Ebml/init.luau"], [1978, "src/Rosetta/containers/Fat.luau"], [2666, "src/Rosetta/containers/Iso9660.luau"], [3171, "src/Rosetta/containers/IsoBmff/init.luau"], [3341, "src/Rosetta/containers/IsoBmff/Box.luau"], [3529, "src/Rosetta/containers/IsoBmff/Demux.luau"], [4374, "src/Rosetta/containers/IsoBmff/Meta.luau"], [4895, "src/Rosetta/containers/IsoBmff/Mux.luau"], [5411, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], [5528, "src/Rosetta/containers/MacFile.luau"], [5677, "src/Rosetta/containers/Ogg/init.luau"], [6102, "src/Rosetta/containers/Riff/init.luau"], [6419, "src/Rosetta/containers/Tar.luau"], [6833, "src/Rosetta/containers/Zip/init.luau"]],
|
||||
"core": [[8, "src/Rosetta/core/Adler32.luau"], [54, "src/Rosetta/core/Base64.luau"], [213, "src/Rosetta/core/Bits.luau"], [506, "src/Rosetta/core/Crc16.luau"], [558, "src/Rosetta/core/Md5.luau"], [717, "src/Rosetta/core/Sniff.luau"]],
|
||||
@@ -47,15 +47,15 @@
|
||||
"image_1": [[8, "src/Rosetta/image/ani/init.luau"], [188, "src/Rosetta/image/art/init.luau"], [676, "src/Rosetta/image/blp/init.luau"], [934, "src/Rosetta/image/bmp/init.luau"], [1349, "src/Rosetta/image/dds/init.luau"], [1832, "src/Rosetta/image/exr/init.luau"], [2592, "src/Rosetta/image/exr/Codec.luau"], [2703, "src/Rosetta/image/exr/Piz.luau"], [3060, "src/Rosetta/image/gif/init.luau"], [3576, "src/Rosetta/image/gif/Decode.luau"], [3639, "src/Rosetta/image/hdr/init.luau"], [3868, "src/Rosetta/image/hdr/Codec.luau"], [4079, "src/Rosetta/image/icns/init.luau"], [4410, "src/Rosetta/image/ico/init.luau"], [4687, "src/Rosetta/image/ico/Dib.luau"], [4782, "src/Rosetta/image/ilbm/init.luau"], [5101, "src/Rosetta/image/jpeg/init.luau"], [5237, "src/Rosetta/image/ktx/init.luau"], [5897, "src/Rosetta/image/pcx/init.luau"], [6161, "src/Rosetta/image/pnm/init.luau"], [6539, "src/Rosetta/image/pnm/Codec.luau"], [6816, "src/Rosetta/image/qoi/init.luau"], [6938, "src/Rosetta/image/qoi/Codec.luau"], [7088, "src/Rosetta/image/sgi/init.luau"], [7373, "src/Rosetta/image/sunras/init.luau"], [7619, "src/Rosetta/image/tga/init.luau"]],
|
||||
"image_2": [[8, "src/Rosetta/image/tga/Codec.luau"], [160, "src/Rosetta/image/tiff/init.luau"], [987, "src/Rosetta/image/tiff/Pixels.luau"], [1377, "src/Rosetta/image/tim/init.luau"], [1619, "src/Rosetta/image/vtf/init.luau"], [1854, "src/Rosetta/image/webp/init.luau"], [2464, "src/Rosetta/image/webp/Alpha.luau"], [2540, "src/Rosetta/image/webp/Anim.luau"], [2695, "src/Rosetta/image/xbm/init.luau"], [2856, "src/Rosetta/image/xpm/init.luau"], [3124, "src/Rosetta/image/xpm/Names.luau"]],
|
||||
"layered": [[8, "src/Rosetta/layered/aseprite/init.luau"], [746, "src/Rosetta/layered/ora/init.luau"], [1033, "src/Rosetta/layered/psd/init.luau"], [1768, "src/Rosetta/layered/psd/Channels.luau"]],
|
||||
"model_1": [[8, "src/Rosetta/model/3ds/init.luau"], [91, "src/Rosetta/model/3ds/Build.luau"], [738, "src/Rosetta/model/3ds/Read.luau"], [1234, "src/Rosetta/model/3ds/Write.luau"], [2039, "src/Rosetta/model/3mf/init.luau"], [2121, "src/Rosetta/model/3mf/Read.luau"], [2709, "src/Rosetta/model/3mf/Write.luau"], [3114, "src/Rosetta/model/b3d/init.luau"], [3169, "src/Rosetta/model/b3d/Read.luau"], [3740, "src/Rosetta/model/bsp/init.luau"], [3885, "src/Rosetta/model/bsp/Brush.luau"], [4148, "src/Rosetta/model/bsp/Quake3.luau"], [4376, "src/Rosetta/model/buildmap/init.luau"], [4648, "src/Rosetta/model/buildmap/Geometry.luau"], [5051, "src/Rosetta/model/dae/init.luau"], [5240, "src/Rosetta/model/dae/Math.luau"], [5287, "src/Rosetta/model/dae/Read.luau"], [7137, "src/Rosetta/model/dae/Write.luau"], [7506, "src/Rosetta/model/fbx/init.luau"]],
|
||||
"model_2": [[8, "src/Rosetta/model/fbx/Ascii.luau"], [278, "src/Rosetta/model/fbx/Binary.luau"], [733, "src/Rosetta/model/fbx/Read.luau"], [2095, "src/Rosetta/model/fbx/Write.luau"], [3080, "src/Rosetta/model/fbx/Xform.luau"], [3121, "src/Rosetta/model/gltf/init.luau"], [3358, "src/Rosetta/model/gltf/Pack.luau"], [3427, "src/Rosetta/model/gltf/Read.luau"], [4158, "src/Rosetta/model/gltf/Write.luau"], [4838, "src/Rosetta/model/iqm/init.luau"], [4914, "src/Rosetta/model/iqm/Read.luau"], [5269, "src/Rosetta/model/iqm/Write.luau"], [5956, "src/Rosetta/model/ldraw/init.luau"], [6034, "src/Rosetta/model/ldraw/Colors.luau"], [6352, "src/Rosetta/model/ldraw/Read.luau"], [6929, "src/Rosetta/model/lwo/init.luau"], [7005, "src/Rosetta/model/lwo/Build.luau"]],
|
||||
"model_3": [[8, "src/Rosetta/model/lwo/Parse.luau"], [551, "src/Rosetta/model/map/init.luau"], [868, "src/Rosetta/model/map/Build.luau"], [1111, "src/Rosetta/model/map/Parse.luau"], [1496, "src/Rosetta/model/map/Write.luau"], [1642, "src/Rosetta/model/mca/init.luau"], [1984, "src/Rosetta/model/mca/Chunk.luau"], [2117, "src/Rosetta/model/mca/Lz4Block.luau"], [2187, "src/Rosetta/model/md2/init.luau"], [2386, "src/Rosetta/model/md3/init.luau"], [2614, "src/Rosetta/model/md5/init.luau"], [2695, "src/Rosetta/model/md5/Read.luau"], [3128, "src/Rosetta/model/mdl/init.luau"], [3210, "src/Rosetta/model/mdl/HalfLife.luau"], [3514, "src/Rosetta/model/mdl/Quake.luau"], [3732, "src/Rosetta/model/ms3d/init.luau"], [3804, "src/Rosetta/model/ms3d/Read.luau"], [4250, "src/Rosetta/model/ms3d/Write.luau"], [4719, "src/Rosetta/model/obj/init.luau"], [5461, "src/Rosetta/model/obj/Mtl.luau"], [5748, "src/Rosetta/model/off/init.luau"], [6210, "src/Rosetta/model/ply/init.luau"], [7315, "src/Rosetta/model/ply/Binary.luau"], [7516, "src/Rosetta/model/pmx/init.luau"], [7585, "src/Rosetta/model/pmx/Build.luau"]],
|
||||
"model_4": [[8, "src/Rosetta/model/pmx/Pmd.luau"], [343, "src/Rosetta/model/pmx/Read.luau"], [747, "src/Rosetta/model/qb/init.luau"], [1140, "src/Rosetta/model/rbxm/init.luau"], [1732, "src/Rosetta/model/rbxmx/init.luau"], [2385, "src/Rosetta/model/robloxmesh/init.luau"], [3044, "src/Rosetta/model/robloxmesh/Parse.luau"], [3501, "src/Rosetta/model/robloxmesh/Write.luau"], [3610, "src/Rosetta/model/schematic/init.luau"], [3931, "src/Rosetta/model/schematic/Common.luau"], [4051, "src/Rosetta/model/schematic/Litematic.luau"], [4262, "src/Rosetta/model/schematic/Mcedit.luau"], [4506, "src/Rosetta/model/schematic/Sponge.luau"], [4635, "src/Rosetta/model/smd/init.luau"], [4702, "src/Rosetta/model/smd/Read.luau"], [4971, "src/Rosetta/model/smd/Write.luau"], [5214, "src/Rosetta/model/sourcemdl/init.luau"], [5385, "src/Rosetta/model/sourcemdl/Build.luau"], [5815, "src/Rosetta/model/sourcemdl/Material.luau"], [5976, "src/Rosetta/model/sourcemdl/Mdl.luau"], [6503, "src/Rosetta/model/sourcemdl/Phy.luau"], [6626, "src/Rosetta/model/sourcemdl/Vtx.luau"], [6808, "src/Rosetta/model/sourcemdl/Vvd.luau"], [6902, "src/Rosetta/model/stl/init.luau"], [7352, "src/Rosetta/model/stl/Decode.luau"], [7426, "src/Rosetta/model/usda/init.luau"]],
|
||||
"model_5": [[8, "src/Rosetta/model/usda/Build.luau"], [1286, "src/Rosetta/model/usda/Parse.luau"], [2084, "src/Rosetta/model/usda/Write.luau"], [2901, "src/Rosetta/model/vbsp/init.luau"], [3347, "src/Rosetta/model/vbsp/Faces.luau"], [3571, "src/Rosetta/model/vbsp/Props.luau"], [3663, "src/Rosetta/model/vmf/init.luau"], [3988, "src/Rosetta/model/vmf/Build.luau"], [4412, "src/Rosetta/model/vox/init.luau"], [5298, "src/Rosetta/model/vox/Grid.luau"], [5355, "src/Rosetta/model/vrml/init.luau"], [5421, "src/Rosetta/model/x/init.luau"], [5551, "src/Rosetta/model/x/Build.luau"], [6114, "src/Rosetta/model/x/Parse.luau"], [6411, "src/Rosetta/model/x3d/init.luau"]],
|
||||
"model_1": [[8, "src/Rosetta/model/3ds/init.luau"], [91, "src/Rosetta/model/3ds/Build.luau"], [738, "src/Rosetta/model/3ds/Read.luau"], [1234, "src/Rosetta/model/3ds/Write.luau"], [2039, "src/Rosetta/model/3mf/init.luau"], [2121, "src/Rosetta/model/3mf/Read.luau"], [2709, "src/Rosetta/model/3mf/Write.luau"], [3114, "src/Rosetta/model/b3d/init.luau"], [3169, "src/Rosetta/model/b3d/Read.luau"], [3740, "src/Rosetta/model/bsp/init.luau"], [3885, "src/Rosetta/model/bsp/Brush.luau"], [4148, "src/Rosetta/model/bsp/Quake3.luau"], [4376, "src/Rosetta/model/buildmap/init.luau"], [4648, "src/Rosetta/model/buildmap/Geometry.luau"], [5051, "src/Rosetta/model/d3map/init.luau"], [5333, "src/Rosetta/model/d3map/Parse.luau"], [5531, "src/Rosetta/model/dae/init.luau"], [5720, "src/Rosetta/model/dae/Math.luau"], [5767, "src/Rosetta/model/dae/Read.luau"]],
|
||||
"model_2": [[8, "src/Rosetta/model/dae/Write.luau"], [377, "src/Rosetta/model/fbx/init.luau"], [525, "src/Rosetta/model/fbx/Ascii.luau"], [795, "src/Rosetta/model/fbx/Binary.luau"], [1250, "src/Rosetta/model/fbx/Read.luau"], [2612, "src/Rosetta/model/fbx/Write.luau"], [3597, "src/Rosetta/model/fbx/Xform.luau"], [3638, "src/Rosetta/model/gltf/init.luau"], [3875, "src/Rosetta/model/gltf/Pack.luau"], [3944, "src/Rosetta/model/gltf/Read.luau"], [4675, "src/Rosetta/model/gltf/Write.luau"], [5355, "src/Rosetta/model/iqm/init.luau"], [5431, "src/Rosetta/model/iqm/Read.luau"], [5786, "src/Rosetta/model/iqm/Write.luau"], [6473, "src/Rosetta/model/ldraw/init.luau"], [6551, "src/Rosetta/model/ldraw/Colors.luau"], [6869, "src/Rosetta/model/ldraw/Read.luau"]],
|
||||
"model_3": [[8, "src/Rosetta/model/lwo/init.luau"], [84, "src/Rosetta/model/lwo/Build.luau"], [546, "src/Rosetta/model/lwo/Parse.luau"], [1089, "src/Rosetta/model/map/init.luau"], [1406, "src/Rosetta/model/map/Build.luau"], [1649, "src/Rosetta/model/map/Parse.luau"], [2034, "src/Rosetta/model/map/Write.luau"], [2180, "src/Rosetta/model/mca/init.luau"], [2522, "src/Rosetta/model/mca/Chunk.luau"], [2655, "src/Rosetta/model/mca/Lz4Block.luau"], [2725, "src/Rosetta/model/md2/init.luau"], [2924, "src/Rosetta/model/md3/init.luau"], [3152, "src/Rosetta/model/md5/init.luau"], [3233, "src/Rosetta/model/md5/Read.luau"], [3666, "src/Rosetta/model/mdl/init.luau"], [3748, "src/Rosetta/model/mdl/HalfLife.luau"], [4052, "src/Rosetta/model/mdl/Quake.luau"], [4270, "src/Rosetta/model/ms3d/init.luau"], [4342, "src/Rosetta/model/ms3d/Read.luau"], [4788, "src/Rosetta/model/ms3d/Write.luau"], [5257, "src/Rosetta/model/obj/init.luau"], [5999, "src/Rosetta/model/obj/Mtl.luau"], [6286, "src/Rosetta/model/off/init.luau"], [6748, "src/Rosetta/model/ply/init.luau"]],
|
||||
"model_4": [[8, "src/Rosetta/model/ply/Binary.luau"], [209, "src/Rosetta/model/pmx/init.luau"], [278, "src/Rosetta/model/pmx/Build.luau"], [574, "src/Rosetta/model/pmx/Pmd.luau"], [909, "src/Rosetta/model/pmx/Read.luau"], [1313, "src/Rosetta/model/proc/init.luau"], [1695, "src/Rosetta/model/qb/init.luau"], [2088, "src/Rosetta/model/rbxm/init.luau"], [2680, "src/Rosetta/model/rbxmx/init.luau"], [3333, "src/Rosetta/model/robloxmesh/init.luau"], [3992, "src/Rosetta/model/robloxmesh/Parse.luau"], [4449, "src/Rosetta/model/robloxmesh/Write.luau"], [4558, "src/Rosetta/model/schematic/init.luau"], [4879, "src/Rosetta/model/schematic/Common.luau"], [4999, "src/Rosetta/model/schematic/Litematic.luau"], [5210, "src/Rosetta/model/schematic/Mcedit.luau"], [5454, "src/Rosetta/model/schematic/Sponge.luau"], [5583, "src/Rosetta/model/smd/init.luau"], [5650, "src/Rosetta/model/smd/Read.luau"], [5919, "src/Rosetta/model/smd/Write.luau"], [6162, "src/Rosetta/model/sourcemdl/init.luau"], [6333, "src/Rosetta/model/sourcemdl/Build.luau"], [6763, "src/Rosetta/model/sourcemdl/Material.luau"], [6924, "src/Rosetta/model/sourcemdl/Mdl.luau"], [7451, "src/Rosetta/model/sourcemdl/Phy.luau"], [7574, "src/Rosetta/model/sourcemdl/Vtx.luau"], [7756, "src/Rosetta/model/sourcemdl/Vvd.luau"]],
|
||||
"model_5": [[8, "src/Rosetta/model/stl/init.luau"], [458, "src/Rosetta/model/stl/Decode.luau"], [532, "src/Rosetta/model/udmf/init.luau"], [615, "src/Rosetta/model/usda/init.luau"], [824, "src/Rosetta/model/usda/Build.luau"], [2102, "src/Rosetta/model/usda/Parse.luau"], [2900, "src/Rosetta/model/usda/Write.luau"], [3717, "src/Rosetta/model/vbsp/init.luau"], [4163, "src/Rosetta/model/vbsp/Faces.luau"], [4387, "src/Rosetta/model/vbsp/Props.luau"], [4479, "src/Rosetta/model/vmf/init.luau"], [4804, "src/Rosetta/model/vmf/Build.luau"], [5228, "src/Rosetta/model/vox/init.luau"], [6114, "src/Rosetta/model/vox/Grid.luau"], [6171, "src/Rosetta/model/vrml/init.luau"], [6237, "src/Rosetta/model/x/init.luau"], [6367, "src/Rosetta/model/x/Build.luau"], [6930, "src/Rosetta/model/x/Parse.luau"], [7227, "src/Rosetta/model/x3d/init.luau"]],
|
||||
"music": [[8, "src/Rosetta/music/669/init.luau"], [214, "src/Rosetta/music/ahx/init.luau"], [265, "src/Rosetta/music/far/init.luau"], [494, "src/Rosetta/music/hmp/init.luau"], [758, "src/Rosetta/music/hvl/init.luau"], [809, "src/Rosetta/music/it/init.luau"], [1227, "src/Rosetta/music/it/Itsex.luau"], [1343, "src/Rosetta/music/med/init.luau"], [1990, "src/Rosetta/music/midi/init.luau"], [2133, "src/Rosetta/music/midi/Smf.luau"], [2544, "src/Rosetta/music/mod/init.luau"], [2897, "src/Rosetta/music/mtm/init.luau"], [3119, "src/Rosetta/music/mus/init.luau"], [3276, "src/Rosetta/music/okt/init.luau"], [3557, "src/Rosetta/music/ptm/init.luau"], [3779, "src/Rosetta/music/s3m/init.luau"], [4015, "src/Rosetta/music/sf2/init.luau"], [4058, "src/Rosetta/music/stm/init.luau"], [4289, "src/Rosetta/music/ult/init.luau"], [4593, "src/Rosetta/music/umx/init.luau"], [4809, "src/Rosetta/music/xm/init.luau"], [5370, "src/Rosetta/music/xmi/init.luau"]],
|
||||
"ops": [[8, "src/Rosetta/ops/AudioOps.luau"], [457, "src/Rosetta/ops/LayerOps.luau"], [550, "src/Rosetta/ops/MeshOps/init.luau"], [1586, "src/Rosetta/ops/MeshOps/Greedy.luau"], [1753, "src/Rosetta/ops/MusicOps.luau"]],
|
||||
"playlist": [[8, "src/Rosetta/playlist/m3u/init.luau"], [361, "src/Rosetta/playlist/pls/init.luau"], [539, "src/Rosetta/playlist/xspf/init.luau"]],
|
||||
"subtitle": [[8, "src/Rosetta/subtitle/ass/init.luau"], [452, "src/Rosetta/subtitle/srt/init.luau"], [625, "src/Rosetta/subtitle/vtt/init.luau"]],
|
||||
"vector": [[8, "src/Rosetta/vector/svg/init.luau"], [94, "src/Rosetta/vector/svg/Parse.luau"], [840, "src/Rosetta/vector/svg/PathData.luau"], [1208, "src/Rosetta/vector/svg/Render.luau"], [1625, "src/Rosetta/vector/svg/Style.luau"], [1997, "src/Rosetta/vector/svg/Write.luau"], [2197, "src/Rosetta/vector/tiled/init.luau"], [2377, "src/Rosetta/vector/tiled/Data.luau"], [2528, "src/Rosetta/vector/tiled/Tmj.luau"], [3159, "src/Rosetta/vector/tiled/Tmx.luau"]],
|
||||
"vector": [[8, "src/Rosetta/vector/gamemaps/init.luau"], [195, "src/Rosetta/vector/gamemaps/Expand.luau"], [292, "src/Rosetta/vector/svg/init.luau"], [378, "src/Rosetta/vector/svg/Parse.luau"], [1124, "src/Rosetta/vector/svg/PathData.luau"], [1492, "src/Rosetta/vector/svg/Render.luau"], [1909, "src/Rosetta/vector/svg/Style.luau"], [2281, "src/Rosetta/vector/svg/Write.luau"], [2481, "src/Rosetta/vector/tiled/init.luau"], [2661, "src/Rosetta/vector/tiled/Data.luau"], [2812, "src/Rosetta/vector/tiled/Tmj.luau"], [3443, "src/Rosetta/vector/tiled/Tmx.luau"]],
|
||||
"video": [[8, "src/Rosetta/video/avi/init.luau"], [302, "src/Rosetta/video/fli/init.luau"], [453, "src/Rosetta/video/flv/init.luau"], [837, "src/Rosetta/video/flv/Amf.luau"], [995, "src/Rosetta/video/flv/Mux.luau"], [1276, "src/Rosetta/video/h264/init.luau"], [1415, "src/Rosetta/video/mkv/init.luau"], [1571, "src/Rosetta/video/mkv/Mux.luau"], [1850, "src/Rosetta/video/mkv/Parse.luau"], [2571, "src/Rosetta/video/mp4/init.luau"], [2899, "src/Rosetta/video/mpegps/init.luau"], [3086, "src/Rosetta/video/mpegts/init.luau"], [3324, "src/Rosetta/video/ogv/init.luau"], [3719, "src/Rosetta/video/smk/init.luau"], [4028, "src/Rosetta/video/smk/Audio.luau"], [4148, "src/Rosetta/video/y4m/init.luau"]]
|
||||
}
|
||||
+2491
-522
File diff suppressed because it is too large.
Load diff
+2401
-441
File diff suppressed because it is too large.
Load diff
+571
-562
File diff suppressed because it is too large.
Load diff
@@ -68,6 +68,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| model | b3d | .b3d | yes | - | materials: true, textures: true, skins: true, animation: true, colors: true | `tests/model/b3d.luau` |
|
||||
| model | bsp | .bsp | yes | - | variants: "quake", "halflife", "quake2", "quake3", lightmaps: "quake3" | `tests/model/bsp.luau` |
|
||||
| model | buildmap | .map | yes | yes | sprites: true, slopes: true | `tests/model/buildmap.luau` |
|
||||
| model | d3map | .map | yes | - | patches: true, variants: "doom3", "quake4" | `tests/model/d3map.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, draco: true | `tests/model/gltf.luau` |
|
||||
@@ -85,6 +86,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| 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 | proc | .proc | yes | - | portals: true | `tests/model/proc.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` |
|
||||
@@ -93,6 +95,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| model | smd | .smd | yes | yes | skins: true, animation: true | `tests/model/smd.luau` |
|
||||
| model | sourcemdl | .mdl | yes | - | skins: true, morph: true, animation: true, lods: true | `tests/model/sourcemdl.luau` |
|
||||
| model | stl | .stl | yes | yes | ascii: true, binary: true, colors: true, indexed: false | `tests/model/stl.luau` |
|
||||
| model | udmf | .udmf .textmap | yes | - | maps: true | `tests/model/udmf.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 | vbsp | .bsp | yes | - | versions: 19, 20, 21, displacements: true, staticProps: true, pak: true | `tests/model/vbsp.luau` |
|
||||
| model | vmf | .vmf .vmx | yes | yes | displacements: true, roundTrip: true | `tests/model/vmf.luau` |
|
||||
@@ -136,6 +139,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| 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` |
|
||||
| archive | vpk | .vpk | yes | yes | versions: 1, 2, multipart: true | `tests/archive/vpk.luau` |
|
||||
| archive | vswap | .wl6 .wl1 .sod .sdm .vswap | yes | - | images: true, sounds: true | `tests/archive/vswap.luau` |
|
||||
| archive | wad | .wad | yes | yes | images: true, maps: true, variants: "iwad", "pwad" | `tests/archive/wad.luau` |
|
||||
| archive | xz | .xz .txz .lzma | yes | - | stream: true, filters: "lzma2", "lzma", "delta", "x86", "powerpc", "arm", "armthumb", "sparc", "arm64" | `tests/archive/xz.luau` |
|
||||
| archive | yenc | .yenc .ync | yes | yes | multipart: true | `tests/archive/yenc.luau` |
|
||||
@@ -155,6 +159,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
|
||||
| data | vdf | .vdf .acf .res .kv | yes | yes | ordered: true, binary: true | `tests/data/vdf.luau` |
|
||||
| data | xml | .xml .xsd .xsl .xslt .rss .atom .xhtml | yes | yes | namespaces: true, streaming: true | `tests/data/xml.luau` |
|
||||
| data | yaml | .yaml .yml | yes | yes | ordered: true, multiDocument: true, anchors: true | `tests/data/yaml.luau` |
|
||||
| vector | gamemaps | .wl6 .wl1 .sod .sdm | yes | - | tilemap: true | `tests/vector/gamemaps.luau` |
|
||||
| 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` |
|
||||
@@ -255,6 +260,7 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
|
||||
- **model**
|
||||
- codecs/model/Brush: convex plane brushes -> polygons and Scene primitives, with Quake-family texture projection.
|
||||
- codecs/model/Displacement: Source engine displacement surfaces (VBSP ddispinfo_t / Hammer dispinfo), as
|
||||
- codecs/model/DoomMap: Doom / Heretic / Hexen binary map lumps (Hexen when BEHAVIOR is present) and UDMF TEXTMAP to
|
||||
- codecs/model/Draco: Google Draco geometry decompression (.drc; glTF KHR_draco_mesh_compression; Roblox mesh v6 / v7).
|
||||
- codecs/model/Mat4: 4x4 matrix (column-major, glTF / Types.Scene layout) and quaternion { x, y, z, w } helpers.
|
||||
- codecs/model/MeshFlatten: a Scene to one world-space mesh, for the writers of mesh-only formats (STL, PLY, OFF).
|
||||
@@ -269,6 +275,7 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
|
||||
- **text**
|
||||
- codecs/text/Json: JSON (RFC 8259 / ECMA-404) parse and serialize, the engine data/json, glTF, TMJ, ... use. New code.
|
||||
- codecs/text/KeyValues: Valve KeyValues text (tier1/KeyValues.cpp of the Source SDK 2013, srctools' reading of it)
|
||||
- codecs/text/Lexer: C-style tokens for id Tech / UDMF text (idLib idLexer conventions, UDMF 1.1 §I; no code taken):
|
||||
- codecs/text/Nbt: Minecraft's Named Binary Tag format and SNBT (Minecraft wiki "NBT format", wiki.vg "NBT").
|
||||
- codecs/text/Text: text decoding helpers: BOM stripping, Windows-1252 for text that is not UTF-8, line splitting.
|
||||
- codecs/text/Url: RFC 3986 reference resolution (section 5.2), local-path classification and percent-encoding.
|
||||
|
||||
@@ -36,6 +36,9 @@ src/Rosetta/
|
||||
text/ Json KeyValues Nbt Text Url Xml
|
||||
font/ Bitmap Cff GlyphNames TrueType
|
||||
model/ Brush Displacement Draco Mat4 MeshFlatten Minecraft Patch Polygon Rbx Rig Sampler SourceAnim Vrml
|
||||
text/ Json Lexer Nbt Text Url Xml
|
||||
font/ Bitmap Cff GlyphNames TrueType
|
||||
model/ Brush DoomMap Draco Mat4 MeshFlatten Minecraft Patch Polygon Rbx Rig Sampler Vrml
|
||||
host/ host (layer 2) runtime adapters; only the api uses them
|
||||
Types.luau types (layer 1) standard types + constructors
|
||||
core/ core (layer 0) Adler32 Base64 Bits Bytes Crc16 Crc32 Err Input
|
||||
@@ -243,6 +246,8 @@ them. Anything generic goes down a layer and is called:
|
||||
| animation channels sampled at a time; game-model frames, joints and skins -> Scene | `codecs/model/Sampler`, `codecs/model/Rig` |
|
||||
| polygons with holes -> triangles | `codecs/model/Polygon` |
|
||||
| studio model animation values (GoldSrc / Source run-length shorts, Quaternion48 / 64, bone records) | `codecs/model/SourceAnim` |
|
||||
| Doom-engine maps (binary lumps, UDMF) -> tables and a Scene | `codecs/model/DoomMap` |
|
||||
| C-style tokens (id Tech / UDMF text: comments, strings, numbers, words) | `codecs/text/Lexer` |
|
||||
| plane brushes -> polygons (CSG hull, coplanar merge, Quake / Valve 220 / brush-primitive texturing); Bezier patches | `codecs/model/Brush`, `codecs/model/Patch` |
|
||||
| Quake / GoldSrc mip textures, WAD2 / WAD3 directories; palettes (keyed index, grey, colormap) | `codecs/image/Miptex`, `codecs/image/Pixels` |
|
||||
| NBT / SNBT values; Minecraft block states and colours | `codecs/text/Nbt`, `codecs/model/Minecraft` |
|
||||
|
||||
+19
-2
@@ -210,7 +210,7 @@ assert(F.archive.load(bytes):read("maps/e1m1.bsp"))
|
||||
A WAD's lumps keep their order; lumps of a map are named `"<map>/<lump>"` (`"E1M1/THINGS"`) and repeated names get
|
||||
`"~2"`, `"~3"`, ... so every entry is unique (writing strips both again). The format module turns lumps into game
|
||||
data: graphics (flats, patches, sprites, menu pictures) into Images through the `PLAYPAL` palette, wall textures
|
||||
composed from their patches, and maps into a Scene (z up, map units: floors and ceilings triangulated from the
|
||||
composed from their patches, and maps (binary lumps or UDMF `TEXTMAP`) into a Scene (z up, map units: floors and ceilings triangulated from the
|
||||
sector outlines, walls, things as nodes standing on their floor).
|
||||
|
||||
```luau
|
||||
@@ -254,6 +254,22 @@ local named = assert(F.archive.load(mpqBytes, { names = { "war3map.w3e" } }))
|
||||
assert(#named:list() >= 2)
|
||||
```
|
||||
|
||||
Wolfenstein 3D's page file (`VSWAP.WL6`, also `.WL1`, Spear of Destiny's `.SOD` / `.SDM`) loads as an Archive of
|
||||
its pages (`walls/000`, `sprites/000`, `sounds/000`, `soundinfo`). The format module turns walls and sprites into
|
||||
64 x 64 Images and the digitized sounds into Audio. The game's palette is not part of the file (nor redistributable):
|
||||
pass its 768 bytes as `palette` (6-bit VGA values are scaled up); without it the images are grey.
|
||||
|
||||
```luau
|
||||
local Vswap = F.format("vswap")
|
||||
local pages = assert(F.archive.load(vswapBytes, { name = "VSWAP.WL6" }))
|
||||
assert(pages:list()[1].name == "walls/000")
|
||||
local wall = assert(Vswap.image(pages, "wall", 0, { palette = wolfPaletteBytes }))
|
||||
local guard = assert(Vswap.image(pages, "sprite", 0, { palette = wolfPaletteBytes })) -- alpha 0 = hole
|
||||
assert(wall.width == 64 and guard.height == 64)
|
||||
local sound = assert(Vswap.sound(pages, 1)) -- u8 PCM at 7042 Hz, as f32 Audio
|
||||
assert(sound.sampleRate == 7042 and Vswap.sounds(pages) == 2)
|
||||
```
|
||||
|
||||
## Unix, package and disc archives
|
||||
|
||||
### cpio
|
||||
@@ -431,7 +447,8 @@ assert(F.archive.load(out):list()[1].method == "store")
|
||||
| bzip2 (`.bz2`, `.tbz2`) | yes | - | single stream |
|
||||
| Brotli (`.br`) | yes | - | single stream; no magic number, so pass a `.br` name or `format = "br"` |
|
||||
| PAK (`.pak`) | yes | yes | Quake / Quake II / Half-Life (and SiN `SPAK`) |
|
||||
| WAD (`.wad`) | yes | yes | IWAD / PWAD; lumps, graphics, wall textures and maps through `F.format("wad")` |
|
||||
| WAD (`.wad`) | yes | yes | IWAD / PWAD; lumps, graphics, wall textures and maps (binary and UDMF) through `F.format("wad")` |
|
||||
| VSWAP (Wolfenstein 3D `.wl6` / `.wl1` / `.sod` / `.sdm`) | yes | | pages; walls, sprites and sounds through `F.format("vswap")` |
|
||||
| GRP (`.grp`) | yes | yes | Build engine |
|
||||
| VPK (`.vpk`) | yes | yes | versions 1 / 2, multi-part reading, preload bytes; writes one directory file |
|
||||
| MPQ (`.mpq`, `.w3x`, `.sc2map`, ...) | yes | - | versions 1-4 (classic tables), encryption; no Huffman / ADPCM (WAVE) sectors |
|
||||
|
||||
@@ -625,6 +625,56 @@ local built = assert(F.model.load(assert(F.saveString(doc, { format = "vmf" })),
|
||||
assert(#built.meshes[1].primitives == 1 and built.meta.entities[2].classname == "info_player_start")
|
||||
```
|
||||
|
||||
## Doom maps (UDMF)
|
||||
|
||||
Doom-engine maps load as Scenes (z up, map units): floors and ceilings triangulated from the sector outlines, walls
|
||||
with vanilla texture alignment, things as child nodes standing on their floor. Maps inside a WAD (binary lumps or a
|
||||
UDMF `TEXTMAP`) load through `F.format("wad").map(wad, name)` (see the archive page); a standalone UDMF text
|
||||
(`.udmf`, or a `TEXTMAP` lump saved alone) loads directly, with texture sizes from `textureSize` (else 64 x 128 walls
|
||||
and 64 x 64 flats) and the textures as URIs. `F.format("udmf").data` gives the tables: every UDMF block keeps its
|
||||
fields as written (`fields`, lower-case keys: namespace and `user_` keys too), flags are rebuilt in the binary layout
|
||||
(Doom bits for the Doom / Heretic / Strife namespaces, Hexen bits otherwise), and unknown blocks stay in `blocks`.
|
||||
|
||||
```luau
|
||||
local room = assert(F.model.load(udmfText))
|
||||
assert(room.meta.source.format == "udmf" and room.meta.source.namespace == "ZDoom")
|
||||
assert(room.nodes[3].translation[3] == 40) -- a thing 8 units above the 32-unit pillar
|
||||
local Udmf = F.format("udmf")
|
||||
local data = assert(Udmf.data(F.Bytes.reader(buffer.fromstring(udmfText))))
|
||||
assert(data.sectors[1].fields.user_gravity == 0.5)
|
||||
assert(data.linedefs[4].tag == 7 and data.blocks[1].type == "vavoombox")
|
||||
```
|
||||
|
||||
## Doom 3 / Quake 4 levels
|
||||
|
||||
A compiled `.proc` file (dmap's render geometry: `mapProcFile003`, Quake 4's `PROC "4"`) loads as a Scene: each model
|
||||
(the areas `_area0`, `_area1`, ... and the inline models of entities) is a mesh with a primitive per surface
|
||||
(positions, normals, texture coordinates, Quake 4 vertex colours as `COLOR_0`) and a child node of the root; the
|
||||
materials are URIs. id Tech 4 triangles are clockwise-front, so they are turned counter-clockwise. The portals between
|
||||
areas, the BSP nodes and the shadow models load as data in `meta.proc`.
|
||||
|
||||
The editor's `.map` (`Version 2` for Doom 3, `Version 3` for Quake 4; told apart from Quake's `.map` by that line)
|
||||
loads as a Scene too: `brushDef3` brushes (plane equations) become polygons through the same brush clipper as the
|
||||
Quake maps, with Doom 3's texture matrices, and `patchDef2` / `patchDef3` surfaces become triangle grids (patchDef3 at
|
||||
its stored subdivisions, patchDef2 at `patchLevel` segments per sub-patch). Each entity is a node with its keys in
|
||||
`extras.keys`; entities with geometry get a mesh (in world coordinates), point entities their `origin`, `rotation`
|
||||
or `angle`. `skip` leaves materials out (`"textures/common/caulk"`), `hull` drops faces hidden inside other brushes.
|
||||
|
||||
```luau
|
||||
local level = assert(F.model.load(procText))
|
||||
assert(level.meshes[1].name == "_area0" and level.meta.up == "z")
|
||||
local proc = level.meta.proc
|
||||
assert(proc.areas == 2 and proc.portals[1].positive == 1 and #proc.portals[1].points == 12)
|
||||
assert(proc.nodes[1].negative == -1) -- < 0: area -1 - n; > 0: a node (1-based); 0: solid
|
||||
assert(level.materials[1].name == "textures/base_wall/lfwall1")
|
||||
|
||||
local room = assert(F.model.load(d3mapText, { name = "room.map", skip = { "textures/common/caulk" } }))
|
||||
assert(room.meta.source.format == "d3map" and room.meta.source.variant == "doom3")
|
||||
assert(#room.meshes[1].primitives == 1) -- the floor material; caulk skipped
|
||||
local start = room.nodes[3]
|
||||
assert(start.extras.classname == "info_player_start" and start.translation[3] == 1)
|
||||
```
|
||||
|
||||
## Blitz3D (B3D)
|
||||
|
||||
`.b3d` files (Blitz3D, also written by many old game tools) load read-only. The node tree keeps its names and TRS;
|
||||
@@ -868,6 +918,9 @@ assert(back.meshes[1].primitives[1].indices.count == 3)
|
||||
| MD2, MD3, MDL, MD5, BSP, VBSP | yes | - | game models and maps: see "Game models" above |
|
||||
| VMF | yes | yes (round trip, builders) | Hammer maps: see "Hammer maps (VMF)" above |
|
||||
| SMD | yes | yes | Valve studiomdl data |
|
||||
| Doom 3 / Quake 4 `.proc` | yes | | render geometry per area, portals and BSP nodes as data |
|
||||
| Doom 3 / Quake 4 `.map` (d3map) | yes | | brushDef3, patchDef2 / 3, entities as nodes |
|
||||
| UDMF (`.udmf`, `TEXTMAP`) | yes | | Doom maps as text: see "Doom maps (UDMF)" above |
|
||||
| Roblox `.mesh` (robloxmesh) | yes | yes | see [roblox.md](roblox.md) |
|
||||
| Roblox `.rbxm` / `.rbxl`, `.rbxmx` / `.rbxlx` | as an `RbxTree` | yes | instance trees with typed properties: see [roblox.md](roblox.md) |
|
||||
|
||||
|
||||
+20
-1
@@ -194,14 +194,33 @@ local back = assert(F.load(tmx))
|
||||
assert(back.layers[1].data[6] == 0x80000009)
|
||||
```
|
||||
|
||||
## Wolfenstein 3D maps
|
||||
|
||||
Wolfenstein 3D / Spear of Destiny maps are two files: `GAMEMAPS.WL6` (the Carmack + RLEW compressed planes) and
|
||||
`MAPHEAD.WL6` (the RLEW tag and where each map starts). Load either one: the other comes through `files` /
|
||||
`resolve` (loading a path finds it next to the file) or `mapHead` / `gameMaps`. A map loads as a TileMap with one
|
||||
tile layer per plane (`walls`, `objects`, `plane3`) holding the raw tile values (1..63 walls, 90..101 doors, 106+
|
||||
floor areas; things in `objects`), without a tileset; `map` picks the slot (default: the first present) and
|
||||
`F.format("gamemaps").maps` lists them.
|
||||
|
||||
```luau
|
||||
local files = { ["MAPHEAD.WL6"] = mapheadBytes }
|
||||
local level = assert(F.load(gamemapsBytes, { name = "GAMEMAPS.WL6", files = files }))
|
||||
assert(level.kind == "tilemap" and level.width == 16 and level.properties.name == "Tiny map")
|
||||
assert(level.layers[1].name == "walls" and level.layers[1].data[1] == 1) -- the border wall
|
||||
local maps = assert(F.format("gamemaps").maps(F.Bytes.reader(mapheadBytes), { gameMaps = gamemapsBytes }))
|
||||
assert(#maps == 1 and maps[1].slot == 1)
|
||||
```
|
||||
|
||||
## Formats
|
||||
|
||||
| Format | Read | Write | Notes |
|
||||
|---|---|---|---|
|
||||
| TMX / TSX | yes | yes | CSV, base64 (raw, zlib, gzip) and `<tile>` data; zstd data returns `UNSUPPORTED` |
|
||||
| TMJ / TSJ | yes | yes | |
|
||||
| Wolfenstein 3D GAMEMAPS + MAPHEAD | yes | | the `gamemaps` format: raw tile values, no tileset |
|
||||
|
||||
Both are the `tiled` format in [FORMATS.md](../FORMATS.md). Wang sets and terrains are dropped.
|
||||
TMX and TMJ are the `tiled` format in [FORMATS.md](../FORMATS.md). Wang sets and terrains are dropped.
|
||||
|
||||
## Gotchas
|
||||
|
||||
|
||||
@@ -770,6 +770,18 @@ local list: { Entry } = {
|
||||
return require("@rosetta/model/buildmap")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "d3map",
|
||||
category = "model",
|
||||
path = "model/d3map",
|
||||
extensions = { "map" },
|
||||
mime = { "text/x-doom3-map" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/model/Brush", "codecs/model/Patch", "codecs/model/Mat4", "codecs/text/Lexer" },
|
||||
caps = { decode = true, encode = false, patches = true, variants = { "doom3", "quake4" } },
|
||||
load = function()
|
||||
return require("@rosetta/model/d3map")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "dae",
|
||||
category = "model",
|
||||
@@ -974,6 +986,18 @@ local list: { Entry } = {
|
||||
return require("@rosetta/model/pmx")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "proc",
|
||||
category = "model",
|
||||
path = "model/proc",
|
||||
extensions = { "proc" },
|
||||
mime = { "model/x-doom3-proc" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Lexer" },
|
||||
caps = { decode = true, encode = false, portals = true },
|
||||
load = function()
|
||||
return require("@rosetta/model/proc")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "qb",
|
||||
category = "model",
|
||||
@@ -1070,6 +1094,18 @@ local list: { Entry } = {
|
||||
return require("@rosetta/model/stl")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "udmf",
|
||||
category = "model",
|
||||
path = "model/udmf",
|
||||
extensions = { "udmf", "textmap" },
|
||||
mime = { "text/x-udmf" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/model/DoomMap" },
|
||||
caps = { decode = true, encode = false, maps = true },
|
||||
load = function()
|
||||
return require("@rosetta/model/udmf")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "usda",
|
||||
category = "model",
|
||||
@@ -1586,13 +1622,25 @@ local list: { Entry } = {
|
||||
return require("@rosetta/archive/vpk")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "vswap",
|
||||
category = "archive",
|
||||
path = "archive/vswap",
|
||||
extensions = { "wl6", "wl1", "sod", "sdm", "vswap" },
|
||||
mime = { "application/x-wolf3d-vswap" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels" },
|
||||
caps = { decode = true, encode = false, images = true, sounds = true },
|
||||
load = function()
|
||||
return require("@rosetta/archive/vswap")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "wad",
|
||||
category = "archive",
|
||||
path = "archive/wad",
|
||||
extensions = { "wad" },
|
||||
mime = { "application/x-doom" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels", "codecs/model/Polygon" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels", "codecs/model/DoomMap" },
|
||||
caps = { decode = true, encode = true, images = true, maps = true, variants = { "iwad", "pwad" } },
|
||||
load = function()
|
||||
return require("@rosetta/archive/wad")
|
||||
@@ -1814,6 +1862,18 @@ local list: { Entry } = {
|
||||
return require("@rosetta/data/yaml")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "gamemaps",
|
||||
category = "vector",
|
||||
path = "vector/gamemaps",
|
||||
extensions = { "wl6", "wl1", "sod", "sdm" },
|
||||
mime = { "application/x-wolf3d-gamemaps" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "Types" },
|
||||
caps = { decode = true, encode = false, tilemap = true },
|
||||
load = function()
|
||||
return require("@rosetta/vector/gamemaps")
|
||||
end,
|
||||
},
|
||||
{
|
||||
name = "svg",
|
||||
category = "vector",
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
--!strict
|
||||
-- archive/vswap: Wolfenstein 3D / Spear of Destiny page files (VSWAP.WL1 / .WL6 / .SOD / .SDM: u16 chunks, sprite
|
||||
-- start, sound start; u32 offsets, u16 lengths; ModdingWiki "VSWAP Format", no code taken), read only. Pages load as
|
||||
-- entries walls/NNN, sprites/NNN, sounds/NNN and soundinfo; Vswap.image turns walls (64 x 64 column-major) and
|
||||
-- sprites (t_compshape posts) into Images through a palette passed in (the game's palette is not redistributable),
|
||||
-- Vswap.sound the digitized sounds into Audio (u8 PCM, 7042 Hz). Not supported: writing, Blake Stone / Corridor 7.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Types = require("@rosetta/Types")
|
||||
local Archive = require("@rosetta/containers/Archive")
|
||||
local Pixels = require("@rosetta/codecs/image/Pixels")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
local Vswap = {
|
||||
name = "vswap",
|
||||
category = "archive",
|
||||
extensions = { "wl6", "wl1", "sod", "sdm", "vswap" },
|
||||
mime = { "application/x-wolf3d-vswap" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels" },
|
||||
caps = { decode = true, encode = false, images = true, sounds = true },
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ types
|
||||
export type DecodeOptions = { maxChunks: number? } -- default 65535
|
||||
export type ImageOptions = {
|
||||
palette: (buffer | string)?, -- 768 bytes RGB (6-bit VGA values are scaled up when no byte is above 63); default grey
|
||||
sixBit: boolean?, -- force the 6-bit reading of the palette
|
||||
}
|
||||
export type Page = { kind: "wall" | "sprite" | "sound" | "soundinfo", index: number, offset: number, size: number }
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
local readu8, readu16, readi16, writeu32 = buffer.readu8, buffer.readu16, buffer.readi16, buffer.writeu32
|
||||
local SAMPLE_RATE = 7042 -- the digitized sounds' rate (wolf4sdl ORIGSAMPLERATE)
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ sniff
|
||||
local function header(r: Bytes.Reader): (number?, number, number)
|
||||
if r:remaining() < 6 then
|
||||
return nil, 0, 0
|
||||
end
|
||||
local n, ss, so = readu16(r.buf, r.base), readu16(r.buf, r.base + 2), readu16(r.buf, r.base + 4)
|
||||
if n == 0 or ss > so or so > n or 6 + n * 6 > r:remaining() then
|
||||
return nil, 0, 0
|
||||
end
|
||||
return n, ss, so
|
||||
end
|
||||
|
||||
function Vswap.sniff(r: Bytes.Reader): number
|
||||
local n = header(r)
|
||||
if not n then
|
||||
return 0
|
||||
end
|
||||
local size = r.limit - r.base
|
||||
local b = r.buf
|
||||
local last = 6 + n * 6
|
||||
local nonzero = 0
|
||||
for i = 0, n - 1 do
|
||||
local o = buffer.readu32(b, r.base + 6 + i * 4)
|
||||
local l = readu16(b, r.base + 6 + n * 4 + i * 2)
|
||||
if o ~= 0 then
|
||||
if o < last or o + l > size then
|
||||
return 0
|
||||
end
|
||||
last = o
|
||||
nonzero += 1
|
||||
end
|
||||
end
|
||||
return if nonzero > 0 then 0.6 else 0
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
function Vswap.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
|
||||
if r:remaining() < 6 then
|
||||
return nil, Err.new(Err.TRUNCATED, "header", 0)
|
||||
end
|
||||
local n, ss, so = header(r)
|
||||
if not n then
|
||||
return nil, Err.new(if 6 + readu16(r.buf, r.base) * 6 > r:remaining() then Err.TRUNCATED else Err.CORRUPT, "bad page directory", 0)
|
||||
end
|
||||
if n > (opts and opts.maxChunks or 65535) then
|
||||
return nil, Err.new(Err.LIMIT, "too many pages: " .. n)
|
||||
end
|
||||
local size = r.limit - r.base
|
||||
local b = r.buf
|
||||
local a = Archive.new("vswap")
|
||||
local pages: { Page } = {}
|
||||
local counts: { [string]: number } = { wall = 0, sprite = 0, sound = 0 }
|
||||
for i = 0, n - 1 do
|
||||
local o = buffer.readu32(b, r.base + 6 + i * 4)
|
||||
local l = readu16(b, r.base + 6 + n * 4 + i * 2)
|
||||
if o == 0 then
|
||||
l = 0 -- a sparse page (Spear of Destiny)
|
||||
elseif o + l > size then
|
||||
return nil, Err.new(Err.TRUNCATED, "page " .. i .. " past the end", 6 + i * 4)
|
||||
end
|
||||
local kind: string, idx: number = "sound", i - so
|
||||
if i < ss then
|
||||
kind, idx = "wall", i
|
||||
elseif i < so then
|
||||
kind, idx = "sprite", i - ss
|
||||
elseif i == n - 1 and so < n then
|
||||
kind, idx = "soundinfo", 0
|
||||
end
|
||||
local name = if kind == "soundinfo" then "soundinfo" else kind .. "s/" .. string.format("%03d", idx)
|
||||
if kind ~= "soundinfo" then
|
||||
counts[kind] += 1
|
||||
end
|
||||
table.insert(pages, { kind = kind :: any, index = idx, offset = o, size = l })
|
||||
Archive.put(a, { name = name, size = l, dir = false, method = "store", page = i, kind = kind, load = Archive.slice(b, r.base + o, l) })
|
||||
end
|
||||
a.meta.source = { format = "vswap", chunks = n, spriteStart = ss, soundStart = so, walls = counts.wall, sprites = counts.sprite, soundPages = counts.sound }
|
||||
a.meta.vswap = { pages = pages, buf = b, base = r.base, spriteStart = ss, soundStart = so }
|
||||
return a, nil
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ extras
|
||||
local function info(a: any): any
|
||||
return type(a) == "table" and type(a.meta) == "table" and a.meta.vswap or nil
|
||||
end
|
||||
|
||||
local function palette(opts: ImageOptions?): (buffer, boolean)
|
||||
local p = opts and opts.palette
|
||||
if p == nil then
|
||||
local g = buffer.create(768)
|
||||
for i = 0, 255 do
|
||||
buffer.fill(g, i * 3, i, 3)
|
||||
end
|
||||
return Pixels.palette(g, 0, 256), false
|
||||
end
|
||||
local src = if type(p) == "string" then buffer.fromstring(p) else p
|
||||
local n = math.min(buffer.len(src), 768)
|
||||
local six = opts and opts.sixBit
|
||||
if six == nil then
|
||||
six = true
|
||||
for i = 0, n - 1 do
|
||||
if readu8(src, i) > 63 then
|
||||
six = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if six then
|
||||
local s = buffer.create(768)
|
||||
for i = 0, n - 1 do
|
||||
local v = bit32.band(readu8(src, i), 63)
|
||||
buffer.writeu8(s, i, bit32.bor(bit32.lshift(v, 2), bit32.rshift(v, 4)))
|
||||
end
|
||||
src = s
|
||||
end
|
||||
return Pixels.palette(src, 0, n // 3), true
|
||||
end
|
||||
|
||||
function Vswap.pages(a: any): { Page }?
|
||||
local v = info(a)
|
||||
return v and v.pages
|
||||
end
|
||||
|
||||
function Vswap.image(a: any, kind: "wall" | "sprite", index: number, opts: ImageOptions?): (Types.Image?, Err.Err?)
|
||||
local v = info(a)
|
||||
if not v then
|
||||
return nil, Err.new(Err.ARG, "expected a decoded VSWAP archive")
|
||||
end
|
||||
local page: Page? = nil
|
||||
for _, p in v.pages do
|
||||
if p.kind == kind and p.index == index then
|
||||
page = p
|
||||
break
|
||||
end
|
||||
end
|
||||
if not page then
|
||||
return nil, Err.new(Err.ARG, "no " .. tostring(kind) .. " " .. tostring(index))
|
||||
end
|
||||
local pal, given = palette(opts)
|
||||
local b, at, n = v.buf, v.base + page.offset, page.size
|
||||
local img = Types.Image.new(64, 64)
|
||||
local px = img.pixels
|
||||
if kind == "wall" then
|
||||
if n < 4096 then
|
||||
return nil, Err.new(Err.CORRUPT, "wall page shorter than 4096 bytes", page.offset)
|
||||
end
|
||||
for x = 0, 63 do
|
||||
for y = 0, 63 do
|
||||
writeu32(px, (y * 64 + x) * 4, buffer.readu32(pal, readu8(b, at + x * 64 + y) * 4))
|
||||
end
|
||||
end
|
||||
else
|
||||
if n < 4 then
|
||||
return nil, Err.new(Err.CORRUPT, "sprite page too short", page.offset)
|
||||
end
|
||||
local left, right = readu16(b, at), readu16(b, at + 2)
|
||||
if right < left or right > 63 or 4 + (right - left + 1) * 2 > n then
|
||||
return nil, Err.new(Err.CORRUPT, "bad sprite columns", page.offset)
|
||||
end
|
||||
for x = left, right do
|
||||
local p = readu16(b, at + 4 + (x - left) * 2)
|
||||
for _ = 1, 64 do
|
||||
if p + 2 > n then
|
||||
return nil, Err.new(Err.CORRUPT, "sprite post past the page", page.offset + p)
|
||||
end
|
||||
local endy = readu16(b, at + p) // 2
|
||||
if endy == 0 then
|
||||
break
|
||||
end
|
||||
if p + 6 > n then
|
||||
return nil, Err.new(Err.CORRUPT, "sprite post past the page", page.offset + p)
|
||||
end
|
||||
local src, starty = readi16(b, at + p + 2), readu16(b, at + p + 4) // 2
|
||||
if endy > 64 or starty > endy or src + starty < 0 or src + endy > n then
|
||||
return nil, Err.new(Err.CORRUPT, "bad sprite post", page.offset + p)
|
||||
end
|
||||
for y = starty, endy - 1 do
|
||||
writeu32(px, (y * 64 + x) * 4, buffer.readu32(pal, readu8(b, at + src + y) * 4))
|
||||
end
|
||||
p += 6
|
||||
end
|
||||
end
|
||||
end
|
||||
img.meta.source = { format = "vswap", kind = kind, index = index, palette = given }
|
||||
return img, nil
|
||||
end
|
||||
|
||||
function Vswap.sounds(a: any): number
|
||||
local v = info(a)
|
||||
if not v then
|
||||
return 0
|
||||
end
|
||||
local last = v.pages[#v.pages]
|
||||
return if last and last.kind == "soundinfo" then last.size // 4 else 0
|
||||
end
|
||||
|
||||
function Vswap.sound(a: any, index: number): (Types.Audio?, Err.Err?)
|
||||
local v = info(a)
|
||||
if not v then
|
||||
return nil, Err.new(Err.ARG, "expected a decoded VSWAP archive")
|
||||
end
|
||||
local si = v.pages[#v.pages]
|
||||
if not si or si.kind ~= "soundinfo" or index < 1 or index > si.size // 4 or index % 1 ~= 0 then
|
||||
return nil, Err.new(Err.ARG, "no sound " .. tostring(index))
|
||||
end
|
||||
local b = v.buf
|
||||
local start = readu16(b, v.base + si.offset + (index - 1) * 4)
|
||||
local len = readu16(b, v.base + si.offset + (index - 1) * 4 + 2)
|
||||
local au = Types.Audio.new(SAMPLE_RATE, 1, len)
|
||||
local s = au.samples
|
||||
local got = 0
|
||||
local p = v.soundStart + start + 1
|
||||
while got < len do
|
||||
local page = v.pages[p]
|
||||
if not page or page.kind ~= "sound" then
|
||||
return nil, Err.new(Err.CORRUPT, "sound " .. index .. " runs past the sound pages")
|
||||
end
|
||||
local take = math.min(page.size, len - got)
|
||||
local at = v.base + page.offset
|
||||
for i = 0, take - 1 do
|
||||
buffer.writef32(s, (got + i) * 4, (readu8(b, at + i) - 128) / 128)
|
||||
end
|
||||
got += take
|
||||
p += 1
|
||||
if page.size == 0 then
|
||||
return nil, Err.new(Err.CORRUPT, "empty sound page in sound " .. index)
|
||||
end
|
||||
end
|
||||
au.meta.source = { format = "vswap", sound = index, startPage = start, bytes = len, encoding = "u8" }
|
||||
return au, nil
|
||||
end
|
||||
|
||||
return Vswap
|
||||
@@ -1,7 +1,7 @@
|
||||
--!strict
|
||||
-- archive/wad: Doom-engine WADs (IWAD / PWAD; Unofficial Doom Specs, w_wad.c / r_data.c; no code taken), plus lumps,
|
||||
-- palettes, pictures, wall textures and maps. Entry names: "<map>/<lump>", repeats "<name>~<n>". Not supported: UDMF
|
||||
-- geometry (lumps listed), Strife's TEXTURE variant, big-endian (Jaguar) WADs, compressed Jaguar lumps.
|
||||
-- palettes, pictures, wall textures and maps (binary and UDMF TEXTMAP). Entry names: "<map>/<lump>", repeats
|
||||
-- "<name>~<n>". Not supported: Strife's TEXTURE variant, big-endian (Jaguar) WADs, compressed Jaguar lumps.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
@@ -10,7 +10,7 @@ local Types = require("@rosetta/Types")
|
||||
local Archive = require("@rosetta/containers/Archive")
|
||||
local Pixels = require("@rosetta/codecs/image/Pixels")
|
||||
local Picture = require("@rosetta/archive/wad/Picture")
|
||||
local Map = require("@rosetta/archive/wad/Map")
|
||||
local Map = require("@rosetta/codecs/model/DoomMap")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
local Wad = {
|
||||
@@ -18,7 +18,7 @@ local Wad = {
|
||||
category = "archive",
|
||||
extensions = { "wad" },
|
||||
mime = { "application/x-doom" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels", "codecs/model/Polygon" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels", "codecs/model/DoomMap" },
|
||||
caps = { decode = true, encode = true, images = true, maps = true, variants = { "iwad", "pwad" } },
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ export type Lump = {
|
||||
export type MapOptions = {
|
||||
textures: boolean?, -- default true
|
||||
palette: number?, -- default 0
|
||||
maxBlocks: number?, -- UDMF, default 2^22
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
@@ -377,7 +378,7 @@ function Wad.maps(a: any): { string }
|
||||
return out
|
||||
end
|
||||
|
||||
function Wad.mapData(a: any, name: string): (Map.MapData?, Err.Err?)
|
||||
function Wad.mapData(a: any, name: string, opts: MapOptions?): (Map.MapData?, Err.Err?)
|
||||
local w = info(a)
|
||||
if not w then
|
||||
return nil, Err.new(Err.ARG, "expected a decoded WAD archive")
|
||||
@@ -392,10 +393,13 @@ function Wad.mapData(a: any, name: string): (Map.MapData?, Err.Err?)
|
||||
if not next(lumps) then
|
||||
return nil, Err.new(Err.ARG, "no map named " .. tostring(name))
|
||||
end
|
||||
if lumps.TEXTMAP then
|
||||
return nil, Err.new(Err.UNSUPPORTED, "UDMF (TEXTMAP) maps")
|
||||
local m, msg
|
||||
local tm = lumps.TEXTMAP
|
||||
if tm then
|
||||
m, msg = Map.udmf(buffer.readstring(tm.buf, tm.at, tm.size), opts and opts.maxBlocks)
|
||||
else
|
||||
m, msg = Map.parse(lumps, lumps.BEHAVIOR ~= nil)
|
||||
end
|
||||
local m, msg = Map.parse(lumps, lumps.BEHAVIOR ~= nil)
|
||||
if not m then
|
||||
return nil, Err.from(msg)
|
||||
end
|
||||
@@ -403,7 +407,7 @@ function Wad.mapData(a: any, name: string): (Map.MapData?, Err.Err?)
|
||||
end
|
||||
|
||||
function Wad.map(a: any, name: string, opts: MapOptions?): (Types.Scene?, Err.Err?)
|
||||
local m, err = Wad.mapData(a, name)
|
||||
local m, err = Wad.mapData(a, name, opts)
|
||||
if not m then
|
||||
return nil, err
|
||||
end
|
||||
@@ -441,7 +445,7 @@ function Wad.map(a: any, name: string, opts: MapOptions?): (Types.Scene?, Err.Er
|
||||
image = if images then image else nil,
|
||||
}
|
||||
local scene = Map.scene(m, tex, string.upper(name))
|
||||
scene.meta.source = { format = "wad", map = string.upper(name), mapFormat = m.format, things = #m.things, linedefs = #m.linedefs, sectors = #m.sectors, vertices = #m.vertices // 2 }
|
||||
scene.meta.source = { format = "wad", map = string.upper(name), mapFormat = m.format, namespace = m.namespace, things = #m.things, linedefs = #m.linedefs, sectors = #m.sectors, vertices = #m.vertices // 2 }
|
||||
return scene, nil
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
--!strict
|
||||
-- codecs/model/DoomMap/Udmf: UDMF 1.1 TEXTMAP text (zdoom.org specs/udmf.txt; no code taken) to the DoomMap tables.
|
||||
-- Every block keeps its fields (lower-case keys, namespace and user_ keys included); unknown blocks and global
|
||||
-- assignments are kept as data. Flags are rebuilt in the binary layout of the namespace (Doom or Hexen bits).
|
||||
local Lexer = require("@rosetta/codecs/text/Lexer")
|
||||
|
||||
local Udmf = {}
|
||||
|
||||
export type Block = { type: string, fields: { [string]: any } }
|
||||
export type Document = { namespace: string?, globals: { [string]: any }, blocks: { Block } }
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ parse
|
||||
local function value(L: Lexer.Lexer): (any, string?)
|
||||
local k, v = L:next()
|
||||
if k == "number" then
|
||||
local raw = L.raw :: string
|
||||
-- integer := ... | 0[0-9]+ (octal) | 0x[0-9A-Fa-f]+
|
||||
if string.match(raw, "^[+-]?0[0-7]+$") then
|
||||
local neg = string.sub(raw, 1, 1) == "-"
|
||||
local o = tonumber((string.gsub(raw, "^[+-]?0", "")), 8) :: number
|
||||
return if neg then -o else o, nil
|
||||
end
|
||||
return v, nil
|
||||
elseif k == "string" then
|
||||
return v, nil
|
||||
elseif k == "word" then
|
||||
local w = string.lower(v)
|
||||
if w == "true" then
|
||||
return true, nil
|
||||
elseif w == "false" then
|
||||
return false, nil
|
||||
end
|
||||
return v, nil
|
||||
end
|
||||
return nil, L.err or "expected a value"
|
||||
end
|
||||
|
||||
function Udmf.parse(text: string, maxBlocks: number?): (Document?, string?)
|
||||
local L = Lexer.new(text)
|
||||
local doc: Document = { namespace = nil, globals = {}, blocks = {} }
|
||||
local limit = maxBlocks or 2 ^ 22
|
||||
while true do
|
||||
local k, id = L:next()
|
||||
if k == nil then
|
||||
if L.err then
|
||||
return nil, L.err .. " at line " .. L:line()
|
||||
end
|
||||
break
|
||||
end
|
||||
if k ~= "word" then
|
||||
return nil, "expected an identifier at line " .. L:line()
|
||||
end
|
||||
local name = string.lower(id)
|
||||
local pk, pv = L:next()
|
||||
if pk == "punct" and pv == "=" then
|
||||
local v, err = value(L)
|
||||
if err then
|
||||
return nil, err .. " at line " .. L:line()
|
||||
end
|
||||
local sk, sv = L:next()
|
||||
if sk ~= "punct" or sv ~= ";" then
|
||||
return nil, "expected ; at line " .. L:line()
|
||||
end
|
||||
doc.globals[name] = v
|
||||
if name == "namespace" and type(v) == "string" then
|
||||
doc.namespace = v
|
||||
end
|
||||
elseif pk == "punct" and pv == "{" then
|
||||
if #doc.blocks >= limit then
|
||||
return nil, "limit: more than " .. limit .. " blocks"
|
||||
end
|
||||
local fields: { [string]: any } = {}
|
||||
while true do
|
||||
local fk, fv = L:next()
|
||||
if fk == "punct" and fv == "}" then
|
||||
break
|
||||
end
|
||||
if fk ~= "word" then
|
||||
return nil, (L.err or "expected a field name") .. " at line " .. L:line()
|
||||
end
|
||||
local ek, ev = L:next()
|
||||
if ek ~= "punct" or ev ~= "=" then
|
||||
return nil, "expected = at line " .. L:line()
|
||||
end
|
||||
local v, err = value(L)
|
||||
if err then
|
||||
return nil, err .. " at line " .. L:line()
|
||||
end
|
||||
local sk, sv = L:next()
|
||||
if sk ~= "punct" or sv ~= ";" then
|
||||
return nil, "expected ; at line " .. L:line()
|
||||
end
|
||||
fields[string.lower(fv)] = v
|
||||
end
|
||||
table.insert(doc.blocks, { type = name, fields = fields })
|
||||
else
|
||||
return nil, "expected = or { at line " .. L:line()
|
||||
end
|
||||
end
|
||||
return doc, nil
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ map
|
||||
local LINE_FLAGS: { [string]: number } = { blocking = 1, blockmonsters = 2, twosided = 4, dontpegtop = 8, dontpegbottom = 16, secret = 32, blocksound = 64, dontdraw = 128, mapped = 256 }
|
||||
-- Hexen SPAC activation (bits 10..12) and repeat (bit 9)
|
||||
local SPAC: { [string]: number } = { playercross = 0, playeruse = 1, monstercross = 2, impact = 3, playerpush = 4, missilecross = 5 }
|
||||
|
||||
local function num(f: { [string]: any }, k: string, default: number): number
|
||||
local v = f[k]
|
||||
return if type(v) == "number" then v else default
|
||||
end
|
||||
|
||||
local function flag(f: { [string]: any }, k: string): boolean
|
||||
return f[k] == true
|
||||
end
|
||||
|
||||
local function tex(f: { [string]: any }, k: string, default: string): string
|
||||
local v = f[k]
|
||||
return if type(v) == "string" then string.upper(v) else default
|
||||
end
|
||||
|
||||
local function args(f: { [string]: any }): { number }
|
||||
return { num(f, "arg0", 0), num(f, "arg1", 0), num(f, "arg2", 0), num(f, "arg3", 0), num(f, "arg4", 0) }
|
||||
end
|
||||
|
||||
local function index(f: { [string]: any }, k: string): number?
|
||||
local v = f[k]
|
||||
return if type(v) == "number" and v >= 0 and v % 1 == 0 then v + 1 else nil
|
||||
end
|
||||
|
||||
function Udmf.map(doc: Document): (any, string?)
|
||||
local ns = string.lower(doc.namespace or "")
|
||||
local hexenBits = ns ~= "doom" and ns ~= "heretic" and ns ~= "strife"
|
||||
local m = { format = "udmf", namespace = doc.namespace, globals = doc.globals, things = {}, linedefs = {}, sidedefs = {}, vertices = {}, sectors = {}, blocks = {} }
|
||||
for _, b in doc.blocks do
|
||||
local f = b.fields
|
||||
if b.type == "vertex" then
|
||||
local x, y = f.x, f.y
|
||||
if type(x) ~= "number" or type(y) ~= "number" then
|
||||
return nil, "vertex " .. (#m.vertices // 2) .. " has no x / y"
|
||||
end
|
||||
table.insert(m.vertices, x)
|
||||
table.insert(m.vertices, y)
|
||||
elseif b.type == "linedef" then
|
||||
local flags = 0
|
||||
for k, bit in LINE_FLAGS do
|
||||
if flag(f, k) then
|
||||
flags += bit
|
||||
end
|
||||
end
|
||||
if hexenBits then
|
||||
if flag(f, "repeatspecial") then
|
||||
flags += 512
|
||||
end
|
||||
for k, a in SPAC do
|
||||
if flag(f, k) then
|
||||
flags = bit32.bor(bit32.band(flags, bit32.bnot(0x1C00)), a * 1024)
|
||||
end
|
||||
end
|
||||
end
|
||||
local v1, v2 = index(f, "v1"), index(f, "v2")
|
||||
if not v1 or not v2 then
|
||||
return nil, "linedef " .. #m.linedefs .. " has no v1 / v2"
|
||||
end
|
||||
local a = args(f)
|
||||
table.insert(m.linedefs, {
|
||||
v1 = v1,
|
||||
v2 = v2,
|
||||
flags = flags,
|
||||
special = num(f, "special", 0),
|
||||
tag = if hexenBits then num(f, "id", -1) else a[1],
|
||||
args = a,
|
||||
front = index(f, "sidefront"),
|
||||
back = index(f, "sideback"),
|
||||
fields = f,
|
||||
})
|
||||
elseif b.type == "sidedef" then
|
||||
local s = index(f, "sector")
|
||||
if not s then
|
||||
return nil, "sidedef " .. #m.sidedefs .. " has no sector"
|
||||
end
|
||||
table.insert(m.sidedefs, {
|
||||
xoff = num(f, "offsetx", 0),
|
||||
yoff = num(f, "offsety", 0),
|
||||
upper = tex(f, "texturetop", "-"),
|
||||
lower = tex(f, "texturebottom", "-"),
|
||||
middle = tex(f, "texturemiddle", "-"),
|
||||
sector = s,
|
||||
fields = f,
|
||||
})
|
||||
elseif b.type == "sector" then
|
||||
table.insert(m.sectors, {
|
||||
floor = num(f, "heightfloor", 0),
|
||||
ceiling = num(f, "heightceiling", 0),
|
||||
floorFlat = tex(f, "texturefloor", "-"),
|
||||
ceilingFlat = tex(f, "textureceiling", "-"),
|
||||
light = num(f, "lightlevel", 160),
|
||||
special = num(f, "special", 0),
|
||||
tag = num(f, "id", 0),
|
||||
fields = f,
|
||||
})
|
||||
elseif b.type == "thing" then
|
||||
local x, y = f.x, f.y
|
||||
if type(x) ~= "number" or type(y) ~= "number" then
|
||||
return nil, "thing " .. #m.things .. " has no x / y"
|
||||
end
|
||||
local fl = 0
|
||||
if flag(f, "skill1") or flag(f, "skill2") then
|
||||
fl += 1
|
||||
end
|
||||
if flag(f, "skill3") then
|
||||
fl += 2
|
||||
end
|
||||
if flag(f, "skill4") or flag(f, "skill5") then
|
||||
fl += 4
|
||||
end
|
||||
if flag(f, "ambush") then
|
||||
fl += 8
|
||||
end
|
||||
if hexenBits then
|
||||
fl += (if flag(f, "dormant") then 16 else 0) + (if flag(f, "class1") then 32 else 0) + (if flag(f, "class2") then 64 else 0)
|
||||
+ (if flag(f, "class3") then 128 else 0) + (if flag(f, "single") then 256 else 0) + (if flag(f, "coop") then 512 else 0)
|
||||
+ (if flag(f, "dm") then 1024 else 0)
|
||||
else
|
||||
-- Doom / Boom / MBF: 16 not in single player, 32 not in deathmatch, 64 not in coop, 128 friend
|
||||
fl += (if flag(f, "single") then 0 else 16) + (if flag(f, "dm") then 0 else 32) + (if flag(f, "coop") then 0 else 64)
|
||||
+ (if flag(f, "friend") then 128 else 0)
|
||||
end
|
||||
table.insert(m.things, {
|
||||
x = x,
|
||||
y = y,
|
||||
z = num(f, "height", 0),
|
||||
angle = num(f, "angle", 0),
|
||||
type = num(f, "type", 0),
|
||||
flags = fl,
|
||||
tid = num(f, "id", 0),
|
||||
special = num(f, "special", 0),
|
||||
args = args(f),
|
||||
fields = f,
|
||||
})
|
||||
else
|
||||
table.insert(m.blocks, b)
|
||||
end
|
||||
end
|
||||
return m, nil
|
||||
end
|
||||
|
||||
return Udmf
|
||||
@@ -1,9 +1,10 @@
|
||||
--!strict
|
||||
-- archive/wad/Map: Doom / Heretic / Hexen binary map lumps (Hexen when BEHAVIOR is present) to tables and a Scene, with
|
||||
-- vanilla texture alignment (offsets, unpegged) and the sky hack; z up, map units. From the Unofficial Doom Specs and
|
||||
-- the Hexen specs; no code taken. Not supported: UDMF (TEXTMAP).
|
||||
-- codecs/model/DoomMap: Doom / Heretic / Hexen binary map lumps (Hexen when BEHAVIOR is present) and UDMF TEXTMAP to
|
||||
-- tables and a Scene, with vanilla texture alignment (offsets, unpegged) and the sky hack; z up, map units. From the
|
||||
-- Unofficial Doom Specs, the Hexen specs and UDMF 1.1; no code taken. Not supported: UDMF slopes / per-part offsets.
|
||||
local Types = require("@rosetta/Types")
|
||||
local Polygon = require("@rosetta/codecs/model/Polygon")
|
||||
local Udmf = require("@rosetta/codecs/model/DoomMap/Udmf")
|
||||
|
||||
local Map = {}
|
||||
|
||||
@@ -12,12 +13,16 @@ local readu8, readi16, readu16 = buffer.readu8, buffer.readi16, buffer.readu16
|
||||
local writef32, writeu32 = buffer.writef32, buffer.writeu32
|
||||
|
||||
export type Lump = { buf: buffer, at: number, size: number }
|
||||
export type Thing = { x: number, y: number, z: number?, angle: number, type: number, flags: number, tid: number?, special: number?, args: { number }? }
|
||||
export type Linedef = { v1: number, v2: number, flags: number, special: number, tag: number?, args: { number }?, front: number?, back: number? }
|
||||
export type Sidedef = { xoff: number, yoff: number, upper: string, lower: string, middle: string, sector: number }
|
||||
export type Sector = { floor: number, ceiling: number, floorFlat: string, ceilingFlat: string, light: number, special: number, tag: number }
|
||||
export type Fields = { [string]: any } -- UDMF: the block's fields as written (lower-case keys)
|
||||
export type Thing = { x: number, y: number, z: number?, angle: number, type: number, flags: number, tid: number?, special: number?, args: { number }?, fields: Fields? }
|
||||
export type Linedef = { v1: number, v2: number, flags: number, special: number, tag: number?, args: { number }?, front: number?, back: number?, fields: Fields? }
|
||||
export type Sidedef = { xoff: number, yoff: number, upper: string, lower: string, middle: string, sector: number, fields: Fields? }
|
||||
export type Sector = { floor: number, ceiling: number, floorFlat: string, ceilingFlat: string, light: number, special: number, tag: number, fields: Fields? }
|
||||
export type MapData = {
|
||||
format: "doom" | "hexen",
|
||||
format: "doom" | "hexen" | "udmf",
|
||||
namespace: string?, -- UDMF
|
||||
globals: Fields?, -- UDMF global assignments
|
||||
blocks: { Udmf.Block }?, -- UDMF blocks other than vertex / linedef / sidedef / sector / thing
|
||||
things: { Thing },
|
||||
linedefs: { Linedef },
|
||||
sidedefs: { Sidedef },
|
||||
@@ -136,6 +141,16 @@ function Map.parse(lumps: { [string]: Lump }, hexen: boolean): (MapData?, string
|
||||
return m, nil
|
||||
end
|
||||
|
||||
function Map.udmf(text: string, maxBlocks: number?): (MapData?, string?)
|
||||
local doc, err = Udmf.parse(text, maxBlocks)
|
||||
if not doc then
|
||||
return nil, err
|
||||
end
|
||||
return Udmf.map(doc)
|
||||
end
|
||||
|
||||
Map.parseUdmf = Udmf.parse
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ sector outlines
|
||||
-- sector loops: front sides v1 -> v2, back sides v2 -> v1, lines with the sector on both sides left out; the sharpest
|
||||
-- right turn at forks; unclosed chains dropped
|
||||
@@ -0,0 +1,130 @@
|
||||
--!strict
|
||||
-- codecs/text/Lexer: C-style tokens for id Tech / UDMF text (idLib idLexer conventions, UDMF 1.1 §I; no code taken):
|
||||
-- // and /* */ comments, "strings" with backslash escapes, numbers (decimal, float, 0x hex), bare words, and single
|
||||
-- punctuation characters { } ( ) [ ] ; = ,.
|
||||
local Lexer = {}
|
||||
|
||||
export type Kind = "word" | "number" | "string" | "punct"
|
||||
export type Lexer = {
|
||||
s: string,
|
||||
p: number, -- next byte to read, 1-based
|
||||
n: number,
|
||||
raw: string?, -- the last token's text as written
|
||||
err: string?,
|
||||
next: (self: Lexer) -> (Kind?, any),
|
||||
peek: (self: Lexer) -> (Kind?, any),
|
||||
line: (self: Lexer, at: number?) -> number,
|
||||
}
|
||||
|
||||
local find, sub, byte, match = string.find, string.sub, string.byte, string.match
|
||||
local ESC: { [string]: string } = { n = "\n", t = "\t", r = "\r", ["0"] = "\0" }
|
||||
|
||||
local function skip(L: Lexer): number?
|
||||
local s, p = L.s, L.p
|
||||
while true do
|
||||
p = find(s, "[^ \t\r\n\f\v]", p)
|
||||
if not p then
|
||||
return nil
|
||||
end
|
||||
if byte(s, p) == 47 then
|
||||
local c2 = byte(s, p + 1)
|
||||
if c2 == 47 then
|
||||
local e = find(s, "\n", p + 2, true)
|
||||
if not e then
|
||||
return nil
|
||||
end
|
||||
p = e + 1
|
||||
elseif c2 == 42 then
|
||||
local _, e = find(s, "*/", p + 2, true)
|
||||
if not e then
|
||||
L.err = "unterminated comment"
|
||||
return nil
|
||||
end
|
||||
p = e + 1
|
||||
else
|
||||
return p
|
||||
end
|
||||
else
|
||||
return p
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function token(L: Lexer): (Kind?, any, number)
|
||||
local p = skip(L)
|
||||
if not p then
|
||||
return nil, nil, L.n + 1
|
||||
end
|
||||
local s = L.s
|
||||
local c = byte(s, p)
|
||||
if c == 34 then
|
||||
local parts: { string }? = nil
|
||||
local q = p + 1
|
||||
while true do
|
||||
local e = find(s, "[\"\\]", q)
|
||||
if not e then
|
||||
L.err = "unterminated string"
|
||||
return nil, nil, L.n + 1
|
||||
end
|
||||
if byte(s, e) == 34 then
|
||||
local tail = sub(s, q, e - 1)
|
||||
if parts then
|
||||
table.insert(parts, tail)
|
||||
L.raw = sub(s, p, e)
|
||||
return "string", table.concat(parts), e + 1
|
||||
end
|
||||
L.raw = sub(s, p, e)
|
||||
return "string", tail, e + 1
|
||||
end
|
||||
parts = parts or {}
|
||||
local ch = sub(s, e + 1, e + 1)
|
||||
table.insert(parts :: { string }, sub(s, q, e - 1))
|
||||
table.insert(parts :: { string }, ESC[ch] or ch)
|
||||
q = e + 2
|
||||
end
|
||||
end
|
||||
if find("{}()[];=,", string.char(c), 1, true) then
|
||||
L.raw = string.char(c)
|
||||
return "punct", L.raw, p + 1
|
||||
end
|
||||
local w = match(s, "^[^ \t\r\n\f\v{}()%[%];=,\"]+", p) :: string
|
||||
local e = p + #w
|
||||
-- a comment right after a word ends it
|
||||
local cm = find(w, "/[/*]")
|
||||
if cm then
|
||||
w = sub(w, 1, cm - 1)
|
||||
e = p + #w
|
||||
end
|
||||
L.raw = w
|
||||
if (c >= 48 and c <= 57) or c == 45 or c == 43 or c == 46 then
|
||||
local v = tonumber(w)
|
||||
if v and not find(w, "[iInN]") then
|
||||
return "number", v, e
|
||||
end
|
||||
end
|
||||
return "word", w, e
|
||||
end
|
||||
|
||||
local function nextToken(L: Lexer): (Kind?, any)
|
||||
local k, v, e = token(L)
|
||||
L.p = e
|
||||
return k, v
|
||||
end
|
||||
|
||||
local function peek(L: Lexer): (Kind?, any)
|
||||
local raw = L.raw
|
||||
local k, v = token(L)
|
||||
L.raw = raw
|
||||
return k, v
|
||||
end
|
||||
|
||||
local function line(L: Lexer, at: number?): number
|
||||
local _, n = string.gsub(sub(L.s, 1, (at or L.p) - 1), "\n", "")
|
||||
return n + 1
|
||||
end
|
||||
|
||||
function Lexer.new(s: string): Lexer
|
||||
return { s = s, p = 1, n = #s, raw = nil, err = nil, next = nextToken, peek = peek, line = line }
|
||||
end
|
||||
|
||||
return Lexer
|
||||
@@ -0,0 +1,196 @@
|
||||
--!strict
|
||||
-- model/d3map/Parse: Doom 3 / Quake 4 editor .map text ("Version 2" / "Version 3"; idMapFile / idMapEntity /
|
||||
-- idMapBrush / idMapPatch layouts of the Doom 3 GPL source docs, no code taken) to entities with brushDef3 sides
|
||||
-- (plane a b c d with a x + b y + c z + d = 0, normal out of the brush; 2 x 3 texture matrix) and patchDef2 / 3.
|
||||
local Lexer = require("@rosetta/codecs/text/Lexer")
|
||||
|
||||
local Parse = {}
|
||||
|
||||
export type Side = { plane: { number }, matrix: { { number } }, material: string, flags: { number } }
|
||||
export type Prim = {
|
||||
type: string, -- "brushDef3" | "patchDef2" | "patchDef3"
|
||||
sides: { Side }?,
|
||||
material: string?,
|
||||
info: { number }?, -- patchDef2: width height 0 0 0; patchDef3: width height subdivX subdivY 0 0 0
|
||||
width: number?,
|
||||
height: number?,
|
||||
points: { number }?, -- x y z s t per control point, in file order (column by column)
|
||||
}
|
||||
export type Entity = { keys: { [string]: string }, prims: { Prim }, skipped: number }
|
||||
export type Map = { version: number, entities: { Entity } }
|
||||
|
||||
type P = { L: Lexer.Lexer, err: string? }
|
||||
|
||||
local function fail(p: P, msg: string)
|
||||
if not p.err then
|
||||
p.err = (p.L.err or msg) .. " at line " .. p.L:line()
|
||||
end
|
||||
end
|
||||
|
||||
local function want(p: P, c: string)
|
||||
local k, v = p.L:next()
|
||||
if k ~= "punct" or v ~= c then
|
||||
fail(p, "expected " .. c)
|
||||
end
|
||||
end
|
||||
|
||||
local function number(p: P): number
|
||||
local k, v = p.L:next()
|
||||
if k ~= "number" then
|
||||
fail(p, "expected a number")
|
||||
return 0
|
||||
end
|
||||
return v
|
||||
end
|
||||
|
||||
local function tuple(p: P, n: number): { number }
|
||||
want(p, "(")
|
||||
local out = table.create(n, 0)
|
||||
for i = 1, n do
|
||||
out[i] = number(p)
|
||||
end
|
||||
want(p, ")")
|
||||
return out
|
||||
end
|
||||
|
||||
local function name(p: P): string
|
||||
local k, v = p.L:next()
|
||||
if k == "string" or k == "word" then
|
||||
return v
|
||||
end
|
||||
fail(p, "expected a material name")
|
||||
return ""
|
||||
end
|
||||
|
||||
local function brushDef3(p: P): Prim
|
||||
want(p, "{")
|
||||
local sides: { Side } = {}
|
||||
while not p.err do
|
||||
local k, v = p.L:peek()
|
||||
if k == "punct" and v == "}" then
|
||||
p.L:next()
|
||||
break
|
||||
end
|
||||
local plane = tuple(p, 4)
|
||||
want(p, "(")
|
||||
local m1 = tuple(p, 3)
|
||||
local m2 = tuple(p, 3)
|
||||
want(p, ")")
|
||||
local material = name(p)
|
||||
local flags: { number } = {}
|
||||
while not p.err do
|
||||
local fk = p.L:peek()
|
||||
if fk ~= "number" then
|
||||
break
|
||||
end
|
||||
table.insert(flags, number(p))
|
||||
end
|
||||
table.insert(sides, { plane = plane, matrix = { m1, m2 }, material = material, flags = flags })
|
||||
end
|
||||
return { type = "brushDef3", sides = sides }
|
||||
end
|
||||
|
||||
local function patchDef(p: P, kind: string, maxPoints: number): Prim
|
||||
want(p, "{")
|
||||
local material = name(p)
|
||||
local info = tuple(p, if kind == "patchDef3" then 7 else 5)
|
||||
local w, h = info[1], info[2]
|
||||
if p.err then
|
||||
return { type = kind }
|
||||
end
|
||||
if w < 1 or h < 1 or w % 1 ~= 0 or h % 1 ~= 0 or w * h > maxPoints then
|
||||
fail(p, "limit: patch size " .. w .. " x " .. h)
|
||||
return { type = kind }
|
||||
end
|
||||
local pts: { number } = table.create(w * h * 5, 0)
|
||||
want(p, "(")
|
||||
for i = 0, w - 1 do
|
||||
want(p, "(")
|
||||
for j = 0, h - 1 do
|
||||
local v = tuple(p, 5)
|
||||
if p.err then
|
||||
return { type = kind }
|
||||
end
|
||||
table.move(v, 1, 5, (i * h + j) * 5 + 1, pts)
|
||||
end
|
||||
want(p, ")")
|
||||
end
|
||||
want(p, ")")
|
||||
want(p, "}")
|
||||
return { type = kind, material = material, info = info, width = w, height = h, points = pts }
|
||||
end
|
||||
|
||||
function Parse.parse(text: string, maxPrims: number?): (Map?, string?)
|
||||
local p: P = { L = Lexer.new(text), err = nil }
|
||||
local k, v = p.L:next()
|
||||
if k ~= "word" or v ~= "Version" then
|
||||
return nil, "missing the Version line"
|
||||
end
|
||||
local version = number(p)
|
||||
local m: Map = { version = version, entities = {} }
|
||||
local limit = maxPrims or 2 ^ 20
|
||||
local count = 0
|
||||
while not p.err do
|
||||
local ek, ev = p.L:next()
|
||||
if not ek then
|
||||
if p.L.err then
|
||||
fail(p, p.L.err)
|
||||
end
|
||||
break
|
||||
end
|
||||
if ek ~= "punct" or ev ~= "{" then
|
||||
fail(p, "expected an entity")
|
||||
break
|
||||
end
|
||||
local ent: Entity = { keys = {}, prims = {}, skipped = 0 }
|
||||
while not p.err do
|
||||
local tk, tv = p.L:next()
|
||||
if tk == "string" then
|
||||
local vk, vv = p.L:next()
|
||||
if vk ~= "string" then
|
||||
fail(p, "expected a key value")
|
||||
break
|
||||
end
|
||||
ent.keys[tv] = vv
|
||||
elseif tk == "punct" and tv == "{" then
|
||||
count += 1
|
||||
if count > limit then
|
||||
p.err = "limit: more than " .. limit .. " primitives"
|
||||
break
|
||||
end
|
||||
local pk, pv = p.L:peek()
|
||||
if pk == "word" and (pv == "brushDef3" or pv == "patchDef2" or pv == "patchDef3") then
|
||||
p.L:next()
|
||||
local prim = if pv == "brushDef3" then brushDef3(p) else patchDef(p, pv, 2 ^ 16)
|
||||
want(p, "}")
|
||||
table.insert(ent.prims, prim)
|
||||
else
|
||||
-- brushDef (Quake III brush primitives) and Version 1 brushes are not read
|
||||
ent.skipped += 1
|
||||
local depth = 1
|
||||
while not p.err and depth > 0 do
|
||||
local sk, sv = p.L:next()
|
||||
if not sk then
|
||||
fail(p, "unterminated primitive")
|
||||
elseif sk == "punct" and sv == "{" then
|
||||
depth += 1
|
||||
elseif sk == "punct" and sv == "}" then
|
||||
depth -= 1
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif tk == "punct" and tv == "}" then
|
||||
break
|
||||
else
|
||||
fail(p, if tk then "unexpected " .. tostring(tv) else "unterminated entity")
|
||||
end
|
||||
end
|
||||
table.insert(m.entities, ent)
|
||||
end
|
||||
if p.err then
|
||||
return nil, p.err
|
||||
end
|
||||
return m, nil
|
||||
end
|
||||
|
||||
return Parse
|
||||
@@ -0,0 +1,280 @@
|
||||
--!strict
|
||||
-- model/d3map: Doom 3 / Quake 4 / Prey editor .map ("Version 2" / "Version 3"), read only. brushDef3 sides (plane
|
||||
-- equations, Doom 3 texture matrices on the ComputeAxisBase axes) become polygons through codecs/model/Brush,
|
||||
-- patchDef2 / patchDef3 surfaces grids through codecs/model/Patch (patchDef3: its explicit subdivisions); a mesh per
|
||||
-- entity with geometry, entities as nodes (keys in extras; origin / rotation / angle on point entities), materials as
|
||||
-- URIs. From the Doom 3 GPL source docs (MapFile.cpp layout; no code taken). Not supported: writing, brushDef (Quake
|
||||
-- III brush primitives) and Version 1 brushes (counted in meta.skipped), compiling (see model/proc for dmap output).
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Sniff = require("@rosetta/core/Sniff")
|
||||
local Types = require("@rosetta/Types")
|
||||
local Brush = require("@rosetta/codecs/model/Brush")
|
||||
local Patch = require("@rosetta/codecs/model/Patch")
|
||||
local Mat4 = require("@rosetta/codecs/model/Mat4")
|
||||
local Parse = require("@rosetta/model/d3map/Parse")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
local D3map = {
|
||||
name = "d3map",
|
||||
category = "model",
|
||||
extensions = { "map" },
|
||||
mime = { "text/x-doom3-map" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/model/Brush", "codecs/model/Patch", "codecs/model/Mat4", "codecs/text/Lexer" },
|
||||
caps = { decode = true, encode = false, patches = true, variants = { "doom3", "quake4" } },
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ types
|
||||
export type DecodeOptions = {
|
||||
hull: boolean?, -- drop faces inside / touching other brushes of the same entity, default false
|
||||
merge: boolean?, -- merge coplanar faces with the same material and projection, default false
|
||||
epsilon: number?, -- default 1e-3
|
||||
patchLevel: number?, -- patchDef2 segments per sub-patch, default 4
|
||||
skip: { string }?, -- material names left out of the meshes ("textures/common/caulk", ...)
|
||||
maxPrimitives: number?, -- brushes + patches, default 2^20
|
||||
maxPolygons: number?, -- default 2^20
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
local Scene = Types.Scene
|
||||
local writef32, writeu32 = buffer.writef32, buffer.writeu32
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ sniff
|
||||
function D3map.sniff(r: Bytes.Reader): number
|
||||
local head = Sniff.text(r, 512, true)
|
||||
for _ = 1, 16 do
|
||||
local rest = string.match(head, "^//[^\n]*\n%s*(.*)$")
|
||||
if not rest then
|
||||
break
|
||||
end
|
||||
head = rest
|
||||
end
|
||||
return if string.match(head, "^Version%s+[123]%s") then 1 else 0
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
type Grid = { pos: { number }, nrm: { number }, uv: { number }, idx: { number } }
|
||||
|
||||
local function side(s: Parse.Side): Brush.Face?
|
||||
local a, b, c, d = s.plane[1], s.plane[2], s.plane[3], s.plane[4]
|
||||
local l = math.sqrt(a * a + b * b + c * c)
|
||||
if l < 1e-9 then
|
||||
return nil
|
||||
end
|
||||
-- a x + b y + c z + d = 0 with the normal outward: inside is n . p <= -d
|
||||
return { plane = { a / l, b / l, c / l, -d / l }, texture = s.material, bp = s.matrix, flags = s.flags }
|
||||
end
|
||||
|
||||
local function addPatch(prim: Parse.Prim, level: number, g: Grid): boolean
|
||||
local w, h = prim.width :: number, prim.height :: number
|
||||
local src = prim.points :: { number }
|
||||
if not Patch.valid(w, h, #src // 5) then
|
||||
return false
|
||||
end
|
||||
-- the file lists the grid column by column; Patch wants rows (point (i, j) at j * w + i)
|
||||
local rows = table.create(w * h * 5, 0) :: { number }
|
||||
for col = 0, w - 1 do
|
||||
for row = 0, h - 1 do
|
||||
table.move(src, (col * h + row) * 5 + 1, (col * h + row) * 5 + 5, (row * w + col) * 5 + 1, rows)
|
||||
end
|
||||
end
|
||||
local info = prim.info :: { number }
|
||||
local explicit = prim.type == "patchDef3"
|
||||
local su: number = if explicit then math.max(1, info[3] or 1) else level
|
||||
local sv: number = if explicit then math.max(1, info[4] or 1) else level
|
||||
local pts, gw, gh = Patch.grid(rows, w, h, 5, su, sv)
|
||||
if not pts then
|
||||
return false
|
||||
end
|
||||
local normals = Patch.normals(pts, 5, gw, gh)
|
||||
local first = #g.pos // 3
|
||||
local P, N, U = g.pos, g.nrm, g.uv
|
||||
for v = 0, gw * gh - 1 do
|
||||
P[#P + 1], P[#P + 2], P[#P + 3] = pts[v * 5 + 1], pts[v * 5 + 2], pts[v * 5 + 3]
|
||||
U[#U + 1], U[#U + 2] = pts[v * 5 + 4], pts[v * 5 + 5]
|
||||
N[#N + 1], N[#N + 2], N[#N + 3] = normals[v * 3 + 1], normals[v * 3 + 2], normals[v * 3 + 3]
|
||||
end
|
||||
local I = g.idx
|
||||
for _, t in Patch.triangles(gw, gh) do
|
||||
I[#I + 1] = first + t
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function gridPrimitive(g: Grid): Types.Primitive
|
||||
local n, ni = #g.pos // 3, #g.idx
|
||||
local bp, bn, bu, bi = buffer.create(n * 12), buffer.create(n * 12), buffer.create(n * 8), buffer.create(ni * 4)
|
||||
for i = 0, n - 1 do
|
||||
for c = 0, 2 do
|
||||
writef32(bp, i * 12 + c * 4, g.pos[i * 3 + c + 1])
|
||||
writef32(bn, i * 12 + c * 4, g.nrm[i * 3 + c + 1])
|
||||
end
|
||||
writef32(bu, i * 8, g.uv[i * 2 + 1])
|
||||
writef32(bu, i * 8 + 4, g.uv[i * 2 + 2])
|
||||
end
|
||||
for i = 0, ni - 1 do
|
||||
writeu32(bi, i * 4, g.idx[i + 1])
|
||||
end
|
||||
local attributes = { POSITION = Scene.accessor(bp, "f32", 3, n), NORMAL = Scene.accessor(bn, "f32", 3, n), TEXCOORD_0 = Scene.accessor(bu, "f32", 2, n) }
|
||||
return { attributes = attributes, indices = Scene.accessor(bi, "u32", 1, ni), mode = "triangles" :: any }
|
||||
end
|
||||
|
||||
local function numbers(s: string?, n: number): { number }?
|
||||
if type(s) ~= "string" then
|
||||
return nil
|
||||
end
|
||||
local out = {}
|
||||
for w in string.gmatch(s, "%S+") do
|
||||
local v = tonumber(w)
|
||||
if not v then
|
||||
return nil
|
||||
end
|
||||
table.insert(out, v)
|
||||
end
|
||||
return if #out == n then out else nil
|
||||
end
|
||||
|
||||
-- "rotation": the 3 x 3 axis matrix by rows (row k = local axis k in the world); "angle": yaw in degrees
|
||||
local function orientation(keys: { [string]: string }): { number }?
|
||||
local m = numbers(keys.rotation, 9)
|
||||
if m then
|
||||
return Mat4.quat({ m[1], m[2], m[3], 0, m[4], m[5], m[6], 0, m[7], m[8], m[9], 0, 0, 0, 0, 1 })
|
||||
end
|
||||
local a = tonumber(keys.angle)
|
||||
if a then
|
||||
local h = math.rad(a) / 2
|
||||
return { 0, 0, math.sin(h), math.cos(h) }
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function D3map.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?)
|
||||
local text = Sniff.dropBom(r:string(r:remaining()))
|
||||
if r.err then
|
||||
return nil, r.err
|
||||
end
|
||||
local m, msg = Parse.parse(text, opts and opts.maxPrimitives)
|
||||
if not m then
|
||||
return nil, Err.from(msg)
|
||||
end
|
||||
if #m.entities == 0 then
|
||||
return nil, Err.new(Err.CORRUPT, "no entities")
|
||||
end
|
||||
local skip: { [string]: boolean } = {}
|
||||
for _, s in opts and opts.skip or {} do
|
||||
skip[string.lower(s)] = true
|
||||
end
|
||||
local scene = Scene.new()
|
||||
scene.meta.up = "z"
|
||||
local root: Types.Node = { name = "map", children = {} }
|
||||
scene.nodes[1] = root
|
||||
scene.roots[1] = 1
|
||||
local matIndex: { [string]: number } = {}
|
||||
local function material(nm: string): number
|
||||
local i = matIndex[nm]
|
||||
if not i then
|
||||
table.insert(scene.textures, { name = nm, uri = nm })
|
||||
local mat = Scene.material(nm)
|
||||
mat.metallic = 0
|
||||
mat.baseColorTexture = { texture = #scene.textures }
|
||||
table.insert(scene.materials, mat)
|
||||
i = #scene.materials
|
||||
matIndex[nm] = i
|
||||
end
|
||||
return i
|
||||
end
|
||||
local stats = { brushes = 0, patches = 0, skippedPrimitives = 0, skippedSides = 0, badPatches = 0 }
|
||||
local entities: { { [string]: string } } = {}
|
||||
local total = 0
|
||||
local maxPolys = opts and opts.maxPolygons or 2 ^ 20
|
||||
for ei, ent in m.entities do
|
||||
local keys = ent.keys
|
||||
table.insert(entities, keys)
|
||||
stats.skippedPrimitives += ent.skipped
|
||||
local brushes: { { Brush.Face } } = {}
|
||||
local grids: { [string]: Grid } = {}
|
||||
local gridOrder: { string } = {}
|
||||
for _, prim in ent.prims do
|
||||
if prim.sides then
|
||||
stats.brushes += 1
|
||||
local faces: { Brush.Face } = {}
|
||||
for _, s in prim.sides do
|
||||
local f = side(s)
|
||||
if f then
|
||||
table.insert(faces, f)
|
||||
else
|
||||
stats.skippedSides += 1
|
||||
end
|
||||
end
|
||||
table.insert(brushes, faces)
|
||||
elseif prim.points then
|
||||
stats.patches += 1
|
||||
local mname = prim.material or ""
|
||||
if not skip[string.lower(mname)] then
|
||||
local g = grids[mname]
|
||||
if not g then
|
||||
g = { pos = {}, nrm = {}, uv = {}, idx = {} }
|
||||
grids[mname] = g
|
||||
table.insert(gridOrder, mname)
|
||||
end
|
||||
if not addPatch(prim, opts and opts.patchLevel or 4, g :: Grid) then
|
||||
stats.badPatches += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local prims: { Types.Primitive } = {}
|
||||
if #brushes > 0 then
|
||||
local polys, perr = Brush.polygons(brushes, { hull = opts and opts.hull, merge = opts and opts.merge, epsilon = opts and opts.epsilon, maxPolygons = maxPolys })
|
||||
if not polys then
|
||||
return nil, Err.from(perr)
|
||||
end
|
||||
total += #polys
|
||||
if total > maxPolys then
|
||||
return nil, Err.new(Err.LIMIT, "too many polygons")
|
||||
end
|
||||
local keep: { Brush.Polygon } = {}
|
||||
for _, poly in polys do
|
||||
if not skip[string.lower(brushes[poly.brush][poly.face].texture or "")] then
|
||||
table.insert(keep, poly)
|
||||
end
|
||||
end
|
||||
-- Doom 3 texture matrices are in texture widths already: the size divides nothing
|
||||
local function unit(_: string): (number, number)
|
||||
return 1, 1
|
||||
end
|
||||
for _, built in Brush.primitives(keep, brushes, unit) do
|
||||
built.primitive.material = material(built.texture)
|
||||
built.primitive.extras = { d3map = { material = built.texture } }
|
||||
table.insert(prims, built.primitive)
|
||||
end
|
||||
end
|
||||
for _, mname in gridOrder do
|
||||
local g = grids[mname]
|
||||
if #g.idx > 0 then
|
||||
local prim = gridPrimitive(g)
|
||||
prim.material = material(mname)
|
||||
prim.extras = { d3map = { material = mname, patch = true } }
|
||||
table.insert(prims, prim)
|
||||
end
|
||||
end
|
||||
local node: Types.Node = { name = keys.name or keys.classname or ("entity " .. (ei - 1)), children = {}, extras = { classname = keys.classname, keys = keys, entity = ei - 1 } }
|
||||
if #prims > 0 then
|
||||
table.insert(scene.meshes, { name = node.name, primitives = prims })
|
||||
node.mesh = #scene.meshes
|
||||
elseif #ent.prims == 0 then
|
||||
node.translation = numbers(keys.origin, 3)
|
||||
node.rotation = orientation(keys)
|
||||
end
|
||||
table.insert(scene.nodes, node)
|
||||
table.insert(root.children, #scene.nodes)
|
||||
end
|
||||
scene.meta.entities = entities
|
||||
scene.meta.counts = stats
|
||||
scene.meta.source = { format = "d3map", version = m.version, variant = if m.version >= 3 then "quake4" else "doom3", entities = #m.entities, brushes = stats.brushes, patches = stats.patches }
|
||||
return scene, nil
|
||||
end
|
||||
|
||||
return D3map
|
||||
@@ -0,0 +1,380 @@
|
||||
--!strict
|
||||
-- model/proc: Doom 3 / Quake 4 / Prey `.proc` render geometry (dmap output: "mapProcFile003", Quake 4 "PROC" "4"; the
|
||||
-- Doom 3 GPL source's RenderWorld_load.cpp read for the layout, no code taken), read only. Every model (areas
|
||||
-- "_areaN", inline entity models) is a mesh with a primitive per surface and a node; materials are URIs. Portals,
|
||||
-- the BSP nodes and shadow models load as data in meta.proc. Triangles are clockwise-front in id Tech 4
|
||||
-- (R_DeriveFacePlanes: normal = d2 x d1) and are turned counter-clockwise. Not supported: writing.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Sniff = require("@rosetta/core/Sniff")
|
||||
local Types = require("@rosetta/Types")
|
||||
local Lexer = require("@rosetta/codecs/text/Lexer")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
local Proc = {
|
||||
name = "proc",
|
||||
category = "model",
|
||||
extensions = { "proc" },
|
||||
mime = { "model/x-doom3-proc" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Lexer" },
|
||||
caps = { decode = true, encode = false, portals = true },
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ types
|
||||
export type DecodeOptions = {
|
||||
maxVertices: number?, -- default 2^24 over the file
|
||||
shadows: boolean?, -- default true: keep shadow models in meta.proc.shadowModels
|
||||
}
|
||||
export type Portal = { positive: number, negative: number, points: { number } } -- areas; points x, y, z, ...
|
||||
export type BspNode = { plane: { number }, positive: number, negative: number } -- children: > 0 node (1-based), 0 solid, < 0 area -1 - n
|
||||
export type ShadowModel = { name: string, vertices: { number }, indices: { number }, noCaps: number, noFrontCaps: number, planeBits: number }
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
local Scene = Types.Scene
|
||||
local writef32, writeu32 = buffer.writef32, buffer.writeu32
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ sniff
|
||||
function Proc.sniff(r: Bytes.Reader): number
|
||||
local head = Sniff.text(r, 64, true)
|
||||
if string.match(head, "^mapProcFile%d%d%d") then
|
||||
return 1
|
||||
end
|
||||
if string.match(head, '^"?PROC"?%s+"?%d') then
|
||||
return 0.9
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
type P = { L: Lexer.Lexer, err: string? }
|
||||
|
||||
local function fail(p: P, msg: string)
|
||||
if not p.err then
|
||||
p.err = (p.L.err or msg) .. " at line " .. p.L:line()
|
||||
end
|
||||
end
|
||||
|
||||
local function num(p: P): number
|
||||
local k, v = p.L:next()
|
||||
if k ~= "number" then
|
||||
fail(p, "expected a number")
|
||||
return 0
|
||||
end
|
||||
return v
|
||||
end
|
||||
|
||||
local function punct(p: P, c: string)
|
||||
local k, v = p.L:next()
|
||||
if k ~= "punct" or v ~= c then
|
||||
fail(p, "expected " .. c)
|
||||
end
|
||||
end
|
||||
|
||||
local function str(p: P): string
|
||||
local k, v = p.L:next()
|
||||
if k ~= "string" and k ~= "word" then
|
||||
fail(p, "expected a name")
|
||||
return ""
|
||||
end
|
||||
return v
|
||||
end
|
||||
|
||||
-- numbers up to the next punctuation (the counts after a model / surface name)
|
||||
local function counts(p: P): { number }
|
||||
local out = {}
|
||||
while not p.err do
|
||||
local k, v = p.L:peek()
|
||||
if k ~= "number" then
|
||||
break
|
||||
end
|
||||
p.L:next()
|
||||
table.insert(out, v)
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
local function skipBlock(p: P)
|
||||
local depth = 1
|
||||
while not p.err do
|
||||
local k, v = p.L:next()
|
||||
if not k then
|
||||
fail(p, "unterminated block")
|
||||
return
|
||||
end
|
||||
if k == "punct" then
|
||||
if v == "{" then
|
||||
depth += 1
|
||||
elseif v == "}" then
|
||||
depth -= 1
|
||||
if depth == 0 then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
type Surface = { material: string, verts: { number }, arity: number, indices: { number } }
|
||||
|
||||
local function surface(p: P, budget: { number }): Surface?
|
||||
local material = str(p)
|
||||
local c = counts(p)
|
||||
if p.err then
|
||||
return nil
|
||||
end
|
||||
if #c < 2 then
|
||||
fail(p, "surface without vertex / index counts")
|
||||
return nil
|
||||
end
|
||||
local nv, ni = c[#c - 1], c[#c]
|
||||
if nv < 0 or ni < 0 or nv % 1 ~= 0 or ni % 1 ~= 0 or ni % 3 ~= 0 then
|
||||
fail(p, "bad surface counts")
|
||||
return nil
|
||||
end
|
||||
budget[1] -= nv
|
||||
if budget[1] < 0 then
|
||||
p.err = "limit: too many vertices"
|
||||
return nil
|
||||
end
|
||||
local verts: { number } = {}
|
||||
local arity = 0
|
||||
for i = 1, nv do
|
||||
punct(p, "(")
|
||||
local n = 0
|
||||
while not p.err do
|
||||
local k, v = p.L:next()
|
||||
if k == "number" then
|
||||
n += 1
|
||||
table.insert(verts, v)
|
||||
elseif k == "punct" and v == ")" then
|
||||
break
|
||||
else
|
||||
fail(p, "bad vertex")
|
||||
end
|
||||
end
|
||||
if p.err then
|
||||
return nil
|
||||
end
|
||||
if i == 1 then
|
||||
arity = n
|
||||
if n < 8 then
|
||||
fail(p, "a vertex needs x y z s t nx ny nz")
|
||||
return nil
|
||||
end
|
||||
elseif n ~= arity then
|
||||
fail(p, "vertices of different sizes")
|
||||
return nil
|
||||
end
|
||||
end
|
||||
local idx: { number } = table.create(ni, 0)
|
||||
for i = 1, ni do
|
||||
local v = num(p)
|
||||
if v < 0 or v >= nv or v % 1 ~= 0 then
|
||||
fail(p, "index out of range")
|
||||
return nil
|
||||
end
|
||||
idx[i] = v
|
||||
end
|
||||
punct(p, "}")
|
||||
return { material = material, verts = verts, arity = arity, indices = idx }
|
||||
end
|
||||
|
||||
local function primitive(scene: Types.Scene, s: Surface, matIndex: { [string]: number }): Types.Primitive
|
||||
local a = s.arity
|
||||
local n = #s.verts // a
|
||||
local pb, nb, ub = buffer.create(n * 12), buffer.create(n * 12), buffer.create(n * 8)
|
||||
local cb: buffer? = if a >= 12 then buffer.create(n * 16) else nil
|
||||
local V = s.verts
|
||||
for i = 0, n - 1 do
|
||||
local o = i * a
|
||||
writef32(pb, i * 12, V[o + 1])
|
||||
writef32(pb, i * 12 + 4, V[o + 2])
|
||||
writef32(pb, i * 12 + 8, V[o + 3])
|
||||
writef32(ub, i * 8, V[o + 4])
|
||||
writef32(ub, i * 8 + 4, V[o + 5])
|
||||
writef32(nb, i * 12, V[o + 6])
|
||||
writef32(nb, i * 12 + 4, V[o + 7])
|
||||
writef32(nb, i * 12 + 8, V[o + 8])
|
||||
if cb then
|
||||
for k = 0, 3 do
|
||||
local c = V[o + 9 + k]
|
||||
writef32(cb, i * 16 + k * 4, if c > 1 then c / 255 else c)
|
||||
end
|
||||
end
|
||||
end
|
||||
local ni = #s.indices
|
||||
local ib = buffer.create(ni * 4)
|
||||
for t = 0, ni - 1, 3 do
|
||||
writeu32(ib, t * 4, s.indices[t + 1])
|
||||
writeu32(ib, t * 4 + 4, s.indices[t + 3])
|
||||
writeu32(ib, t * 4 + 8, s.indices[t + 2])
|
||||
end
|
||||
local mi = matIndex[s.material]
|
||||
if not mi then
|
||||
table.insert(scene.textures, { name = s.material, uri = s.material })
|
||||
local mat = Scene.material(s.material)
|
||||
mat.metallic = 0
|
||||
mat.baseColorTexture = { texture = #scene.textures }
|
||||
table.insert(scene.materials, mat)
|
||||
mi = #scene.materials
|
||||
matIndex[s.material] = mi
|
||||
end
|
||||
local attrs: { [string]: Types.Accessor } = {
|
||||
POSITION = Scene.accessor(pb, "f32", 3, n),
|
||||
NORMAL = Scene.accessor(nb, "f32", 3, n),
|
||||
TEXCOORD_0 = Scene.accessor(ub, "f32", 2, n),
|
||||
}
|
||||
if cb then
|
||||
attrs.COLOR_0 = Scene.accessor(cb, "f32", 4, n)
|
||||
end
|
||||
return { attributes = attrs, indices = Scene.accessor(ib, "u32", 1, ni), mode = "triangles" :: any, material = mi, extras = { proc = { material = s.material } } }
|
||||
end
|
||||
|
||||
function Proc.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?)
|
||||
local text = Sniff.dropBom(r:string(r:remaining()))
|
||||
if r.err then
|
||||
return nil, r.err
|
||||
end
|
||||
local p: P = { L = Lexer.new(text), err = nil }
|
||||
local k, head = p.L:next()
|
||||
local version: string
|
||||
if (k == "word" or k == "string") and string.match(head, "^mapProcFile%d+$") then
|
||||
version = head
|
||||
elseif (k == "word" or k == "string") and head == "PROC" then
|
||||
local vk, vv = p.L:next()
|
||||
if vk ~= "number" and vk ~= "string" then
|
||||
return nil, Err.new(Err.CORRUPT, "PROC without a version")
|
||||
end
|
||||
version = "PROC " .. tostring(vv)
|
||||
else
|
||||
return nil, Err.new(Err.CORRUPT, "not a .proc file")
|
||||
end
|
||||
local scene = Scene.new()
|
||||
scene.meta.up = "z"
|
||||
local world: Types.Node = { name = "proc", children = {} }
|
||||
table.insert(scene.nodes, world)
|
||||
scene.roots[1] = 1
|
||||
local info = { version = version, areas = 0, models = {}, portals = {} :: { Portal }, nodes = {} :: { BspNode }, shadowModels = {} :: { ShadowModel } }
|
||||
local matIndex: { [string]: number } = {}
|
||||
local budget = { opts and opts.maxVertices or 2 ^ 24 }
|
||||
local keepShadows = not (opts and opts.shadows == false)
|
||||
while not p.err do
|
||||
local tk, tv = p.L:next()
|
||||
if not tk then
|
||||
if p.L.err then
|
||||
fail(p, p.L.err)
|
||||
end
|
||||
break
|
||||
end
|
||||
if tk ~= "word" then
|
||||
fail(p, "expected a section name")
|
||||
break
|
||||
end
|
||||
punct(p, "{")
|
||||
local section = string.lower(tv)
|
||||
if section == "model" then
|
||||
local name = str(p)
|
||||
local c = counts(p)
|
||||
local ns = c[1] or 0
|
||||
local mesh: Types.Mesh = { name = name, primitives = {} }
|
||||
for _ = 1, ns do
|
||||
punct(p, "{")
|
||||
local s = surface(p, budget)
|
||||
if not s then
|
||||
break
|
||||
end
|
||||
table.insert(mesh.primitives, primitive(scene, s, matIndex))
|
||||
end
|
||||
punct(p, "}")
|
||||
if p.err then
|
||||
break
|
||||
end
|
||||
table.insert(scene.meshes, mesh)
|
||||
table.insert(scene.nodes, { name = name, children = {}, mesh = #scene.meshes })
|
||||
table.insert(world.children, #scene.nodes)
|
||||
table.insert(info.models, { name = name, surfaces = #mesh.primitives, area = tonumber(string.match(name, "^_area(%d+)$")) })
|
||||
elseif section == "interareaportals" then
|
||||
info.areas = num(p)
|
||||
local n = num(p)
|
||||
for _ = 1, n do
|
||||
if p.err then
|
||||
break
|
||||
end
|
||||
local np = num(p)
|
||||
local pos, neg = num(p), num(p)
|
||||
local pts = {}
|
||||
for _ = 1, np do
|
||||
punct(p, "(")
|
||||
table.insert(pts, num(p))
|
||||
table.insert(pts, num(p))
|
||||
table.insert(pts, num(p))
|
||||
punct(p, ")")
|
||||
if p.err then
|
||||
break
|
||||
end
|
||||
end
|
||||
table.insert(info.portals, { positive = pos, negative = neg, points = pts })
|
||||
end
|
||||
punct(p, "}")
|
||||
elseif section == "nodes" then
|
||||
local n = num(p)
|
||||
for _ = 1, n do
|
||||
if p.err then
|
||||
break
|
||||
end
|
||||
punct(p, "(")
|
||||
local pl = { num(p), num(p), num(p), num(p) }
|
||||
punct(p, ")")
|
||||
local pos, neg = num(p), num(p)
|
||||
table.insert(info.nodes, { plane = pl, positive = if pos > 0 then pos + 1 else pos, negative = if neg > 0 then neg + 1 else neg })
|
||||
end
|
||||
punct(p, "}")
|
||||
elseif section == "shadowmodel" then
|
||||
local name = str(p)
|
||||
local c = counts(p)
|
||||
if #c < 5 then
|
||||
fail(p, "shadow model without counts")
|
||||
break
|
||||
end
|
||||
local nv, ni = c[1], c[4]
|
||||
budget[1] -= nv
|
||||
if nv < 0 or ni < 0 or budget[1] < 0 then
|
||||
p.err = if budget[1] < 0 then "limit: too many vertices" else "bad shadow model counts"
|
||||
break
|
||||
end
|
||||
local verts, idx = {}, {}
|
||||
for _ = 1, nv do
|
||||
punct(p, "(")
|
||||
table.insert(verts, num(p))
|
||||
table.insert(verts, num(p))
|
||||
table.insert(verts, num(p))
|
||||
punct(p, ")")
|
||||
if p.err then
|
||||
break
|
||||
end
|
||||
end
|
||||
for _ = 1, ni do
|
||||
table.insert(idx, num(p))
|
||||
if p.err then
|
||||
break
|
||||
end
|
||||
end
|
||||
punct(p, "}")
|
||||
if keepShadows then
|
||||
table.insert(info.shadowModels, { name = name, vertices = verts, indices = idx, noCaps = c[2], noFrontCaps = c[3], planeBits = c[5] })
|
||||
end
|
||||
else
|
||||
skipBlock(p)
|
||||
end
|
||||
end
|
||||
if p.err then
|
||||
return nil, Err.from(p.err)
|
||||
end
|
||||
scene.meta.proc = info
|
||||
scene.meta.source = { format = "proc", version = version, models = #info.models, portals = #info.portals, nodes = #info.nodes, areas = info.areas }
|
||||
return scene, nil
|
||||
end
|
||||
|
||||
return Proc
|
||||
@@ -0,0 +1,81 @@
|
||||
--!strict
|
||||
-- model/udmf: a standalone UDMF TEXTMAP (UDMF 1.1, zdoom.org specs/udmf.txt) into a Scene through codecs/model/DoomMap,
|
||||
-- read only. Texture sizes come from opts.textureSize (default 64 x 128 walls, 64 x 64 flats); textures are URIs.
|
||||
-- Maps inside a WAD load through archive/wad (Wad.map). Not supported: writing, slopes, per-part offsets.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Sniff = require("@rosetta/core/Sniff")
|
||||
local Types = require("@rosetta/Types")
|
||||
local DoomMap = require("@rosetta/codecs/model/DoomMap")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
local Udmf = {
|
||||
name = "udmf",
|
||||
category = "model",
|
||||
extensions = { "udmf", "textmap" },
|
||||
mime = { "text/x-udmf" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/model/DoomMap" },
|
||||
caps = { decode = true, encode = false, maps = true },
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ types
|
||||
export type DecodeOptions = {
|
||||
textureSize: ((kind: string, name: string) -> (number?, number?))?, -- kind "texture" or "flat"
|
||||
decodeTexture: ((kind: string, name: string) -> Types.Image?)?,
|
||||
name: string?, -- the mesh name, default "MAP"
|
||||
maxBlocks: number?, -- default 2^22
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ sniff
|
||||
function Udmf.sniff(r: Bytes.Reader): number
|
||||
local head = Sniff.text(r, 1024, true)
|
||||
for _ = 1, 32 do
|
||||
local rest = string.match(head, "^//[^\n]*\n%s*(.*)$") or string.match(head, "^/%*.-%*/%s*(.*)$")
|
||||
if not rest then
|
||||
break
|
||||
end
|
||||
head = rest
|
||||
end
|
||||
if string.match(head, "^[Nn][Aa][Mm][Ee][Ss][Pp][Aa][Cc][Ee]%s*=%s*\"") then
|
||||
return 0.9
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
function Udmf.data(r: Bytes.Reader, opts: DecodeOptions?): (DoomMap.MapData?, Err.Err?)
|
||||
local text = Sniff.dropBom(r:string(r:remaining()))
|
||||
if r.err then
|
||||
return nil, r.err
|
||||
end
|
||||
local m, msg = DoomMap.udmf(text, opts and opts.maxBlocks)
|
||||
if not m then
|
||||
return nil, Err.from(msg)
|
||||
end
|
||||
return m, nil
|
||||
end
|
||||
|
||||
function Udmf.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?)
|
||||
local m, err = Udmf.data(r, opts)
|
||||
if not m then
|
||||
return nil, err
|
||||
end
|
||||
local size = opts and opts.textureSize
|
||||
local tex: DoomMap.Textures = {
|
||||
size = function(kind: string, name: string): (number?, number?)
|
||||
if size then
|
||||
return size(kind, name)
|
||||
end
|
||||
return nil, nil
|
||||
end,
|
||||
image = opts and opts.decodeTexture,
|
||||
}
|
||||
local name = opts and opts.name or "MAP"
|
||||
local scene = DoomMap.scene(m, tex, name)
|
||||
scene.meta.source = { format = "udmf", namespace = m.namespace, things = #m.things, linedefs = #m.linedefs, sectors = #m.sectors, vertices = #m.vertices // 2 }
|
||||
return scene, nil
|
||||
end
|
||||
|
||||
return Udmf
|
||||
@@ -0,0 +1,95 @@
|
||||
--!strict
|
||||
--!native
|
||||
-- vector/gamemaps/Expand: id's Carmack (near 0xA7 / far 0xA8 word copies) and RLEW (tag, count, value) expansion of
|
||||
-- GAMEMAPS planes (ModdingWiki "Carmack compression", "RLEW compression"; no code taken). Words are u16 LE.
|
||||
local Expand = {}
|
||||
|
||||
local readu8, readu16, writeu16 = buffer.readu8, buffer.readu16, buffer.writeu16
|
||||
|
||||
function Expand.carmack(b: buffer, at: number, n: number, outBytes: number): (buffer?, string?)
|
||||
if outBytes % 2 ~= 0 then
|
||||
return nil, "odd Carmack length"
|
||||
end
|
||||
local out = buffer.create(outBytes)
|
||||
local words = outBytes // 2
|
||||
local o = 0
|
||||
local p, e = at, at + n
|
||||
while o < words do
|
||||
if p + 2 > e then
|
||||
return nil, "truncated Carmack data"
|
||||
end
|
||||
local w = readu16(b, p)
|
||||
p += 2
|
||||
local hi = w // 256
|
||||
if hi == 0xA7 or hi == 0xA8 then
|
||||
local count = w % 256
|
||||
if count == 0 then
|
||||
if p + 1 > e then
|
||||
return nil, "truncated Carmack data"
|
||||
end
|
||||
writeu16(out, o * 2, hi * 256 + readu8(b, p))
|
||||
p += 1
|
||||
o += 1
|
||||
else
|
||||
local from
|
||||
if hi == 0xA7 then
|
||||
if p + 1 > e then
|
||||
return nil, "truncated Carmack data"
|
||||
end
|
||||
from = o - readu8(b, p)
|
||||
p += 1
|
||||
else
|
||||
if p + 2 > e then
|
||||
return nil, "truncated Carmack data"
|
||||
end
|
||||
from = readu16(b, p)
|
||||
p += 2
|
||||
end
|
||||
if from < 0 or from >= o or o + count > words then
|
||||
return nil, "bad Carmack copy"
|
||||
end
|
||||
for k = 0, count - 1 do
|
||||
writeu16(out, (o + k) * 2, readu16(out, (from + k) * 2))
|
||||
end
|
||||
o += count
|
||||
end
|
||||
else
|
||||
writeu16(out, o * 2, w)
|
||||
o += 1
|
||||
end
|
||||
end
|
||||
return out, nil
|
||||
end
|
||||
|
||||
function Expand.rlew(b: buffer, at: number, n: number, outWords: number, tag: number): (buffer?, string?)
|
||||
local out = buffer.create(outWords * 2)
|
||||
local o = 0
|
||||
local p, e = at, at + n
|
||||
while o < outWords do
|
||||
if p + 2 > e then
|
||||
return nil, "truncated RLEW data"
|
||||
end
|
||||
local w = readu16(b, p)
|
||||
p += 2
|
||||
if w == tag then
|
||||
if p + 4 > e then
|
||||
return nil, "truncated RLEW data"
|
||||
end
|
||||
local count, v = readu16(b, p), readu16(b, p + 2)
|
||||
p += 4
|
||||
if o + count > outWords then
|
||||
return nil, "RLEW run past the plane"
|
||||
end
|
||||
for k = 0, count - 1 do
|
||||
writeu16(out, (o + k) * 2, v)
|
||||
end
|
||||
o += count
|
||||
else
|
||||
writeu16(out, o * 2, w)
|
||||
o += 1
|
||||
end
|
||||
end
|
||||
return out, nil
|
||||
end
|
||||
|
||||
return Expand
|
||||
@@ -0,0 +1,185 @@
|
||||
--!strict
|
||||
-- vector/gamemaps: Wolfenstein 3D / Spear of Destiny maps (GAMEMAPS "TED5v1.0" + MAPHEAD: RLEW tag, 100 header
|
||||
-- offsets; map headers of 3 planes, Carmack then RLEW compressed; ModdingWiki "GameMaps Format", no code taken) into a
|
||||
-- TileMap: one tile layer per plane ("walls", "objects", "plane3") with the raw tile values as data (no tileset).
|
||||
-- Either file loads; the other comes through opts.files / opts.resolve. Not supported: writing, uncompressed
|
||||
-- (MAPTEMP / Wolf3D 1.0) maps, Huffman-compressed (Keen) maps.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Input = require("@rosetta/core/Input")
|
||||
local Types = require("@rosetta/Types")
|
||||
local Expand = require("@rosetta/vector/gamemaps/Expand")
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
local Gamemaps = {
|
||||
name = "gamemaps",
|
||||
category = "vector",
|
||||
extensions = { "wl6", "wl1", "sod", "sdm" },
|
||||
mime = { "application/x-wolf3d-gamemaps" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Input", "Types" },
|
||||
caps = { decode = true, encode = false, tilemap = true },
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ types
|
||||
export type DecodeOptions = {
|
||||
map: number?, -- 1-based map slot, default the first present
|
||||
name: string?, -- the file name: picks the sibling's extension (GAMEMAPS.WL6 <-> MAPHEAD.WL6)
|
||||
files: { [string]: buffer | string }?,
|
||||
resolve: ((uri: string) -> (buffer | string)?)?,
|
||||
mapHead: (buffer | string)?, -- MAPHEAD given directly
|
||||
gameMaps: (buffer | string)?, -- GAMEMAPS given directly
|
||||
maxTiles: number?, -- default 2^20 per plane
|
||||
}
|
||||
export type MapInfo = { slot: number, name: string, width: number, height: number, offset: number }
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
local MAGIC = "TED5v1.0"
|
||||
local LAYERS = { "walls", "objects", "plane3" }
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ sniff
|
||||
function Gamemaps.sniff(r: Bytes.Reader): number
|
||||
if r:peek(8) == MAGIC then
|
||||
return 1
|
||||
end
|
||||
-- MAPHEAD: the RLEW tag 0xABCD, then 100 offsets (0 / -1 when absent)
|
||||
if r:remaining() >= 402 and r:remaining() <= 1024 and buffer.readu16(r.buf, r.base) == 0xABCD then
|
||||
local first = buffer.readi32(r.buf, r.base + 2)
|
||||
if first > 0 then
|
||||
return 0.7
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
local function asBuffer(v: any): buffer?
|
||||
if type(v) == "string" then
|
||||
return buffer.fromstring(v)
|
||||
end
|
||||
return if type(v) == "buffer" then v else nil
|
||||
end
|
||||
|
||||
local function sibling(opts: DecodeOptions?, stem: string): buffer?
|
||||
local name = opts and opts.name
|
||||
local ext = name and string.match(name, "%.([^./\\]+)$") or "WL6"
|
||||
local dir = name and string.match(name, "^(.*[/\\])") or ""
|
||||
for _, n in { stem .. "." .. ext, string.upper(stem .. "." .. ext), string.lower(stem .. "." .. ext) } do
|
||||
local got = Input.sibling(opts, dir .. n) or Input.sibling(opts, n)
|
||||
if got then
|
||||
return got
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
type Pair = { head: buffer, maps: buffer, tag: number }
|
||||
|
||||
local function pair(r: Bytes.Reader, opts: DecodeOptions?): (Pair?, Err.Err?)
|
||||
local self = buffer.create(r.limit - r.base)
|
||||
buffer.copy(self, 0, r.buf, r.base, r.limit - r.base)
|
||||
local head: buffer, maps: buffer
|
||||
if buffer.len(self) >= 8 and buffer.readstring(self, 0, 8) == MAGIC then
|
||||
maps = self
|
||||
local got = asBuffer(opts and opts.mapHead) or sibling(opts, "MAPHEAD")
|
||||
if not got then
|
||||
return nil, Err.new(Err.UNSUPPORTED, "MAPHEAD not available (opts.mapHead / opts.files / opts.resolve)")
|
||||
end
|
||||
head = got
|
||||
else
|
||||
head = self
|
||||
local got = asBuffer(opts and opts.gameMaps) or sibling(opts, "GAMEMAPS")
|
||||
if not got then
|
||||
return nil, Err.new(Err.UNSUPPORTED, "GAMEMAPS not available (opts.gameMaps / opts.files / opts.resolve)")
|
||||
end
|
||||
maps = got
|
||||
end
|
||||
if buffer.len(head) < 2 then
|
||||
return nil, Err.new(Err.TRUNCATED, "MAPHEAD")
|
||||
end
|
||||
return { head = head, maps = maps, tag = buffer.readu16(head, 0) }, nil
|
||||
end
|
||||
|
||||
local function list(p: Pair): { MapInfo }
|
||||
local out: { MapInfo } = {}
|
||||
local hn = math.min(100, (buffer.len(p.head) - 2) // 4)
|
||||
local size = buffer.len(p.maps)
|
||||
for i = 0, hn - 1 do
|
||||
local o = buffer.readi32(p.head, 2 + i * 4)
|
||||
if o > 0 and o + 38 <= size then
|
||||
local nm = buffer.readstring(p.maps, o + 22, 16)
|
||||
local z = string.find(nm, "\0", 1, true)
|
||||
table.insert(out, { slot = i + 1, name = if z then string.sub(nm, 1, z - 1) else nm, width = buffer.readu16(p.maps, o + 18), height = buffer.readu16(p.maps, o + 20), offset = o })
|
||||
end
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
function Gamemaps.maps(r: Bytes.Reader, opts: DecodeOptions?): ({ MapInfo }?, Err.Err?)
|
||||
local p, err = pair(r, opts)
|
||||
if not p then
|
||||
return nil, err
|
||||
end
|
||||
return list(p), nil
|
||||
end
|
||||
|
||||
function Gamemaps.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.TileMap?, Err.Err?)
|
||||
local p, err = pair(r, opts)
|
||||
if not p then
|
||||
return nil, err
|
||||
end
|
||||
local maps = list(p)
|
||||
if #maps == 0 then
|
||||
return nil, Err.new(Err.CORRUPT, "no maps in MAPHEAD")
|
||||
end
|
||||
local want = opts and opts.map
|
||||
local m: MapInfo? = if want then nil else maps[1]
|
||||
for _, x in maps do
|
||||
if x.slot == want then
|
||||
m = x
|
||||
end
|
||||
end
|
||||
if not m then
|
||||
return nil, Err.new(Err.ARG, "no map in slot " .. tostring(want))
|
||||
end
|
||||
local w, h = m.width, m.height
|
||||
if w == 0 or h == 0 or w * h > (opts and opts.maxTiles or 2 ^ 20) then
|
||||
return nil, Err.new(if w * h == 0 then Err.CORRUPT else Err.LIMIT, "map size " .. w .. " x " .. h)
|
||||
end
|
||||
local b = p.maps
|
||||
local size = buffer.len(b)
|
||||
local tm = Types.TileMap.new(w, h, 64, 64)
|
||||
for k = 0, 2 do
|
||||
local at = buffer.readi32(b, m.offset + k * 4)
|
||||
local n = buffer.readu16(b, m.offset + 12 + k * 2)
|
||||
if at > 0 and n >= 2 then
|
||||
if at + n > size then
|
||||
return nil, Err.new(Err.TRUNCATED, "plane " .. (k + 1) .. " past the end", at)
|
||||
end
|
||||
local carmackLen = buffer.readu16(b, at)
|
||||
local mid, msg = Expand.carmack(b, at + 2, n - 2, carmackLen)
|
||||
if not mid then
|
||||
return nil, Err.from(msg, at)
|
||||
end
|
||||
if carmackLen < 2 or buffer.readu16(mid, 0) ~= w * h * 2 then
|
||||
return nil, Err.new(Err.CORRUPT, "plane " .. (k + 1) .. ": RLEW length is not width x height", at)
|
||||
end
|
||||
local plane, rmsg = Expand.rlew(mid, 2, carmackLen - 2, w * h, p.tag)
|
||||
if not plane then
|
||||
return nil, Err.from(rmsg, at)
|
||||
end
|
||||
local data = table.create(w * h, 0)
|
||||
for i = 0, w * h - 1 do
|
||||
data[i + 1] = buffer.readu16(plane, i * 2)
|
||||
end
|
||||
local layer: Types.TileLayer = { type = "tiles", id = k + 1, name = LAYERS[k + 1], width = w, height = h, data = data, visible = true, opacity = 1, properties = {} }
|
||||
table.insert(tm.layers, layer)
|
||||
end
|
||||
end
|
||||
tm.properties.name = m.name
|
||||
tm.meta.source = { format = "gamemaps", map = m.slot, name = m.name, rlewTag = p.tag, maps = maps }
|
||||
return tm, nil
|
||||
end
|
||||
|
||||
return Gamemaps
|
||||
@@ -0,0 +1,66 @@
|
||||
-- archive/vswap tests: a Wolfenstein 3D page file written by the fixture's own writer (walls, sprites with gaps,
|
||||
-- sounds across pages) against its source pixels and samples.
|
||||
-- Fixtures: tools/fixtures/wolf3d.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@rosetta")
|
||||
local Vswap = require("@rosetta/archive/vswap")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Crc32 = require("@rosetta/core/Crc32")
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Fx = require("@tests/gen/wolf3d")
|
||||
|
||||
local t = T.suite("vswap")
|
||||
t:eq(Vswap.name, "vswap", "name")
|
||||
|
||||
local vs = Fx.vswap
|
||||
t:eq(F.detect(vs.data, { name = "VSWAP.WL6" }), "vswap", "F.detect VSWAP")
|
||||
local a, err = Vswap.decode(Bytes.reader(buffer.fromstring(vs.data)))
|
||||
t:check(a, "vswap: " .. tostring(err))
|
||||
do
|
||||
local list = a:list()
|
||||
t:eq(list[1].name, "walls/000", "wall entry")
|
||||
t:eq(list[#vs.walls + 1].name, "sprites/000", "sprite entry")
|
||||
t:eq(list[#list].name, "soundinfo", "sound info entry")
|
||||
t:eq(a.meta.source.walls, #vs.walls, "wall count")
|
||||
t:eq(a.meta.source.sprites, #vs.sprites, "sprite count")
|
||||
for i, crc in vs.walls do
|
||||
local img, e = Vswap.image(a, "wall", i - 1, { palette = Fx.palette })
|
||||
t:check(img, "wall " .. i .. ": " .. tostring(e))
|
||||
t:eq(Crc32.of((img :: any).pixels), crc, "wall " .. i .. " pixels (column-major, 6-bit palette)")
|
||||
end
|
||||
for i, crc in vs.sprites do
|
||||
local img, e = Vswap.image(a, "sprite", i - 1, { palette = Fx.palette })
|
||||
t:check(img, "sprite " .. i .. ": " .. tostring(e))
|
||||
t:eq(Crc32.of((img :: any).pixels), crc, "sprite " .. i .. " pixels and holes")
|
||||
end
|
||||
local grey = Vswap.image(a, "wall", 0) :: any
|
||||
t:eq(grey.meta.source.palette, false, "no palette: grey")
|
||||
t:eq(Vswap.sounds(a), #vs.sounds, "sound count")
|
||||
for i, s in vs.sounds do
|
||||
local au, e = Vswap.sound(a, i)
|
||||
t:check(au, "sound " .. i .. ": " .. tostring(e))
|
||||
local x = au :: any
|
||||
t:eq(x.frames, s.bytes, "sound " .. i .. " length (across pages)")
|
||||
t:eq(buffer.readf32(x.samples, 0), (s.first - 128) / 128, "sound " .. i .. " first sample")
|
||||
t:eq(buffer.readf32(x.samples, (s.bytes - 1) * 4), (s.last - 128) / 128, "sound " .. i .. " last sample")
|
||||
t:eq(x.sampleRate, 7042, "rate")
|
||||
end
|
||||
local _, e1 = Vswap.image(a, "wall", 99)
|
||||
t:check(e1 and e1.code == Err.ARG, "missing wall")
|
||||
local _, e2 = Vswap.sound(a, 0)
|
||||
t:check(e2 and e2.code == Err.ARG, "missing sound")
|
||||
end
|
||||
|
||||
t:fuzz("vswap", function(b: buffer)
|
||||
local w = Vswap.decode(Bytes.reader(b))
|
||||
if w then
|
||||
for i = 0, 3 do
|
||||
Vswap.image(w, "wall", i)
|
||||
Vswap.image(w, "sprite", i)
|
||||
end
|
||||
Vswap.sound(w, 1)
|
||||
Vswap.sound(w, 2)
|
||||
end
|
||||
return w
|
||||
end, { buffer.fromstring(vs.data) }, { mutations = 300 })
|
||||
t:done()
|
||||
@@ -121,8 +121,8 @@ do
|
||||
t:eq(names[17], "E1M2/ENDMAP", "up to ENDMAP")
|
||||
t:eq(names[18], "DEMO1", "after the map")
|
||||
t:eq(names[19], "DEMO1~2", "duplicate names get ~n")
|
||||
local _, ue = Wad.map(rm, "E1M2")
|
||||
t:check(ue and ue.code == Err.UNSUPPORTED, "UDMF unsupported")
|
||||
local us = Wad.map(rm, "E1M2") :: any
|
||||
t:check(us and us.meta.source.mapFormat == "udmf" and #us.meshes[1].primitives == 0, "UDMF stub: an empty map")
|
||||
local s = Wad.map(rm, "E1M1") :: any
|
||||
local area = { floor = 0, ceil = 0, wall = 0 }
|
||||
for _, p in s.meshes[1].primitives do
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
-- codecs/text/Lexer tests: token kinds, comments, escapes, numbers, errors, and a no-throw pass.
|
||||
local T = require("@tests/T")
|
||||
local Lexer = require("@rosetta/codecs/text/Lexer")
|
||||
|
||||
local t = T.suite("lexer")
|
||||
|
||||
local function all(s: string): ({ string }, string?)
|
||||
local L = Lexer.new(s)
|
||||
local out = {}
|
||||
while true do
|
||||
local k, v = L:next()
|
||||
if not k then
|
||||
break
|
||||
end
|
||||
table.insert(out, k .. ":" .. tostring(v))
|
||||
end
|
||||
return out, L.err
|
||||
end
|
||||
|
||||
local got = all('Version 2 // c\n{ "a \\"b\\"" ( -0.5 25e-2 0x10 ) /* x\n y */ textures/base_wall/lfwall13f3 a=b; }')
|
||||
t:eq(table.concat(got, " "), 'word:Version number:2 punct:{ string:a "b" punct:( number:-0.5 number:0.25 number:16 punct:) word:textures/base_wall/lfwall13f3 word:a punct:= word:b punct:; punct:}', "tokens")
|
||||
local L = Lexer.new("a // tail")
|
||||
t:eq(select(2, L:peek()), "a", "peek")
|
||||
t:eq(select(2, L:next()), "a", "next after peek")
|
||||
t:eq(L:next(), nil, "end after a trailing comment")
|
||||
t:eq(table.concat((all("x/*y*/z")), " "), "word:x word:z", "a comment ends a word")
|
||||
t:eq(table.concat((all("- inf 1.2.3")), " "), "word:- word:inf word:1.2.3", "not numbers")
|
||||
t:eq(select(2, all('"open')), "unterminated string", "unterminated string")
|
||||
t:eq(select(2, all("/* open")), "unterminated comment", "unterminated comment")
|
||||
local L2 = Lexer.new("a\nb\nc")
|
||||
L2:next()
|
||||
L2:next()
|
||||
t:eq(L2:line(), 2, "line")
|
||||
|
||||
local rand = T.rng(5)
|
||||
local alphabet = '{}()[];=,"\\/* \n\t0123456789.-+exabc_'
|
||||
t:fuzz("tokens", function(b: buffer)
|
||||
local L3 = Lexer.new(buffer.tostring(b))
|
||||
for _ = 1, 10000 do
|
||||
if not L3:next() then
|
||||
break
|
||||
end
|
||||
end
|
||||
return true
|
||||
end, (function()
|
||||
local out = {}
|
||||
for _ = 1, 50 do
|
||||
local s = {}
|
||||
for _ = 1, 1 + rand(80) do
|
||||
local i = 1 + rand(#alphabet)
|
||||
table.insert(s, string.sub(alphabet, i, i))
|
||||
end
|
||||
table.insert(out, buffer.fromstring(table.concat(s)))
|
||||
end
|
||||
return out
|
||||
end)())
|
||||
t:done()
|
||||
@@ -0,0 +1,161 @@
|
||||
-- model/d3map tests: an editor-layout Doom 3 / Quake 4 map written by the fixture: brushDef3 side areas against qhull
|
||||
-- (scipy HalfspaceIntersection), texture coordinates against Doom 3's ComputeAxisBase + matrix, the patchDef3 grid
|
||||
-- against a direct Bezier evaluation, entities. Fixtures: tools/fixtures/d3map.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@rosetta")
|
||||
local D3map = require("@rosetta/model/d3map")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Types = require("@rosetta/Types")
|
||||
local Fx = require("@tests/gen/d3map")
|
||||
|
||||
local t = T.suite("d3map")
|
||||
t:eq(D3map.name, "d3map", "name")
|
||||
t:eq(F.detect(Fx.doom3, { name = "test.map" }), "d3map", "F.detect: Version 2 is not a Quake map")
|
||||
t:eq(F.detect(Fx.quake4, { name = "test.map" }), "d3map", "F.detect: Version 3")
|
||||
|
||||
local s, err = D3map.decode(Bytes.reader(buffer.fromstring(Fx.doom3)))
|
||||
t:check(s, "doom3: " .. tostring(err))
|
||||
local sc = s :: any
|
||||
t:eq(sc.meta.source.variant, "doom3", "variant")
|
||||
t:eq((F.load(Fx.quake4, { format = "d3map" }) :: any).meta.source.variant, "quake4", "Quake 4")
|
||||
t:eq(sc.meta.counts.brushes, 3, "brushes")
|
||||
t:eq(sc.meta.counts.patches, 2, "patches")
|
||||
t:eq(sc.meta.counts.skippedPrimitives, 1, "brushDef skipped")
|
||||
|
||||
local byMaterial: { [string]: any } = {}
|
||||
for _, mesh in sc.meshes do
|
||||
for _, p in mesh.primitives do
|
||||
byMaterial[sc.materials[p.material].name] = p
|
||||
end
|
||||
end
|
||||
|
||||
local function tris(p: any, fn: (ax: number, ay: number, az: number, bx: number, by: number, bz: number, cx: number, cy: number, cz: number, a: number, b: number, c: number) -> ())
|
||||
local pos = Types.Scene.reader(p.attributes.POSITION) :: any
|
||||
local idx = Types.Scene.reader(p.indices) :: any
|
||||
for k = 0, p.indices.count - 1, 3 do
|
||||
local a, b, c = idx(k, 0), idx(k + 1, 0), idx(k + 2, 0)
|
||||
fn(pos(a, 0), pos(a, 1), pos(a, 2), pos(b, 0), pos(b, 1), pos(b, 2), pos(c, 0), pos(c, 1), pos(c, 2), a, b, c)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local bad, uvBad, windBad, faces = {}, 0, 0, 0
|
||||
for _, w in Fx.sides do
|
||||
local p = byMaterial[w.material]
|
||||
if w.area < 1e-6 then
|
||||
t:check(p == nil, w.material .. ": a redundant side has no polygon")
|
||||
elseif not p then
|
||||
table.insert(bad, w.material .. " missing")
|
||||
else
|
||||
faces += 1
|
||||
local area = 0
|
||||
local nrm = Types.Scene.reader(p.attributes.NORMAL) :: any
|
||||
tris(p, function(ax, ay, az, bx, by, bz, cx, cy, cz, a)
|
||||
local ux, uy, uz, vx, vy, vz = bx - ax, by - ay, bz - az, cx - ax, cy - ay, cz - az
|
||||
local nx, ny, nz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx
|
||||
area += math.sqrt(nx * nx + ny * ny + nz * nz) / 2
|
||||
if nx * nrm(a, 0) + ny * nrm(a, 1) + nz * nrm(a, 2) <= 0 then
|
||||
windBad += 1
|
||||
end
|
||||
end)
|
||||
if math.abs(area - w.area) > 1e-3 * math.max(1, w.area) then
|
||||
table.insert(bad, string.format("%s: %.4f vs %.4f", w.material, area, w.area))
|
||||
end
|
||||
local pos = Types.Scene.reader(p.attributes.POSITION) :: any
|
||||
local uv = Types.Scene.reader(p.attributes.TEXCOORD_0) :: any
|
||||
local v = w.vecs
|
||||
for i = 0, p.attributes.POSITION.count - 1 do
|
||||
local x, y, z = pos(i, 0), pos(i, 1), pos(i, 2)
|
||||
local su = x * v[1] + y * v[2] + z * v[3] + v[4]
|
||||
local tv = x * v[5] + y * v[6] + z * v[7] + v[8]
|
||||
if math.abs(uv(i, 0) - su) > 1e-3 or math.abs(uv(i, 1) - tv) > 1e-3 then
|
||||
uvBad += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
t:eq(#bad, 0, "side areas against qhull: " .. table.concat(bad, "; ", 1, math.min(#bad, 4)))
|
||||
t:eq(uvBad, 0, "texture coordinates: ComputeAxisBase + the texture matrix")
|
||||
t:eq(windBad, 0, "brush triangles counter-clockwise about the side normal")
|
||||
t:note("%d brush sides with polygons match qhull; volumes %s", faces, table.concat(Fx.volumes :: any, ", "))
|
||||
end
|
||||
|
||||
do
|
||||
local p = byMaterial["textures/test/patchDef3"]
|
||||
t:check(p, "patchDef3 primitive")
|
||||
local w = Fx.patch3
|
||||
t:eq(p.attributes.POSITION.count, w.width * w.height, "patchDef3: explicit subdivisions")
|
||||
local pos = Types.Scene.reader(p.attributes.POSITION) :: any
|
||||
local worst = 0
|
||||
for i = 0, w.width * w.height - 1 do
|
||||
for c = 0, 2 do
|
||||
worst = math.max(worst, math.abs(pos(i, c) - w.points[i * 3 + c + 1]))
|
||||
end
|
||||
end
|
||||
t:check(worst < 1e-3, string.format("patchDef3 grid against the Bezier evaluation (worst %.2g)", worst))
|
||||
local p2 = byMaterial["textures/test/patchDef2"]
|
||||
t:check(p2, "patchDef2 primitive")
|
||||
local pos2 = Types.Scene.reader(p2.attributes.POSITION) :: any
|
||||
local c = Fx.patch2.corners
|
||||
t:check(pos2(0, 0) == c[1] and pos2(0, 1) == c[2] and math.abs(pos2(0, 2) - c[3]) < 1e-4, "patchDef2 first corner")
|
||||
local n2 = p2.attributes.POSITION.count - 1
|
||||
t:check(pos2(n2, 0) == c[4] and pos2(n2, 1) == c[5] and math.abs(pos2(n2, 2) - c[6]) < 1e-4, "patchDef2 last corner")
|
||||
local nrm = Types.Scene.reader(p2.attributes.NORMAL) :: any
|
||||
local agree = 0
|
||||
local total = 0
|
||||
tris(p2, function(ax, ay, az, bx, by, bz, cx, cy, cz, a)
|
||||
local ux, uy, uz, vx, vy, vz = bx - ax, by - ay, bz - az, cx - ax, cy - ay, cz - az
|
||||
local d = (uy * vz - uz * vy) * nrm(a, 0) + (uz * vx - ux * vz) * nrm(a, 1) + (ux * vy - uy * vx) * nrm(a, 2)
|
||||
total += 1
|
||||
if d > 0 then
|
||||
agree += 1
|
||||
end
|
||||
end)
|
||||
t:eq(agree, total, "patch normals face the triangle winding")
|
||||
end
|
||||
|
||||
do
|
||||
local named: { [string]: any } = {}
|
||||
for _, n in sc.nodes do
|
||||
named[n.name] = n
|
||||
end
|
||||
t:eq(#sc.nodes, 1 + 4, "root + 4 entities")
|
||||
t:check(named.worldspawn and named.worldspawn.mesh, "worldspawn mesh")
|
||||
t:check(named.crate and named.crate.mesh and named.crate.extras.keys.model == "crate", "func_static: mesh and keys")
|
||||
t:check(named.crate.translation == nil, "brush entities stay in world coordinates")
|
||||
local l = named.light_1
|
||||
t:check(l.translation[1] == 10 and l.translation[3] == 30, "light origin")
|
||||
local q = l.rotation
|
||||
t:check(math.abs(q[3] - math.sqrt(0.5)) < 1e-6 and math.abs(q[4] - math.sqrt(0.5)) < 1e-6, "rotation matrix rows: yaw 90")
|
||||
local ps = named.info_player_start_1
|
||||
t:check(math.abs(ps.rotation[3] - math.sqrt(0.5)) < 1e-6, "angle 90")
|
||||
t:eq(ps.extras.classname, "info_player_start", "classname")
|
||||
t:eq(sc.meta.entities[1].classname, "worldspawn", "meta.entities")
|
||||
local lean = D3map.decode(Bytes.reader(buffer.fromstring(Fx.doom3)), { skip = { "textures/test/box_0", "TEXTURES/TEST/PATCHDEF2" } }) :: any
|
||||
local seen = {}
|
||||
for _, mesh in lean.meshes do
|
||||
for _, p in mesh.primitives do
|
||||
seen[lean.materials[p.material].name] = true
|
||||
end
|
||||
end
|
||||
t:check(not seen["textures/test/box_0"] and not seen["textures/test/patchDef2"] and seen["textures/test/box_1"], "skip")
|
||||
end
|
||||
|
||||
do
|
||||
local function code(src: string, opts: any?): any
|
||||
local _, e = D3map.decode(Bytes.reader(buffer.fromstring(src)), opts)
|
||||
return e and e.code
|
||||
end
|
||||
t:eq(code("{ }"), Err.CORRUPT, "no Version")
|
||||
t:eq(code("Version 2\n{ \"classname\" \"worldspawn\"\n{ brushDef3 { ( 0 0 1 0 ) ( ( 1 0 0 ) ( 0 1 0 ) ) \"x\" 0 0 0 }"), Err.CORRUPT, "truncated")
|
||||
t:eq(code("Version 2\n{ \"classname\" \"worldspawn\" { patchDef2 { \"x\" ( 4 3 0 0 0 ) ( ) } } }"), Err.CORRUPT, "short patch")
|
||||
t:eq(code(Fx.doom3, { maxPrimitives = 2 }), Err.LIMIT, "maxPrimitives")
|
||||
t:eq(code("Version 2\n"), Err.CORRUPT, "no entities")
|
||||
t:check(F.detect("Version 2\n{\n\"classname\" \"worldspawn\"\n}\n") == "d3map", "an empty map sniffs")
|
||||
end
|
||||
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return D3map.decode(Bytes.reader(b))
|
||||
end, { buffer.fromstring(Fx.doom3) }, { mutations = 200 })
|
||||
t:done()
|
||||
@@ -0,0 +1,87 @@
|
||||
-- model/proc tests: dmap-layout Doom 3 and Quake 4 files written by the fixture (models, surfaces, portals, nodes,
|
||||
-- shadow models) against the writer's geometry. Fixtures: tools/fixtures/proc.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@rosetta")
|
||||
local Proc = require("@rosetta/model/proc")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Crc32 = require("@rosetta/core/Crc32")
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Types = require("@rosetta/Types")
|
||||
local Fx = require("@tests/gen/proc")
|
||||
|
||||
local t = T.suite("proc")
|
||||
t:eq(Proc.name, "proc", "name")
|
||||
|
||||
for key, c in Fx do
|
||||
t:eq(F.detect(c.text), "proc", key .. ": F.detect")
|
||||
local s, e = Proc.decode(Bytes.reader(buffer.fromstring(c.text)))
|
||||
t:check(s, key .. ": " .. tostring(e))
|
||||
local sc = s :: any
|
||||
t:eq(#sc.meshes, #c.models, key .. ": models")
|
||||
for mi, m in c.models do
|
||||
local mesh = sc.meshes[mi]
|
||||
t:eq(mesh.name, m.name, key .. ": model name")
|
||||
t:eq(#mesh.primitives, #m.surfaces, key .. ": surfaces of " .. m.name)
|
||||
for si, w in m.surfaces do
|
||||
local p = mesh.primitives[si]
|
||||
local label = key .. " " .. m.name .. " surface " .. si
|
||||
t:eq(p.attributes.POSITION.count, w.verts, label .. ": vertices")
|
||||
t:eq(Crc32.of(p.attributes.POSITION.data), w.pos, label .. ": positions")
|
||||
t:eq(Crc32.of(p.attributes.TEXCOORD_0.data), w.uv, label .. ": texcoords")
|
||||
t:eq(Crc32.of(p.indices.data), w.idx, label .. ": indices, counter-clockwise")
|
||||
t:eq(sc.materials[p.material].name, w.material, label .. ": material")
|
||||
-- every triangle faces its vertex normal after the turn
|
||||
local pos = Types.Scene.reader(p.attributes.POSITION) :: any
|
||||
local nrm = Types.Scene.reader(p.attributes.NORMAL) :: any
|
||||
local idx = Types.Scene.reader(p.indices) :: any
|
||||
local ok = true
|
||||
for k = 0, p.indices.count - 1, 3 do
|
||||
local a, b, cc = idx(k, 0), idx(k + 1, 0), idx(k + 2, 0)
|
||||
local ux, uy, uz = pos(b, 0) - pos(a, 0), pos(b, 1) - pos(a, 1), pos(b, 2) - pos(a, 2)
|
||||
local vx, vy, vz = pos(cc, 0) - pos(a, 0), pos(cc, 1) - pos(a, 1), pos(cc, 2) - pos(a, 2)
|
||||
local d = (uy * vz - uz * vy) * nrm(a, 0) + (uz * vx - ux * vz) * nrm(a, 1) + (ux * vy - uy * vx) * nrm(a, 2)
|
||||
ok = ok and d > 0
|
||||
end
|
||||
t:check(ok, label .. ": winding faces the normals")
|
||||
if key == "quake4" then
|
||||
t:check(p.attributes.COLOR_0 ~= nil, label .. ": vertex colours")
|
||||
end
|
||||
end
|
||||
end
|
||||
local info = sc.meta.proc
|
||||
t:eq(info.areas, c.areas, key .. ": areas")
|
||||
t:eq(#info.portals, #c.portals, key .. ": portals")
|
||||
t:eq(info.portals[1].positive, c.portals[1].positive, key .. ": portal areas")
|
||||
t:eq(#info.portals[1].points, #c.portals[1].points, key .. ": portal points")
|
||||
t:eq(info.portals[1].points[12], c.portals[1].points[12], key .. ": portal point")
|
||||
t:eq(#info.nodes, #c.nodes, key .. ": nodes")
|
||||
t:eq(info.nodes[1].positive, 2, key .. ": node children 1-based")
|
||||
t:eq(info.nodes[1].negative, -1, key .. ": area children kept")
|
||||
t:eq(info.nodes[1].plane[4], c.nodes[1].plane[4], key .. ": node plane")
|
||||
t:eq(info.shadowModels[1].name, c.shadow.name, key .. ": shadow model")
|
||||
t:eq(#info.shadowModels[1].vertices, c.shadow.verts * 3, key .. ": shadow vertices")
|
||||
t:eq(#info.shadowModels[1].indices, c.shadow.indices, key .. ": shadow indices")
|
||||
t:eq(info.models[1].area, 0, key .. ": area number")
|
||||
t:eq(#sc.nodes, 1 + #c.models, key .. ": a node per model")
|
||||
t:eq(sc.meta.up, "z", key .. ": z up")
|
||||
end
|
||||
t:eq((F.load(Fx.quake4.text) :: any).meta.source.version, "PROC 4", "Quake 4 version")
|
||||
|
||||
do
|
||||
local function code(s: string, opts: any?): any
|
||||
local _, e = Proc.decode(Bytes.reader(buffer.fromstring(s)), opts)
|
||||
return e and e.code
|
||||
end
|
||||
t:eq(code("hello"), Err.CORRUPT, "not a proc")
|
||||
t:eq(code('mapProcFile003 model { "m" 1 { "x" 1 3 ( 0 0 0 0 0 0 0 1 ) 0 0 5 } }'), Err.CORRUPT, "index out of range")
|
||||
t:eq(code('mapProcFile003 model { "m" 1 { "x" 1 3 ( 0 0 0 ) 0 0 0 } }'), Err.CORRUPT, "short vertex")
|
||||
t:eq(code('mapProcFile003 model { "m" 1 { "x" 1 3 ( 0 0 0 0 0 0 0 1 ) 0 0'), Err.CORRUPT, "truncated")
|
||||
t:eq(code(Fx.doom3.text, { maxVertices = 10 }), Err.LIMIT, "maxVertices")
|
||||
local s = Proc.decode(Bytes.reader(buffer.fromstring("mapProcFile003 unknownSection { a { b } c } model { \"m\" 0 }"))) :: any
|
||||
t:check(s and #s.meshes == 1, "unknown sections skipped")
|
||||
end
|
||||
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Proc.decode(Bytes.reader(b))
|
||||
end, { buffer.fromstring(Fx.doom3.text), buffer.fromstring(Fx.quake4.text) }, { mutations = 300 })
|
||||
t:done()
|
||||
@@ -0,0 +1,173 @@
|
||||
-- model/udmf + archive/wad UDMF tests: Freedoom MAP01 converted to TEXTMAP against its binary lumps (same tables, same
|
||||
-- Scene geometry), and a hand-written ZDoom room with exact areas. Fixtures: tools/fixtures/udmf.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@rosetta")
|
||||
local Udmf = require("@rosetta/model/udmf")
|
||||
local Wad = require("@rosetta/archive/wad")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Types = require("@rosetta/Types")
|
||||
local Fx = require("@tests/gen/udmf")
|
||||
|
||||
local t = T.suite("udmf")
|
||||
t:eq(Udmf.name, "udmf", "name")
|
||||
t:eq(F.detect(Fx.room), "udmf", "F.detect")
|
||||
|
||||
do
|
||||
local bin = Wad.decode(Bytes.reader(buffer.fromstring(Fx.binary))) :: any
|
||||
local udmf = Wad.decode(Bytes.reader(buffer.fromstring(Fx.textmap))) :: any
|
||||
t:eq(Wad.maps(udmf)[1], "MAP01", "UDMF map listed")
|
||||
local a = Wad.mapData(bin, "MAP01") :: any
|
||||
local b, e = Wad.mapData(udmf, "MAP01")
|
||||
t:check(b, "TEXTMAP: " .. tostring(e))
|
||||
local m = b :: any
|
||||
t:eq(m.format, "udmf", "format")
|
||||
t:eq(m.namespace, "Doom", "namespace")
|
||||
t:eq(#m.vertices, #a.vertices, "vertices")
|
||||
local same = true
|
||||
for i, v in a.vertices do
|
||||
same = same and m.vertices[i] == v
|
||||
end
|
||||
t:check(same, "vertex coordinates")
|
||||
for _, k in { "linedefs", "sidedefs", "sectors", "things" } do
|
||||
t:eq(#m[k], #a[k], k)
|
||||
end
|
||||
local bad = {}
|
||||
for i, l in a.linedefs do
|
||||
local u = m.linedefs[i]
|
||||
if u.v1 ~= l.v1 or u.v2 ~= l.v2 or u.flags ~= l.flags or u.special ~= l.special or (l.special ~= 0 and u.tag ~= l.tag) or u.front ~= l.front or u.back ~= l.back then
|
||||
table.insert(bad, "linedef " .. i)
|
||||
end
|
||||
end
|
||||
for i, s in a.sidedefs do
|
||||
local u = m.sidedefs[i]
|
||||
if u.xoff ~= s.xoff or u.yoff ~= s.yoff or u.upper ~= s.upper or u.lower ~= s.lower or u.middle ~= s.middle or u.sector ~= s.sector then
|
||||
table.insert(bad, "sidedef " .. i)
|
||||
end
|
||||
end
|
||||
for i, s in a.sectors do
|
||||
local u = m.sectors[i]
|
||||
if u.floor ~= s.floor or u.ceiling ~= s.ceiling or u.floorFlat ~= s.floorFlat or u.ceilingFlat ~= s.ceilingFlat or u.light ~= s.light or u.special ~= s.special or u.tag ~= s.tag then
|
||||
table.insert(bad, "sector " .. i)
|
||||
end
|
||||
end
|
||||
for i, th in a.things do
|
||||
local u = m.things[i]
|
||||
if u.x ~= th.x or u.y ~= th.y or u.type ~= th.type or u.angle ~= th.angle or u.flags ~= th.flags then
|
||||
table.insert(bad, "thing " .. i)
|
||||
end
|
||||
end
|
||||
t:eq(#bad, 0, "TEXTMAP tables equal the binary ones: " .. table.concat(bad, ", ", 1, math.min(#bad, 5)))
|
||||
local t0 = T.clock()
|
||||
local s1 = Wad.map(bin, "MAP01") :: any
|
||||
local s2, se = Wad.map(udmf, "MAP01")
|
||||
t:check(s2, "TEXTMAP scene: " .. tostring(se))
|
||||
local dt = T.clock() - t0
|
||||
local p1, p2 = s1.meshes[1].primitives, (s2 :: any).meshes[1].primitives
|
||||
t:eq(#p2, #p1, "primitives")
|
||||
local geo = true
|
||||
for i, p in p1 do
|
||||
local q = p2[i]
|
||||
geo = geo and q ~= nil and p.extras.wad.texture == q.extras.wad.texture
|
||||
and buffer.tostring(p.attributes.POSITION.data) == buffer.tostring(q.attributes.POSITION.data)
|
||||
and buffer.tostring(p.attributes.TEXCOORD_0.data) == buffer.tostring(q.attributes.TEXCOORD_0.data)
|
||||
end
|
||||
t:check(geo, "the TEXTMAP Scene is the binary map's geometry, byte for byte")
|
||||
local withImage = 0
|
||||
for _, tex in (s2 :: any).textures do
|
||||
if tex.image then
|
||||
withImage += 1
|
||||
end
|
||||
end
|
||||
t:check(withImage > 0, "textures from the WAD")
|
||||
t:eq((s2 :: any).meta.source.namespace, "Doom", "meta namespace")
|
||||
t:eq(#(s2 :: any).nodes, 1 + #a.things, "a node per thing")
|
||||
t:note("MAP01 as UDMF: %d bytes of TEXTMAP, %d primitives, both scenes in %.2f s", #Fx.text, #p2, dt)
|
||||
t:check(F.detect(Fx.text) == "udmf", "TEXTMAP text detected")
|
||||
local alone = F.load(Fx.text) :: any
|
||||
t:check(alone and #alone.meshes[1].primitives == #p1, "standalone TEXTMAP: same batches")
|
||||
end
|
||||
|
||||
do
|
||||
local s, e = Udmf.decode(Bytes.reader(buffer.fromstring(Fx.room)), { textureSize = function(kind: string, name: string)
|
||||
if kind == "texture" then
|
||||
return 64, 128
|
||||
end
|
||||
return 64, 64
|
||||
end })
|
||||
t:check(s, "room: " .. tostring(e))
|
||||
local area = { floor = 0, ceil = 0, wall = 0 }
|
||||
for _, p in (s :: any).meshes[1].primitives do
|
||||
local pos = Types.Scene.reader(p.attributes.POSITION) :: any
|
||||
local nrm = Types.Scene.reader(p.attributes.NORMAL) :: any
|
||||
for k = 0, p.attributes.POSITION.count - 1, 3 do
|
||||
local ux, uy, uz = pos(k + 1, 0) - pos(k, 0), pos(k + 1, 1) - pos(k, 1), pos(k + 1, 2) - pos(k, 2)
|
||||
local vx, vy, vz = pos(k + 2, 0) - pos(k, 0), pos(k + 2, 1) - pos(k, 1), pos(k + 2, 2) - pos(k, 2)
|
||||
local cx, cy, cz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx
|
||||
local ar = math.sqrt(cx * cx + cy * cy + cz * cz) / 2
|
||||
if nrm(k, 2) > 0.5 then
|
||||
area.floor += ar
|
||||
elseif nrm(k, 2) < -0.5 then
|
||||
area.ceil += ar
|
||||
else
|
||||
area.wall += ar
|
||||
end
|
||||
end
|
||||
end
|
||||
t:eq(area.floor, 256 * 256, "room floors")
|
||||
t:eq(area.ceil, 256 * 256, "room ceilings")
|
||||
t:eq(area.wall, 4 * 256 * 128 + 4 * 64 * 32, "room walls")
|
||||
local sc = s :: any
|
||||
t:eq(sc.nodes[3].translation[3], 40, "thing height above the pillar floor")
|
||||
t:eq(sc.nodes[3].translation[1], 128.5, "float coordinates")
|
||||
t:eq(sc.meta.source.namespace, "ZDoom", "namespace (case-insensitive key)")
|
||||
local m = Udmf.data(Bytes.reader(buffer.fromstring(Fx.room))) :: any
|
||||
t:eq(m.globals.user_note, 'a "quoted" \\ note', "string escapes")
|
||||
t:eq(m.vertices[3], 256, "hex")
|
||||
t:eq(m.vertices[8], 256, "octal")
|
||||
t:eq(m.sectors[1].fields.user_gravity, 0.5, "user_ field kept")
|
||||
t:eq(m.sidedefs[5].fields.offsetx_bottom, 4, "namespace field kept")
|
||||
t:eq(m.sidedefs[1].middle, "WALL", "texture names upper-cased")
|
||||
t:eq(m.sidedefs[1].fields.texturemiddle, "Wall", "as written in fields")
|
||||
t:eq(m.linedefs[2].flags, 1, "keys and keywords are case-insensitive")
|
||||
t:eq(m.linedefs[4].flags, 1 + 512 + 1024, "Hexen bits: blocking, repeat, use activation")
|
||||
t:eq(m.linedefs[4].tag, 7, "id is the tag outside Doom namespaces")
|
||||
t:eq(m.linedefs[4].args[1], 3, "args")
|
||||
t:eq(m.sectors[2].light, 200, "light")
|
||||
t:eq(m.sectors[2].tag, 3, "sector id")
|
||||
t:eq(m.things[2].flags, 16, "Hexen thing bits: dormant")
|
||||
t:eq(m.things[2].tid, 5, "thing id")
|
||||
t:eq(m.blocks[1].type, "vavoombox", "unknown block kept")
|
||||
t:eq(m.blocks[1].fields.foo, 1, "unknown block fields")
|
||||
end
|
||||
|
||||
do
|
||||
local function bad(s: string): any
|
||||
local _, e = Udmf.decode(Bytes.reader(buffer.fromstring(s)))
|
||||
return e and e.code
|
||||
end
|
||||
t:eq(bad('namespace = "x"; vertex { x = 1 y = 2; }'), Err.CORRUPT, "missing ;")
|
||||
t:eq(bad('namespace = "x"; /* open'), Err.CORRUPT, "unterminated comment")
|
||||
t:eq(bad('namespace = "x'), Err.CORRUPT, "unterminated string")
|
||||
t:eq(bad('namespace = "x"; linedef { v2 = 1; sidefront = 0; }'), Err.CORRUPT, "linedef without v1")
|
||||
t:eq(bad('namespace = "x"; vertex { x = 1; y = 2; } vertex { x = 1; y = 2; } } '), Err.CORRUPT, "stray }")
|
||||
local _, le = Udmf.decode(Bytes.reader(buffer.fromstring('namespace = "x"; a {} b {} c {}')), { maxBlocks = 2 })
|
||||
t:check(le and le.code == Err.LIMIT, "maxBlocks")
|
||||
t:check(F.detect("namespace = 1;") ~= "udmf", "a quoted namespace is required to sniff")
|
||||
end
|
||||
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Udmf.decode(Bytes.reader(b))
|
||||
end, { buffer.fromstring(Fx.room) }, { mutations = 400 })
|
||||
local small = Wad.new()
|
||||
small:add("E1M1", "")
|
||||
small:add("TEXTMAP", Fx.room)
|
||||
small:add("ENDMAP", "")
|
||||
t:fuzz("wad", function(b: buffer)
|
||||
local w = Wad.decode(Bytes.reader(b))
|
||||
if w then
|
||||
Wad.map(w, "MAP01")
|
||||
end
|
||||
return w
|
||||
end, { small:write() :: buffer }, { mutations = 300 })
|
||||
t:done()
|
||||
@@ -0,0 +1,53 @@
|
||||
-- vector/gamemaps tests: Wolfenstein 3D GAMEMAPS + MAPHEAD written by the fixture's own writer (Carmack near / far
|
||||
-- copies and escapes, RLEW runs and a literal tag) against the source tiles. Fixtures: tools/fixtures/wolf3d.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@rosetta")
|
||||
local Gamemaps = require("@rosetta/vector/gamemaps")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Crc32 = require("@rosetta/core/Crc32")
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Fx = require("@tests/gen/wolf3d")
|
||||
|
||||
local t = T.suite("gamemaps")
|
||||
t:eq(Gamemaps.name, "gamemaps", "name")
|
||||
|
||||
do
|
||||
t:eq(F.detect(Fx.gamemaps, { name = "GAMEMAPS.WL6" }), "gamemaps", "F.detect GAMEMAPS")
|
||||
t:eq(F.detect(Fx.maphead, { name = "MAPHEAD.WL6" }), "gamemaps", "F.detect MAPHEAD")
|
||||
local files = { ["MAPHEAD.WL6"] = Fx.maphead, ["GAMEMAPS.WL6"] = Fx.gamemaps }
|
||||
local list = Gamemaps.maps(Bytes.reader(buffer.fromstring(Fx.gamemaps)), { name = "GAMEMAPS.WL6", files = files }) :: any
|
||||
t:eq(#list, #Fx.maps, "maps listed (slot 2 is -1)")
|
||||
for _, m in Fx.maps do
|
||||
for _, from in { "gamemaps", "maphead" } do
|
||||
local src = if from == "gamemaps" then Fx.gamemaps else Fx.maphead
|
||||
local tm, e = Gamemaps.decode(Bytes.reader(buffer.fromstring(src)), { name = string.upper(from) .. ".WL6", files = files, map = m.slot })
|
||||
t:check(tm, m.name .. " from " .. from .. ": " .. tostring(e))
|
||||
local x = tm :: any
|
||||
t:eq(x.width, m.width, m.name .. ": width")
|
||||
t:eq(x.height, m.height, m.name .. ": height")
|
||||
t:eq(x.properties.name, m.name, m.name .. ": name")
|
||||
t:eq(#x.layers, 3, m.name .. ": planes")
|
||||
for k, crc in m.planes do
|
||||
local b = buffer.create(m.width * m.height * 2)
|
||||
for i, v in x.layers[k].data do
|
||||
buffer.writeu16(b, (i - 1) * 2, v)
|
||||
end
|
||||
t:eq(Crc32.of(b), crc, m.name .. ": plane " .. k .. " after Carmack + RLEW")
|
||||
end
|
||||
end
|
||||
end
|
||||
local tm = F.load(Fx.gamemaps, { name = "GAMEMAPS.WL6", files = files }) :: any
|
||||
t:check(tm and tm.kind == "tilemap" and tm.layers[1].name == "walls", "F.load: a TileMap")
|
||||
local _, e = Gamemaps.decode(Bytes.reader(buffer.fromstring(Fx.gamemaps)))
|
||||
t:check(e and e.code == Err.UNSUPPORTED, "no MAPHEAD")
|
||||
local _, e2 = Gamemaps.decode(Bytes.reader(buffer.fromstring(Fx.gamemaps)), { mapHead = Fx.maphead, map = 2 })
|
||||
t:check(e2 and e2.code == Err.ARG, "empty slot")
|
||||
end
|
||||
|
||||
t:fuzz("gamemaps", function(b: buffer)
|
||||
return Gamemaps.decode(Bytes.reader(b), { mapHead = Fx.maphead, map = 3 })
|
||||
end, { buffer.fromstring(Fx.gamemaps) }, { mutations = 300 })
|
||||
t:fuzz("maphead", function(b: buffer)
|
||||
return Gamemaps.decode(Bytes.reader(b), { gameMaps = Fx.gamemaps })
|
||||
end, { buffer.fromstring(Fx.maphead) }, { mutations = 300 })
|
||||
t:done()
|
||||
@@ -1278,6 +1278,27 @@ do
|
||||
Wad.map(w, "MAP01", { textures = false })
|
||||
end)
|
||||
end
|
||||
do
|
||||
-- id Tech text (ws-idtech): Freedoom MAP01 as a UDMF TEXTMAP (tools/fixtures/udmf.py) parsed to tables and built
|
||||
-- into a Scene, a Doom 3 .proc (tools/fixtures/proc.py) to a Scene; MB/s of text
|
||||
local DoomMap = require("@rosetta/codecs/model/DoomMap")
|
||||
local Udmf = require("@rosetta/model/udmf")
|
||||
local Proc = require("@rosetta/model/proc")
|
||||
local UD = require("@tests/gen/udmf")
|
||||
local PR = require("@tests/gen/proc")
|
||||
bench("udmf MAP01 TEXTMAP -> tables", 3, #UD.text, function()
|
||||
DoomMap.udmf(UD.text)
|
||||
end)
|
||||
local ub = buffer.fromstring(UD.text)
|
||||
bench("udmf MAP01 TEXTMAP -> Scene", 3, #UD.text, function()
|
||||
Udmf.decode(Bytes.reader(ub))
|
||||
end)
|
||||
local big = PR.doom3.text
|
||||
local pb = buffer.fromstring(big)
|
||||
bench("proc (" .. #big .. " B) -> Scene", 20, #big, function()
|
||||
Proc.decode(Bytes.reader(pb))
|
||||
end)
|
||||
end
|
||||
do
|
||||
-- Draco (codecs/model/Draco): the Stanford bunny (35k points, 69k faces, Edgebreaker valence, normals) and a UV
|
||||
-- sphere with seams; MB/s of decoded output (u32 indices + f32 attributes per point), plus triangles per second.
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
# Doom 3 / Quake 4 .map fixtures (tools/fixtures.py). Doom 3's maps are not redistributable, so the map is written here
|
||||
# in the editor's layout (the Doom 3 GPL source docs' idMapFile text, read for the layout; no code taken): a box and a
|
||||
# random convex brush in worldspawn (every side its own material), a func_static with a box, a patchDef3 and a
|
||||
# patchDef2, a light with a rotation matrix, a player start with an angle, and a Quake III brushDef (skipped). The
|
||||
# reference: scipy's HalfspaceIntersection (qhull) per brush -> the area of every side; the side's texture vectors by
|
||||
# Doom 3's ComputeAxisBase + texture matrix; the patchDef3 grid by evaluating the biquadratic Bezier sub-patches.
|
||||
# tests/gen/d3map.luau { doom3 = <text>, quake4 = <text>, sides = { { material, area, vecs = { 8 } } },
|
||||
# patch3 = { width, height, points = { x, y, z, ... } }, ... }
|
||||
import json, math
|
||||
|
||||
REF = r"""
|
||||
import json, sys
|
||||
import numpy as np
|
||||
from scipy.spatial import HalfspaceIntersection, ConvexHull
|
||||
brushes = json.loads(sys.stdin.read())
|
||||
out = []
|
||||
for b in brushes:
|
||||
hs = np.array([s["plane"] for s in b["sides"]], dtype=float)
|
||||
hi = HalfspaceIntersection(hs, np.array(b["inside"], dtype=float))
|
||||
pts = hi.intersections
|
||||
vol = ConvexHull(pts).volume
|
||||
for s in b["sides"]:
|
||||
n, d = np.array(s["plane"][:3], dtype=float), s["plane"][3]
|
||||
on = pts[np.abs(pts @ n + d) < 1e-6]
|
||||
area = 0.0
|
||||
if len(on) >= 3:
|
||||
u = np.cross(n, [1, 0, 0] if abs(n[0]) < 0.9 else [0, 1, 0]); u /= np.linalg.norm(u)
|
||||
v = np.cross(n, u)
|
||||
q = np.stack([on @ u, on @ v], axis=1)
|
||||
q = np.unique(np.round(q, 9), axis=0)
|
||||
if len(q) >= 3:
|
||||
area = ConvexHull(q).volume
|
||||
out.append({"material": s["material"], "area": area})
|
||||
out.append({"volume": vol})
|
||||
print(json.dumps(out))
|
||||
"""
|
||||
|
||||
|
||||
def axis_base(n):
|
||||
rot_y = -math.atan2(n[2], math.sqrt(n[1] * n[1] + n[0] * n[0]))
|
||||
rot_z = math.atan2(n[1], n[0])
|
||||
s = (-math.sin(rot_z), math.cos(rot_z), 0.0)
|
||||
t = (-math.sin(rot_y) * math.cos(rot_z), -math.sin(rot_y) * math.sin(rot_z), -math.cos(rot_y))
|
||||
return s, t
|
||||
|
||||
|
||||
def vecs(n, m):
|
||||
s, t = axis_base(n)
|
||||
out = []
|
||||
for i in range(2):
|
||||
out += [s[k] * m[i][0] + t[k] * m[i][1] for k in range(3)] + [m[i][2]]
|
||||
return out
|
||||
|
||||
|
||||
def box(x0, y0, z0, x1, y1, z1):
|
||||
return [((-1, 0, 0), x0), ((1, 0, 0), -x1), ((0, -1, 0), y0), ((0, 1, 0), -y1), ((0, 0, -1), z0), ((0, 0, 1), -z1)]
|
||||
|
||||
|
||||
def g(v):
|
||||
return repr(round(v, 9)).rstrip("0").rstrip(".") if isinstance(v, float) else str(v)
|
||||
|
||||
|
||||
def bezier(ctrl, w, h, su, sv):
|
||||
# ctrl[row][col] = (x, y, z, s, t); sub-patches of 3 x 3; su / sv segments per sub-patch
|
||||
def b(t):
|
||||
return ((1 - t) ** 2, 2 * t * (1 - t), t * t)
|
||||
gw, gh = (w - 1) // 2 * su + 1, (h - 1) // 2 * sv + 1
|
||||
pts = []
|
||||
for gy in range(gh):
|
||||
py, ty = min(gy // sv, (h - 1) // 2 - 1), None
|
||||
ty = gy / sv - py
|
||||
for gx in range(gw):
|
||||
px = min(gx // su, (w - 1) // 2 - 1)
|
||||
tx = gx / su - px
|
||||
bu, bv = b(tx), b(ty)
|
||||
p = [0.0] * 3
|
||||
for j in range(3):
|
||||
for i in range(3):
|
||||
c = ctrl[py * 2 + j][px * 2 + i]
|
||||
for k in range(3):
|
||||
p[k] += bv[j] * bu[i] * c[k]
|
||||
pts += p
|
||||
return gw, gh, pts
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
rng = ctx.rng(3)
|
||||
brushes = []
|
||||
sides = []
|
||||
|
||||
def brush(planes, inside, tag):
|
||||
b = {"inside": inside, "sides": []}
|
||||
for k, (n, d) in enumerate(planes):
|
||||
m = [[rng.choice([1 / 64, 1 / 128, -1 / 128]), rng.uniform(-0.01, 0.01), rng.uniform(-1, 1)],
|
||||
[rng.uniform(-0.01, 0.01), rng.choice([1 / 64, 1 / 128]), rng.uniform(-1, 1)]]
|
||||
mat = "textures/test/%s_%d" % (tag, k)
|
||||
b["sides"].append({"plane": [n[0], n[1], n[2], d], "material": mat, "m": m, "vecs": vecs(n, m)})
|
||||
brushes.append(b)
|
||||
return b
|
||||
|
||||
world = [brush(box(-128, -128, -16, 128, 128, 0), [0, 0, -8], "box")]
|
||||
planes = []
|
||||
cx, cy, cz = 200.0, 0.0, 64.0
|
||||
for _ in range(12):
|
||||
z = rng.uniform(-1, 1)
|
||||
a = rng.uniform(0, 2 * math.pi)
|
||||
n = (math.sqrt(1 - z * z) * math.cos(a), math.sqrt(1 - z * z) * math.sin(a), z)
|
||||
r = rng.uniform(40, 64)
|
||||
planes.append((n, -(n[0] * cx + n[1] * cy + n[2] * cz) - r))
|
||||
for n, d in box(cx - 100, cy - 100, cz - 100, cx + 100, cy + 100, cz + 100):
|
||||
planes.append((n, d))
|
||||
world.append(brush(planes, [cx, cy, cz], "rnd"))
|
||||
crate = brush(box(-16, 284, 0, 16, 316, 32), [0, 300, 16], "crate")
|
||||
|
||||
def side_text(s):
|
||||
p = s["plane"]
|
||||
m = s["m"]
|
||||
return ' ( %s %s %s %s ) ( ( %s %s %s ) ( %s %s %s ) ) "%s" 0 0 0' % tuple(
|
||||
[g(float(x)) for x in p] + [g(float(x)) for x in m[0]] + [g(float(x)) for x in m[1]] + [s["material"]])
|
||||
|
||||
def brush_text(i, b):
|
||||
return "// primitive %d\n{\n brushDef3\n {\n%s\n }\n}" % (i, "\n".join(side_text(s) for s in b["sides"]))
|
||||
|
||||
# patchDef3: 3 x 3, a bump; patchDef2: 5 wide x 3 high, a half pipe
|
||||
p3 = [[(x * 32.0, 300 + y * 32.0, 40 + (16.0 if x == 0 and y == 0 else 0.0), (x + 1) / 2, (y + 1) / 2) for x in (-1, 0, 1)] for y in (-1, 0, 1)]
|
||||
p2 = [[(-64 + x * 32.0, 400 + y * 64.0, 64 * abs(math.cos(x * math.pi / 4)), x / 4, y / 2) for x in range(5)] for y in range(3)]
|
||||
|
||||
def patch_text(kind, ctrl, info):
|
||||
h, w = len(ctrl), len(ctrl[0])
|
||||
cols = []
|
||||
for i in range(w):
|
||||
cols.append(" ( " + " ".join("( %s )" % " ".join(g(float(v)) for v in ctrl[j][i]) for j in range(h)) + " )")
|
||||
return '{\n %s\n {\n "textures/test/%s"\n ( %s )\n (\n%s\n )\n }\n}' % (kind, kind, " ".join(str(x) for x in info), "\n".join(cols))
|
||||
|
||||
def text(version):
|
||||
out = ["Version %d" % version, "// entity 0", "{", '"classname" "worldspawn"']
|
||||
for i, b in enumerate(world):
|
||||
out.append(brush_text(i, b))
|
||||
out.append("// primitive 2\n{\nbrushDef\n{\n( ( 0.0078125 0 0 ) ( 0 0.0078125 0 ) ) common/caulk 0 0 0\n}\n}")
|
||||
out.append("}")
|
||||
out += ["// entity 1", "{", '"classname" "func_static"', '"name" "crate"', '"origin" "0 300 16"', '"model" "crate"',
|
||||
brush_text(0, crate), patch_text("patchDef3", p3, [3, 3, 4, 4, 0, 0, 0]),
|
||||
patch_text("patchDef2", p2, [5, 3, 0, 0, 0]), "}"]
|
||||
out += ["// entity 2", "{", '"classname" "light"', '"name" "light_1"', '"origin" "10 20 30"',
|
||||
'"rotation" "0 1 0 -1 0 0 0 0 1"', '"light_radius" "300 300 300"', "}"]
|
||||
out += ["// entity 3", "{", '"classname" "info_player_start"', '"name" "info_player_start_1"', '"origin" "-64 0 1"',
|
||||
'"angle" "90"', "}"]
|
||||
return "\n".join(out) + "\n"
|
||||
|
||||
ref = json.loads(ctx.python(["numpy", "scipy"], REF, input=json.dumps(
|
||||
[{"inside": b["inside"], "sides": [{"plane": s["plane"], "material": s["material"]} for s in b["sides"]]} for b in brushes]).encode()))
|
||||
vols = [r["volume"] for r in ref if "volume" in r]
|
||||
areas = [r for r in ref if "volume" not in r]
|
||||
k = 0
|
||||
for b in brushes:
|
||||
for s in b["sides"]:
|
||||
assert areas[k]["material"] == s["material"]
|
||||
sides.append({"material": s["material"], "area": areas[k]["area"], "vecs": s["vecs"]})
|
||||
k += 1
|
||||
gw, gh, pts = bezier([[c for c in row] for row in p3], 3, 3, 4, 4)
|
||||
ctx.emit("d3map", {"doom3": text(2), "quake4": text(3), "sides": sides, "volumes": vols,
|
||||
"patch3": {"width": gw, "height": gh, "points": pts},
|
||||
"patch2": {"corners": list(p2[0][0][:3]) + list(p2[2][4][:3])}})
|
||||
@@ -0,0 +1,70 @@
|
||||
# Docs inputs for the id Tech sections of the scene / tilemap / archive pages (tools/fixtures.py; tools/docs_check.py
|
||||
# explains the inputs), a hand-written Doom 3 .map, and inputs made by the format fixtures' writers: the hand-written UDMF room (udmf.py), a dmap-layout
|
||||
# .proc (proc.py), a VSWAP and a one-map GAMEMAPS + MAPHEAD with a random palette (wolf3d.py).
|
||||
# tests/gen/docs_idtech.luau { files = { [name] = bytes }, vars = { udmfText = "room.udmf", ... } }
|
||||
import importlib.util, os, struct
|
||||
|
||||
INPUTS = ["tools/docs_check.py", "tools/fixtures/udmf.py", "tools/fixtures/proc.py", "tools/fixtures/wolf3d.py"]
|
||||
|
||||
|
||||
D3MAP = """Version 2
|
||||
// entity 0
|
||||
{
|
||||
"classname" "worldspawn"
|
||||
// primitive 0
|
||||
{
|
||||
brushDef3
|
||||
{
|
||||
( 0 0 -1 -16 ) ( ( 0.0078125 0 0 ) ( 0 0.0078125 0 ) ) "textures/base_floor/a_sofloor1_d" 0 0 0
|
||||
( 0 0 1 0 ) ( ( 0.0078125 0 0 ) ( 0 0.0078125 0 ) ) "textures/base_floor/a_sofloor1_d" 0 0 0
|
||||
( 0 -1 0 -128 ) ( ( 0.0078125 0 0 ) ( 0 0.0078125 0 ) ) "textures/common/caulk" 0 0 0
|
||||
( 1 0 0 -128 ) ( ( 0.0078125 0 0 ) ( 0 0.0078125 0 ) ) "textures/common/caulk" 0 0 0
|
||||
( 0 1 0 -128 ) ( ( 0.0078125 0 0 ) ( 0 0.0078125 0 ) ) "textures/common/caulk" 0 0 0
|
||||
( -1 0 0 -128 ) ( ( 0.0078125 0 0 ) ( 0 0.0078125 0 ) ) "textures/common/caulk" 0 0 0
|
||||
}
|
||||
}
|
||||
}
|
||||
// entity 1
|
||||
{
|
||||
"classname" "info_player_start"
|
||||
"name" "info_player_start_1"
|
||||
"origin" "0 0 1"
|
||||
"angle" "90"
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def mod(ctx, name):
|
||||
spec = importlib.util.spec_from_file_location("fx_" + name, os.path.join(ctx.root, "tools", name + ".py") if name == "docs_check"
|
||||
else os.path.join(ctx.root, "tools", "fixtures", name + ".py"))
|
||||
m = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(m)
|
||||
return m
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
check = mod(ctx, "docs_check")
|
||||
P = mod(ctx, "proc")
|
||||
models, portals, nodes, areas, shadow = P.level(ctx.rng(2), False)
|
||||
files = {"room.udmf": mod(ctx, "udmf").ROOM.encode(),
|
||||
"level.proc": P.write(models, portals, nodes, areas, shadow, "mapProcFile003", False).encode()}
|
||||
W = mod(ctx, "wolf3d")
|
||||
rng = ctx.rng(5)
|
||||
pal = bytes(rng.randrange(64) for _ in range(768))
|
||||
files["VSWAP.WL6"], _ = W.vswap(rng, pal)
|
||||
files["wolf.pal"] = pal
|
||||
g = W.grid(rng, 16, 16, 0)
|
||||
planes = [W.plane(g), W.plane([0] * 256), W.plane([0] * 256)]
|
||||
body = bytearray(b"TED5v1.0")
|
||||
starts = []
|
||||
for pl in planes:
|
||||
starts.append(len(body))
|
||||
body += pl
|
||||
head = len(body)
|
||||
body += struct.pack("<iiiHHHHH16s", *starts, *(len(pl) for pl in planes), 16, 16, b"Tiny map") + b"!ID!"
|
||||
files["GAMEMAPS.WL6"] = bytes(body)
|
||||
files["MAPHEAD.WL6"] = struct.pack("<H100i", W.TAG, head, *([0] * 99))
|
||||
files["room.map"] = D3MAP.encode()
|
||||
vars = {"d3mapText": "room.map", "udmfText": "room.udmf", "procText": "level.proc", "vswapBytes": "VSWAP.WL6", "wolfPaletteBytes": "wolf.pal",
|
||||
"gamemapsBytes": "GAMEMAPS.WL6", "mapheadBytes": "MAPHEAD.WL6"}
|
||||
check.emit_inputs(ctx, files, vars)
|
||||
@@ -0,0 +1,124 @@
|
||||
# Doom 3 .proc fixtures (tools/fixtures.py). Doom 3's data is not redistributable, so the files are written here in
|
||||
# dmap's layout (the Doom 3 GPL source's WriteOutputFile, read for the text layout; no code taken): two area models
|
||||
# made of boxes, an inline entity model, portals, BSP nodes and a shadow model; and a Quake 4 "PROC" "4" file with
|
||||
# vertex colours. The reference is this script's own geometry: per model and surface the vertex count, CRC-32 of the
|
||||
# positions / texcoords as f32 LE, and of the indices as u32 LE with every triangle turned counter-clockwise.
|
||||
# tests/gen/proc.luau { doom3 = { text, models = { { name, surfaces = { { material, verts, pos, uv, idx } } } },
|
||||
# portals, nodes, areas, shadow = { name, verts, indices } }, quake4 = { ... } }
|
||||
import struct, zlib
|
||||
|
||||
|
||||
def box(rng, x0, y0, z0, x1, y1, z1):
|
||||
# 6 quads; triangles clockwise seen from outside (id Tech 4's front faces)
|
||||
c = [(x0, y0, z0), (x1, y0, z0), (x1, y1, z0), (x0, y1, z0), (x0, y0, z1), (x1, y0, z1), (x1, y1, z1), (x0, y1, z1)]
|
||||
faces = [((0, 1, 2, 3), (0, 0, -1)), ((4, 7, 6, 5), (0, 0, 1)), ((0, 4, 5, 1), (0, -1, 0)), ((1, 5, 6, 2), (1, 0, 0)),
|
||||
((2, 6, 7, 3), (0, 1, 0)), ((3, 7, 4, 0), (-1, 0, 0))]
|
||||
verts, idx = [], []
|
||||
for quad, n in faces:
|
||||
b = len(verts)
|
||||
for k, vi in enumerate(quad):
|
||||
x, y, z = c[vi]
|
||||
verts.append((x, y, z, (k & 1) * 2.5 + rng.randint(0, 3) * 0.25, (k >> 1) * -1.5 + 0.0, n[0], n[1], n[2]))
|
||||
# clockwise triangles about n, whichever way the corners run
|
||||
(ax, ay, az), (bx, by, bz), (cx, cy, cz) = c[quad[0]], c[quad[1]], c[quad[2]]
|
||||
ux, uy, uz, vx, vy, vz = bx - ax, by - ay, bz - az, cx - ax, cy - ay, cz - az
|
||||
ccw = (uy * vz - uz * vy) * n[0] + (uz * vx - ux * vz) * n[1] + (ux * vy - uy * vx) * n[2] > 0
|
||||
idx += [b, b + 2, b + 1, b, b + 3, b + 2] if ccw else [b, b + 1, b + 2, b, b + 2, b + 3]
|
||||
return verts, idx
|
||||
|
||||
|
||||
def fmt(v):
|
||||
return ("%d" % v) if float(v).is_integer() else ("%g" % v)
|
||||
|
||||
|
||||
def write(models, portals, nodes, areas, shadow, header, colors):
|
||||
out = [header, ""]
|
||||
for m in models:
|
||||
out.append('model { /* name = */ "%s" /* numSurfaces = */ %d' % (m["name"], len(m["surfaces"])))
|
||||
out.append("")
|
||||
for si, s in enumerate(m["surfaces"]):
|
||||
out.append('/* surface %d */ { "%s" /* numVerts = */ %d /* numIndexes = */ %d' % (si, s["material"], len(s["verts"]), len(s["idx"])))
|
||||
line = []
|
||||
for v in s["verts"]:
|
||||
vals = list(v) + (s["color"] if colors else [])
|
||||
line.append("( " + " ".join(fmt(x) for x in vals) + " )")
|
||||
if len(line) == 3:
|
||||
out.append(" ".join(line))
|
||||
line = []
|
||||
if line:
|
||||
out.append(" ".join(line))
|
||||
for k in range(0, len(s["idx"]), 15):
|
||||
out.append(" ".join(str(i) for i in s["idx"][k:k + 15]) + " ")
|
||||
out.append("}")
|
||||
out.append("")
|
||||
out.append("}")
|
||||
out.append("")
|
||||
out.append("shadowModel { /* name = */ \"%s\"" % shadow["name"])
|
||||
out.append("/* numVerts = */ %d /* noCaps = */ 0 /* noFrontCaps = */ 0 /* numIndexes = */ %d /* planeBits = */ 59"
|
||||
% (len(shadow["verts"]) // 3, len(shadow["indices"])))
|
||||
out.append(" ".join("( %s %s %s )" % tuple(fmt(x) for x in shadow["verts"][k:k + 3]) for k in range(0, len(shadow["verts"]), 3)))
|
||||
out.append(" ".join(str(i) for i in shadow["indices"]))
|
||||
out.append("}")
|
||||
out.append("")
|
||||
out.append("interAreaPortals { /* numAreas = */ %d /* numIAP = */ %d" % (areas, len(portals)))
|
||||
out.append("")
|
||||
out.append("/* interAreaPortal format is: numPoints positiveSideArea negativeSideArea ( point) ... */")
|
||||
for i, p in enumerate(portals):
|
||||
pts = " ".join("( %s %s %s )" % tuple(fmt(x) for x in p["points"][k:k + 3]) for k in range(0, len(p["points"]), 3))
|
||||
out.append("/* iap %d */ %d %d %d %s " % (i, len(p["points"]) // 3, p["positive"], p["negative"], pts))
|
||||
out.append("}")
|
||||
out.append("")
|
||||
out.append("nodes { /* numNodes = */ %d" % len(nodes))
|
||||
out.append("")
|
||||
out.append("/* node format is: ( planeVector ) positiveChild negativeChild */")
|
||||
out.append("/* a child number of 0 is an opaque, solid area */")
|
||||
out.append("/* negative child numbers are areas: (-1-child) */")
|
||||
for i, n in enumerate(nodes):
|
||||
out.append("/* node %d */ ( %s ) %d %d " % (i, " ".join(fmt(x) for x in n["plane"]), n["positive"], n["negative"]))
|
||||
out.append("}")
|
||||
return "\n".join(out) + "\n"
|
||||
|
||||
|
||||
def ref(models):
|
||||
res = []
|
||||
for m in models:
|
||||
ss = []
|
||||
for s in m["surfaces"]:
|
||||
pos = b"".join(struct.pack("<3f", *v[0:3]) for v in s["verts"])
|
||||
uv = b"".join(struct.pack("<2f", *v[3:5]) for v in s["verts"])
|
||||
ccw = []
|
||||
for k in range(0, len(s["idx"]), 3):
|
||||
a, b, c = s["idx"][k:k + 3]
|
||||
ccw += [a, c, b]
|
||||
ss.append({"material": s["material"], "verts": len(s["verts"]), "pos": zlib.crc32(pos), "uv": zlib.crc32(uv),
|
||||
"idx": zlib.crc32(struct.pack("<%dI" % len(ccw), *ccw)), "tris": len(ccw) // 3})
|
||||
res.append({"name": m["name"], "surfaces": ss})
|
||||
return res
|
||||
|
||||
|
||||
def level(rng, colors):
|
||||
models = []
|
||||
for a in range(2):
|
||||
surfs = []
|
||||
for k in range(2 + a):
|
||||
v, i = box(rng, a * 512 + k * 64, -128, 0, a * 512 + k * 64 + 48, 128 + rng.randint(0, 4) * 8, 96.5)
|
||||
surfs.append({"material": "textures/base_wall/lfwall%d" % (k + 1), "verts": v, "idx": i,
|
||||
"color": [255, 128, 0, 255]})
|
||||
models.append({"name": "_area%d" % a, "surfaces": surfs})
|
||||
v, i = box(rng, 100, 0, 8, 116, 16, 24)
|
||||
models.append({"name": "func_static_1", "surfaces": [{"material": "models/mapobjects/crate", "verts": v, "idx": i, "color": [10, 20, 30, 40]}]})
|
||||
portals = [{"positive": 1, "negative": 0, "points": [448, -128, 0, 448, 128, 0, 448, 128, 96, 448, -128, 96]}]
|
||||
nodes = [{"plane": [1, 0, 0, -448], "positive": 1, "negative": -1}, {"plane": [0, 0, 1, 0], "positive": 0, "negative": -2}]
|
||||
shadow = {"name": "_prelight_light_1", "verts": [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1], "indices": [0, 1, 2, 0, 2, 3]}
|
||||
return models, portals, nodes, 2, shadow
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
rng = ctx.rng(31)
|
||||
out = {}
|
||||
for key, header, colors in [("doom3", "mapProcFile003", False), ("quake4", 'PROC "4"', True)]:
|
||||
models, portals, nodes, areas, shadow = level(rng, colors)
|
||||
out[key] = {"text": write(models, portals, nodes, areas, shadow, header, colors), "models": ref(models),
|
||||
"portals": portals, "nodes": nodes, "areas": areas,
|
||||
"shadow": {"name": shadow["name"], "verts": len(shadow["verts"]) // 3, "indices": len(shadow["indices"])}}
|
||||
ctx.emit("proc", out)
|
||||
@@ -0,0 +1,112 @@
|
||||
# UDMF fixtures (tools/fixtures.py). Freedoom has no UDMF maps, so Freedoom MAP01 (BSD, licenses/freedoom-COPYING.txt;
|
||||
# the nix freedoom package, cut down as in wad.py) is converted here to a "Doom"-namespace TEXTMAP by the UDMF 1.1
|
||||
# conversion rules (tag -> id and arg0, flag bits -> booleans). The test checks that the TEXTMAP map gives the same
|
||||
# tables and the same Scene geometry as the binary lumps. Plus a hand-written ZDoom-namespace room (comments, octal /
|
||||
# hex, escapes, user_ and unknown keys, an unknown block) with exact areas.
|
||||
# tests/gen/udmf.luau { binary = <IWAD>, textmap = <PWAD with MAP01 as UDMF>, text = <the TEXTMAP>, room = <text> }
|
||||
import importlib.util, os, struct
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def wadgen():
|
||||
spec = importlib.util.spec_from_file_location("_wadfx", os.path.join(HERE, "wad.py"))
|
||||
m = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(m)
|
||||
return m
|
||||
|
||||
|
||||
def q(s):
|
||||
return '"' + s.replace("\\", "\\\\").replace('"', '\\"') + '"'
|
||||
|
||||
|
||||
def to_udmf(d):
|
||||
out = ['namespace = "Doom";', ""]
|
||||
nm = lambda b: b.split(b"\0")[0].decode("latin1")
|
||||
for i in range(0, len(d["THINGS"]), 10):
|
||||
x, y, a, t, f = struct.unpack_from("<hhHHH", d["THINGS"], i)
|
||||
kv = ["x = %d.0;" % x, "y = %d.0;" % y, "angle = %d;" % a, "type = %d;" % t]
|
||||
for k, on in [("skill1", f & 1), ("skill2", f & 1), ("skill3", f & 2), ("skill4", f & 4), ("skill5", f & 4),
|
||||
("ambush", f & 8), ("single", not f & 16), ("dm", not f & 32), ("coop", not f & 64), ("friend", f & 128)]:
|
||||
if on:
|
||||
kv.append("%s = true;" % k)
|
||||
out.append("thing // %d\n{\n%s\n}\n" % (i // 10, "\n".join(kv)))
|
||||
for i in range(0, len(d["VERTEXES"]), 4):
|
||||
x, y = struct.unpack_from("<hh", d["VERTEXES"], i)
|
||||
out.append("vertex { x = %d.000; y = %d.000; }" % (x, y))
|
||||
bits = ["blocking", "blockmonsters", "twosided", "dontpegtop", "dontpegbottom", "secret", "blocksound", "dontdraw", "mapped"]
|
||||
for i in range(0, len(d["LINEDEFS"]), 14):
|
||||
v1, v2, f, sp, tag, fr, bk = struct.unpack_from("<HHHHHHH", d["LINEDEFS"], i)
|
||||
kv = ["id = %d;" % tag, "v1 = %d;" % v1, "v2 = %d;" % v2, "sidefront = %d;" % fr]
|
||||
if bk != 0xFFFF:
|
||||
kv.append("sideback = %d;" % bk)
|
||||
if sp:
|
||||
kv += ["special = %d;" % sp, "arg0 = %d;" % tag]
|
||||
kv += ["%s = true;" % b for k, b in enumerate(bits) if f & (1 << k)]
|
||||
out.append("linedef\n{\n%s\n}\n" % "\n".join(kv))
|
||||
for i in range(0, len(d["SIDEDEFS"]), 30):
|
||||
xo, yo, up, lo, mid, sec = struct.unpack_from("<hh8s8s8sH", d["SIDEDEFS"], i)
|
||||
kv = ["sector = %d;" % sec]
|
||||
if xo:
|
||||
kv.append("offsetx = %d;" % xo)
|
||||
if yo:
|
||||
kv.append("offsety = %d;" % yo)
|
||||
for k, v in [("texturetop", up), ("texturebottom", lo), ("texturemiddle", mid)]:
|
||||
if nm(v) != "-":
|
||||
kv.append("%s = %s;" % (k, q(nm(v))))
|
||||
out.append("sidedef\n{\n%s\n}\n" % "\n".join(kv))
|
||||
for i in range(0, len(d["SECTORS"]), 26):
|
||||
fl, ce, ff, cf, li, sp, tag = struct.unpack_from("<hh8s8sHHH", d["SECTORS"], i)
|
||||
kv = ["heightfloor = %d;" % fl, "heightceiling = %d;" % ce, "texturefloor = %s;" % q(nm(ff)),
|
||||
"textureceiling = %s;" % q(nm(cf)), "lightlevel = %d;" % li]
|
||||
if sp:
|
||||
kv.append("special = %d;" % sp)
|
||||
if tag:
|
||||
kv.append("id = %d;" % tag)
|
||||
out.append("sector\n{\n%s\n}\n" % "\n".join(kv))
|
||||
return "\n".join(out) + "\n"
|
||||
|
||||
|
||||
ROOM = r'''// a 256 x 256 room (sector 0) with a 64 x 64 pillar sector (1), pillar floor 32
|
||||
/* written by hand
|
||||
for the rosetta tests */
|
||||
NameSpace = "ZDoom";
|
||||
user_note = "a \"quoted\" \\ note";
|
||||
vertex { x = 0; y = 0.0; } // 0
|
||||
vertex { x = 0x100; y = 0; } // 1: hex
|
||||
vertex { x = 256.0; y = 256e0; } // 2
|
||||
vertex { x = 0; y = 0400; } // 3: octal 256
|
||||
vertex { x = 96; y = 96; } vertex { x = 160; y = 96; } vertex { x = 160; y = 160; } vertex { x = 96; y = 160; }
|
||||
sidedef { sector = 0; texturemiddle = "Wall"; }
|
||||
sidedef { sector = 0; texturemiddle = "WALL"; }
|
||||
sidedef { sector = 0; texturemiddle = "WALL"; }
|
||||
sidedef { sector = 0; texturemiddle = "WALL"; }
|
||||
sidedef { sector = 0; texturebottom = "STEP"; offsetx_bottom = 4.0; } sidedef { sector = 0; texturebottom = "STEP"; }
|
||||
sidedef { sector = 0; texturebottom = "STEP"; } sidedef { sector = 0; texturebottom = "STEP"; }
|
||||
sidedef { sector = 1; } sidedef { sector = 1; } sidedef { sector = 1; } sidedef { sector = 1; }
|
||||
linedef { v1 = 0; v2 = 3; sidefront = 0; blocking = true; }
|
||||
linedef { v1 = 3; v2 = 2; sidefront = 1; Blocking = TRUE; }
|
||||
linedef { v1 = 2; v2 = 1; sidefront = 2; blocking = true; }
|
||||
linedef { v1 = 1; v2 = 0; sidefront = 3; blocking = true; id = 7; special = 80; arg0 = 3; playeruse = true; repeatspecial = true; }
|
||||
linedef { v1 = 4; v2 = 5; sidefront = 4; sideback = 8; twosided = true; }
|
||||
linedef { v1 = 5; v2 = 6; sidefront = 5; sideback = 9; twosided = true; }
|
||||
linedef { v1 = 6; v2 = 7; sidefront = 6; sideback = 10; twosided = true; }
|
||||
linedef { v1 = 7; v2 = 4; sidefront = 7; sideback = 11; twosided = true; }
|
||||
sector { heightfloor = 0; heightceiling = 128; texturefloor = "FLOOR"; textureceiling = "CEIL"; user_gravity = 0.5; }
|
||||
sector { heightfloor = 32; heightceiling = 128; texturefloor = "FLOOR"; textureceiling = "CEIL"; lightlevel = 200; id = 3; }
|
||||
thing { x = 32; y = 32; angle = 90; type = 1; skill1 = true; single = true; }
|
||||
thing { x = 128.5; y = 128; height = 8; type = 2014; id = 5; special = 80; arg0 = 1; dormant = true; }
|
||||
vavoombox { foo = 1; } // unknown block, kept
|
||||
'''
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
W = wadgen()
|
||||
root = ctx.nix("freedoom", ["sh", "-c", "dirname $(dirname $(readlink -f $(command -v freedoom2)))"]).decode().strip()
|
||||
full = open(os.path.join(root, W.FREEDOOM), "rb").read()
|
||||
sel, rng = W.cut(full)
|
||||
sel += rng("P_START", "P_END", 40) + rng("F_START", "F_END", 40)
|
||||
binary = W.write(b"IWAD", sel)
|
||||
text = to_udmf(dict(sel[1:11]))
|
||||
textmap = W.write(b"PWAD", [("MAP01", b""), ("TEXTMAP", text.encode()), ("ENDMAP", b"")] + sel[11:])
|
||||
ctx.emit("udmf", {"binary": binary, "textmap": textmap, "text": text, "room": ROOM})
|
||||
@@ -0,0 +1,183 @@
|
||||
# Wolfenstein 3D fixtures (tools/fixtures.py). id's data and source are not redistributable / GPL, so everything is
|
||||
# written here by this script's own writers from the ModdingWiki format descriptions: a random 6-bit palette; a VSWAP
|
||||
# with walls, sprites (t_compshape posts, with gaps), sound pages and the sound info page; a GAMEMAPS + MAPHEAD pair
|
||||
# with two maps (slots 1 and 3) whose planes are RLEW then Carmack compressed (near and far copies, literal 0xA7xx /
|
||||
# 0xA8xx words, RLEW runs and a literal tag value). The references are the source pixels / tiles: CRC-32 of the RGBA
|
||||
# (6-bit values scaled as (v << 2) | (v >> 4), sprite holes 0) and of the tiles as u16 LE.
|
||||
# tests/gen/wolf3d.luau { palette, vswap = { data, walls = { crc }, sprites = { crc }, sounds = { { bytes, crc } } },
|
||||
# gamemaps, maphead, maps = { { slot, name, width, height, planes = { crc } } } }
|
||||
import struct, zlib
|
||||
|
||||
TAG = 0xABCD
|
||||
|
||||
|
||||
def rgba(pal, idx, holes=None):
|
||||
out = bytearray()
|
||||
for k, i in enumerate(idx):
|
||||
if holes is not None and holes[k]:
|
||||
out += b"\0\0\0\0"
|
||||
else:
|
||||
r, g, b = (pal[i * 3 + c] for c in range(3))
|
||||
out += bytes([(r << 2) | (r >> 4), (g << 2) | (g >> 4), (b << 2) | (b >> 4), 255])
|
||||
return zlib.crc32(bytes(out))
|
||||
|
||||
|
||||
def sprite(rng):
|
||||
# columns left..right, each with 1-2 posts; pixel data first, then the column post lists
|
||||
left, right = rng.randint(0, 10), rng.randint(40, 63)
|
||||
img = [None] * 4096 # row-major y * 64 + x: palette index, None = hole
|
||||
pix = bytearray()
|
||||
cols = []
|
||||
hdr = 4 + (right - left + 1) * 2
|
||||
for x in range(left, right + 1):
|
||||
posts = []
|
||||
y = rng.randint(0, 8)
|
||||
for _ in range(rng.randint(1, 2)):
|
||||
y0 = y
|
||||
y1 = min(64, y0 + rng.randint(4, 30))
|
||||
if y0 >= y1:
|
||||
break
|
||||
base = hdr + len(pix)
|
||||
for yy in range(y0, y1):
|
||||
v = rng.randrange(256)
|
||||
img[yy * 64 + x] = v
|
||||
pix.append(v)
|
||||
posts.append((y1 * 2, base - y0, y0 * 2))
|
||||
y = y1 + rng.randint(2, 10)
|
||||
if y >= 60:
|
||||
break
|
||||
cols.append(posts)
|
||||
body = bytearray(pix)
|
||||
ofs = []
|
||||
for posts in cols:
|
||||
ofs.append(hdr + len(body))
|
||||
for e, s, st in posts:
|
||||
body += struct.pack("<HhH", e, s, st)
|
||||
body += struct.pack("<H", 0)
|
||||
data = struct.pack("<HH", left, right) + b"".join(struct.pack("<H", o) for o in ofs) + bytes(body)
|
||||
return data, img
|
||||
|
||||
|
||||
def vswap(rng, pal):
|
||||
walls, sprites, sounds = [], [], []
|
||||
for _ in range(3):
|
||||
cm = bytes(rng.randrange(256) for _ in range(4096)) # column-major x * 64 + y
|
||||
walls.append((cm, rgba(pal, [cm[x * 64 + y] for y in range(64) for x in range(64)])))
|
||||
for _ in range(3):
|
||||
data, img = sprite(rng)
|
||||
sprites.append((data, rgba(pal, [v or 0 for v in img], [v is None for v in img])))
|
||||
pages = [w for w, _ in walls] + [s for s, _ in sprites]
|
||||
ss, so = len(walls), len(walls) + len(sprites)
|
||||
# sound 1: one page; sound 2: two pages (4096 + 1000)
|
||||
snd = [bytes(rng.randrange(256) for _ in range(700)), bytes(rng.randrange(256) for _ in range(5096))]
|
||||
spages, info = [], b""
|
||||
for s in snd:
|
||||
info += struct.pack("<HH", len(spages), len(s))
|
||||
for k in range(0, len(s), 4096):
|
||||
spages.append(s[k:k + 4096])
|
||||
pages += spages + [info]
|
||||
n = len(pages)
|
||||
# a sparse page (offset 0) after the walls is legal: the second wall page stays, an extra sprite slot is sparse
|
||||
head = struct.pack("<HHH", n, ss, so)
|
||||
at = 6 + n * 6
|
||||
at = (at + 511) // 512 * 512
|
||||
offs, body = [], bytearray()
|
||||
for p in pages:
|
||||
offs.append(at + len(body))
|
||||
body += p
|
||||
body += b"\0" * ((-len(body)) % 512)
|
||||
out = head + b"".join(struct.pack("<I", o) for o in offs) + b"".join(struct.pack("<H", len(p)) for p in pages)
|
||||
out += b"\0" * (at - len(out)) + bytes(body)
|
||||
return out, {"walls": [c for _, c in walls], "sprites": [c for _, c in sprites],
|
||||
"sounds": [{"bytes": len(s), "first": s[0], "last": s[-1]} for s in snd]}
|
||||
|
||||
|
||||
def rlew(words):
|
||||
out = []
|
||||
i = 0
|
||||
while i < len(words):
|
||||
j = i
|
||||
while j < len(words) and words[j] == words[i] and j - i < 0xFFFF:
|
||||
j += 1
|
||||
if j - i > 3 or words[i] == TAG:
|
||||
out += [TAG, j - i, words[i]]
|
||||
else:
|
||||
out += words[i:j]
|
||||
i = j
|
||||
return out
|
||||
|
||||
|
||||
def carmack(words):
|
||||
out = bytearray()
|
||||
pos = {}
|
||||
i = 0
|
||||
while i < len(words):
|
||||
best, bo = 0, 0
|
||||
for cand in reversed(pos.get((words[i], words[i + 1]) if i + 1 < len(words) else None, [])[-32:]):
|
||||
k = 0
|
||||
while i + k < len(words) and words[cand + k] == words[i + k] and k < 255 and cand + k < i:
|
||||
k += 1
|
||||
if k > best:
|
||||
best, bo = k, cand
|
||||
if best >= 2:
|
||||
if i - bo <= 255:
|
||||
out += struct.pack("<HB", 0xA700 | best, i - bo)
|
||||
else:
|
||||
out += struct.pack("<HH", 0xA800 | best, bo)
|
||||
step = best
|
||||
else:
|
||||
w = words[i]
|
||||
if w >> 8 in (0xA7, 0xA8):
|
||||
out += struct.pack("<HB", w & 0xFF00, w & 0xFF)
|
||||
else:
|
||||
out += struct.pack("<H", w)
|
||||
step = 1
|
||||
for k in range(i, i + step):
|
||||
if k + 1 < len(words):
|
||||
pos.setdefault((words[k], words[k + 1]), []).append(k)
|
||||
i += step
|
||||
return bytes(out)
|
||||
|
||||
|
||||
def plane(words):
|
||||
r = [len(words) * 2] + rlew(words)
|
||||
return struct.pack("<H", len(r) * 2) + carmack(r)
|
||||
|
||||
|
||||
def grid(rng, w, h, k):
|
||||
g = []
|
||||
for y in range(h):
|
||||
for x in range(w):
|
||||
if k == 0:
|
||||
v = 1 if x in (0, w - 1) or y in (0, h - 1) else (rng.choice([108, 108, 108, 2, 90]) if rng.random() < 0.2 else 108)
|
||||
elif k == 1:
|
||||
v = rng.choice([0] * 20 + [19, 23, 0xA7FF, 0xA801, TAG])
|
||||
else:
|
||||
v = 0
|
||||
g.append(v)
|
||||
return g
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
rng = ctx.rng(64)
|
||||
pal = bytes(rng.randrange(64) for _ in range(768))
|
||||
vs, vref = vswap(rng, pal)
|
||||
maps, body = [], bytearray(b"TED5v1.0")
|
||||
heads = [0] * 100
|
||||
for slot, (name, w, h) in [(1, ("Wolf1 Map1", 64, 64)), (3, ("Test map", 20, 12))]:
|
||||
planes, crcs = [], []
|
||||
for k in range(3):
|
||||
g = grid(rng, w, h, k)
|
||||
crcs.append(zlib.crc32(struct.pack("<%dH" % len(g), *g)))
|
||||
planes.append(plane(g))
|
||||
starts = []
|
||||
for p in planes:
|
||||
starts.append(len(body))
|
||||
body += p
|
||||
heads[slot - 1] = len(body)
|
||||
body += struct.pack("<iiiHHHHH16s", *starts, *(len(p) for p in planes), w, h, name.encode())
|
||||
body += b"!ID!"
|
||||
maps.append({"slot": slot, "name": name, "width": w, "height": h, "planes": crcs})
|
||||
heads[1] = -1
|
||||
maphead = struct.pack("<H100i", TAG, *heads)
|
||||
ctx.emit("wolf3d", {"palette": pal, "vswap": dict(vref, data=vs), "gamemaps": bytes(body), "maphead": maphead, "maps": maps})
|
||||
Reference in new issue
Block a user