@bitefoundry/retrieviewer 0.0.3 → 0.0.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 (254) hide show
  1. package/ASSET-PROVENANCE.md +6 -0
  2. package/ASSETS-LICENSE.md +2 -1
  3. package/ATTRIBUTION.md +6 -1
  4. package/COMFORT-ART.md +65 -0
  5. package/DESKTOP-PLATFORMS.md +6 -1
  6. package/PLUGIN.md +13 -10
  7. package/PREREQUISITES.md +95 -0
  8. package/PUPPY-MEMORY.md +102 -1
  9. package/README.ko.md +110 -0
  10. package/README.md +117 -59
  11. package/RELEASING.md +23 -12
  12. package/THIRD-PARTY-NOTICES.md +5 -3
  13. package/braille.mjs +35 -9
  14. package/examples/live.mjs +2 -2
  15. package/integrations/linux-overlay/overlay.py +2 -2
  16. package/integrations/macos-overlay/overlay.jxa +8 -6
  17. package/integrations/opencode/runtime.mjs +4 -4
  18. package/integrations/opencode/tui.tsx +1 -1
  19. package/integrations/windows-overlay/Overlay.cs +4 -4
  20. package/integrations/windows-overlay/protocol.mjs +11 -7
  21. package/package.json +34 -13
  22. package/puppy-comfort-sprites.mjs +25 -0
  23. package/puppy-companion-comfort-q5.bin.gz +0 -0
  24. package/puppy-companion-comfort.json +77 -0
  25. package/puppy-companion-life.mjs +49 -16
  26. package/puppy-companion-objects.mjs +12 -0
  27. package/puppy-frame-predictive.mjs +15 -9
  28. package/puppy-frame-store.mjs +2 -2
  29. package/puppy-paper-world.mjs +14 -0
  30. package/puppy-paper.mjs +65 -14
  31. package/retrieviewer-plugin.d.mts +1 -1
  32. package/retrieviewer-plugin.mjs +1 -1
  33. package/retrieviewer.d.mts +10 -4
  34. package/retrieviewer.mjs +20 -14
  35. package/locomotion-core.mjs +0 -21
  36. package/locomotion-puppy.animal +0 -0
  37. package/vendor/procedural-animals/package.json +0 -40
  38. package/vendor/procedural-animals/src/animal.js +0 -146
  39. package/vendor/procedural-animals/src/bake.js +0 -51
  40. package/vendor/procedural-animals/src/build.js +0 -81
  41. package/vendor/procedural-animals/src/core/build/coatKit.js +0 -121
  42. package/vendor/procedural-animals/src/core/build/featherCards.js +0 -189
  43. package/vendor/procedural-animals/src/core/build/finEdges.js +0 -85
  44. package/vendor/procedural-animals/src/core/build/furSlope.js +0 -115
  45. package/vendor/procedural-animals/src/core/build/mesh.js +0 -67
  46. package/vendor/procedural-animals/src/core/build/pipeline.js +0 -272
  47. package/vendor/procedural-animals/src/core/build/seams.js +0 -183
  48. package/vendor/procedural-animals/src/core/build/warp.js +0 -112
  49. package/vendor/procedural-animals/src/core/build/weights.js +0 -393
  50. package/vendor/procedural-animals/src/core/math/vec.js +0 -81
  51. package/vendor/procedural-animals/src/core/motion/actions.js +0 -800
  52. package/vendor/procedural-animals/src/core/motion/bird.js +0 -3063
  53. package/vendor/procedural-animals/src/core/motion/birdActions.js +0 -1059
  54. package/vendor/procedural-animals/src/core/motion/common.js +0 -158
  55. package/vendor/procedural-animals/src/core/motion/index.js +0 -22
  56. package/vendor/procedural-animals/src/core/motion/quadruped.js +0 -2875
  57. package/vendor/procedural-animals/src/core/motion/snake.js +0 -1594
  58. package/vendor/procedural-animals/src/core/motion/spider.js +0 -1810
  59. package/vendor/procedural-animals/src/core/motion/swimmer.js +0 -1047
  60. package/vendor/procedural-animals/src/core/motion/swimmerActions.js +0 -613
  61. package/vendor/procedural-animals/src/core/render/animalObject.js +0 -262
  62. package/vendor/procedural-animals/src/core/render/coatMaterial.js +0 -1301
  63. package/vendor/procedural-animals/src/core/render/dqs.js +0 -159
  64. package/vendor/procedural-animals/src/core/render/eyes.js +0 -676
  65. package/vendor/procedural-animals/src/core/render/membranes.js +0 -77
  66. package/vendor/procedural-animals/src/core/render/skeleton.js +0 -41
  67. package/vendor/procedural-animals/src/core/rig/bird.js +0 -327
  68. package/vendor/procedural-animals/src/core/rig/quadruped.js +0 -76
  69. package/vendor/procedural-animals/src/core/rig/rig.js +0 -79
  70. package/vendor/procedural-animals/src/core/rig/snake.js +0 -76
  71. package/vendor/procedural-animals/src/core/rig/spider.js +0 -110
  72. package/vendor/procedural-animals/src/core/rig/swimmer.js +0 -181
  73. package/vendor/procedural-animals/src/core/sdf/eyeSocket.js +0 -53
  74. package/vendor/procedural-animals/src/core/sdf/mesher.js +0 -238
  75. package/vendor/procedural-animals/src/core/sdf/sdf.js +0 -263
  76. package/vendor/procedural-animals/src/index.d.ts +0 -98
  77. package/vendor/procedural-animals/src/index.js +0 -29
  78. package/vendor/procedural-animals/src/registry.js +0 -48
  79. package/vendor/procedural-animals/src/species/bear/behaviour.js +0 -463
  80. package/vendor/procedural-animals/src/species/bear/claws.js +0 -147
  81. package/vendor/procedural-animals/src/species/bear/coat.js +0 -726
  82. package/vendor/procedural-animals/src/species/bear/index.js +0 -139
  83. package/vendor/procedural-animals/src/species/bear/motion.js +0 -112
  84. package/vendor/procedural-animals/src/species/bear/regions.js +0 -78
  85. package/vendor/procedural-animals/src/species/bear/rig.js +0 -112
  86. package/vendor/procedural-animals/src/species/bear/sculpt.js +0 -272
  87. package/vendor/procedural-animals/src/species/boar/behaviour.js +0 -335
  88. package/vendor/procedural-animals/src/species/boar/coat.js +0 -372
  89. package/vendor/procedural-animals/src/species/boar/index.js +0 -110
  90. package/vendor/procedural-animals/src/species/boar/motion.js +0 -85
  91. package/vendor/procedural-animals/src/species/boar/regions.js +0 -88
  92. package/vendor/procedural-animals/src/species/boar/rig.js +0 -111
  93. package/vendor/procedural-animals/src/species/boar/sculpt.js +0 -285
  94. package/vendor/procedural-animals/src/species/cat/behaviour.js +0 -559
  95. package/vendor/procedural-animals/src/species/cat/coat.js +0 -841
  96. package/vendor/procedural-animals/src/species/cat/index.js +0 -211
  97. package/vendor/procedural-animals/src/species/cat/motion.js +0 -101
  98. package/vendor/procedural-animals/src/species/cat/regions.js +0 -82
  99. package/vendor/procedural-animals/src/species/cat/rig.js +0 -100
  100. package/vendor/procedural-animals/src/species/cat/sculpt.js +0 -266
  101. package/vendor/procedural-animals/src/species/cat/whiskers.js +0 -110
  102. package/vendor/procedural-animals/src/species/cheetah/coat.js +0 -427
  103. package/vendor/procedural-animals/src/species/cheetah/index.js +0 -51
  104. package/vendor/procedural-animals/src/species/cheetah/joints.js +0 -3
  105. package/vendor/procedural-animals/src/species/cheetah/motion.js +0 -77
  106. package/vendor/procedural-animals/src/species/cheetah/regions.js +0 -95
  107. package/vendor/procedural-animals/src/species/cheetah/rig.js +0 -66
  108. package/vendor/procedural-animals/src/species/cheetah/sculpt.js +0 -158
  109. package/vendor/procedural-animals/src/species/chicken/coat.js +0 -313
  110. package/vendor/procedural-animals/src/species/chicken/coverts.js +0 -320
  111. package/vendor/procedural-animals/src/species/chicken/index.js +0 -110
  112. package/vendor/procedural-animals/src/species/chicken/motion.js +0 -177
  113. package/vendor/procedural-animals/src/species/chicken/regions.js +0 -66
  114. package/vendor/procedural-animals/src/species/chicken/rig.js +0 -144
  115. package/vendor/procedural-animals/src/species/chicken/sculpt.js +0 -389
  116. package/vendor/procedural-animals/src/species/chicken/wingLook.js +0 -66
  117. package/vendor/procedural-animals/src/species/chicken/wingStack.js +0 -124
  118. package/vendor/procedural-animals/src/species/cow/behaviour.js +0 -521
  119. package/vendor/procedural-animals/src/species/cow/coat.js +0 -465
  120. package/vendor/procedural-animals/src/species/cow/index.js +0 -118
  121. package/vendor/procedural-animals/src/species/cow/motion.js +0 -81
  122. package/vendor/procedural-animals/src/species/cow/regions.js +0 -98
  123. package/vendor/procedural-animals/src/species/cow/rig.js +0 -116
  124. package/vendor/procedural-animals/src/species/cow/sculpt.js +0 -339
  125. package/vendor/procedural-animals/src/species/crow/coat.js +0 -145
  126. package/vendor/procedural-animals/src/species/crow/index.js +0 -70
  127. package/vendor/procedural-animals/src/species/crow/joints.js +0 -3
  128. package/vendor/procedural-animals/src/species/crow/motion.js +0 -101
  129. package/vendor/procedural-animals/src/species/crow/regions.js +0 -50
  130. package/vendor/procedural-animals/src/species/crow/rig.js +0 -83
  131. package/vendor/procedural-animals/src/species/crow/sculpt.js +0 -118
  132. package/vendor/procedural-animals/src/species/deer/behaviour.js +0 -513
  133. package/vendor/procedural-animals/src/species/deer/coat.js +0 -391
  134. package/vendor/procedural-animals/src/species/deer/index.js +0 -106
  135. package/vendor/procedural-animals/src/species/deer/motion.js +0 -97
  136. package/vendor/procedural-animals/src/species/deer/regions.js +0 -60
  137. package/vendor/procedural-animals/src/species/deer/rig.js +0 -124
  138. package/vendor/procedural-animals/src/species/deer/sculpt.js +0 -297
  139. package/vendor/procedural-animals/src/species/dog/behaviour.js +0 -521
  140. package/vendor/procedural-animals/src/species/dog/coat.js +0 -495
  141. package/vendor/procedural-animals/src/species/dog/index.js +0 -144
  142. package/vendor/procedural-animals/src/species/dog/motion.js +0 -118
  143. package/vendor/procedural-animals/src/species/dog/regions.js +0 -61
  144. package/vendor/procedural-animals/src/species/dog/rig.js +0 -129
  145. package/vendor/procedural-animals/src/species/dog/sculpt.js +0 -246
  146. package/vendor/procedural-animals/src/species/eagle/coat.js +0 -250
  147. package/vendor/procedural-animals/src/species/eagle/index.js +0 -76
  148. package/vendor/procedural-animals/src/species/eagle/joints.js +0 -3
  149. package/vendor/procedural-animals/src/species/eagle/motion.js +0 -137
  150. package/vendor/procedural-animals/src/species/eagle/regions.js +0 -57
  151. package/vendor/procedural-animals/src/species/eagle/rig.js +0 -107
  152. package/vendor/procedural-animals/src/species/eagle/sculpt.js +0 -137
  153. package/vendor/procedural-animals/src/species/fish/coat.js +0 -271
  154. package/vendor/procedural-animals/src/species/fish/index.js +0 -88
  155. package/vendor/procedural-animals/src/species/fish/motion.js +0 -92
  156. package/vendor/procedural-animals/src/species/fish/regions.js +0 -27
  157. package/vendor/procedural-animals/src/species/fish/rig.js +0 -143
  158. package/vendor/procedural-animals/src/species/fish/sculpt.js +0 -214
  159. package/vendor/procedural-animals/src/species/fish/variants.js +0 -126
  160. package/vendor/procedural-animals/src/species/fox/behaviour.js +0 -314
  161. package/vendor/procedural-animals/src/species/fox/coat.js +0 -444
  162. package/vendor/procedural-animals/src/species/fox/index.js +0 -120
  163. package/vendor/procedural-animals/src/species/fox/motion.js +0 -81
  164. package/vendor/procedural-animals/src/species/fox/regions.js +0 -59
  165. package/vendor/procedural-animals/src/species/fox/rig.js +0 -91
  166. package/vendor/procedural-animals/src/species/fox/sculpt.js +0 -202
  167. package/vendor/procedural-animals/src/species/frog/behaviour.js +0 -590
  168. package/vendor/procedural-animals/src/species/frog/coat.js +0 -305
  169. package/vendor/procedural-animals/src/species/frog/index.js +0 -97
  170. package/vendor/procedural-animals/src/species/frog/motion.js +0 -69
  171. package/vendor/procedural-animals/src/species/frog/regions.js +0 -46
  172. package/vendor/procedural-animals/src/species/frog/rig.js +0 -156
  173. package/vendor/procedural-animals/src/species/frog/sculpt.js +0 -240
  174. package/vendor/procedural-animals/src/species/goat/behaviour.js +0 -509
  175. package/vendor/procedural-animals/src/species/goat/coat.js +0 -590
  176. package/vendor/procedural-animals/src/species/goat/index.js +0 -149
  177. package/vendor/procedural-animals/src/species/goat/motion.js +0 -95
  178. package/vendor/procedural-animals/src/species/goat/regions.js +0 -98
  179. package/vendor/procedural-animals/src/species/goat/rig.js +0 -181
  180. package/vendor/procedural-animals/src/species/goat/sculpt.js +0 -547
  181. package/vendor/procedural-animals/src/species/horse/coat.js +0 -361
  182. package/vendor/procedural-animals/src/species/horse/coatSeam.js +0 -122
  183. package/vendor/procedural-animals/src/species/horse/index.js +0 -80
  184. package/vendor/procedural-animals/src/species/horse/motion.js +0 -245
  185. package/vendor/procedural-animals/src/species/horse/regions.js +0 -60
  186. package/vendor/procedural-animals/src/species/horse/rig.js +0 -117
  187. package/vendor/procedural-animals/src/species/horse/sculpt.js +0 -316
  188. package/vendor/procedural-animals/src/species/horse/seamWeights.js +0 -272
  189. package/vendor/procedural-animals/src/species/lion/behaviour.js +0 -509
  190. package/vendor/procedural-animals/src/species/lion/coat.js +0 -1016
  191. package/vendor/procedural-animals/src/species/lion/index.js +0 -111
  192. package/vendor/procedural-animals/src/species/lion/motion.js +0 -87
  193. package/vendor/procedural-animals/src/species/lion/regions.js +0 -106
  194. package/vendor/procedural-animals/src/species/lion/rig.js +0 -110
  195. package/vendor/procedural-animals/src/species/lion/sculpt.js +0 -384
  196. package/vendor/procedural-animals/src/species/lion/whiskers.js +0 -132
  197. package/vendor/procedural-animals/src/species/pig/behaviour.js +0 -575
  198. package/vendor/procedural-animals/src/species/pig/coat.js +0 -730
  199. package/vendor/procedural-animals/src/species/pig/ears.js +0 -242
  200. package/vendor/procedural-animals/src/species/pig/index.js +0 -161
  201. package/vendor/procedural-animals/src/species/pig/motion.js +0 -105
  202. package/vendor/procedural-animals/src/species/pig/regions.js +0 -100
  203. package/vendor/procedural-animals/src/species/pig/rig.js +0 -152
  204. package/vendor/procedural-animals/src/species/pig/sculpt.js +0 -382
  205. package/vendor/procedural-animals/src/species/rabbit/behaviour.js +0 -605
  206. package/vendor/procedural-animals/src/species/rabbit/coat.js +0 -285
  207. package/vendor/procedural-animals/src/species/rabbit/index.js +0 -85
  208. package/vendor/procedural-animals/src/species/rabbit/motion.js +0 -85
  209. package/vendor/procedural-animals/src/species/rabbit/regions.js +0 -48
  210. package/vendor/procedural-animals/src/species/rabbit/rig.js +0 -99
  211. package/vendor/procedural-animals/src/species/rabbit/sculpt.js +0 -148
  212. package/vendor/procedural-animals/src/species/rat/behaviour.js +0 -539
  213. package/vendor/procedural-animals/src/species/rat/coat.js +0 -341
  214. package/vendor/procedural-animals/src/species/rat/index.js +0 -111
  215. package/vendor/procedural-animals/src/species/rat/motion.js +0 -90
  216. package/vendor/procedural-animals/src/species/rat/regions.js +0 -92
  217. package/vendor/procedural-animals/src/species/rat/rig.js +0 -112
  218. package/vendor/procedural-animals/src/species/rat/sculpt.js +0 -163
  219. package/vendor/procedural-animals/src/species/rat/whiskers.js +0 -119
  220. package/vendor/procedural-animals/src/species/shark/coat.js +0 -383
  221. package/vendor/procedural-animals/src/species/shark/index.js +0 -104
  222. package/vendor/procedural-animals/src/species/shark/motion.js +0 -69
  223. package/vendor/procedural-animals/src/species/shark/regions.js +0 -34
  224. package/vendor/procedural-animals/src/species/shark/rig.js +0 -194
  225. package/vendor/procedural-animals/src/species/shark/sculpt.js +0 -343
  226. package/vendor/procedural-animals/src/species/shark/variants.js +0 -105
  227. package/vendor/procedural-animals/src/species/sheep/behaviour.js +0 -522
  228. package/vendor/procedural-animals/src/species/sheep/coat.js +0 -529
  229. package/vendor/procedural-animals/src/species/sheep/index.js +0 -152
  230. package/vendor/procedural-animals/src/species/sheep/motion.js +0 -86
  231. package/vendor/procedural-animals/src/species/sheep/neck.js +0 -41
  232. package/vendor/procedural-animals/src/species/sheep/regions.js +0 -62
  233. package/vendor/procedural-animals/src/species/sheep/rig.js +0 -163
  234. package/vendor/procedural-animals/src/species/sheep/sculpt.js +0 -542
  235. package/vendor/procedural-animals/src/species/snake/coat.js +0 -315
  236. package/vendor/procedural-animals/src/species/snake/index.js +0 -73
  237. package/vendor/procedural-animals/src/species/snake/motion.js +0 -51
  238. package/vendor/procedural-animals/src/species/snake/regions.js +0 -51
  239. package/vendor/procedural-animals/src/species/snake/rig.js +0 -108
  240. package/vendor/procedural-animals/src/species/snake/sculpt.js +0 -122
  241. package/vendor/procedural-animals/src/species/spider/coat.js +0 -279
  242. package/vendor/procedural-animals/src/species/spider/index.js +0 -78
  243. package/vendor/procedural-animals/src/species/spider/motion.js +0 -72
  244. package/vendor/procedural-animals/src/species/spider/regions.js +0 -87
  245. package/vendor/procedural-animals/src/species/spider/rig.js +0 -118
  246. package/vendor/procedural-animals/src/species/spider/sculpt.js +0 -182
  247. package/vendor/procedural-animals/src/species/wolf/behaviour.js +0 -160
  248. package/vendor/procedural-animals/src/species/wolf/coat.js +0 -749
  249. package/vendor/procedural-animals/src/species/wolf/index.js +0 -107
  250. package/vendor/procedural-animals/src/species/wolf/motion.js +0 -80
  251. package/vendor/procedural-animals/src/species/wolf/regions.js +0 -57
  252. package/vendor/procedural-animals/src/species/wolf/rig.js +0 -87
  253. package/vendor/procedural-animals/src/species/wolf/sculpt.js +0 -339
  254. package/vendor/procedural-animals/src/worker.js +0 -29
