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 | 5x 5x 2840x 2840x 2840x 1420x 4260x 1420x 2840x 1420x 1420x 1420x 2840x 2840x 5x 142x 2840x 2840x 2840x | /**
* Muscle system component for realistic fighter physiology visualization
*
* Renders dynamic muscle groups that flex and tense during combat techniques.
* Implements anatomically accurate muscle activation with smooth transitions.
*
* @module components/three/MuscleSystem
* @category 3D Components
* @korean 근육시스템컴포넌트
*/
import { useFrame } from "@react-three/fiber";
import React, { useMemo, useRef } from "react";
import * as THREE from "three";
import { KOREAN_COLORS } from "../../types/constants";
import type { MuscleGroup, MuscleMeshProps } from "../../types/muscle";
import { DEFAULT_MUSCLE_CONFIG } from "../../types/muscle";
/**
* Comprehensive muscle group definitions for humanoid character
*
* Positions are relative to character center (spine base).
* All measurements in Three.js units (approximately meters).
*
* @korean 근육그룹정의
*/
export const MUSCLE_GROUPS: Record<string, MuscleGroup> = {
// Shoulders - 어깨
SHOULDER_L: {
name: "SHOULDER_L",
korean: "왼쪽어깨",
english: "Left Shoulder",
baseScale: new THREE.Vector3(0.15, 0.1, 0.1),
maxFlexScale: new THREE.Vector3(0.20, 0.13, 0.13), // +33% size
position: new THREE.Vector3(-0.35, 1.5, 0),
geometryParams: { radius: 0.1, length: 0.1, capSegments: 8, radialSegments: 16 },
},
SHOULDER_R: {
name: "SHOULDER_R",
korean: "오른쪽어깨",
english: "Right Shoulder",
baseScale: new THREE.Vector3(0.15, 0.1, 0.1),
maxFlexScale: new THREE.Vector3(0.20, 0.13, 0.13),
position: new THREE.Vector3(0.35, 1.5, 0),
geometryParams: { radius: 0.1, length: 0.1, capSegments: 8, radialSegments: 16 },
},
// Biceps - 이두근
BICEP_L: {
name: "BICEP_L",
korean: "왼쪽이두근",
english: "Left Bicep",
baseScale: new THREE.Vector3(0.09, 0.25, 0.09),
maxFlexScale: new THREE.Vector3(0.12, 0.25, 0.12), // +33% width
position: new THREE.Vector3(-0.3, 1.1, 0),
geometryParams: { radius: 0.09, length: 0.25, capSegments: 8, radialSegments: 16 },
},
BICEP_R: {
name: "BICEP_R",
korean: "오른쪽이두근",
english: "Right Bicep",
baseScale: new THREE.Vector3(0.09, 0.25, 0.09),
maxFlexScale: new THREE.Vector3(0.12, 0.25, 0.12),
position: new THREE.Vector3(0.3, 1.1, 0),
geometryParams: { radius: 0.09, length: 0.25, capSegments: 8, radialSegments: 16 },
},
// Triceps - 삼두근
TRICEP_L: {
name: "TRICEP_L",
korean: "왼쪽삼두근",
english: "Left Tricep",
baseScale: new THREE.Vector3(0.08, 0.22, 0.08),
maxFlexScale: new THREE.Vector3(0.10, 0.22, 0.10),
position: new THREE.Vector3(-0.3, 1.1, -0.05),
geometryParams: { radius: 0.08, length: 0.22, capSegments: 8, radialSegments: 16 },
},
TRICEP_R: {
name: "TRICEP_R",
korean: "오른쪽삼두근",
english: "Right Tricep",
baseScale: new THREE.Vector3(0.08, 0.22, 0.08),
maxFlexScale: new THREE.Vector3(0.10, 0.22, 0.10),
position: new THREE.Vector3(0.3, 1.1, -0.05),
geometryParams: { radius: 0.08, length: 0.22, capSegments: 8, radialSegments: 16 },
},
// Forearms - 전완근
FOREARM_L: {
name: "FOREARM_L",
korean: "왼쪽전완근",
english: "Left Forearm",
baseScale: new THREE.Vector3(0.07, 0.20, 0.07),
maxFlexScale: new THREE.Vector3(0.09, 0.20, 0.09),
position: new THREE.Vector3(-0.28, 0.7, 0),
geometryParams: { radius: 0.07, length: 0.20, capSegments: 8, radialSegments: 16 },
},
FOREARM_R: {
name: "FOREARM_R",
korean: "오른쪽전완근",
english: "Right Forearm",
baseScale: new THREE.Vector3(0.07, 0.20, 0.07),
maxFlexScale: new THREE.Vector3(0.09, 0.20, 0.09),
position: new THREE.Vector3(0.28, 0.7, 0),
geometryParams: { radius: 0.07, length: 0.20, capSegments: 8, radialSegments: 16 },
},
// Chest - 가슴
PECTORALS: {
name: "PECTORALS",
korean: "대흉근",
english: "Pectorals",
baseScale: new THREE.Vector3(0.25, 0.15, 0.10),
maxFlexScale: new THREE.Vector3(0.33, 0.18, 0.13),
position: new THREE.Vector3(0, 1.4, 0.08),
geometryParams: { radius: 0.12, length: 0.15, capSegments: 8, radialSegments: 16 },
},
// Core muscles - 복근
CORE: {
name: "CORE",
korean: "코어",
english: "Core",
baseScale: new THREE.Vector3(0.20, 0.25, 0.12),
maxFlexScale: new THREE.Vector3(0.24, 0.30, 0.14),
position: new THREE.Vector3(0, 1.0, 0.05),
geometryParams: { radius: 0.10, length: 0.25, capSegments: 8, radialSegments: 16 },
},
ABS: {
name: "ABS",
korean: "복근",
english: "Abdominals",
baseScale: new THREE.Vector3(0.18, 0.20, 0.10),
maxFlexScale: new THREE.Vector3(0.22, 0.24, 0.12),
position: new THREE.Vector3(0, 0.9, 0.08),
geometryParams: { radius: 0.09, length: 0.20, capSegments: 8, radialSegments: 16 },
},
OBLIQUES: {
name: "OBLIQUES",
korean: "복사근",
english: "Obliques",
baseScale: new THREE.Vector3(0.15, 0.18, 0.08),
maxFlexScale: new THREE.Vector3(0.18, 0.22, 0.10),
position: new THREE.Vector3(0, 0.95, 0.12),
geometryParams: { radius: 0.08, length: 0.18, capSegments: 8, radialSegments: 16 },
},
// Legs - 다리
QUAD_L: {
name: "QUAD_L",
korean: "왼쪽대퇴사두근",
english: "Left Quadriceps",
baseScale: new THREE.Vector3(0.11, 0.35, 0.11),
maxFlexScale: new THREE.Vector3(0.15, 0.35, 0.15), // +36% width
position: new THREE.Vector3(-0.15, 0.6, 0),
geometryParams: { radius: 0.11, length: 0.35, capSegments: 8, radialSegments: 16 },
},
QUAD_R: {
name: "QUAD_R",
korean: "오른쪽대퇴사두근",
english: "Right Quadriceps",
baseScale: new THREE.Vector3(0.11, 0.35, 0.11),
maxFlexScale: new THREE.Vector3(0.15, 0.35, 0.15),
position: new THREE.Vector3(0.15, 0.6, 0),
geometryParams: { radius: 0.11, length: 0.35, capSegments: 8, radialSegments: 16 },
},
HAMSTRING_L: {
name: "HAMSTRING_L",
korean: "왼쪽햄스트링",
english: "Left Hamstring",
baseScale: new THREE.Vector3(0.10, 0.32, 0.10),
maxFlexScale: new THREE.Vector3(0.13, 0.32, 0.13),
position: new THREE.Vector3(-0.15, 0.6, -0.05),
geometryParams: { radius: 0.10, length: 0.32, capSegments: 8, radialSegments: 16 },
},
HAMSTRING_R: {
name: "HAMSTRING_R",
korean: "오른쪽햄스트링",
english: "Right Hamstring",
baseScale: new THREE.Vector3(0.10, 0.32, 0.10),
maxFlexScale: new THREE.Vector3(0.13, 0.32, 0.13),
position: new THREE.Vector3(0.15, 0.6, -0.05),
geometryParams: { radius: 0.10, length: 0.32, capSegments: 8, radialSegments: 16 },
},
CALF_L: {
name: "CALF_L",
korean: "왼쪽종아리",
english: "Left Calf",
baseScale: new THREE.Vector3(0.08, 0.28, 0.08),
maxFlexScale: new THREE.Vector3(0.10, 0.28, 0.10),
position: new THREE.Vector3(-0.15, 0.25, -0.02),
geometryParams: { radius: 0.08, length: 0.28, capSegments: 8, radialSegments: 16 },
},
CALF_R: {
name: "CALF_R",
korean: "오른쪽종아리",
english: "Right Calf",
baseScale: new THREE.Vector3(0.08, 0.28, 0.08),
maxFlexScale: new THREE.Vector3(0.10, 0.28, 0.10),
position: new THREE.Vector3(0.15, 0.25, -0.02),
geometryParams: { radius: 0.08, length: 0.28, capSegments: 8, radialSegments: 16 },
},
GLUTE_L: {
name: "GLUTE_L",
korean: "왼쪽둔근",
english: "Left Glute",
baseScale: new THREE.Vector3(0.12, 0.12, 0.10),
maxFlexScale: new THREE.Vector3(0.16, 0.14, 0.13),
position: new THREE.Vector3(-0.12, 0.85, -0.08),
geometryParams: { radius: 0.10, length: 0.10, capSegments: 8, radialSegments: 16 },
},
GLUTE_R: {
name: "GLUTE_R",
korean: "오른쪽둔근",
english: "Right Glute",
baseScale: new THREE.Vector3(0.12, 0.12, 0.10),
maxFlexScale: new THREE.Vector3(0.16, 0.14, 0.13),
position: new THREE.Vector3(0.12, 0.85, -0.08),
geometryParams: { radius: 0.10, length: 0.10, capSegments: 8, radialSegments: 16 },
},
} as const;
/**
* Individual muscle mesh with dynamic tension and shaking effects
*
* Renders a single muscle group with smooth scaling transitions.
* Applies shaking effect when exhausted (stamina < 20%).
*
* @korean 근육메시컴포넌트
*/
export const MuscleMesh: React.FC<MuscleMeshProps> = ({
muscleGroup,
tension,
isShaking,
color = KOREAN_COLORS.MUSCLE_TONE,
metalness = 0.1,
roughness = 0.9,
}) => {
const meshRef = useRef<THREE.Mesh>(null);
// Reduce sensitivity to tiny floating-point changes in tension
const roundedTension = Math.round(tension * 100) / 100;
// Interpolate between base and flexed scale based on tension (0-1)
const currentScale = useMemo(() => {
// Clamp tension to 0-1 range
const t = Math.max(0, Math.min(1, roundedTension));
// Linear interpolation: start + (end - start) * t
const lerp = (start: number, end: number, t: number) => start + (end - start) * t;
return new THREE.Vector3(
lerp(muscleGroup.baseScale.x, muscleGroup.maxFlexScale.x, t),
lerp(muscleGroup.baseScale.y, muscleGroup.maxFlexScale.y, t),
lerp(muscleGroup.baseScale.z, muscleGroup.maxFlexScale.z, t)
);
}, [muscleGroup, roundedTension]);
// Muscle color based on tension and exhaustion (use rounded tension for stability)
const muscleColor = useMemo(() => {
Iif (isShaking) {
// Exhausted state visually overrides flexed state when both are true
return KOREAN_COLORS.MUSCLE_EXHAUSTED; // Darker when exhausted
I} else if (roundedTension > 0.7) {
return KOREAN_COLORS.MUSCLE_FLEXED; // Lighter when flexed
}
return color;
}, [roundedTension, isShaking, color]);
// Shaking effect animation at 60fps
useFrame((state) => {
if (!meshRef.current) return;
if (!isShaking) {
// Reset rotation when not shaking
meshRef.current.rotation.z = 0;
return;
}
// Shaking frequency: 20Hz (as per spec)
const shake = Math.sin(state.clock.elapsedTime * 20 * Math.PI * 2) * 0.02;
meshRef.current.rotation.z = shake;
});
return (
<mesh
ref={meshRef}
position={muscleGroup.position}
scale={currentScale}
castShadow
receiveShadow
data-testid={`muscle-${muscleGroup.name}`}
>
<capsuleGeometry
args={[
muscleGroup.geometryParams.radius,
muscleGroup.geometryParams.length,
muscleGroup.geometryParams.capSegments,
muscleGroup.geometryParams.radialSegments,
]}
/>
<meshStandardMaterial
color={muscleColor}
metalness={metalness}
roughness={roughness}
transparent={false}
/>
</mesh>
);
};
/**
* Complete muscle system rendering all muscle groups
*
* @param muscleStates - Map of muscle group names to tension levels (0-1)
* @param isExhausted - Whether character is exhausted (triggers shaking)
*
* @korean 전체근육시스템
*/
export interface MuscleSystemProps {
readonly muscleStates: Map<string, number>;
readonly isExhausted?: boolean;
}
export const MuscleSystem: React.FC<MuscleSystemProps> = ({
muscleStates,
isExhausted = false,
}) => {
return (
<group data-testid="muscle-system">
{Object.entries(MUSCLE_GROUPS).map(([name, muscleGroup]) => {
const tension = muscleStates.get(name) ?? 0;
const isShaking =
isExhausted &&
tension > DEFAULT_MUSCLE_CONFIG.shakingTensionThreshold;
return (
<MuscleMesh
key={name}
muscleGroup={muscleGroup}
tension={tension}
isShaking={isShaking}
/>
);
})}
</group>
);
};
export default MuscleSystem;
|