@woosh/meep-engine 3.78.4 → 3.79.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/package.json +1 -1
  3. package/src/engine/asset/GameAssetType.d.ts +2 -0
  4. package/src/engine/asset/GameAssetType.js +10 -0
  5. package/src/engine/asset/guessAssetType.d.ts.map +1 -1
  6. package/src/engine/asset/guessAssetType.js +4 -0
  7. package/src/engine/asset/load_model_scene_bundle.d.ts +1 -1
  8. package/src/engine/asset/load_model_scene_bundle.js +2 -2
  9. package/src/engine/asset/loaders/MTFSceneBundleAssetLoader.d.ts +42 -0
  10. package/src/engine/asset/loaders/MTFSceneBundleAssetLoader.d.ts.map +1 -0
  11. package/src/engine/asset/loaders/MTFSceneBundleAssetLoader.js +83 -0
  12. package/src/engine/asset/loaders/MTFTextureAssetLoader.d.ts +36 -0
  13. package/src/engine/asset/loaders/MTFTextureAssetLoader.d.ts.map +1 -0
  14. package/src/engine/asset/loaders/MTFTextureAssetLoader.js +78 -0
  15. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.d.ts +6 -1
  16. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.d.ts.map +1 -1
  17. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +8 -2
  18. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  19. package/src/shade/renderer/acoustics/GPUAcousticLattice.d.ts +1 -1
  20. package/src/shade/renderer/acoustics/GPUAcousticProbes.d.ts +1 -1
  21. package/src/shade/renderer/acoustics/GPUAcoustics.d.ts +1 -1
  22. package/src/shade/renderer/animation/ShadeAnimationClipSerializationAdapter.d.ts +33 -0
  23. package/src/shade/renderer/animation/ShadeAnimationClipSerializationAdapter.d.ts.map +1 -0
  24. package/src/shade/renderer/animation/ShadeAnimationClipSerializationAdapter.js +196 -0
  25. package/src/shade/renderer/animation/SkinSerializationAdapter.d.ts +25 -0
  26. package/src/shade/renderer/animation/SkinSerializationAdapter.d.ts.map +1 -0
  27. package/src/shade/renderer/animation/SkinSerializationAdapter.js +85 -0
  28. package/src/shade/renderer/hair/GPUHairSystem.d.ts.map +1 -1
  29. package/src/shade/renderer/hair/GPUHairSystem.js +16 -7
  30. package/src/shade/renderer/hair/HAIR.d.ts +5 -3
  31. package/src/shade/renderer/hair/HAIR.d.ts.map +1 -1
  32. package/src/shade/renderer/hair/HAIR.js +6 -4
  33. package/src/shade/renderer/hair/hair_shadow_draw.d.ts +10 -10
  34. package/src/shade/renderer/hair/hair_shadow_draw.d.ts.map +1 -1
  35. package/src/shade/renderer/hair/hair_shadow_draw.js +21 -17
  36. package/src/shade/renderer/hair/shader_hair_cull.d.ts.map +1 -1
  37. package/src/shade/renderer/hair/shader_hair_cull.js +6 -2
  38. package/src/shade/renderer/hair/shader_hair_shadow_list.d.ts +5 -4
  39. package/src/shade/renderer/hair/shader_hair_shadow_list.d.ts.map +1 -1
  40. package/src/shade/renderer/hair/shader_hair_shadow_list.js +10 -12
  41. package/src/shade/renderer/loader/SceneNodeSerializationAdapter.d.ts +38 -0
  42. package/src/shade/renderer/loader/SceneNodeSerializationAdapter.d.ts.map +1 -0
  43. package/src/shade/renderer/loader/SceneNodeSerializationAdapter.js +198 -0
  44. package/src/shade/renderer/loader/mtf/MTFTexture.d.ts +88 -0
  45. package/src/shade/renderer/loader/mtf/MTFTexture.d.ts.map +1 -0
  46. package/src/shade/renderer/loader/mtf/MTFTexture.js +159 -0
  47. package/src/shade/renderer/loader/mtf/MTFTextureSerializationAdapter.d.ts +30 -0
  48. package/src/shade/renderer/loader/mtf/MTFTextureSerializationAdapter.d.ts.map +1 -0
  49. package/src/shade/renderer/loader/mtf/MTFTextureSerializationAdapter.js +136 -0
  50. package/src/shade/renderer/loader/mtf/MTF_PACKAGE_MAGIC.d.ts +7 -0
  51. package/src/shade/renderer/loader/mtf/MTF_PACKAGE_MAGIC.d.ts.map +1 -0
  52. package/src/shade/renderer/loader/mtf/MTF_PACKAGE_MAGIC.js +6 -0
  53. package/src/shade/renderer/loader/mtf/MTF_PACKAGE_VERSION.d.ts +8 -0
  54. package/src/shade/renderer/loader/mtf/MTF_PACKAGE_VERSION.d.ts.map +1 -0
  55. package/src/shade/renderer/loader/mtf/MTF_PACKAGE_VERSION.js +7 -0
  56. package/src/shade/renderer/loader/mtf/MTF_TEXTURE_MAGIC.d.ts +7 -0
  57. package/src/shade/renderer/loader/mtf/MTF_TEXTURE_MAGIC.d.ts.map +1 -0
  58. package/src/shade/renderer/loader/mtf/MTF_TEXTURE_MAGIC.js +6 -0
  59. package/src/shade/renderer/loader/mtf/MTF_TEXTURE_VERSION.d.ts +7 -0
  60. package/src/shade/renderer/loader/mtf/MTF_TEXTURE_VERSION.d.ts.map +1 -0
  61. package/src/shade/renderer/loader/mtf/MTF_TEXTURE_VERSION.js +6 -0
  62. package/src/shade/renderer/loader/mtf/load_mtf.d.ts +41 -0
  63. package/src/shade/renderer/loader/mtf/load_mtf.d.ts.map +1 -0
  64. package/src/shade/renderer/loader/mtf/load_mtf.js +73 -0
  65. package/src/shade/renderer/loader/mtf/mtf_bundle_textures.d.ts +19 -0
  66. package/src/shade/renderer/loader/mtf/mtf_bundle_textures.d.ts.map +1 -0
  67. package/src/shade/renderer/loader/mtf/mtf_bundle_textures.js +57 -0
  68. package/src/shade/renderer/loader/mtf/mtf_encode_texture.d.ts +9 -0
  69. package/src/shade/renderer/loader/mtf/mtf_encode_texture.d.ts.map +1 -0
  70. package/src/shade/renderer/loader/mtf/mtf_encode_texture.js +78 -0
  71. package/src/shade/renderer/loader/mtf/mtf_export.d.ts +45 -0
  72. package/src/shade/renderer/loader/mtf/mtf_export.d.ts.map +1 -0
  73. package/src/shade/renderer/loader/mtf/mtf_export.js +161 -0
  74. package/src/shade/renderer/loader/mtf/mtf_is_texture.d.ts +9 -0
  75. package/src/shade/renderer/loader/mtf/mtf_is_texture.d.ts.map +1 -0
  76. package/src/shade/renderer/loader/mtf/mtf_is_texture.js +12 -0
  77. package/src/shade/renderer/loader/mtf/mtf_read_collection.d.ts +24 -0
  78. package/src/shade/renderer/loader/mtf/mtf_read_collection.d.ts.map +1 -0
  79. package/src/shade/renderer/loader/mtf/mtf_read_collection.js +37 -0
  80. package/src/shade/renderer/loader/mtf/mtf_read_scene.d.ts +27 -0
  81. package/src/shade/renderer/loader/mtf/mtf_read_scene.d.ts.map +1 -0
  82. package/src/shade/renderer/loader/mtf/mtf_read_scene.js +121 -0
  83. package/src/shade/renderer/loader/mtf/mtf_read_textures.d.ts +18 -0
  84. package/src/shade/renderer/loader/mtf/mtf_read_textures.d.ts.map +1 -0
  85. package/src/shade/renderer/loader/mtf/mtf_read_textures.js +51 -0
  86. package/src/shade/renderer/loader/mtf/mtf_resolve_uri.d.ts +21 -0
  87. package/src/shade/renderer/loader/mtf/mtf_resolve_uri.d.ts.map +1 -0
  88. package/src/shade/renderer/loader/mtf/mtf_resolve_uri.js +98 -0
  89. package/src/shade/renderer/loader/mtf/mtf_serialization_registry.d.ts +25 -0
  90. package/src/shade/renderer/loader/mtf/mtf_serialization_registry.d.ts.map +1 -0
  91. package/src/shade/renderer/loader/mtf/mtf_serialization_registry.js +51 -0
  92. package/src/shade/renderer/loader/mtf/mtf_texture_read.d.ts +20 -0
  93. package/src/shade/renderer/loader/mtf/mtf_texture_read.d.ts.map +1 -0
  94. package/src/shade/renderer/loader/mtf/mtf_texture_read.js +80 -0
  95. package/src/shade/renderer/loader/mtf/mtf_texture_select.d.ts +24 -0
  96. package/src/shade/renderer/loader/mtf/mtf_texture_select.d.ts.map +1 -0
  97. package/src/shade/renderer/loader/mtf/mtf_texture_select.js +42 -0
  98. package/src/shade/renderer/loader/mtf/mtf_texture_write.d.ts +31 -0
  99. package/src/shade/renderer/loader/mtf/mtf_texture_write.d.ts.map +1 -0
  100. package/src/shade/renderer/loader/mtf/mtf_texture_write.js +87 -0
  101. package/src/shade/renderer/loader/mtf/mtf_write.d.ts +36 -0
  102. package/src/shade/renderer/loader/mtf/mtf_write.d.ts.map +1 -0
  103. package/src/shade/renderer/loader/mtf/mtf_write.js +161 -0
  104. package/src/shade/renderer/material/StandardShadeMaterialSerializationAdapter.d.ts +39 -0
  105. package/src/shade/renderer/material/StandardShadeMaterialSerializationAdapter.d.ts.map +1 -0
  106. package/src/shade/renderer/material/StandardShadeMaterialSerializationAdapter.js +207 -0
  107. package/src/shade/renderer/scene/optimization/source_to_sampler2d.d.ts.map +1 -1
  108. package/src/shade/renderer/scene/optimization/source_to_sampler2d.js +3 -1
  109. package/src/shade/renderer/scene/serialization/STANDARD_MATERIAL_SERIALIZED_BYTE_SIZE.d.ts +5 -5
  110. package/src/shade/renderer/scene/serialization/STANDARD_MATERIAL_SERIALIZED_BYTE_SIZE.js +5 -5
  111. package/src/shade/renderer/scene/serialization/deserialize_scene.d.ts.map +1 -1
  112. package/src/shade/renderer/scene/serialization/deserialize_scene.js +491 -528
  113. package/src/shade/renderer/scene/serialization/serialize_scene.d.ts +0 -10
  114. package/src/shade/renderer/scene/serialization/serialize_scene.d.ts.map +1 -1
  115. package/src/shade/renderer/scene/serialization/serialize_scene.js +15 -71
  116. package/src/shade/renderer/texture/format/gpu_texture_format_without_srgb.d.ts +11 -0
  117. package/src/shade/renderer/texture/format/gpu_texture_format_without_srgb.d.ts.map +1 -0
  118. package/src/shade/renderer/texture/format/gpu_texture_format_without_srgb.js +14 -0
  119. package/src/shade/renderer/texture/texture_role_image_quality.d.ts +10 -0
  120. package/src/shade/renderer/texture/texture_role_image_quality.d.ts.map +1 -0
  121. package/src/shade/renderer/texture/texture_role_image_quality.js +29 -0
