@driftengine/assets 4.8.2 → 4.8.4

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 (50) hide show
  1. package/README.md +1 -1
  2. package/dist/bc7Decode.d.ts +33 -0
  3. package/dist/bc7Decode.js +197 -0
  4. package/dist/bcAnswer.d.ts +28 -0
  5. package/dist/bcAnswer.js +15 -0
  6. package/dist/bcDecode.d.ts +28 -0
  7. package/dist/bcDecode.js +175 -0
  8. package/dist/bcFlip.d.ts +21 -0
  9. package/dist/bcFlip.js +52 -0
  10. package/dist/bcImage.d.ts +15 -0
  11. package/dist/bcImage.js +38 -0
  12. package/dist/bcLoad.d.ts +26 -0
  13. package/dist/bcLoad.js +113 -0
  14. package/dist/bcWorker.d.ts +1 -0
  15. package/dist/bcWorker.js +14 -0
  16. package/dist/dds.d.ts +16 -18
  17. package/dist/dds.js +20 -293
  18. package/dist/ddsBlocks.d.ts +3 -0
  19. package/dist/ddsBlocks.js +54 -0
  20. package/dist/ddsHeader.d.ts +32 -0
  21. package/dist/ddsHeader.js +119 -0
  22. package/dist/drftLoader.d.ts +18 -0
  23. package/dist/drftLoader.js +98 -8
  24. package/dist/fbx.js +32 -13
  25. package/dist/fbxRig.d.ts +0 -18
  26. package/dist/fbxRig.js +0 -37
  27. package/dist/gltf.js +74 -12
  28. package/dist/index.d.ts +4 -0
  29. package/dist/index.js +7 -2
  30. package/dist/influences.d.ts +40 -0
  31. package/dist/influences.js +53 -0
  32. package/dist/weld.js +3 -0
  33. package/package.json +4 -4
  34. package/src/bc7Decode.ts +237 -0
  35. package/src/bcAnswer.ts +45 -0
  36. package/src/bcDecode.ts +218 -0
  37. package/src/bcFlip.ts +55 -0
  38. package/src/bcImage.ts +58 -0
  39. package/src/bcLoad.ts +154 -0
  40. package/src/bcWorker.ts +20 -0
  41. package/src/dds.ts +21 -337
  42. package/src/ddsBlocks.ts +63 -0
  43. package/src/ddsHeader.ts +160 -0
  44. package/src/drftLoader.ts +115 -9
  45. package/src/fbx.ts +34 -18
  46. package/src/fbxRig.ts +0 -41
  47. package/src/gltf.ts +75 -13
  48. package/src/index.ts +7 -2
  49. package/src/influences.ts +77 -0
  50. package/src/weld.ts +3 -0
package/src/index.ts CHANGED
@@ -235,11 +235,16 @@ export type { Localised } from './localise.ts';
235
235
  */
236
236
  export { colliderBeside, levelsBeside } from './readModel.ts';
237
237
  /*
238
- * DDS block decoding, for the block-compressed textures a vehicle model carries. Baker work: RGBA
239
- * is larger than the source and nothing ships a block decoder into a frame.
238
+ * DDS for the baker: `ddsBlocks` keeps a block-compressed surface's blocks and stored chain for a
239
+ * `CODEC_BC` texture, and `ddsToRgba` decodes level 0 for what cannot be kept. `decodeBc` is the
240
+ * block decoder both share with the loader, which runs it on a device that cannot sample BC.
240
241
  */
241
242
  export { ddsToRgba, isDds } from './dds.ts';
242
243
  export type { DdsImage } from './dds.ts';
