3D 리플레이 무기 스킨: 뽑아 둔 스킨이면 3인칭 손의 총 · 1인칭 총을 그 모델로 (없거나 못 받으면 기본 총), 없는 스킨은 POST /site/maps3d/skins/want 로 요청 (기본 스킨 · 실패한 것 제외) · 서버 GET /site/maps3d/skins · want.json (형식 검사 · 중복 제거 · 다른 사이트 요청 막음 · 최대 2000) · 목 서버 · 테스트

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-20 22:28:13 +09:00
parent 0da993928e
commit 200dbceece
10 changed files with 294 additions and 18 deletions

View File

@@ -6,7 +6,8 @@ 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, indexAt, isDead, roundAt, samplePath, samplePlayer, type ReplayFile, type ReplaySync } from '../lib/replay';
import { equipAt, equipLabel, equipTracks, indexAt, isDead, roundAt, samplePath, samplePlayer, skinTracks, type ReplayFile, type ReplaySync } from '../lib/replay';
import { loadSkins, lookOf, requestMissing } from '../lib/skins';
import { findMap3d, loadMap3d, mapMaterial, worldMatrix } from '../lib/map3d';
import { AgentRig, isGun, loadAgent, loadAnims, loadWeapon, weaponCat } from '../lib/agents3d';
import { Viewmodel, viewmodelIndex } from '../lib/viewmodel';
@@ -386,6 +387,19 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
});
let vmOn = false;
let scopedNow = false;
// 무기 스킨: 뽑아 둔 것만 그 스킨으로, 없는 것은 뽑아 달라고 요청한다 (다음에 열면 보인다)
const skinByPlayer = skinTracks(replay);
let skinIdx: Awaited<ReturnType<typeof loadSkins>> = null;
if (replay.skins?.length) {
void loadSkins().then((ix) => {
if (!disposed) skinIdx = ix;
});
void requestMissing(replay);
}
const skinLookAt = (p: number, t: number) => {
const s = equipAt(skinByPlayer[p], t);
return s >= 0 ? lookOf(skinIdx, replay.skins?.[s]) : null;
};
// 선택한 선수 이동 경로 (최근 6초)
const trailGeo = new THREE.BufferGeometry();
@@ -821,7 +835,7 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
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(isGun(ek) ? ek : null);
v.rig.setWeapon(isGun(ek) ? ek : null, isGun(ek) ? skinLookAt(v.idx, t) : 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);
@@ -1022,7 +1036,7 @@ export default function ReplayViewer({ m, replay, sync }: Props) {
const chr = replay.players[selIdx].character;
vmOn = !!fp && !sc && !!vm && vm.has(chr, fp.kind);
if (vmOn && vm && chr && fp) {
vm.set(chr, fp.kind!);
vm.set(chr, fp.kind!, skinLookAt(selIdx, t));
vm.pose(fp.input);
}
// 조준점: 선수 조준점(설정에 따라) 또는 내 조준점. 저격총 줌은 조준경 가운데 점, 정조준은 정조준 조준점

View File

@@ -3,6 +3,7 @@ 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';
import { skinFileUrl, type SkinLook } from './skins';
/**
* 요원 3D 몸 · 총 (tools/map-extract agents → 사이트 서버 /site/maps3d, 맵과 같은 폴더).
@@ -37,8 +38,12 @@ export async function loadAgent(characterClass: string): Promise<GLTF | null> {
return a && idx?.dir ? load(assetUrl(idx.dir, a.file)) : null;
}
/** 총 (리플레이 equipKinds 이름: Vandal · Classic · Melee …). 없으면 null */
export async function loadWeapon(name: string): Promise<GLTF | null> {
/** 총 (리플레이 equipKinds 이름: Vandal · Classic · Melee …). 스킨 3인칭 모델이 있으면 그것 (받지 못하면 기본 스킨). 없으면 null */
export async function loadWeapon(name: string, skin?: SkinLook | null): Promise<GLTF | null> {
if (skin?.w3p) {
const g = await load(skinFileUrl(skin.w3p)).catch(() => null);
if (g) return g;
}
const idx = await loadIndex();
const w = idx?.dir ? idx.weapons?.[name] : undefined;
return w && idx?.dir ? load(assetUrl(idx.dir, w.file)) : null;
@@ -161,6 +166,7 @@ export class AgentRig {
/** 총구 불꽃 (사격 순간에 잠깐) */
readonly muzzle: THREE.Sprite;
private gunName: string | null = null;
private gunSkin: SkinLook | null = null;
private gunReq = 0;
private gunTip = 60;
private readonly tmp = new THREE.Vector3();
@@ -198,14 +204,15 @@ export class AgentRig {
return a;
}
/** 들고 있는 총 바꾸기 (이름 없으면 맨손) */
setWeapon(name: string | null) {
if (name === this.gunName) return;
/** 들고 있는 총 바꾸기 (이름 없으면 맨손, 스킨 모습이 있으면 그 스킨) */
setWeapon(name: string | null, skin?: SkinLook | null) {
if (name === this.gunName && (skin ?? null) === this.gunSkin) return;
this.gunName = name;
this.gunSkin = skin ?? null;
const req = ++this.gunReq;
for (const c of [...this.gunSlot.children]) if (c !== this.muzzle) this.gunSlot.remove(c);
if (!name) return;
void loadWeapon(name)
void loadWeapon(name, skin)
.then((g) => {
if (!g || req !== this.gunReq) return;
const gun = g.scene.clone(true);

View File

@@ -45,13 +45,24 @@ export interface ReplayFile {
/** 이어지는 동작 [t0, t1, player, actionKind] (Plant · Defuse · Rope) */
actions?: [number, number, number, number][];
actionKinds?: string[];
/** 들고 있는 것이 바뀐 시각 [t, player, kind] (변환기 새 버전부터. 옛 리플레이 JSON 에는 없다) */
equips?: [number, number, number][];
/** 들고 있는 것이 바뀐 시각 [t, player, kind, skin] (변환기 새 버전부터. 옛 리플레이 JSON 에는 없다. skin = skins 번호 · 모르면 -1, 변환기 1.10.0~) */
equips?: [number, number, number, number?][];
equipKinds?: string[];
/** 무기 스킨 (게임 데이터 에셋 경로). 줍거나 떨어뜨려도 그 총의 스킨은 처음 주인 것 (변환기 1.10.0~) */
skins?: SkinInfo[];
/** 점수판 (게임 Tab): 선수 값이 바뀔 때마다 [t, player, 크레딧, 궁극기 점수, 킬, 데스, 어시스트, 전투 점수] (모르는 값 -1, 변환기 1.10.0~) */
scoreboard?: number[][];
}
/** 무기 스킨: 스킨 · 단계 · 색상 · 총 장식 (예: /Game/Equippables/Guns/Rifles/AK/HypeBeast/AssaultRifle_AK_HypeBeast_PrimaryAsset) */
export interface SkinInfo {
skin: string;
level: string | null;
chroma: string | null;
charm?: string | null;
charmLevel?: string | null;
}
export interface ObjectPath {
o: number;
t: number[];
@@ -145,6 +156,13 @@ export function equipTracks(r: ReplayFile): [number, number][][] {
return out;
}
/** 선수별 [t, skin] 목록 (equipTracks 와 같은 시각, equipAt 으로 찾는다. 스킨 기록이 없으면 -1) */
export function skinTracks(r: ReplayFile): [number, number][][] {
const out: [number, number][][] = r.players.map(() => []);
for (const [t, p, , s] of r.equips ?? []) out[p]?.push([t, s ?? -1]);
return out;
}
/** t 시점에 들고 있던 것 (kind 번호, 없으면 -1) */
export function equipAt(track: [number, number][] | undefined, t: number): number {
if (!track?.length || t < track[0][0]) return -1;

72
site/web/src/lib/skins.ts Normal file
View File

@@ -0,0 +1,72 @@
import type { ReplayFile, SkinInfo } from './replay';
/**
* 무기 스킨 3D (사이트 서버 /site/maps3d/skins, 로그인 필요).
* 리플레이 skins 의 스킨 · 단계 · 색상으로 찾는다. 아직 없는 스킨은 요청만 해 두고 기본 스킨으로 그린다
* (이 서버가 몇 분 안에 그 스킨만 뽑아 올리므로 다음에 열면 보인다, tools/map-extract/scripts/skins-update.sh).
* skins[열쇠] = {weapon, sig}, looks[sig] = {w3p(3인칭 glb), w1p(1인칭 glb, 총 동작 포함), …}. 파일은 /site/maps3d/skins/<파일>
*/
export interface SkinLook {
w3p?: string;
w1p?: string;
points?: Record<string, number[]>;
points1p?: Record<string, number[]>;
gunClips?: string[];
}
interface SkinsIndex {
skins: Record<string, { weapon: string; sig: string }>;
looks: Record<string, SkinLook>;
failed?: Record<string, string>;
}
export const skinKey = (s: SkinInfo) => `${s.skin}|${s.level ?? ''}|${s.chroma ?? ''}`;
/** 기본 스킨 (…_Standard_PrimaryAsset, 예: Melee_Base_Standard · Compact_Standard): 따로 뽑지 않고 기본 무기 모델을 쓴다 */
export const isDefaultSkin = (s: SkinInfo) => /_Standard_PrimaryAsset$/.test(s.skin);
export const skinFileUrl = (file: string) => `/site/maps3d/skins/${encodeURIComponent(file)}`;
let indexP: Promise<SkinsIndex | null> | null = null;
export function loadSkins(): Promise<SkinsIndex | null> {
indexP ??= fetch('/site/maps3d/skins', { credentials: 'same-origin' })
.then((r) => (r.ok ? (r.json() as Promise<SkinsIndex>) : null))
.catch(() => null)
.then((d) => {
if (!d) indexP = null;
return d;
});
return indexP;
}
/** 이 스킨의 모습 (없거나 기본 스킨이면 null) */
export function lookOf(idx: SkinsIndex | null, s: SkinInfo | undefined | null): SkinLook | null {
if (!idx || !s || isDefaultSkin(s)) return null;
const e = idx.skins[skinKey(s)];
return (e && idx.looks[e.sig]) || null;
}
/** 리플레이에 나온 스킨 중 아직 없는 것 (기본 스킨 · 실패한 것은 빼고) */
export function missingSkins(idx: SkinsIndex, r: Pick<ReplayFile, 'skins'>): string[] {
const out = new Set<string>();
for (const s of r.skins ?? []) {
if (isDefaultSkin(s)) continue;
const k = skinKey(s);
if (!idx.skins[k] && !idx.failed?.[k]) out.add(k);
}
return [...out];
}
/** 없는 스킨을 뽑아 달라고 요청한다 (한 번에 100개까지, 실패해도 그냥 기본 스킨) */
export async function requestMissing(r: Pick<ReplayFile, 'skins'>): Promise<number> {
const idx = await loadSkins();
if (!idx) return 0;
const keys = missingSkins(idx, r).slice(0, 100);
if (!keys.length) return 0;
const res = await fetch('/site/maps3d/skins/want', {
method: 'POST',
credentials: 'same-origin',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ keys }),
}).catch(() => null);
return res?.ok ? (((await res.json()) as { queued?: number }).queued ?? 0) : 0;
}

View File

@@ -4,6 +4,7 @@ import { MeshoptDecoder } from 'three/examples/jsm/libs/meshopt_decoder.module.j
import { clone as cloneSkinned } from 'three/examples/jsm/utils/SkeletonUtils.js';
import { assetUrl } from './agents3d';
import { loadIndex } from './map3d';
import { skinFileUrl, type SkinLook } from './skins';
/**
* 1인칭 화면 팔 · 총 (tools/map-extract viewmodels → index.json viewmodels).
@@ -120,16 +121,17 @@ export class Viewmodel {
return !!character && !!weapon && !!this.idx.arms[character] && !!this.idx.weapons[weapon];
}
/** 요원 · 무기를 바꾼다 (같으면 그대로). 받는 동안은 이전 모델을 그린다 */
set(character: string, weapon: string) {
const key = `${character}|${weapon}`;
/** 요원 · 무기(· 스킨)를 바꾼다 (같으면 그대로). 받는 동안은 이전 모델을 그린다. 스킨 1인칭 모델을 받지 못하면 기본 스킨 */
set(character: string, weapon: string, skin?: SkinLook | null) {
const key = `${character}|${weapon}|${skin?.w1p ?? ''}`;
if (key === this.want) return;
this.want = key;
const a = this.idx.arms[character];
const w = this.idx.weapons[weapon];
if (!a || !w) return;
const url = (f: string) => assetUrl(this.idx.dir, f);
void Promise.all([load(url(a.file)), load(url(w.file)), load(url(w.anim))])
const gun = skin?.w1p ? load(skinFileUrl(skin.w1p)).catch(() => load(url(w.file))) : load(url(w.file));
void Promise.all([load(url(a.file)), gun, load(url(w.anim))])
.then(([ag, wg, an]) => {
if (this.disposed || this.want !== key) return;
this.build(ag, wg, an);