@bitefoundry/retrieviewer 0.0.0-stage → 0.0.2

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 (297) hide show
  1. package/ASSET-PROVENANCE.md +43 -0
  2. package/ASSETS-LICENSE.md +58 -0
  3. package/ATTRIBUTION.md +54 -0
  4. package/EMBEDDING.md +96 -0
  5. package/INSTALLING.md +126 -0
  6. package/LICENSE +16 -0
  7. package/LICENSE-CODE +21 -0
  8. package/PLUGIN.md +110 -0
  9. package/PUPPY-MEMORY.md +57 -0
  10. package/PUPPY-Q5-COMPARISON.md +73 -0
  11. package/README.md +86 -2
  12. package/RELEASING.md +70 -0
  13. package/THIRD-PARTY-NOTICES.md +17 -0
  14. package/TRADEMARKS.md +21 -0
  15. package/WINDOWS-COMPANION.md +113 -0
  16. package/braille.mjs +45 -0
  17. package/examples/bridge.py +62 -0
  18. package/examples/embed.mjs +15 -0
  19. package/examples/live.mjs +40 -0
  20. package/examples/plugin.mjs +21 -0
  21. package/integrations/opencode/runtime.mjs +195 -0
  22. package/integrations/opencode/tui.tsx +59 -0
  23. package/integrations/windows-overlay/Overlay.cs +259 -0
  24. package/integrations/windows-overlay/desktop.mjs +87 -0
  25. package/integrations/windows-overlay/protocol.mjs +39 -0
  26. package/integrations/windows-overlay/worker.mjs +60 -0
  27. package/locomotion-core.mjs +21 -0
  28. package/locomotion-puppy.animal +0 -0
  29. package/package.json +131 -4
  30. package/pet-q5-manifest.json +118 -0
  31. package/puppy-clean.mjs +51 -0
  32. package/puppy-companion-interactions-v3-q5.bin.gz +0 -0
  33. package/puppy-companion-interactions-v3.json +1 -0
  34. package/puppy-companion-life.mjs +182 -0
  35. package/puppy-companion-objects.mjs +30 -0
  36. package/puppy-companion-sprites.mjs +14 -0
  37. package/puppy-continuous.mjs +57 -0
  38. package/puppy-face.mjs +46 -0
  39. package/puppy-frame-predictive.mjs +147 -0
  40. package/puppy-frame-store.mjs +108 -0
  41. package/puppy-mouth-anchor.json +1 -0
  42. package/puppy-mouth-anchor.mjs +33 -0
  43. package/puppy-paper-actions-v9-q5.bin.gz +0 -0
  44. package/puppy-paper-actions-v9.json +1 -0
  45. package/puppy-paper-actions.mjs +48 -0
  46. package/puppy-paper-approach-q5.bin.gz +0 -0
  47. package/puppy-paper-approach.json +1 -0
  48. package/puppy-paper-area.mjs +15 -0
  49. package/puppy-paper-arrival-seat-q5.bin.gz +0 -0
  50. package/puppy-paper-arrival-seat.json +1 -0
  51. package/puppy-paper-behaviors-q5.bin.gz +0 -0
  52. package/puppy-paper-behaviors.json +1 -0
  53. package/puppy-paper-behaviors.mjs +8 -0
  54. package/puppy-paper-contact.mjs +103 -0
  55. package/puppy-paper-director.mjs +21 -0
  56. package/puppy-paper-paw-transport.mjs +76 -0
  57. package/puppy-paper-rear-gallop-q5.bin.gz +0 -0
  58. package/puppy-paper-rear-gallop.json +1 -0
  59. package/puppy-paper-seat-q5.bin.gz +0 -0
  60. package/puppy-paper-seat.json +14 -0
  61. package/puppy-paper-seat.mjs +13 -0
  62. package/puppy-paper-trick-timing.mjs +58 -0
  63. package/puppy-paper-world.mjs +108 -0
  64. package/puppy-paper.mjs +271 -0
  65. package/puppy-stable-meta.json +1606 -0
  66. package/puppy-stable.mjs +72 -0
  67. package/puppy-stride-meta.json +343 -0
  68. package/puppy-stride-tweens-q5.bin.gz +0 -0
  69. package/puppy-zoomies.mjs +27 -0
  70. package/puppy-zoomies30.mjs +12 -0
  71. package/retrieviewer-cli.mjs +94 -0
  72. package/retrieviewer-config.mjs +49 -0
  73. package/retrieviewer-install.mjs +157 -0
  74. package/retrieviewer-plugin.d.mts +44 -0
  75. package/retrieviewer-plugin.mjs +97 -0
  76. package/retrieviewer-stdio.mjs +38 -0
  77. package/retrieviewer.d.mts +85 -0
  78. package/retrieviewer.mjs +142 -0
  79. package/vendor/procedural-animals/LICENSE +21 -0
  80. package/vendor/procedural-animals/package.json +40 -0
  81. package/vendor/procedural-animals/src/animal.js +146 -0
  82. package/vendor/procedural-animals/src/bake.js +51 -0
  83. package/vendor/procedural-animals/src/build.js +81 -0
  84. package/vendor/procedural-animals/src/core/build/coatKit.js +121 -0
  85. package/vendor/procedural-animals/src/core/build/featherCards.js +189 -0
  86. package/vendor/procedural-animals/src/core/build/finEdges.js +85 -0
  87. package/vendor/procedural-animals/src/core/build/furSlope.js +115 -0
  88. package/vendor/procedural-animals/src/core/build/mesh.js +67 -0
  89. package/vendor/procedural-animals/src/core/build/pipeline.js +272 -0
  90. package/vendor/procedural-animals/src/core/build/seams.js +183 -0
  91. package/vendor/procedural-animals/src/core/build/warp.js +112 -0
  92. package/vendor/procedural-animals/src/core/build/weights.js +393 -0
  93. package/vendor/procedural-animals/src/core/math/vec.js +81 -0
  94. package/vendor/procedural-animals/src/core/motion/actions.js +800 -0
  95. package/vendor/procedural-animals/src/core/motion/bird.js +3063 -0
  96. package/vendor/procedural-animals/src/core/motion/birdActions.js +1059 -0
  97. package/vendor/procedural-animals/src/core/motion/common.js +158 -0
  98. package/vendor/procedural-animals/src/core/motion/index.js +22 -0
  99. package/vendor/procedural-animals/src/core/motion/quadruped.js +2875 -0
  100. package/vendor/procedural-animals/src/core/motion/snake.js +1594 -0
  101. package/vendor/procedural-animals/src/core/motion/spider.js +1810 -0
  102. package/vendor/procedural-animals/src/core/motion/swimmer.js +1047 -0
  103. package/vendor/procedural-animals/src/core/motion/swimmerActions.js +613 -0
  104. package/vendor/procedural-animals/src/core/render/animalObject.js +262 -0
  105. package/vendor/procedural-animals/src/core/render/coatMaterial.js +1301 -0
  106. package/vendor/procedural-animals/src/core/render/dqs.js +159 -0
  107. package/vendor/procedural-animals/src/core/render/eyes.js +676 -0
  108. package/vendor/procedural-animals/src/core/render/membranes.js +77 -0
  109. package/vendor/procedural-animals/src/core/render/skeleton.js +41 -0
  110. package/vendor/procedural-animals/src/core/rig/bird.js +327 -0
  111. package/vendor/procedural-animals/src/core/rig/quadruped.js +76 -0
  112. package/vendor/procedural-animals/src/core/rig/rig.js +79 -0
  113. package/vendor/procedural-animals/src/core/rig/snake.js +76 -0
  114. package/vendor/procedural-animals/src/core/rig/spider.js +110 -0
  115. package/vendor/procedural-animals/src/core/rig/swimmer.js +181 -0
  116. package/vendor/procedural-animals/src/core/sdf/eyeSocket.js +53 -0
  117. package/vendor/procedural-animals/src/core/sdf/mesher.js +238 -0
  118. package/vendor/procedural-animals/src/core/sdf/sdf.js +263 -0
  119. package/vendor/procedural-animals/src/index.d.ts +98 -0
  120. package/vendor/procedural-animals/src/index.js +29 -0
  121. package/vendor/procedural-animals/src/registry.js +48 -0
  122. package/vendor/procedural-animals/src/species/bear/behaviour.js +463 -0
  123. package/vendor/procedural-animals/src/species/bear/claws.js +147 -0
  124. package/vendor/procedural-animals/src/species/bear/coat.js +726 -0
  125. package/vendor/procedural-animals/src/species/bear/index.js +139 -0
  126. package/vendor/procedural-animals/src/species/bear/motion.js +112 -0
  127. package/vendor/procedural-animals/src/species/bear/regions.js +78 -0
  128. package/vendor/procedural-animals/src/species/bear/rig.js +112 -0
  129. package/vendor/procedural-animals/src/species/bear/sculpt.js +272 -0
  130. package/vendor/procedural-animals/src/species/boar/behaviour.js +335 -0
  131. package/vendor/procedural-animals/src/species/boar/coat.js +372 -0
  132. package/vendor/procedural-animals/src/species/boar/index.js +110 -0
  133. package/vendor/procedural-animals/src/species/boar/motion.js +85 -0
  134. package/vendor/procedural-animals/src/species/boar/regions.js +88 -0
  135. package/vendor/procedural-animals/src/species/boar/rig.js +111 -0
  136. package/vendor/procedural-animals/src/species/boar/sculpt.js +285 -0
  137. package/vendor/procedural-animals/src/species/cat/behaviour.js +559 -0
  138. package/vendor/procedural-animals/src/species/cat/coat.js +841 -0
  139. package/vendor/procedural-animals/src/species/cat/index.js +211 -0
  140. package/vendor/procedural-animals/src/species/cat/motion.js +101 -0
  141. package/vendor/procedural-animals/src/species/cat/regions.js +82 -0
  142. package/vendor/procedural-animals/src/species/cat/rig.js +100 -0
  143. package/vendor/procedural-animals/src/species/cat/sculpt.js +266 -0
  144. package/vendor/procedural-animals/src/species/cat/whiskers.js +110 -0
  145. package/vendor/procedural-animals/src/species/cheetah/coat.js +427 -0
  146. package/vendor/procedural-animals/src/species/cheetah/index.js +51 -0
  147. package/vendor/procedural-animals/src/species/cheetah/joints.js +3 -0
  148. package/vendor/procedural-animals/src/species/cheetah/motion.js +77 -0
  149. package/vendor/procedural-animals/src/species/cheetah/regions.js +95 -0
  150. package/vendor/procedural-animals/src/species/cheetah/rig.js +66 -0
  151. package/vendor/procedural-animals/src/species/cheetah/sculpt.js +158 -0
  152. package/vendor/procedural-animals/src/species/chicken/coat.js +313 -0
  153. package/vendor/procedural-animals/src/species/chicken/coverts.js +320 -0
  154. package/vendor/procedural-animals/src/species/chicken/index.js +110 -0
  155. package/vendor/procedural-animals/src/species/chicken/motion.js +177 -0
  156. package/vendor/procedural-animals/src/species/chicken/regions.js +66 -0
  157. package/vendor/procedural-animals/src/species/chicken/rig.js +144 -0
  158. package/vendor/procedural-animals/src/species/chicken/sculpt.js +389 -0
  159. package/vendor/procedural-animals/src/species/chicken/wingLook.js +66 -0
  160. package/vendor/procedural-animals/src/species/chicken/wingStack.js +124 -0
  161. package/vendor/procedural-animals/src/species/cow/behaviour.js +521 -0
  162. package/vendor/procedural-animals/src/species/cow/coat.js +465 -0
  163. package/vendor/procedural-animals/src/species/cow/index.js +118 -0
  164. package/vendor/procedural-animals/src/species/cow/motion.js +81 -0
  165. package/vendor/procedural-animals/src/species/cow/regions.js +98 -0
  166. package/vendor/procedural-animals/src/species/cow/rig.js +116 -0
  167. package/vendor/procedural-animals/src/species/cow/sculpt.js +339 -0
  168. package/vendor/procedural-animals/src/species/crow/coat.js +145 -0
  169. package/vendor/procedural-animals/src/species/crow/index.js +70 -0
  170. package/vendor/procedural-animals/src/species/crow/joints.js +3 -0
  171. package/vendor/procedural-animals/src/species/crow/motion.js +101 -0
  172. package/vendor/procedural-animals/src/species/crow/regions.js +50 -0
  173. package/vendor/procedural-animals/src/species/crow/rig.js +83 -0
  174. package/vendor/procedural-animals/src/species/crow/sculpt.js +118 -0
  175. package/vendor/procedural-animals/src/species/deer/behaviour.js +513 -0
  176. package/vendor/procedural-animals/src/species/deer/coat.js +391 -0
  177. package/vendor/procedural-animals/src/species/deer/index.js +106 -0
  178. package/vendor/procedural-animals/src/species/deer/motion.js +97 -0
  179. package/vendor/procedural-animals/src/species/deer/regions.js +60 -0
  180. package/vendor/procedural-animals/src/species/deer/rig.js +124 -0
  181. package/vendor/procedural-animals/src/species/deer/sculpt.js +297 -0
  182. package/vendor/procedural-animals/src/species/dog/behaviour.js +521 -0
  183. package/vendor/procedural-animals/src/species/dog/coat.js +495 -0
  184. package/vendor/procedural-animals/src/species/dog/index.js +144 -0
  185. package/vendor/procedural-animals/src/species/dog/motion.js +118 -0
  186. package/vendor/procedural-animals/src/species/dog/regions.js +61 -0
  187. package/vendor/procedural-animals/src/species/dog/rig.js +129 -0
  188. package/vendor/procedural-animals/src/species/dog/sculpt.js +246 -0
  189. package/vendor/procedural-animals/src/species/eagle/coat.js +250 -0
  190. package/vendor/procedural-animals/src/species/eagle/index.js +76 -0
  191. package/vendor/procedural-animals/src/species/eagle/joints.js +3 -0
  192. package/vendor/procedural-animals/src/species/eagle/motion.js +137 -0
  193. package/vendor/procedural-animals/src/species/eagle/regions.js +57 -0
  194. package/vendor/procedural-animals/src/species/eagle/rig.js +107 -0
  195. package/vendor/procedural-animals/src/species/eagle/sculpt.js +137 -0
  196. package/vendor/procedural-animals/src/species/fish/coat.js +271 -0
  197. package/vendor/procedural-animals/src/species/fish/index.js +88 -0
  198. package/vendor/procedural-animals/src/species/fish/motion.js +92 -0
  199. package/vendor/procedural-animals/src/species/fish/regions.js +27 -0
  200. package/vendor/procedural-animals/src/species/fish/rig.js +143 -0
  201. package/vendor/procedural-animals/src/species/fish/sculpt.js +214 -0
  202. package/vendor/procedural-animals/src/species/fish/variants.js +126 -0
  203. package/vendor/procedural-animals/src/species/fox/behaviour.js +314 -0
  204. package/vendor/procedural-animals/src/species/fox/coat.js +444 -0
  205. package/vendor/procedural-animals/src/species/fox/index.js +120 -0
  206. package/vendor/procedural-animals/src/species/fox/motion.js +81 -0
  207. package/vendor/procedural-animals/src/species/fox/regions.js +59 -0
  208. package/vendor/procedural-animals/src/species/fox/rig.js +91 -0
  209. package/vendor/procedural-animals/src/species/fox/sculpt.js +202 -0
  210. package/vendor/procedural-animals/src/species/frog/behaviour.js +590 -0
  211. package/vendor/procedural-animals/src/species/frog/coat.js +305 -0
  212. package/vendor/procedural-animals/src/species/frog/index.js +97 -0
  213. package/vendor/procedural-animals/src/species/frog/motion.js +69 -0
  214. package/vendor/procedural-animals/src/species/frog/regions.js +46 -0
  215. package/vendor/procedural-animals/src/species/frog/rig.js +156 -0
  216. package/vendor/procedural-animals/src/species/frog/sculpt.js +240 -0
  217. package/vendor/procedural-animals/src/species/goat/behaviour.js +509 -0
  218. package/vendor/procedural-animals/src/species/goat/coat.js +590 -0
  219. package/vendor/procedural-animals/src/species/goat/index.js +149 -0
  220. package/vendor/procedural-animals/src/species/goat/motion.js +95 -0
  221. package/vendor/procedural-animals/src/species/goat/regions.js +98 -0
  222. package/vendor/procedural-animals/src/species/goat/rig.js +181 -0
  223. package/vendor/procedural-animals/src/species/goat/sculpt.js +547 -0
  224. package/vendor/procedural-animals/src/species/horse/coat.js +361 -0
  225. package/vendor/procedural-animals/src/species/horse/coatSeam.js +122 -0
  226. package/vendor/procedural-animals/src/species/horse/index.js +80 -0
  227. package/vendor/procedural-animals/src/species/horse/motion.js +245 -0
  228. package/vendor/procedural-animals/src/species/horse/regions.js +60 -0
  229. package/vendor/procedural-animals/src/species/horse/rig.js +117 -0
  230. package/vendor/procedural-animals/src/species/horse/sculpt.js +316 -0
  231. package/vendor/procedural-animals/src/species/horse/seamWeights.js +272 -0
  232. package/vendor/procedural-animals/src/species/lion/behaviour.js +509 -0
  233. package/vendor/procedural-animals/src/species/lion/coat.js +1016 -0
  234. package/vendor/procedural-animals/src/species/lion/index.js +111 -0
  235. package/vendor/procedural-animals/src/species/lion/motion.js +87 -0
  236. package/vendor/procedural-animals/src/species/lion/regions.js +106 -0
  237. package/vendor/procedural-animals/src/species/lion/rig.js +110 -0
  238. package/vendor/procedural-animals/src/species/lion/sculpt.js +384 -0
  239. package/vendor/procedural-animals/src/species/lion/whiskers.js +132 -0
  240. package/vendor/procedural-animals/src/species/pig/behaviour.js +575 -0
  241. package/vendor/procedural-animals/src/species/pig/coat.js +730 -0
  242. package/vendor/procedural-animals/src/species/pig/ears.js +242 -0
  243. package/vendor/procedural-animals/src/species/pig/index.js +161 -0
  244. package/vendor/procedural-animals/src/species/pig/motion.js +105 -0
  245. package/vendor/procedural-animals/src/species/pig/regions.js +100 -0
  246. package/vendor/procedural-animals/src/species/pig/rig.js +152 -0
  247. package/vendor/procedural-animals/src/species/pig/sculpt.js +382 -0
  248. package/vendor/procedural-animals/src/species/rabbit/behaviour.js +605 -0
  249. package/vendor/procedural-animals/src/species/rabbit/coat.js +285 -0
  250. package/vendor/procedural-animals/src/species/rabbit/index.js +85 -0
  251. package/vendor/procedural-animals/src/species/rabbit/motion.js +85 -0
  252. package/vendor/procedural-animals/src/species/rabbit/regions.js +48 -0
  253. package/vendor/procedural-animals/src/species/rabbit/rig.js +99 -0
  254. package/vendor/procedural-animals/src/species/rabbit/sculpt.js +148 -0
  255. package/vendor/procedural-animals/src/species/rat/behaviour.js +539 -0
  256. package/vendor/procedural-animals/src/species/rat/coat.js +341 -0
  257. package/vendor/procedural-animals/src/species/rat/index.js +111 -0
  258. package/vendor/procedural-animals/src/species/rat/motion.js +90 -0
  259. package/vendor/procedural-animals/src/species/rat/regions.js +92 -0
  260. package/vendor/procedural-animals/src/species/rat/rig.js +112 -0
  261. package/vendor/procedural-animals/src/species/rat/sculpt.js +163 -0
  262. package/vendor/procedural-animals/src/species/rat/whiskers.js +119 -0
  263. package/vendor/procedural-animals/src/species/shark/coat.js +383 -0
  264. package/vendor/procedural-animals/src/species/shark/index.js +104 -0
  265. package/vendor/procedural-animals/src/species/shark/motion.js +69 -0
  266. package/vendor/procedural-animals/src/species/shark/regions.js +34 -0
  267. package/vendor/procedural-animals/src/species/shark/rig.js +194 -0
  268. package/vendor/procedural-animals/src/species/shark/sculpt.js +343 -0
  269. package/vendor/procedural-animals/src/species/shark/variants.js +105 -0
  270. package/vendor/procedural-animals/src/species/sheep/behaviour.js +522 -0
  271. package/vendor/procedural-animals/src/species/sheep/coat.js +529 -0
  272. package/vendor/procedural-animals/src/species/sheep/index.js +152 -0
  273. package/vendor/procedural-animals/src/species/sheep/motion.js +86 -0
  274. package/vendor/procedural-animals/src/species/sheep/neck.js +41 -0
  275. package/vendor/procedural-animals/src/species/sheep/regions.js +62 -0
  276. package/vendor/procedural-animals/src/species/sheep/rig.js +163 -0
  277. package/vendor/procedural-animals/src/species/sheep/sculpt.js +542 -0
  278. package/vendor/procedural-animals/src/species/snake/coat.js +315 -0
  279. package/vendor/procedural-animals/src/species/snake/index.js +73 -0
  280. package/vendor/procedural-animals/src/species/snake/motion.js +51 -0
  281. package/vendor/procedural-animals/src/species/snake/regions.js +51 -0
  282. package/vendor/procedural-animals/src/species/snake/rig.js +108 -0
  283. package/vendor/procedural-animals/src/species/snake/sculpt.js +122 -0
  284. package/vendor/procedural-animals/src/species/spider/coat.js +279 -0
  285. package/vendor/procedural-animals/src/species/spider/index.js +78 -0
  286. package/vendor/procedural-animals/src/species/spider/motion.js +72 -0
  287. package/vendor/procedural-animals/src/species/spider/regions.js +87 -0
  288. package/vendor/procedural-animals/src/species/spider/rig.js +118 -0
  289. package/vendor/procedural-animals/src/species/spider/sculpt.js +182 -0
  290. package/vendor/procedural-animals/src/species/wolf/behaviour.js +160 -0
  291. package/vendor/procedural-animals/src/species/wolf/coat.js +749 -0
  292. package/vendor/procedural-animals/src/species/wolf/index.js +107 -0
  293. package/vendor/procedural-animals/src/species/wolf/motion.js +80 -0
  294. package/vendor/procedural-animals/src/species/wolf/regions.js +57 -0
  295. package/vendor/procedural-animals/src/species/wolf/rig.js +87 -0
  296. package/vendor/procedural-animals/src/species/wolf/sculpt.js +339 -0
  297. package/vendor/procedural-animals/src/worker.js +29 -0
