- 추출기: 레벨 BuiltData 의 HQ 라이트맵을 메시 칸마다 풀어 irr · sh 아틀라스 두 장으로 (src/Lightmaps.cs), 조명 있는 배치는 LOD0 + 라이트맵 UV(TEXCOORD_1), ISM 은 인스턴스마다 칸 - glb: 재질 occlusionTexture(irr) · emissiveTexture(sh, 세기 0) · extras.lightmap.k. pack.py 는 맵 UV 를 실수로(-vtf, gltfpack 이 두 UV 채널을 한 범위로 양자화해서 라이트맵이 어긋나던 것) - 사이트 map3d.ts: 색 = 텍스처 × irr × K × max(0, 1 + dot(sh, N.yzx)). 옛 glb 는 그대로 - install.sh: 꺼 둔 자동 갱신 타이머는 다시 켜지 않는다 - 조사 명령 lmprobe · 작업 노트 docs/dev/replay-3d.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
4.8 KiB
C#
77 lines
4.8 KiB
C#
using SixLabors.ImageSharp;
|
|
using CUE4Parse.FileProvider;
|
|
using CUE4Parse.UE4.Assets.Exports;
|
|
using CUE4Parse.UE4.Assets.Exports.BuildData;
|
|
using CUE4Parse.UE4.Assets.Exports.Component.StaticMesh;
|
|
using CUE4Parse.UE4.Assets.Exports.StaticMesh;
|
|
using CUE4Parse.UE4.Assets.Exports.Texture;
|
|
|
|
namespace GvrMapExtract;
|
|
|
|
/// <summary>조사용: 레벨 BuiltData 의 라이트맵</summary>
|
|
public static class ProbeLight
|
|
{
|
|
public static void Run(IFileProvider provider, string umap)
|
|
{
|
|
var bd = umap[..^".umap".Length] + "_BuiltData.uasset";
|
|
var pkg = provider.LoadPackage(bd);
|
|
var reg = pkg.GetExports().OfType<UMapBuildDataRegistry>().FirstOrDefault();
|
|
Console.WriteLine($"{bd}: exports {string.Join(',', pkg.GetExports().GroupBy(e => e.ExportType).Select(g => g.Key + "x" + g.Count()))}");
|
|
if (reg == null) return;
|
|
Console.WriteLine($"mesh build data {reg.MeshBuildData?.Count} light {reg.LightBuildData?.Count} vlm {reg.LevelPrecomputedVolumetricLightmapBuildData?.Count}");
|
|
var dump = Environment.GetEnvironmentVariable("GVR_LM_DUMP");
|
|
foreach (var t in pkg.GetExports().OfType<UTexture2D>().Where(t => !t.Name.StartsWith("AOMaterial")))
|
|
{
|
|
Console.WriteLine($" tex {t.Name} {t.ExportType} {t.PlatformData?.SizeX}x{t.PlatformData?.SizeY} {t.Format} mips {t.PlatformData?.Mips?.Length} srgb {t.SRGB}");
|
|
if (dump == null) continue;
|
|
var c = CUE4Parse_Conversion.Textures.TextureDecoder.Decode(t);
|
|
if (c == null) { Console.WriteLine(" decode null"); continue; }
|
|
Console.WriteLine($" decoded {c.Width}x{c.Height} {c.PixelFormat} {c.Data.Length}");
|
|
Directory.CreateDirectory(dump);
|
|
var px = c.Data;
|
|
using var rgb = new SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgba32>(c.Width, c.Height);
|
|
using var a = new SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.L8>(c.Width, c.Height);
|
|
var bgra = c.PixelFormat == CUE4Parse.UE4.Assets.Exports.Texture.EPixelFormat.PF_B8G8R8A8;
|
|
for (var y = 0; y < c.Height; y++) for (var x = 0; x < c.Width; x++)
|
|
{
|
|
var i = (y * c.Width + x) * 4;
|
|
rgb[x, y] = bgra ? new(px[i + 2], px[i + 1], px[i], 255) : new(px[i], px[i + 1], px[i + 2], 255);
|
|
a[x, y] = new(px[i + 3]);
|
|
}
|
|
rgb.SaveAsPng(Path.Combine(dump, t.Name + ".rgb.png"));
|
|
a.SaveAsPng(Path.Combine(dump, t.Name + ".a.png"));
|
|
}
|
|
var n = 0;
|
|
foreach (var (g, d) in reg.MeshBuildData ?? new())
|
|
{
|
|
if (n++ >= 4) break;
|
|
if (d.LightMap is FLightMap2D lm)
|
|
Console.WriteLine($" {g}: tex {lm.Textures?[0]?.Name}/{lm.Textures?[1]?.Name} vt {lm.VirtualTextures?[0]?.Name} sky {lm.SkyOcclusionTexture?.Name} scale {string.Join(' ', lm.ScaleVectors!.Select(v => $"({v.X:F3},{v.Y:F3},{v.Z:F3},{v.W:F3})"))} add {string.Join(' ', lm.AddVectors!.Select(v => $"({v.X:F3},{v.Y:F3},{v.Z:F3},{v.W:F3})"))} cs {lm.CoordinateScale} cb {lm.CoordinateBias} inst {d.PerInstanceLightmapData.Length} shadow {d.ShadowMap?.GetType().Name}");
|
|
else Console.WriteLine($" {g}: lightmap {d.LightMap?.GetType().Name ?? "none"} inst {d.PerInstanceLightmapData.Length}");
|
|
}
|
|
// 레벨 컴포넌트 → 빌드 데이터 연결
|
|
var lvl = provider.LoadPackage(umap);
|
|
int comps = 0, hit = 0, ism = 0, ismHit = 0, lodMulti = 0;
|
|
foreach (var lazy in lvl.ExportsLazy)
|
|
{
|
|
UObject o;
|
|
try { o = lazy.Value; } catch { continue; }
|
|
if (o is not UStaticMeshComponent c) continue;
|
|
comps++;
|
|
var ids = c.LODData?.Select(l => l.MapBuildDataId).ToArray() ?? [];
|
|
if (ids.Length > 1) lodMulti++;
|
|
var ok = ids.Length > 0 && reg.MeshBuildData!.ContainsKey(ids[0]);
|
|
if (ok) hit++;
|
|
if (c is UInstancedStaticMeshComponent im) { ism++; if (ok) ismHit++; }
|
|
if (comps <= 5)
|
|
{
|
|
UStaticMesh? mesh = null;
|
|
try { mesh = c.GetStaticMesh()?.Load<UStaticMesh>(); } catch { }
|
|
var lods = mesh?.RenderData?.LODs;
|
|
Console.WriteLine($" comp {c.Name} {c.ExportType} lods {ids.Length} [{string.Join(',', ids.Select(i => reg.MeshBuildData!.ContainsKey(i) ? "Y" : "n"))}] mesh {mesh?.Name} lmIdx {mesh?.GetOrDefault<int>("LightMapCoordinateIndex")} lmRes {mesh?.GetOrDefault<int>("LightMapResolution")} meshLods {lods?.Length} uvs {string.Join('/', lods?.Select(l => l.VertexBuffer?.NumTexCoords ?? 0) ?? [])} compLmRes {c.GetOrDefault<int>("OverriddenLightMapRes")}");
|
|
}
|
|
}
|
|
Console.WriteLine($"comps {comps} with build data {hit}; ism {ism} hit {ismHit}; multi-lod {lodMulti}");
|
|
}
|
|
}
|