@bitefoundry/retrieviewer 0.0.2 → 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 (261) 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 +75 -0
  6. package/INSTALLING.md +8 -5
  7. package/PLUGIN.md +13 -10
  8. package/PREREQUISITES.md +95 -0
  9. package/PUPPY-MEMORY.md +102 -1
  10. package/README.ko.md +110 -0
  11. package/README.md +119 -58
  12. package/RELEASING.md +27 -14
  13. package/THIRD-PARTY-NOTICES.md +5 -3
  14. package/braille.mjs +35 -9
  15. package/examples/live.mjs +2 -2
  16. package/integrations/desktop/platform.mjs +27 -0
  17. package/integrations/linux-overlay/README.md +83 -0
  18. package/integrations/linux-overlay/overlay.py +1094 -0
  19. package/integrations/macos-overlay/README.md +83 -0
  20. package/integrations/macos-overlay/overlay.jxa +639 -0
  21. package/integrations/opencode/runtime.mjs +4 -4
  22. package/integrations/opencode/tui.tsx +1 -1
  23. package/integrations/windows-overlay/Overlay.cs +4 -4
  24. package/integrations/windows-overlay/desktop.mjs +40 -8
  25. package/integrations/windows-overlay/protocol.mjs +11 -7
  26. package/integrations/windows-overlay/worker.mjs +13 -7
  27. package/package.json +41 -14
  28. package/puppy-comfort-sprites.mjs +25 -0
  29. package/puppy-companion-comfort-q5.bin.gz +0 -0
  30. package/puppy-companion-comfort.json +77 -0
  31. package/puppy-companion-life.mjs +49 -16
  32. package/puppy-companion-objects.mjs +12 -0
  33. package/puppy-frame-predictive.mjs +15 -9
  34. package/puppy-frame-store.mjs +2 -2
  35. package/puppy-paper-world.mjs +14 -0
  36. package/puppy-paper.mjs +65 -14
  37. package/retrieviewer-cli.mjs +10 -3
  38. package/retrieviewer-plugin.d.mts +1 -1
  39. package/retrieviewer-plugin.mjs +1 -1
  40. package/retrieviewer.d.mts +10 -4
  41. package/retrieviewer.mjs +20 -14
  42. package/locomotion-core.mjs +0 -21
  43. package/locomotion-puppy.animal +0 -0
  44. package/vendor/procedural-animals/package.json +0 -40
  45. package/vendor/procedural-animals/src/animal.js +0 -146
  46. package/vendor/procedural-animals/src/bake.js +0 -51
  47. package/vendor/procedural-animals/src/build.js +0 -81
  48. package/vendor/procedural-animals/src/core/build/coatKit.js +0 -121
  49. package/vendor/procedural-animals/src/core/build/featherCards.js +0 -189
  50. package/vendor/procedural-animals/src/core/build/finEdges.js +0 -85
  51. package/vendor/procedural-animals/src/core/build/furSlope.js +0 -115
  52. package/vendor/procedural-animals/src/core/build/mesh.js +0 -67
  53. package/vendor/procedural-animals/src/core/build/pipeline.js +0 -272
  54. package/vendor/procedural-animals/src/core/build/seams.js +0 -183
  55. package/vendor/procedural-animals/src/core/build/warp.js +0 -112
  56. package/vendor/procedural-animals/src/core/build/weights.js +0 -393
  57. package/vendor/procedural-animals/src/core/math/vec.js +0 -81
  58. package/vendor/procedural-animals/src/core/motion/actions.js +0 -800
  59. package/vendor/procedural-animals/src/core/motion/bird.js +0 -3063
  60. package/vendor/procedural-animals/src/core/motion/birdActions.js +0 -1059
  61. package/vendor/procedural-animals/src/core/motion/common.js +0 -158
  62. package/vendor/procedural-animals/src/core/motion/index.js +0 -22
  63. package/vendor/procedural-animals/src/core/motion/quadruped.js +0 -2875
  64. package/vendor/procedural-animals/src/core/motion/snake.js +0 -1594
  65. package/vendor/procedural-animals/src/core/motion/spider.js +0 -1810
  66. package/vendor/procedural-animals/src/core/motion/swimmer.js +0 -1047
  67. package/vendor/procedural-animals/src/core/motion/swimmerActions.js +0 -613
  68. package/vendor/procedural-animals/src/core/render/animalObject.js +0 -262
  69. package/vendor/procedural-animals/src/core/render/coatMaterial.js +0 -1301
  70. package/vendor/procedural-animals/src/core/render/dqs.js +0 -159
  71. package/vendor/procedural-animals/src/core/render/eyes.js +0 -676
  72. package/vendor/procedural-animals/src/core/render/membranes.js +0 -77
  73. package/vendor/procedural-animals/src/core/render/skeleton.js +0 -41
  74. package/vendor/procedural-animals/src/core/rig/bird.js +0 -327
  75. package/vendor/procedural-animals/src/core/rig/quadruped.js +0 -76
  76. package/vendor/procedural-animals/src/core/rig/rig.js +0 -79
  77. package/vendor/procedural-animals/src/core/rig/snake.js +0 -76
  78. package/vendor/procedural-animals/src/core/rig/spider.js +0 -110
  79. package/vendor/procedural-animals/src/core/rig/swimmer.js +0 -181
  80. package/vendor/procedural-animals/src/core/sdf/eyeSocket.js +0 -53
  81. package/vendor/procedural-animals/src/core/sdf/mesher.js +0 -238
  82. package/vendor/procedural-animals/src/core/sdf/sdf.js +0 -263
  83. package/vendor/procedural-animals/src/index.d.ts +0 -98
  84. package/vendor/procedural-animals/src/index.js +0 -29
  85. package/vendor/procedural-animals/src/registry.js +0 -48
  86. package/vendor/procedural-animals/src/species/bear/behaviour.js +0 -463
  87. package/vendor/procedural-animals/src/species/bear/claws.js +0 -147
  88. package/vendor/procedural-animals/src/species/bear/coat.js +0 -726
  89. package/vendor/procedural-animals/src/species/bear/index.js +0 -139
  90. package/vendor/procedural-animals/src/species/bear/motion.js +0 -112
  91. package/vendor/procedural-animals/src/species/bear/regions.js +0 -78
  92. package/vendor/procedural-animals/src/species/bear/rig.js +0 -112
  93. package/vendor/procedural-animals/src/species/bear/sculpt.js +0 -272
  94. package/vendor/procedural-animals/src/species/boar/behaviour.js +0 -335
  95. package/vendor/procedural-animals/src/species/boar/coat.js +0 -372
  96. package/vendor/procedural-animals/src/species/boar/index.js +0 -110
  97. package/vendor/procedural-animals/src/species/boar/motion.js +0 -85
  98. package/vendor/procedural-animals/src/species/boar/regions.js +0 -88
  99. package/vendor/procedural-animals/src/species/boar/rig.js +0 -111
  100. package/vendor/procedural-animals/src/species/boar/sculpt.js +0 -285
  101. package/vendor/procedural-animals/src/species/cat/behaviour.js +0 -559
  102. package/vendor/procedural-animals/src/species/cat/coat.js +0 -841
  103. package/vendor/procedural-animals/src/species/cat/index.js +0 -211
  104. package/vendor/procedural-animals/src/species/cat/motion.js +0 -101
  105. package/vendor/procedural-animals/src/species/cat/regions.js +0 -82
  106. package/vendor/procedural-animals/src/species/cat/rig.js +0 -100
  107. package/vendor/procedural-animals/src/species/cat/sculpt.js +0 -266
  108. package/vendor/procedural-animals/src/species/cat/whiskers.js +0 -110
  109. package/vendor/procedural-animals/src/species/cheetah/coat.js +0 -427
  110. package/vendor/procedural-animals/src/species/cheetah/index.js +0 -51
  111. package/vendor/procedural-animals/src/species/cheetah/joints.js +0 -3
  112. package/vendor/procedural-animals/src/species/cheetah/motion.js +0 -77
  113. package/vendor/procedural-animals/src/species/cheetah/regions.js +0 -95
  114. package/vendor/procedural-animals/src/species/cheetah/rig.js +0 -66
  115. package/vendor/procedural-animals/src/species/cheetah/sculpt.js +0 -158
  116. package/vendor/procedural-animals/src/species/chicken/coat.js +0 -313
  117. package/vendor/procedural-animals/src/species/chicken/coverts.js +0 -320
  118. package/vendor/procedural-animals/src/species/chicken/index.js +0 -110
  119. package/vendor/procedural-animals/src/species/chicken/motion.js +0 -177
  120. package/vendor/procedural-animals/src/species/chicken/regions.js +0 -66
  121. package/vendor/procedural-animals/src/species/chicken/rig.js +0 -144
  122. package/vendor/procedural-animals/src/species/chicken/sculpt.js +0 -389
  123. package/vendor/procedural-animals/src/species/chicken/wingLook.js +0 -66
  124. package/vendor/procedural-animals/src/species/chicken/wingStack.js +0 -124
  125. package/vendor/procedural-animals/src/species/cow/behaviour.js +0 -521
  126. package/vendor/procedural-animals/src/species/cow/coat.js +0 -465
  127. package/vendor/procedural-animals/src/species/cow/index.js +0 -118
  128. package/vendor/procedural-animals/src/species/cow/motion.js +0 -81
  129. package/vendor/procedural-animals/src/species/cow/regions.js +0 -98
  130. package/vendor/procedural-animals/src/species/cow/rig.js +0 -116
  131. package/vendor/procedural-animals/src/species/cow/sculpt.js +0 -339
  132. package/vendor/procedural-animals/src/species/crow/coat.js +0 -145
  133. package/vendor/procedural-animals/src/species/crow/index.js +0 -70
  134. package/vendor/procedural-animals/src/species/crow/joints.js +0 -3
  135. package/vendor/procedural-animals/src/species/crow/motion.js +0 -101
  136. package/vendor/procedural-animals/src/species/crow/regions.js +0 -50
  137. package/vendor/procedural-animals/src/species/crow/rig.js +0 -83
  138. package/vendor/procedural-animals/src/species/crow/sculpt.js +0 -118
  139. package/vendor/procedural-animals/src/species/deer/behaviour.js +0 -513
  140. package/vendor/procedural-animals/src/species/deer/coat.js +0 -391
  141. package/vendor/procedural-animals/src/species/deer/index.js +0 -106
  142. package/vendor/procedural-animals/src/species/deer/motion.js +0 -97
  143. package/vendor/procedural-animals/src/species/deer/regions.js +0 -60
  144. package/vendor/procedural-animals/src/species/deer/rig.js +0 -124
  145. package/vendor/procedural-animals/src/species/deer/sculpt.js +0 -297
  146. package/vendor/procedural-animals/src/species/dog/behaviour.js +0 -521
  147. package/vendor/procedural-animals/src/species/dog/coat.js +0 -495
  148. package/vendor/procedural-animals/src/species/dog/index.js +0 -144
  149. package/vendor/procedural-animals/src/species/dog/motion.js +0 -118
  150. package/vendor/procedural-animals/src/species/dog/regions.js +0 -61
  151. package/vendor/procedural-animals/src/species/dog/rig.js +0 -129
  152. package/vendor/procedural-animals/src/species/dog/sculpt.js +0 -246
  153. package/vendor/procedural-animals/src/species/eagle/coat.js +0 -250
  154. package/vendor/procedural-animals/src/species/eagle/index.js +0 -76
  155. package/vendor/procedural-animals/src/species/eagle/joints.js +0 -3
  156. package/vendor/procedural-animals/src/species/eagle/motion.js +0 -137
  157. package/vendor/procedural-animals/src/species/eagle/regions.js +0 -57
  158. package/vendor/procedural-animals/src/species/eagle/rig.js +0 -107
  159. package/vendor/procedural-animals/src/species/eagle/sculpt.js +0 -137
  160. package/vendor/procedural-animals/src/species/fish/coat.js +0 -271
  161. package/vendor/procedural-animals/src/species/fish/index.js +0 -88
  162. package/vendor/procedural-animals/src/species/fish/motion.js +0 -92
  163. package/vendor/procedural-animals/src/species/fish/regions.js +0 -27
  164. package/vendor/procedural-animals/src/species/fish/rig.js +0 -143
  165. package/vendor/procedural-animals/src/species/fish/sculpt.js +0 -214
  166. package/vendor/procedural-animals/src/species/fish/variants.js +0 -126
  167. package/vendor/procedural-animals/src/species/fox/behaviour.js +0 -314
  168. package/vendor/procedural-animals/src/species/fox/coat.js +0 -444
  169. package/vendor/procedural-animals/src/species/fox/index.js +0 -120
  170. package/vendor/procedural-animals/src/species/fox/motion.js +0 -81
  171. package/vendor/procedural-animals/src/species/fox/regions.js +0 -59
  172. package/vendor/procedural-animals/src/species/fox/rig.js +0 -91
  173. package/vendor/procedural-animals/src/species/fox/sculpt.js +0 -202
  174. package/vendor/procedural-animals/src/species/frog/behaviour.js +0 -590
  175. package/vendor/procedural-animals/src/species/frog/coat.js +0 -305
  176. package/vendor/procedural-animals/src/species/frog/index.js +0 -97
  177. package/vendor/procedural-animals/src/species/frog/motion.js +0 -69
  178. package/vendor/procedural-animals/src/species/frog/regions.js +0 -46
  179. package/vendor/procedural-animals/src/species/frog/rig.js +0 -156
  180. package/vendor/procedural-animals/src/species/frog/sculpt.js +0 -240
  181. package/vendor/procedural-animals/src/species/goat/behaviour.js +0 -509
  182. package/vendor/procedural-animals/src/species/goat/coat.js +0 -590
  183. package/vendor/procedural-animals/src/species/goat/index.js +0 -149
  184. package/vendor/procedural-animals/src/species/goat/motion.js +0 -95
  185. package/vendor/procedural-animals/src/species/goat/regions.js +0 -98
  186. package/vendor/procedural-animals/src/species/goat/rig.js +0 -181
  187. package/vendor/procedural-animals/src/species/goat/sculpt.js +0 -547
  188. package/vendor/procedural-animals/src/species/horse/coat.js +0 -361
  189. package/vendor/procedural-animals/src/species/horse/coatSeam.js +0 -122
  190. package/vendor/procedural-animals/src/species/horse/index.js +0 -80
  191. package/vendor/procedural-animals/src/species/horse/motion.js +0 -245
  192. package/vendor/procedural-animals/src/species/horse/regions.js +0 -60
  193. package/vendor/procedural-animals/src/species/horse/rig.js +0 -117
  194. package/vendor/procedural-animals/src/species/horse/sculpt.js +0 -316
  195. package/vendor/procedural-animals/src/species/horse/seamWeights.js +0 -272
  196. package/vendor/procedural-animals/src/species/lion/behaviour.js +0 -509
  197. package/vendor/procedural-animals/src/species/lion/coat.js +0 -1016
  198. package/vendor/procedural-animals/src/species/lion/index.js +0 -111
  199. package/vendor/procedural-animals/src/species/lion/motion.js +0 -87
  200. package/vendor/procedural-animals/src/species/lion/regions.js +0 -106
  201. package/vendor/procedural-animals/src/species/lion/rig.js +0 -110
  202. package/vendor/procedural-animals/src/species/lion/sculpt.js +0 -384
  203. package/vendor/procedural-animals/src/species/lion/whiskers.js +0 -132
  204. package/vendor/procedural-animals/src/species/pig/behaviour.js +0 -575
  205. package/vendor/procedural-animals/src/species/pig/coat.js +0 -730
  206. package/vendor/procedural-animals/src/species/pig/ears.js +0 -242
  207. package/vendor/procedural-animals/src/species/pig/index.js +0 -161
  208. package/vendor/procedural-animals/src/species/pig/motion.js +0 -105
  209. package/vendor/procedural-animals/src/species/pig/regions.js +0 -100
  210. package/vendor/procedural-animals/src/species/pig/rig.js +0 -152
  211. package/vendor/procedural-animals/src/species/pig/sculpt.js +0 -382
  212. package/vendor/procedural-animals/src/species/rabbit/behaviour.js +0 -605
  213. package/vendor/procedural-animals/src/species/rabbit/coat.js +0 -285
  214. package/vendor/procedural-animals/src/species/rabbit/index.js +0 -85
  215. package/vendor/procedural-animals/src/species/rabbit/motion.js +0 -85
  216. package/vendor/procedural-animals/src/species/rabbit/regions.js +0 -48
  217. package/vendor/procedural-animals/src/species/rabbit/rig.js +0 -99
  218. package/vendor/procedural-animals/src/species/rabbit/sculpt.js +0 -148
  219. package/vendor/procedural-animals/src/species/rat/behaviour.js +0 -539
  220. package/vendor/procedural-animals/src/species/rat/coat.js +0 -341
  221. package/vendor/procedural-animals/src/species/rat/index.js +0 -111
  222. package/vendor/procedural-animals/src/species/rat/motion.js +0 -90
  223. package/vendor/procedural-animals/src/species/rat/regions.js +0 -92
  224. package/vendor/procedural-animals/src/species/rat/rig.js +0 -112
  225. package/vendor/procedural-animals/src/species/rat/sculpt.js +0 -163
  226. package/vendor/procedural-animals/src/species/rat/whiskers.js +0 -119
  227. package/vendor/procedural-animals/src/species/shark/coat.js +0 -383
  228. package/vendor/procedural-animals/src/species/shark/index.js +0 -104
  229. package/vendor/procedural-animals/src/species/shark/motion.js +0 -69
  230. package/vendor/procedural-animals/src/species/shark/regions.js +0 -34
  231. package/vendor/procedural-animals/src/species/shark/rig.js +0 -194
  232. package/vendor/procedural-animals/src/species/shark/sculpt.js +0 -343
  233. package/vendor/procedural-animals/src/species/shark/variants.js +0 -105
  234. package/vendor/procedural-animals/src/species/sheep/behaviour.js +0 -522
  235. package/vendor/procedural-animals/src/species/sheep/coat.js +0 -529
  236. package/vendor/procedural-animals/src/species/sheep/index.js +0 -152
  237. package/vendor/procedural-animals/src/species/sheep/motion.js +0 -86
  238. package/vendor/procedural-animals/src/species/sheep/neck.js +0 -41
  239. package/vendor/procedural-animals/src/species/sheep/regions.js +0 -62
  240. package/vendor/procedural-animals/src/species/sheep/rig.js +0 -163
  241. package/vendor/procedural-animals/src/species/sheep/sculpt.js +0 -542
  242. package/vendor/procedural-animals/src/species/snake/coat.js +0 -315
  243. package/vendor/procedural-animals/src/species/snake/index.js +0 -73
  244. package/vendor/procedural-animals/src/species/snake/motion.js +0 -51
  245. package/vendor/procedural-animals/src/species/snake/regions.js +0 -51
  246. package/vendor/procedural-animals/src/species/snake/rig.js +0 -108
  247. package/vendor/procedural-animals/src/species/snake/sculpt.js +0 -122
  248. package/vendor/procedural-animals/src/species/spider/coat.js +0 -279
  249. package/vendor/procedural-animals/src/species/spider/index.js +0 -78
  250. package/vendor/procedural-animals/src/species/spider/motion.js +0 -72
  251. package/vendor/procedural-animals/src/species/spider/regions.js +0 -87
  252. package/vendor/procedural-animals/src/species/spider/rig.js +0 -118
  253. package/vendor/procedural-animals/src/species/spider/sculpt.js +0 -182
  254. package/vendor/procedural-animals/src/species/wolf/behaviour.js +0 -160
  255. package/vendor/procedural-animals/src/species/wolf/coat.js +0 -749
  256. package/vendor/procedural-animals/src/species/wolf/index.js +0 -107
  257. package/vendor/procedural-animals/src/species/wolf/motion.js +0 -80
  258. package/vendor/procedural-animals/src/species/wolf/regions.js +0 -57
  259. package/vendor/procedural-animals/src/species/wolf/rig.js +0 -87
  260. package/vendor/procedural-animals/src/species/wolf/sculpt.js +0 -339
  261. package/vendor/procedural-animals/src/worker.js +0 -29
