Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 | 4x 71x 71x 4x 71x 71x 4x 4x 4x 4x 4x 4x 142x 142x 142x 142x 142x 71x 71x 71x 142x 142x 142x 142x 142x 142x 142x 142x 142x 142x 71x 142x 71x 71x 69x 142x 142x 142x 142x 142x 142x 142x 142x 71x 71x 71x 71x 142x 71x 71x 71x 142x 71x 71x 71x 142x 71x 142x 71x 71x 142x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 142x 142x 142x 142x | /**
* SkeletalPlayer3D component with articulated body model
*
* Implements full skeletal rigging system for realistic fighter animations
* with independent limb movement, elbow/knee joints, and attack animations.
*
* @module components/three/SkeletalPlayer3D
* @category 3D Components
* @korean 골격플레이어3D컴포넌트
*/
import { Html } from "@react-three/drei";
import { useFrame } from "@react-three/fiber";
import React, { useEffect, useMemo, useRef, useState } from "react";
import * as THREE from "three";
import {
applyKeyframeToRig,
createDefaultFacialDamage,
createHumanoidRig,
createInitialHandAnimationState,
getAnimation,
getExpressionFromCombatState,
getTechniqueHandPose,
updateAnimation,
updateHandAnimationState,
} from "../../systems/animation";
import { MuscleActivationManager } from "../../systems/animation/MuscleActivation";
import { FONT_FAMILY, KOREAN_COLORS } from "../../types/constants";
import { FacialExpression } from "../../types/facial";
import type { HandAnimationState } from "../../types/hand-animation";
import { HandPoseType } from "../../types/hand-animation";
import type { Player3DUnifiedProps } from "../../types/player-visual";
import type { SkeletalAnimationState, SkeletalRig } from "../../types/skeletal";
import { toHexColor } from "../../utils/colorHelpers";
import { getArchetypeColors } from "../../utils/colorUtils";
import BoneRenderer from "./BoneRenderer";
import MuscleSystem from "./MuscleSystem";
import PlayerStateIndicators from "./PlayerStateIndicators";
import StanceAura from "./StanceAura";
/**
* Get stance-specific color from Korean theming
*
* @param stance - Current trigram stance
* @returns Hex color number
* @korean 자세색상가져오기
*/
const getStanceColor = (stance: string): number => {
const stanceColors: Record<string, number> = {
geon: KOREAN_COLORS.TRIGRAM_GEON_PRIMARY,
tae: KOREAN_COLORS.TRIGRAM_TAE_PRIMARY,
li: KOREAN_COLORS.TRIGRAM_LI_PRIMARY,
jin: KOREAN_COLORS.TRIGRAM_JIN_PRIMARY,
son: KOREAN_COLORS.TRIGRAM_SON_PRIMARY,
gam: KOREAN_COLORS.TRIGRAM_GAM_PRIMARY,
gan: KOREAN_COLORS.TRIGRAM_GAN_PRIMARY,
gon: KOREAN_COLORS.TRIGRAM_GON_PRIMARY,
};
return stanceColors[stance] ?? KOREAN_COLORS.PRIMARY_CYAN;
};
/**
* Get trigram symbol for stance
*
* @param stance - Current trigram stance
* @returns Unicode trigram symbol
* @korean 팔괘기호가져오기
*/
const getTrigramSymbol = (stance: string): string => {
const symbols: Record<string, string> = {
geon: "☰",
tae: "☱",
li: "☲",
jin: "☳",
son: "☴",
gam: "☵",
gan: "☶",
gon: "☷",
};
return symbols[stance] ?? "☰";
};
/**
* Default transition duration for hand pose changes (in seconds)
* @korean 손자세전환기본지속시간
*/
const DEFAULT_HAND_TRANSITION_DURATION = 0.2;
/**
* Frequency of React state syncs during hand animations.
* Value of 20 means sync every 5% progress (~every 3 frames at 60fps).
* This reduces React re-renders from 60/sec to ~20/sec during transitions.
* @korean 손상태동기화빈도
*/
const HAND_STATE_SYNC_FREQUENCY = 20;
/**
* Animation constants for balance state sway effects.
* Defines intensity, speed, and lean parameters for visual feedback.
* @korean 균형상태애니메이션상수
*/
const BALANCE_STATE_ANIMATION_CONSTANTS = {
SHAKEN: {
swayIntensity: 0.02, // 2% subtle sway
swaySpeed: 2, // Hz frequency
},
VULNERABLE: {
swayIntensity: 0.04, // 4% moderate sway
swaySpeed: 3, // Hz frequency
},
HELPLESS: {
stumbleIntensity: 0.08, // 8% pronounced stumble
stumbleSpeed: 1.5, // Hz frequency (slower, more dramatic)
leanIntensity: 0.15, // 15° forward lean angle
lowerStance: -0.15, // Lower Y position for stumbling effect
},
SWAY_THRESHOLD: 0.001, // Minimum sway to consider significant
} as const;
/**
* Updates hand animation state for a single hand at 60fps.
* Uses refs to avoid triggering React re-renders on every frame.
* Only syncs to React state periodically or when transition completes.
*
* @param handStateRef - Ref storing current hand animation state
* @param setHandState - React setState function to update hand state
* @param delta - Time elapsed since last frame (in seconds)
* @korean 손애니메이션프레임업데이트
*/
const updateHandAnimationFrame = (
handStateRef: React.MutableRefObject<HandAnimationState>,
setHandState: React.Dispatch<React.SetStateAction<HandAnimationState>>,
delta: number
): void => {
if (handStateRef.current && handStateRef.current.targetPose !== null) {
const previousState = handStateRef.current;
const updatedState = updateHandAnimationState(
previousState,
previousState.targetPose,
delta,
DEFAULT_HAND_TRANSITION_DURATION
);
handStateRef.current = updatedState;
// Sync to React state periodically (approximately every 3 frames at 60fps)
// to balance animation smoothness with React render performance.
if (
updatedState.targetPose === null ||
Math.floor(
updatedState.transitionProgress * HAND_STATE_SYNC_FREQUENCY
) !==
Math.floor(previousState.transitionProgress * HAND_STATE_SYNC_FREQUENCY)
) {
setHandState(updatedState);
}
}
};
/**
* Checks if there is significant sway that requires animation updates.
*
* @param swayPosition - Current sway position [x, y, z]
* @param helplessRotation - Current helpless rotation angle
* @returns True if sway is above threshold
* @korean 의미있는흔들림확인
*/
const hasSignificantSway = (
swayPosition: [number, number, number],
helplessRotation: number
): boolean => {
return (
Math.abs(swayPosition[0]) > BALANCE_STATE_ANIMATION_CONSTANTS.SWAY_THRESHOLD ||
Math.abs(swayPosition[1]) > BALANCE_STATE_ANIMATION_CONSTANTS.SWAY_THRESHOLD ||
Math.abs(helplessRotation) > BALANCE_STATE_ANIMATION_CONSTANTS.SWAY_THRESHOLD
);
};
/**
* SkeletalPlayer3D Component
*
* Complete skeletal player with 28-bone rig and realistic animations.
* Supports all Korean martial arts attack animations (jab, cross, kicks, block).
*
* @example
* ```tsx
* <SkeletalPlayer3D
* playerId="player1"
* archetype={PlayerArchetype.MUSA}
* stance={TrigramStance.GEON}
* position={[0, 0, 0]}
* rotation={0}
* health={85}
* maxHealth={100}
* stamina={60}
* ki={40}
* currentAnimation="attack"
* attackAnimation="jab"
* showDetails={true}
* />
* ```
*
* @korean 골격플레이어3D컴포넌트
*/
export const SkeletalPlayer3D: React.FC<
Player3DUnifiedProps & {
readonly attackAnimation?: string;
readonly showSkeleton?: boolean;
}
> = ({
playerId,
archetype,
stance,
position,
rotation,
health,
maxHealth,
stamina,
ki,
pain,
balance,
consciousness,
bloodLoss,
isBlocking,
isStunned = false,
isCountering = false,
currentAnimation,
isMobile,
name,
scale = 1,
showDetails = true,
facing = "right",
showStanceIndicator = true,
onAnimationComplete,
attackAnimation,
showSkeleton = false,
facialExpression,
facialDamage,
enableFacialExpressions = false,
enableEyeTracking = true,
opponentPosition,
}) => {
// Create skeletal rig
const rig = useMemo<SkeletalRig>(() => createHumanoidRig(), []);
// Muscle activation manager
const muscleManager = useRef(new MuscleActivationManager());
const [muscleStates, setMuscleStates] = useState<Map<string, number>>(
new Map()
);
const frameCounter = useRef(0);
// Cleanup muscle manager on unmount
useEffect(() => {
return () => {
try {
muscleManager.current.reset();
} catch (error) {
console.warn("MuscleActivationManager reset failed:", error);
}
};
}, []);
// Animation state
const [animState, setAnimState] = useState<SkeletalAnimationState>({
currentAnimation: null,
currentTime: 0,
isPlaying: false,
playbackSpeed: 1.0,
previousKeyframeIndex: 0,
nextKeyframeIndex: 1,
});
// Hand animation state for both hands
const [leftHandState, setLeftHandState] = useState<HandAnimationState>(
createInitialHandAnimationState(HandPoseType.OPEN)
);
const [rightHandState, setRightHandState] = useState<HandAnimationState>(
createInitialHandAnimationState(HandPoseType.OPEN)
);
// Refs for 60fps animation updates without triggering React re-renders
const leftHandStateRef = useRef<HandAnimationState>(leftHandState);
const rightHandStateRef = useRef<HandAnimationState>(rightHandState);
// Sync refs with state
useEffect(() => {
leftHandStateRef.current = leftHandState;
}, [leftHandState]);
useEffect(() => {
rightHandStateRef.current = rightHandState;
}, [rightHandState]);
// Get archetype colors
const archetypeColors = useMemo(
() => getArchetypeColors(archetype),
[archetype]
);
// Body color based on state
const bodyColor = useMemo(() => {
Iif (isStunned) return KOREAN_COLORS.WARNING_YELLOW;
if (health / maxHealth < 0.3) return KOREAN_COLORS.ACCENT_RED;
Eif (ki / 100 > 0.8) return KOREAN_COLORS.PRIMARY_CYAN;
return archetypeColors.primary;
}, [isStunned, health, maxHealth, ki, archetypeColors.primary]);
// Stance color
const stanceColor = useMemo(() => getStanceColor(stance), [stance]);
const trigramSymbol = useMemo(() => getTrigramSymbol(stance), [stance]);
// Animation time ref - use ref to avoid state updates during render
const animTimeRef = useRef(0);
// Ref for character sway based on balance state
const swayTimeRef = useRef(0);
// Track recent combat events for expression calculation
const [justHit, setJustHit] = useState(false);
const [justLanded, setJustLanded] = useState(false);
const lastHealthRef = useRef(health);
// Detect hit events (health decreased)
useEffect(() => {
let timeoutId: ReturnType<typeof setTimeout> | undefined;
Iif (health < lastHealthRef.current) {
setJustHit(true);
timeoutId = setTimeout(() => setJustHit(false), 1000); // Clear after 1 second
}
lastHealthRef.current = health;
return () => {
Iif (timeoutId !== undefined) {
clearTimeout(timeoutId);
}
};
}, [health]);
// Detect successful attacks (currentAnimation changed to attack)
useEffect(() => {
let timeoutId: ReturnType<typeof setTimeout> | undefined;
Iif (currentAnimation === "attack") {
setJustLanded(true);
timeoutId = setTimeout(() => setJustLanded(false), 500); // Clear after 0.5 seconds
}
return () => {
Iif (timeoutId !== undefined) {
clearTimeout(timeoutId);
}
};
}, [currentAnimation]);
// Calculate facial expression from combat state (or use provided one)
const calculatedExpression = useMemo(() => {
Iif (!enableFacialExpressions) {
return FacialExpression.NEUTRAL;
}
Iif (facialExpression) {
return facialExpression;
}
return getExpressionFromCombatState(
health,
maxHealth,
stamina,
pain,
consciousness,
justHit,
justLanded
);
}, [
enableFacialExpressions,
facialExpression,
health,
maxHealth,
stamina,
pain,
consciousness,
justHit,
justLanded,
]);
// Facial damage state
const calculatedFacialDamage = useMemo(() => {
return facialDamage ?? createDefaultFacialDamage();
}, [facialDamage]);
// Opponent position for eye tracking
const opponentPos = useMemo(() => {
Eif (opponentPosition) {
return new THREE.Vector3(...opponentPosition);
}
// Default: opponent in front
return new THREE.Vector3(facing === "right" ? 5 : -5, 2, 0);
}, [opponentPosition, facing]);
// Load attack/defend/idle/walk animation when currentAnimation or blocking state changes
useEffect(() => {
// Reset animation time ref whenever animation changes
animTimeRef.current = 0;
Iif (currentAnimation === "attack" && attackAnimation) {
const anim = getAnimation(attackAnimation);
if (anim) {
// Update animation state based on prop changes - this is intentional and safe
setAnimState({
currentAnimation: anim,
currentTime: 0,
isPlaying: true,
playbackSpeed: 1.0,
previousKeyframeIndex: 0,
nextKeyframeIndex: 1,
});
// Update hand poses based on attack technique
const handPose = getTechniqueHandPose(attackAnimation);
setLeftHandState((prev) =>
updateHandAnimationState(
prev,
handPose.leftHandPose,
0,
handPose.transitionDuration
)
);
setRightHandState((prev) =>
updateHandAnimationState(
prev,
handPose.rightHandPose,
0,
handPose.transitionDuration
)
);
}
I} else if (currentAnimation === "defend" || isBlocking) {
const blockAnim = getAnimation("block");
if (blockAnim) {
setAnimState({
currentAnimation: blockAnim,
currentTime: 0,
isPlaying: true,
playbackSpeed: 1.0,
previousKeyframeIndex: 0,
nextKeyframeIndex: 1,
});
// Open hands for blocking
setLeftHandState((prev) =>
updateHandAnimationState(prev, HandPoseType.OPEN, 0, 0.1)
);
setRightHandState((prev) =>
updateHandAnimationState(prev, HandPoseType.OPEN, 0, 0.1)
);
}
I} else if (currentAnimation === "walk") {
// Walking animation - 걷기 애니메이션
const walkAnim = getAnimation("walk");
if (walkAnim) {
setAnimState({
currentAnimation: walkAnim,
currentTime: 0,
isPlaying: true,
playbackSpeed: 1.0, // Normal walking speed
previousKeyframeIndex: 0,
nextKeyframeIndex: 1,
});
// Relaxed hands while walking
setLeftHandState((prev) =>
updateHandAnimationState(prev, HandPoseType.RELAXED, 0, 0.2)
);
setRightHandState((prev) =>
updateHandAnimationState(prev, HandPoseType.RELAXED, 0, 0.2)
);
}
I} else if (currentAnimation === "stance_change") {
// Stance change animation - 자세 변경 애니메이션
const idleAnim = getAnimation("idle_stance");
if (idleAnim) {
setAnimState({
currentAnimation: idleAnim,
currentTime: 0,
isPlaying: true,
playbackSpeed: 1.2, // Slightly faster for responsiveness
previousKeyframeIndex: 0,
nextKeyframeIndex: 1,
});
// Guard hands during stance change
setLeftHandState((prev) =>
updateHandAnimationState(prev, HandPoseType.OPEN, 0, 0.15)
);
setRightHandState((prev) =>
updateHandAnimationState(prev, HandPoseType.OPEN, 0, 0.15)
);
}
I} else if (currentAnimation === "hit") {
// Hit reaction - keep current pose but stop animation
setAnimState((prev) => ({
...prev,
isPlaying: false,
currentTime: 0,
}));
} else {
// Idle animation - 대기 애니메이션
const idleAnim = getAnimation("idle_stance");
if (idleAnim) {
setAnimState({
currentAnimation: idleAnim,
currentTime: 0,
isPlaying: true,
playbackSpeed: 0.5, // Slow breathing animation
previousKeyframeIndex: 0,
nextKeyframeIndex: 1,
});
} else E{
// Fallback: stop animation if idle_stance not found
setAnimState((prev) => ({
...prev,
isPlaying: false,
currentTime: 0,
}));
}
// Return to relaxed hand pose when idle
setLeftHandState((prev) =>
updateHandAnimationState(prev, HandPoseType.RELAXED, 0, 0.3)
);
setRightHandState((prev) =>
updateHandAnimationState(prev, HandPoseType.RELAXED, 0, 0.3)
);
}
}, [currentAnimation, attackAnimation, isBlocking]);
// Calculate sway position based on balance state
const [swayPosition, setSwayPosition] = useState<[number, number, number]>([0, 0, 0]);
const [helplessRotation, setHelplessRotation] = useState<number>(0);
// Animation loop using useFrame (60fps)
useFrame((_state, delta) => {
// Calculate sway/stumble based on balance state
if (balance === "HELPLESS") {
// Helpless state: pronounced stumbling motion
swayTimeRef.current += delta;
const { stumbleIntensity, stumbleSpeed, leanIntensity, lowerStance } =
BALANCE_STATE_ANIMATION_CONSTANTS.HELPLESS;
const swayX = Math.sin(swayTimeRef.current * stumbleSpeed) * stumbleIntensity;
const swayY = Math.cos(swayTimeRef.current * stumbleSpeed * 0.5) * stumbleIntensity * 0.3 + lowerStance;
const leanAngle = Math.sin(swayTimeRef.current * stumbleSpeed * 0.7) * leanIntensity;
// Update periodically to reduce React re-renders while keeping helpless animation dramatic
if (frameCounter.current % 2 === 0) {
setSwayPosition([swayX, swayY, 0]);
setHelplessRotation(leanAngle);
}
} else if (balance === "SHAKEN" || balance === "VULNERABLE") {
// Shaken/Vulnerable state: subtle sway
swayTimeRef.current += delta;
const animConfig = balance === "SHAKEN"
? BALANCE_STATE_ANIMATION_CONSTANTS.SHAKEN
: BALANCE_STATE_ANIMATION_CONSTANTS.VULNERABLE;
const swayX = Math.sin(swayTimeRef.current * animConfig.swaySpeed) * animConfig.swayIntensity;
const swayY = Math.cos(swayTimeRef.current * animConfig.swaySpeed * 0.8) * animConfig.swayIntensity * 0.5;
// Update sway position periodically to reduce re-renders
if (frameCounter.current % 2 === 0) {
setSwayPosition([swayX, swayY, 0]);
setHelplessRotation(0);
}
} else {
// Smoothly return to neutral position
if (frameCounter.current % 2 === 0 && hasSignificantSway(swayPosition, helplessRotation)) {
setSwayPosition([swayPosition[0] * 0.95, swayPosition[1] * 0.95, 0]);
setHelplessRotation(helplessRotation * 0.95);
}
// Reset sway time when not swaying
if (!hasSignificantSway(swayPosition, helplessRotation)) {
swayTimeRef.current = 0;
}
}
// Update hand animation state at 60fps using refs to reduce React re-render frequency
updateHandAnimationFrame(leftHandStateRef, setLeftHandState, delta);
updateHandAnimationFrame(rightHandStateRef, setRightHandState, delta);
// Update muscle system at 60fps
if (currentAnimation === "attack" && attackAnimation) {
muscleManager.current.update(attackAnimation, stamina, delta);
} else if (currentAnimation === "defend" || isBlocking) {
muscleManager.current.update("block", stamina, delta);
} else if (
currentAnimation === "walk" ||
currentAnimation === "stance_change"
) {
// Engage stance/leg/core muscles during movement and stance changes
muscleManager.current.update("stance_change", stamina, delta);
} else {
muscleManager.current.relaxAllMuscles(delta);
}
// Sync muscle states to React state deterministically (every 10 frames at 60fps = ~6 times/sec)
// to balance animation smoothness with performance and reduce GC pressure
frameCounter.current = (frameCounter.current + 1) % 10;
if (frameCounter.current === 0) {
// Reuse scratch map from manager to avoid repeated allocations
const scratchMap = muscleManager.current.getScratchMapForSync();
setMuscleStates(scratchMap);
}
// Update skeletal animation
if (!animState.isPlaying || !animState.currentAnimation) {
return;
}
// Update animation time and get interpolated keyframe
const result = updateAnimation(
animState.currentAnimation,
animTimeRef.current,
delta,
animState.playbackSpeed
);
// Apply keyframe to rig
applyKeyframeToRig(rig, result.keyframe);
// Update time ref
animTimeRef.current = result.time;
// Handle animation completion - only update state when animation completes
if (result.completed) {
animTimeRef.current = 0;
setAnimState((prev) => ({
...prev,
isPlaying: false,
currentTime: 0,
}));
// Trigger callback
if (onAnimationComplete) {
onAnimationComplete();
}
}
});
return (
<group
position={position}
rotation={[0, rotation, 0]}
scale={[facing === "left" ? -scale : scale, scale, scale]}
data-testid={`skeletal-player3d-${playerId}`}
>
{/* Inner group for sway animation and helpless lean */}
<group position={swayPosition} rotation={[helplessRotation, 0, 0]}>
{/* Stance aura effect */}
<StanceAura stance={stance} intensity={ki / 100} animated />
{/* Muscle system rendering */}
<MuscleSystem muscleStates={muscleStates} isExhausted={stamina < 20} />
{/* Skeletal rig rendering */}
<BoneRenderer
rig={rig}
color={bodyColor}
showBones={true}
renderMode={showSkeleton ? "debug" : "solid"}
leftHandState={leftHandState}
rightHandState={rightHandState}
cameraDistance={10}
facialExpression={calculatedExpression}
facialDamage={calculatedFacialDamage}
opponentPosition={opponentPos}
enableFacialExpressions={enableFacialExpressions}
enableEyeTracking={enableEyeTracking}
/>
{/* Blocking shield effect */}
{isBlocking && (
<mesh position={[0, 1.2, 0.3]}>
<circleGeometry args={[0.5, 32]} />
<meshBasicMaterial
color={KOREAN_COLORS.PRIMARY_BLUE}
transparent
opacity={0.5}
side={2}
/>
</mesh>
)}
{/* Counter indicator */}
{isCountering && (
<mesh position={[0, 1.5, 0]}>
<torusGeometry args={[0.4, 0.05, 8, 32]} />
<meshBasicMaterial color={KOREAN_COLORS.ACCENT_PURPLE} />
</mesh>
)}
{/* Player name overlay */}
{showDetails && name && (
<Html
position={[0, 2.8, 0]}
center
distanceFactor={isMobile ? 15 : 10}
occlude={false}
style={{ pointerEvents: "none", userSelect: "none" }}
>
<div
style={{
fontFamily: FONT_FAMILY.KOREAN,
textAlign: "center",
color: "white",
textShadow: "0 0 4px rgba(0,0,0,0.8)",
}}
>
{/* Player name */}
<div
style={{
fontSize: isMobile ? "12px" : "14px",
fontWeight: "bold",
marginBottom: "4px",
}}
data-testid="player-name"
>
{name.korean}
</div>
{/* Trigram symbol */}
{showStanceIndicator && (
<div
style={{
fontSize: isMobile ? "14px" : "16px",
color: toHexColor(stanceColor),
}}
data-testid="trigram-symbol"
>
{trigramSymbol}
</div>
)}
{/* Combat state text */}
{(isBlocking || isStunned || isCountering) && (
<div
style={{
fontSize: isMobile ? "10px" : "12px",
fontWeight: "bold",
color: "#ffff00",
marginTop: "4px",
}}
data-testid="combat-state"
>
{isBlocking ? "방어" : isStunned ? "기절" : "반격"}
</div>
)}
</div>
</Html>
)}
{/* State indicators (health, stamina, Ki, balance) */}
{showDetails && (
<PlayerStateIndicators
health={health}
maxHealth={maxHealth}
stamina={stamina}
ki={ki}
balance={balance}
consciousness={consciousness}
pain={pain}
bloodLoss={bloodLoss}
isMobile={isMobile}
/>
)}
</group> {/* Close inner sway group */}
</group>
);
};
export default SkeletalPlayer3D;
|