@hackbuild/agents-views 0.2.8 → 0.2.10

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.
package/README.md CHANGED
@@ -51,7 +51,7 @@ setInterval(() => {
51
51
 
52
52
  ## Live example
53
53
 
54
- Three demo pages run one yard built in code through a scripted day, so the views move with nobody at the keys: [drive bars](https://hackbuild.github.io/hackbuild-agents/drives-bars/), [associations table](https://hackbuild.github.io/hackbuild-agents/associations-table/) and [eye card](https://hackbuild.github.io/hackbuild-agents/eye-inset/). The suite's [creature with drives](https://hackbuild.github.io/hackbuild-suite/#/examples/think/drives) puts the bars beside a running animal.
54
+ Three demo pages run one yard built in code through a scripted day, so the views move with nobody at the keys: [drive bars](https://hackbuild.github.io/hackbuild-agents/drives-bars/), [associations table](https://hackbuild.github.io/hackbuild-agents/associations-table/) and [eye card](https://hackbuild.github.io/hackbuild-agents/eye-inset/). The suite's [creature with drives](https://hackbuild.github.io/hackbuild-suite/#/recipes/think/drives) puts the bars beside a running animal.
55
55
 
56
56
  ## Concepts
57
57
 
@@ -1724,6 +1724,17 @@ function trailDir(p, prev) {
1724
1724
  }
1725
1725
  function puffConc(x, z) { let c = 0; for (const p of puffs) { const s2 = 0.0025 + 0.03 * p.age, dx = x - p.x, dz = z - p.z, d2 = dx * dx + dz * dz; if (d2 < 9 * s2) c += p.m * 0.012 / s2 * Math.exp(-d2 / (2 * s2)); } return c; }
1726
1726
  function groundConc(x, z) { const i = tgi(x, z); return i < 0 ? 0 : trail[i] * 0.5; }
1727
+ // what the dog smells where it stands: the stronger of the field under its body and at its nose,
1728
+ // and with `reach` the ground one step around the nose as well, as a sniffing sweep covers. A
1729
+ // chase stops the body about 0.75 m short of the squirrel's trail at its tree (measured), so the
1730
+ // search found that trail on 1 of 6 seeds, and 5 of 6 with the nose and its reach (dog simulator
1731
+ // scenario scent-trail, measured)
1732
+ function smellAt(field, reach = 0) {
1733
+ const n = headWorld(dog.noseL, V3());
1734
+ let m = Math.max(field(dog.pos.x, dog.pos.z), field(n.x, n.z));
1735
+ if (reach) for (let dz = -1; dz <= 1; dz++) for (let dx = -1; dx <= 1; dx++) m = Math.max(m, field(n.x + dx * reach, n.z + dz * reach));
1736
+ return m;
1737
+ }
1727
1738
  // scent at a point: the plume model, or the older smooth gaussian field when the layer is off
1728
1739
  function scentAt(x, z) {
1729
1740
  if (ON('L.plume')) return puffConc(x, z) + groundConc(x, z);
@@ -1767,7 +1778,7 @@ function sniffRun(B, dt) {
1767
1778
  }
1768
1779
  const S = B.sn || (B.sn = { mode: 'cast', side: RNG() < 0.5 ? 1 : -1, amp: 0.8, wp: null, t: 0 });
1769
1780
  const up = V3(-wind.v.x, 0, -wind.v.z); if (up.lengthSq() < 1e-4) up.set(Math.sin(dog.yaw), 0, Math.cos(dog.yaw)); up.normalize();
1770
- const cross = V3(-up.z, 0, up.x), lr = sniff.cL - sniff.cR, gnd = groundConc(dog.pos.x, dog.pos.z);
1781
+ const cross = V3(-up.z, 0, up.x), lr = sniff.cL - sniff.cR, gnd = smellAt(groundConc, TGS / TG);
1771
1782
  S.t += dt;
1772
1783
  // ground trail: a deciding phase of 3 to 5 s at half speed over a few footprints, then follow toward the fresher end (Thesen 1993, Hepper and Wells 2005)
1773
1784
  if (gnd > 0.08 && S.mode !== 'decide' && S.mode !== 'trail' && (!S.trailDone || now - S.trailDone > 15)) { S.mode = 'decide'; S.dEnd = now + ORG.exg(3.2, 0.5, 1); S.wp = null; }
@@ -1778,7 +1789,7 @@ function sniffRun(B, dt) {
1778
1789
  return;
1779
1790
  }
1780
1791
  if (S.mode === 'trail') {
1781
- if (!S.wp || motor.done) { const d = trailDir(dog.pos, S.tdir); if (!d || groundConc(dog.pos.x, dog.pos.z) < 0.03) { S.mode = 'cast'; S.trailDone = now; S.wp = null; } else { S.tdir = d; S.wp = dog.pos.clone().addScaledVector(d, 1.5); pushOut(S.wp, 0.4); motor.done = false; } }
1792
+ if (!S.wp || motor.done) { const d = trailDir(dog.pos, S.tdir); if (!d || smellAt(groundConc) < 0.03) { S.mode = 'cast'; S.trailDone = now; S.wp = null; } else { S.tdir = d; S.wp = dog.pos.clone().addScaledVector(d, 1.5); pushOut(S.wp, 0.4); motor.done = false; } }
1782
1793
  if (S.wp) { motor.mode = 'goto'; motor.target.copy(S.wp); motor.speed = 0.9; motor.stopDist = 0.3; }
1783
1794
  dog.head.tPitch = 0.9 - dog.bodyPitch + (NG.active ? 0.25 : 0); dog.head.tYaw = Math.sin(now * 2.2) * 0.25;
1784
1795
  if (S.t > 24) { B.done = true; B.sn = null; }
@@ -2318,7 +2329,7 @@ Object.assign(brain, {
2318
2329
  const ballMoving = ballP && ballP.vis && ballP.speed > 1.2;
2319
2330
  const ballAtYou = ball && !ball.held && bodyPos(ball).distanceTo(V3(YOU.x, bodyPos(ball).y, YOU.z)) < 1.3;
2320
2331
  const nearYou = Math.hypot(dog.pos.x - YOU.x, dog.pos.z - YOU.z) < 1.8, youDist = dist2(dog.pos, YOU);
2321
- const sc = scentAt(dog.pos.x, dog.pos.z), youVis = percepts.you && percepts.you.vis;
2332
+ const sc = smellAt(scentAt), youVis = percepts.you && percepts.you.vis;
2322
2333
  const sleepy = ON('L.sleep') ? 0.8 * this.Sp + 0.5 * (this.circ ?? 0.3) : d.fatigue;
2323
2334
  if (ON('L.drives')) {
2324
2335
  const G = (b, s = 1) => this.gain(EFFECT[b], s);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hackbuild/agents-views",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "Views that bind the agents packages to the hackbuild-ui class layer: the behaviour, utility and drive bars, the cues by acts associations table, the eye inset, and Yard, the dog simulator's stage and rack as one view. Each small view ships as a Vue component and as a custom element.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -48,7 +48,7 @@
48
48
  "@hackbuild/motion-net": "^0.2.0",
49
49
  "@hackbuild/gait": "^0.1.0",
50
50
  "@hackbuild/tunables": "^0.1.0",
51
- "@hackbuild/senses": "0.1.4",
51
+ "@hackbuild/senses": "0.1.5",
52
52
  "@hackbuild/drives": "0.1.5",
53
53
  "@hackbuild/cameras": "^0.1.0",
54
54
  "@hackbuild/weights": "^0.1.0"