@@ -1,112 +0,0 @@
1
- // Seeded proportion variation as smooth spatial warps.
2
- //
3
- // Species sculpt and paint in their own reference space. Per-individual proportions (longer legs,
4
- // a bigger head, a longer body) are applied afterwards as a smooth warp of the finished, skinned,
5
- // painted mesh and of the skeleton, so one sculpt serves every individual and the coat pattern is
6
- // carried along with the skin instead of being re-grown. Warps are small (a few to ~15 %).
7
- //
8
- // Warp specs (all optional, composed in order):
9
- // { type: 'legs', k, top } stretch y below `top` by k (everything above moves up)
10
- // { type: 'length', k, z0, z1 } stretch z between z0 and z1 (torso length)
11
- // { type: 'scaleAbout', c, k, r0, r1 } scale by k about c, fading out between radius r0 and r1
12
- // { type: 'girth', k, y0, y1, zRange } scale x (and y about the torso centre) inside a region
13
- // { type: 'scale', k } uniform size
14
- // { type: 'shift', a, b, d } move by d, ramping in along a -> b (smoothstep of the projection: 0
15
- // before a, 1 beyond b): a part beyond b (a head) moves rigidly and
16
- // what lies between a and b (a neck) shortens or lengthens
17
- import { smoothstep } from '../math/vec.js';
18
-
19
- // Integral of smoothstep(a, b, x) from -inf to z: a C2 ramp used to build C1 clamps.
20
- const S = (z, a, b) => {
21
- if (z <= a) return 0;
22
- const w = b - a;
23
- if (z >= b) return w * 0.5 + (z - b);
24
- const u = (z - a) / w;
25
- return w * (u * u * u - 0.5 * u * u * u * u);
26
- };
27
- function one(w) {
28
- switch (w.type) {
29
- case 'scale': return (p) => [p[0] * w.k, p[1] * w.k, p[2] * w.k];
30
- case 'legs': {
31
- // y' = y + (k-1) * c(y), c' = 1 below the belly line, easing to 0 above it
32
- const top = w.top, k = w.k, bw = top * 0.15;
33
- return (p) => [p[0], p[1] + (k - 1) * (Math.max(p[1], 0) - S(p[1], top - bw, top + bw)), p[2]];
34
- }
35
- case 'length': {
36
- // stretches the span z0..z1 about its middle; the ends move rigidly
37
- const { k, z0, z1 } = w, bw = (z1 - z0) * 0.12, zc = (z0 + z1) * 0.5;
38
- const t = (z) => S(z, z0 - bw, z0 + bw) - S(z, z1 - bw, z1 + bw);
39
- const tc = t(zc);
40
- return (p) => [p[0], p[1], p[2] + (k - 1) * (t(p[2]) - tc)];
41
- }
42
- case 'scaleAbout': {
43
- const { c, k, r0, r1 } = w;
44
- return (p) => {
45
- const dx = p[0] - c[0], dy = p[1] - c[1], dz = p[2] - c[2];
46
- const r = Math.hypot(dx, dy, dz);
47
- const f = 1 + (k - 1) * (1 - smoothstep(r0, r1, r));
48
- return [c[0] + dx * f, c[1] + dy * f, c[2] + dz * f];
49
- };
50
- }
51
- case 'girth': {
52
- const { k, cy, z0, z1, fade = 0.08 } = w;
53
- return (p) => {
54
- const f = 1 + (k - 1) * smoothstep(z0 - fade, z0 + fade, p[2]) * (1 - smoothstep(z1 - fade, z1 + fade, p[2])) * smoothstep(cy * 0.35, cy * 0.7, p[1]);
55
- return [p[0] * f, cy + (p[1] - cy) * f, p[2]];
56
- };
57
- }
58
- case 'shift': {
59
- const { a, b, d } = w;
60
- const ab = [b[0] - a[0], b[1] - a[1], b[2] - a[2]], L2 = ab[0] * ab[0] + ab[1] * ab[1] + ab[2] * ab[2];
61
- return (p) => {
62
- const f = smoothstep(0, 1, ((p[0] - a[0]) * ab[0] + (p[1] - a[1]) * ab[1] + (p[2] - a[2]) * ab[2]) / L2);
63
- return [p[0] + d[0] * f, p[1] + d[1] * f, p[2] + d[2] * f];
64
- };
65
- }
66
- default: throw new Error('unknown warp ' + w.type);
67
- }
68
- }
69
-
70
- export function composeWarps(list = []) {
71
- const fs = list.filter(Boolean).map(one);
72
- if (!fs.length) return null;
73
- return (p) => { for (const f of fs) p = f(p); return p; };
74
- }
75
-
76
- // Applies a warp to positions (in place) and re-orients normals with the warp's Jacobian
77
- // (finite differences, inverse transpose).
78
- export function warpMesh(pos, nrm, f, eps = 0.002) {
79
- const n = pos.length / 3;
80
- for (let v = 0; v < n; v++) {
81
- const p = [pos[v * 3], pos[v * 3 + 1], pos[v * 3 + 2]];
82
- const q = f(p);
83
- const jx = f([p[0] + eps, p[1], p[2]]), jy = f([p[0], p[1] + eps, p[2]]), jz = f([p[0], p[1], p[2] + eps]);
84
- // columns of the Jacobian
85
- const a = [(jx[0] - q[0]) / eps, (jx[1] - q[1]) / eps, (jx[2] - q[2]) / eps];
86
- const b = [(jy[0] - q[0]) / eps, (jy[1] - q[1]) / eps, (jy[2] - q[2]) / eps];
87
- const c = [(jz[0] - q[0]) / eps, (jz[1] - q[1]) / eps, (jz[2] - q[2]) / eps];
88
- // inverse transpose applied to n = cofactor matrix * n (up to scale)
89
- const nx = nrm[v * 3], ny = nrm[v * 3 + 1], nz = nrm[v * 3 + 2];
90
- const bc = [b[1] * c[2] - b[2] * c[1], b[2] * c[0] - b[0] * c[2], b[0] * c[1] - b[1] * c[0]];
91
- const ca = [c[1] * a[2] - c[2] * a[1], c[2] * a[0] - c[0] * a[2], c[0] * a[1] - c[1] * a[0]];
92
- const ab = [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
93
- let mx = bc[0] * nx + ca[0] * ny + ab[0] * nz;
94
- let my = bc[1] * nx + ca[1] * ny + ab[1] * nz;
95
- let mz = bc[2] * nx + ca[2] * ny + ab[2] * nz;
96
- const l = Math.hypot(mx, my, mz) || 1;
97
- pos[v * 3] = q[0]; pos[v * 3 + 1] = q[1]; pos[v * 3 + 2] = q[2];
98
- nrm[v * 3] = mx / l; nrm[v * 3 + 1] = my / l; nrm[v * 3 + 2] = mz / l;
99
- }
100
- }
101
-
102
- // local isotropic scale of the warp at p (cube root of the Jacobian determinant)
103
- export function warpScaleAt(f, p, eps = 0.002) {
104
- const q = f(p);
105
- const jx = f([p[0] + eps, p[1], p[2]]), jy = f([p[0], p[1] + eps, p[2]]), jz = f([p[0], p[1], p[2] + eps]);
106
- const a = [(jx[0] - q[0]) / eps, (jx[1] - q[1]) / eps, (jx[2] - q[2]) / eps];
107
- const b = [(jy[0] - q[0]) / eps, (jy[1] - q[1]) / eps, (jy[2] - q[2]) / eps];
108
- const c = [(jz[0] - q[0]) / eps, (jz[1] - q[1]) / eps, (jz[2] - q[2]) / eps];
109
- const det = a[0] * (b[1] * c[2] - b[2] * c[1]) - a[1] * (b[0] * c[2] - b[2] * c[0]) + a[2] * (b[0] * c[1] - b[1] * c[0]);
110
- return Math.cbrt(Math.abs(det));
111
- }
112
-
@@ -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
- }