244
+ export { ddsBlocks } from './ddsBlocks.ts';
245
+ export { decodeBc } from './bcDecode.ts';
246
+ export { decodeBcImage } from './bcImage.ts';
247
+ export { flipBc5Green } from './bcFlip.ts';
243
248
  /*
244
249
  * **The offline half of the GPU-driven pipeline, which nothing outside this package could reach.**
245
250
  *
@@ -0,0 +1,77 @@
1
+ /**
2
+ * A vertex's joint influences, sorted, cut to eight and normalised into the two sets a mesh carries.
3
+ *
4
+ * **Eight and not four, since 4.8.4.** A rig authored for eight — a face, a shoulder, a hand — loses
5
+ * the shape of its deformation when the four lightest are dropped, and both importers dropped them.
6
+ * Heaviest first is the contract the format relies on: the first set always holds the four that
7
+ * matter most, so a renderer or an older pipeline reading only that set keeps the best four, and
8
+ * the second set holds what is left. Shared by the glTF and FBX readers so both cut and order the
9
+ * same way.
10
+ *
11
+ * **What it gives up** is anything past eight, renormalised over what is kept, as four was before.
12
+ * Runs at import, off the frame, so it allocates where that is clearer.
13
+ */
14
+
15
+ /** One joint and how much of a vertex it moves. */
16
+ export interface Influence {
17
+ readonly joint: number;
18
+ readonly weight: number;
19
+ }
20
+
21
+ /** The four arrays a mesh's influences land in, four floats per vertex each. */
22
+ export interface InfluenceSets {
23
+ readonly joints: Float32Array;
24
+ readonly weights: Float32Array;
25
+ readonly joints2: Float32Array;
26
+ readonly weights2: Float32Array;
27
+ }
28
+
29
+ /** What a vertex's influences needed: dropping past eight, rescaling, and a second set at all. */
30
+ export interface InfluenceReport {
31
+ readonly dropped: boolean;
32
+ readonly rescaled: boolean;
33
+ readonly second: boolean;
34
+ }
35
+
36
+ /** The most influences a vertex keeps: two sets of four. */
37
+ export const MAX_INFLUENCES = 8;
38
+
39
+ const NONE: InfluenceReport = Object.freeze({ dropped: false, rescaled: false, second: false });
40
+
41
+ /**
42
+ * Write vertex `at`'s influences into `out`, heaviest first: the four heaviest into `joints` and
43
+ * `weights`, the next four into `joints2` and `weights2`, normalised to sum to one over all kept.
44
+ * A vertex with no positive weight is left all zero and reported as nothing, because inventing an
45
+ * influence would move geometry nobody rigged.
46
+ */
47
+ export function writeInfluences(
48
+ influences: readonly Influence[] | undefined,
49
+ out: InfluenceSets,
50
+ at: number,
51
+ ): InfluenceReport {
52
+ if (influences === undefined || influences.length === 0) return NONE;
53
+ /* Stable, so equal weights keep the order they arrived in: set 0 before set 1. */
54
+ const sorted = influences
55
+ .map((influence, order) => ({ ...influence, order }))
56
+ .filter((influence) => influence.weight > 0)
57
+ .sort((a, b) => b.weight - a.weight || a.order - b.order);
58
+ const kept = sorted.slice(0, MAX_INFLUENCES);
59
+ let sum = 0;
60
+ for (const influence of kept) sum += influence.weight;
61
+ if (sum <= 0) return NONE;
62
+ for (let i = 0; i < kept.length; i++) {
63
+ const influence = kept[i] as Influence;
64
+ const joints = i < 4 ? out.joints : out.joints2;
65
+ const weights = i < 4 ? out.weights : out.weights2;
66
+ joints[at * 4 + (i % 4)] = influence.joint;
67
+ weights[at * 4 + (i % 4)] = influence.weight / sum;
68
+ }
69
+ let total = 0;
70
+ for (const influence of sorted) total += influence.weight;
71
+ return {
72
+ dropped: sorted.length > MAX_INFLUENCES,
73
+ /* A tenth of a per cent, which is wider than float noise and narrower than an authoring slip. */
74
+ rescaled: Math.abs(total - 1) > 1e-3,
75
+ second: kept.length > 4,
76
+ };
77
+ }
package/src/weld.ts CHANGED
@@ -57,6 +57,9 @@ const ATTRIBUTES = {
57
57
  tangents: 4,
58
58
  joints: 4,
59
59
  weights: 4,
60
+ /* The fifth to eighth influences, which are per vertex like the first four. */
61
+ joints2: 4,
62
+ weights2: 4,
60
63
  /*
61
64
  * The four-lane per-vertex channel. It joins the key above as well as the copy below, which is
62
65
  * the behaviour that matters: two vertices at one position whose sway or sky exposure differ