@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,77 +0,0 @@
1
- // Translucent fin membranes (material 11). The meshed surface stays one skinned geometry; triangles
2
- // whose three vertices are membrane are moved out of the opaque base draw into a second, transparent
3
- // draw that shares every vertex buffer (and the dual-quaternion texture) with the base. At the crowd
4
- // tier (one draw call) the membranes go back into the opaque base.
5
- //
6
- // Draw calls for a fish: hero / high / medium / low = base + membranes + eyes; crowd = base.
7
- // Shells and hair fins are hidden for builds without any hairy vertex (render/animalObject.js).
8
- import * as THREE from 'three';
9
-
10
- export const MEMBRANE_MAT = 11;
11
-
12
- /** Splits the index into opaque and membrane triangles; null when there is no membrane. */
13
- export function splitMembranes(data, mat = MEMBRANE_MAT) {
14
- const idx = data.index, tint = data.tint, nT = idx.length / 3;
15
- const isM = (v) => Math.round(tint[v * 4 + 3]) === mat;
16
- let nM = 0;
17
- const flag = new Uint8Array(nT);
18
- for (let t = 0; t < nT; t++) if (isM(idx[t * 3]) && isM(idx[t * 3 + 1]) && isM(idx[t * 3 + 2])) { flag[t] = 1; nM++; }
19
- if (!nM) return null;
20
- const opaque = new Uint32Array((nT - nM) * 3), membrane = new Uint32Array(nM * 3);
21
- let o = 0, m = 0;
22
- for (let t = 0; t < nT; t++) {
23
- const dst = flag[t] ? membrane : opaque;
24
- const k = flag[t] ? m : o;
25
- dst[k] = idx[t * 3]; dst[k + 1] = idx[t * 3 + 1]; dst[k + 2] = idx[t * 3 + 2];
26
- if (flag[t]) m += 3; else o += 3;
27
- }
28
- return { opaque, membrane };
29
- }
30
-
31
- /** True when any vertex grows hair (fur 0, bristly skin 4 with fur length, feathers 9). */
32
- export function hasHair(data) {
33
- const tint = data.tint, coat = data.coat;
34
- for (let v = 0; v < data.nV; v++) {
35
- const m = Math.round(tint[v * 4 + 3]);
36
- if ((m === 0 || m === 4 || m === 8 || m === 9) && coat[v * 4 + 2] > 0.0005) return true;
37
- }
38
- return false;
39
- }
40
-
41
- /**
42
- * @param data packed build data
43
- * @param geometry the base BufferGeometry (its index is swapped between opaque-only and full)
44
- * @param material the membrane ShaderMaterial (coatMaterial.js createCoatMaterials().membrane)
45
- * @param shadowMats { depth, distance } dual-quaternion shadow materials
46
- * @returns { mesh, setCrowd(on), dispose() } or null when the build has no membranes
47
- */
48
- export function createMembranes(data, geometry, material, shadowMats, { castShadow = true, receiveShadow = true } = {}) {
49
- const split = splitMembranes(data);
50
- if (!split) return null;
51
- const full = geometry.index;
52
- const opaque = new THREE.BufferAttribute(split.opaque, 1);
53
- const mg = new THREE.BufferGeometry();
54
- for (const k of Object.keys(geometry.attributes)) mg.setAttribute(k, geometry.attributes[k]);
55
- mg.setIndex(new THREE.BufferAttribute(split.membrane, 1));
56
- mg.boundingSphere = geometry.boundingSphere;
57
- const mesh = new THREE.Mesh(mg, material);
58
- mesh.name = 'membranes';
59
- mesh.frustumCulled = false;
60
- mesh.renderOrder = 5;
61
- mesh.castShadow = castShadow;
62
- mesh.receiveShadow = receiveShadow;
63
- mesh.customDepthMaterial = shadowMats.depth;
64
- mesh.customDistanceMaterial = shadowMats.distance;
65
- geometry.setIndex(opaque);
66
- let crowd = false;
67
- return {
68
- mesh,
69
- setCrowd(on) {
70
- if (on === crowd) return;
71
- crowd = on;
72
- geometry.setIndex(on ? full : opaque);
73
- mesh.visible = !on;
74
- },
75
- dispose() { mg.dispose(); },
76
- };
77
- }
@@ -1,41 +0,0 @@
1
- // Runtime skeleton: bones are not parented in the scene graph; the motion engine writes their world
2
- // matrices directly (frames built from joint positions + lateral references), using the same
3
- // convention as the bind pose (origin = head joint, +Y along the bone, +X lateral).
4
- import * as THREE from 'three';
5
-
6
- export function frameMatrix(target, o, y, xRef) {
7
- const Y = new THREE.Vector3(y[0], y[1], y[2]).normalize();
8
- const X = new THREE.Vector3(xRef[0], xRef[1], xRef[2]);
9
- X.addScaledVector(Y, -X.dot(Y));
10
- if (X.lengthSq() < 1e-10) X.set(0, 0, 1).addScaledVector(Y, -Y.z);
11
- X.normalize();
12
- const Z = new THREE.Vector3().crossVectors(X, Y);
13
- target.set(X.x, Y.x, Z.x, o[0], X.y, Y.y, Z.y, o[1], X.z, Y.z, Z.z, o[2], 0, 0, 0, 1);
14
- return target;
15
- }
16
-
17
- // data: packed build data (bones + joints)
18
- export function createSkeleton(data) {
19
- const J = data.joints;
20
- const bones = data.bones.map((b) => {
21
- const bone = new THREE.Bone();
22
- bone.name = b.name;
23
- bone.matrixAutoUpdate = false;
24
- bone.matrixWorldAutoUpdate = false;
25
- return bone;
26
- });
27
- const bind = data.bones.map((b) => {
28
- const h = J[b.headJ], t = J[b.tailJ];
29
- return frameMatrix(new THREE.Matrix4(), h, [t[0] - h[0], t[1] - h[1], t[2] - h[2]], [1, 0, 0]);
30
- });
31
- const inverses = bind.map((m) => m.clone().invert());
32
- bones.forEach((bone, i) => bone.matrixWorld.copy(bind[i]));
33
- const skeleton = new THREE.Skeleton(bones, inverses);
34
- const byName = Object.fromEntries(bones.map((b) => [b.name, b]));
35
- const index = Object.fromEntries(data.bones.map((b, i) => [b.name, i]));
36
- return { bones, bind, inverses, skeleton, byName, index, defs: data.bones, joints: J };
37
- }
38
-
39
- export function resetToBind(sk) {
40
- sk.bones.forEach((b, i) => b.matrixWorld.copy(sk.bind[i]));
41
- }
@@ -1,327 +0,0 @@
1
- // Standard bird skeleton and the wing / feather geometry shared by the build (bind pose, feather
2
- // cards) and the bird motion engine (core/motion/bird.js).
3
- //
4
- // Bones (names the bird engine expects; {S} = L / R):
5
- // axial pelvis (synsacrum -> tailBase, root), chest (synsacrum -> neckBase), neck0..neckN-1
6
- // (neckBase -> neck1 -> ... -> occiput), head (occiput -> bill), jaw (jawHinge -> jawTip,
7
- // lower mandible), tail (tailBase -> tailTip, the pygostyle)
8
- // legs femur{S} (hip -> knee, hidden in the body), tibia{S} (knee -> ankle: tibiotarsus, the
9
- // feathered drumstick), tarsus{S} (ankle -> mtp: tarsometatarsus), toes toe{j}a{S} (mtp ->
10
- // t{j}m{S}) and toe{j}b{S} (t{j}m{S} -> t{j}t{S}) for j = 1 (hallux, points back), 2 (inner),
11
- // 3 (middle: region 'foot', the canonical foot), 4 (outer)
12
- // wings humerus{S} (shoulder -> elbow), ulna{S} (elbow -> wrist), hand{S} (wrist -> handTip:
13
- // carpometacarpus + digits)
14
- // feathers pri{k}{S} (primaries, on the hand, k = 1 innermost .. n outermost), sec{k}{S}
15
- // (secondaries + tertials, on the ulna, k = 1 at the wrist .. n at the elbow), rec{k}{S}
16
- // (rectrices, on the tail, k = 1 central .. n outer); joint names <bone>r{S} (root) and
17
- // <bone>t{S} (tip). Feather bones carry rigid feather cards (core/build/featherCards.js).
18
- //
19
- // Wing model. A wing is three segments in a plane that the shoulder orients: `elev` rotates the
20
- // plane about the body's long axis (+ raises the tip, the fold is about -85), `pitch` tilts it about
21
- // the span (+ leading edge up), `alpha` swings the humerus inside the plane (+ backwards), `elbow`
22
- // flexes the ulna forward, `wrist` flexes the hand backwards (both 0 = straight), `bend` lifts the
23
- // hand out of the plane (+ up), `twist` pronates it (+ leading edge down). Folding the elbow and wrist
24
- // Z-folds the wing against the flank exactly like a bird's (humerus back, ulna forward, hand back).
25
- // Feather directions are in-plane angles from their segment toward the trailing edge, interpolated
26
- // between a folded and a spread value by the segment's extension (the ligament "drawing" mechanism
27
- // that fans the flight feathers when the wing opens).
28
- //
29
- // All functions work on plain {x, y, z} objects (THREE.Vector3 qualifies) and never allocate when
30
- // given output objects, so the engine can call them every frame.
31
-
32
- export const DEG = Math.PI / 180;
33
-
34
- // ---------------------------------------------------------------- bones
35
- export function birdBones({ neckSegs = 4, jaw = true, primaries = 10, secondaries = 9, rectrices = 6, extra = [] } = {}) {
36
- const b = [
37
- ['pelvis', 'synsacrum', 'tailBase', null, { region: 'torso' }],
38
- ['chest', 'synsacrum', 'neckBase', 'pelvis', { region: 'torso' }],
39
- ];
40
- const nj = (i) => (i === 0 ? 'neckBase' : i === neckSegs ? 'occiput' : 'neck' + i);
41
- for (let i = 0; i < neckSegs; i++) b.push(['neck' + i, nj(i), nj(i + 1), i ? 'neck' + (i - 1) : 'chest', { region: 'neck' }]);
42
- b.push(['head', 'occiput', 'bill', 'neck' + (neckSegs - 1), { region: 'head' }]);
43
- if (jaw) b.push(['jaw', 'jawHinge', 'jawTip', 'head', { region: 'jaw', group: 'jaw' }]);
44
- b.push(['tail', 'tailBase', 'tailTip', 'pelvis', { region: 'tail' }]);
45
- b.push(
46
- ['humerus{S}', 'shoulder{S}', 'elbow{S}', 'chest', { region: 'wing', group: 'wing{S}' }],
47
- ['ulna{S}', 'elbow{S}', 'wrist{S}', 'humerus{S}', { region: 'wing', group: 'wing{S}' }],
48
- ['hand{S}', 'wrist{S}', 'handTip{S}', 'ulna{S}', { region: 'wing', group: 'wing{S}' }],
49
- ['femur{S}', 'hip{S}', 'knee{S}', 'pelvis', { region: 'limb', group: 'leg{S}' }],
50
- ['tibia{S}', 'knee{S}', 'ankle{S}', 'femur{S}', { region: 'limb', group: 'leg{S}' }],
51
- ['tarsus{S}', 'ankle{S}', 'mtp{S}', 'tibia{S}', { region: 'limb', group: 'leg{S}' }],
52
- );
53
- for (const j of [1, 2, 3, 4]) {
54
- const region = j === 3 ? 'foot' : 'toe';
55
- b.push([`toe${j}a{S}`, 'mtp{S}', `t${j}m{S}`, 'tarsus{S}', { region, group: 'leg{S}' }]);
56
- b.push([`toe${j}b{S}`, `t${j}m{S}`, `t${j}t{S}`, `toe${j}a{S}`, { region, group: 'leg{S}' }]);
57
- }
58
- for (let k = 1; k <= primaries; k++) b.push([`pri${k}{S}`, `pri${k}r{S}`, `pri${k}t{S}`, 'hand{S}', { region: 'feather', group: 'wing{S}' }]);
59
- for (let k = 1; k <= secondaries; k++) b.push([`sec${k}{S}`, `sec${k}r{S}`, `sec${k}t{S}`, 'ulna{S}', { region: 'feather', group: 'wing{S}' }]);
60
- for (let k = 1; k <= rectrices; k++) b.push([`rec${k}{S}`, `rec${k}r{S}`, `rec${k}t{S}`, 'tail', { region: 'feather', group: 'tailfan' }]);
61
- return b.concat(extra);
62
- }
63
-
64
- // Limb descriptions for the harmonic skin weights (see core/build/weights.js). Legs blend from the
65
- // hip (the femur lives inside the body, only the drumstick below the knee is limb skin); wings from
66
- // the shoulder.
67
- export function birdLimbs({ leg = {}, wing = {} } = {}) {
68
- const L = {};
69
- for (const S of ['L', 'R']) {
70
- const side = S === 'L' ? 1 : -1;
71
- const toes = [1, 2, 3, 4].flatMap((j) => [`toe${j}a${S}`, `toe${j}b${S}`]);
72
- L['leg' + S] = {
73
- side, S, front: false,
74
- bones: ['femur' + S, 'tibia' + S, 'tarsus' + S, ...toes],
75
- proximal: ['femur' + S], distal: ['tarsus' + S, ...toes],
76
- field: { a: 'hip' + S, b: 'knee' + S, top: 'femur' + S, tCore: 0.9, aCore: 0.012, aBody: -0.01, midX: 0.004, ...leg },
77
- };
78
- L['wing' + S] = {
79
- side, S, front: true,
80
- bones: ['humerus' + S, 'ulna' + S, 'hand' + S],
81
- proximal: ['humerus' + S], distal: ['hand' + S],
82
- field: { a: 'shoulder' + S, b: 'elbow' + S, top: 'humerus' + S, tCore: 0.45, aCore: 0.01, aBody: -0.012, midX: 0.01, ...wing },
83
- };
84
- }
85
- return L;
86
- }
87
-
88
- // Neck joints neck1..neckN-1 on a planar S-curve between neckBase and occiput (bind helper): a cubic
89
- // Bezier with the given start / end tangents (unit, in the y-z plane), sampled at equal arc length.
90
- export function neckChain(J, neckSegs, t0, t1, bulge = 0.4) {
91
- const A = J.neckBase, B = J.occiput;
92
- const d = Math.hypot(B[0] - A[0], B[1] - A[1], B[2] - A[2]);
93
- const P1 = [A[0] + t0[0] * d * bulge, A[1] + t0[1] * d * bulge, A[2] + t0[2] * d * bulge];
94
- const P2 = [B[0] - t1[0] * d * bulge, B[1] - t1[1] * d * bulge, B[2] - t1[2] * d * bulge];
95
- const bez = (t) => {
96
- const u = 1 - t;
97
- return [0, 1, 2].map((k) => u * u * u * A[k] + 3 * u * u * t * P1[k] + 3 * u * t * t * P2[k] + t * t * t * B[k]);
98
- };
99
- const N = 200, pts = [], s = [0];
100
- for (let i = 0; i <= N; i++) pts.push(bez(i / N));
101
- for (let i = 1; i <= N; i++) s.push(s[i - 1] + Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1], pts[i][2] - pts[i - 1][2]));
102
- for (let j = 1; j < neckSegs; j++) {
103
- const target = (s[N] * j) / neckSegs;
104
- let i = 1;
105
- while (i < N && s[i] < target) i++;
106
- const f = (target - s[i - 1]) / (s[i] - s[i - 1] || 1);
107
- J['neck' + j] = [0, 1, 2].map((k) => pts[i - 1][k] + (pts[i][k] - pts[i - 1][k]) * f);
108
- }
109
- return J;
110
- }
111
-
112
- // ---------------------------------------------------------------- tiny vector helpers ({x,y,z})
113
- export const v3 = (x = 0, y = 0, z = 0) => ({ x, y, z });
114
- const set = (o, x, y, z) => { o.x = x; o.y = y; o.z = z; return o; };
115
- const cp = (o, a) => { o.x = a.x; o.y = a.y; o.z = a.z; return o; };
116
- const nrm = (o) => { const l = Math.hypot(o.x, o.y, o.z) || 1; o.x /= l; o.y /= l; o.z /= l; return o; };
117
- const dot = (a, b) => a.x * b.x + a.y * b.y + a.z * b.z;
118
- // o = a x b (o may alias a or b)
119
- const crs = (o, a, b) => set(o, a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
120
- // o = v rotated about the unit axis k by angle a (Rodrigues; o may alias v)
121
- export function rot(o, v, k, a) {
122
- const c = Math.cos(a), s = Math.sin(a), d = (k.x * v.x + k.y * v.y + k.z * v.z) * (1 - c);
123
- return set(o,
124
- v.x * c + (k.y * v.z - k.z * v.y) * s + k.x * d,
125
- v.y * c + (k.z * v.x - k.x * v.z) * s + k.y * d,
126
- v.z * c + (k.x * v.y - k.y * v.x) * s + k.z * d);
127
- }
128
-
129
- // ---------------------------------------------------------------- wing kinematics
130
- const XAX = { x: 1, y: 0, z: 0 };
131
- const TILTED = ['xw', 'n', 'dH', 'nH', 'dU', 'nU', 'dM', 'nM'];
132
- // Output container for wingFK (preallocate once per wing).
133
- export function makeWingFrames() {
134
- return {
135
- xw: v3(), n: v3(), dH: v3(), nH: v3(), dU: v3(), nU: v3(), dM: v3(), nM: v3(),
136
- elbow: v3(), wrist: v3(), tip: v3(), k: v3(), t: v3(),
137
- };
138
- }
139
-
140
- /**
141
- * Wing forward kinematics in body-local coordinates (x = left, y = up, z = forward), relative to the
142
- * shoulder (which is at the origin of the result positions).
143
- * @param o makeWingFrames() output
144
- * @param side +1 left, -1 right
145
- * @param L { h, u, m } segment lengths (humerus, ulna, hand)
146
- * @param a { elev, pitch, alpha, elbow, wrist, bend, twist, uTwist? } radians
147
- */
148
- export function wingFK(o, side, L, a) {
149
- const s = side, k = o.k;
150
- // spread frame: outward, dorsal; elevation about the body's long axis
151
- const ce = Math.cos(a.elev), se = Math.sin(a.elev);
152
- set(o.xw, s * ce, se, 0);
153
- set(o.n, -s * se, ce, 0);
154
- // pitch about the span axis (+ leading edge up)
155
- rot(o.n, o.n, o.xw, -s * a.pitch);
156
- // in-plane rotations about s * n (positive = toward the trailing edge)
157
- set(k, o.n.x * s, o.n.y * s, o.n.z * s);
158
- rot(o.dH, o.xw, k, a.alpha);
159
- cp(o.nH, o.n);
160
- rot(o.dU, o.dH, k, -a.elbow);
161
- cp(o.nU, o.n);
162
- if (a.uTwist) rot(o.nU, o.nU, o.dU, s * a.uTwist);
163
- rot(o.dM, o.dU, k, a.wrist);
164
- // out-of-plane bend of the hand (tip up), then pronation about the hand axis
165
- const cb = Math.cos(a.bend), sb = Math.sin(a.bend);
166
- const mx = o.dM.x * cb + o.nU.x * sb, my = o.dM.y * cb + o.nU.y * sb, mz = o.dM.z * cb + o.nU.z * sb;
167
- set(o.nM, o.nU.x * cb - o.dM.x * sb, o.nU.y * cb - o.dM.y * sb, o.nU.z * cb - o.dM.z * sb);
168
- set(o.dM, mx, my, mz);
169
- if (a.twist) rot(o.nM, o.nM, o.dM, s * a.twist);
170
- // optional wing-root tilt: the wing frame follows a body axis pitched `tilt` nose-up from the bind
171
- // frame's horizontal (upright birds such as raptors: the stroke plane and the glide chord stay level
172
- // in flight when the body is levelled by the standing tilt)
173
- if (a.tilt) for (const v of TILTED) rot(o[v], o[v], XAX, -a.tilt);
174
- // joints
175
- set(o.elbow, o.dH.x * L.h, o.dH.y * L.h, o.dH.z * L.h);
176
- set(o.wrist, o.elbow.x + o.dU.x * L.u, o.elbow.y + o.dU.y * L.u, o.elbow.z + o.dU.z * L.u);
177
- set(o.tip, o.wrist.x + o.dM.x * L.m, o.wrist.y + o.dM.y * L.m, o.wrist.z + o.dM.z * L.m);
178
- return o;
179
- }
180
-
181
- // Extension of a wing segment for the feather fan: 0 folded .. 1 spread.
182
- export const extension = (flex, foldFlex, spreadFlex) => {
183
- const t = (foldFlex - flex) / (foldFlex - spreadFlex);
184
- const c = t < 0 ? 0 : t > 1 ? 1 : t;
185
- return c * c * (3 - 2 * c);
186
- };
187
-
188
- /**
189
- * One flight feather on a wing segment. Segment frame: P0 (proximal joint of the feather row: the
190
- * wrist for both rows), d (segment axis pointing outward), n (dorsal normal), length Ls, side.
191
- * f: { u (root along the row, 0 at P0), a (in-plane angle from d toward the trailing edge, rad),
192
- * lift (dorsal root offset, m), back (root offset toward the trailing edge, m), bend (out of plane,
193
- * + up, rad), twist (about its own axis, rad) }; `inward` = the row runs from P0 back along -d
194
- * (secondaries along the ulna from the wrist to the elbow).
195
- * Writes root, axis (unit) and normal (unit, dorsal side of the vane).
196
- */
197
- export function featherFrame(out, P0, d, n, Ls, side, f, a, inward) {
198
- const s = side;
199
- // trailing direction in the segment plane
200
- const tx = s * (n.y * d.z - n.z * d.y), ty = s * (n.z * d.x - n.x * d.z), tz = s * (n.x * d.y - n.y * d.x);
201
- const along = (inward ? -1 : 1) * Ls * f.u;
202
- set(out.root,
203
- P0.x + d.x * along + tx * f.back + n.x * f.lift,
204
- P0.y + d.y * along + ty * f.back + n.y * f.lift,
205
- P0.z + d.z * along + tz * f.back + n.z * f.lift);
206
- const ca = Math.cos(a), sa = Math.sin(a);
207
- let ax = d.x * ca + tx * sa, ay = d.y * ca + ty * sa, az = d.z * ca + tz * sa;
208
- const cb = Math.cos(f.bend || 0), sb = Math.sin(f.bend || 0);
209
- ax = ax * cb + n.x * sb; ay = ay * cb + n.y * sb; az = az * cb + n.z * sb;
210
- set(out.axis, ax, ay, az); nrm(out.axis);
211
- const dn = dot(n, out.axis);
212
- set(out.normal, n.x - out.axis.x * dn, n.y - out.axis.y * dn, n.z - out.axis.z * dn); nrm(out.normal);
213
- if (f.twist) rot(out.normal, out.normal, out.axis, s * f.twist);
214
- return out;
215
- }
216
-
217
- /**
218
- * One rectrix on the tail. Tail frame: P0 (tail tip joint), d (tail axis, backwards), n (dorsal),
219
- * lat (the bird's left). f: { x (lateral root offset, m, >0 = own side), lift, a (fan angle, rad,
220
- * outward), bend, twist }.
221
- */
222
- export function rectrixFrame(out, P0, d, n, lat, side, f, a) {
223
- const s = side;
224
- set(out.root, P0.x + lat.x * s * f.x + n.x * f.lift, P0.y + lat.y * s * f.x + n.y * f.lift, P0.z + lat.z * s * f.x + n.z * f.lift);
225
- const ca = Math.cos(a), sa = Math.sin(a);
226
- let ax = d.x * ca + lat.x * s * sa, ay = d.y * ca + lat.y * s * sa, az = d.z * ca + lat.z * s * sa;
227
- const cb = Math.cos(f.bend || 0), sb = Math.sin(f.bend || 0);
228
- ax = ax * cb + n.x * sb; ay = ay * cb + n.y * sb; az = az * cb + n.z * sb;
229
- set(out.axis, ax, ay, az); nrm(out.axis);
230
- const dn = dot(n, out.axis);
231
- set(out.normal, n.x - out.axis.x * dn, n.y - out.axis.y * dn, n.z - out.axis.z * dn); nrm(out.normal);
232
- if (f.twist) rot(out.normal, out.normal, out.axis, -s * f.twist);
233
- return out;
234
- }
235
-
236
- export const makeFeatherFrame = () => ({ root: v3(), axis: v3(), normal: v3() });
237
-
238
- // ---------------------------------------------------------------- species feather spec helpers
239
- // Resolves species.motion.feathers into per-feather records (angles in radians, lengths in metres at
240
- // the reference size). Spec:
241
- // primaries: [{ len, width, u, spread, fold, emarg?, lift?, bend?, twist? }] inner -> outer
242
- // secondaries: [{ len, width, u, spread, fold, lift?, ... }] wrist -> elbow
243
- // (any feather: arch? = vane edges below the rachis as a fraction of the half-width, default 0.12;
244
- // base0? = vane width at the root as a fraction of the full width, default 0.3; cov? = overrides of
245
- // its covert card: { lift, shift, lenK, widthK, shape }, see core/build/featherCards.js)
246
- // rectrices: [{ len, width, x, fan, lift?, arc? (deg: rachis bent on a circular arc toward the
247
- // inner vane, e.g. a rooster's sickles), ... }] central -> outer
248
- // coverts: { primary: len fraction, secondary: len fraction, tail: len fraction, rows? }
249
- export function resolveFeathers(spec = {}) {
250
- const P = (spec.primaries || []).map((f, i, arr) => ({
251
- kind: 'pri', i, n: arr.length, len: f.len, width: f.width, u: f.u, spread: f.spread * DEG, fold: f.fold * DEG,
252
- lift: f.lift ?? (arr.length - 1 - i) * 0.0006, back: f.back ?? 0.002, bend: (f.bend || 0) * DEG, twist: (f.twist ?? 4) * DEG,
253
- emarg: f.emarg || 0, outer: f.outer ?? 0.32, curve: f.curve ?? 0.05, droop: f.droop ?? 0.02, tipRound: f.tipRound ?? 0.35, arch: f.arch,
254
- finger: f.finger ?? 0, cov: f.cov, base0: f.base0,
255
- }));
256
- const nP = P.length;
257
- const Sd = (spec.secondaries || []).map((f, i, arr) => ({
258
- kind: 'sec', i, n: arr.length, len: f.len, width: f.width, u: f.u, spread: f.spread * DEG, fold: f.fold * DEG,
259
- lift: f.lift ?? (nP + i) * 0.0006, back: f.back ?? 0.002, bend: (f.bend || 0) * DEG, twist: (f.twist ?? 3) * DEG,
260
- emarg: 0, outer: f.outer ?? 0.42, curve: f.curve ?? 0.03, droop: f.droop ?? 0.015, tipRound: f.tipRound ?? 0.5, finger: 0, arch: f.arch,
261
- cov: f.cov, base0: f.base0,
262
- }));
263
- const R = (spec.rectrices || []).map((f, i, arr) => ({
264
- kind: 'rec', i, n: arr.length, len: f.len, width: f.width, x: f.x, fan: f.fan * DEG, fold: (f.fold || 0) * DEG,
265
- lift: f.lift ?? (arr.length - 1 - i) * 0.0008, bend: (f.bend || 0) * DEG, twist: (f.twist ?? 2) * DEG,
266
- outer: f.outer ?? (i === 0 ? 0.5 : 0.4), curve: f.curve ?? 0.0, droop: f.droop ?? 0.01, tipRound: f.tipRound ?? 0.55, emarg: 0, finger: 0,
267
- arc: (f.arc || 0) * DEG, arch: f.arch, cov: f.cov, base0: f.base0,
268
- }));
269
- return { primaries: P, secondaries: Sd, rectrices: R, coverts: { primary: 0.36, secondary: 0.46, tail: 0.42, ...(spec.coverts || {}) } };
270
- }
271
-
272
- // Bind-pose feather joints for one side from the bind wing configuration. Writes J[`pri{k}rL`] etc.
273
- // (left side; buildRig mirrors). Returns the per-feather bind frames (used by the card builder).
274
- export function featherJoints(J, wingSpec, feathers, tailSpec) {
275
- const F = resolveFeathers(feathers);
276
- const sh = J.shoulderL;
277
- const L = wingLengths(J, wingSpec);
278
- const fr = wingFK(makeWingFrames(), 1, L, degs({ ...wingSpec.bind, tilt: wingSpec.tilt }));
279
- const P0 = v3(sh[0] + fr.wrist.x, sh[1] + fr.wrist.y, sh[2] + fr.wrist.z);
280
- const out = { pri: [], sec: [], rec: [] };
281
- const eH = extension(wingSpec.bind.wrist * DEG, wingSpec.fold.wrist * DEG, (wingSpec.open || wingSpec.glide).wrist * DEG);
282
- const eU = extension(wingSpec.bind.elbow * DEG, wingSpec.fold.elbow * DEG, (wingSpec.open || wingSpec.glide).elbow * DEG);
283
- for (const f of F.primaries) {
284
- const o = featherFrame(makeFeatherFrame(), P0, fr.dM, fr.nM, L.m, 1, f, f.fold + (f.spread - f.fold) * eH, false);
285
- J[`pri${f.i + 1}rL`] = [o.root.x, o.root.y, o.root.z];
286
- J[`pri${f.i + 1}tL`] = [o.root.x + o.axis.x * f.len, o.root.y + o.axis.y * f.len, o.root.z + o.axis.z * f.len];
287
- out.pri.push({ f, ...o });
288
- }
289
- for (const f of F.secondaries) {
290
- const o = featherFrame(makeFeatherFrame(), P0, fr.dU, fr.nU, L.u, 1, f, f.fold + (f.spread - f.fold) * eU, true);
291
- J[`sec${f.i + 1}rL`] = [o.root.x, o.root.y, o.root.z];
292
- J[`sec${f.i + 1}tL`] = [o.root.x + o.axis.x * f.len, o.root.y + o.axis.y * f.len, o.root.z + o.axis.z * f.len];
293
- out.sec.push({ f, ...o });
294
- }
295
- // tail: the bind tail frame follows the pygostyle (tailBase -> tailTip), dorsal = up
296
- const tb = J.tailBase, tt = J.tailTip;
297
- const d = nrm(v3(tt[0] - tb[0], tt[1] - tb[1], tt[2] - tb[2]));
298
- const lat = v3(1, 0, 0);
299
- const n = nrm(crs(v3(), d, lat)); // d x left = up for a backward-pointing d
300
- if (n.y < 0) set(n, -n.x, -n.y, -n.z);
301
- const fan = (tailSpec && tailSpec.bindFan) ?? 0.2;
302
- for (const f of F.rectrices) {
303
- const o = rectrixFrame(makeFeatherFrame(), v3(tt[0], tt[1], tt[2]), d, n, lat, 1, f, f.fold + (f.fan - f.fold) * fan);
304
- J[`rec${f.i + 1}rL`] = [o.root.x, o.root.y, o.root.z];
305
- J[`rec${f.i + 1}tL`] = [o.root.x + o.axis.x * f.len, o.root.y + o.axis.y * f.len, o.root.z + o.axis.z * f.len];
306
- out.rec.push({ f, ...o });
307
- }
308
- return { J, frames: out, F, wing: fr, lengths: L };
309
- }
310
-
311
- // Segment lengths: from the species wing spec (reference size).
312
- export function wingLengths(J, w) { return { h: w.lengths[0], u: w.lengths[1], m: w.lengths[2] }; }
313
-
314
- export function degs(a) {
315
- return { elev: (a.elev || 0) * DEG, pitch: (a.pitch || 0) * DEG, alpha: (a.alpha || 0) * DEG, elbow: (a.elbow || 0) * DEG, wrist: (a.wrist || 0) * DEG, bend: (a.bend || 0) * DEG, twist: (a.twist || 0) * DEG, uTwist: (a.uTwist || 0) * DEG, tilt: (a.tilt || 0) * DEG };
316
- }
317
-
318
- // Wing joints (left) from the bind configuration.
319
- export function wingJoints(J, wingSpec) {
320
- const L = wingLengths(J, wingSpec);
321
- const fr = wingFK(makeWingFrames(), 1, L, degs({ ...wingSpec.bind, tilt: wingSpec.tilt }));
322
- const sh = J.shoulderL;
323
- J.elbowL = [sh[0] + fr.elbow.x, sh[1] + fr.elbow.y, sh[2] + fr.elbow.z];
324
- J.wristL = [sh[0] + fr.wrist.x, sh[1] + fr.wrist.y, sh[2] + fr.wrist.z];
325
- J.handTipL = [sh[0] + fr.tip.x, sh[1] + fr.tip.y, sh[2] + fr.tip.z];
326
- return fr;
327
- }
@@ -1,76 +0,0 @@
1
- // Standard quadruped skeleton (the names the quadruped motion engine expects).
2
- //
3
- // Axial: pelvis, spine1 (lumbar), spine2 (thoracolumbar), spine3 (thorax), chest, neck1, neck2, head, jaw
4
- // Front limb: scapula, humerus, radius, metacarpus (cannon in ungulates), fpaw (pastern + hoof in ungulates)
5
- // Hind limb: femur, tibia, metatarsus (cannon), hpaw
6
- // Joint names: nose, occiput, neckMid, neckBase, chestMid, thoraxRear, lumbarMid, lumbosacral, tailBase,
7
- // scapTop, shoulder, elbow, wrist, mcp, ftoe | hip, knee, hock, mtp, htoe (suffix L/R),
8
- // jawHinge, jawTip, earBase, earTip, tail1..tailN.
9
- // Plantigrade (bear, rat, rabbit hind) and unguligrade (hoofed) animals use the same names; only
10
- // the joint positions and the foot settings of the motion plan differ.
11
-
12
- export function quadrupedBones({ tailSegs = 10, ears = true, jaw = true, extra = [] } = {}) {
13
- const b = [
14
- ['pelvis', 'lumbosacral', 'tailBase', null, { region: 'torso' }],
15
- ['spine1', 'lumbosacral', 'lumbarMid', 'pelvis', { region: 'torso' }],
16
- ['spine2', 'lumbarMid', 'thoraxRear', 'spine1', { region: 'torso' }],
17
- ['spine3', 'thoraxRear', 'chestMid', 'spine2', { region: 'torso' }],
18
- ['chest', 'chestMid', 'neckBase', 'spine3', { region: 'torso' }],
19
- ['neck1', 'neckBase', 'neckMid', 'chest', { region: 'neck' }],
20
- ['neck2', 'neckMid', 'occiput', 'neck1', { region: 'neck' }],
21
- ['head', 'occiput', 'nose', 'neck2', { region: 'head' }],
22
- ];
23
- if (jaw) b.push(['jaw', 'jawHinge', 'jawTip', 'head', { region: 'jaw', group: 'jaw' }]);
24
- if (ears) b.push(['ear{S}', 'earBase{S}', 'earTip{S}', 'head', { region: 'ear', group: 'ear{S}' }]);
25
- b.push(
26
- ['scapula{S}', 'scapTop{S}', 'shoulder{S}', 'chest', { region: 'limb', group: 'F{S}' }],
27
- ['humerus{S}', 'shoulder{S}', 'elbow{S}', 'scapula{S}', { region: 'limb', group: 'F{S}' }],
28
- ['radius{S}', 'elbow{S}', 'wrist{S}', 'humerus{S}', { region: 'limb', group: 'F{S}' }],
29
- ['metacarpus{S}', 'wrist{S}', 'mcp{S}', 'radius{S}', { region: 'limb', group: 'F{S}' }],
30
- ['fpaw{S}', 'mcp{S}', 'ftoe{S}', 'metacarpus{S}', { region: 'foot', group: 'F{S}' }],
31
- ['femur{S}', 'hip{S}', 'knee{S}', 'pelvis', { region: 'limb', group: 'H{S}' }],
32
- ['tibia{S}', 'knee{S}', 'hock{S}', 'femur{S}', { region: 'limb', group: 'H{S}' }],
33
- ['metatarsus{S}', 'hock{S}', 'mtp{S}', 'tibia{S}', { region: 'limb', group: 'H{S}' }],
34
- ['hpaw{S}', 'mtp{S}', 'htoe{S}', 'metatarsus{S}', { region: 'foot', group: 'H{S}' }],
35
- );
36
- for (let i = 0; i < tailSegs; i++) b.push(['tail' + i, 'tail' + i, 'tail' + (i + 1), i === 0 ? 'pelvis' : 'tail' + (i - 1), { region: 'tail' }]);
37
- return b.concat(extra);
38
- }
39
-
40
- // Limb descriptions for the harmonic limb weights.
41
- // tCore: fraction of the way from the girdle top (scapTop / hip) to the elbow / knee below which
42
- // skin belongs rigidly to the limb; aCore / aBody: how much closer to the limb than to the
43
- // body (SDF distance, metres at unit 1) skin must be to count as limb core / body core;
44
- // midX: skin nearer the midline than this never follows the limb.
45
- export function quadrupedLimbs({ front, hind }) {
46
- const L = {};
47
- for (const S of ['L', 'R']) {
48
- const side = S === 'L' ? 1 : -1;
49
- L['F' + S] = {
50
- side, S, front: true,
51
- bones: ['scapula' + S, 'humerus' + S, 'radius' + S, 'metacarpus' + S, 'fpaw' + S],
52
- proximal: ['scapula' + S, 'humerus' + S], distal: ['metacarpus' + S, 'fpaw' + S],
53
- field: { a: 'scapTop' + S, b: 'elbow' + S, top: 'scapula' + S, ...front },
54
- };
55
- L['H' + S] = {
56
- side, S, front: false,
57
- bones: ['femur' + S, 'tibia' + S, 'metatarsus' + S, 'hpaw' + S],
58
- proximal: ['femur' + S], distal: ['metatarsus' + S, 'hpaw' + S],
59
- field: { a: 'hip' + S, b: 'knee' + S, top: 'femur' + S, ...hind },
60
- };
61
- }
62
- return L;
63
- }
64
-
65
- // Tail joints tail0..tailN from a base joint: per-segment pitch (degrees from horizontal, pointing
66
- // backwards) and lengths. Writes into J.
67
- export function tailChain(J, base, anglesDeg, lens, name = 'tail') {
68
- let p = J[base].slice();
69
- J[name + '0'] = p.slice();
70
- for (let i = 0; i < anglesDeg.length; i++) {
71
- const a = (anglesDeg[i] * Math.PI) / 180;
72
- p = [p[0], p[1] + Math.sin(a) * lens[i], p[2] - Math.cos(a) * lens[i]];
73
- J[name + (i + 1)] = p;
74
- }
75
- return J;
76
- }
@@ -1,79 +0,0 @@
1
- // Generic rig description. A species supplies joints (left side only for paired joints; the right
2
- // side is mirrored), a bone list and a few chains; this module turns that into the structures the
3
- // build pipeline and the motion engines use.
4
- //
5
- // Coordinates: metres, forward = +Z, up = +Y, the animal's left = +X. Bind pose stands on y = 0.
6
- //
7
- // Bone convention (shared with the skinning and the motion code): a bone's frame has its origin at
8
- // its head joint, +Y along the bone (head -> tail joint) and +X as close as possible to world +X.
9
- import { mirror, sub, norm, cross, len, dot } from '../math/vec.js';
10
-
11
- /**
12
- * @param {object} spec
13
- * joints: { name: [x,y,z] } names ending in L are mirrored to R
14
- * bones: [[name, headJoint, tailJoint, parent|null, { region, group }?], ...]
15
- * names containing '{S}' are expanded for S in L,R
16
- * axial: { points: [jointNames nose -> tail tip], bones: [boneNames between them] }
17
- * limbs: { FL: { side:'L', bones:[...], proximal:[...], distal:[...], field:{...} }, ... }
18
- * unit: characteristic length relative to the cheetah (shoulder height / 0.76 m)
19
- */
20
- export function buildRig(spec) {
21
- const J = {};
22
- for (const [k, v] of Object.entries(spec.joints)) J[k] = v.slice();
23
- for (const k of Object.keys(J)) if (k.endsWith('L') && !J[k.slice(0, -1) + 'R']) J[k.slice(0, -1) + 'R'] = mirror(J[k]);
24
- const defs = [];
25
- for (const d of spec.bones) {
26
- const [name, h, t, parent, meta = {}] = d;
27
- if (name.includes('{S}')) {
28
- for (const S of ['L', 'R']) {
29
- const r = (s) => (s ? s.replaceAll('{S}', S) : s);
30
- defs.push([r(name), r(h), r(t), r(parent), { ...meta, group: r(meta.group), side: S }]);
31
- }
32
- } else defs.push([name, h, t, parent, meta]);
33
- }
34
- const BONES = defs.map(([name, h, t, parent, meta], index) => {
35
- if (!J[h] || !J[t]) throw new Error(`bone ${name}: missing joint ${!J[h] ? h : t}`);
36
- return {
37
- name, index, headJ: h, tailJ: t, head: J[h], tail: J[t], parent,
38
- length: len(sub(J[t], J[h])),
39
- region: meta.region || 'torso',
40
- group: meta.group || 'axial',
41
- side: meta.side || null,
42
- };
43
- });
44
- const BONE = Object.fromEntries(BONES.map((b) => [b.name, b]));
45
- for (const b of BONES) if (b.parent && !BONE[b.parent]) throw new Error(`bone ${b.name}: unknown parent ${b.parent}`);
46
- const axial = spec.axial ? { points: spec.axial.points.map((p) => J[p]), names: spec.axial.points, bones: spec.axial.bones, blend: spec.axial.blend || {}, bodyTail: spec.axial.bodyTail, cascade: spec.axial.cascade || false } : null;
47
- const limbs = spec.limbs || {};
48
- return {
49
- J, BONES, BONE, AXIAL: axial, LIMBS: limbs,
50
- unit: spec.unit || 1,
51
- headOrigin: spec.headOrigin || null,
52
- meta: spec.meta || {},
53
- appendages: spec.appendages || [],
54
- webTags: spec.webTags || [],
55
- };
56
- }
57
-
58
- // Bone frame: origin at head joint, +Y along the bone, +X = lateral reference.
59
- export function boneFrame(head, tail, lateralRef = [1, 0, 0]) {
60
- const y = norm(sub(tail, head));
61
- let x = sub(lateralRef, [y[0] * dot(lateralRef, y), y[1] * dot(lateralRef, y), y[2] * dot(lateralRef, y)]);
62
- if (len(x) < 1e-6) x = [0, 0, 1];
63
- x = norm(x);
64
- const z = cross(x, y);
65
- return { x, y, z, o: head };
66
- }
67
-
68
- // Apply a point transform to every joint of a rig (used by the variation warps and by size scaling).
69
- export function transformRig(rig, f) {
70
- const J = {};
71
- for (const [k, v] of Object.entries(rig.J)) J[k] = f(v);
72
- const BONES = rig.BONES.map((b) => ({ ...b, head: J[b.headJ], tail: J[b.tailJ], length: len(sub(J[b.tailJ], J[b.headJ])) }));
73
- return {
74
- ...rig, J, BONES,
75
- BONE: Object.fromEntries(BONES.map((b) => [b.name, b])),
76
- AXIAL: rig.AXIAL ? { ...rig.AXIAL, points: rig.AXIAL.names.map((n) => J[n]) } : null,
77
- headOrigin: rig.headOrigin ? f(rig.headOrigin) : null,
78
- };
79
- }