@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,427 @@
1
+ // The cheetah's coat: Poisson-disc spots grown on the actual surface, tear marks, lips, eye rims,
2
+ // ear backs, tail rings, countershading and fur length / comb fields, all baked per vertex.
3
+ // Works in the cheetah's reference space (see rig.js); seeded variation shifts the base colours
4
+ // and re-seeds the spot layout.
5
+ import { HEAD_O } from './rig.js';
6
+ import { neckS } from './regions.js';
7
+ import { SDFModel } from '../../core/sdf/sdf.js';
8
+ import { norm, sub, dot, cross, len, add, mul, smoothstep, clamp, mix, rng, fbm3, vnoise3 } from '../../core/math/vec.js';
9
+ import { srgb, mix3 } from '../../core/build/coatKit.js';
10
+
11
+ function coatColours(p) {
12
+ // calibrated against sampled reference photos (buff/tawny, fairly desaturated); `hue` shifts
13
+ // individuals between paler / more golden coats
14
+ const k = p.coatWarmth || 0, l = p.coatLightness || 0;
15
+ const tweak = (c) => [c[0] * (1 + 0.1 * k + l), c[1] * (1 + 0.02 * k + l), c[2] * (1 - 0.12 * k + l)];
16
+ return {
17
+ dorsal: tweak(srgb(0xae8558)),
18
+ flank: tweak(srgb(0xc29d72)),
19
+ lowFlank: tweak(srgb(0xd2b690)),
20
+ white: srgb(0xebe5d9),
21
+ cream: srgb(0xdccbae),
22
+ legOuter: tweak(srgb(0xc6a479)),
23
+ face: tweak(srgb(0xc19668)),
24
+ muzzle: srgb(0xefe9df),
25
+ nose: srgb(0x2c2624),
26
+ black: srgb(0x15110f),
27
+ mouth: srgb(0x7a3a3a),
28
+ earInner: srgb(0xcbb699),
29
+ };
30
+ }
31
+
32
+ export function cheetahCoat(ctx) {
33
+ const { model, rig, pos, nrm, regionOf: partOf, weights, nV, patchOf, params } = ctx;
34
+ const { BONES, AXIAL } = rig;
35
+ const AX_LEN = weights.axialLengths;
36
+ const R = rng(1337 + (params.coatSeed || 0));
37
+ const COL = coatColours(params);
38
+ const { dominant, axialS, skinIndex, skinWeight, limbMember, limbWhich } = weights;
39
+ const P = (v) => [pos[v * 3], pos[v * 3 + 1], pos[v * 3 + 2]];
40
+ const N = (v) => [nrm[v * 3], nrm[v * 3 + 1], nrm[v * 3 + 2]];
41
+ const sOcc = AX_LEN[1], sNeckBase = AX_LEN[3], sTailBase = AX_LEN[8], sTip = AX_LEN[AX_LEN.length - 1];
42
+ const tailLen = sTip - sTailBase;
43
+ const eyePrims = model.prims.filter((p) => p.tag === 'eyesocket');
44
+ const nosePrim = model.prims.find((p) => p.tag === 'nose');
45
+ const jawPrims = model.forPart('jaw');
46
+ const bodyPrims = model.forPart('body');
47
+ const headPrims = bodyPrims.filter((p) => p.bone === 'head' && !p.carve);
48
+ const earPrims = model.prims.filter((p) => p.tag === 'ear');
49
+ const isLimb = BONES.map((b) => /^(scapula|humerus|radius|metacarpus|fpaw|femur|tibia|metatarsus|hpaw)/.test(b.name));
50
+
51
+ // --- regions per vertex. Legs are not a region but a continuous blend (legness) that follows the
52
+ // harmonic limb field used for skinning, so coat colour, spot size, fur length and hair flow all
53
+ // change smoothly from flank to thigh and from chest to upper arm.
54
+ const region = new Uint8Array(nV); // 0 torso, 1 neck, 2 head, 4 tail, 5 ear, 6 jaw
55
+ const legness = new Float32Array(nV);
56
+ const legBone = new Int16Array(nV).fill(-1); // strongest limb bone of the vertex
57
+ const legH = new Float32Array(nV); // normalised height on the limb (0 paw .. 1 body)
58
+ const junction = new Float32Array(nV); // 1 in the middle of a limb/body blend (armpit, groin, fold)
59
+ const tailT = new Float32Array(nV);
60
+ for (let v = 0; v < nV; v++) {
61
+ const bn = BONES[dominant[v]].name;
62
+ const p = P(v);
63
+ let lb = -1, lw = 0;
64
+ for (let k = 0; k < 4; k++) {
65
+ const b = skinIndex[v * 4 + k], w = skinWeight[v * 4 + k];
66
+ if (isLimb[b] && w > lw) { lw = w; lb = b; }
67
+ }
68
+ legBone[v] = lb;
69
+ const m = limbMember[v];
70
+ legness[v] = lb >= 0 ? smoothstep(0.15, 0.85, m) : 0;
71
+ junction[v] = lb >= 0 ? 4 * m * (1 - m) : 0;
72
+ legH[v] = clamp(p[1] / 0.55, 0, 1);
73
+ if (partOf[v] === 2) region[v] = 6;
74
+ else if (bn.startsWith('ear')) region[v] = 5;
75
+ else if (axialS[v] > sTailBase + 0.03 && bn.startsWith('tail')) { region[v] = 4; tailT[v] = clamp((axialS[v] - sTailBase) / tailLen, 0, 1); }
76
+ else if (axialS[v] < sOcc + 0.01 || partOf[v] === 1 && neckS(p[0], p[1], p[2]) > 0.02) region[v] = 2;
77
+ else if (axialS[v] < sNeckBase) region[v] = 1;
78
+ else region[v] = 0;
79
+ if (region[v] === 2 || region[v] === 5 || region[v] === 6 || region[v] === 4) { legness[v] = 0; junction[v] = 0; }
80
+ }
81
+
82
+ // skin tucked between limb and body: armpit (behind/below the upper arm) and groin/flank fold
83
+ const underFactor = (v) => {
84
+ const n = N(v), p = P(v), li = limbWhich[v];
85
+ if (li < 0 || junction[v] <= 0) return 0;
86
+ if (li <= 1) return junction[v] * Math.max(smoothstep(0.15, -0.55, n[2]) * smoothstep(0.55, 0.42, p[1]), smoothstep(0.2, -0.6, n[1]));
87
+ return junction[v] * smoothstep(0.35, -0.45, n[1] + 0.35 * Math.abs(n[2]));
88
+ };
89
+
90
+ // --- ventral / countershading factor
91
+ const ventral = new Float32Array(nV);
92
+ for (let v = 0; v < nV; v++) {
93
+ const p = P(v), n = N(v), r = region[v];
94
+ let w = 0;
95
+ if (r === 0) {
96
+ w = smoothstep(-0.15, -0.7, n[1]);
97
+ // chest front & between forelegs (midline bib only)
98
+ if (p[2] > 0.22 && p[1] < 0.58) w = Math.max(w, smoothstep(0.58, 0.46, p[1]) * smoothstep(0.075, 0.03, Math.abs(p[0])) * smoothstep(-0.2, 0.4, n[2]));
99
+ w *= smoothstep(0.6, 0.5, p[1]) * 0.6 + 0.4;
100
+ } else if (r === 1) {
101
+ w = smoothstep(0.15, -0.55, n[1]);
102
+ } else if (r === 4) {
103
+ w = smoothstep(0.0, -0.7, n[1]) * 0.8;
104
+ } else if (r === 2 || r === 6) {
105
+ const h = sub(p, HEAD_O);
106
+ w = smoothstep(-0.045, -0.07, h[1]) * smoothstep(-0.2, -0.7, n[1]) * 0.9 + (r === 6 ? 0.7 : 0);
107
+ }
108
+ const L = legness[v];
109
+ if (L > 0) {
110
+ const side = p[0] >= 0 ? 1 : -1;
111
+ const inner = smoothstep(0.0, -0.7, n[0] * side);
112
+ const wl = inner * 0.45 * smoothstep(0.15, 0.45, p[1]) + smoothstep(-0.3, -0.85, n[1]) * 0.45;
113
+ w = mix(w, wl, L);
114
+ }
115
+ // armpits, groin and the flank fold are pale, like the belly they continue
116
+ w = Math.max(w, underFactor(v) * 0.9);
117
+ ventral[v] = clamp(w, 0, 1);
118
+ }
119
+
120
+ // --- comb (hair flow) direction, in bind space
121
+ const comb = new Float32Array(nV * 3);
122
+ for (let v = 0; v < nV; v++) {
123
+ const p = P(v), n = N(v), r = region[v];
124
+ let d;
125
+ const bone = BONES[dominant[v]];
126
+ if (r === 5) {
127
+ d = norm(sub(bone.tail, bone.head));
128
+ } else if (r === 2 || r === 6) {
129
+ const h = sub(p, HEAD_O);
130
+ const fromNose = norm(sub(h, [0, -0.012, 0.1]));
131
+ d = norm(add(mul(fromNose, 1.0), [0, -0.25, -0.6]));
132
+ } else {
133
+ const seg = weights.segT[v * 2] | 0;
134
+ const a = AXIAL.points[seg], b = AXIAL.points[Math.min(seg + 1, AXIAL.points.length - 1)];
135
+ d = norm(sub(b, a));
136
+ if (r === 0) d = norm(add(d, [0, -0.35 * Math.abs(n[0]), 0]));
137
+ if (r === 1) d = norm(add(d, [0, -0.2, 0]));
138
+ const L = legness[v];
139
+ if (L > 0 && legBone[v] >= 0) {
140
+ const lbn = BONES[legBone[v]];
141
+ let dl = norm(sub(lbn.tail, lbn.head));
142
+ if (/fpaw|hpaw/.test(lbn.name)) dl = norm(add(dl, [0, 0, 0.4]));
143
+ else dl = norm(add(dl, [0, -0.2, -0.25]));
144
+ d = norm(add(mul(d, 1 - L), mul(dl, L)));
145
+ }
146
+ }
147
+ // project to tangent plane
148
+ let t = sub(d, mul(n, dot(d, n)));
149
+ if (len(t) < 1e-4) t = cross(n, [1, 0, 0]);
150
+ t = norm(t);
151
+ comb[v * 3] = t[0]; comb[v * 3 + 1] = t[1]; comb[v * 3 + 2] = t[2];
152
+ }
153
+
154
+ // --- Poisson-disc spot centres on the surface
155
+ // A cheetah carries ~2000 solid round spots 2-3 cm across; on the flank ~15 lie on a line from
156
+ // shoulder to hip and they cover ~27 % of the coat (side / three-quarter photos). The neck, throat
157
+ // and chest carry smaller, denser spots, the lower legs smaller still.
158
+ const spotRadius = (v) => {
159
+ const p = P(v), r = region[v];
160
+ const L = legness[v];
161
+ if (r === 0 || r === 1) {
162
+ const onTorso = smoothstep(sNeckBase - 0.1, sNeckBase + 0.05, axialS[v]);
163
+ const ax = mix(0.007, 0.0111 * mix(1, 0.74, ventral[v]), onTorso);
164
+ const lg = mix(0.0035, 0.0099, smoothstep(0.05, 0.55, legH[v]));
165
+ return mix(ax, lg, L);
166
+ }
167
+ if (r === 2) {
168
+ const h = sub(p, HEAD_O);
169
+ if (h[2] > 0.03 && Math.abs(h[0]) < 0.02) return 0; // nose bridge: no spots
170
+ if (h[1] < -0.012 && h[2] > 0.02) return 0; // muzzle
171
+ if (h[2] > 0.05) return 0;
172
+ return mix(0.0031, 0.0052, smoothstep(0.04, -0.06, h[2]));
173
+ }
174
+ if (r === 4) return 0.0104;
175
+ return 0;
176
+ };
177
+ const order = new Uint32Array(nV);
178
+ for (let i = 0; i < nV; i++) order[i] = i;
179
+ for (let i = nV - 1; i > 0; i--) { const j = Math.floor(R() * (i + 1)); const t = order[i]; order[i] = order[j]; order[j] = t; }
180
+ // (the grid cell is at least the largest Poisson distance, so the 3x3x3 search sees every conflict)
181
+ const cell = 0.042;
182
+ const grid = new Map();
183
+ const key = (x, y, z) => ((x + 512) * 1024 + (y + 512)) * 1024 + (z + 512);
184
+ const spots = [];
185
+ for (let k = 0; k < nV; k++) {
186
+ const v = order[k];
187
+ if (partOf[v] === 1 && neckS(pos[v * 3], pos[v * 3 + 1], pos[v * 3 + 2]) < 0) continue; // avoid duplicates in overlap band
188
+ if (partOf[v] === 0 && neckS(pos[v * 3], pos[v * 3 + 1], pos[v * 3 + 2]) > 0) continue;
189
+ let r = spotRadius(v);
190
+ if (r <= 0) continue;
191
+ if (region[v] === 4 && tailT[v] > 0.58) continue;
192
+ r *= 0.78 + 0.44 * R();
193
+ // armpits and groin (skin that stretches most in a gallop) carry smaller, fainter spots
194
+ const under = underFactor(v);
195
+ r *= 1 - 0.35 * under;
196
+ const p = P(v);
197
+ // the belly behind the chest is white with sparse, faded spots; the chest and throat keep dense
198
+ // black ones (front / side photos)
199
+ const belly = region[v] === 0 ? smoothstep(0.45, 0.95, ventral[v]) * smoothstep(0.2, 0.06, p[2]) * (1 - legness[v]) : 0;
200
+ const rs = r * (1 + 0.7 * belly); // spacing radius
201
+ const gx = Math.floor(p[0] / cell), gy = Math.floor(p[1] / cell), gz = Math.floor(p[2] / cell);
202
+ let ok = true;
203
+ for (let dz = -1; dz <= 1 && ok; dz++)
204
+ for (let dy = -1; dy <= 1 && ok; dy++)
205
+ for (let dx = -1; dx <= 1 && ok; dx++) {
206
+ const arr = grid.get(key(gx + dx, gy + dy, gz + dz));
207
+ if (!arr) continue;
208
+ for (const s of arr) {
209
+ const minD = 1.34 * (rs + s.rs) + 0.002;
210
+ const ddx = p[0] - s.p[0], ddy = p[1] - s.p[1], ddz = p[2] - s.p[2];
211
+ if (ddx * ddx + ddy * ddy + ddz * ddz < minD * minD) { ok = false; break; }
212
+ }
213
+ }
214
+ if (!ok) continue;
215
+ const s = { p, r, rs, n: N(v), c: [comb[v * 3], comb[v * 3 + 1], comb[v * 3 + 2]], el: 1.05 + 0.25 * R(), pale: belly, under };
216
+ spots.push(s);
217
+ const kk = key(gx, gy, gz);
218
+ (grid.get(kk) || grid.set(kk, []).get(kk)).push(s);
219
+ }
220
+
221
+ // --- per-vertex fields
222
+ const spotSDF = new Float32Array(nV).fill(1);
223
+ const spotInt = new Float32Array(nV);
224
+ const markSDF = new Float32Array(nV).fill(1);
225
+ const furLen = new Float32Array(nV);
226
+ const tint = new Float32Array(nV * 4);
227
+
228
+ // tear line polylines (head-local), projected to the surface
229
+ // The tear line starts at the inner corner of the eye (where the lower lid's black rim runs into it)
230
+ // and runs down the junction of muzzle and cheek to the corner of the mouth, ~25-35 mm off the
231
+ // midline and only 13-23 mm in front of the eye (face-on and profile photos). There the skin faces
232
+ // forward and sideways, so the line reads from the front as well as from the side.
233
+ const tearPts = [[0.018, 0.0219, 0.0335], [0.0191, 0.0111, 0.0357], [0.0222, 0.0011, 0.0395], [0.0262, -0.0086, 0.0426], [0.0285, -0.0198, 0.0441], [0.0305, -0.028, 0.043], [0.0335, -0.0355, 0.0425], [0.0355, -0.0435, 0.0415]];
234
+ const headList = bodyPrims;
235
+ const projectToSurface = (q) => {
236
+ let x = q.slice();
237
+ for (let i = 0; i < 6; i++) {
238
+ const d = SDFModel.evalList(headList, x[0], x[1], x[2]);
239
+ const e = 0.0005;
240
+ const g = [
241
+ SDFModel.evalList(headList, x[0] + e, x[1], x[2]) - d,
242
+ SDFModel.evalList(headList, x[0], x[1] + e, x[2]) - d,
243
+ SDFModel.evalList(headList, x[0], x[1], x[2] + e) - d,
244
+ ].map((c) => c / e);
245
+ const gl = len(g) || 1;
246
+ x = sub(x, mul(g, d / (gl * gl)));
247
+ }
248
+ return x;
249
+ };
250
+ const tears = [1, -1].map((s) => tearPts.map((q) => projectToSurface(add(HEAD_O, [q[0] * s, q[1], q[2]]))));
251
+ const tearW = [0.0022, 0.0031, 0.0037, 0.0041, 0.0043, 0.0043, 0.004, 0.0034];
252
+ const distPoly = (p, poly) => {
253
+ let best = 1e9;
254
+ for (let i = 0; i < poly.length - 1; i++) {
255
+ const a = poly[i], b = poly[i + 1], ab = sub(b, a);
256
+ const t = clamp(dot(sub(p, a), ab) / dot(ab, ab), 0, 1);
257
+ const d = len(sub(p, add(a, mul(ab, t)))) - mix(tearW[i], tearW[i + 1], t);
258
+ if (d < best) best = d;
259
+ }
260
+ return best;
261
+ };
262
+
263
+ const ringTs = [0.61, 0.685, 0.755, 0.82, 0.88, 0.935];
264
+ const spotGrid = grid;
265
+
266
+ for (let v = 0; v < nV; v++) {
267
+ const p = P(v), n = N(v), r = region[v];
268
+ const h = sub(p, HEAD_O);
269
+
270
+ // ---- spots
271
+ let best = 1, bestInt = 0;
272
+ const wob = 1 + 0.22 * (vnoise3(p[0] * 180, p[1] * 180, p[2] * 180) - 0.5);
273
+ const gx = Math.floor(p[0] / cell), gy = Math.floor(p[1] / cell), gz = Math.floor(p[2] / cell);
274
+ for (let dz = -1; dz <= 1; dz++)
275
+ for (let dy = -1; dy <= 1; dy++)
276
+ for (let dx = -1; dx <= 1; dx++) {
277
+ const arr = spotGrid.get(key(gx + dx, gy + dy, gz + dz));
278
+ if (!arr) continue;
279
+ for (const s of arr) {
280
+ if (dot(s.n, n) < 0.2) continue; // do not bleed through thin parts
281
+ const d = sub(p, s.p);
282
+ const along = dot(d, s.c);
283
+ const dd = Math.sqrt(Math.max(0, dot(d, d) - along * along * (1 - 1 / (s.el * s.el))));
284
+ const sd = dd - s.r * wob;
285
+ if (sd < best) { best = sd; bestInt = (1 - 0.55 * s.pale) * (1 - 0.55 * s.under); }
286
+ }
287
+ }
288
+ spotSDF[v] = best;
289
+ spotInt[v] = bestInt;
290
+
291
+ // ---- base colour
292
+ let col;
293
+ const skinFlag = { v: 0 };
294
+ let fl = 0.009;
295
+ let mark = 1;
296
+ if (r === 0 || r === 1) {
297
+ const up = clamp(n[1], -1, 1);
298
+ col = mix3(COL.lowFlank, COL.flank, smoothstep(-0.2, 0.4, up));
299
+ col = mix3(col, COL.dorsal, smoothstep(0.55, 0.95, up) * 0.85);
300
+ col = mix3(col, COL.white, ventral[v]);
301
+ // coarse short body coat, a longer soft fringe along the belly and chest
302
+ // (the chest in front of the forelegs keeps a shorter, flatter bib than the belly fringe)
303
+ fl = mix(0.0135, r === 0 ? mix(0.032, 0.017, smoothstep(0.12, 0.3, p[2])) : 0.0135, smoothstep(0.25, 0.9, ventral[v]));
304
+ fl = Math.max(fl, 0.017 * smoothstep(0.8, 0.97, n[1])); // dorsal line
305
+ if (r === 1) {
306
+ // nape crest (mane) — longer fur along the top of the neck
307
+ fl = Math.max(fl, 0.031 * smoothstep(0.45, 0.95, n[1]));
308
+ } else if (p[2] > 0.12) {
309
+ // the mantle runs on over the withers and fades out behind the shoulders
310
+ fl = Math.max(fl, 0.026 * smoothstep(0.55, 0.95, n[1]) * smoothstep(0.12, 0.3, p[2]));
311
+ }
312
+ const L = legness[v];
313
+ if (L > 0) {
314
+ let lc = mix3(COL.legOuter, COL.cream, ventral[v] * 0.8);
315
+ lc = mix3(lc, COL.dorsal, smoothstep(0.6, 1.0, n[1]) * 0.3);
316
+ let lf = mix(0.0045, 0.013, smoothstep(0.1, 0.7, legH[v]));
317
+ // "breeches": longer hair on the back of the thighs
318
+ if (p[2] < -0.3) lf = Math.max(lf, 0.019 * smoothstep(-0.3, -0.75, n[2]) * smoothstep(0.35, 0.7, legH[v]));
319
+ if (legBone[v] >= 0 && /fpaw|hpaw/.test(BONES[legBone[v]].name)) { lf = 0.003; lc = mix3(lc, COL.cream, 0.3); }
320
+ col = mix3(col, lc, L);
321
+ fl = mix(fl, lf, L);
322
+ }
323
+ } else if (r === 4) {
324
+ const t = tailT[v];
325
+ col = mix3(COL.flank, COL.white, ventral[v]);
326
+ col = mix3(col, COL.white, smoothstep(0.55, 0.9, t) * 0.55);
327
+ fl = mix(0.016, 0.03, smoothstep(0.45, 1.0, t));
328
+ // rings
329
+ const s = t * tailLen;
330
+ let rs = 1;
331
+ for (let k = 0; k < ringTs.length; k++) {
332
+ const hw = 0.012 + 0.003 * (k / ringTs.length);
333
+ rs = Math.min(rs, Math.abs(s - ringTs[k] * tailLen) - hw);
334
+ }
335
+ rs += 0.006 * ventral[v];
336
+ if (t > 0.965) rs = 1; // white tip
337
+ if (t > 0.965) col = COL.white;
338
+ mark = Math.min(mark, rs);
339
+ } else if (r === 5) {
340
+ // ears: back mostly black at base, inner light
341
+ const earP = earPrims[p[0] > 0 ? 0 : 1];
342
+ const faceDir = [earP.P[9], earP.P[10], earP.P[11]]; // local z of ear ellipsoid = facing
343
+ const front = dot(n, faceDir);
344
+ const upE = [earP.P[6], earP.P[7], earP.P[8]];
345
+ const ht = dot(sub(p, [earP.P[0], earP.P[1], earP.P[2]]), upE) / 0.02; // -1 base .. 1 tip
346
+ if (front > 0.35) { col = mix3(COL.face, COL.earInner, smoothstep(0.35, 0.8, front)); fl = 0.007; }
347
+ else {
348
+ col = COL.face;
349
+ fl = 0.004;
350
+ mark = Math.min(mark, (ht - 0.25) * 0.01 + (front + 0.6) * 0.01);
351
+ }
352
+ } else {
353
+ // head & jaw
354
+ col = COL.face;
355
+ fl = 0.005;
356
+ // muzzle / chin / cheeks white
357
+ const g3 = (c, r) => Math.exp(-(((Math.abs(h[0]) - c[0]) / r[0]) ** 2 + ((h[1] - c[1]) / r[1]) ** 2 + ((h[2] - c[2]) / r[2]) ** 2));
358
+ // whisker pads pale buff, white only along the upper lip margin ("moustache"), the chin and throat
359
+ const whisker = g3([0.015, -0.035, 0.08], [0.02, 0.016, 0.024]) * 0.5;
360
+ const moustache = g3([0.017, -0.047, 0.07], [0.024, 0.0085, 0.034]);
361
+ const lip = g3([0.0, -0.042, 0.088], [0.014, 0.01, 0.016]);
362
+ const underEye = g3([0.031, 0.009, 0.033], [0.011, 0.0075, 0.016]) * 0.8;
363
+ const aboveEye = g3([0.03, 0.044, 0.025], [0.012, 0.006, 0.015]) * 0.45;
364
+ const chinW = partOf[v] === 2 ? smoothstep(-0.02, 0.03, h[2]) * 0.9 + smoothstep(-0.2, -0.7, n[1]) * 0.6 : 0;
365
+ const throatW = smoothstep(-0.045, -0.065, h[1]) * smoothstep(-0.3, -0.8, n[1]) * 0.9;
366
+ const w = clamp(Math.max(whisker, moustache, lip, underEye, aboveEye, chinW, throatW), 0, 1);
367
+ col = mix3(col, COL.muzzle, w);
368
+ fl = mix(0.0045, 0.003, smoothstep(0.03, 0.07, h[2]));
369
+ if (Math.abs(h[0]) > 0.035 && h[1] < 0.0) fl = 0.009; // cheek ruff
370
+ if (h[1] > 0.04) fl = 0.005;
371
+ // tear marks
372
+ for (const poly of tears) mark = Math.min(mark, distPoly(p, poly));
373
+ // eye rims
374
+ for (const e of eyePrims) {
375
+ const de = SDFModel.dist(e, p[0], p[1], p[2]);
376
+ if (Math.abs(de) < 0.004) mark = Math.min(mark, Math.abs(de) - 0.0021);
377
+ if (Math.abs(de) < 0.0016) { skinFlag.v = 2; fl = 0; }
378
+ else if (Math.abs(de) < 0.004) fl = Math.min(fl, 0.0015);
379
+ }
380
+ // nose leather
381
+ const dn = SDFModel.dist(nosePrim, p[0], p[1], p[2]);
382
+ if (dn < 0.0022 && h[2] > 0.085) { skinFlag.v = 1; col = COL.nose; fl = 0; }
383
+ // lips: head vertices near the jaw surface, jaw vertices near the head surface
384
+ if (partOf[v] !== 2) {
385
+ const dj = SDFModel.evalList(jawPrims, p[0], p[1], p[2]);
386
+ if (dj < 0.0015) { skinFlag.v = 3; col = COL.mouth; fl = 0; }
387
+ else if (dj < 0.004 && h[2] > 0.0) { mark = Math.min(mark, dj - 0.0038); fl = Math.min(fl, 0.002); }
388
+ } else {
389
+ const dh = SDFModel.evalList(headPrims, p[0], p[1], p[2]);
390
+ if (dh < 0.0) { skinFlag.v = 3; col = COL.mouth; fl = 0; }
391
+ else if (dh < 0.0035) { mark = Math.min(mark, dh - 0.003); fl = Math.min(fl, 0.002); }
392
+ }
393
+ if (r === 2 && h[2] < -0.04) {
394
+ // back of head blends to neck colour
395
+ col = mix3(col, COL.dorsal, smoothstep(-0.04, -0.09, h[2]) * smoothstep(0.0, 0.6, n[1]) * 0.6);
396
+ }
397
+ }
398
+ // low frequency colour variation
399
+ const cv = fbm3(p[0] * 9, p[1] * 9, p[2] * 9, 3) - 0.5;
400
+ const cvh = fbm3(p[0] * 4 + 5, p[1] * 4, p[2] * 4, 2) - 0.5;
401
+ col = [col[0] * (1 + 0.16 * cv + 0.1 * cvh), col[1] * (1 + 0.14 * cv), col[2] * (1 + 0.1 * cv - 0.08 * cvh)];
402
+
403
+ markSDF[v] = mark;
404
+ furLen[v] = fl;
405
+ tint[v * 4] = col[0]; tint[v * 4 + 1] = col[1]; tint[v * 4 + 2] = col[2]; tint[v * 4 + 3] = skinFlag.v;
406
+ }
407
+
408
+ // smooth fur length a little so shells do not step
409
+ const nb = weights.neighbors;
410
+ const tmp = new Float32Array(nV);
411
+ for (let it = 0; it < 2; it++) {
412
+ for (let v = 0; v < nV; v++) {
413
+ const ns = nb[v];
414
+ if (!ns.length || tint[v * 4 + 3] > 0) { tmp[v] = furLen[v]; continue; }
415
+ let a = 0;
416
+ for (const n of ns) a += furLen[n];
417
+ tmp[v] = 0.5 * furLen[v] + (0.5 * a) / ns.length;
418
+ }
419
+ furLen.set(tmp);
420
+ }
421
+
422
+ void skinIndex; void skinWeight; void patchOf;
423
+ const patternColor = new Float32Array(nV * 4);
424
+ for (let v = 0; v < nV; v++) { patternColor[v * 4] = 0.016; patternColor[v * 4 + 1] = 0.0105; patternColor[v * 4 + 2] = 0.0075; patternColor[v * 4 + 3] = spotInt[v]; }
425
+ return { comb, tint, pattern: spotSDF, mark: markSDF, furLen, patternColor, stats: { spots: spots.length }, region, ventral, tailT };
426
+ }
427
+
@@ -0,0 +1,51 @@
1
+ // Cheetah (Acinonyx jubatus). Ported from the original procedural cheetah, which set the quality bar.
2
+ import { cheetahRig, HEAD_O } from './rig.js';
3
+ import { sculptCheetah, EYE } from './sculpt.js';
4
+ import { cheetahRegions } from './regions.js';
5
+ import { cheetahCoat } from './coat.js';
6
+ import { motion } from './motion.js';
7
+
8
+ export default {
9
+ id: 'cheetah',
10
+ name: 'Cheetah',
11
+ latin: 'Acinonyx jubatus',
12
+ group: 'paws',
13
+ plan: 'quadruped',
14
+ covering: 'fur',
15
+
16
+ // Seeded individual: size, proportions and coat. Adults only differ a little by sex (males ~10 %
17
+ // heavier, slightly larger heads); juveniles are smaller with relatively bigger heads and paws.
18
+ variation(R, o) {
19
+ const sex = o.sex || (R() < 0.5 ? 'male' : 'female');
20
+ const age = o.age || 'adult';
21
+ const juv = age === 'juvenile';
22
+ const g = () => (R() + R() + R() - 1.5) / 1.5; // ~[-1, 1], peaked
23
+ const size = (sex === 'male' ? 1.02 : 0.96) * (1 + 0.04 * g()) * (juv ? 0.62 : 1);
24
+ return {
25
+ sex, age, size,
26
+ warps: [
27
+ { type: 'legs', k: 1 + 0.035 * g() - (juv ? 0.06 : 0), top: 0.5 },
28
+ { type: 'length', k: 1 + 0.03 * g(), z0: -0.45, z1: 0.35 },
29
+ { type: 'scaleAbout', c: HEAD_O, k: (sex === 'male' ? 1.03 : 0.98) * (1 + 0.025 * g()) * (juv ? 1.18 : 1), r0: 0.07, r1: 0.16 },
30
+ ],
31
+ coatWarmth: 0.6 * g(),
32
+ coatLightness: 0.05 * g(),
33
+ coatSeed: Math.floor(R() * 1e6),
34
+ };
35
+ },
36
+ rig: () => cheetahRig(),
37
+ sculpt: (m, rig) => sculptCheetah(m, rig),
38
+ regions: cheetahRegions,
39
+ coat: cheetahCoat,
40
+ eyeSpecs: () => [1, -1].map((side) => ({ side, spec: EYE, headOrigin: HEAD_O, bone: 'head', look: EYE_LOOK })),
41
+ motion,
42
+ };
43
+
44
+ // Round pupil, amber iris, dark lid margins (the famous black "eyeliner").
45
+ export const EYE_LOOK = {
46
+ pupil: 'round',
47
+ lids: 'mammal',
48
+ iris: { inner: [0.2, 0.06, 0.007], mid: [0.54, 0.2, 0.022], hi: [0.78, 0.38, 0.055], outer: [0.26, 0.075, 0.009] },
49
+ lidColor: [0.5, 0.31, 0.15],
50
+ pupilSize: [0.3, 0.5],
51
+ };
@@ -0,0 +1,3 @@
1
+ // Reference-pose joints of the cheetah (see rig.js), exported for modules that need fixed landmarks.
2
+ import { cheetahJoints } from './rig.js';
3
+ export const J = cheetahJoints();
@@ -0,0 +1,77 @@
1
+ // Cheetah motion data for the quadruped engine (schema: src/core/motion/quadruped.js).
2
+ // Numbers are for the reference individual (params.size = 1, shoulder height ~0.76 m); the engine
3
+ // scales them by dynamic similarity for smaller / larger individuals.
4
+ //
5
+ // Gaits (from high-speed footage studies of cheetahs, Hildebrand 1959/1961, Hudson et al. 2012):
6
+ // lateral-sequence walk, trot, rotary canter and rotary gallop with two flight phases (gathered and
7
+ // extended); stride frequency rises only slowly with speed (2.3 -> 3.6 Hz), stride length does the work.
8
+ const G = (name, v, f, D, off, o) => ({ name, v, f, D, off, ...o });
9
+
10
+ export const motion = {
11
+ unit: 1, // the reference size the engine's own constants were tuned on
12
+ maxSpeed: 29,
13
+ moveCrouch: 0.02, // (its long, light legs need little extra flex; more stretched the neck and flank skin)
14
+ stride: { bob: 0.3 }, // (a sprinter runs flat: its back flexes, the body hardly bounces)
15
+ accel: [7, 10],
16
+ decel: 11,
17
+ turnRate: 2.4,
18
+ latAccelMax: 13,
19
+ gears: { walk: 1.25, trot: 3.0, canter: 5.6, gallop: 13, sprint: 27 },
20
+ gallopBlend: [4.5, 9],
21
+ gaits: [
22
+ G('walk', 0.0, 0.8, 0.7, [0.2, 0.7, 0.0, 0.5], { liftF: 0.06, liftH: 0.05, bobF: 0.006, bobH: 0.006, flex: 0.0, lat: 0.06, fold: 1.0, heel: 40, tail: 0, drop: 0.0 }),
23
+ G('walk', 1.5, 1.25, 0.62, [0.22, 0.72, 0.0, 0.5], { liftF: 0.075, liftH: 0.06, bobF: 0.01, bobH: 0.01, flex: 0.0, lat: 0.06, fold: 1.25, heel: 45, tail: 0.15, drop: 0.0 }),
24
+ G('trot', 2.4, 1.75, 0.46, [0.51, 0.01, 0.0, 0.5], { liftF: 0.11, liftH: 0.09, bobF: 0.022, bobH: 0.022, flex: 0.03, lat: 0.02, fold: 1.5, heel: 55, tail: 0.35, drop: 0.01 }),
25
+ G('trot', 3.6, 1.95, 0.41, [0.51, 0.01, 0.0, 0.5], { liftF: 0.13, liftH: 0.11, bobF: 0.026, bobH: 0.026, flex: 0.04, lat: 0.01, fold: 1.6, heel: 60, tail: 0.45, drop: 0.015 }),
26
+ G('canter', 5.2, 2.1, 0.36, [0.47, 0.35, 0.0, 0.14], { liftF: 0.17, liftH: 0.15, bobF: 0.022, bobH: 0.035, flex: 0.22, lat: 0, fold: 1.8, heel: 65, tail: 0.6, drop: 0.025 }),
27
+ G('gallop', 8.5, 2.3, 0.3, [0.62, 0.52, 0.0, 0.11], { liftF: 0.22, liftH: 0.2, bobF: 0.03, bobH: 0.05, flex: 0.38, lat: 0, fold: 1.95, heel: 70, tail: 0.8, drop: 0.035 }),
28
+ G('gallop', 16, 2.9, 0.25, [0.62, 0.5, 0.0, 0.13], { liftF: 0.26, liftH: 0.24, bobF: 0.03, bobH: 0.055, flex: 0.5, lat: 0, fold: 2.05, heel: 75, tail: 0.95, drop: 0.06 }),
29
+ G('sprint', 29, 3.6, 0.22, [0.63, 0.5, 0.0, 0.14], { liftF: 0.27, liftH: 0.25, bobF: 0.03, bobH: 0.055, flex: 0.56, lat: 0, fold: 2.1, heel: 78, tail: 1.0, drop: 0.07 }),
30
+ ],
31
+ feet: {
32
+ front: { type: 'digitigrade', curl: 55 },
33
+ hind: { type: 'digitigrade', curl: 70 },
34
+ },
35
+ stance: { width: 1, gallopWidth: 0.55, sprawl: 0, crouch: 0 },
36
+ // torso cross-sections (bind pose, reference size): centre height, half height, half width
37
+ body: {
38
+ chest: { y: 0.5, hh: 0.135, hw: 0.115 },
39
+ pelvis: { y: 0.55, hh: 0.105, hw: 0.12 }, // hw includes the thigh muscles (lying on the side)
40
+ rump: { z: -0.578, y: 0.6, hh: 0.115, hw: 0.097 }, // over the tail root (from the mesh; low enough for the flanks)
41
+ back: 0.075,
42
+ },
43
+ head: {
44
+ // stride nod [walk, trot, gallop, phase]: a cheetah holds its head famously still while it runs
45
+ nod: [0.03, 0.015, 0.012, 0.04],
46
+ // [speed, raise (m), reach (m), pitch (rad, + = nose down)]
47
+ carriage: [[0, 0.012, -0.012, 0], [4.5, 0.012, -0.012, 0], [9, -0.06, 0.045, 0.15]],
48
+ // [speed, stabilisation 0..1]
49
+ stab: [[0, 0], [0.9, 0.22], [1.8, 0.24], [4.5, 0.32], [9, 0.62]],
50
+ neckBend: 36, neckPivot: 0.6, yaw: 1.1, pitchUp: 0.5, pitchDown: 0.6,
51
+ },
52
+ tail: {
53
+ // [speed, pitch per segment from horizontal (deg), base -> tip]
54
+ carriage: [
55
+ [0.0, [-42, -58, -67, -72, -73, -68, -54, -30, 0, 22]],
56
+ [1.2, [-34, -50, -60, -63, -61, -53, -38, -16, 6, 22]],
57
+ [3.0, [-26, -35, -38, -37, -32, -24, -14, -3, 8, 17]],
58
+ [5.6, [-20, -22, -19, -14, -9, -4, 1, 6, 11, 16]],
59
+ [13, [-16, -12, -8, -5, -2, 1, 3, 6, 9, 13]],
60
+ [27, [-12, -8, -5, -2, 0, 2, 3, 5, 8, 11]],
61
+ ],
62
+ stiffness: 1, sway: 7, flick: 1, wag: 0, swish: 0, curl: 0,
63
+ balance: 1, // cheetah tail-use model in turns and speed changes
64
+ radius: [0.028, 0.016],
65
+ },
66
+ ears: { mobility: 1, speedFlatten: 0.7, twitch: 1, prick: 0.35 },
67
+ breath: { rate: 0.35, amp: 0.012, pant: true, pantRate: 2.6, pantAmp: 0.05, heatSpeed: 9 },
68
+ actions: {
69
+ attack: { style: 'bite-lunge' },
70
+ eat: { style: 'tear', dropF: 0.62, dropH: 0.7 }, // crouched over the kill: hindquarters down too
71
+ drink: { dropF: 0.72, dropH: 0.3, fold: 0.5 },
72
+ jump: { height: 0.75, distance: 3.2 },
73
+ sit: {},
74
+ lie: {},
75
+ sleep: { style: 'curl' },
76
+ },
77
+ };
@@ -0,0 +1,95 @@
1
+ // Meshing plan: body at 5.4 mm, head at 2.5 mm (overlapping across the upper neck and cross-faded),
2
+ // eyelid patches at 1 mm, and the lower jaw as its own surface so the mouth can open.
3
+ import { J } from './joints.js';
4
+ import { EYE } from './sculpt.js';
5
+ import { HEAD_O, TAIL_SEGS } from './rig.js';
6
+ import { eyeFrameOf } from '../../core/sdf/eyeSocket.js';
7
+ import { lerp, norm, sub, smoothstep } from '../../core/math/vec.js';
8
+
9
+ export const NECK_CUT = (() => {
10
+ const d = norm(sub(J.occiput, J.neckMid));
11
+ const c = lerp(J.neckMid, J.occiput, 0.55);
12
+ return { c, d, band: 0.012 };
13
+ })();
14
+ export const neckS = (x, y, z) => (x - NECK_CUT.c[0]) * NECK_CUT.d[0] + (y - NECK_CUT.c[1]) * NECK_CUT.d[1] + (z - NECK_CUT.c[2]) * NECK_CUT.d[2];
15
+
16
+ export const EYE_PATCH = { R: 0.021, B: 0.004, h: 0.001, centres: [1, -1].map((s) => eyeFrameOf(EYE, HEAD_O, s).c) };
17
+ export function eyePatchWeight(x, y, z) {
18
+ let dmin = 1e9;
19
+ for (const c of EYE_PATCH.centres) dmin = Math.min(dmin, Math.hypot(x - c[0], y - c[1], z - c[2]));
20
+ return 1 - smoothstep(EYE_PATCH.R - EYE_PATCH.B, EYE_PATCH.R + EYE_PATCH.B, dmin);
21
+ }
22
+
23
+ // The tail as a polyline tail0 .. tail10: arc length s from the tail root and distance d of the
24
+ // closest point (bind pose). Only tail skin lies within TAIL_R of the polyline past the cut.
25
+ const TAIL_PTS = Array.from({ length: TAIL_SEGS + 1 }, (_, i) => J['tail' + i]);
26
+ const TAIL_ACC = TAIL_PTS.map((_, i) => TAIL_PTS.slice(1, i + 1).reduce((a, p, k) => a + norm3(sub(p, TAIL_PTS[k])), 0));
27
+ function norm3(v) { return Math.hypot(v[0], v[1], v[2]); }
28
+ export function tailSD(x, y, z) {
29
+ let best = 1e9, bs = 0;
30
+ for (let i = 0; i < TAIL_SEGS; i++) {
31
+ const a = TAIL_PTS[i], b = TAIL_PTS[i + 1];
32
+ const ab = [b[0] - a[0], b[1] - a[1], b[2] - a[2]], L2 = ab[0] * ab[0] + ab[1] * ab[1] + ab[2] * ab[2];
33
+ let t = ((x - a[0]) * ab[0] + (y - a[1]) * ab[1] + (z - a[2]) * ab[2]) / L2;
34
+ t = t < 0 ? 0 : t > 1 ? 1 : t;
35
+ const d = Math.hypot(x - a[0] - ab[0] * t, y - a[1] - ab[1] * t, z - a[2] - ab[2] * t);
36
+ if (d < best) { best = d; bs = TAIL_ACC[i] + t * (TAIL_ACC[i + 1] - TAIL_ACC[i]); }
37
+ }
38
+ return [bs, best];
39
+ }
40
+ const TAIL_R = 0.05;
41
+ export const TAIL_CUT = TAIL_ACC[3]; // tail3
42
+
43
+ export function cheetahRegions(rig, params, Q) {
44
+ const r = Q.res, hBody = 0.0054 * r, hHead = 0.0025 * r;
45
+ // The band is at least about a body cell wide on each side (low: 16 mm cells, crowd: 23 mm), so the
46
+ // seam skirt that sinks the surface handing over (fade 0.5 -> 0.1) spans whole triangles.
47
+ const B = Math.max(NECK_CUT.band, 1.1 * hBody);
48
+ // Without fur shells (crowd tier) the coarse body surface (2 cm cells) and the head surface do not
49
+ // coincide in the overlap band: a hard switch at the cut left see-through slits under the throat.
50
+ // There each surface stays visible past the cut by D (they overlap and the depth test picks the
51
+ // outer one); with shells the surfaces are fine enough and the band stays a clean switch.
52
+ const D = Q.shells > 0 ? 0 : 0.6 * 0.0054 * r;
53
+ // The mesher keeps whole cells (by centre), so a clipped surface ends up to ~1.4 cells inside its
54
+ // clip plane: each clip lies 1.5 cells past the point where the surface's fade reaches 0.1 (where
55
+ // the renderer stops drawing it, 0.61 B past its midline). A clip at the band edge left the body's
56
+ // rim in the visible half of the band at the low tier (see-through specks at the side of the neck).
57
+ const cBody = D + 0.61 * B + 1.5 * hBody, cHead = D + 0.61 * B + 1.5 * hHead;
58
+ const patches = Q.eyePatches ? EYE_PATCH.centres.map((c) => ({ c, R: EYE_PATCH.R, B: EYE_PATCH.B, h: EYE_PATCH.h * Math.max(1, r) })) : [];
59
+ // Crowd tier: at 23 mm body cells the tail (rings ~25 mm wide, 50 mm apart, a 25 mm white tip) is
60
+ // meshed at about one ring period and loses its rings and tip, so from tail3 on the tail is its own
61
+ // ~1 cm region, cross-faded with the body like the neck (~ +600 vertices of the 8k budget).
62
+ const tailOwn = Q.shells <= 0, hTail = 0.0098, BT = 1.1 * hBody;
63
+ const cTailBody = 0.61 * BT + 1.5 * hBody, cTail = 0.61 * BT + 1.5 * hTail;
64
+ const inTail = (x, y, z, c) => { const [s, d] = tailSD(x, y, z); return d < TAIL_R && s > TAIL_CUT + c; };
65
+ const bodyClip = tailOwn
66
+ ? (x, y, z) => neckS(x, y, z) < cBody && !inTail(x, y, z, cTailBody)
67
+ : (x, y, z) => neckS(x, y, z) < cBody;
68
+ const jobs = [
69
+ [{ name: 'body', part: 'body', bmin: [-0.2, -0.03, -1.2], bmax: [0.2, 0.93, 0.62], h: hBody, F: 4, clip: bodyClip }],
70
+ [
71
+ { name: 'head', part: 'body', bmin: [-0.1, 0.64, 0.42], bmax: [0.1, 0.91, 0.73], h: hHead, F: 6, clip: (x, y, z) => neckS(x, y, z) > -cHead, patches },
72
+ { name: 'jaw', part: 'jaw', bmin: [-0.07, 0.69, 0.55], bmax: [0.07, 0.8, 0.72], h: hHead, F: 6, rigidBone: 'jaw' },
73
+ ],
74
+ ];
75
+ if (tailOwn) {
76
+ const lo = [1, 1, 1], hi = [-1, -1, -1];
77
+ for (const p of TAIL_PTS.slice(2)) for (let k = 0; k < 3; k++) { lo[k] = Math.min(lo[k], p[k] - TAIL_R); hi[k] = Math.max(hi[k], p[k] + TAIL_R); }
78
+ jobs.push([{ name: 'tail', part: 'body', bmin: lo, bmax: hi, h: hTail, F: 4, clip: (x, y, z) => inTail(x, y, z, -cTail) }]);
79
+ }
80
+ const tailFade = (x, y, z) => { const [s, d] = tailSD(x, y, z); return d < TAIL_R ? smoothstep(-BT, BT, s - TAIL_CUT) : 0; };
81
+ return {
82
+ jobs,
83
+ fade(x, y, z, name, patch) {
84
+ const sN = neckS(x, y, z);
85
+ if (name === 'body') return (1 - smoothstep(-B, B, sN - D)) * (tailOwn ? 1 - tailFade(x, y, z) : 1);
86
+ if (name === 'tail') return tailFade(x, y, z);
87
+ if (name === 'head') {
88
+ let f = smoothstep(-B, B, sN + D);
89
+ if (patches.length) { const ew = eyePatchWeight(x, y, z); f *= patch ? ew : 1 - ew; }
90
+ return f;
91
+ }
92
+ return 1;
93
+ },
94
+ };
95
+ }