@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,161 @@
1
+ import { assert } from "../../../../core/assert.js";
2
+ import { scene_optimize } from "../../scene/optimization/scene_optimize.js";
3
+ import { mtf_bundle_textures } from "./mtf_bundle_textures.js";
4
+ import { mtf_encode_texture } from "./mtf_encode_texture.js";
5
+ import { mtf_write } from "./mtf_write.js";
6
+
7
+ /**
8
+ * @typedef {import("../SceneBundle.js").SceneBundle} SceneBundle
9
+ * @typedef {import("../../texture/ShadeTexture.js").ShadeTexture} ShadeTexture
10
+ * @typedef {import("../../texture/TextureVariantSet.js").TextureVariantSet} TextureVariantSet
11
+ * @typedef {import("./mtf_encode_texture.js").MTFTextureEncoder} MTFTextureEncoder
12
+ */
13
+
14
+ /**
15
+ * What a file name may hold wherever it ends up: a file system, a URL, a shell.
16
+ *
17
+ * @type {RegExp}
18
+ */
19
+ const UNSAFE_IN_A_FILE_NAME = /[^A-Za-z0-9._-]/g;
20
+
21
+ /**
22
+ * How much of a texture's label goes into its file name. A label can be a whole path, and a name is for telling
23
+ * files apart by eye: the number in front of it is what makes it unique.
24
+ *
25
+ * @type {number}
26
+ */
27
+ const LABEL_IN_A_FILE_NAME = 48;
28
+
29
+ /**
30
+ * @param {number} index
31
+ * @param {string} label
32
+ * @returns {string} a file name, without an extension, that no other index gets
33
+ */
34
+ function texture_file_stem(index, label) {
35
+ const number = String(index).padStart(4, "0");
36
+ const safe = label.replace(UNSAFE_IN_A_FILE_NAME, () => "_").substring(0, LABEL_IN_A_FILE_NAME);
37
+
38
+ return safe.length === 0 ? number : `${number}_${safe}`;
39
+ }
40
+
41
+ /**
42
+ * A model as the files of an MTF export: its package, and beside it a folder of the files its textures are in.
43
+ *
44
+ * <pre>
45
+ * &lt;name&gt;.mtf
46
+ * &lt;name&gt;_textures/0000_&lt;label&gt;.avif
47
+ * &lt;name&gt;_textures/0001_&lt;label&gt;.mtt
48
+ * ...
49
+ * </pre>
50
+ *
51
+ * The steps, in order:
52
+ *
53
+ * 1. With `optimize`, {@link scene_optimize} first: geometries that are alike become one, pieces that repeat are
54
+ * shared, and images that are the same pixels become one image. **It rewrites the bundle in place**, so the
55
+ * bundle is the caller's to give away. A model with skins is refused: the optimizer does not carry skinning.
56
+ * 2. The files of each texture are asked of `encode_texture`, once for each image a role is met with: textures
57
+ * over one image share its files.
58
+ * 3. {@link mtf_write}.
59
+ *
60
+ * Nothing is put anywhere. What comes back is the files by where they go relative to one another, and writing
61
+ * them out is the caller's.
62
+ *
63
+ * @param {object} options
64
+ * @param {SceneBundle} options.bundle
65
+ * @param {string} options.name what the package's file is called, without a folder or an extension
66
+ * @param {boolean} [options.optimize] whether to optimize the bundle before it is written
67
+ * @param {MTFTextureEncoder} [options.encode_texture] what builds a texture's files. The default builds a
68
+ * fallback and no block formats ({@link mtf_encode_texture})
69
+ * @returns {Promise<Map<string, ArrayBuffer>>} every file by its path, the package first. A texture's path is
70
+ * the URI the package names it by
71
+ *
72
+ * @author Alex Goldring
73
+ * @copyright Company Named Limited (c) 2026
74
+ */
75
+ export async function mtf_export({
76
+ bundle,
77
+ name,
78
+ optimize = false,
79
+ encode_texture = mtf_encode_texture,
80
+ }) {
81
+ assert.defined(bundle, 'bundle');
82
+ assert.equal(bundle.isSceneBundle, true, 'bundle.isSceneBundle !== true');
83
+ assert.isString(name, 'name');
84
+ if (name.length === 0 || name.includes("/") || name.includes("\\")) {
85
+ // not an assert: a texture's URI is built from the name and resolved against the package's own folder, so
86
+ // a name with a folder in it writes a package whose textures are not where it says
87
+ throw new Error(`the package's name is a file's name without a folder or an extension, got '${name}'`);
88
+ }
89
+
90
+ assert.isBoolean(optimize, 'optimize');
91
+ assert.isFunction(encode_texture, 'encode_texture');
92
+
93
+ if (optimize) {
94
+ if (bundle.skins.length > 0) {
95
+ // the optimizer rebuilds the pieces it shares without their joints and weights, and makes a node it
96
+ // splits a parent of pieces while its skin still names the node
97
+ throw new Error(`the model has ${bundle.skins.length} skin(s), and scene optimization does not carry skinning: export it as it is`);
98
+ }
99
+
100
+ scene_optimize(bundle);
101
+ }
102
+
103
+ /** @type {Map<string, ArrayBuffer>} */
104
+ const files = new Map();
105
+
106
+ const package_path = `${name}.mtf`;
107
+
108
+ // its place is the first; its bytes come last, when every texture's files are known
109
+ files.set(package_path, null);
110
+
111
+ /** @type {ShadeTexture[]} */
112
+ const textures = [];
113
+
114
+ /** @type {Promise<TextureVariantSet>[]} one a texture, shared by textures over one image in one role */
115
+ const encodings = [];
116
+
117
+ /** @type {Map<*, Map<number, Promise<TextureVariantSet>>>} image source, then role */
118
+ const encoded = new Map();
119
+
120
+ let file_count = 0;
121
+
122
+ for (const [texture, role] of mtf_bundle_textures(bundle)) {
123
+ const source = texture.image.source;
124
+
125
+ let by_role = encoded.get(source);
126
+
127
+ if (by_role === undefined) {
128
+ by_role = new Map();
129
+
130
+ encoded.set(source, by_role);
131
+ }
132
+
133
+ let encoding = by_role.get(role);
134
+
135
+ if (encoding === undefined) {
136
+ const stem = `${name}_textures/${texture_file_stem(file_count, texture.label)}`;
137
+
138
+ file_count++;
139
+
140
+ encoding = encode_texture(texture, role, stem, files);
141
+
142
+ by_role.set(role, encoding);
143
+ }
144
+
145
+ textures.push(texture);
146
+ encodings.push(encoding);
147
+ }
148
+
149
+ const variant_sets = await Promise.all(encodings);
150
+
151
+ /** @type {Map<ShadeTexture, TextureVariantSet>} */
152
+ const texture_variants = new Map();
153
+
154
+ for (let i = 0; i < textures.length; i++) {
155
+ texture_variants.set(textures[i], variant_sets[i]);
156
+ }
157
+
158
+ files.set(package_path, mtf_write(bundle, texture_variants));
159
+
160
+ return files;
161
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Whether bytes are an MTF texture file, by how they open. What a texture's fallback is — a texture file or an
3
+ * image — is told this way and not from its URI.
4
+ *
5
+ * @param {ArrayBuffer} data
6
+ * @returns {boolean}
7
+ */
8
+ export function mtf_is_texture(data: ArrayBuffer): boolean;
9
+ //# sourceMappingURL=mtf_is_texture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mtf_is_texture.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/loader/mtf/mtf_is_texture.js"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,qCAHW,WAAW,GACT,OAAO,CAInB"}
@@ -0,0 +1,12 @@
1
+ import { MTF_TEXTURE_MAGIC } from "./MTF_TEXTURE_MAGIC.js";
2
+
3
+ /**
4
+ * Whether bytes are an MTF texture file, by how they open. What a texture's fallback is — a texture file or an
5
+ * image — is told this way and not from its URI.
6
+ *
7
+ * @param {ArrayBuffer} data
8
+ * @returns {boolean}
9
+ */
10
+ export function mtf_is_texture(data) {
11
+ return data.byteLength >= 4 && new DataView(data).getUint32(0, true) === MTF_TEXTURE_MAGIC;
12
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @typedef {import("../../../../core/binary/BinaryBuffer.js").BinaryBuffer} BinaryBuffer
3
+ * @typedef {import("../../../../engine/ecs/storage/binary/BinarySerializationRegistry.js").BinarySerializationRegistry} BinarySerializationRegistry
4
+ * @typedef {import("../../../../engine/ecs/storage/binary/collection/BinaryCollectionDeSerializer.js").BinaryCollectionDeSerializer} BinaryCollectionDeSerializer
5
+ */
6
+ /**
7
+ * Read the collection at the deserializer's buffer position, which a package holds as its next one, and append
8
+ * its elements to `out` in the order they were written.
9
+ *
10
+ * A collection written at an earlier version of its class is brought up to this one by the registry's upgraders,
11
+ * element by element; one written at a later version is refused by the deserializer.
12
+ *
13
+ * @template T
14
+ * @param {BinaryCollectionDeSerializer} deserializer with its registry and buffer set
15
+ * @param {string} class_name what a package holds at this point
16
+ * @param {Array} adapter_options what the class's adapter is initialized with
17
+ * @param {T[]} out
18
+ * @throws {Error} if the collection is of another class
19
+ */
20
+ export function mtf_read_collection<T>(deserializer: BinaryCollectionDeSerializer, class_name: string, adapter_options: any[], out: T[]): void;
21
+ export type BinaryBuffer = import("../../../../core/binary/BinaryBuffer.js").BinaryBuffer;
22
+ export type BinarySerializationRegistry = import("../../../../engine/ecs/storage/binary/BinarySerializationRegistry.js").BinarySerializationRegistry;
23
+ export type BinaryCollectionDeSerializer = import("../../../../engine/ecs/storage/binary/collection/BinaryCollectionDeSerializer.js").BinaryCollectionDeSerializer;
24
+ //# sourceMappingURL=mtf_read_collection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mtf_read_collection.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/loader/mtf/mtf_read_collection.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;GAaG;AACH,qDANW,4BAA4B,cAC5B,MAAM,0CAqBhB;2BAnCY,OAAO,yCAAyC,EAAE,YAAY;0CAC9D,OAAO,sEAAsE,EAAE,2BAA2B;2CAC1G,OAAO,kFAAkF,EAAE,4BAA4B"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @typedef {import("../../../../core/binary/BinaryBuffer.js").BinaryBuffer} BinaryBuffer
3
+ * @typedef {import("../../../../engine/ecs/storage/binary/BinarySerializationRegistry.js").BinarySerializationRegistry} BinarySerializationRegistry
4
+ * @typedef {import("../../../../engine/ecs/storage/binary/collection/BinaryCollectionDeSerializer.js").BinaryCollectionDeSerializer} BinaryCollectionDeSerializer
5
+ */
6
+
7
+ /**
8
+ * Read the collection at the deserializer's buffer position, which a package holds as its next one, and append
9
+ * its elements to `out` in the order they were written.
10
+ *
11
+ * A collection written at an earlier version of its class is brought up to this one by the registry's upgraders,
12
+ * element by element; one written at a later version is refused by the deserializer.
13
+ *
14
+ * @template T
15
+ * @param {BinaryCollectionDeSerializer} deserializer with its registry and buffer set
16
+ * @param {string} class_name what a package holds at this point
17
+ * @param {Array} adapter_options what the class's adapter is initialized with
18
+ * @param {T[]} out
19
+ * @throws {Error} if the collection is of another class
20
+ */
21
+ export function mtf_read_collection(deserializer, class_name, adapter_options, out) {
22
+ const expected = deserializer.getRegistry().getAdapter(class_name);
23
+
24
+ deserializer.initialize({ adapterOptionsSupplier: () => adapter_options });
25
+
26
+ if (deserializer.getElementClass() !== expected.klass) {
27
+ throw new Error(`the MTF package holds a collection of another class where its '${class_name}' are due`);
28
+ }
29
+
30
+ const count = deserializer.getElementCount();
31
+
32
+ for (let i = 0; i < count; i++) {
33
+ out.push(deserializer.read().value);
34
+ }
35
+
36
+ deserializer.finalize();
37
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The second half of reading an MTF package: its materials, geometries, nodes, skins and clips, as the bundle
3
+ * every loader produces.
4
+ *
5
+ * A geometry or a material several nodes draw is one object in the bundle, as it is one record in the package.
6
+ * Nothing is built: a geometry comes back with the tree it was written with, and a clip with its curves as they
7
+ * were.
8
+ *
9
+ * Every refusal is a thrown error and none is an assert: a file is outside data.
10
+ *
11
+ * @param {BinaryBuffer} buffer where {@link mtf_read_textures} left it
12
+ * @param {ShadeTexture[]} textures one for each record {@link mtf_read_textures} returned, in that order
13
+ * @returns {SceneBundle}
14
+ * @throws {Error} if a record names something the package does not hold, a node comes before its parent, or
15
+ * bytes follow the last collection
16
+ *
17
+ * @author Alex Goldring
18
+ * @copyright Company Named Limited (c) 2026
19
+ */
20
+ export function mtf_read_scene(buffer: BinaryBuffer, textures: ShadeTexture[]): SceneBundle;
21
+ export type BinaryBuffer = import("../../../../core/binary/BinaryBuffer.js").BinaryBuffer;
22
+ export type ShadeTexture = import("../../texture/ShadeTexture.js").ShadeTexture;
23
+ export type StandardShadeMaterial = import("../../material/StandardShadeMaterial.js").StandardShadeMaterial;
24
+ export type MeshletGeometry = import("../../geometry/MeshletGeometry.js").MeshletGeometry;
25
+ export type SceneNode = import("../SceneNode.js").SceneNode;
26
+ import { SceneBundle } from "../SceneBundle.js";
27
+ //# sourceMappingURL=mtf_read_scene.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mtf_read_scene.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/loader/mtf/mtf_read_scene.js"],"names":[],"mappings":"AAqCA;;;;;;;;;;;;;;;;;;GAkBG;AACH,uCATW,YAAY,YACZ,YAAY,EAAE,GACZ,WAAW,CAuEvB;2BA3GY,OAAO,yCAAyC,EAAE,YAAY;2BAC9D,OAAO,+BAA+B,EAAE,YAAY;oCACpD,OAAO,yCAAyC,EAAE,qBAAqB;8BACvE,OAAO,mCAAmC,EAAE,eAAe;wBAC3D,OAAO,iBAAiB,EAAE,SAAS;4BAhBpB,mBAAmB"}
@@ -0,0 +1,121 @@
1
+ import { BinaryCollectionDeSerializer } from "../../../../engine/ecs/storage/binary/collection/BinaryCollectionDeSerializer.js";
2
+ import { SceneBundle } from "../SceneBundle.js";
3
+ import { mtf_read_collection } from "./mtf_read_collection.js";
4
+ import {
5
+ MTF_CLASS_CLIP,
6
+ MTF_CLASS_GEOMETRY,
7
+ MTF_CLASS_MATERIAL,
8
+ MTF_CLASS_NODE,
9
+ MTF_CLASS_SKIN,
10
+ mtf_serialization_registry
11
+ } from "./mtf_serialization_registry.js";
12
+
13
+ /**
14
+ * @typedef {import("../../../../core/binary/BinaryBuffer.js").BinaryBuffer} BinaryBuffer
15
+ * @typedef {import("../../texture/ShadeTexture.js").ShadeTexture} ShadeTexture
16
+ * @typedef {import("../../material/StandardShadeMaterial.js").StandardShadeMaterial} StandardShadeMaterial
17
+ * @typedef {import("../../geometry/MeshletGeometry.js").MeshletGeometry} MeshletGeometry
18
+ * @typedef {import("../SceneNode.js").SceneNode} SceneNode
19
+ */
20
+
21
+ const NO_OPTIONS = [];
22
+
23
+ /**
24
+ * @param {string} owner what names the nodes, for the refusal
25
+ * @param {number[]} indices
26
+ * @param {number} node_count
27
+ */
28
+ function check_node_indices(owner, indices, node_count) {
29
+ for (let i = 0; i < indices.length; i++) {
30
+ const index = indices[i];
31
+
32
+ if (index >= node_count) {
33
+ throw new Error(`${owner} names node ${index}, and the MTF package holds ${node_count}`);
34
+ }
35
+ }
36
+ }
37
+
38
+ /**
39
+ * The second half of reading an MTF package: its materials, geometries, nodes, skins and clips, as the bundle
40
+ * every loader produces.
41
+ *
42
+ * A geometry or a material several nodes draw is one object in the bundle, as it is one record in the package.
43
+ * Nothing is built: a geometry comes back with the tree it was written with, and a clip with its curves as they
44
+ * were.
45
+ *
46
+ * Every refusal is a thrown error and none is an assert: a file is outside data.
47
+ *
48
+ * @param {BinaryBuffer} buffer where {@link mtf_read_textures} left it
49
+ * @param {ShadeTexture[]} textures one for each record {@link mtf_read_textures} returned, in that order
50
+ * @returns {SceneBundle}
51
+ * @throws {Error} if a record names something the package does not hold, a node comes before its parent, or
52
+ * bytes follow the last collection
53
+ *
54
+ * @author Alex Goldring
55
+ * @copyright Company Named Limited (c) 2026
56
+ */
57
+ export function mtf_read_scene(buffer, textures) {
58
+ const deserializer = new BinaryCollectionDeSerializer();
59
+
60
+ deserializer.setRegistry(mtf_serialization_registry());
61
+ deserializer.setBuffer(buffer);
62
+
63
+ /** @type {StandardShadeMaterial[]} */
64
+ const materials = [];
65
+
66
+ /** @type {MeshletGeometry[]} */
67
+ const geometries = [];
68
+
69
+ /** @type {SceneNode[]} */
70
+ const nodes = [];
71
+
72
+ mtf_read_collection(deserializer, MTF_CLASS_MATERIAL, [textures], materials);
73
+ mtf_read_collection(deserializer, MTF_CLASS_GEOMETRY, NO_OPTIONS, geometries);
74
+ mtf_read_collection(deserializer, MTF_CLASS_NODE, [geometries, materials], nodes);
75
+
76
+ const bundle = new SceneBundle();
77
+ const node_count = nodes.length;
78
+
79
+ for (let i = 0; i < node_count; i++) {
80
+ const node = nodes[i];
81
+
82
+ // pre-order is what lets every reader of a bundle compose worlds in one forward pass
83
+ if (node.parent < -1 || node.parent >= i) {
84
+ throw new Error(`node ${i} '${node.name}' of the MTF package names parent ${node.parent}: a parent comes before its children`);
85
+ }
86
+
87
+ bundle.add_node(node);
88
+ }
89
+
90
+ const skins = bundle.skins;
91
+ const clips = bundle.clips;
92
+
93
+ mtf_read_collection(deserializer, MTF_CLASS_SKIN, NO_OPTIONS, skins);
94
+ mtf_read_collection(deserializer, MTF_CLASS_CLIP, NO_OPTIONS, clips);
95
+
96
+ for (let i = 0; i < skins.length; i++) {
97
+ const skin = skins[i];
98
+
99
+ check_node_indices(`skin '${skin.name}'`, skin.joints, node_count);
100
+ check_node_indices(`skin '${skin.name}'`, skin.meshes, node_count);
101
+ }
102
+
103
+ for (let i = 0; i < clips.length; i++) {
104
+ const clip = clips[i];
105
+ const channels = clip.channels;
106
+
107
+ for (let c = 0; c < channels.length; c++) {
108
+ const target = channels[c].target;
109
+
110
+ if (target >= node_count) {
111
+ throw new Error(`clip '${clip.name}' names node ${target}, and the MTF package holds ${node_count}`);
112
+ }
113
+ }
114
+ }
115
+
116
+ if (buffer.position !== buffer.capacity) {
117
+ throw new Error(`the MTF package holds ${buffer.capacity - buffer.position} bytes after its last collection`);
118
+ }
119
+
120
+ return bundle;
121
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The first half of reading an MTF package: its header and its texture records.
3
+ *
4
+ * A package holds no texels, so between this and {@link mtf_read_scene} somebody fetches them: a record says
5
+ * which encodings exist and where, the caller picks one for its device and makes a texture of what arrives, and
6
+ * the second half is given those textures in the order of these records.
7
+ *
8
+ * @param {BinaryBuffer} buffer at the start of a package; left at the start of what {@link mtf_read_scene} reads
9
+ * @returns {MTFTexture[]} in the order materials name them by
10
+ * @throws {Error} if the bytes are not a package, or are of a version newer than {@link MTF_PACKAGE_VERSION}
11
+ *
12
+ * @author Alex Goldring
13
+ * @copyright Company Named Limited (c) 2026
14
+ */
15
+ export function mtf_read_textures(buffer: BinaryBuffer): MTFTexture[];
16
+ export type BinaryBuffer = import("../../../../core/binary/BinaryBuffer.js").BinaryBuffer;
17
+ export type MTFTexture = import("./MTFTexture.js").MTFTexture;
18
+ //# sourceMappingURL=mtf_read_textures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mtf_read_textures.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/loader/mtf/mtf_read_textures.js"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;GAaG;AACH,0CAPW,YAAY,GACV,UAAU,EAAE,CA6BxB;2BA3CY,OAAO,yCAAyC,EAAE,YAAY;yBAC9D,OAAO,iBAAiB,EAAE,UAAU"}
@@ -0,0 +1,51 @@
1
+ import { BinaryCollectionDeSerializer } from "../../../../engine/ecs/storage/binary/collection/BinaryCollectionDeSerializer.js";
2
+ import { MTF_PACKAGE_MAGIC } from "./MTF_PACKAGE_MAGIC.js";
3
+ import { MTF_PACKAGE_VERSION } from "./MTF_PACKAGE_VERSION.js";
4
+ import { mtf_read_collection } from "./mtf_read_collection.js";
5
+ import { MTF_CLASS_TEXTURE, mtf_serialization_registry } from "./mtf_serialization_registry.js";
6
+
7
+ /**
8
+ * @typedef {import("../../../../core/binary/BinaryBuffer.js").BinaryBuffer} BinaryBuffer
9
+ * @typedef {import("./MTFTexture.js").MTFTexture} MTFTexture
10
+ */
11
+
12
+ const NO_OPTIONS = [];
13
+
14
+ /**
15
+ * The first half of reading an MTF package: its header and its texture records.
16
+ *
17
+ * A package holds no texels, so between this and {@link mtf_read_scene} somebody fetches them: a record says
18
+ * which encodings exist and where, the caller picks one for its device and makes a texture of what arrives, and
19
+ * the second half is given those textures in the order of these records.
20
+ *
21
+ * @param {BinaryBuffer} buffer at the start of a package; left at the start of what {@link mtf_read_scene} reads
22
+ * @returns {MTFTexture[]} in the order materials name them by
23
+ * @throws {Error} if the bytes are not a package, or are of a version newer than {@link MTF_PACKAGE_VERSION}
24
+ *
25
+ * @author Alex Goldring
26
+ * @copyright Company Named Limited (c) 2026
27
+ */
28
+ export function mtf_read_textures(buffer) {
29
+ // thrown, not asserted: a file is outside data, and a wrong one is refused with asserts stripped too
30
+ if (buffer.capacity - buffer.position < 8 || buffer.readUint32() !== MTF_PACKAGE_MAGIC) {
31
+ throw new Error("not an MTF package: it does not open with 'MTFP'");
32
+ }
33
+
34
+ const version = buffer.readUint32();
35
+
36
+ if (version > MTF_PACKAGE_VERSION) {
37
+ throw new Error(`an MTF package of version ${version}, newer than this engine reads (${MTF_PACKAGE_VERSION})`);
38
+ }
39
+
40
+ const deserializer = new BinaryCollectionDeSerializer();
41
+
42
+ deserializer.setRegistry(mtf_serialization_registry());
43
+ deserializer.setBuffer(buffer);
44
+
45
+ /** @type {MTFTexture[]} */
46
+ const records = [];
47
+
48
+ mtf_read_collection(deserializer, MTF_CLASS_TEXTURE, NO_OPTIONS, records);
49
+
50
+ return records;
51
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Where a file an MTF package names is: the URI as the package holds it, resolved against the package's own URL
3
+ * the way a browser resolves a link against the page it is on.
4
+ *
5
+ * The result has no `.` or `..` left in it wherever the package's URL allows, and that is the point of doing it
6
+ * here rather than leaving it to the fetch: a texture is shared by being asked for under one name. Two packages
7
+ * in different folders reach the same file by different relative URIs, and an asset manager that keyed on the
8
+ * unresolved forms would fetch it twice and hold two images.
9
+ *
10
+ * Characters are left as they are. Nothing is percent-encoded or decoded, so a path that names a file comes back
11
+ * as a path that names it.
12
+ *
13
+ * @param {string} uri relative to the package, from a root, or whole
14
+ * @param {string} package_url what the package was asked for by: a URL, or a path
15
+ * @returns {string}
16
+ *
17
+ * @author Alex Goldring
18
+ * @copyright Company Named Limited (c) 2026
19
+ */
20
+ export function mtf_resolve_uri(uri: string, package_url: string): string;
21
+ //# sourceMappingURL=mtf_resolve_uri.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mtf_resolve_uri.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/loader/mtf/mtf_resolve_uri.js"],"names":[],"mappings":"AAqBA;;;;;;;;;;;;;;;;;;GAkBG;AACH,qCAPW,MAAM,eACN,MAAM,GACJ,MAAM,CA8DlB"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * A URI that says where it is on its own: it opens with a scheme.
3
+ *
4
+ * @type {RegExp}
5
+ */
6
+ const HAS_SCHEME = /^[a-z][a-z0-9+.-]*:/i;
7
+
8
+ /**
9
+ * The part of a URL that is not path: a scheme and a host, or a host alone.
10
+ *
11
+ * @type {RegExp}
12
+ */
13
+ const AUTHORITY = /^(?:[a-z][a-z0-9+.-]*:)?\/\/[^/?#]*/i;
14
+
15
+ /**
16
+ * Where a path ends and a query or a fragment begins.
17
+ *
18
+ * @type {RegExp}
19
+ */
20
+ const AFTER_PATH = /[?#]/;
21
+
22
+ /**
23
+ * Where a file an MTF package names is: the URI as the package holds it, resolved against the package's own URL
24
+ * the way a browser resolves a link against the page it is on.
25
+ *
26
+ * The result has no `.` or `..` left in it wherever the package's URL allows, and that is the point of doing it
27
+ * here rather than leaving it to the fetch: a texture is shared by being asked for under one name. Two packages
28
+ * in different folders reach the same file by different relative URIs, and an asset manager that keyed on the
29
+ * unresolved forms would fetch it twice and hold two images.
30
+ *
31
+ * Characters are left as they are. Nothing is percent-encoded or decoded, so a path that names a file comes back
32
+ * as a path that names it.
33
+ *
34
+ * @param {string} uri relative to the package, from a root, or whole
35
+ * @param {string} package_url what the package was asked for by: a URL, or a path
36
+ * @returns {string}
37
+ *
38
+ * @author Alex Goldring
39
+ * @copyright Company Named Limited (c) 2026
40
+ */
41
+ export function mtf_resolve_uri(uri, package_url) {
42
+ if (HAS_SCHEME.test(uri) || uri.startsWith("//")) {
43
+ return uri;
44
+ }
45
+
46
+ const authority = AUTHORITY.exec(package_url);
47
+ const prefix = authority === null ? "" : authority[0];
48
+
49
+ if (uri.startsWith("/")) {
50
+ return prefix + uri;
51
+ }
52
+
53
+ let base_path = package_url.substring(prefix.length);
54
+
55
+ const base_end = base_path.search(AFTER_PATH);
56
+
57
+ if (base_end !== -1) {
58
+ base_path = base_path.substring(0, base_end);
59
+ }
60
+
61
+ const uri_end = uri.search(AFTER_PATH);
62
+ const uri_path = uri_end === -1 ? uri : uri.substring(0, uri_end);
63
+ const uri_rest = uri_end === -1 ? "" : uri.substring(uri_end);
64
+
65
+ const segments = base_path.split("/");
66
+
67
+ // the package's own name
68
+ segments.pop();
69
+
70
+ // a path from a root opens with an empty segment, which is the root: nothing climbs above it
71
+ const rooted = prefix.length > 0 || base_path.startsWith("/");
72
+ const floor = rooted && segments.length > 0 && segments[0] === "" ? 1 : 0;
73
+
74
+ const parts = uri_path.split("/");
75
+
76
+ for (let i = 0; i < parts.length; i++) {
77
+ const part = parts[i];
78
+
79
+ if (part === ".") {
80
+ continue;
81
+ }
82
+
83
+ if (part !== "..") {
84
+ segments.push(part);
85
+
86
+ continue;
87
+ }
88
+
89
+ if (segments.length > floor && segments[segments.length - 1] !== "..") {
90
+ segments.pop();
91
+ } else if (!rooted) {
92
+ // a relative path may be climbed out of: where that leads is whoever resolves it next to say
93
+ segments.push("..");
94
+ }
95
+ }
96
+
97
+ return prefix + segments.join("/") + uri_rest;
98
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The adapters an MTF package is written and read with, and the upgraders that bring a collection written at an
3
+ * earlier version of its class up to the one the adapter reads. A new registry a call: the adapters that resolve
4
+ * indices hold the lists they resolve against while a collection is being written or read.
5
+ *
6
+ * A class that gains a version registers its upgrader here, and every package ever written keeps reading.
7
+ *
8
+ * @returns {BinarySerializationRegistry}
9
+ *
10
+ * @author Alex Goldring
11
+ * @copyright Company Named Limited (c) 2026
12
+ */
13
+ export function mtf_serialization_registry(): BinarySerializationRegistry;
14
+ /**
15
+ * The names an MTF package's collections carry, in the order a package holds them. A name is what the file says
16
+ * its elements are, and what the reader finds their adapter and its upgraders by.
17
+ */
18
+ export const MTF_CLASS_TEXTURE: "MTFTexture";
19
+ export const MTF_CLASS_MATERIAL: "StandardShadeMaterial";
20
+ export const MTF_CLASS_GEOMETRY: "MeshletGeometry";
21
+ export const MTF_CLASS_NODE: "SceneNode";
22
+ export const MTF_CLASS_SKIN: "Skin";
23
+ export const MTF_CLASS_CLIP: "ShadeAnimationClip";
24
+ import { BinarySerializationRegistry } from "../../../../engine/ecs/storage/binary/BinarySerializationRegistry.js";
25
+ //# sourceMappingURL=mtf_serialization_registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mtf_serialization_registry.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/loader/mtf/mtf_serialization_registry.js"],"names":[],"mappings":"AAoBA;;;;;;;;;;;GAWG;AACH,8CALa,2BAA2B,CAuBvC;AAzCD;;;GAGG;AACH,6CAA8C;AAC9C,yDAA0D;AAC1D,mDAAoD;AACpD,yCAA0C;AAC1C,oCAAqC;AACrC,kDAAmD;4CAlBP,sEAAsE"}