3D 리플레이: 요원 3D 몸(뼈대 · 텍스처 · 공용 걷기/달리기 + 총 든 자세) · 총 22종 추출, 재생기가 원기둥 대신 요원과 손에 든 총을 그림
- map-extract agents: 요원 30명 agent_<코드>.glb (위/아래 몸 애니메이션 분리, ACL 풀기용 CUE4Parse-Natives 를 g++ 로 빌드), 무기 weapon_<이름>.glb - pack.py: 요원 · 무기도 압축해 index.json agents · weapons - 사이트: AgentRig (이동 방향 · 속도로 다리 애니메이션 섞기, 오른손에 총), 1인칭 · 자유시점에서 이름표 작게 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ 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 { findMap3d, loadMap3d, mapMaterial, worldMatrix } from '../lib/map3d';
|
||||
import { AgentRig, loadAgent } from '../lib/agents3d';
|
||||
|
||||
/**
|
||||
* 3D 리플레이 (발로란트 .vrf → tools/replay-extract → gvr-replay JSON).
|
||||
@@ -28,8 +29,11 @@ const CEIL_ABOVE = 380;
|
||||
/** 리플레이 선수 위치(캡슐 중심)에서 눈 · 발까지 (cm) */
|
||||
const EYE_CM = 60;
|
||||
const FOOT_CM = 90;
|
||||
/** 1인칭 · 자유시점에서는 선수 표시를 실제 크기 가깝게 줄인다 */
|
||||
const REAL_SCALE = 0.5;
|
||||
/** 1인칭 · 자유시점에서는 선수 표시(이름표 · 원기둥)를 줄이고 머리 위(이 높이, cm)로 올린다 */
|
||||
const REAL_SCALE = 0.2;
|
||||
const REAL_LABEL_CM = 190;
|
||||
/** 위에서 볼 때 요원 몸을 이만큼 키운다 (맵 전체를 볼 때도 보이게) */
|
||||
const TOP_MODEL_SCALE = 1.8;
|
||||
|
||||
/** 카메라: 위에서 보기(돌리기) · 1인칭(고른 선수 눈) · 자유시점(WASD) */
|
||||
type CamMode = 'top' | 'fp' | 'free';
|
||||
@@ -93,6 +97,8 @@ interface PlayerView {
|
||||
/** 바닥(미니맵)까지 내린 선과 그림자 점: 높이가 있어도 평면 위치가 보이게 */
|
||||
drop: THREE.Line;
|
||||
shadow: THREE.Mesh;
|
||||
/** 요원 3D 몸 (게임 파일에서 뽑은 것, 받기 전 · 없으면 null → 원기둥) */
|
||||
rig: AgentRig | null;
|
||||
}
|
||||
|
||||
export default function ReplayViewer({ m, replay, sync }: Props) {
|
||||
@@ -269,9 +275,28 @@ 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 };
|
||||
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 };
|
||||
});
|
||||
|
||||
// 요원 3D 몸: UE 좌표(cm) 그대로 두고 맵과 같은 행렬로 옮긴다
|
||||
const agentsGroup = new THREE.Group();
|
||||
agentsGroup.matrixAutoUpdate = false;
|
||||
agentsGroup.matrix.copy(worldMatrix(T, S, zBase, VEX));
|
||||
scene.add(agentsGroup);
|
||||
for (const v of views) {
|
||||
const cls = replay.players[v.idx].character;
|
||||
if (!cls) continue;
|
||||
void loadAgent(cls)
|
||||
.then((g) => {
|
||||
if (!g || disposed) return;
|
||||
v.rig = new AgentRig(g);
|
||||
agentsGroup.add(v.rig.root);
|
||||
agentsGroup.updateMatrixWorld(true);
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
let prevT = localT.current;
|
||||
|
||||
// 총 이름표 (같은 글자는 텍스처 하나)
|
||||
const weaponTex = new Map<string, { tex: THREE.Texture; aspect: number }>();
|
||||
const setWeapon = (v: PlayerView, kind: number) => {
|
||||
@@ -403,6 +428,8 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
|
||||
renderer.domElement.addEventListener('keyup', onKey);
|
||||
renderer.domElement.addEventListener('blur', onBlur);
|
||||
|
||||
// 개발 확인용 (목 서버 스크린샷 스크립트가 카메라를 옮긴다)
|
||||
if (import.meta.env.DEV) (window as unknown as { __r3d: unknown }).__r3d = { camera, controls, views, scene, free };
|
||||
let raf = 0;
|
||||
let lastUi = 0;
|
||||
let lastNow = 0;
|
||||
@@ -436,6 +463,9 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
|
||||
const t = inScene ? ps.sceneTs! - base : localT.current;
|
||||
if (!inScene) localT.current = t;
|
||||
const ts = base + t;
|
||||
// 리플레이 시간 흐름 (애니메이션용, 시간을 크게 옮기면 0)
|
||||
const dtR = t - prevT >= 0 && t - prevT < 1000 ? (t - prevT) / 1000 : 0;
|
||||
prevT = t;
|
||||
// 지금 말하는 사람
|
||||
const speaking = new Set<number>();
|
||||
for (const u of m.utterances) if (u.ts <= ts && ts <= u.endTs && !u.noise) {
|
||||
@@ -453,7 +483,7 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
|
||||
// 1인칭으로 보는 선수 자신은 숨긴다
|
||||
v.group.visible = !(mode === 'fp' && v.idx === selRef.current);
|
||||
v.drop.visible = v.shadow.visible = !mapReady && !real;
|
||||
v.group.position.copy(toWorld(p.x, p.y, Math.max(p.z, zBase - 400) - (real ? FOOT_CM : 0), zBase));
|
||||
v.group.position.copy(toWorld(p.x, p.y, Math.max(p.z, zBase - 400) + (real ? REAL_LABEL_CM - FOOT_CM : 0), zBase));
|
||||
v.group.scale.setScalar(real ? REAL_SCALE : 1);
|
||||
v.shadow.position.set(v.group.position.x, 0.04, v.group.position.z);
|
||||
const dp = v.drop.geometry.getAttribute('position') as THREE.BufferAttribute;
|
||||
@@ -469,8 +499,30 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
|
||||
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;
|
||||
setWeapon(v, dead ? -1 : equipAt(equipByPlayer[v.idx], t));
|
||||
const kind = dead ? -1 : equipAt(equipByPlayer[v.idx], t);
|
||||
setWeapon(v, kind);
|
||||
v.weapon.material.opacity = v.label.material.opacity;
|
||||
if (v.rig) {
|
||||
// 몸이 있으면 원기둥 대신. 죽으면 몸을 숨긴다 (죽은 자리는 X 표시)
|
||||
v.body.visible = v.cone.visible = false;
|
||||
const rr = v.rig.root;
|
||||
rr.visible = v.group.visible && !dead;
|
||||
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);
|
||||
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 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);
|
||||
}
|
||||
} else {
|
||||
v.body.visible = true;
|
||||
v.cone.visible = true;
|
||||
}
|
||||
v.ring.visible = v.idx === selIdx;
|
||||
}
|
||||
// 천장 자르기
|
||||
@@ -531,7 +583,7 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
|
||||
if (on) {
|
||||
const age = t - k.t;
|
||||
const s = age < 600 ? 1 + (600 - age) / 300 : 1;
|
||||
k.mk.scale.setScalar(s);
|
||||
k.mk.scale.setScalar(s * (real ? 0.25 : 1));
|
||||
}
|
||||
}
|
||||
// 스킬 · 설치물: 생긴 뒤 사라질 때까지 (사라진 시각을 모르면 12초)
|
||||
@@ -585,6 +637,7 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
|
||||
renderer.domElement.removeEventListener('keyup', onKey);
|
||||
renderer.domElement.removeEventListener('blur', onBlur);
|
||||
controls.dispose();
|
||||
for (const v of views) v.rig?.dispose();
|
||||
scene.traverse((o) => {
|
||||
const mesh = o as THREE.Mesh;
|
||||
mesh.geometry?.dispose?.();
|
||||
|
||||
147
site/web/src/lib/agents3d.ts
Normal file
147
site/web/src/lib/agents3d.ts
Normal file
@@ -0,0 +1,147 @@
|
||||
import * as THREE from 'three';
|
||||
import { GLTFLoader, type GLTF } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
||||
import { MeshoptDecoder } from 'three/examples/jsm/libs/meshopt_decoder.module.js';
|
||||
import { clone as cloneSkinned } from 'three/examples/jsm/utils/SkeletonUtils.js';
|
||||
import { loadIndex } from './map3d';
|
||||
|
||||
/**
|
||||
* 요원 3D 몸 · 총 (tools/map-extract agents → 사이트 서버 /site/maps3d, 맵과 같은 폴더).
|
||||
* 좌표는 게임(UE) 그대로: cm, 발 = 원점 근처, 앞 = +X (애니메이션의 Root 회전 포함).
|
||||
* 몸 애니메이션은 위(ub_rifle, 총 든 자세)와 아래(lb_idle · lb_run* · lb_walk*)를 따로 섞는다.
|
||||
*/
|
||||
const cache = new Map<string, Promise<GLTF>>();
|
||||
|
||||
function load(url: string): Promise<GLTF> {
|
||||
let p = cache.get(url);
|
||||
if (!p) {
|
||||
const loader = new GLTFLoader();
|
||||
loader.setMeshoptDecoder(MeshoptDecoder);
|
||||
p = loader.loadAsync(url);
|
||||
p.catch(() => cache.delete(url)); // 실패하면 다음에 다시
|
||||
cache.set(url, p);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
function url(dir: string, file: string) {
|
||||
return `/site/maps3d/${encodeURIComponent(dir)}/${encodeURIComponent(file)}`;
|
||||
}
|
||||
|
||||
/** 리플레이 캐릭터 클래스(Wushu_PC_C)의 몸. 없으면 null */
|
||||
export async function loadAgent(characterClass: string): Promise<GLTF | null> {
|
||||
const idx = await loadIndex();
|
||||
const a = idx?.dir ? idx.agents?.[characterClass] : undefined;
|
||||
return a && idx?.dir ? load(url(idx.dir, a.file)) : null;
|
||||
}
|
||||
|
||||
/** 총 (리플레이 equipKinds 이름: Vandal · Classic · Melee …). 없으면 null */
|
||||
export async function loadWeapon(name: string): Promise<GLTF | null> {
|
||||
const idx = await loadIndex();
|
||||
const w = idx?.dir ? idx.weapons?.[name] : undefined;
|
||||
return w && idx?.dir ? load(url(idx.dir, w.file)) : null;
|
||||
}
|
||||
|
||||
const LOWER = ['lb_idle', 'lb_runN', 'lb_runS', 'lb_runE', 'lb_runW', 'lb_walkN', 'lb_walkS', 'lb_walkE', 'lb_walkW'] as const;
|
||||
type Lower = (typeof LOWER)[number];
|
||||
/** 애니메이션이 만든 속도 (cm/s): 이보다 빠르면 빨리 돌린다 */
|
||||
const RUN_CM_S = 540;
|
||||
const WALK_CM_S = 300;
|
||||
|
||||
/** 선수 한 명의 몸 (복제본) · 애니메이션 · 손에 든 총 */
|
||||
export class AgentRig {
|
||||
/** UE 좌표(cm) 공간의 선수 자리. 뷰어가 위치 · yaw 를 넣는다 */
|
||||
readonly root = new THREE.Group();
|
||||
private readonly model: THREE.Object3D;
|
||||
private readonly mixer: THREE.AnimationMixer;
|
||||
private readonly lower = new Map<Lower, THREE.AnimationAction>();
|
||||
private readonly hand: THREE.Object3D | null;
|
||||
private readonly gunSlot = new THREE.Group();
|
||||
private gunName: string | null = null;
|
||||
private gunReq = 0;
|
||||
private readonly tmp = new THREE.Vector3();
|
||||
|
||||
constructor(gltf: GLTF) {
|
||||
this.model = cloneSkinned(gltf.scene);
|
||||
this.model.traverse((o) => {
|
||||
const m = o as THREE.Mesh;
|
||||
if (m.isMesh) m.frustumCulled = false;
|
||||
});
|
||||
this.root.add(this.model);
|
||||
this.root.add(this.gunSlot);
|
||||
this.mixer = new THREE.AnimationMixer(this.model);
|
||||
const clip = (n: string) => gltf.animations.find((a) => a.name === n);
|
||||
const ub = clip('ub_rifle');
|
||||
if (ub) this.mixer.clipAction(ub).play();
|
||||
for (const n of LOWER) {
|
||||
const c = clip(n);
|
||||
if (!c) continue;
|
||||
const a = this.mixer.clipAction(c);
|
||||
a.play();
|
||||
a.setEffectiveWeight(n === 'lb_idle' ? 1 : 0);
|
||||
this.lower.set(n, a);
|
||||
}
|
||||
// R_WeaponPoint 는 공용 애니메이션이 움직이지 않아 손에서 떨어져 있다 → 손목(R_Hand) 기준
|
||||
this.hand = this.model.getObjectByName('R_Hand') ?? null;
|
||||
}
|
||||
|
||||
/** 들고 있는 총 바꾸기 (이름 없으면 맨손) */
|
||||
setWeapon(name: string | null) {
|
||||
if (name === this.gunName) return;
|
||||
this.gunName = name;
|
||||
const req = ++this.gunReq;
|
||||
this.gunSlot.clear();
|
||||
if (!name) return;
|
||||
void loadWeapon(name)
|
||||
.then((g) => {
|
||||
if (!g || req !== this.gunReq) return;
|
||||
const gun = g.scene.clone(true);
|
||||
gun.traverse((o) => {
|
||||
const m = o as THREE.Mesh;
|
||||
if (m.isMesh) m.frustumCulled = false;
|
||||
});
|
||||
gun.position.x = 7; // 손목 → 손바닥 (총 원점 = 손잡이)
|
||||
if (name === 'Melee') gun.rotation.y = Math.PI / 2; // 칼은 날이 +Z → 앞(+X)으로
|
||||
this.gunSlot.add(gun);
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
/**
|
||||
* 애니메이션 진행. dt: 리플레이 시간(초), fwd · right: 몸 기준 이동 속도(cm/s, UE: 앞 +X · 오른쪽 +Y), pitch: 위아래 보는 각(도)
|
||||
*/
|
||||
update(dt: number, fwd: number, right: number, pitch: number) {
|
||||
const speed = Math.hypot(fwd, right);
|
||||
const moving = THREE.MathUtils.smoothstep(speed, 40, 140);
|
||||
const run = speed > 400;
|
||||
const sum = Math.abs(fwd) + Math.abs(right) || 1;
|
||||
const w: Record<Lower, number> = {
|
||||
lb_idle: 1 - moving,
|
||||
lb_runN: 0, lb_runS: 0, lb_runE: 0, lb_runW: 0,
|
||||
lb_walkN: 0, lb_walkS: 0, lb_walkE: 0, lb_walkW: 0,
|
||||
};
|
||||
const g = run ? 'lb_run' : 'lb_walk';
|
||||
w[`${g}N` as Lower] = (moving * Math.max(0, fwd)) / sum;
|
||||
w[`${g}S` as Lower] = (moving * Math.max(0, -fwd)) / sum;
|
||||
w[`${g}E` as Lower] = (moving * Math.max(0, right)) / sum;
|
||||
w[`${g}W` as Lower] = (moving * Math.max(0, -right)) / sum;
|
||||
const scale = THREE.MathUtils.clamp(speed / (run ? RUN_CM_S : WALK_CM_S), 0.6, 1.5);
|
||||
for (const [n, a] of this.lower) {
|
||||
a.setEffectiveWeight(w[n]);
|
||||
a.setEffectiveTimeScale(n === 'lb_idle' ? 1 : scale);
|
||||
}
|
||||
this.mixer.update(dt);
|
||||
// 총: 오른손 자리에, 몸 앞(+X)을 보는 방향 + 위아래 각
|
||||
if (this.hand && this.gunSlot.children.length) {
|
||||
this.root.updateWorldMatrix(true, true);
|
||||
this.hand.getWorldPosition(this.tmp);
|
||||
this.root.worldToLocal(this.tmp);
|
||||
this.gunSlot.position.copy(this.tmp);
|
||||
this.gunSlot.rotation.set(0, (-THREE.MathUtils.clamp(pitch, -80, 80) * Math.PI) / 180, 0);
|
||||
}
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.mixer.stopAllAction();
|
||||
this.gunSlot.clear();
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,13 @@ interface Index {
|
||||
dir: string | null;
|
||||
version: string | null;
|
||||
maps: Record<string, { code: string; file: string; bytes: number; triangles: number }>;
|
||||
/** 요원 몸 (리플레이 캐릭터 클래스 → glb), 무기 (equipKinds 이름 → glb). 옛 index 에는 없다 */
|
||||
agents?: Record<string, { code: string; file: string; bytes: number }>;
|
||||
weapons?: Record<string, { file: string; bytes: number }>;
|
||||
}
|
||||
|
||||
let indexP: Promise<Index | null> | null = null;
|
||||
function loadIndex(): Promise<Index | null> {
|
||||
export function loadIndex(): Promise<Index | null> {
|
||||
indexP ??= fetch('/site/maps3d', { credentials: 'same-origin' })
|
||||
.then((r) => (r.ok ? (r.json() as Promise<Index>) : null))
|
||||
.catch(() => null)
|
||||
|
||||
Reference in New Issue
Block a user