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 | 1x 1x 1x | /**
* ArterialSpray3D - High-pressure arterial blood jet particle system
*
* Simulates arterial blood spray from vital point strikes on major arteries
* (carotid, femoral, brachial, subclavian). Features pulsating high-velocity
* jets synchronized with heart rate for brutal realism.
*
* Features:
* - High-pressure jet physics (10-15 m/s vs regular 2-5 m/s)
* - Narrow spray cone (15° vs 45° regular)
* - Pulsating intensity (1.2 Hz heart rate simulation)
* - 3-5 second sustained spray duration
* - Mobile-optimized particle counts
*
* @module components/combat/ArterialSpray3D
* @category Combat Effects
* @korean 동맥분사3D
*/
import { useFrame } from "@react-three/fiber";
import React, { useRef, useMemo } from "react";
import * as THREE from "three";
import { KOREAN_COLORS } from "../../../../../types/constants";
import { ThreeObjectPools } from "../../../../../utils/threeObjectPool";
/**
* Arterial vital point types for targeted strikes
* 동맥 급소 유형
*/
export type ArterialVitalPoint =
| "carotid" // 경동맥 - Neck artery
| "femoral" // 대퇴동맥 - Thigh artery
| "brachial" // 상완동맥 - Upper arm artery
| "subclavian"; // 쇄골하동맥 - Below collarbone artery
/**
* Arterial spray effect configuration
*/
export interface ArterialSprayEffect {
/** Unique identifier */
readonly id: string;
/** Origin position in 3D world space */
readonly position: [number, number, number];
/** Spray direction (normalized) */
readonly direction: [number, number, number];
/** Type of artery struck */
readonly vitalPoint: ArterialVitalPoint;
/** Blood pressure intensity (0.5-1.0) - affects velocity */
readonly pressure: number;
/** Whether to enable pulsating spray */
readonly pulsating: boolean;
/** Timestamp when effect was created */
readonly startTime: number;
}
/**
* Props for ArterialSpray3D component
*/
export interface ArterialSpray3DProps {
/** Active arterial spray effects to render */
readonly effects: readonly ArterialSprayEffect[];
/** Whether to enable arterial blood effects */
readonly enabled?: boolean;
/** Mobile device mode (reduced particle count) */
readonly isMobile?: boolean;
/** Callback when effect completes */
readonly onEffectComplete?: (effectId: string) => void;
}
/**
* Arterial spray physics constants
* 동맥 분사 물리 상수
*/
const ARTERIAL_CONSTANTS = {
/** High-velocity range (m/s) - 3x faster than regular blood */
VELOCITY_MIN: 10,
VELOCITY_MAX: 15,
/** Narrow spray cone angle (radians) - focused jet */
SPRAY_CONE_ANGLE: Math.PI / 12, // 15 degrees
/** Heart beat frequency (Hz) for pulsing */
PULSE_FREQUENCY: 1.2, // 72 bpm
/** Pulse intensity variation (0-1) */
PULSE_AMPLITUDE: 0.4,
/** Spray duration (seconds) */
DURATION: 5.0,
/** Gravity acceleration (m/s²) */
GRAVITY: -9.8,
/** Air resistance coefficient */
AIR_RESISTANCE: 0.97,
/** Floor Y position */
FLOOR_Y: 0,
/** Pool lifetime after settling (seconds) */
POOL_LIFETIME: 10,
/** Fade-out duration for pools (seconds) */
POOL_FADE: 2,
/** Particle counts */
MAX_PARTICLES_DESKTOP: 250,
MAX_PARTICLES_MOBILE: 120,
/** Particle size range */
PARTICLE_SIZE_MIN: 0.06,
PARTICLE_SIZE_MAX: 0.12,
/** Max delta time to prevent physics explosion */
MAX_DELTA: 1 / 30,
} as const;
/**
* Arterial particle data structure
*/
interface ArterialParticle {
position: THREE.Vector3;
velocity: THREE.Vector3;
age: number;
lifetime: number;
settled: boolean;
size: number;
}
/**
* Effect instance tracking
*/
interface EffectInstance {
particles: ArterialParticle[];
startTime: number;
effect: ArterialSprayEffect;
}
/**
* ArterialSpray3D Component
*
* Renders high-pressure arterial blood jets from vital point strikes
*
* @example
* ```tsx
* <ArterialSpray3D
* effects={arterialEffects}
* enabled={settings.blood}
* isMobile={isMobile}
* onEffectComplete={handleEffectComplete}
* />
* ```
*/
export const ArterialSpray3D: React.FC<ArterialSpray3DProps> = ({
effects,
enabled = true,
isMobile = false,
onEffectComplete,
}) => {
const effectInstancesRef = useRef<Map<string, EffectInstance>>(new Map());
const pointsRef = useRef<THREE.Points>(null);
const maxParticles = isMobile
? ARTERIAL_CONSTANTS.MAX_PARTICLES_MOBILE
: ARTERIAL_CONSTANTS.MAX_PARTICLES_DESKTOP;
const { positionArray, sizeArray, opacityArray } = useMemo(() => {
const maxTotal = maxParticles * 10; // Support up to 10 simultaneous effects
return {
positionArray: new Float32Array(maxTotal * 3),
sizeArray: new Float32Array(maxTotal),
opacityArray: new Float32Array(maxTotal),
};
}, [maxParticles]);
React.useEffect(() => {
if (!enabled) return;
effects.forEach((effect) => {
if (!effectInstancesRef.current.has(effect.id)) {
const arterySizeMultiplier = effect.vitalPoint === "carotid" ? 1.2 : 1.0;
const particleCount = Math.floor(maxParticles * arterySizeMultiplier);
const particles: ArterialParticle[] = [];
const tempDir = ThreeObjectPools.vector3.acquire();
const tempAxis = ThreeObjectPools.vector3.acquire();
const tempUp = ThreeObjectPools.vector3.acquire();
const tempVel = ThreeObjectPools.vector3.acquire();
try {
tempDir.set(...effect.direction).normalize();
tempUp.set(0, 1, 0);
for (let i = 0; i < particleCount; i++) {
const theta = Math.random() * Math.PI * 2;
const phi =
Math.random() * ARTERIAL_CONSTANTS.SPRAY_CONE_ANGLE;
tempAxis.copy(tempUp).cross(tempDir).normalize();
tempVel.copy(tempDir);
tempVel.applyAxisAngle(tempAxis, phi);
tempVel.applyAxisAngle(tempDir, theta);
const speed =
ARTERIAL_CONSTANTS.VELOCITY_MIN +
Math.random() *
(ARTERIAL_CONSTANTS.VELOCITY_MAX - ARTERIAL_CONSTANTS.VELOCITY_MIN);
tempVel.multiplyScalar(speed * effect.pressure);
particles.push({
position: new THREE.Vector3(...effect.position),
velocity: tempVel.clone(),
age: 0,
lifetime:
ARTERIAL_CONSTANTS.DURATION +
ARTERIAL_CONSTANTS.POOL_LIFETIME,
settled: false,
size:
ARTERIAL_CONSTANTS.PARTICLE_SIZE_MIN +
Math.random() *
(ARTERIAL_CONSTANTS.PARTICLE_SIZE_MAX -
ARTERIAL_CONSTANTS.PARTICLE_SIZE_MIN),
});
}
} finally {
ThreeObjectPools.vector3.release(tempDir);
ThreeObjectPools.vector3.release(tempAxis);
ThreeObjectPools.vector3.release(tempUp);
ThreeObjectPools.vector3.release(tempVel);
}
effectInstancesRef.current.set(effect.id, {
particles,
startTime: Date.now(),
effect,
});
}
});
const activeIds = new Set(effects.map((e) => e.id));
effectInstancesRef.current.forEach((_, id) => {
if (!activeIds.has(id)) {
effectInstancesRef.current.delete(id);
}
});
}, [effects, enabled, maxParticles]);
useFrame((_, delta) => {
if (!enabled || !pointsRef.current) return;
const safeDelta = Math.min(delta, ARTERIAL_CONSTANTS.MAX_DELTA);
const currentTime = Date.now();
let particleIndex = 0;
effectInstancesRef.current.forEach((instance, effectId) => {
const { particles, startTime, effect } = instance;
const elapsed = (currentTime - startTime) / 1000;
const pulseFactor = effect.pulsating
? 1.0 +
Math.sin(elapsed * ARTERIAL_CONSTANTS.PULSE_FREQUENCY * Math.PI * 2) *
ARTERIAL_CONSTANTS.PULSE_AMPLITUDE
: 1.0;
let allSettled = true;
particles.forEach((particle) => {
particle.age += safeDelta;
if (particle.age < particle.lifetime) {
allSettled = false;
if (!particle.settled) {
if (particle.age < ARTERIAL_CONSTANTS.DURATION) {
particle.velocity.multiplyScalar(pulseFactor);
}
particle.position.addScaledVector(particle.velocity, safeDelta);
particle.velocity.y += ARTERIAL_CONSTANTS.GRAVITY * safeDelta;
particle.velocity.multiplyScalar(ARTERIAL_CONSTANTS.AIR_RESISTANCE);
if (particle.position.y <= ARTERIAL_CONSTANTS.FLOOR_Y) {
particle.position.y = ARTERIAL_CONSTANTS.FLOOR_Y;
particle.velocity.set(0, 0, 0);
particle.settled = true;
}
}
if (particleIndex < positionArray.length / 3) {
const i3 = particleIndex * 3;
positionArray[i3] = particle.position.x;
positionArray[i3 + 1] = particle.position.y;
positionArray[i3 + 2] = particle.position.z;
sizeArray[particleIndex] = particle.size;
let opacity = 1.0;
if (particle.settled) {
const poolAge = particle.age - ARTERIAL_CONSTANTS.DURATION;
const fadeStart =
ARTERIAL_CONSTANTS.POOL_LIFETIME - ARTERIAL_CONSTANTS.POOL_FADE;
if (poolAge > fadeStart) {
opacity =
1.0 - (poolAge - fadeStart) / ARTERIAL_CONSTANTS.POOL_FADE;
}
}
opacityArray[particleIndex] = opacity;
particleIndex++;
}
}
});
if (allSettled && onEffectComplete) {
onEffectComplete(effectId);
}
});
const geometry = pointsRef.current.geometry;
if (geometry.attributes.position) {
geometry.attributes.position.needsUpdate = true;
geometry.attributes.size.needsUpdate = true;
geometry.attributes.opacity.needsUpdate = true;
}
});
if (!enabled || effects.length === 0) return null;
return (
<points ref={pointsRef}>
<bufferGeometry>
<bufferAttribute
attach="attributes-position"
count={positionArray.length / 3}
array={positionArray}
itemSize={3}
args={[positionArray, 3]}
/>
</bufferGeometry>
<pointsMaterial
size={0.1}
color={KOREAN_COLORS.PRIMARY_RED} // Deep red for arterial blood
transparent
opacity={0.9}
sizeAttenuation
depthWrite={false}
/>
</points>
);
};
ArterialSpray3D.displayName = "ArterialSpray3D";
|