@adatechnology/game-characters-three 0.4.2 → 0.5.1

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/dist/index.js CHANGED
@@ -4065,6 +4065,7 @@ function createCharactersTestModule(options = {}) {
4065
4065
  return {
4066
4066
  id: CHARACTERS_AREA_ID,
4067
4067
  name: text.name,
4068
+ ground: { surface: "concrete_slab" },
4068
4069
  group: text.group,
4069
4070
  get entries() {
4070
4071
  return entries;
@@ -4378,6 +4379,24 @@ var createPlayerAvatar = (THREE, options = {}) => {
4378
4379
  });
4379
4380
  return { armR: shoulder, armL: shoulder, armRz: AIMED.zRight, armLz: AIMED.zLeft, elbR: AIMED.elbowRight, elbL: AIMED.elbowLeft };
4380
4381
  };
4382
+ const pushingPose = (push) => {
4383
+ const on = push.phase === "grip" ? Math.min(1, push.progress * 2.2) : 1;
4384
+ const strain = push.phase === "strain" ? 1 : 0;
4385
+ const shake = strain * Math.sin(time * 40) * 0.025;
4386
+ const raise = -1.5 * on;
4387
+ const elbow = -0.9 + 0.72 * (push.phase === "grip" ? push.progress : 1) + strain * 0.12;
4388
+ return {
4389
+ lean: (0.2 + 0.2 * strain) * on,
4390
+ headX: (0.05 + 0.08 * strain) * on,
4391
+ armR: raise + shake,
4392
+ armL: raise - shake,
4393
+ armRz: -0.08 * on,
4394
+ armLz: 0.08 * on,
4395
+ elbR: elbow,
4396
+ elbL: elbow,
4397
+ ...strain ? { legL: -0.5, legR: 0.4, kneeL: 0.55, kneeR: 0.08, drop: -0.05 } : {}
4398
+ };
4399
+ };
4381
4400
  const holdingPose = (gait, itemUse) => {
4382
4401
  const bob = Math.sin(cycles * TWO_PI) * 0.05 * gait;
4383
4402
  if (!itemUse) {
@@ -4505,7 +4524,7 @@ var createPlayerAvatar = (THREE, options = {}) => {
4505
4524
  const fireClipEvents = (r, from, to) => {
4506
4525
  for (const event of clipEventsBetween(r.clip, from, to)) emit({ ...event, clip: r.clip.id }, r.onEvent);
4507
4526
  };
4508
- const stepClip = (dt, down) => {
4527
+ const stepClip = (dt, down, crouch) => {
4509
4528
  if (!run) return;
4510
4529
  const r = run;
4511
4530
  const from = r.time;
@@ -4525,7 +4544,9 @@ var createPlayerAvatar = (THREE, options = {}) => {
4525
4544
  return;
4526
4545
  }
4527
4546
  if (down) return;
4528
- const sampled = filterPoseChannels(samplePoseClip(r.clip, Math.min(r.time, duration)), r.clip.channels ?? "full");
4547
+ const keepsCrouch = crouch && !r.clip.events?.some((event) => event.data?.kind === "kick");
4548
+ const channels = r.clip.channels ?? "full";
4549
+ const sampled = filterPoseChannels(filterPoseChannels(samplePoseClip(r.clip, Math.min(r.time, duration)), channels), keepsCrouch ? "upper" : "full");
4529
4550
  const current = readPose();
4530
4551
  const blended = {};
4531
4552
  for (const [name, value] of Object.entries(sampled)) if (name in current) blended[name] = current[name] + (value - current[name]) * r.weight;
@@ -4556,7 +4577,8 @@ var createPlayerAvatar = (THREE, options = {}) => {
4556
4577
  else {
4557
4578
  if (running) animator.setPose(rig, runningPose(gait, Boolean(state.armed || state.holding || state.itemUse)));
4558
4579
  if (state.crouch) animator.setPose(rig, crouchPose(gait));
4559
- if (state.armed) animator.setPose(rig, armed(state.pitch ?? 0, gait, state.hip ?? 0));
4580
+ if (state.push) animator.setPose(rig, pushingPose(state.push));
4581
+ else if (state.armed) animator.setPose(rig, armed(state.pitch ?? 0, gait, state.hip ?? 0));
4560
4582
  else if (state.holding || state.itemUse) animator.setPose(rig, holdingPose(gait, state.itemUse));
4561
4583
  else if (!running) {
4562
4584
  animator.setPose(rig, {
@@ -4568,15 +4590,15 @@ var createPlayerAvatar = (THREE, options = {}) => {
4568
4590
  }
4569
4591
  }
4570
4592
  placeBody(fall);
4571
- stepClip(dt, down);
4593
+ stepClip(dt, down, Boolean(state.crouch));
4572
4594
  if (smooth) animator.cascade(rig, run && !run.clip.loop ? dt * clipCascade : dt);
4573
- const clipId = run ? run.clip.id : null;
4595
+ const blow = run?.clip.events?.find((event) => (event.type === "impact" || event.type === "grip") && event.data?.kind)?.data?.kind;
4574
4596
  const ph = cycles * TWO_PI;
4575
4597
  hands.forEach((hand) => {
4576
4598
  const isRight = hand.side < 0;
4577
4599
  const holdRight = isRight && (!!state.holding || !!state.itemUse);
4578
4600
  const holdLeft = !isRight && (state.itemUse?.id === "open" || state.itemUse?.id === "close");
4579
- const grip = clipId?.startsWith("punch_") ? 1.4 : clipId === "shove_two_hands" ? 0.15 : state.armed || holdRight || holdLeft ? 1.22 : running ? 0.85 : 0.12;
4601
+ const grip = blow === "punch" ? 1.4 : blow === "shove" ? 0.15 : state.armed || holdRight || holdLeft ? 1.22 : running ? 0.85 : 0.12;
4580
4602
  const wristSwing = holdRight || state.armed || running ? 0 : -Math.min(1, gait) * Math.sin(ph - 0.6) * 0.12 * hand.side;
4581
4603
  setHandGrip(hand, grip, wristSwing);
4582
4604
  });
@@ -5182,6 +5204,8 @@ function createFirstPersonArms(THREE, options = {}) {
5182
5204
 
5183
5205
  // src/player/room-avatar.ts
5184
5206
  var impactOf = (clip) => clip.events?.find((event) => event.type === "impact")?.t ?? null;
5207
+ var isPunch = (clip) => clip.events?.some((event) => event.type === "impact" && event.data?.kind === "punch") ?? false;
5208
+ var GUARD_SPEED = 0.3;
5185
5209
  var toRoomAvatar = (avatar, options = {}) => {
5186
5210
  const arms = options.firstPerson === false ? null : createFirstPersonArms(avatar.three, {
5187
5211
  colors: { skin: avatar.colors.skin, sleeve: avatar.colors.longSleeves ? avatar.colors.shirt : avatar.colors.skin, trouser: avatar.colors.trousers, shoe: avatar.colors.shoes, ...options.firstPerson?.colors },
@@ -5196,27 +5220,58 @@ var toRoomAvatar = (avatar, options = {}) => {
5196
5220
  if (!found) mirrored.set(clip.id, found = mirrorPoseClip(clip, `${clip.id}_left`));
5197
5221
  return found;
5198
5222
  };
5223
+ const guard = options.guardClip === false ? void 0 : strikes.get(options.guardClip ?? "fight_guard");
5224
+ const guardHold = options.guardHold ?? 1.2;
5225
+ const punchBlend = options.punchBlend ?? 0.05;
5226
+ let strikeLeft = 0;
5227
+ let guardLeft = 0;
5228
+ let guarding = false;
5229
+ const stepGuard = (dt, state) => {
5230
+ if (!guard) return;
5231
+ const free = state.speed < GUARD_SPEED && !state.down && !state.armed && !state.holding && !state.push && !state.itemUse && !state.running;
5232
+ if (strikeLeft > 0) {
5233
+ strikeLeft -= dt;
5234
+ if (strikeLeft <= 0 && guardLeft > 0 && free) {
5235
+ avatar.play(guard);
5236
+ guarding = true;
5237
+ }
5238
+ return;
5239
+ }
5240
+ guardLeft = Math.max(0, guardLeft - dt);
5241
+ if (guarding && (guardLeft <= 0 || !free || avatar.playing !== guard.id)) {
5242
+ if (avatar.playing === guard.id) avatar.stop();
5243
+ guarding = false;
5244
+ }
5245
+ };
5199
5246
  return {
5200
5247
  root: avatar.root,
5201
5248
  avatar,
5202
5249
  arms,
5203
5250
  ...arms ? { firstPerson: { root: arms.root, update: (dt, state) => arms.update(dt, state) } } : {},
5204
- update: (dt, state) => avatar.update(dt, {
5205
- speed: state.speed,
5206
- running: state.running,
5207
- crouch: state.crouch,
5208
- down: state.down,
5209
- armed: state.armed,
5210
- pitch: -state.pitch,
5211
- ...state.holding !== void 0 ? { holding: state.holding } : {},
5212
- ...state.itemUse !== void 0 ? { itemUse: state.itemUse } : {}
5213
- }),
5251
+ update: (dt, state) => {
5252
+ stepGuard(dt, state);
5253
+ avatar.update(dt, {
5254
+ speed: state.speed,
5255
+ running: state.running,
5256
+ crouch: state.crouch,
5257
+ down: state.down,
5258
+ armed: state.armed,
5259
+ pitch: -state.pitch,
5260
+ ...state.holding !== void 0 ? { holding: state.holding } : {},
5261
+ ...state.itemUse !== void 0 ? { itemUse: state.itemUse } : {},
5262
+ ...state.push !== void 0 ? { push: state.push } : {}
5263
+ });
5264
+ },
5214
5265
  hand: (side) => avatar.hand(side),
5215
5266
  strike: (clipId, strikeOptions) => {
5216
5267
  const clip = strikes.get(clipId);
5217
5268
  if (!clip) return null;
5218
5269
  const left = strikeOptions?.leg === "left" || strikeOptions?.hand === "left";
5219
- avatar.play(left ? leftOf(clip) : clip);
5270
+ const punch = guard !== void 0 && isPunch(clip);
5271
+ avatar.play(left ? leftOf(clip) : clip, punch ? { blend: punchBlend } : void 0);
5272
+ strikeLeft = punch ? clip.duration : 0;
5273
+ guardLeft = punch ? guardHold : 0;
5274
+ guarding = false;
5220
5275
  arms?.play(clipId, strikeOptions?.leg === "left" ? { leg: "left" } : strikeOptions?.hand === "left" ? { hand: "left" } : void 0);
5221
5276
  return impactOf(clip);
5222
5277
  }
@@ -5332,6 +5387,7 @@ function createAvatarTestModule(options) {
5332
5387
  return {
5333
5388
  id: AVATAR_AREA_ID,
5334
5389
  name: textOf().name,
5390
+ ground: { surface: "concrete_slab" },
5335
5391
  group: textOf().group,
5336
5392
  state,
5337
5393
  items: () => [],