@@ -0,0 +1,124 @@
1
+ // White-tailed deer skeleton in bind pose (metres). Forward = +Z, up = +Y, the animal's left = +X.
2
+ // Reference individual: an adult white-tailed deer of 0.92 m at the withers (a doe / young buck,
3
+ // ~55 kg). Bucks are built from it by the seeded size (x 1.08), fawns at x 0.5 with long legs.
4
+ // Landmarks measured on side_buck2.jpg / side_full.jpg (normalised to the withers height) and the
5
+ // limb-bone lengths of OsteoID: point of shoulder 0.64 m, elbow 0.49,
6
+ // carpus 0.28, fore fetlock 0.085, stifle 0.54, hock 0.33, hind fetlock 0.085; body length (point
7
+ // of shoulder -> point of buttock) 0.98 m.
8
+ //
9
+ // Hooves as on the horse: the standard quadruped bones plus a hoof bone per leg (fpaw / hpaw =
10
+ // pastern, fetlock -> coffin joint; fhoof / hhoof = the cloven hoof, coffin joint -> toe).
11
+ import { buildRig } from '../../core/rig/rig.js';
12
+ import { quadrupedBones, quadrupedLimbs, tailChain } from '../../core/rig/quadruped.js';
13
+
14
+ export const TAIL_SEGS = 6;
15
+
16
+ // Head frame: modelled along its own axis (poll -> nose), pitched 50 degrees nose down in the bind
17
+ // pose. Head-local coordinates: x lateral, y dorsal (forehead side), z along the nasal line toward
18
+ // the nose; origin on the axis 0.09 m in front of the poll, level with the eyes.
19
+ export const HEAD_PITCH = (50 * Math.PI) / 180;
20
+ export const HZ = [0, -Math.sin(HEAD_PITCH), Math.cos(HEAD_PITCH)];
21
+ export const HY = [0, Math.cos(HEAD_PITCH), Math.sin(HEAD_PITCH)];
22
+ export const POLL = [0, 1.2, 0.5]; // top of the poll (skin), bind
23
+ export const HEAD_O = [0, POLL[1] + 0.09 * HZ[1] - 0.035 * HY[1], POLL[2] + 0.09 * HZ[2] - 0.035 * HY[2]];
24
+ export const hl = (v) => [HEAD_O[0] + v[0], HEAD_O[1] + v[1] * HY[1] + v[2] * HZ[1], HEAD_O[2] + v[1] * HY[2] + v[2] * HZ[2]];
25
+ // head-local direction -> world
26
+ export const hdir = (v) => [v[0], v[1] * HY[1] + v[2] * HZ[1], v[1] * HY[2] + v[2] * HZ[2]];
27
+
28
+ // The barrel between the fore and hind legs is long in the photos (point of shoulder -> stifle
29
+ // 0.96-1.2 withers heights in side_buck2 / side1, chest front -> rump rear 1.26-1.5): everything from
30
+ // the loin back sits LOIN further back than the first build had it (0.75 / 1.14-1.19 WH, a short,
31
+ // boxy trunk). bz(z) maps a reference z of that first layout to the lengthened body (the loin and
32
+ // flank stretch between z -0.1 and -0.25, the hindquarters move back rigidly).
33
+ export const LOIN = 0.1;
34
+ const sstep = (a, b, x) => { const t = Math.min(1, Math.max(0, (x - a) / (b - a))); return t * t * (3 - 2 * t); };
35
+ export const bz = (z) => z - LOIN * sstep(-0.1, -0.25, z);
36
+ const B = (v) => [v[0], v[1], bz(v[2])];
37
+
38
+ export function deerJoints() {
39
+ const J = {
40
+ nose: hl([0, -0.005, 0.19]),
41
+ occiput: hl([0, -0.01, -0.085]),
42
+ // the neck leaves the chest low, at the thoracic inlet in front of the shoulders (not at the
43
+ // withers): a grazing deer swings it down to the ground on straight forelegs
44
+ neckMid: [0, 0.945, 0.425],
45
+ neckBase: [0, 0.7, 0.355],
46
+ chestMid: [0, 0.8, 0.2],
47
+ thoraxRear: [0, 0.81, -0.02],
48
+ lumbarMid: B([0, 0.83, -0.2]),
49
+ lumbosacral: B([0, 0.845, -0.34]),
50
+ tailBase: B([0, 0.83, -0.56]),
51
+ // fore: scapula sloping ~55 deg, humerus down and back, radius and cannon near vertical, the
52
+ // pastern ~50 deg to the ground, a small cloven hoof
53
+ scapTopL: [0.055, 0.87, 0.26],
54
+ shoulderL: [0.095, 0.64, 0.405],
55
+ elbowL: [0.088, 0.495, 0.3],
56
+ wristL: [0.074, 0.28, 0.345],
57
+ mcpL: [0.07, 0.085, 0.35],
58
+ fcoffinL: [0.07, 0.032, 0.385],
59
+ ftoeL: [0.07, 0.003, 0.43],
60
+ // hind: hip joint, stifle, hock, fetlock, coffin joint, toe. Long tibia and metatarsus (the
61
+ // cursorial look), hock well behind the hip
62
+ hipL: B([0.085, 0.745, -0.38]),
63
+ kneeL: B([0.1, 0.54, -0.285]),
64
+ hockL: B([0.074, 0.33, -0.49]),
65
+ mtpL: B([0.068, 0.085, -0.455]),
66
+ hcoffinL: B([0.068, 0.031, -0.42]),
67
+ htoeL: B([0.068, 0.003, -0.377]),
68
+ jawHinge: hl([0, -0.045, -0.035]),
69
+ jawTip: hl([0, -0.062, 0.17]),
70
+ // large mobile ears carried up and out in a wide V (~45 deg above the horizontal)
71
+ earBaseL: hl([0.034, 0.03, -0.055]),
72
+ earTipL: [0, 0, 0],
73
+ };
74
+ // ear direction: lateral + world up (head-local: world up = (0, cos p, -sin p)), a little back
75
+ const up = [0, Math.cos(HEAD_PITCH), -Math.sin(HEAD_PITCH)];
76
+ const d = [0.85, 0.52 * up[1] - 0.1, 0.52 * up[2] - 0.14];
77
+ const n = Math.hypot(...d);
78
+ const b = [0.034, 0.03, -0.055];
79
+ J.earTipL = hl([b[0] + (0.145 * d[0]) / n, b[1] + (0.145 * d[1]) / n, b[2] + (0.145 * d[2]) / n]);
80
+ // tail hangs flat against the rump (brown side out), 0.24 m
81
+ tailChain(J, 'tailBase', [-45, -62, -72, -78, -80, -80], [0.04, 0.04, 0.04, 0.04, 0.04, 0.04]);
82
+ return J;
83
+ }
84
+
85
+ export function deerBones() {
86
+ const b = quadrupedBones({ tailSegs: TAIL_SEGS, ears: true, jaw: true });
87
+ for (const d of b) {
88
+ if (d[0] === 'fpaw{S}') { d[2] = 'fcoffin{S}'; d[4] = { region: 'limb', group: 'F{S}' }; }
89
+ if (d[0] === 'hpaw{S}') { d[2] = 'hcoffin{S}'; d[4] = { region: 'limb', group: 'H{S}' }; }
90
+ }
91
+ b.push(
92
+ ['fhoof{S}', 'fcoffin{S}', 'ftoe{S}', 'fpaw{S}', { region: 'foot', group: 'F{S}' }],
93
+ ['hhoof{S}', 'hcoffin{S}', 'htoe{S}', 'hpaw{S}', { region: 'foot', group: 'H{S}' }],
94
+ );
95
+ return b;
96
+ }
97
+
98
+ export function deerRig(J = deerJoints()) {
99
+ const limbs = quadrupedLimbs({
100
+ front: { tCore: 0.55, aCore: 0.055, aBody: -0.1, midX: 0.0 },
101
+ hind: { tCore: 0.5, aCore: 0.022, aBody: -0.08, midX: 0.008 },
102
+ });
103
+ for (const L of Object.values(limbs)) { L.bones.push((L.front ? 'fhoof' : 'hhoof') + L.S); L.distal.push((L.front ? 'fhoof' : 'hhoof') + L.S); }
104
+ return buildRig({
105
+ joints: J,
106
+ unit: 0.92 / 0.76,
107
+ headOrigin: HEAD_O,
108
+ bones: deerBones(),
109
+ axial: {
110
+ points: ['nose', 'occiput', 'neckMid', 'neckBase', 'chestMid', 'thoraxRear', 'lumbarMid', 'lumbosacral', 'tailBase', ...Array.from({ length: TAIL_SEGS }, (_, i) => 'tail' + (i + 1))],
111
+ bones: ['head', 'neck2', 'neck1', 'chest', 'spine3', 'spine2', 'spine1', 'pelvis', ...Array.from({ length: TAIL_SEGS }, (_, i) => 'tail' + i)],
112
+ // the skull's influence reaches back into the throat latch (3rd value: the blend widens with
113
+ // the skin's distance from the axis on the ventral side, the throat under the jaw)
114
+ blend: { 1: [-0.03, 0.12, 6], 3: [-0.12, 0.12, 2] },
115
+ bodyTail: 0, // the tail lies flat on the rump: body skin blends into it only at the tail base
116
+ },
117
+ limbs,
118
+ appendages: [
119
+ { group: 'earL', bone: 'earL', blend: [-0.002, 0.004] },
120
+ { group: 'earR', bone: 'earR', blend: [-0.002, 0.004] },
121
+ ],
122
+ webTags: ['flankfold', 'thighfront', 'scapmuscle', 'pectoral', 'forearmweb'],
123
+ });
124
+ }
@@ -0,0 +1,297 @@
1
+ // The white-tailed deer, sculpted as a signed distance field.
2
+ // Every primitive is attached to a bone (skinning) and a group (axial / limb / ear / jaw).
3
+ // The head is modelled in its own frame (rig.js: hl()), measured from the profile and face
4
+ // references; the body relative to the joints so the sculpt follows the skeleton. Antlers are rigid
5
+ // bone-coloured geometry on the head bone, meshed as their own region ('antler' part).
6
+ import { HEAD_O, HZ, HY, hl, hdir, TAIL_SEGS, bz } from './rig.js';
7
+ import { add, sub, mul, lerp, norm, cross, rng } from '../../core/math/vec.js';
8
+ import { eyeFrameOf, sculptEyeSocket } from '../../core/sdf/eyeSocket.js';
9
+
10
+ // Eye (head-local centre -> offset from HEAD_O): globe ~27 mm, palpebral opening ~30 x 18 mm, set
11
+ // high on the side of the skull, looking out and a little forward.
12
+ const EYE_LOCAL = [0.05, 0.006, 0.0];
13
+ const eyeDir = (() => {
14
+ const a = (18 * Math.PI) / 180;
15
+ return norm(add([Math.cos(a), 0, 0], mul(HZ, Math.sin(a))));
16
+ })();
17
+ const EYE_BASE = {
18
+ c: sub(hl(EYE_LOCAL), HEAD_O), r: 0.015, back: 0.003, yaw: Math.atan2(eyeDir[0], eyeDir[2]), pitch: Math.asin(eyeDir[1]),
19
+ lid: 0.0017, R: 0.019, d: 0.009, off: -0.0006, tilt: 0, irisZ: 0.0082, irisR: 0.0116,
20
+ };
21
+ // roll the almond so its long axis follows the nasal line (inner corner toward the nose, lower)
22
+ EYE_BASE.tilt = (() => {
23
+ let best = 0, bd = -2;
24
+ for (let t = -1.6; t <= 1.6; t += 0.005) {
25
+ const f = eyeFrameOf({ ...EYE_BASE, tilt: t }, HEAD_O, 1);
26
+ const d = f.x[0] * HZ[0] + f.x[1] * HZ[1] + f.x[2] * HZ[2];
27
+ if (d > bd) { bd = d; best = t; }
28
+ }
29
+ return best - 0.18;
30
+ })();
31
+ export const EYE = EYE_BASE;
32
+
33
+ const X = [1, 0, 0];
34
+
35
+ export function sculptDeer(m, rig, params = {}) {
36
+ const J = rig.J;
37
+ const fawn = params.age === 'juvenile';
38
+ const neckK = params.neck ?? 0; // 0 doe .. 1 buck in rut (swollen neck)
39
+
40
+ const ellY = (o) => {
41
+ const y = norm(o.ydir);
42
+ const lat = o.lateral || X;
43
+ const z = norm(cross(lat, y));
44
+ return m.ell({ ...o, axis: z, up: y, r: [o.r[0], o.r[1], o.r[2]] });
45
+ };
46
+ const H = { bone: 'head' };
47
+ const hell = (o) => m.ell({ ...H, ...o, c: hl(o.c), axis: o.axisL ? norm(hdir(o.axisL)) : HZ, up: o.upL ? norm(hdir(o.upL)) : HY });
48
+
49
+ // ---------------------------------------------------------------- TORSO
50
+ // slim barrel, deep narrow chest (sternum ~0.47 m), belly tucked up toward the flank; a long loin
51
+ // and flank (rig.js: bz), a straight back and a smooth flank with the shoulder and hip only hinted
52
+ m.ell({ tag: 'ribcage', bone: 'spine3', c: [0, 0.665, 0.055], r: [0.155, 0.195, 0.345], axis: norm([0, 0.05, 1]), k: 0 });
53
+ m.ell({ tag: 'girth', bone: 'chest', c: [0, 0.64, 0.26], r: [0.13, 0.165, 0.13], k: 0.05 });
54
+ m.ell({ tag: 'abdomen', bone: 'spine2', c: [0, 0.67, -0.19], r: [0.16, 0.165, 0.25], axis: norm([0, 0.14, -1]), k: 0.06 });
55
+ m.ell({ tag: 'flank', bone: 'spine1', c: [0, 0.73, bz(-0.29)], r: [0.14, 0.125, 0.16], k: 0.07 });
56
+ // withers: the dorsal spines make a low ridge between the scapulae
57
+ m.ell({ tag: 'withers', bone: 'chest', c: [0, 0.86, 0.24], r: [0.035, 0.055, 0.14], axis: norm([0, -0.2, 1]), k: 0.08 });
58
+ m.ell({ tag: 'back', bone: 'spine3', c: [0, 0.845, -0.02], r: [0.085, 0.045, 0.27], k: 0.07 });
59
+ m.ell({ tag: 'loin', bone: 'spine1', c: [0, 0.855, -0.25], r: [0.095, 0.045, 0.2], k: 0.07 });
60
+ // hindquarters: croup (a little higher than the withers), points of hip, buttocks
61
+ m.ell({ tag: 'pelvis', bone: 'pelvis', c: [0, 0.8, bz(-0.41)], r: [0.138, 0.12, 0.15], k: 0.05 });
62
+ m.ell({ tag: 'croup', bone: 'pelvis', c: [0, 0.855, bz(-0.4)], r: [0.095, 0.05, 0.16], axis: norm([0, -0.1, 1]), k: 0.06 });
63
+ for (const s of [1, -1]) {
64
+ m.sphere({ tag: 'hippoint', bone: 'pelvis', c: [0.105 * s, 0.835, bz(-0.29)], rad: 0.025, k: 0.07 });
65
+ m.ell({ tag: 'rump', bone: 'pelvis', c: [0.065 * s, 0.77, bz(-0.5)], r: [0.07, 0.11, 0.07], k: 0.05 });
66
+ }
67
+ // chest front: narrow breast between the forelegs (no pouter-pigeon bulge in front of them)
68
+ m.ell({ tag: 'brisket', bone: 'chest', c: [0, 0.575, 0.31], r: [0.075, 0.085, 0.08], k: 0.05 });
69
+ for (const s of [1, -1]) m.ell({ tag: 'pectoral', bone: 'chest', c: [0.048 * s, 0.585, 0.365], r: [0.04, 0.06, 0.035], k: 0.045 });
70
+
71
+ // ---------------------------------------------------------------- NECK
72
+ // slender and laterally flattened in does, swollen in rutting bucks
73
+ const nb = J.neckBase, nm = J.neckMid, occ = J.occiput;
74
+ const nd1 = norm(sub(nm, nb)), nd2 = norm(sub(occ, nm));
75
+ const nk = 1 + 0.3 * neckK;
76
+ const up1 = [0, 0.6, -1];
77
+ m.ell({ tag: 'neck', bone: 'neck1', c: add(lerp(nb, nm, 0.15), [0, 0.012, -0.012]), r: [0.07 * nk, 0.1 * nk, 0.1], axis: nd1, up: up1, k: 0.06 });
78
+ m.ell({ tag: 'neck', bone: 'neck1', c: add(lerp(nb, nm, 0.65), [0, -0.01, 0.005]), r: [0.05 * nk, 0.085 * nk, 0.1], axis: nd1, up: up1, k: 0.05 });
79
+ m.ell({ tag: 'neck', bone: 'neck2', c: add(lerp(nm, occ, 0.5), [0, -0.02, 0.01]), r: [0.043 * (1 + 0.2 * neckK), 0.066 * (1 + 0.2 * neckK), 0.075], axis: nd2, up: up1, k: 0.045 });
80
+ m.ell({ tag: 'crest', bone: 'neck1', c: add(lerp(nb, nm, 0.55), [0, 0.03 + 0.01 * neckK, -0.04]), r: [0.03 + 0.02 * neckK, 0.03 + 0.015 * neckK, 0.12], axis: nd1, k: 0.05 });
81
+ // underline of the neck (trachea) from the breast to the throat latch
82
+ const thr = hl([0, -0.068, -0.045]);
83
+ m.cone({ tag: 'throat', bone: 'neck1', a: [0, 0.67, 0.36], b: add(lerp([0, 0.67, 0.36], thr, 0.55), [0, 0, 0.0]), ra: 0.04 * nk, rb: 0.04 * nk, k: 0.05 });
84
+ m.cone({ tag: 'throat', bone: 'neck2', a: lerp([0, 0.67, 0.36], thr, 0.5), b: thr, ra: 0.04 * nk, rb: 0.032, k: 0.045 });
85
+
86
+ // ---------------------------------------------------------------- HEAD (head-local, see rig.js)
87
+ // landmarks (doe, poll -> nose 0.28 m): forehead y 0.035 at z 0, nasal bridge 0.022 at 0.12,
88
+ // nose top 0.012 at 0.17, nose tip z 0.195; jaw angle y -0.075 at z -0.045, chin y -0.05 at 0.16;
89
+ // eyes (+-0.047, 0.006, 0); skull 0.105 wide across the orbits, muzzle 0.045
90
+ hell({ tag: 'cranium', c: [0, 0.0, -0.035], r: [0.049, 0.04, 0.062], k: 0.03 });
91
+ hell({ tag: 'poll', c: [0, -0.005, -0.07], r: [0.036, 0.038, 0.035], k: 0.03 });
92
+ hell({ tag: 'forehead', c: [0, 0.014, 0.02], r: [0.046, 0.022, 0.058], k: 0.025 });
93
+ hell({ tag: 'face', c: [0, 0.006, 0.1], r: [0.031, 0.021, 0.09], k: 0.025 });
94
+ hell({ tag: 'lowerface', c: [0, -0.024, 0.085], r: [0.034, 0.037, 0.085], k: 0.03 });
95
+ hell({ tag: 'muzzle', c: [0, -0.014, 0.16], r: [0.027, 0.027, 0.032], k: 0.02 });
96
+ hell({ tag: 'nose', c: [0, -0.006, 0.182], r: [0.024, 0.021, 0.015], k: 0.012 });
97
+ hell({ tag: 'upperlip', c: [0, -0.034, 0.17], r: [0.018, 0.012, 0.022], k: 0.012 });
98
+ for (const s of [1, -1]) {
99
+ // masseter (cheek) and the mandible's lower border from the jaw angle to the chin
100
+ hell({ tag: 'cheek', c: [0.031 * s, -0.04, -0.01], r: [0.024, 0.036, 0.05], k: 0.025 });
101
+ m.cone({ ...H, tag: 'mandible', a: hl([0.027 * s, -0.068, -0.045]), b: hl([0.017 * s, -0.052, 0.12]), ra: 0.014, rb: 0.01, k: 0.02 });
102
+ hell({ tag: 'brow', c: [0.043 * s, 0.022, -0.002], r: [0.014, 0.01, 0.022], k: 0.015 });
103
+ hell({ tag: 'nostrilwing', c: [0.019 * s, -0.012, 0.18], r: [0.011, 0.015, 0.016], k: 0.01 });
104
+ sculptEyeSocket(m, EYE, HEAD_O, s, { orbit: { r: [0.017, 0.012, 0.01], at: [0.0, 0.001, 0.016], k: 0.007 } });
105
+ // preorbital (lacrimal) gland: a dark slit in front of the inner corner
106
+ hell({ tag: 'preorbital', c: [0.045 * s, -0.004, 0.034], r: [0.004, 0.0035, 0.011], axisL: [-0.35 * s, -0.15, 1], k: 0.004, carve: true });
107
+ // nostrils: comma-shaped, opening forward and out
108
+ hell({ tag: 'nostril', c: [0.014 * s, -0.01, 0.194], r: [0.0045, 0.009, 0.007], axisL: [0.3 * s, -0.2, 1], upL: [0.5 * s, 1, 0], k: 0.003, carve: true });
109
+ }
110
+
111
+ // ---------------------------------------------------------------- JAW (lower lip and chin)
112
+ const JW = { bone: 'jaw', group: 'jaw', part: 'jaw' };
113
+ m.ell({ ...JW, tag: 'chin', c: hl([0, -0.051, 0.15]), r: [0.02, 0.014, 0.028], axis: HZ, up: HY, k: 0 });
114
+ m.ell({ ...JW, tag: 'lowerlip', c: hl([0, -0.043, 0.172]), r: [0.019, 0.01, 0.018], axis: HZ, up: HY, k: 0.01 });
115
+ for (const s of [1, -1]) m.cone({ ...JW, tag: 'mandible', a: hl([0.014 * s, -0.051, 0.115]), b: hl([0.01 * s, -0.047, 0.158]), ra: 0.009, rb: 0.011, k: 0.012 });
116
+
117
+ // ---------------------------------------------------------------- EARS (large, broad, cupped)
118
+ const earK = fawn ? 1.0 : 1.0; // (fawn ears are big by the head scale warp)
119
+ for (const S of ['L', 'R']) {
120
+ const s = S === 'L' ? 1 : -1;
121
+ const base = J['earBase' + S], tip = J['earTip' + S];
122
+ const up = norm(sub(tip, base));
123
+ const facing = norm(add(mul(hdir([0, 0.3, 1]), 0.8), [0.5 * s, 0, 0])); // cup opens forward and out
124
+ const lat = norm(cross(up, facing));
125
+ const ear = { bone: 'ear' + S, group: 'ear' + S, thin: true };
126
+ ellY({ ...ear, tag: 'ear', c: lerp(base, tip, 0.45), ydir: up, lateral: lat, r: [0.045 * earK, 0.074, 0.011], k: 0.012 });
127
+ ellY({ ...ear, tag: 'eartip', c: lerp(base, tip, 0.8), ydir: up, lateral: lat, r: [0.028, 0.035, 0.008], k: 0.012 });
128
+ ellY({ ...ear, tag: 'earinner', c: add(lerp(base, tip, 0.5), mul(facing, 0.009)), ydir: up, lateral: lat, r: [0.036, 0.068, 0.008], k: 0.004, carve: true });
129
+ m.sphere({ ...H, tag: 'earbase', c: add(base, mul(up, -0.006)), rad: 0.017, k: 0.02 });
130
+ }
131
+
132
+ // ---------------------------------------------------------------- LEGS (very slender)
133
+ for (const S of ['L', 'R']) {
134
+ const s = S === 'L' ? 1 : -1;
135
+ const lat = [s, 0, 0];
136
+ const sx = (v) => [v[0] * s, v[1], v[2]];
137
+ // front
138
+ const g = 'F' + S;
139
+ const Sc = J['scapTop' + S], Sh = J['shoulder' + S], E = J['elbow' + S], W = J['wrist' + S], M = J['mcp' + S], C = J['fcoffin' + S], T = J['ftoe' + S];
140
+ ellY({ tag: 'scapmuscle', bone: 'scapula' + S, group: g, c: add(lerp(Sc, Sh, 0.45), sx([0.032, 0, -0.01])), ydir: sub(Sh, Sc), lateral: lat, r: [0.04, 0.14, 0.08], k: 0.08, bias: 0.002 });
141
+ m.sphere({ tag: 'shoulderpoint', bone: 'humerus' + S, group: g, c: add(Sh, sx([0.008, 0.0, 0.0])), rad: 0.032, k: 0.05 });
142
+ m.cone({ tag: 'upperarm', bone: 'humerus' + S, group: g, a: add(Sh, [0, 0, -0.01]), b: E, ra: 0.043, rb: 0.042, k: 0.05 });
143
+ ellY({ tag: 'triceps', bone: 'humerus' + S, group: g, c: add(lerp(Sh, E, 0.55), sx([0.005, 0.01, -0.05])), ydir: sub(E, Sh), lateral: lat, r: [0.05, 0.09, 0.06], k: 0.05 });
144
+ m.sphere({ tag: 'olecranon', bone: 'radius' + S, group: g, c: add(E, [0, 0.012, -0.038]), rad: 0.027, k: 0.03 });
145
+ m.cone({ tag: 'forearm', bone: 'radius' + S, group: g, a: add(E, [0, 0, -0.005]), b: W, ra: 0.04, rb: 0.02, k: 0.03 });
146
+ ellY({ tag: 'forearmmuscle', bone: 'radius' + S, group: g, c: add(lerp(E, W, 0.22), sx([0.004, 0, 0.006])), ydir: sub(W, E), lateral: lat, r: [0.04, 0.094, 0.044], k: 0.03 });
147
+ m.cone({ tag: 'forearmweb', bone: 'radius' + S, group: g, a: add(E, sx([-0.02, 0.035, -0.01])), b: add(lerp(E, W, 0.3), sx([-0.01, 0, 0])), ra: 0.03, rb: 0.022, k: 0.035 });
148
+ // knee (carpus), cannon (flat bone in front, tendons behind), fetlock, dew claws, pastern, hoof
149
+ ellY({ tag: 'knee', bone: 'metacarpus' + S, group: g, c: add(W, [0, 0.0, 0.002]), ydir: [0, 1, 0], lateral: lat, r: [0.021, 0.028, 0.02], k: 0.012 });
150
+ m.sphere({ tag: 'accessory', bone: 'metacarpus' + S, group: g, c: add(W, [0, 0.014, -0.017]), rad: 0.011, k: 0.01 });
151
+ m.cone({ tag: 'cannon', bone: 'metacarpus' + S, group: g, a: add(W, [0, -0.01, 0.0]), b: add(M, [0, 0.01, 0.0]), ra: 0.0135, rb: 0.012, k: 0.01 });
152
+ m.cone({ tag: 'tendon', bone: 'metacarpus' + S, group: g, a: add(W, [0, -0.015, -0.012]), b: add(M, [0, 0.015, -0.013]), ra: 0.009, rb: 0.01, k: 0.01 });
153
+ ellY({ tag: 'fetlock', bone: 'metacarpus' + S, group: g, c: add(M, [0, 0.0, -0.004]), ydir: [0, 1, 0.3], lateral: lat, r: [0.016, 0.02, 0.019], k: 0.01 });
154
+ sculptDigit(m, 'fpaw' + S, 'fhoof' + S, g, M, C, T, 1.0);
155
+ // hind
156
+ const h = 'H' + S;
157
+ const Hp = J['hip' + S], K = J['knee' + S], Hk = J['hock' + S], Mt = J['mtp' + S], Ch = J['hcoffin' + S], Tt = J['htoe' + S];
158
+ ellY({ tag: 'thigh', bone: 'femur' + S, group: h, c: add(lerp(Hp, K, 0.42), sx([0.02, 0, -0.03])), ydir: sub(K, Hp), lateral: lat, r: [0.055, 0.17, 0.11], k: 0.06, bias: 0.004 });
159
+ m.cone({ tag: 'thighfront', bone: 'femur' + S, group: h, a: sx([0.1, 0.8, bz(-0.28)]), b: add(K, sx([0.0, 0.03, 0.02])), ra: 0.06, rb: 0.038, k: 0.06 });
160
+ m.cone({ tag: 'hamstring', bone: 'femur' + S, group: h, a: sx([0.06, 0.79, bz(-0.53)]), b: add(lerp(K, Hk, 0.3), [0, 0, -0.045]), ra: 0.06, rb: 0.032, k: 0.05 });
161
+ ellY({ tag: 'flankfold', bone: 'femur' + S, group: h, c: sx([0.1, 0.6, bz(-0.23)]), ydir: [-0.1, 0.3, 0.12], lateral: lat, r: [0.03, 0.08, 0.045], k: 0.06 });
162
+ m.sphere({ tag: 'stifle', bone: 'tibia' + S, group: h, c: add(K, sx([0.005, 0.005, 0.016])), rad: 0.032, k: 0.04 });
163
+ ellY({ tag: 'gaskin', bone: 'tibia' + S, group: h, c: add(lerp(K, Hk, 0.3), sx([0.004, 0, -0.022])), ydir: sub(Hk, K), lateral: lat, r: [0.04, 0.094, 0.05], k: 0.035 });
164
+ m.cone({ tag: 'shin', bone: 'tibia' + S, group: h, a: lerp(K, Hk, 0.1), b: Hk, ra: 0.03, rb: 0.018, k: 0.03 });
165
+ m.cone({ tag: 'achilles', bone: 'tibia' + S, group: h, a: add(lerp(K, Hk, 0.45), [0, 0, -0.04]), b: add(Hk, [0, 0.035, -0.032]), ra: 0.014, rb: 0.011, k: 0.018 });
166
+ m.sphere({ tag: 'calcaneus', bone: 'metatarsus' + S, group: h, c: add(Hk, [0, 0.035, -0.031]), rad: 0.015, k: 0.014 });
167
+ ellY({ tag: 'hock', bone: 'metatarsus' + S, group: h, c: add(Hk, [0, 0.005, -0.004]), ydir: [0, 1, 0.2], lateral: lat, r: [0.02, 0.034, 0.024], k: 0.014 });
168
+ m.cone({ tag: 'cannon', bone: 'metatarsus' + S, group: h, a: add(Hk, [0, -0.02, 0.002]), b: add(Mt, [0, 0.01, 0.0]), ra: 0.0145, rb: 0.012, k: 0.01 });
169
+ m.cone({ tag: 'tendon', bone: 'metatarsus' + S, group: h, a: add(Hk, [0, -0.02, -0.014]), b: add(Mt, [0, 0.015, -0.013]), ra: 0.009, rb: 0.01, k: 0.01 });
170
+ ellY({ tag: 'fetlock', bone: 'metatarsus' + S, group: h, c: add(Mt, [0, 0.0, -0.004]), ydir: [0, 1, 0.3], lateral: lat, r: [0.016, 0.02, 0.019], k: 0.01 });
171
+ sculptDigit(m, 'hpaw' + S, 'hhoof' + S, h, Mt, Ch, Tt, 0.95);
172
+ }
173
+
174
+ // ---------------------------------------------------------------- TAIL: broad, flat, hairy
175
+ for (let i = 0; i < TAIL_SEGS; i++) {
176
+ const a = J['tail' + i], b = J['tail' + (i + 1)];
177
+ const t0 = i / TAIL_SEGS;
178
+ const d = norm(sub(b, a));
179
+ const w = 0.03 + 0.018 * Math.sin(Math.PI * Math.min(1, 0.25 + t0 * 0.95)); // broadest in the middle
180
+ ellY({ tag: 'tail', bone: 'tail' + i, c: lerp(a, b, 0.5), ydir: d, lateral: X, r: [w, 0.034, 0.016 - 0.004 * t0], k: i === 0 ? 0.04 : 0.012, thin: true });
181
+ }
182
+ m.cone({ tag: 'tailroot', bone: 'tail0', a: J.tail0, b: J.tail2, ra: 0.03, rb: 0.022, k: 0.04 });
183
+
184
+ if (params.antlers) sculptAntlers(m, params.antlers);
185
+ return m;
186
+ }
187
+
188
+ // Pastern, dew claws and a small cloven hoof: two pointed claws with a cleft between them, the sole
189
+ // flat on the ground (carved at y = 0).
190
+ function sculptDigit(m, paw, hoof, group, M, C, T, w) {
191
+ m.cone({ tag: 'pastern', bone: paw, group, a: M, b: C, ra: 0.013 * w, rb: 0.014 * w, k: 0.008 });
192
+ // dew claws: two small horny points behind the fetlock
193
+ for (const s of [1, -1]) m.cone({ tag: 'dewclaw', bone: paw, group, a: add(M, [0.009 * s, -0.012, -0.012]), b: add(M, [0.011 * s, -0.03, -0.022]), ra: 0.0055, rb: 0.003, k: 0.004 });
194
+ const dir = norm(sub(T, C));
195
+ const heel = add(C, [0, -0.012, -0.012]);
196
+ for (const s of [1, -1]) {
197
+ // each claw: a round cone from the heel bulb to the pointed toe
198
+ m.cone({ tag: 'hoof', bone: hoof, group, a: add(heel, [0.0085 * s * w, 0.004, 0]), b: add(T, [0.006 * s * w, 0.002, -0.004]), ra: 0.0135 * w, rb: 0.005 * w, k: 0.006 });
199
+ }
200
+ m.cone({ tag: 'coronet', bone: hoof, group, a: add(C, [0, 0.008, -0.006]), b: add(C, mul(dir, 0.01)), ra: 0.016 * w, rb: 0.015 * w, k: 0.008 });
201
+ m.sphere({ tag: 'heelbulb', bone: hoof, group, c: add(C, [0, -0.012, -0.018]), rad: 0.012 * w, k: 0.008 });
202
+ // cleft between the claws, and the flat sole
203
+ m.ell({ tag: 'cleft', bone: hoof, group, c: add(lerp(C, T, 0.75), [0, -0.006, 0]), r: [0.0012, 0.02, 0.035], axis: dir, k: 0.002, carve: true });
204
+ m.ell({ tag: 'sole', bone: hoof, group, c: [C[0], -0.2 + 0.0015, (C[2] + T[2]) * 0.5], r: [0.2, 0.2, 0.2], k: 0.002, carve: true });
205
+ }
206
+
207
+ // ------------------------------------------------------------------------------------------------
208
+ // Antlers. A = params.antlers: { burr: [x, y, z] head-local, beam (m), spread (0..1), rise, curl,
209
+ // tines: [[t along the beam, length, lean], ...] per side, spike: bool, seed }. The main beam leaves
210
+ // the burr up, out and back, then sweeps forward and in; the tines rise near-vertically from its top
211
+ // (not forked as in mule deer). Geometry is in the bind-pose world frame relative to the burr.
212
+ export function antlerCurves(A) {
213
+ const sides = [];
214
+ for (const s of [1, -1]) {
215
+ const Rr = rng((A.seed || 1) * 31 + (s > 0 ? 7 : 13));
216
+ const jit = () => 1 + (Rr() - 0.5) * 0.12; // left / right asymmetry
217
+ const burr = hl([A.burr[0] * s, A.burr[1], A.burr[2]]);
218
+ const L = A.beam * jit();
219
+ let pts;
220
+ if (A.spike) {
221
+ // yearling spike: a near-straight point, up and a little out and back
222
+ pts = [[0, 0, 0], [0.12 * s, 0.5, -0.12], [0.2 * s, 0.97, -0.08]].map((p) => mul(p, L));
223
+ } else {
224
+ // main beam in fractions of its length: [out, up, forward]
225
+ const sp = A.spread * jit(), ri = A.rise, cu = A.curl;
226
+ pts = [
227
+ [0, 0, 0],
228
+ [0.13 * sp * s, 0.24 * ri, -0.12],
229
+ [0.38 * sp * s, 0.33 * ri, -0.08],
230
+ [0.54 * sp * s, 0.37 * ri, 0.08 * cu],
231
+ [0.5 * sp * s, 0.4 * ri, 0.28 * cu],
232
+ [0.32 * sp * s, 0.43 * ri, 0.44 * cu],
233
+ ].map((p) => mul(p, L));
234
+ }
235
+ pts = pts.map((p) => add(burr, p));
236
+ // Catmull-Rom resampling
237
+ const beam = catmull(pts, A.spike ? 8 : 16);
238
+ const tines = [];
239
+ if (!A.spike) {
240
+ for (const [t, len, lean] of A.tines) {
241
+ const b = sampleAt(beam, t);
242
+ const tangent = norm(sub(sampleAt(beam, Math.min(1, t + 0.03)), sampleAt(beam, Math.max(0, t - 0.03))));
243
+ // up, a little outward from the beam's curve and forward at the tip
244
+ const out = norm(cross(tangent, [0, 1, 0]));
245
+ const flip = out[0] * s < 0 ? -1 : 1;
246
+ const l = len * jit();
247
+ const p1 = add(b, [0, 0.5 * l, 0]);
248
+ const p2 = add(add(b, [0, 0.95 * l, 0]), mul(out, flip * lean * l * 0.25));
249
+ const p3 = add(p2, [0, 0.05 * l, 0.12 * l]);
250
+ tines.push({ pts: catmull([b, p1, p2, p3], 6), t });
251
+ }
252
+ }
253
+ sides.push({ s, burr, beam, tines });
254
+ }
255
+ return sides;
256
+ }
257
+
258
+ function catmull(P, n) {
259
+ const out = [];
260
+ const seg = P.length - 1;
261
+ for (let i = 0; i <= n; i++) {
262
+ const u = (i / n) * seg, k = Math.min(seg - 1, Math.floor(u)), t = u - k;
263
+ const p0 = P[Math.max(0, k - 1)], p1 = P[k], p2 = P[k + 1], p3 = P[Math.min(seg, k + 2)];
264
+ const t2 = t * t, t3 = t2 * t;
265
+ out.push([0, 1, 2].map((j) => 0.5 * (2 * p1[j] + (-p0[j] + p2[j]) * t + (2 * p0[j] - 5 * p1[j] + 4 * p2[j] - p3[j]) * t2 + (-p0[j] + 3 * p1[j] - 3 * p2[j] + p3[j]) * t3)));
266
+ }
267
+ return out;
268
+ }
269
+ function sampleAt(pts, t) {
270
+ const u = Math.max(0, Math.min(1, t)) * (pts.length - 1), k = Math.min(pts.length - 2, Math.floor(u));
271
+ return lerp(pts[k], pts[k + 1], u - k);
272
+ }
273
+
274
+ function sculptAntlers(m, A) {
275
+ const AN = { bone: 'head', group: 'axial', part: 'antler' };
276
+ const r0 = A.base; // beam radius at the burr
277
+ for (const side of antlerCurves(A)) {
278
+ const { beam, tines, burr } = side;
279
+ // burr (coronet): a rough ring at the base, pedicle into the skull
280
+ const d0 = norm(sub(beam[1], beam[0]));
281
+ m.cone({ ...AN, tag: 'burr', a: add(burr, mul(d0, -0.012)), b: add(burr, mul(d0, 0.004)), ra: r0 * 1.12, rb: r0 * 1.1, k: 0.004 });
282
+ const n = beam.length - 1;
283
+ for (let i = 0; i < n; i++) {
284
+ const t0 = i / n, t1 = (i + 1) / n;
285
+ const rad = (t) => r0 * (1 - 0.55 * Math.pow(t, 1.3)) * (A.spike ? 1 - 0.55 * t : 1);
286
+ m.cone({ ...AN, tag: 'beam', a: beam[i], b: beam[i + 1], ra: rad(t0), rb: Math.max(0.0025, rad(t1) * (i === n - 1 ? 0.45 : 1)), k: 0.004 });
287
+ }
288
+ for (const tn of tines) {
289
+ const P = tn.pts, k = P.length - 1;
290
+ const rb = r0 * (0.75 - 0.4 * tn.t);
291
+ for (let i = 0; i < k; i++) {
292
+ const u0 = i / k, u1 = (i + 1) / k;
293
+ m.cone({ ...AN, tag: 'tine', a: P[i], b: P[i + 1], ra: Math.max(0.0025, rb * (1 - 0.8 * u0)), rb: Math.max(0.0022, rb * (1 - 0.8 * u1)), k: i === 0 ? 0.008 : 0.003 });
294
+ }
295
+ }
296
+ }
297
+ }