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 | 9x 3976x 3976x 3976x 3976x 3976x 3976x 3976x 9x 3976x 3976x 3976x 3976x 3976x 3976x 15904x 15904x 3976x 9x 15904x 15904x 15904x 15904x 3976x 142x 142x 142x 142x 3976x 284x 284x 284x 3976x 284x 284x 284x 3976x 3976x 284x 284x 284x 3976x 284x 284x 284x 3976x 2240x 80x 80x 80x 2240x 1680x 60x 60x 60x 60x 1680x 15904x 9x 3976x 3976x 3976x 3976x 3976x 1418x 1418x 3976x 3976x 3976x 3976x 3976x 3976x 1418x 3976x 2618x 1358x 1418x | /**
* Bone-attached clothing system for realistic clothing movement with skeleton
*
* Clothing is rendered as children of their parent bones, inheriting bone
* transformations automatically for proper movement during animation.
* This mirrors the BoneMuscles approach for consistent rendering.
*
* @module components/three/BoneClothing
* @category 3D Components
* @korean 뼈부착의류시스템
*/
import React, { useEffect, useMemo } from "react";
import * as THREE from "three";
import { getArchetypeClothing } from "../../../../data/archetypeClothing";
import type { ClothingItem } from "../../../../types/clothing";
import type { PlayerArchetype } from "../../../../types/common";
/**
* Clothing attachment configuration for a bone
*
* Defines how clothing is positioned relative to its parent bone.
* Position is in local bone space, so clothing moves with the bone.
*
* @korean 의류부착설정
*/
export interface ClothingAttachment {
/** Geometry for this clothing piece */
readonly geometry: THREE.BufferGeometry;
/** Local position offset from bone origin */
readonly localOffset: THREE.Vector3;
/** Local rotation relative to bone */
readonly localRotation: THREE.Euler;
/** Color of the clothing */
readonly color: number;
/** Emissive color for glow effects */
readonly emissiveColor?: number;
/** Emissive intensity */
readonly emissiveIntensity?: number;
/** Metalness for material */
readonly metalness?: number;
/** Roughness for material */
readonly roughness?: number;
/** Clothing item ID */
readonly itemId: string;
}
/**
* Props for BoneClothing component
*/
export interface BoneClothingProps {
/** Name of the bone this clothing attaches to */
readonly boneName: string;
/** Player archetype for clothing style */
readonly archetype: PlayerArchetype;
/** Physical attributes for sizing */
readonly physicalAttributes?: {
readonly muscleMass: number;
readonly fatMass: number;
readonly shoulderWidth: number;
readonly torsoLength: number;
readonly armLength: number;
readonly legLength: number;
};
}
/**
* Calculate body thickness multiplier based on muscle mass and fat mass
*/
const calculateBodyThickness = (
muscleMass: number,
fatMass: number
): number => {
const referenceMuscle = 35;
const referenceFat = 12;
const muscleRatio = muscleMass / referenceMuscle;
const muscleContribution = Math.sqrt(muscleRatio) * 0.7;
const fatRatio = fatMass / referenceFat;
const fatContribution = Math.sqrt(fatRatio) * 0.3;
return muscleContribution + fatContribution;
};
/**
* Get clothing attachments for a specific bone
*/
const getClothingForBone = (
boneName: string,
archetype: PlayerArchetype,
physicalAttributes: {
muscleMass: number;
fatMass: number;
shoulderWidth: number;
torsoLength: number;
armLength: number;
legLength: number;
}
): ClothingAttachment[] => {
const clothingSet = getArchetypeClothing(archetype);
const attachments: ClothingAttachment[] = [];
const bodyThickness = calculateBodyThickness(
physicalAttributes.muscleMass,
physicalAttributes.fatMass
);
// Scaling factors
const torsoScale = physicalAttributes.torsoLength / 59;
const legScale = physicalAttributes.legLength / 96;
for (const item of clothingSet.items) {
const attachmentsForItem = getAttachmentsForItem(
item,
boneName,
bodyThickness,
torsoScale,
legScale,
physicalAttributes
);
attachments.push(...attachmentsForItem);
}
return attachments;
};
/**
* Generate clothing attachments for a specific item on a bone
*/
const getAttachmentsForItem = (
item: ClothingItem,
boneName: string,
bodyThickness: number,
torsoScale: number,
legScale: number,
physicalAttributes: {
shoulderWidth: number;
armLength: number;
legLength: number;
}
): ClothingAttachment[] => {
const fitScaleMap: Record<string, number> = {
tight: 1.08,
fitted: 1.15,
loose: 1.25,
oversized: 1.4,
};
const fitScale = fitScaleMap[item.fit] ?? 1.15;
const attachments: ClothingAttachment[] = [];
switch (item.type) {
case "torso":
// Main torso on spine_middle
if (boneName === "spine_middle") {
const width =
(physicalAttributes.shoulderWidth / 100) * fitScale * bodyThickness;
const height = (59 / 100) * torsoScale * 1.2; // Using base torsoLength
const depth = 0.22 * fitScale * bodyThickness;
attachments.push({
geometry: new THREE.BoxGeometry(width, height, depth),
localOffset: new THREE.Vector3(0, 0, 0.04 * bodyThickness),
localRotation: new THREE.Euler(0, 0, 0),
color: item.colorPrimary,
emissiveColor: item.colorEmissive,
emissiveIntensity: item.emissiveIntensity,
metalness: item.metalness,
roughness: item.roughness,
itemId: item.id,
});
}
// Sleeves
if (boneName === "upper_arm_L" || boneName === "upper_arm_R") {
const armThickness = 0.08 * fitScale * bodyThickness;
const upperArmLength = (physicalAttributes.armLength / 100) * 0.45;
attachments.push({
geometry: new THREE.CylinderGeometry(
armThickness * 1.1,
armThickness * 0.95,
upperArmLength,
12
),
localOffset: new THREE.Vector3(0, -upperArmLength * 0.4, 0),
localRotation: new THREE.Euler(0, 0, 0),
color: item.colorPrimary,
emissiveColor: item.colorEmissive,
emissiveIntensity: item.emissiveIntensity,
metalness: item.metalness,
roughness: item.roughness,
itemId: `${item.id}-sleeve-upper-${boneName}`,
});
}
if (boneName === "forearm_L" || boneName === "forearm_R") {
const armThickness = 0.08 * fitScale * bodyThickness;
const forearmLength = (physicalAttributes.armLength / 100) * 0.4;
attachments.push({
geometry: new THREE.CylinderGeometry(
armThickness * 0.95,
armThickness * 0.85,
forearmLength,
12
),
localOffset: new THREE.Vector3(0, -forearmLength * 0.4, 0),
localRotation: new THREE.Euler(0, 0, 0),
color: item.colorPrimary,
emissiveColor: item.colorEmissive,
emissiveIntensity: item.emissiveIntensity,
metalness: item.metalness,
roughness: item.roughness,
itemId: `${item.id}-sleeve-forearm-${boneName}`,
});
}
break;
case "pants":
// Thigh segments
if (boneName === "thigh_L" || boneName === "thigh_R") {
const legThickness = 0.1 * fitScale * bodyThickness;
const thighLength =
(physicalAttributes.legLength / 100) * legScale * 0.45;
attachments.push({
geometry: new THREE.CylinderGeometry(
legThickness * 1.15,
legThickness * 0.95,
thighLength,
16
),
localOffset: new THREE.Vector3(0, -thighLength * 0.4, 0),
localRotation: new THREE.Euler(0, 0, 0),
color: item.colorPrimary,
emissiveColor: item.colorEmissive,
emissiveIntensity: item.emissiveIntensity,
metalness: item.metalness,
roughness: item.roughness,
itemId: `${item.id}-thigh-${boneName}`,
});
}
// Shin segments
if (boneName === "shin_L" || boneName === "shin_R") {
const legThickness = 0.1 * fitScale * bodyThickness;
const shinLength =
(physicalAttributes.legLength / 100) * legScale * 0.42;
attachments.push({
geometry: new THREE.CylinderGeometry(
legThickness * 0.95,
legThickness * 0.8,
shinLength,
16
),
localOffset: new THREE.Vector3(0, -shinLength * 0.4, 0),
localRotation: new THREE.Euler(0, 0, 0),
color: item.colorPrimary,
emissiveColor: item.colorEmissive,
emissiveIntensity: item.emissiveIntensity,
metalness: item.metalness,
roughness: item.roughness,
itemId: `${item.id}-shin-${boneName}`,
});
}
break;
case "belt":
if (boneName === "pelvis") {
const beltWidth =
(physicalAttributes.shoulderWidth / 100) * 0.85 * bodyThickness;
const beltDepth = 0.18 * bodyThickness;
attachments.push({
geometry: new THREE.BoxGeometry(beltWidth, 0.1, beltDepth),
localOffset: new THREE.Vector3(0, 0, 0.04 * bodyThickness),
localRotation: new THREE.Euler(0, 0, 0),
color: item.colorPrimary,
emissiveColor: item.colorEmissive,
emissiveIntensity: item.emissiveIntensity,
metalness: item.metalness,
roughness: item.roughness,
itemId: item.id,
});
}
break;
case "vest":
if (boneName === "spine_middle") {
const width =
(physicalAttributes.shoulderWidth / 100) *
0.95 *
fitScale *
bodyThickness;
const height = (59 / 100) * 0.75 * torsoScale;
const depth = 0.2 * fitScale * bodyThickness;
attachments.push({
geometry: new THREE.BoxGeometry(width, height, depth),
localOffset: new THREE.Vector3(0, 0, 0.06 * bodyThickness),
localRotation: new THREE.Euler(0, 0, 0),
color: item.colorPrimary,
emissiveColor: item.colorEmissive,
emissiveIntensity: item.emissiveIntensity,
metalness: item.metalness,
roughness: item.roughness,
itemId: item.id,
});
}
break;
}
return attachments;
};
/**
* BoneClothing Component
*
* Renders clothing attached to a specific bone.
* Clothing inherits bone transformations automatically through the scene graph.
*
* @korean 뼈부착의류
*/
export const BoneClothing: React.FC<BoneClothingProps> = ({
boneName,
archetype,
physicalAttributes,
}) => {
// Default physical attributes if not provided
const attrs = physicalAttributes ?? {
muscleMass: 35,
fatMass: 12,
shoulderWidth: 45,
torsoLength: 59,
armLength: 62,
legLength: 96,
};
// Get clothing attachments for this bone
const attachments = useMemo(
() => getClothingForBone(boneName, archetype, attrs),
[boneName, archetype, attrs]
);
// Create materials with cleanup
const materials = useMemo(() => {
return attachments.map((attachment) => {
const mat = new THREE.MeshStandardMaterial({
color: attachment.color,
emissive: attachment.emissiveColor ?? 0x000000,
emissiveIntensity: attachment.emissiveIntensity ?? 0,
metalness: attachment.metalness ?? 0.3,
roughness: attachment.roughness ?? 0.7,
});
return mat;
});
}, [attachments]);
// Cleanup materials on unmount
useEffect(() => {
return () => {
materials.forEach((mat) => mat.dispose());
};
}, [materials]);
// Cleanup geometries on unmount
useEffect(() => {
return () => {
attachments.forEach((attachment) => {
attachment.geometry.dispose();
});
};
}, [attachments]);
if (attachments.length === 0) {
return null;
}
return (
<>
{attachments.map((attachment, index) => (
<mesh
key={attachment.itemId}
geometry={attachment.geometry}
material={materials[index]}
position={attachment.localOffset.toArray()}
rotation={[
attachment.localRotation.x,
attachment.localRotation.y,
attachment.localRotation.z,
]}
castShadow
receiveShadow
name={`clothing-${attachment.itemId}`}
/>
))}
</>
);
};
export default BoneClothing;
|