3D 리플레이 실감 1단계: 변환기 v2 (스킬 주인 · 투사체 경로 · 앉기/점프 · 무기 상태 · 맞은 자리 · 사망 모션 · 설치/해체) · 공용 애니메이션 anims.glb · 요원 동작(앉기 · 점프 · 착지 · 조준 각 · 사격 반동 · 재장전 · 던지기 · 사망) · 예광 · 작은 이름표 · 요루 분신

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-18 00:29:09 +09:00
parent 5c8ba05da4
commit c94edac147
13 changed files with 1092 additions and 163 deletions

View File

@@ -6,9 +6,10 @@ import { player } from '../store/player';
import { settings, useSettings } from '../store/settings';
import { useData } from '../store/app';
import { fmtClock } from '../lib/format';
import { equipAt, equipLabel, equipTracks, isDead, roundAt, samplePlayer, type ReplayFile, type ReplaySync } from '../lib/replay';
import { equipAt, equipLabel, equipTracks, isDead, roundAt, samplePath, samplePlayer, type ReplayFile, type ReplaySync } from '../lib/replay';
import { findMap3d, loadMap3d, mapMaterial, worldMatrix } from '../lib/map3d';
import { AgentRig, loadAgent, loadWeapon } from '../lib/agents3d';
import { AgentRig, isGun, loadAgent, loadAnims, loadWeapon } from '../lib/agents3d';
import { buildAnimIndex, rigInput } from '../lib/replayAnim';
import { abilityLook, type AbilityLook } from '../lib/abilities';
/**
@@ -52,10 +53,13 @@ interface Props {
sync: ReplaySync;
}
/** 이름표: 거리와 상관없이 화면에서 같은 크기 (게임처럼 작게) */
const LABEL_H = 0.028;
function labelSprite(text: string, color: string) {
const { tex, aspect } = labelTexture(text, color);
const sp = new THREE.Sprite(new THREE.SpriteMaterial({ map: tex, depthTest: false, transparent: true }));
sp.scale.set(aspect * 2.2, 2.2, 1);
const sp = new THREE.Sprite(new THREE.SpriteMaterial({ map: tex, depthTest: false, transparent: true, sizeAttenuation: false }));
sp.scale.set(aspect * LABEL_H, LABEL_H, 1);
sp.center.set(0.5, 0);
sp.renderOrder = 10;
return sp;
}
@@ -63,22 +67,24 @@ function labelSprite(text: string, color: string) {
function labelTexture(text: string, color: string) {
const c = document.createElement('canvas');
const ctx = c.getContext('2d')!;
const font = '600 44px Pretendard, "Noto Sans KR", sans-serif';
const font = '700 40px Pretendard, "Noto Sans KR", sans-serif';
ctx.font = font;
const w = Math.ceil(ctx.measureText(text).width) + 36;
const w = Math.ceil(ctx.measureText(text).width) + 12;
c.width = w;
c.height = 68;
c.height = 56;
ctx.font = font;
ctx.fillStyle = 'rgba(8,14,20,0.78)';
ctx.beginPath();
ctx.roundRect(0, 0, w, 68, 18);
ctx.fill();
ctx.fillStyle = color;
ctx.textBaseline = 'middle';
ctx.fillText(text, 18, 36);
// 배경 상자 없이 글자 테두리만 (게임 이름표처럼)
ctx.lineWidth = 7;
ctx.strokeStyle = 'rgba(0,0,0,0.75)';
ctx.lineJoin = 'round';
ctx.strokeText(text, 6, 30);
ctx.fillStyle = color;
ctx.fillText(text, 6, 30);
const tex = new THREE.CanvasTexture(c);
tex.colorSpace = THREE.SRGBColorSpace;
return { tex, aspect: w / 68 };
tex.minFilter = THREE.LinearFilter;
return { tex, aspect: w / 56 };
}
interface PlayerView {
@@ -90,9 +96,6 @@ interface PlayerView {
body: THREE.Mesh;
cone: THREE.Mesh;
label: THREE.Sprite;
/** 들고 있는 것 (총 이름) */
weapon: THREE.Sprite;
weaponKind: number;
voice: THREE.Sprite;
ring: THREE.Mesh;
/** 바닥(미니맵)까지 내린 선과 그림자 점: 높이가 있어도 평면 위치가 보이게 */
@@ -254,21 +257,17 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
cone.geometry.rotateX(Math.PI / 2);
cone.geometry.translate(0, 0, 2.2);
cone.position.y = 1.9;
const label = labelSprite(r.info?.character?.name ? `${r.name} · ${r.info.character.name}` : r.name, r.ally ? '#8fd8ff' : '#ff9aa5');
label.position.y = 4.4;
// 이름표 · 말하는 표시는 화면에서 같은 크기라 선수 묶음(크기가 바뀐다) 밖에 둔다
const label = labelSprite(r.name, r.ally ? '#7fd3ff' : '#ff8a96');
label.userData.idx = r.idx;
const weapon = new THREE.Sprite(new THREE.SpriteMaterial({ depthTest: false, transparent: true }));
weapon.position.y = 2.75;
weapon.renderOrder = 10;
weapon.visible = false;
const voice = labelSprite('🔊 말하는 중', '#ffe08a');
voice.position.y = 6.6;
const voice = labelSprite('🔊', '#ffe08a');
voice.visible = false;
scene.add(label, voice);
const ring = new THREE.Mesh(new THREE.RingGeometry(1.4, 1.8, 32), new THREE.MeshBasicMaterial({ color: 0xffe08a, side: THREE.DoubleSide }));
ring.rotation.x = -Math.PI / 2;
ring.position.y = 0.05;
ring.visible = false;
group.add(body, cone, label, weapon, voice, ring);
group.add(body, cone, ring);
scene.add(group);
const dropGeo = new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(), new THREE.Vector3()]);
const drop = new THREE.Line(dropGeo, new THREE.LineBasicMaterial({ color, transparent: true, opacity: 0.7 }));
@@ -276,7 +275,7 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
const shadow = new THREE.Mesh(new THREE.CircleGeometry(0.75, 20), new THREE.MeshBasicMaterial({ color, transparent: true, opacity: 0.85 }));
shadow.rotation.x = -Math.PI / 2;
scene.add(drop, shadow);
return { idx: r.idx, info: r.info, name: r.name, ally: r.ally, group, body, cone, label, weapon, weaponKind: -2, voice, ring, drop, shadow, rig: null };
return { idx: r.idx, info: r.info, name: r.name, ally: r.ally, group, body, cone, label, voice, ring, drop, shadow, rig: null };
});
// 요원 3D 몸: UE 좌표(cm) 그대로 두고 맵과 같은 행렬로 옮긴다
@@ -287,10 +286,10 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
for (const v of views) {
const cls = replay.players[v.idx].character;
if (!cls) continue;
void loadAgent(cls)
.then((g) => {
void Promise.all([loadAgent(cls), loadAnims()])
.then(([g, anims]) => {
if (!g || disposed) return;
v.rig = new AgentRig(g);
v.rig = new AgentRig(g, anims);
agentsGroup.add(v.rig.root);
agentsGroup.updateMatrixWorld(true);
})
@@ -298,23 +297,7 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
}
let prevT = localT.current;
// 총 이름표 (같은 글자는 텍스처 하나)
const weaponTex = new Map<string, { tex: THREE.Texture; aspect: number }>();
const setWeapon = (v: PlayerView, kind: number) => {
if (v.weaponKind === kind) return;
v.weaponKind = kind;
const text = equipLabel(replay.equipKinds?.[kind]);
if (!text) {
v.weapon.visible = false;
return;
}
let lt = weaponTex.get(text);
if (!lt) weaponTex.set(text, (lt = labelTexture(`🔫 ${text}`, '#ffe9b0')));
v.weapon.material.map = lt.tex;
v.weapon.material.needsUpdate = true;
v.weapon.scale.set(lt.aspect * 1.6, 1.6, 1);
v.weapon.visible = true;
};
const animIx = buildAnimIndex(replay, equipByPlayer);
// 선택한 선수 이동 경로 (최근 6초)
const trailGeo = new THREE.BufferGeometry();
@@ -323,13 +306,47 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
trail.frustumCulled = false;
scene.add(trail);
// 사격 궤적 (최근 150ms)
// 총알 궤적 (예광): 쏜 자리 → 맞은 자리 (맞은 기록이 없으면 보는 방향으로 50m). UE 좌표(cm), 요원과 같은 묶음
const MAX_SHOTS = 48;
const TRACER_MS = 90;
const shotGeo = new THREE.BufferGeometry();
shotGeo.setAttribute('position', new THREE.BufferAttribute(new Float32Array(MAX_SHOTS * 6), 3));
const shots = new THREE.LineSegments(shotGeo, new THREE.LineBasicMaterial({ color: 0xfff1a8, transparent: true, opacity: 0.9 }));
const shots = new THREE.LineSegments(shotGeo, new THREE.LineBasicMaterial({ color: 0xffe9a0, transparent: true, opacity: 0.95, blending: THREE.AdditiveBlending, depthWrite: false }));
shots.frustumCulled = false;
scene.add(shots);
agentsGroup.add(shots);
// 사격별 끝점 (같은 선수가 같은 때 맞힌 기록)
const hitsByShooter = new Map<number, number[][]>();
for (const h of replay.hits ?? []) {
if (h[1] < 0) continue;
let a = hitsByShooter.get(h[1]);
if (!a) hitsByShooter.set(h[1], (a = []));
a.push(h);
}
const shotEnd = replay.shots.map(([st, pl, x, y, z, yaw, pitch]) => {
const h = hitsByShooter.get(pl)?.find((q) => Math.abs(q[0] - st) <= 40);
if (h) return [h[6], h[7], h[8]];
const yr = (yaw * Math.PI) / 180;
const pr = (signed(pitch) * Math.PI) / 180;
return [x + Math.cos(pr) * Math.cos(yr) * 5000, y + Math.cos(pr) * Math.sin(yr) * 5000, z + Math.sin(pr) * 5000];
});
// 맞은 자리 튀는 것 (사람이면 붉게, 0.25초)
const sparkTex = (() => {
const c = document.createElement('canvas');
c.width = c.height = 32;
const g = c.getContext('2d')!;
const rg = g.createRadialGradient(16, 16, 0, 16, 16, 16);
rg.addColorStop(0, 'rgba(255,255,255,1)');
rg.addColorStop(1, 'rgba(255,255,255,0)');
g.fillStyle = rg;
g.fillRect(0, 0, 32, 32);
return new THREE.CanvasTexture(c);
})();
const sparks = Array.from({ length: 24 }, () => {
const sp = new THREE.Sprite(new THREE.SpriteMaterial({ map: sparkTex, transparent: true, depthWrite: false, blending: THREE.AdditiveBlending }));
sp.visible = false;
agentsGroup.add(sp);
return sp;
});
// 킬 표시 (죽은 자리 X)
const killGroup = new THREE.Group();
@@ -433,10 +450,28 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
}
obj.position.copy(toWorld(x, y, z, zBase));
scene.add(obj);
// 요루 분신: 요루 몸이 경로를 따라 달린다
if (/^Pawn_Stealth_4_Decoy/.test(replay.objectKinds[kind] ?? '')) {
const owner = replay.objects[i][6];
void Promise.all([loadAgent(replay.players[owner]?.character ?? 'Stealth_PC_C'), loadAnims()])
.then(([g, anims]) => {
if (!g || disposed) return;
const rig = new AgentRig(g, anims);
agentsGroup.add(rig.root);
const cur = objViews.get(i);
if (cur) {
cur.obj.children.forEach((c) => (c.visible = false));
cur.obj.userData.rig = rig;
}
})
.catch(() => {});
}
ov = { look, obj, mats, t0, end: t1 >= t0 ? t1 : t0 + look.defaultMs };
objViews.set(i, ov);
return ov;
};
// 움직이는 스킬 경로 (투사체 · 드론 · 분신): objects 번호 → 경로
const pathOf = new Map((replay.objectPaths ?? []).map((p) => [p.o, p]));
const setOpacity = (ov: ObjView, k: number) => {
for (const m of ov.mats) {
const base = (m.userData.baseOpacity ??= m.opacity) as number;
@@ -555,7 +590,8 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
const tr = replay.players[v.idx].track;
const p = samplePlayer(tr, t, replay.sampleMs * 6);
if (!p) {
v.group.visible = v.drop.visible = v.shadow.visible = false;
v.group.visible = v.drop.visible = v.shadow.visible = v.label.visible = v.voice.visible = false;
if (v.rig) v.rig.root.visible = false;
continue;
}
// 1인칭으로 보는 선수 자신은 숨긴다
@@ -574,28 +610,33 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
const op = dead ? 0.22 : 1;
(v.body.material as THREE.MeshStandardMaterial).opacity = op;
(v.cone.material as THREE.MeshStandardMaterial).opacity = dead ? 0 : 0.85;
v.label.material.opacity = dead ? 0.35 : 1;
(v.shadow.material as THREE.MeshBasicMaterial).opacity = dead ? 0.25 : 0.85;
v.voice.visible = speaking.has(v.idx) && !dead;
const kind = dead ? -1 : equipAt(equipByPlayer[v.idx], t);
setWeapon(v, kind);
v.weapon.material.opacity = v.label.material.opacity;
// 이름표: 머리 위 (위에서 볼 때는 몸을 키운 만큼 위로). 죽으면 숨김, 1인칭으로 보는 선수 자신도 숨김
const scaleBody = v.rig && !real ? TOP_MODEL_SCALE : 1;
v.label.position.copy(toWorld(p.x, p.y, Math.max(p.z, zBase - 400) - FOOT_CM + (v.rig ? 195 * scaleBody : 260), zBase));
v.label.visible = v.group.visible && !dead;
v.voice.position.copy(v.label.position);
v.voice.center.set(0.5, -1.05);
v.voice.visible = v.label.visible && speaking.has(v.idx);
if (v.rig) {
// 몸이 있으면 원기둥 대신. 죽으면 몸을 숨긴다 (죽은 자리는 X 표시)
// 몸이 있으면 원기둥 대신. 죽으면 사망 모션 끝 자세로 라운드 끝까지 누워 있다
v.body.visible = v.cone.visible = false;
const rr = v.rig.root;
rr.visible = v.group.visible && !dead;
rr.visible = v.group.visible;
rr.position.set(p.x, p.y, Math.max(p.z, zBase - 400) - FOOT_CM);
rr.rotation.set(0, 0, (p.yaw * Math.PI) / 180);
rr.scale.setScalar(real ? 1 : TOP_MODEL_SCALE);
rr.scale.setScalar(scaleBody);
if (rr.visible) {
const q = samplePlayer(tr, t - 150, replay.sampleMs * 6);
const vx = q ? ((p.x - q.x) * 1000) / 150 : 0;
const vy = q ? ((p.y - q.y) * 1000) / 150 : 0;
const vx = q && !dead ? ((p.x - q.x) * 1000) / 150 : 0;
const vy = q && !dead ? ((p.y - q.y) * 1000) / 150 : 0;
const a = (p.yaw * Math.PI) / 180;
const ek = replay.equipKinds?.[kind];
v.rig.setWeapon(ek && !/^Ability_|Unarmed|Bomb_Defuser/.test(ek) ? ek : null);
v.rig.update(dtR, vx * Math.cos(a) + vy * Math.sin(a), -vx * Math.sin(a) + vy * Math.cos(a), p.pitch);
v.rig.setWeapon(isGun(ek) ? ek : null);
const inp = rigInput(replay, animIx, v.idx, t, { dt: dtR, fwd: vx * Math.cos(a) + vy * Math.sin(a), right: -vx * Math.sin(a) + vy * Math.cos(a), pitch: p.pitch });
v.rig.setShot(inp.shotMs);
v.rig.update(inp);
}
} else {
v.body.visible = true;
@@ -638,25 +679,41 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
camera.position.add(tmp);
}
} else trail.visible = false;
// 사격
// 총알 궤적: 날아가는 짧은 빛줄기 (쏜 뒤 TRACER_MS 동안 끝점까지)
const sp = shotGeo.getAttribute('position') as THREE.BufferAttribute;
let ns = 0;
for (let i = lowerBound(replay.shots, t - 150); i < replay.shots.length && replay.shots[i][0] <= t && ns < MAX_SHOTS; i++) {
const [, , x, y, z, yaw, pitch] = replay.shots[i];
const a = toWorld(x, y, z, zBase);
const d = dirOf(yaw);
const len = 26;
const b = a.clone().add(d.multiplyScalar(len * Math.cos((pitch * Math.PI) / 180))).add(new THREE.Vector3(0, len * Math.sin((pitch * Math.PI) / 180) * 0.3, 0));
sp.setXYZ(ns * 2, a.x, a.y + 1.6, a.z);
sp.setXYZ(ns * 2 + 1, b.x, b.y + 1.6, b.z);
for (let i = lowerBound(replay.shots, t - TRACER_MS); i < replay.shots.length && replay.shots[i][0] <= t && ns < MAX_SHOTS; i++) {
const [st, , x, y, z] = replay.shots[i];
const e = shotEnd[i];
const k = (t - st) / TRACER_MS;
const k0 = Math.max(0, k - 0.35);
const k1 = Math.min(1, k + 0.05);
// 눈높이에서 쏜 기록 → 총구는 조금 아래
const zz = z - 12;
sp.setXYZ(ns * 2, x + (e[0] - x) * k0, y + (e[1] - y) * k0, zz + (e[2] - zz) * k0);
sp.setXYZ(ns * 2 + 1, x + (e[0] - x) * k1, y + (e[1] - y) * k1, zz + (e[2] - zz) * k1);
ns++;
}
shotGeo.setDrawRange(0, ns * 2);
sp.needsUpdate = true;
let nk = 0;
const hits = replay.hits ?? [];
for (let i = lowerBound(hits as [number, ...number[]][], t - 250); i < hits.length && hits[i][0] <= t && nk < sparks.length; i++) {
const h = hits[i];
const k = (t - h[0]) / 250;
const s = sparks[nk++];
s.visible = true;
s.position.set(h[6], h[7], h[8]);
s.scale.setScalar((h[2] >= 0 ? 34 : 22) * (0.6 + k));
s.material.color.set(h[2] >= 0 ? (h[9] === 1 ? 0xff5040 : 0xc0201a) : 0xffe0a0);
s.material.opacity = 1 - k;
}
for (let i = nk; i < sparks.length; i++) sparks[i].visible = false;
// 킬 표시: 이 라운드에서 이미 난 킬
const rd = roundAt(replay, t);
for (const k of killMarks) {
const on = !!rd && k.t >= rd.buy && k.t <= t;
// 요원 몸이 있으면 죽은 몸(사망 모션)이 그 자리에 누워 있으므로 X 는 위에서 볼 때만
const on = !!rd && k.t >= rd.buy && k.t <= t && (!views[k.victim]?.rig || mode === 'top');
k.mk.visible = on;
if (on) {
const age = t - k.t;
@@ -674,11 +731,27 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
if (ov0) {
ov0.obj.visible = false;
if (ov0.obj.userData.model) (ov0.obj.userData.model as THREE.Object3D).visible = false;
if (ov0.obj.userData.rig) (ov0.obj.userData.rig as AgentRig).root.visible = false;
}
continue;
}
const ov = objView(i);
const age = t - t0;
const path = pathOf.get(i);
const pp = path ? samplePath(path, Math.min(t, path.t[path.t.length - 1])) : null;
if (pp) ov.obj.position.copy(toWorld(pp.x, pp.y, pp.z, zBase));
const decoy = ov.obj.userData.rig as AgentRig | undefined;
if (decoy) {
decoy.root.visible = true;
if (pp) {
const yaw = ((pp.yaw ?? 0) * Math.PI) / 180;
decoy.root.position.set(pp.x, pp.y, pp.z - FOOT_CM);
decoy.root.rotation.set(0, 0, yaw);
decoy.root.scale.setScalar(real ? 1 : TOP_MODEL_SCALE);
decoy.update({ dt: dtR, fwd: pp.vx * Math.cos(yaw) + pp.vy * Math.sin(yaw), right: -pp.vx * Math.sin(yaw) + pp.vy * Math.cos(yaw), pitch: 0, crouch: false, airMs: null, landMs: null, cat: 'ability', overlay: null, death: null });
}
continue;
}
const left = ov.end - t;
ov.obj.visible = true;
const model = ov.obj.userData.model as THREE.Object3D | undefined;
@@ -706,7 +779,8 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
break;
}
case 'projectile':
ov.obj.visible = age < 400;
// 경로가 있으면 부딪힐 때까지 따라 날아간다 (옛 리플레이는 던진 자리에 잠깐)
ov.obj.visible = path ? true : age < 400;
ov.obj.scale.setScalar(big);
break;
default:
@@ -924,6 +998,12 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
);
}
/** 게임 각도(0~360) → -180~180 */
function signed(a: number) {
const v = ((a % 360) + 360) % 360;
return v > 180 ? v - 360 : v;
}
function lowerBound(a: [number, ...number[]][], t: number) {
let lo = 0;
let hi = a.length;