@@ -1,393 +0,0 @@
1
- // Skin weights from the SDF sculpt.
2
- //
3
- // * Axial skin (spine, neck, tail) gets smooth chain weights from a soft arc-length coordinate
4
- // along the axial polyline, relaxed over the surface so it never jumps where the chain bends.
5
- // * Each limb's share is a harmonic field on the mesh between two cores: the limb below its
6
- // proximal joint (1) and body skin clearly away from it (0). The whole hip or shoulder blends, so
7
- // the stretch of a swinging leg spreads over a wide region instead of creasing at the outline.
8
- // Inside the limb, bones blend by SDF distance to their primitives; thin distal joints blend
9
- // narrowly.
10
- // * Appendages (ears, horns...) blend by SDF distance; rigid parts (a separately meshed jaw) take
11
- // one bone.
12
- // All distances scale with rig.unit (1 = cheetah-sized).
13
- import { SDFModel } from '../sdf/sdf.js';
14
- import { sub, dot, len, clamp, smoothstep } from '../math/vec.js';
15
-
16
- export function buildNeighbors(index, nV) {
17
- const sets = new Array(nV);
18
- for (let i = 0; i < index.length; i += 3) {
19
- const a = index[i], b = index[i + 1], c = index[i + 2];
20
- (sets[a] ||= new Set()).add(b).add(c);
21
- (sets[b] ||= new Set()).add(a).add(c);
22
- (sets[c] ||= new Set()).add(a).add(b);
23
- }
24
- return Array.from(sets, (s) => (s ? [...s] : []));
25
- }
26
-
27
- export function axialLengths(rig) {
28
- const P = rig.AXIAL.points;
29
- const L = [0];
30
- for (let i = 0; i < P.length - 1; i++) L.push(L[i] + len(sub(P[i + 1], P[i])));
31
- return L;
32
- }
33
-
34
- // Nearest-segment projection onto the axial polyline, plus a *soft* arc-length coordinate: where the
35
- // polyline bends, points below the bend are nearly equidistant from two segments and the hard
36
- // projection would jump by centimetres.
37
- function makeProjector(rig) {
38
- const pts = rig.AXIAL.points;
39
- const AXP = pts.flat();
40
- const AXL = axialLengths(rig);
41
- const n = pts.length - 1;
42
- const soft = 0.018 * rig.unit;
43
- const ds = new Float64Array(n), ss = new Float64Array(n);
44
- return (px, py, pz) => {
45
- let best = 1e9, bi = 0, bt = 0;
46
- for (let i = 0; i < n; i++) {
47
- const ax = AXP[i * 3], ay = AXP[i * 3 + 1], az = AXP[i * 3 + 2];
48
- const bx = AXP[i * 3 + 3] - ax, by = AXP[i * 3 + 4] - ay, bz = AXP[i * 3 + 5] - az;
49
- let t = ((px - ax) * bx + (py - ay) * by + (pz - az) * bz) / (bx * bx + by * by + bz * bz);
50
- t = t < 0 ? 0 : t > 1 ? 1 : t;
51
- const dx = px - ax - bx * t, dy = py - ay - by * t, dz = pz - az - bz * t;
52
- const d = dx * dx + dy * dy + dz * dz;
53
- ds[i] = Math.sqrt(d);
54
- ss[i] = AXL[i] + t * (AXL[i + 1] - AXL[i]);
55
- if (d < best) { best = d; bi = i; bt = t; }
56
- }
57
- const dmin = Math.sqrt(best);
58
- let sw = 0, s = 0;
59
- for (let i = 0; i < n; i++) {
60
- const w = Math.exp(-(ds[i] - dmin) / soft);
61
- if (w < 1e-4) continue;
62
- sw += w;
63
- s += w * ss[i];
64
- }
65
- return { seg: bi, t: bt, d: dmin, s: s / sw };
66
- };
67
- }
68
-
69
- // d: the vertex's depth on the ventral side of the axial chain. A blend override [a, b, lever] widens
70
- // by lever x d on both sides: ventral skin far from the axis (a horse's throat under the jaw) swings
71
- // further for the same joint angle, so it needs a proportionally longer blend to spread the stretch.
72
- //
73
- // By default a vertex blends only across the two joints of the segment it projects on, so a blend that
74
- // reaches past the next joint (a long throat lever) is cut there: the skull's share drops from ~0.2-0.4
75
- // to 0 across the mid-neck joint, and the neck creases along that line whenever the head pitches or turns.
76
- // The weighting is a cascade: with a_j the share of the chain past joint j (its smoothstep), bone k takes
77
- // a_1 ... a_k (1 - a_(k+1)), where the default clamps a_j to 1 once s is past joint j + 1 and to 0 before
78
- // joint j - 1 (the cut). `axial.cascade` (opt-in) lets the blends of the joints listed run on into the next
79
- // segment on either side and fade out there instead: `{ j: fade }` fades joint j's blend out over `fade` x
80
- // rig.unit metres past joint j + 1 (to 1) and before joint j - 1 (to 0), at most the whole segment; an array
81
- // of joint indices (or true for all) fades over the whole next segment. Continuous everywhere, and never
82
- // further than one more segment, however long the lever (a deep breast does not follow the skull). Where a
83
- // blend stays inside its two segments nothing changes.
84
- export function chainWeights(rig, s, AXL = axialLengths(rig), d = 0) {
85
- const bones = rig.AXIAL.bones;
86
- const n = bones.length;
87
- const blend = (j) => {
88
- const ov = rig.AXIAL.blend[j];
89
- if (ov) { const e = (ov[2] || 0) * d; return smoothstep(AXL[j] + ov[0] * rig.unit - e, AXL[j] + ov[1] * rig.unit + e, s); }
90
- const l0 = AXL[j] - AXL[j - 1], l1 = AXL[j + 1] - AXL[j];
91
- const w = Math.min(0.4 * l0, 0.4 * l1, 0.07 * rig.unit);
92
- return smoothstep(AXL[j] - w, AXL[j] + w, s);
93
- };
94
- let i = 0;
95
- while (i < n - 1 && s > AXL[i + 1]) i++;
96
- const cas = rig.AXIAL.cascade;
97
- if (cas && (cas === true || Object.keys(cas).length)) {
98
- // fade length past the neighbouring joint (Infinity: the whole segment), 0 = cut (the default weighting)
99
- const fadeOf = (j) => (cas === true ? Infinity : Array.isArray(cas) ? (cas.includes(j) ? Infinity : 0) : (cas[j] ?? 0) * rig.unit);
100
- const share = (j) => {
101
- const f = fadeOf(j);
102
- if (j >= i + 2) return i === j - 2 && f > 0 && j >= 2 ? blend(j) * smoothstep(Math.max(AXL[j - 2], AXL[j - 1] - f), AXL[j - 1], s) : 0;
103
- if (j <= i - 1) return i === j + 1 && f > 0 && j + 2 <= n ? 1 - (1 - blend(j)) * (1 - smoothstep(AXL[j + 1], Math.min(AXL[j + 2], AXL[j + 1] + f), s)) : 1;
104
- return blend(j);
105
- };
106
- const out = new Map();
107
- let past = 1; // share of the chain beyond the joints so far
108
- for (let k = 0; k < n && past > 1e-6; k++) {
109
- const j = k + 1;
110
- const a = j > n - 1 ? 0 : share(j);
111
- const w = past * (1 - a);
112
- if (w > 1e-6) out.set(bones[k], w);
113
- past *= a;
114
- }
115
- return out;
116
- }
117
- const out = new Map([[bones[i], 1]]);
118
- if (i > 0) {
119
- const a = blend(i);
120
- if (a < 1) { out.set(bones[i], a); out.set(bones[i - 1], 1 - a); }
121
- }
122
- if (i < n - 1) {
123
- const a = blend(i + 1);
124
- if (a > 0) {
125
- const cur = out.get(bones[i]);
126
- out.set(bones[i], cur * (1 - a));
127
- out.set(bones[i + 1], (out.get(bones[i + 1]) || 0) + cur * a);
128
- }
129
- }
130
- return out;
131
- }
132
-
133
- /**
134
- * @param mesh { pos, nrm, index, lists (per-vertex prim lists), rigidBone (per-vertex bone index or -1), nV }
135
- */
136
- export function computeWeights(mesh, rig) {
137
- const { pos, index, lists, nV } = mesh;
138
- const rigid = mesh.rigidBone;
139
- const U = rig.unit;
140
- const { BONES, BONE } = rig;
141
- const NB = BONES.length;
142
- const limbIds = Object.keys(rig.LIMBS);
143
- const limbs = limbIds.map((id) => rig.LIMBS[id]);
144
- const NL = limbs.length;
145
- const groupsOf = ['axial', ...limbIds, ...rig.appendages.map((a) => a.group)];
146
- const NG = groupsOf.length;
147
- const W = new Float32Array(nV * NB);
148
- const axialS = new Float32Array(nV);
149
- const segT = new Float32Array(nV * 2);
150
- const axD = new Float32Array(nV);
151
- const GD = new Float32Array(nV * NG).fill(1e9);
152
- const bd = new Float64Array(NB);
153
- const sigB = 0.011 * U, sigBDistal = 0.0035 * U;
154
- const DISTAL = new Uint8Array(NB), PROXIMAL = new Uint8Array(NB);
155
- for (const L of limbs) {
156
- for (const n of L.distal || []) DISTAL[BONE[n].index] = 1;
157
- for (const n of L.proximal || []) PROXIMAL[BONE[n].index] = 1;
158
- }
159
- const limbBW = Array.from({ length: NL }, () => new Array(nV));
160
- // skin of the tail (nearest primitive on a tail bone) never belongs to a limb: a tail hanging close
161
- // to the hocks (a wolf's brush, a horse's hair) otherwise took thigh weights and tore when the
162
- // legs moved
163
- const tailSkin = new Uint8Array(nV);
164
- const TAILB = new Uint8Array(NB);
165
- for (const b of BONES) if (/^tail\d+$/.test(b.name)) TAILB[b.index] = 1;
166
- const topBone = new Int8Array(nV * NL);
167
- const webTag = new Int8Array(nV * NL);
168
- const nbr = buildNeighbors(index, nV);
169
- const project = makeProjector(rig);
170
- const webTags = new Set(rig.webTags);
171
- const gIndex = (g) => groupsOf.indexOf(g);
172
-
173
- for (let v = 0; v < nV; v++) {
174
- const px = pos[v * 3], py = pos[v * 3 + 1], pz = pos[v * 3 + 2];
175
- const pr = project(px, py, pz);
176
- axialS[v] = pr.s;
177
- {
178
- // depth on the ventral side of the axial chain (throat, belly): the lever of a blend override.
179
- // Ventral = the segment direction (nose -> tail) turned 90 deg down in the sagittal plane
180
- const P = rig.AXIAL.points, a0 = P[pr.seg], a1 = P[pr.seg + 1];
181
- const dy = a1[1] - a0[1], dz = a1[2] - a0[2], dl = Math.hypot(dy, dz) || 1;
182
- const oy = py - (a0[1] + dy * pr.t), oz = pz - (a0[2] + dz * pr.t);
183
- axD[v] = Math.max(0, (oy * dz - oz * dy) / dl);
184
- }
185
- segT[v * 2] = pr.seg;
186
- segT[v * 2 + 1] = pr.t;
187
- if (rigid[v] >= 0) continue;
188
- bd.fill(1e9);
189
- for (const prim of lists[v]) {
190
- if (prim.carve) continue;
191
- if (prim._gi === undefined) {
192
- prim._gi = gIndex(prim.group);
193
- if (!BONE[prim.bone]) throw new Error(`primitive ${prim.tag} uses unknown bone ${prim.bone}`);
194
- prim._bi = BONE[prim.bone].index;
195
- }
196
- const gi = prim._gi;
197
- if (gi < 0) continue;
198
- const d = SDFModel.dist(prim, px, py, pz) - prim.bias;
199
- if (d < GD[v * NG + gi]) GD[v * NG + gi] = d;
200
- if (d < bd[prim._bi]) bd[prim._bi] = d;
201
- }
202
- {
203
- let dm = 1e9, bm = -1;
204
- for (let bi = 0; bi < NB; bi++) if (bd[bi] < dm) { dm = bd[bi]; bm = bi; }
205
- if (bm >= 0 && TAILB[bm]) tailSkin[v] = 1;
206
- }
207
- for (let li = 0; li < NL; li++) {
208
- const g = li + 1;
209
- if (GD[v * NG + g] > 1e8) continue;
210
- const uniq = [];
211
- for (const prim of lists[v]) if (prim._gi === g && !prim.carve && !uniq.includes(prim._bi)) uniq.push(prim._bi);
212
- let bmin = 1e9, bestB = -1;
213
- for (const bi of uniq) if (bd[bi] < bmin) { bmin = bd[bi]; bestB = bi; }
214
- // webs and sheet muscles that span limb and body never anchor the limb core
215
- let pmin = 1e9, ptag = '';
216
- for (const prim of lists[v]) {
217
- if (prim._gi !== g || prim.carve) continue;
218
- const dp = SDFModel.dist(prim, px, py, pz) - prim.bias;
219
- if (dp < pmin) { pmin = dp; ptag = prim.tag; }
220
- }
221
- webTag[v * NL + li] = webTags.has(ptag) ? 1 : 0;
222
- // thin distal joints fold 100+ degrees: keep their blend narrow
223
- let distal = false;
224
- for (const bi of uniq) if (DISTAL[bi] && bd[bi] - bmin < 0.02 * U) distal = true;
225
- const sig = distal ? sigBDistal : sigB;
226
- let sum = 0;
227
- const tmp = uniq.map((bi) => { const w = Math.exp(-(bd[bi] - bmin) / sig); sum += w; return [bi, w]; });
228
- limbBW[li][v] = tmp.map(([bi, w]) => [bi, w / sum]);
229
- topBone[v * NL + li] = bestB === BONE[limbs[li].field.top].index ? 1 : 0;
230
- }
231
- }
232
-
233
- // relax the axial coordinate over the surface
234
- {
235
- const tmpS = new Float32Array(nV);
236
- for (let it = 0; it < 24; it++) {
237
- for (let v = 0; v < nV; v++) {
238
- const ns = nbr[v];
239
- if (!ns.length || rigid[v] >= 0) { tmpS[v] = axialS[v]; continue; }
240
- let a = 0;
241
- for (const n of ns) a += axialS[n];
242
- tmpS[v] = 0.5 * axialS[v] + (0.5 * a) / ns.length;
243
- }
244
- axialS.set(tmpS);
245
- }
246
- }
247
-
248
- // body skin never takes the weights of the tail beyond its root: skin at the back of a thigh or
249
- // buttock lies nearer to a hanging tail's segments than to the pelvis and projected onto them (it
250
- // swung with the tail). axial.bodyTail: tail segments body skin may still blend into (1: up to the
251
- // tail1 joint; 0: only across the tail base, for a tail that hangs down behind the buttocks)
252
- {
253
- const k = rig.AXIAL.bones.indexOf('tail0');
254
- if (k >= 0) {
255
- const sMax = axialLengths(rig)[k + (rig.AXIAL.bodyTail ?? 1)];
256
- for (let v = 0; v < nV; v++) if (!tailSkin[v] && axialS[v] > sMax) axialS[v] = sMax;
257
- }
258
- }
259
-
260
- // harmonic limb membership fields
261
- const limbM = Array.from({ length: NL }, () => new Float32Array(nV));
262
- const J = rig.J;
263
- for (let li = 0; li < NL; li++) {
264
- const L = limbs[li], F = L.field, g = li + 1, m = limbM[li];
265
- const A = J[F.a], B = J[F.b], AB = sub(B, A), ab2 = dot(AB, AB);
266
- const free = [];
267
- const aCore = F.aCore * U, aBody = F.aBody * U, midX = (F.midX || 0) * U;
268
- const e0 = (F.soft0 ?? -0.006) * U, e1 = (F.soft1 ?? 0.01) * U;
269
- const lateralAxis = F.lateralAxis || [L.side, 0, 0];
270
- for (let v = 0; v < nV; v++) {
271
- const dG = GD[v * NG + g];
272
- if (rigid[v] >= 0 || dG > 1e8 || tailSkin[v]) { m[v] = 0; continue; }
273
- // > 0: closer to the limb than to the body and than to any other limb (a big plantigrade hind
274
- // foot is further from the body than from the forefoot: it must not join the foreleg)
275
- let dO = GD[v * NG];
276
- for (let l2 = 0; l2 < NL; l2++) if (l2 !== li && GD[v * NG + l2 + 1] < dO) dO = GD[v * NG + l2 + 1];
277
- const a = dO - dG;
278
- const mb = smoothstep(e0, e1, a);
279
- const px = pos[v * 3], py = pos[v * 3 + 1], pz = pos[v * 3 + 2];
280
- const t = ((px - A[0]) * AB[0] + (py - A[1]) * AB[1] + (pz - A[2]) * AB[2]) / ab2;
281
- // never let a limb pull skin across the midline (chest floor, groin)
282
- const lateral = F.noMidline ? 1 : px * lateralAxis[0] + py * lateralAxis[1] + pz * lateralAxis[2];
283
- if (a > aCore && (t > F.tCore || !topBone[v * NL + li]) && !webTag[v * NL + li] && lateral > 0.0) { m[v] = 1; }
284
- else if (a < aBody || lateral < midX) { m[v] = 0; }
285
- else { m[v] = mb * clamp(t / F.tCore, 0, 1); free.push(v); }
286
- }
287
- const omega = 1.85;
288
- for (let it = 0; it < 320; it++) {
289
- for (let i = 0; i < free.length; i++) {
290
- const v = free[i], ns = nbr[v];
291
- if (!ns.length) continue;
292
- let a = 0;
293
- for (const n of ns) a += m[n];
294
- m[v] = m[v] + omega * (a / ns.length - m[v]);
295
- }
296
- }
297
- for (const v of free) m[v] = clamp(m[v], 0, 1);
298
- }
299
-
300
- // assemble
301
- const AXL = axialLengths(rig);
302
- for (let v = 0; v < nV; v++) {
303
- const o = v * NB;
304
- if (rigid[v] >= 0) { W[o + rigid[v]] = 1; continue; }
305
- let rest = 1;
306
- for (let li = 0; li < NL; li++) {
307
- const mv = limbM[li][v];
308
- const mm = mv * rest;
309
- if (mm <= 1e-4) continue;
310
- const bw = limbBW[li][v];
311
- const topI = BONE[limbs[li].field.top].index;
312
- // in the blend zone only the proximal bones may pull body skin; distal bones take over as m -> 1
313
- const kd = mv * mv * mv * mv;
314
- let prox = 0;
315
- if (bw) for (const [bi, w] of bw) if (PROXIMAL[bi]) prox += w;
316
- if (bw && bw.length) {
317
- for (const [bi, w] of bw) {
318
- const wp = PROXIMAL[bi] && prox > 1e-6 ? w / prox : 0;
319
- W[o + bi] += mm * (kd * w + (1 - kd) * wp);
320
- }
321
- if (prox <= 1e-6) W[o + topI] += mm * (1 - kd);
322
- } else W[o + topI] += mm;
323
- rest -= mm;
324
- }
325
- for (const ap of rig.appendages) {
326
- const gi = gIndex(ap.group);
327
- const dE = GD[v * NG + gi];
328
- if (dE > 1e8) continue;
329
- const bl = ap.blend || [-0.003, 0.005];
330
- // nearer to this appendage than to the body AND than to any other appendage (long ears: the
331
- // tip of one ear is far from the body, so the body test alone let the first ear take it)
332
- let dO = 1e9;
333
- for (const ap2 of rig.appendages) if (ap2 !== ap) dO = Math.min(dO, GD[v * NG + gIndex(ap2.group)]);
334
- const e = smoothstep(bl[0] * U, bl[1] * U, Math.min(GD[v * NG], dO) - dE) * rest;
335
- if (e > 1e-4) { W[o + BONE[ap.bone].index] += e; rest -= e; }
336
- }
337
- if (rest > 1e-5) for (const [bn, w] of chainWeights(rig, axialS[v], AXL, axD[v])) W[o + BONE[bn].index] += rest * w;
338
- }
339
- const limbMember = new Float32Array(nV), limbWhich = new Int8Array(nV).fill(-1);
340
- for (let v = 0; v < nV; v++) for (let li = 0; li < NL; li++) if (limbM[li][v] > limbMember[v]) { limbMember[v] = limbM[li][v]; limbWhich[v] = li; }
341
-
342
- // sparse Laplacian smoothing
343
- const K = 8;
344
- let SB = new Int16Array(nV * K).fill(-1), SW = new Float32Array(nV * K);
345
- for (let v = 0; v < nV; v++) {
346
- const o = v * NB;
347
- let c = 0;
348
- for (let b = 0; b < NB && c < K; b++) if (W[o + b] > 1e-4) { SB[v * K + c] = b; SW[v * K + c] = W[o + b]; c++; }
349
- }
350
- const acc = new Float32Array(NB);
351
- const touched = [];
352
- for (let it = 0; it < 3; it++) {
353
- const NBw = new Int16Array(nV * K).fill(-1), NWw = new Float32Array(nV * K);
354
- for (let v = 0; v < nV; v++) {
355
- const ns = nbr[v];
356
- touched.length = 0;
357
- const addW = (u, f) => {
358
- for (let k = 0; k < K; k++) {
359
- const b = SB[u * K + k];
360
- if (b < 0) break;
361
- if (acc[b] === 0) touched.push(b);
362
- acc[b] += SW[u * K + k] * f;
363
- }
364
- };
365
- if (!ns.length || rigid[v] >= 0 || DISTAL[SB[v * K]]) addW(v, 1);
366
- else {
367
- addW(v, 0.5);
368
- const f = 0.5 / ns.length;
369
- for (const n of ns) addW(n, f);
370
- }
371
- touched.sort((a, b) => acc[b] - acc[a]);
372
- const m = Math.min(K, touched.length);
373
- for (let k = 0; k < m; k++) { NBw[v * K + k] = touched[k]; NWw[v * K + k] = acc[touched[k]]; }
374
- for (const b of touched) acc[b] = 0;
375
- }
376
- SB = NBw; SW = NWw;
377
- }
378
- const skinIndex = new Uint16Array(nV * 4), skinWeight = new Float32Array(nV * 4);
379
- const dominant = new Uint16Array(nV);
380
- for (let v = 0; v < nV; v++) {
381
- let sum = 0;
382
- for (let k = 0; k < 4; k++) if (SB[v * K + k] >= 0) sum += SW[v * K + k];
383
- sum = sum || 1;
384
- for (let k = 0; k < 4; k++) {
385
- const b = SB[v * K + k];
386
- if (b < 0) break;
387
- skinIndex[v * 4 + k] = b;
388
- skinWeight[v * 4 + k] = SW[v * K + k] / sum;
389
- }
390
- dominant[v] = Math.max(0, SB[v * K]);
391
- }
392
- return { skinIndex, skinWeight, dominant, axialS, segT, neighbors: nbr, limbMember, limbWhich, axialLengths: AXL };
393
- }
@@ -1,81 +0,0 @@
1
- // Tiny allocation-light vector helpers used by the procedural modelling code.
2
- // Vectors are plain [x, y, z] arrays.
3
-
4
- export const add = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
5
- export const sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
6
- export const mul = (a, s) => [a[0] * s, a[1] * s, a[2] * s];
7
- export const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
8
- export const cross = (a, b) => [
9
- a[1] * b[2] - a[2] * b[1],
10
- a[2] * b[0] - a[0] * b[2],
11
- a[0] * b[1] - a[1] * b[0],
12
- ];
13
- export const len = (a) => Math.hypot(a[0], a[1], a[2]);
14
- export const norm = (a) => {
15
- const l = len(a) || 1;
16
- return [a[0] / l, a[1] / l, a[2] / l];
17
- };
18
- export const lerp = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
19
- export const mirror = (a) => [-a[0], a[1], a[2]];
20
- export const dist = (a, b) => Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);
21
- export const clamp = (x, a, b) => (x < a ? a : x > b ? b : x);
22
- export const smoothstep = (e0, e1, x) => {
23
- const t = clamp((x - e0) / (e1 - e0), 0, 1);
24
- return t * t * (3 - 2 * t);
25
- };
26
- export const mix = (a, b, t) => a + (b - a) * t;
27
-
28
- // Orthonormal frame from a primary axis (becomes local Z) and an up hint (local Y).
29
- export function frameZY(zDir, upHint = [0, 1, 0]) {
30
- const z = norm(zDir);
31
- let x = cross(upHint, z);
32
- if (len(x) < 1e-6) x = cross([1, 0, 0], z);
33
- x = norm(x);
34
- const y = cross(z, x);
35
- return [x, y, z];
36
- }
37
-
38
- // Deterministic PRNG (mulberry32)
39
- export function rng(seed) {
40
- let a = seed >>> 0;
41
- return function () {
42
- a |= 0;
43
- a = (a + 0x6d2b79f5) | 0;
44
- let t = Math.imul(a ^ (a >>> 15), 1 | a);
45
- t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
46
- return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
47
- };
48
- }
49
-
50
- // Integer hash based value noise (identical implementation exists in GLSL: see noise.glsl in shaders.js)
51
- export function ihash(x, y, z) {
52
- let h = (Math.imul(x | 0, 0x8da6b343) ^ Math.imul(y | 0, 0xd8163841) ^ Math.imul(z | 0, 0xcb1ab31f)) >>> 0;
53
- h = Math.imul(h ^ (h >>> 13), 0x5bd1e995) >>> 0;
54
- h = (h ^ (h >>> 15)) >>> 0;
55
- return h / 4294967296;
56
- }
57
-
58
- export function vnoise3(x, y, z) {
59
- const xi = Math.floor(x), yi = Math.floor(y), zi = Math.floor(z);
60
- const xf = x - xi, yf = y - yi, zf = z - zi;
61
- const u = xf * xf * (3 - 2 * xf), v = yf * yf * (3 - 2 * yf), w = zf * zf * (3 - 2 * zf);
62
- const c000 = ihash(xi, yi, zi), c100 = ihash(xi + 1, yi, zi);
63
- const c010 = ihash(xi, yi + 1, zi), c110 = ihash(xi + 1, yi + 1, zi);
64
- const c001 = ihash(xi, yi, zi + 1), c101 = ihash(xi + 1, yi, zi + 1);
65
- const c011 = ihash(xi, yi + 1, zi + 1), c111 = ihash(xi + 1, yi + 1, zi + 1);
66
- const x00 = c000 + (c100 - c000) * u, x10 = c010 + (c110 - c010) * u;
67
- const x01 = c001 + (c101 - c001) * u, x11 = c011 + (c111 - c011) * u;
68
- const y0 = x00 + (x10 - x00) * v, y1 = x01 + (x11 - x01) * v;
69
- return y0 + (y1 - y0) * w;
70
- }
71
-
72
- export function fbm3(x, y, z, oct = 4) {
73
- let a = 0.5, f = 1, s = 0, n = 0;
74
- for (let i = 0; i < oct; i++) {
75
- s += a * vnoise3(x * f + i * 17.3, y * f - i * 9.1, z * f + i * 3.7);
76
- n += a;
77
- a *= 0.5;
78
- f *= 2.03;
79
- }
80
- return s / n;
81
- }