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 790 791 792 793 794 795 796 | 12x 12x 7409x 7409x 7409x 7409x 12x 7399x 7399x 7399x 7399x 12x 7400x 7400x 7400x 7400x 7400x 12x 7656x 7656x 7656x 7656x 3132x 3132x 9396x 3132x 7656x 3132x 7656x 3132x 3132x 3132x 7656x 7656x 22968x 12x 7392x 7392x 7392x 7392x 7392x 7392x 7392x 7392x 7392x 7392x 7392x 3168x 4224x 7656x 7656x 7656x | /* eslint-disable react-refresh/only-export-components */
/**
* Bone-attached muscle system for realistic muscle movement with skeleton
*
* Muscles are rendered as children of their parent bones, inheriting bone
* transformations automatically for proper movement during animation.
*
* @module components/three/BoneAttachedMuscles
* @category 3D Components
* @korean 뼈부착근육시스템
*/
import { useFrame } from "@react-three/fiber";
import React, { useMemo, useRef } from "react";
import * as THREE from "three";
import {
ABS_LENGTH,
ABS_RADIUS,
BICEP_LENGTH,
BICEP_RADIUS,
CALF_LENGTH,
CALF_RADIUS,
CORE_LENGTH,
CORE_RADIUS,
ERECTOR_SPINAE_LENGTH,
ERECTOR_SPINAE_RADIUS,
FOREARM_LENGTH,
FOREARM_RADIUS,
GLUTE_LENGTH,
GLUTE_RADIUS,
HAMSTRING_LENGTH,
HAMSTRING_RADIUS,
HIP_FLEXOR_LENGTH,
HIP_FLEXOR_RADIUS,
LAT_LENGTH,
LAT_RADIUS,
OBLIQUES_LENGTH,
OBLIQUES_RADIUS,
PECTORALS_LENGTH,
PECTORALS_RADIUS,
QUAD_LENGTH,
QUAD_RADIUS,
SHOULDER_LENGTH,
SHOULDER_RADIUS,
TRAPEZIUS_LENGTH,
TRAPEZIUS_RADIUS,
TRICEP_LENGTH,
TRICEP_RADIUS,
} from "../../../../constants/bodyDimensions";
import { KOREAN_COLORS } from "../../../../types/constants";
import type { MuscleGroupName } from "../../../../types/muscle";
import { DEFAULT_MUSCLE_CONFIG } from "../../../../types/muscle";
/**
* Muscle attachment configuration
*
* Defines how a muscle is positioned relative to its parent bone.
* Position is in local bone space, so muscles move with the bone.
*
* @korean 근육부착설정
*/
export interface MuscleAttachment {
/** Muscle group name */
readonly name: MuscleGroupName;
/** Korean name for UI */
readonly korean: string;
/** English name for UI */
readonly english: string;
/** Local position offset from bone origin */
readonly localOffset: THREE.Vector3;
/** Local rotation relative to bone */
readonly localRotation: THREE.Euler;
/** Base scale when relaxed */
readonly baseScale: THREE.Vector3;
/** Max scale when fully flexed */
readonly maxFlexScale: THREE.Vector3;
/** Capsule geometry radius */
readonly radius: number;
/** Capsule geometry length */
readonly length: number;
}
/**
* Mapping of bone names to their attached muscles
*
* Each bone can have multiple muscles attached to it.
* Positions are relative to the bone's local coordinate system.
*
* @korean 뼈근육매핑
*/
export const BONE_MUSCLE_MAP: Record<string, MuscleAttachment[]> = {
// Shoulders - deltoid muscles
shoulder_L: [
{
name: "SHOULDER_L",
korean: "왼쪽어깨",
english: "Left Shoulder",
localOffset: new THREE.Vector3(-0.04, 0, 0),
localRotation: new THREE.Euler(0, 0, Math.PI / 2),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.2, 1.15, 1.15),
radius: SHOULDER_RADIUS,
length: SHOULDER_LENGTH,
},
],
shoulder_R: [
{
name: "SHOULDER_R",
korean: "오른쪽어깨",
english: "Right Shoulder",
localOffset: new THREE.Vector3(0.04, 0, 0),
localRotation: new THREE.Euler(0, 0, -Math.PI / 2),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.2, 1.15, 1.15),
radius: SHOULDER_RADIUS,
length: SHOULDER_LENGTH,
},
],
// Upper arms - biceps and triceps
upper_arm_L: [
{
name: "BICEP_L",
korean: "왼쪽이두근",
english: "Left Bicep",
localOffset: new THREE.Vector3(-0.06, 0, 0.03),
localRotation: new THREE.Euler(0, 0, Math.PI / 2),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.2, 1.1, 1.2),
radius: BICEP_RADIUS,
length: BICEP_LENGTH,
},
{
name: "TRICEP_L",
korean: "왼쪽삼두근",
english: "Left Tricep",
localOffset: new THREE.Vector3(-0.06, 0, -0.03),
localRotation: new THREE.Euler(0, 0, Math.PI / 2),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.15, 1.1, 1.15),
radius: TRICEP_RADIUS,
length: TRICEP_LENGTH,
},
],
upper_arm_R: [
{
name: "BICEP_R",
korean: "오른쪽이두근",
english: "Right Bicep",
localOffset: new THREE.Vector3(0.06, 0, 0.03),
localRotation: new THREE.Euler(0, 0, -Math.PI / 2),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.2, 1.1, 1.2),
radius: BICEP_RADIUS,
length: BICEP_LENGTH,
},
{
name: "TRICEP_R",
korean: "오른쪽삼두근",
english: "Right Tricep",
localOffset: new THREE.Vector3(0.06, 0, -0.03),
localRotation: new THREE.Euler(0, 0, -Math.PI / 2),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.15, 1.1, 1.15),
radius: TRICEP_RADIUS,
length: TRICEP_LENGTH,
},
],
// Forearms
forearm_L: [
{
name: "FOREARM_L",
korean: "왼쪽전완근",
english: "Left Forearm",
localOffset: new THREE.Vector3(-0.05, 0, 0),
localRotation: new THREE.Euler(0, 0, Math.PI / 2),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.1, 1.05, 1.1),
radius: FOREARM_RADIUS,
length: FOREARM_LENGTH,
},
],
forearm_R: [
{
name: "FOREARM_R",
korean: "오른쪽전완근",
english: "Right Forearm",
localOffset: new THREE.Vector3(0.05, 0, 0),
localRotation: new THREE.Euler(0, 0, -Math.PI / 2),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.1, 1.05, 1.1),
radius: FOREARM_RADIUS,
length: FOREARM_LENGTH,
},
],
// Spine - chest/core muscles attach to spine_middle
spine_middle: [
{
name: "PECTORALS",
korean: "대흉근",
english: "Pectorals",
localOffset: new THREE.Vector3(0, 0.08, 0.14),
localRotation: new THREE.Euler(Math.PI / 2, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.15, 1.2, 1.15),
radius: PECTORALS_RADIUS,
length: PECTORALS_LENGTH,
},
{
name: "CORE",
korean: "코어",
english: "Core",
localOffset: new THREE.Vector3(0, -0.04, 0.06),
localRotation: new THREE.Euler(0, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.1, 1.1, 1.1),
radius: CORE_RADIUS,
length: CORE_LENGTH,
},
{
name: "ABS",
korean: "복근",
english: "Abdominals",
localOffset: new THREE.Vector3(0, -0.18, 0.12),
localRotation: new THREE.Euler(0, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.1, 1.1, 1.1),
radius: ABS_RADIUS,
length: ABS_LENGTH,
},
{
name: "OBLIQUES",
korean: "복사근",
english: "Obliques",
localOffset: new THREE.Vector3(0, -0.1, 0.16),
localRotation: new THREE.Euler(0, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.1, 1.1, 1.1),
radius: OBLIQUES_RADIUS,
length: OBLIQUES_LENGTH,
},
],
// Pelvis - central hip/waist muscles
pelvis: [
{
name: "HIP_FLEXOR_L",
korean: "왼쪽고관절굴근",
english: "Left Hip Flexor",
localOffset: new THREE.Vector3(-0.05, 0.02, 0.03),
localRotation: new THREE.Euler(0.2, 0, 0.15),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.1, 1.1, 1.1),
radius: HIP_FLEXOR_RADIUS,
length: HIP_FLEXOR_LENGTH,
},
{
name: "HIP_FLEXOR_R",
korean: "오른쪽고관절굴근",
english: "Right Hip Flexor",
localOffset: new THREE.Vector3(0.05, 0.02, 0.03),
localRotation: new THREE.Euler(0.2, 0, -0.15),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.1, 1.1, 1.1),
radius: HIP_FLEXOR_RADIUS,
length: HIP_FLEXOR_LENGTH,
},
{
name: "LOWER_ABS",
korean: "하복근",
english: "Lower Abdominals",
localOffset: new THREE.Vector3(0, 0.01, 0.05),
localRotation: new THREE.Euler(0, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.1, 1.1, 1.1),
radius: 0.05, // Lower abs - slightly larger than hip flexor
length: 0.14,
},
],
// Spine lower - lower back muscles for torso definition
spine_lower: [
{
name: "ERECTOR_SPINAE_L",
korean: "왼쪽척추기립근",
english: "Left Erector Spinae",
localOffset: new THREE.Vector3(-0.03, 0.03, -0.04),
localRotation: new THREE.Euler(0, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.1, 1.1, 1.1),
radius: ERECTOR_SPINAE_RADIUS,
length: ERECTOR_SPINAE_LENGTH,
},
{
name: "ERECTOR_SPINAE_R",
korean: "오른쪽척추기립근",
english: "Right Erector Spinae",
localOffset: new THREE.Vector3(0.03, 0.03, -0.04),
localRotation: new THREE.Euler(0, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.1, 1.1, 1.1),
radius: ERECTOR_SPINAE_RADIUS,
length: ERECTOR_SPINAE_LENGTH,
},
],
// Spine upper - lats and traps for V-shaped back
spine_upper: [
{
name: "LAT_L",
korean: "왼쪽광배근",
english: "Left Latissimus",
localOffset: new THREE.Vector3(-0.07, -0.01, -0.03),
localRotation: new THREE.Euler(0, 0.2, 0.3),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.15, 1.2, 1.1),
radius: LAT_RADIUS,
length: LAT_LENGTH,
},
{
name: "LAT_R",
korean: "오른쪽광배근",
english: "Right Latissimus",
localOffset: new THREE.Vector3(0.07, -0.01, -0.03),
localRotation: new THREE.Euler(0, -0.2, -0.3),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.15, 1.2, 1.1),
radius: LAT_RADIUS,
length: LAT_LENGTH,
},
{
name: "TRAPEZIUS",
korean: "승모근",
english: "Trapezius",
localOffset: new THREE.Vector3(0, 0.05, -0.04),
localRotation: new THREE.Euler(-0.25, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.15, 1.15, 1.1),
radius: TRAPEZIUS_RADIUS,
length: TRAPEZIUS_LENGTH,
},
{
name: "RHOMBOID",
korean: "능형근",
english: "Rhomboid",
localOffset: new THREE.Vector3(0, 0.01, -0.05),
localRotation: new THREE.Euler(0, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.15, 1.1, 1.1),
radius: 0.04, // Rhomboid - slightly smaller than trapezius
length: 0.14,
},
],
// Hips - glutes attach here
hip_L: [
{
name: "GLUTE_L",
korean: "왼쪽둔근",
english: "Left Glute",
localOffset: new THREE.Vector3(-0.03, -0.02, -0.05),
localRotation: new THREE.Euler(Math.PI / 2, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.15, 1.15, 1.15),
radius: GLUTE_RADIUS,
length: GLUTE_LENGTH,
},
],
hip_R: [
{
name: "GLUTE_R",
korean: "오른쪽둔근",
english: "Right Glute",
localOffset: new THREE.Vector3(0.03, -0.02, -0.05),
localRotation: new THREE.Euler(Math.PI / 2, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.15, 1.15, 1.15),
radius: GLUTE_RADIUS,
length: GLUTE_LENGTH,
},
],
// Thighs - quads and hamstrings
thigh_L: [
{
name: "QUAD_L",
korean: "왼쪽대퇴사두근",
english: "Left Quadriceps",
localOffset: new THREE.Vector3(0, -0.08, 0.03),
localRotation: new THREE.Euler(0, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.15, 1.1, 1.15),
radius: QUAD_RADIUS,
length: QUAD_LENGTH,
},
{
name: "HAMSTRING_L",
korean: "왼쪽햄스트링",
english: "Left Hamstring",
localOffset: new THREE.Vector3(0, -0.08, -0.03),
localRotation: new THREE.Euler(0, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.12, 1.1, 1.12),
radius: HAMSTRING_RADIUS,
length: HAMSTRING_LENGTH,
},
],
thigh_R: [
{
name: "QUAD_R",
korean: "오른쪽대퇴사두근",
english: "Right Quadriceps",
localOffset: new THREE.Vector3(0, -0.08, 0.03),
localRotation: new THREE.Euler(0, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.15, 1.1, 1.15),
radius: QUAD_RADIUS,
length: QUAD_LENGTH,
},
{
name: "HAMSTRING_R",
korean: "오른쪽햄스트링",
english: "Right Hamstring",
localOffset: new THREE.Vector3(0, -0.08, -0.03),
localRotation: new THREE.Euler(0, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.12, 1.1, 1.12),
radius: HAMSTRING_RADIUS,
length: HAMSTRING_LENGTH,
},
],
// Shins - calves
shin_L: [
{
name: "CALF_L",
korean: "왼쪽종아리",
english: "Left Calf",
localOffset: new THREE.Vector3(0, -0.04, -0.01),
localRotation: new THREE.Euler(0, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.1, 1.08, 1.1),
radius: CALF_RADIUS,
length: CALF_LENGTH,
},
],
shin_R: [
{
name: "CALF_R",
korean: "오른쪽종아리",
english: "Right Calf",
localOffset: new THREE.Vector3(0, -0.04, -0.01),
localRotation: new THREE.Euler(0, 0, 0),
baseScale: new THREE.Vector3(1.0, 1.0, 1.0),
maxFlexScale: new THREE.Vector3(1.1, 1.08, 1.1),
radius: CALF_RADIUS,
length: CALF_LENGTH,
},
],
};
// Import centralized constants
import {
MIN_MUSCLE_SCALE,
MUSCLE_AMPLIFICATION_BASE,
MUSCLE_AMPLIFICATION_EXPONENT,
MUSCLE_GEOMETRY_NORMALIZATION,
REFERENCE_MUSCLE_MASS,
} from "../../../../constants/bodyRenderingConstants";
/**
* Calculate muscle scale factor based on muscle mass with proportional scaling.
*
* Linear scaling for realistic visual differences:
* - 28kg (Hacker) → 0.84 scale (lean, defined)
* - 30kg (Amsalja) → 0.89 scale (lean athlete)
* - 32kg (Jeongbo) → 0.93 scale (fit operative)
* - 35kg (Musa) → 1.0 scale (reference baseline)
* - 48kg (Jojik) → 1.30 scale (massive, powerful)
*
* @param muscleMass - Muscle mass in kilograms (archetype range: 28-48kg)
* @returns Scale factor for muscle geometry
*
* @korean 근육크기계산
*/
export const calculateMuscleScaleFactor = (muscleMass: number): number => {
const massRatio = muscleMass / REFERENCE_MUSCLE_MASS;
const deviation = massRatio - 1.0;
// Exponential curve for dramatic differences
const exponentialDeviation =
Math.sign(deviation) *
Math.pow(Math.abs(deviation), MUSCLE_AMPLIFICATION_EXPONENT);
return Math.max(
MIN_MUSCLE_SCALE,
1.0 + exponentialDeviation * MUSCLE_AMPLIFICATION_BASE,
);
};
/**
* Calculate fat layer opacity with expanded range for better distinction.
*
* Previous: 0.1-0.7 opacity (insufficient contrast)
* New: 0.05-0.85 opacity (dramatic difference)
*
* @param fatMass - Fat mass in kilograms (archetype range: 10-22kg)
* @returns Opacity value for fat layer (0.05-0.85)
*
* @korean 지방층투명도계산
*/
export const calculateFatLayerOpacity = (fatMass: number): number => {
const minFat = 10; // Amsalja minimum
const maxFat = 22; // Jojik maximum
const normalizedFat = (fatMass - minFat) / (maxFat - minFat);
// Expanded range: 0.05 (lean) to 0.85 (heavy)
return Math.max(0.05, Math.min(0.85, 0.05 + normalizedFat * 0.8));
};
/**
* Calculate fat layer thickness with non-linear scaling.
*
* Previous: 0.05-0.45 linear
* New: 0.02-0.60 exponential (skinny = very thin, heavy = very thick)
*
* @param fatMass - Fat mass in kilograms (archetype range: 10-22kg)
* @returns Scale increase for fat layer (0.02-0.60)
*
* @korean 지방층두께계산
*/
export const calculateFatLayerThickness = (fatMass: number): number => {
const minFat = 10;
const maxFat = 22;
const normalizedFat = (fatMass - minFat) / (maxFat - minFat);
// Exponential curve for fat thickness
const exponentialFat = Math.pow(normalizedFat, 1.5);
return Math.max(0.02, Math.min(0.6, 0.02 + exponentialFat * 0.58));
};
/**
* Props for BoneAttachedMuscle component
*
* @korean 뼈부착근육속성
*/
export interface BoneAttachedMuscleProps {
/** Muscle attachment configuration */
readonly attachment: MuscleAttachment;
/** Tension level (0-1) for muscle flex */
readonly tension: number;
/** Whether muscle is shaking (exhausted state) */
readonly isShaking: boolean;
/** Muscle scale factor based on archetype */
readonly muscleScaleFactor: number;
/** Fat layer opacity */
readonly fatLayerOpacity: number;
/** Fat layer thickness multiplier */
readonly fatLayerThickness: number;
}
/**
* Single bone-attached muscle component
*
* Renders a muscle mesh that follows its parent bone's transformations.
* Includes dynamic scaling based on tension and archetype.
*
* @korean 뼈부착근육컴포넌트
*/
export const BoneAttachedMuscle: React.FC<BoneAttachedMuscleProps> = ({
attachment,
tension,
isShaking,
muscleScaleFactor,
fatLayerOpacity,
fatLayerThickness,
}) => {
const meshRef = useRef<THREE.Mesh>(null);
const fatMeshRef = useRef<THREE.Mesh>(null);
// Round tension to reduce unnecessary re-renders
const roundedTension = Math.round(tension * 100) / 100;
// Calculate current scale based on tension
const currentScale = useMemo(() => {
const t = Math.max(0, Math.min(1, roundedTension));
const lerp = (start: number, end: number, factor: number) =>
start + (end - start) * factor;
return new THREE.Vector3(
lerp(attachment.baseScale.x, attachment.maxFlexScale.x, t) *
muscleScaleFactor,
lerp(attachment.baseScale.y, attachment.maxFlexScale.y, t) *
muscleScaleFactor,
lerp(attachment.baseScale.z, attachment.maxFlexScale.z, t) *
muscleScaleFactor,
);
}, [attachment, roundedTension, muscleScaleFactor]);
// Fat layer scale
const fatScale = useMemo(() => {
return new THREE.Vector3(
currentScale.x * (1 + fatLayerThickness),
currentScale.y * (1 + fatLayerThickness),
currentScale.z * (1 + fatLayerThickness),
);
}, [currentScale, fatLayerThickness]);
// Muscle color based on tension and exhaustion
const muscleColor = useMemo(() => {
Iif (isShaking) {
return KOREAN_COLORS.MUSCLE_EXHAUSTED;
I} else if (roundedTension > 0.7) {
return KOREAN_COLORS.MUSCLE_FLEXED;
}
return KOREAN_COLORS.MUSCLE_TONE;
}, [roundedTension, isShaking]);
// Shaking animation at 60fps
useFrame((state) => {
if (!meshRef.current) return;
if (!isShaking) {
meshRef.current.rotation.z = attachment.localRotation.z;
return;
}
// Shaking frequency: 20Hz
const shake = Math.sin(state.clock.elapsedTime * 20 * Math.PI * 2) * 0.02;
meshRef.current.rotation.z = attachment.localRotation.z + shake;
if (fatMeshRef.current) {
fatMeshRef.current.rotation.z = attachment.localRotation.z + shake;
}
});
return (
<group
position={
attachment.localOffset
.toArray()
.map((v) => v * MUSCLE_GEOMETRY_NORMALIZATION) as [
number,
number,
number,
]
}
rotation={[attachment.localRotation.x, attachment.localRotation.y, 0]}
>
{/* Main muscle mesh */}
<mesh
ref={meshRef}
rotation={[0, 0, attachment.localRotation.z]}
scale={currentScale.toArray()}
castShadow
receiveShadow
name={`muscle-${attachment.name}`}
>
<capsuleGeometry
args={[
attachment.radius * MUSCLE_GEOMETRY_NORMALIZATION,
attachment.length * MUSCLE_GEOMETRY_NORMALIZATION,
8,
16,
]}
/>
<meshPhysicalMaterial
color={muscleColor}
metalness={0.02}
roughness={0.85}
clearcoat={0.08}
clearcoatRoughness={0.6}
envMapIntensity={0.3}
sheen={0.15}
sheenRoughness={0.8}
sheenColor={muscleColor}
/>
</mesh>
{/* Fat layer (only visible when fat mass is significant) */}
{fatLayerOpacity > 0.05 && (
<mesh
ref={fatMeshRef}
rotation={[0, 0, attachment.localRotation.z]}
scale={fatScale.toArray()}
castShadow
receiveShadow
name={`fat-layer-${attachment.name}`}
>
<capsuleGeometry
args={[
attachment.radius * MUSCLE_GEOMETRY_NORMALIZATION,
attachment.length * MUSCLE_GEOMETRY_NORMALIZATION,
8,
16,
]}
/>
<meshStandardMaterial
color={KOREAN_COLORS.SKIN_TONE}
metalness={0.05}
roughness={0.95}
transparent={true}
opacity={fatLayerOpacity}
depthWrite={false}
/>
</mesh>
)}
</group>
);
};
/**
* Props for BoneMuscles component (renders all muscles for a bone)
*
* @korean 뼈근육들속성
*/
export interface BoneMusclesProps {
/** Bone name to look up muscles for */
readonly boneName: string;
/** Map of muscle name to tension level */
readonly muscleStates: Map<string, number>;
/** Whether character is exhausted (triggers shaking) */
readonly isExhausted: boolean;
/** Physical attributes for scaling */
readonly physicalAttributes?: {
readonly muscleMass: number;
readonly fatMass: number;
};
}
/**
* Renders all muscles attached to a specific bone
*
* Looks up muscle attachments by bone name and renders each one.
* Muscles inherit the bone's transformations automatically.
*
* @korean 뼈근육들컴포넌트
*/
export const BoneMuscles: React.FC<BoneMusclesProps> = ({
boneName,
muscleStates,
isExhausted,
physicalAttributes,
}) => {
// Get muscle attachments for this bone
const attachments = BONE_MUSCLE_MAP[boneName];
// Calculate scaling factors
const muscleScaleFactor = useMemo(() => {
Iif (!physicalAttributes) return 1.0;
return calculateMuscleScaleFactor(physicalAttributes.muscleMass);
}, [physicalAttributes]);
const fatLayerOpacity = useMemo(() => {
Iif (!physicalAttributes) return 0.0;
return calculateFatLayerOpacity(physicalAttributes.fatMass);
}, [physicalAttributes]);
const fatLayerThickness = useMemo(() => {
Iif (!physicalAttributes) return 0.0;
return calculateFatLayerThickness(physicalAttributes.fatMass);
}, [physicalAttributes]);
// No muscles for this bone
if (!attachments || attachments.length === 0) {
return null;
}
return (
<>
{attachments.map((attachment) => {
const tension = muscleStates.get(attachment.name) ?? 0;
const isShaking =
isExhausted &&
tension > DEFAULT_MUSCLE_CONFIG.shakingTensionThreshold;
return (
<BoneAttachedMuscle
key={attachment.name}
attachment={attachment}
tension={tension}
isShaking={isShaking}
muscleScaleFactor={muscleScaleFactor}
fatLayerOpacity={fatLayerOpacity}
fatLayerThickness={fatLayerThickness}
/>
);
})}
</>
);
};
export default BoneMuscles;
|