@@ -0,0 +1,51 @@
1
+ import { BinarySerializationRegistry } from "../../../../engine/ecs/storage/binary/BinarySerializationRegistry.js";
2
+ import { ShadeAnimationClipSerializationAdapter } from "../../animation/ShadeAnimationClipSerializationAdapter.js";
3
+ import { SkinSerializationAdapter } from "../../animation/SkinSerializationAdapter.js";
4
+ import { MeshletGeometrySerializationAdapter } from "../../geometry/MeshletGeometrySerializationAdapter.js";
5
+ import { MeshletGeometrySerializationUpgrader_0_1 } from "../../geometry/MeshletGeometrySerializationUpgrader_0_1.js";
6
+ import { StandardShadeMaterialSerializationAdapter } from "../../material/StandardShadeMaterialSerializationAdapter.js";
7
+ import { SceneNodeSerializationAdapter } from "../SceneNodeSerializationAdapter.js";
8
+ import { MTFTextureSerializationAdapter } from "./MTFTextureSerializationAdapter.js";
9
+
10
+ /**
11
+ * The names an MTF package's collections carry, in the order a package holds them. A name is what the file says
12
+ * its elements are, and what the reader finds their adapter and its upgraders by.
13
+ */
14
+ export const MTF_CLASS_TEXTURE = "MTFTexture";
15
+ export const MTF_CLASS_MATERIAL = "StandardShadeMaterial";
16
+ export const MTF_CLASS_GEOMETRY = "MeshletGeometry";
17
+ export const MTF_CLASS_NODE = "SceneNode";
18
+ export const MTF_CLASS_SKIN = "Skin";
19
+ export const MTF_CLASS_CLIP = "ShadeAnimationClip";
20
+
21
+ /**
22
+ * The adapters an MTF package is written and read with, and the upgraders that bring a collection written at an
23
+ * earlier version of its class up to the one the adapter reads. A new registry a call: the adapters that resolve
24
+ * indices hold the lists they resolve against while a collection is being written or read.
25
+ *
26
+ * A class that gains a version registers its upgrader here, and every package ever written keeps reading.
27
+ *
28
+ * @returns {BinarySerializationRegistry}
29
+ *
30
+ * @author Alex Goldring
31
+ * @copyright Company Named Limited (c) 2026
32
+ */
33
+ export function mtf_serialization_registry() {
34
+ const registry = new BinarySerializationRegistry();
35
+
36
+ registry.registerAdapter(new MTFTextureSerializationAdapter(), MTF_CLASS_TEXTURE);
37
+ registry.registerAdapter(new StandardShadeMaterialSerializationAdapter(), MTF_CLASS_MATERIAL);
38
+
39
+ // with its tree: a package is read without building anything
40
+ const geometry = new MeshletGeometrySerializationAdapter();
41
+ geometry.serialize_bvh = true;
42
+
43
+ registry.registerAdapter(geometry, MTF_CLASS_GEOMETRY);
44
+ registry.registerUpgrader(MTF_CLASS_GEOMETRY, new MeshletGeometrySerializationUpgrader_0_1());
45
+
46
+ registry.registerAdapter(new SceneNodeSerializationAdapter(), MTF_CLASS_NODE);
47
+ registry.registerAdapter(new SkinSerializationAdapter(), MTF_CLASS_SKIN);
48
+ registry.registerAdapter(new ShadeAnimationClipSerializationAdapter(), MTF_CLASS_CLIP);
49
+
50
+ return registry;
51
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The texture an MTF texture file holds, as {@link mtf_texture_write} wrote it.
3
+ *
4
+ * Its levels are views of `data`, not copies: a level goes to the device from the file it arrived in, and the file
5
+ * lives as long as the texels do.
6
+ *
7
+ * Every refusal is a thrown error and none is an assert: a file is outside data, and a wrong one has to be refused
8
+ * in a build with asserts stripped too.
9
+ *
10
+ * @param {ArrayBuffer} data the whole file
11
+ * @returns {ShadeTexelData}
12
+ * @throws {Error} if the bytes are not a texture file, are of a version newer than {@link MTF_TEXTURE_VERSION},
13
+ * name a format the engine does not know, or are not exactly as long as their levels
14
+ *
15
+ * @author Alex Goldring
16
+ * @copyright Company Named Limited (c) 2026
17
+ */
18
+ export function mtf_texture_read(data: ArrayBuffer): ShadeTexelData;
19
+ import { ShadeTexelData } from "../../texture/source/ShadeTexelData.js";
20
+ //# sourceMappingURL=mtf_texture_read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mtf_texture_read.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/loader/mtf/mtf_texture_read.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;GAgBG;AACH,uCARW,WAAW,GACT,cAAc,CA+D1B;+BA7E8B,wCAAwC"}
@@ -0,0 +1,80 @@
1
+ import { BinaryBuffer } from "../../../../core/binary/BinaryBuffer.js";
2
+ import { gpu_texture_format_without_srgb } from "../../texture/format/gpu_texture_format_without_srgb.js";
3
+ import { ShadeTexelData } from "../../texture/source/ShadeTexelData.js";
4
+ import { mtf_is_texture } from "./mtf_is_texture.js";
5
+ import { MTF_TEXTURE_VERSION } from "./MTF_TEXTURE_VERSION.js";
6
+
7
+ /**
8
+ * The texture an MTF texture file holds, as {@link mtf_texture_write} wrote it.
9
+ *
10
+ * Its levels are views of `data`, not copies: a level goes to the device from the file it arrived in, and the file
11
+ * lives as long as the texels do.
12
+ *
13
+ * Every refusal is a thrown error and none is an assert: a file is outside data, and a wrong one has to be refused
14
+ * in a build with asserts stripped too.
15
+ *
16
+ * @param {ArrayBuffer} data the whole file
17
+ * @returns {ShadeTexelData}
18
+ * @throws {Error} if the bytes are not a texture file, are of a version newer than {@link MTF_TEXTURE_VERSION},
19
+ * name a format the engine does not know, or are not exactly as long as their levels
20
+ *
21
+ * @author Alex Goldring
22
+ * @copyright Company Named Limited (c) 2026
23
+ */
24
+ export function mtf_texture_read(data) {
25
+ if (!mtf_is_texture(data)) {
26
+ throw new Error("not an MTF texture file: it does not open with 'MTFT'");
27
+ }
28
+
29
+ const buffer = BinaryBuffer.fromArrayBuffer(data);
30
+
31
+ // the magic
32
+ buffer.skip(4);
33
+
34
+ const version = buffer.readUint32();
35
+
36
+ if (version > MTF_TEXTURE_VERSION) {
37
+ throw new Error(`an MTF texture file of version ${version}, newer than this engine reads (${MTF_TEXTURE_VERSION})`);
38
+ }
39
+
40
+ // a file that names the sRGB one of a pair holds the same bytes: read as the other, as this engine writes it
41
+ const format = gpu_texture_format_without_srgb(buffer.readUTF8String());
42
+
43
+ const width = buffer.readUint32();
44
+ const height = buffer.readUint32();
45
+ const depth = buffer.readUint32();
46
+
47
+ const level_count = buffer.readUint8();
48
+
49
+ if (width === 0 || height === 0 || depth === 0 || level_count === 0) {
50
+ throw new Error(`an MTF texture file of ${width}x${height}x${depth} texels and ${level_count} levels holds no texture`);
51
+ }
52
+
53
+ const file_bytes = buffer.raw_bytes;
54
+ const file_length = data.byteLength;
55
+
56
+ /** @type {Uint8Array[]} */
57
+ const levels = new Array(level_count);
58
+
59
+ let position = buffer.position;
60
+
61
+ for (let level = level_count - 1; level >= 0; level--) {
62
+ // throws for a name that is not a format
63
+ const length = ShadeTexelData.level_byte_length(format, width, height, depth, level);
64
+
65
+ if (position + length > file_length) {
66
+ throw new Error(`the MTF texture file is cut short: level ${level} of the ${width}x${height}x${depth} '${format}' texture is ${length} bytes from ${position}, and the file is ${file_length} bytes long`);
67
+ }
68
+
69
+ levels[level] = file_bytes.subarray(position, position + length);
70
+
71
+ position += length;
72
+ }
73
+
74
+ if (position !== file_length) {
75
+ throw new Error(`the MTF texture file holds ${file_length - position} bytes after its last level`);
76
+ }
77
+
78
+ // refuses a chain that is neither one level nor whole
79
+ return new ShadeTexelData(format, width, height, depth, levels);
80
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @typedef {import("../../texture/TextureVariantSet.js").TextureVariantSet} TextureVariantSet
3
+ * @typedef {import("../../texture/TextureRole.js").TextureRole} TextureRole
4
+ */
5
+ /**
6
+ * Which of a texture's files a device fetches.
7
+ *
8
+ * First the engine's own choice: the best format for the role that was built and that the device samples
9
+ * ({@link texture_variant_select}). Where none of those was built, any format that was and that the device samples,
10
+ * in the order the record lists them, which is the order whoever built them chose. The fallback only when the
11
+ * device samples nothing that was built: texels a device takes as they are come before an image it has to decode.
12
+ *
13
+ * @param {TextureVariantSet} variants what was built for the texture
14
+ * @param {TextureRole|number} role what the texture is for
15
+ * @param {Set<GPUTextureFormat>} support what the device can sample
16
+ * @returns {string} the URI to fetch, as the record holds it
17
+ *
18
+ * @author Alex Goldring
19
+ * @copyright Company Named Limited (c) 2026
20
+ */
21
+ export function mtf_texture_select(variants: TextureVariantSet, role: TextureRole | number, support: Set<GPUTextureFormat>): string;
22
+ export type TextureVariantSet = import("../../texture/TextureVariantSet.js").TextureVariantSet;
23
+ export type TextureRole = import("../../texture/TextureRole.js").TextureRole;
24
+ //# sourceMappingURL=mtf_texture_select.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mtf_texture_select.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/loader/mtf/mtf_texture_select.js"],"names":[],"mappings":"AAEA;;;GAGG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,6CARW,iBAAiB,QACjB,WAAW,GAAC,MAAM,WAClB,qBAAqB,GACnB,MAAM,CAuBlB;gCAtCY,OAAO,oCAAoC,EAAE,iBAAiB;0BAC9D,OAAO,8BAA8B,EAAE,WAAW"}
@@ -0,0 +1,42 @@
1
+ import { texture_variant_select } from "../../texture/format/texture_variant_select.js";
2
+
3
+ /**
4
+ * @typedef {import("../../texture/TextureVariantSet.js").TextureVariantSet} TextureVariantSet
5
+ * @typedef {import("../../texture/TextureRole.js").TextureRole} TextureRole
6
+ */
7
+
8
+ /**
9
+ * Which of a texture's files a device fetches.
10
+ *
11
+ * First the engine's own choice: the best format for the role that was built and that the device samples
12
+ * ({@link texture_variant_select}). Where none of those was built, any format that was and that the device samples,
13
+ * in the order the record lists them, which is the order whoever built them chose. The fallback only when the
14
+ * device samples nothing that was built: texels a device takes as they are come before an image it has to decode.
15
+ *
16
+ * @param {TextureVariantSet} variants what was built for the texture
17
+ * @param {TextureRole|number} role what the texture is for
18
+ * @param {Set<GPUTextureFormat>} support what the device can sample
19
+ * @returns {string} the URI to fetch, as the record holds it
20
+ *
21
+ * @author Alex Goldring
22
+ * @copyright Company Named Limited (c) 2026
23
+ */
24
+ export function mtf_texture_select(variants, role, support) {
25
+ const preferred = texture_variant_select(variants, role, support);
26
+
27
+ if (preferred !== variants.fallback) {
28
+ return preferred;
29
+ }
30
+
31
+ const formats = variants.formats;
32
+
33
+ for (let i = 0; i < formats.length; i++) {
34
+ const format = formats[i];
35
+
36
+ if (support.has(format)) {
37
+ return variants.path(format);
38
+ }
39
+ }
40
+
41
+ return variants.fallback;
42
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * One texture in one GPU format, as an MTF texture file:
3
+ *
4
+ * <pre>
5
+ * u32 magic {@link MTF_TEXTURE_MAGIC}
6
+ * u32 version {@link MTF_TEXTURE_VERSION}
7
+ * UTF8 format the WebGPU name the payload states
8
+ * u32 width texels of the base level
9
+ * u32 height
10
+ * u32 depth
11
+ * u8 level_count
12
+ * levels coarsest first, the base level last
13
+ * </pre>
14
+ *
15
+ * A level is the payload's own bytes, rows of blocks with no padding, and its length is not written: it follows
16
+ * from the format and the size ({@link ShadeTexelData.level_byte_length}). Coarsest first puts a usable texture at
17
+ * the head of the file.
18
+ *
19
+ * What the bytes mean is the producer's to have settled: colour that carries opacity is premultiplied, and the
20
+ * format named is the non-sRGB one of its pair.
21
+ *
22
+ * @param {ShadeTexelData} texel_data every level present
23
+ * @returns {ArrayBuffer} the file
24
+ * @throws {Error} if a level has not arrived
25
+ *
26
+ * @author Alex Goldring
27
+ * @copyright Company Named Limited (c) 2026
28
+ */
29
+ export function mtf_texture_write(texel_data: ShadeTexelData): ArrayBuffer;
30
+ export type ShadeTexelData = import("../../texture/source/ShadeTexelData.js").ShadeTexelData;
31
+ //# sourceMappingURL=mtf_texture_write.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mtf_texture_write.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/loader/mtf/mtf_texture_write.js"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,8CAPW,cAAc,GACZ,WAAW,CAgDvB;6BAhFY,OAAO,wCAAwC,EAAE,cAAc"}
@@ -0,0 +1,87 @@
1
+ import { BinaryBuffer } from "../../../../core/binary/BinaryBuffer.js";
2
+ import { gpu_texture_format_without_srgb } from "../../texture/format/gpu_texture_format_without_srgb.js";
3
+ import { MTF_TEXTURE_MAGIC } from "./MTF_TEXTURE_MAGIC.js";
4
+ import { MTF_TEXTURE_VERSION } from "./MTF_TEXTURE_VERSION.js";
5
+
6
+ /**
7
+ * @typedef {import("../../texture/source/ShadeTexelData.js").ShadeTexelData} ShadeTexelData
8
+ */
9
+
10
+ /**
11
+ * More than the bytes of a texture file ahead of its levels: two words, a format name, three extents and a count.
12
+ *
13
+ * @type {number}
14
+ */
15
+ const HEADER_RESERVE = 128;
16
+
17
+ /**
18
+ * One texture in one GPU format, as an MTF texture file:
19
+ *
20
+ * <pre>
21
+ * u32 magic {@link MTF_TEXTURE_MAGIC}
22
+ * u32 version {@link MTF_TEXTURE_VERSION}
23
+ * UTF8 format the WebGPU name the payload states
24
+ * u32 width texels of the base level
25
+ * u32 height
26
+ * u32 depth
27
+ * u8 level_count
28
+ * levels coarsest first, the base level last
29
+ * </pre>
30
+ *
31
+ * A level is the payload's own bytes, rows of blocks with no padding, and its length is not written: it follows
32
+ * from the format and the size ({@link ShadeTexelData.level_byte_length}). Coarsest first puts a usable texture at
33
+ * the head of the file.
34
+ *
35
+ * What the bytes mean is the producer's to have settled: colour that carries opacity is premultiplied, and the
36
+ * format named is the non-sRGB one of its pair.
37
+ *
38
+ * @param {ShadeTexelData} texel_data every level present
39
+ * @returns {ArrayBuffer} the file
40
+ * @throws {Error} if a level has not arrived
41
+ *
42
+ * @author Alex Goldring
43
+ * @copyright Company Named Limited (c) 2026
44
+ */
45
+ export function mtf_texture_write(texel_data) {
46
+ const levels = texel_data.levels;
47
+ const level_count = levels.length;
48
+
49
+ let level_bytes = 0;
50
+
51
+ for (let level = 0; level < level_count; level++) {
52
+ const bytes = levels[level];
53
+
54
+ if (bytes === undefined) {
55
+ throw new Error(`level ${level} of the ${texel_data.width}x${texel_data.height}x${texel_data.depth} '${texel_data.format}' payload has not arrived, and a texture file holds every level`);
56
+ }
57
+
58
+ level_bytes += bytes.byteLength;
59
+ }
60
+
61
+ const buffer = new BinaryBuffer();
62
+
63
+ // once, rather than by growth: a base level is megabytes
64
+ buffer.ensureCapacity(HEADER_RESERVE + level_bytes);
65
+
66
+ buffer.writeUint32(MTF_TEXTURE_MAGIC);
67
+ buffer.writeUint32(MTF_TEXTURE_VERSION);
68
+
69
+ // the pair's two names are the same bytes: which of them a texture is, is its record's to say
70
+ buffer.writeUTF8String(gpu_texture_format_without_srgb(texel_data.format));
71
+
72
+ buffer.writeUint32(texel_data.width);
73
+ buffer.writeUint32(texel_data.height);
74
+ buffer.writeUint32(texel_data.depth);
75
+
76
+ buffer.writeUint8(level_count);
77
+
78
+ for (let level = level_count - 1; level >= 0; level--) {
79
+ const bytes = levels[level];
80
+
81
+ buffer.writeBytes(bytes, 0, bytes.byteLength);
82
+ }
83
+
84
+ buffer.trim();
85
+
86
+ return buffer.data;
87
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * A model as an MTF package: a header, then six collections in the order each needs the ones before it.
3
+ *
4
+ * <pre>
5
+ * u32 magic {@link MTF_PACKAGE_MAGIC}
6
+ * u32 version {@link MTF_PACKAGE_VERSION}
7
+ * collection of {@link MTFTexture} one a texture the materials name
8
+ * collection of {@link StandardShadeMaterial} one a material the nodes draw with
9
+ * collection of {@link MeshletGeometry} one a geometry the nodes draw, with its tree
10
+ * collection of {@link SceneNode} the bundle's nodes, in their order
11
+ * collection of {@link Skin}
12
+ * collection of {@link ShadeAnimationClip}
13
+ * </pre>
14
+ *
15
+ * A collection is what {@link BinaryCollectionSerializer} writes: its class's name and version, a count, and each
16
+ * element by its adapter. The package holds no texels. A texture's record says where its files are
17
+ * (`texture_variants`), and whoever wrote those files is who knows.
18
+ *
19
+ * The bundle is read and not changed.
20
+ *
21
+ * @param {SceneBundle} bundle
22
+ * @param {Map<ShadeTexture, TextureVariantSet>} texture_variants for every texture of {@link mtf_bundle_textures},
23
+ * the encodings built for it and the URI of each, relative to where the package will be or absolute
24
+ * @returns {ArrayBuffer} the package
25
+ * @throws {Error} if a texture has no entry in `texture_variants`, a node draws with a material that is not a
26
+ * {@link StandardShadeMaterial} or a geometry whose meshlets are not in memory, or the bundle carries lights or
27
+ * foliage wind rigs
28
+ *
29
+ * @author Alex Goldring
30
+ * @copyright Company Named Limited (c) 2026
31
+ */
32
+ export function mtf_write(bundle: SceneBundle, texture_variants: Map<ShadeTexture, TextureVariantSet>): ArrayBuffer;
33
+ export type SceneBundle = import("../SceneBundle.js").SceneBundle;
34
+ export type ShadeTexture = import("../../texture/ShadeTexture.js").ShadeTexture;
35
+ export type TextureVariantSet = import("../../texture/TextureVariantSet.js").TextureVariantSet;
36
+ //# sourceMappingURL=mtf_write.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mtf_write.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/loader/mtf/mtf_write.js"],"names":[],"mappings":"AAiDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,kCAXW,WAAW,oBACX,IAAI,YAAY,EAAE,iBAAiB,CAAC,GAElC,WAAW,CAwFvB;0BA/IY,OAAO,mBAAmB,EAAE,WAAW;2BACvC,OAAO,+BAA+B,EAAE,YAAY;gCACpD,OAAO,oCAAoC,EAAE,iBAAiB"}
@@ -0,0 +1,161 @@
1
+ import { BinaryBuffer } from "../../../../core/binary/BinaryBuffer.js";
2
+ import { BinaryCollectionSerializer } from "../../../../engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js";
3
+ import { mtf_bundle_textures } from "./mtf_bundle_textures.js";
4
+ import { MTF_PACKAGE_MAGIC } from "./MTF_PACKAGE_MAGIC.js";
5
+ import { MTF_PACKAGE_VERSION } from "./MTF_PACKAGE_VERSION.js";
6
+ import {
7
+ MTF_CLASS_CLIP,
8
+ MTF_CLASS_GEOMETRY,
9
+ MTF_CLASS_MATERIAL,
10
+ MTF_CLASS_NODE,
11
+ MTF_CLASS_SKIN,
12
+ MTF_CLASS_TEXTURE,
13
+ mtf_serialization_registry
14
+ } from "./mtf_serialization_registry.js";
15
+ import { MTFTexture } from "./MTFTexture.js";
16
+
17
+ /**
18
+ * @typedef {import("../SceneBundle.js").SceneBundle} SceneBundle
19
+ * @typedef {import("../../texture/ShadeTexture.js").ShadeTexture} ShadeTexture
20
+ * @typedef {import("../../texture/TextureVariantSet.js").TextureVariantSet} TextureVariantSet
21
+ */
22
+
23
+ const NO_OPTIONS = [];
24
+
25
+ /**
26
+ * @param {BinaryCollectionSerializer} serializer
27
+ * @param {string} class_name
28
+ * @param {Array} elements
29
+ * @param {Array} adapter_options what the class's adapter is initialized with
30
+ */
31
+ function write_collection(serializer, class_name, elements, adapter_options) {
32
+ serializer.setClass(class_name);
33
+
34
+ // no dictionary: each object is written once already, by which object it is. A material's own equality does
35
+ // not look at its name or its draw side, nor a geometry's at its name or its tree, and a dictionary would
36
+ // write one of two such as a reference to the other
37
+ const ready = serializer.initialize({ adapterOptionsSupplier: () => adapter_options, dictionary: false });
38
+
39
+ if (!ready) {
40
+ throw new Error(`no adapter is registered for '${class_name}'`);
41
+ }
42
+
43
+ for (let i = 0; i < elements.length; i++) {
44
+ serializer.write(i, elements[i]);
45
+ }
46
+
47
+ serializer.finalize();
48
+ }
49
+
50
+ /**
51
+ * A model as an MTF package: a header, then six collections in the order each needs the ones before it.
52
+ *
53
+ * <pre>
54
+ * u32 magic {@link MTF_PACKAGE_MAGIC}
55
+ * u32 version {@link MTF_PACKAGE_VERSION}
56
+ * collection of {@link MTFTexture} one a texture the materials name
57
+ * collection of {@link StandardShadeMaterial} one a material the nodes draw with
58
+ * collection of {@link MeshletGeometry} one a geometry the nodes draw, with its tree
59
+ * collection of {@link SceneNode} the bundle's nodes, in their order
60
+ * collection of {@link Skin}
61
+ * collection of {@link ShadeAnimationClip}
62
+ * </pre>
63
+ *
64
+ * A collection is what {@link BinaryCollectionSerializer} writes: its class's name and version, a count, and each
65
+ * element by its adapter. The package holds no texels. A texture's record says where its files are
66
+ * (`texture_variants`), and whoever wrote those files is who knows.
67
+ *
68
+ * The bundle is read and not changed.
69
+ *
70
+ * @param {SceneBundle} bundle
71
+ * @param {Map<ShadeTexture, TextureVariantSet>} texture_variants for every texture of {@link mtf_bundle_textures},
72
+ * the encodings built for it and the URI of each, relative to where the package will be or absolute
73
+ * @returns {ArrayBuffer} the package
74
+ * @throws {Error} if a texture has no entry in `texture_variants`, a node draws with a material that is not a
75
+ * {@link StandardShadeMaterial} or a geometry whose meshlets are not in memory, or the bundle carries lights or
76
+ * foliage wind rigs
77
+ *
78
+ * @author Alex Goldring
79
+ * @copyright Company Named Limited (c) 2026
80
+ */
81
+ export function mtf_write(bundle, texture_variants) {
82
+ const nodes = bundle.nodes;
83
+
84
+ // what a bundle can carry and a package of this version cannot: said, rather than left out without a word
85
+ if (bundle.lights.length > 0) {
86
+ throw new Error(`the model carries ${bundle.lights.length} light(s), which an MTF package of version ${MTF_PACKAGE_VERSION} does not hold: take them off the bundle to write it without them`);
87
+ }
88
+
89
+ if (bundle.foliage_rigs.length > 0) {
90
+ throw new Error(`the model carries ${bundle.foliage_rigs.length} foliage wind rig(s), which an MTF package of version ${MTF_PACKAGE_VERSION} does not hold: take them off the bundle to write it without them`);
91
+ }
92
+
93
+ // in the order nodes first name them; a Set keeps that order
94
+ const geometry_set = new Set();
95
+ const material_set = new Set();
96
+
97
+ for (let i = 0; i < nodes.length; i++) {
98
+ const node = nodes[i];
99
+
100
+ if (node.geometry === null) {
101
+ continue;
102
+ }
103
+
104
+ const material = node.material;
105
+
106
+ if (material.isStandardShadeMaterial !== true) {
107
+ throw new Error(`node '${node.name}' draws with material '${material.name}', which is not a StandardShadeMaterial: an MTF package of version ${MTF_PACKAGE_VERSION} holds no other kind`);
108
+ }
109
+
110
+ const geometry = node.geometry;
111
+
112
+ if (geometry.meshlets.count === 0 && geometry.primitive_count > 0) {
113
+ // a geometry streamed in pages holds its meshlets elsewhere, and would be written as one that draws nothing
114
+ throw new Error(`node '${node.name}' draws geometry '${geometry.name}', whose ${geometry.primitive_count} triangles are not held in memory as meshlets: an MTF package of version ${MTF_PACKAGE_VERSION} holds a geometry whole`);
115
+ }
116
+
117
+ geometry_set.add(geometry);
118
+ material_set.add(material);
119
+ }
120
+
121
+ const geometries = Array.from(geometry_set);
122
+ const materials = Array.from(material_set);
123
+
124
+ /** @type {ShadeTexture[]} */
125
+ const textures = [];
126
+
127
+ /** @type {MTFTexture[]} */
128
+ const records = [];
129
+
130
+ for (const [texture, role] of mtf_bundle_textures(bundle)) {
131
+ const variants = texture_variants.get(texture);
132
+
133
+ if (variants === undefined) {
134
+ throw new Error(`texture '${texture.label}' has no files given for it: every texture a material names needs the set of its encodings`);
135
+ }
136
+
137
+ textures.push(texture);
138
+ records.push(MTFTexture.from(texture, role, variants));
139
+ }
140
+
141
+ const buffer = new BinaryBuffer();
142
+
143
+ buffer.writeUint32(MTF_PACKAGE_MAGIC);
144
+ buffer.writeUint32(MTF_PACKAGE_VERSION);
145
+
146
+ const serializer = new BinaryCollectionSerializer();
147
+
148
+ serializer.setRegistry(mtf_serialization_registry());
149
+ serializer.setBuffer(buffer);
150
+
151
+ write_collection(serializer, MTF_CLASS_TEXTURE, records, NO_OPTIONS);
152
+ write_collection(serializer, MTF_CLASS_MATERIAL, materials, [textures]);
153
+ write_collection(serializer, MTF_CLASS_GEOMETRY, geometries, NO_OPTIONS);
154
+ write_collection(serializer, MTF_CLASS_NODE, nodes, [geometries, materials]);
155
+ write_collection(serializer, MTF_CLASS_SKIN, bundle.skins, NO_OPTIONS);
156
+ write_collection(serializer, MTF_CLASS_CLIP, bundle.clips, NO_OPTIONS);
157
+
158
+ buffer.trim();
159
+
160
+ return buffer.data;
161
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * A {@link StandardShadeMaterial} on disk: the one spelling of it, which a SHADE scene and an MTF package both hold.
3
+ *
4
+ * <pre>
5
+ * UTF8 name
6
+ * u32 x 3 transparency_mode, draw_mode, draw_side
7
+ * u32 x 4 albedo, normal, occlusion-roughness-metalness, emissive: a texture's place in the list, or
8
+ * 0xFFFFFFFF for none
9
+ * f32 x 4 diffuse_color
10
+ * f32 x 2 roughness_factor, metallic_factor
11
+ * f32 x 4 emissive_factor
12
+ * f32 x 2 transmission_factor, ior_factor
13
+ * f32 x 2 ambient_factors: multiplier, offset
14
+ * </pre>
15
+ *
16
+ * A material names its textures by their place in a list, so the list is given before the first material is
17
+ * written or read ({@link initialize}): the textures being written beside the materials, in the order they are
18
+ * written, or the textures already read. {@link StandardShadeMaterial.medium} and
19
+ * {@link StandardShadeMaterial.vt_stack} are not written.
20
+ *
21
+ * @extends BinaryClassSerializationAdapter<StandardShadeMaterial>
22
+ *
23
+ * @author Alex Goldring
24
+ * @copyright Company Named Limited (c) 2026
25
+ */
26
+ export class StandardShadeMaterialSerializationAdapter extends BinaryClassSerializationAdapter<StandardShadeMaterial> {
27
+ constructor();
28
+ klass: typeof StandardShadeMaterial;
29
+ /**
30
+ * @param {ShadeTexture[]} textures what a material's texture indices are places in
31
+ */
32
+ initialize(textures: ShadeTexture[]): void;
33
+ #private;
34
+ }
35
+ export type BinaryBuffer = import("../../../core/binary/BinaryBuffer.js").BinaryBuffer;
36
+ export type ShadeTexture = import("../texture/ShadeTexture.js").ShadeTexture;
37
+ import { StandardShadeMaterial } from "./StandardShadeMaterial.js";
38
+ import { BinaryClassSerializationAdapter } from "../../../engine/ecs/storage/binary/BinaryClassSerializationAdapter.js";
39
+ //# sourceMappingURL=StandardShadeMaterialSerializationAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardShadeMaterialSerializationAdapter.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/material/StandardShadeMaterialSerializationAdapter.js"],"names":[],"mappings":"AA+DA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH;;IACI,oCAA8B;IAc9B;;OAEG;IACH,qBAFW,YAAY,EAAE,QAYxB;;CA0FJ;2BA1MY,OAAO,sCAAsC,EAAE,YAAY;2BAC3D,OAAO,4BAA4B,EAAE,YAAY;sCAJxB,4BAA4B;gDADlB,uEAAuE"}