@adatechnology/game-characters-three 0.8.0 → 0.9.0

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.
@@ -521,7 +521,7 @@ var createBestBuilder = (host, { types, random = Math.random }) => {
521
521
  };
522
522
  function build(spec) {
523
523
  const ti = Math.max(0, BCARDS.findIndex((x) => x.n === spec.type)), z = BCARDS[ti];
524
- const P = Object.assign({}, BASE, TYPES[spec.type] || {}, spec.pose || {}), d = spec.decay ?? 0, life = spec.life ?? 1, cut = spec.cut || {};
524
+ const P = Object.assign({}, BASE, TYPES[spec.type ?? ""] || {}, spec.pose || {}), d = spec.decay ?? 0, life = spec.life ?? 1, cut = spec.cut || {};
525
525
  P.s *= spec.h ?? 1;
526
526
  P.bulk *= spec.bulk ?? 1;
527
527
  if (life === 0) {
@@ -585,7 +585,7 @@ var createBestBuilder = (host, { types, random = Math.random }) => {
585
585
  };
586
586
  const ball = (p2, r, m, x, y, z2) => add(p2, SPH(r, SEG, 12), m, x, y, z2);
587
587
  topM_ref = topM;
588
- const SKM = {}, skM = (c) => SKM[c] || (SKM[c] = new THREE.MeshStandardMaterial({ color: c, roughness: 0.3, metalness: 0, polygonOffset: true, polygonOffsetFactor: -4, polygonOffsetUnits: -4 }));
588
+ const SKM = {}, skM = (c) => SKM[String(c)] || (SKM[String(c)] = new THREE.MeshStandardMaterial({ color: c, roughness: 0.3, metalness: 0, polygonOffset: true, polygonOffsetFactor: -4, polygonOffsetUnits: -4 }));
589
589
  const flat = (p2, x, y, zz, sx, sy, c) => {
590
590
  const m = new THREE.Mesh(BLOB, skM(c));
591
591
  m.rotation.set(PI / 2, 0, BR() * 6.28);
@@ -1004,7 +1004,7 @@ var createBestBuilder = (host, { types, random = Math.random }) => {
1004
1004
  root.userData.rig = rig;
1005
1005
  return root;
1006
1006
  }
1007
- const marked = (...args) => markKitOrigin(build(...args), { owner: "game-characters-three", kind: "person" });
1007
+ const marked = (spec) => markKitOrigin(build(spec), { owner: "game-characters-three", kind: "person" });
1008
1008
  return { build: marked, TYPES, setLOD(k) {
1009
1009
  LK = k;
1010
1010
  SEG = Math.max(5, Math.round(16 * k));
@@ -1342,12 +1342,12 @@ var HATS = [
1342
1342
  const o = add(Hd, cap(0.205, PI / 2), c, 0, 1.835, -5e-3);
1343
1343
  o.scale.set(1, 0.98, 1.08);
1344
1344
  add(Hd, new THREE.CylinderGeometry(0.208, 0.212, 0.04, 20), c, 0, 1.84, -5e-3);
1345
- if (sp.hat.tape) add(Hd, new THREE.CylinderGeometry(0.205, 0.207, 0.035, 20), cmat(sp.hat.tape), 0, 1.9, -5e-3);
1346
- if (sp.hat.photo) {
1345
+ if (sp.hat?.tape) add(Hd, new THREE.CylinderGeometry(0.205, 0.207, 0.035, 20), cmat(sp.hat.tape), 0, 1.9, -5e-3);
1346
+ if (sp.hat?.photo) {
1347
1347
  add(Hd, Bx(0.07, 0.08, 0.012), cmat(16052448), 0.13, 1.9, 0.14, 0, 0.75, 0);
1348
1348
  add(Hd, Bx(0.05, 0.055, 0.014), cmat(9071184), 0.13, 1.9, 0.141, 0, 0.75, 0);
1349
1349
  }
1350
- if (sp.hat.nvg) {
1350
+ if (sp.hat?.nvg) {
1351
1351
  add(Hd, Bx(0.07, 0.05, 0.06), cmat(1710618), 0, 2, 0.175);
1352
1352
  for (const s of [-1, 1]) add(Hd, new THREE.CylinderGeometry(0.024, 0.024, 0.09, 10).rotateX(PI / 2), cmat(2767402), s * 0.032, 1.965, 0.235);
1353
1353
  }
@@ -2061,7 +2061,7 @@ var createPersonBuilder = (host, options = {}) => {
2061
2061
  const hg = new THREE.Group();
2062
2062
  hg.position.y = -0.3;
2063
2063
  el.add(hg);
2064
- const handM = glove ? cmat(glove[1]) : skinM;
2064
+ const handM = glove ? cmat(glove[1] ?? 16777215) : skinM;
2065
2065
  const palm = ball(hg, 0.048, handM, 0, -0.035, 0);
2066
2066
  palm.scale.set(0.6, 1.05, 1);
2067
2067
  const { fingers, th } = buildHand({ THREE, add, hg, handM, s, detailed });
@@ -2073,7 +2073,7 @@ var createPersonBuilder = (host, options = {}) => {
2073
2073
  }
2074
2074
  for (const e of sp.ex || []) {
2075
2075
  const [k, c] = e;
2076
- const m = c !== void 0 ? cmat(c) : null;
2076
+ const m = c !== void 0 ? cmat(c) : topM;
2077
2077
  EXTRAS[k]?.({ THREE, PI, U, Hd, root, add, Bx, cmat, ring, torsoGeo, legs, arms, fem, topM, m, e, k, headG, fig, upper, skinM, sp, splat, R, ball, cap, hc });
2078
2078
  }
2079
2079
  if (sp.back === "shotgun") {
@@ -2094,10 +2094,11 @@ var createPersonBuilder = (host, options = {}) => {
2094
2094
  const metal = cmat(9080982, { metalness: 0.7, roughness: 0.35 }), dark = cmat(1842463, { metalness: 0.6, roughness: 0.45 }), woodM = cmat(6961692);
2095
2095
  HAND_ITEMS[kind]?.({ THREE, PI, add, Bx, cmat, g, metal, dark, woodM, lights: options.lights, sources: lightSources });
2096
2096
  }
2097
- item(sp.hand, arms[0].mount);
2098
- item(sp.lhand, arms[1].mount);
2099
- if (sp.hand) arms[0].hold = true;
2100
- if (sp.lhand) arms[1].hold = true;
2097
+ const [rightArm, leftArm] = arms;
2098
+ item(sp.hand, rightArm.mount);
2099
+ item(sp.lhand, leftArm.mount);
2100
+ if (sp.hand) rightArm.hold = true;
2101
+ if (sp.lhand) leftArm.hold = true;
2101
2102
  const zb = [];
2102
2103
  for (let i = 0; i < 4; i++) splat(U, -0.15 + R() * 0.3, 1.2 + R() * 0.25, 0.17, 0.035 + R() * 0.025, 3874068, 3, zb);
2103
2104
  {
@@ -2141,8 +2142,9 @@ var createPersonBuilder = (host, options = {}) => {
2141
2142
  segs["shin" + k] = { node: l.kn, label: "Canela e p\xE9 " + LSIDE[k], hp: 55, r: 0.08, leg: k };
2142
2143
  });
2143
2144
  for (const k in segs) {
2144
- segs[k].max = segs[k].hp;
2145
- segs[k].state = "ok";
2145
+ const seg = segs[k];
2146
+ seg.max = seg.hp;
2147
+ seg.state = "ok";
2146
2148
  }
2147
2149
  const mouth = add(Hd, Bx(0.1, 0.04, 0.02), cmat(3803656), 0, 1.69, 0.145);
2148
2150
  mouth.visible = false;
@@ -2210,7 +2212,7 @@ var createPersonBuilder = (host, options = {}) => {
2210
2212
  if (a.fingers) {
2211
2213
  const gr = (a.hold || a.grip ? 1.25 : 0.4) * (z ? 0.5 : 1);
2212
2214
  a.fingers.forEach((f, j) => f.rotation.z = -a.s * gr * (j % 2 ? 1.1 : 0.9));
2213
- a.th.rotation.z = -a.s * (0.45 + gr * 0.25);
2215
+ if (a.th) a.th.rotation.z = -a.s * (0.45 + gr * 0.25);
2214
2216
  a.hg.rotation.x = reduce ? 0 : -W * Math.sin(ph - 0.6) * 0.15 * a.s;
2215
2217
  }
2216
2218
  });
@@ -2224,7 +2226,7 @@ var createPersonBuilder = (host, options = {}) => {
2224
2226
  }
2225
2227
  function zombify(c, cat) {
2226
2228
  c.skinM.color.copy(c.base).lerp(ZSKIN2, 1);
2227
- c.eyeM.color.set(EYE[cat || "lento"]);
2229
+ c.eyeM.color.set(EYE[cat || "lento"] ?? EYE.lento);
2228
2230
  c.zb.forEach((b) => b.visible = true);
2229
2231
  c.mouth.visible = true;
2230
2232
  c.bags.material.opacity = 0.9;
@@ -2236,7 +2238,7 @@ var createPersonBuilder = (host, options = {}) => {
2236
2238
  chars.push(c);
2237
2239
  root.add(c.root);
2238
2240
  if (zed && !p2.kid) zombify(c, p2.zcat);
2239
- c.z = zed && !p2.kid;
2241
+ c.z = !!(zed && !p2.kid);
2240
2242
  }
2241
2243
  (p2.kids || []).forEach((k) => {
2242
2244
  const c = build(k, 0);
@@ -2246,7 +2248,7 @@ var createPersonBuilder = (host, options = {}) => {
2246
2248
  chars.push(c);
2247
2249
  root.add(c.root);
2248
2250
  });
2249
- chars.forEach((c) => pose(c, c.z, 0, 0));
2251
+ chars.forEach((c) => pose(c, !!c.z, 0, 0));
2250
2252
  return { root, chars };
2251
2253
  }
2252
2254
  const mark = (c) => {
@@ -3646,74 +3648,24 @@ var hitFor = (preset2, origin, y, known) => {
3646
3648
  var hex = (value) => parseInt(value, 16);
3647
3649
  var personSpecOf = (profession) => {
3648
3650
  const { look } = profession;
3649
- const spec = {
3651
+ const ex = profession.accessories.map((accessory) => accessory.color ? [accessory.id, hex(accessory.color)] : [accessory.id]);
3652
+ return {
3650
3653
  skin: hex(look.skin),
3651
3654
  hair: { s: look.hair.style, c: hex(look.hair.color) },
3652
3655
  top: { c: hex(look.top.color), sl: look.top.sleeve, ...look.top.plaid ? { plaid: hex(look.top.plaid) } : {} },
3653
3656
  pants: { c: hex(look.pants.color) },
3654
3657
  shoes: hex(look.shoes),
3655
- ex: profession.accessories.map((accessory) => accessory.color ? [accessory.id, hex(accessory.color)] : [accessory.id])
3658
+ ex,
3659
+ ...profession.female ? { fem: 1 } : {},
3660
+ ...look.hat ? { hat: { k: look.hat.kind, c: hex(look.hat.color) } } : {},
3661
+ ...look.face && look.face.length > 0 ? { face: [...look.face] } : {},
3662
+ ...profession.hand ? { hand: profession.hand } : {},
3663
+ ...profession.leftHand ? { lhand: profession.leftHand } : {}
3656
3664
  };
3657
- if (profession.female) spec.fem = 1;
3658
- if (look.hat) spec.hat = { k: look.hat.kind, c: hex(look.hat.color) };
3659
- if (look.face && look.face.length > 0) spec.face = [...look.face];
3660
- if (profession.hand) spec.hand = profession.hand;
3661
- if (profession.leftHand) spec.lhand = profession.leftHand;
3662
- return spec;
3663
3665
  };
3664
3666
 
3665
3667
  // src/test-area/knock.ts
3666
- import { blastShove } from "@adatechnology/game-contracts";
3667
- var KNOCK_DOWN_SPEED = 2.5;
3668
- var KNOCKED_DOWN_ANGLE = 1.35;
3669
- var LIE_SECONDS = 1.6;
3670
- var STAND_UP_PER_SPEED = 0.25;
3671
- var FALL_SECONDS = 0.25;
3672
- var RISE_SECONDS = 0.6;
3673
- var GROUND_FRICTION = 7;
3674
- var GRAVITY2 = 9.81;
3675
- var CHEST = 1.1;
3676
- var bodyMass = (height, build = 1) => 70 * (height / 1.75) ** 2 * build;
3677
- function knockOf(blast, feet, mass, options) {
3678
- const hit = blastShove(blast, { position: [feet[0], feet[1] + CHEST, feet[2]], mass }, options);
3679
- if (!hit) return void 0;
3680
- const [dx, dy, dz] = hit.direction;
3681
- return { velocity: [dx * hit.speed, Math.max(0, dy * hit.speed), dz * hit.speed], airborne: dy > 0, lying: 0, lieLeft: 0, down: hit.speed >= KNOCK_DOWN_SPEED };
3682
- }
3683
- function stepKnock(knock, position, dt, groundAt, alive) {
3684
- const v = knock.velocity;
3685
- position.x += v[0] * dt;
3686
- position.z += v[2] * dt;
3687
- const ground = groundAt(position.x, position.z);
3688
- if (knock.airborne || position.y > ground + 1e-4) {
3689
- v[1] -= GRAVITY2 * dt;
3690
- position.y += v[1] * dt;
3691
- if (position.y <= ground) {
3692
- position.y = ground;
3693
- v[1] = 0;
3694
- knock.airborne = false;
3695
- }
3696
- } else position.y = ground;
3697
- const horizontal = Math.hypot(v[0], v[2]);
3698
- if (!knock.airborne && horizontal > 0) {
3699
- const slowed = Math.max(0, horizontal - GROUND_FRICTION * dt);
3700
- v[0] *= slowed / horizontal;
3701
- v[2] *= slowed / horizontal;
3702
- }
3703
- const moving = horizontal > 0.05 || knock.airborne;
3704
- if (knock.down) {
3705
- if (moving) knock.lying = Math.min(1, knock.lying + dt / FALL_SECONDS);
3706
- else {
3707
- knock.lying = 1;
3708
- if (alive) {
3709
- knock.lieLeft = knock.lieLeft > 0 ? knock.lieLeft : LIE_SECONDS + Math.hypot(v[0], v[2]) * STAND_UP_PER_SPEED;
3710
- knock.lieLeft -= dt;
3711
- if (knock.lieLeft <= 0) knock.down = false;
3712
- }
3713
- }
3714
- } else if (knock.lying > 0) knock.lying = Math.max(0, knock.lying - dt / RISE_SECONDS);
3715
- return !moving && !knock.down && knock.lying === 0;
3716
- }
3668
+ import { bodyMass, KNOCK_CHEST, KNOCK_DOWN_SPEED, KNOCKED_DOWN_ANGLE, knockOf, stepKnock } from "@adatechnology/game-contracts";
3717
3669
 
3718
3670
  // src/test-area/scenarios.ts
3719
3671
  import { SEGMENT_IDS } from "@adatechnology/game-characters";
@@ -4359,7 +4311,8 @@ function createCharactersTestModule(options = {}) {
4359
4311
  for (const entry of entries.values()) {
4360
4312
  if (!entry.root.parent) continue;
4361
4313
  const p2 = entry.root.position;
4362
- const knock = knockOf(event, [p2.x, p2.y, p2.z], bodyMass(entry.character.spec.height, entry.character.spec.build), lent.blastShove);
4314
+ const reach = lent.blastReach?.(event.point, [p2.x, p2.y + KNOCK_CHEST, p2.z], [event.source, entry.id]) ?? 1;
4315
+ const knock = knockOf({ ...event, reach }, [p2.x, p2.y, p2.z], bodyMass(entry.character.spec.height, entry.character.spec.build), lent.blastShove);
4363
4316
  if (knock) entry.knock = entry.knock ? { ...knock, lying: entry.knock.lying } : knock;
4364
4317
  }
4365
4318
  });
@@ -4658,4 +4611,4 @@ export {
4658
4611
  AVATAR_AREA_ID,
4659
4612
  createAvatarTestModule
4660
4613
  };
4661
- //# sourceMappingURL=chunk-3CHBEUHW.js.map
4614
+ //# sourceMappingURL=chunk-XSMP7T6O.js.map