fix(render,sim): preserve MechPaint albedo/COLOR_0, monotonic tracer VFX IDs, dither fade, and GLB COLOR_0 check
This commit is contained in:
parent
2529ba62d2
commit
d81865091d
8 changed files with 201 additions and 56 deletions
|
|
@ -479,8 +479,8 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
}
|
||||
|
||||
// C: Build single-node BakedStaticMesh + decimated BakedLodFarMesh (>130m) per template
|
||||
ArrayMesh bakedStaticMesh = BuildBakedStaticMesh(sceneRoot, coarseMaterials: false, bakeVertexColor: false);
|
||||
ArrayMesh bakedCoarseStatic = BuildBakedStaticMesh(sceneRoot, coarseMaterials: true, bakeVertexColor: false);
|
||||
ArrayMesh bakedStaticMesh = BuildBakedStaticMesh(sceneRoot, coarseMaterials: false);
|
||||
ArrayMesh bakedCoarseStatic = BuildBakedStaticMesh(sceneRoot, coarseMaterials: true);
|
||||
ArrayMesh bakedLodFarMesh = DecimateMeshGrid(bakedCoarseStatic, cellSize: 0.45f, targetMinY: minY);
|
||||
|
||||
ArrayMesh singleSurfaceStatic = CollapseToSingleSurfaceMechPaintMesh(bakedStaticMesh);
|
||||
|
|
@ -547,7 +547,7 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
ComputeSceneMeshBounds(sceneRoot, out Vector3 bMin, out Vector3 bMax);
|
||||
var partCentroids = CollectGearPartCentroids(sceneRoot);
|
||||
MergeGearSubMeshes(sceneRoot, gearId);
|
||||
ArrayMesh bakedDropMesh = BuildBakedStaticMesh(sceneRoot, coarseMaterials: false, bakeVertexColor: false);
|
||||
ArrayMesh bakedDropMesh = BuildBakedStaticMesh(sceneRoot, coarseMaterials: false);
|
||||
ArrayMesh singleSurfaceMesh = CollapseToSingleSurfaceMechPaintMesh(bakedDropMesh);
|
||||
Vector3 localFwd = new Vector3(0f, 0f, 1f);
|
||||
|
||||
|
|
@ -929,7 +929,7 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
PruneEmptyNonProtectedNodes(sceneRoot, sceneRoot, keptNodes);
|
||||
}
|
||||
|
||||
private static ArrayMesh BuildBakedStaticMesh(Node3D sceneRoot, bool coarseMaterials = false, bool bakeVertexColor = true)
|
||||
private static ArrayMesh BuildBakedStaticMesh(Node3D sceneRoot, bool coarseMaterials = false)
|
||||
{
|
||||
var allMeshes = new List<MeshInstance3D>();
|
||||
CollectAllMeshInstances(sceneRoot, allMeshes);
|
||||
|
|
@ -944,7 +944,7 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
}
|
||||
}
|
||||
|
||||
return BuildMergedArrayMesh(items, coarseMaterials, bakeVertexColor) ?? new ArrayMesh();
|
||||
return BuildMergedArrayMesh(items, coarseMaterials) ?? new ArrayMesh();
|
||||
}
|
||||
|
||||
private static Dictionary<string, Vector3> CollectGearPartCentroids(Node3D sceneRoot)
|
||||
|
|
@ -1430,9 +1430,7 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
private static bool TryGetMaterialValueKey(
|
||||
Material mat,
|
||||
bool coarse,
|
||||
bool bakeVertexColor,
|
||||
out StandardMatKey key,
|
||||
out Color vertexTint)
|
||||
out StandardMatKey key)
|
||||
{
|
||||
if (mat is StandardMaterial3D sm &&
|
||||
sm.AlbedoTexture is null &&
|
||||
|
|
@ -1445,16 +1443,14 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
int paintTag = (mName.Contains("olive") || mName.Contains("khaki")) ? 1
|
||||
: (mName.Contains("signal") || mName.Contains("orange")) ? 2
|
||||
: 0;
|
||||
bool useVCol = bakeVertexColor && paintTag == 0;
|
||||
vertexTint = useVCol ? sm.AlbedoColor : Colors.White;
|
||||
float colorScale = coarse ? 2f : 32f;
|
||||
float pbrScale = coarse ? 0f : 4f;
|
||||
key = new StandardMatKey(
|
||||
paintTag,
|
||||
useVCol ? 0 : (int)MathF.Round(sm.AlbedoColor.R * colorScale),
|
||||
useVCol ? 0 : (int)MathF.Round(sm.AlbedoColor.G * colorScale),
|
||||
useVCol ? 0 : (int)MathF.Round(sm.AlbedoColor.B * colorScale),
|
||||
useVCol ? 10 : (int)MathF.Round(sm.AlbedoColor.A * 10f),
|
||||
(int)MathF.Round(sm.AlbedoColor.R * colorScale),
|
||||
(int)MathF.Round(sm.AlbedoColor.G * colorScale),
|
||||
(int)MathF.Round(sm.AlbedoColor.B * colorScale),
|
||||
(int)MathF.Round(sm.AlbedoColor.A * 10f),
|
||||
(int)MathF.Round(sm.Metallic * pbrScale),
|
||||
(int)MathF.Round(sm.Roughness * pbrScale),
|
||||
sm.EmissionEnabled,
|
||||
|
|
@ -1467,21 +1463,18 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
return true;
|
||||
}
|
||||
key = default;
|
||||
vertexTint = Colors.White;
|
||||
return false;
|
||||
}
|
||||
|
||||
private sealed class MaterialSurfaceBucket
|
||||
{
|
||||
public required Material? Material;
|
||||
public bool UsesVertexColor;
|
||||
public readonly List<(Mesh Mesh, int SurfaceIdx, Transform3D RelXf, Color VertexTint)> Sources = new();
|
||||
public readonly List<(Mesh Mesh, int SurfaceIdx, Transform3D RelXf)> Sources = new();
|
||||
}
|
||||
|
||||
private static ArrayMesh? BuildMergedArrayMesh(
|
||||
List<(MeshInstance3D Mi, Transform3D RelXf)> items,
|
||||
bool coarseMaterials = false,
|
||||
bool bakeVertexColor = true)
|
||||
bool coarseMaterials = false)
|
||||
{
|
||||
if (items.Count == 0)
|
||||
{
|
||||
|
|
@ -1490,7 +1483,7 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
|
||||
var buckets = new List<MaterialSurfaceBucket>();
|
||||
var bucketByMatId = new Dictionary<ulong, MaterialSurfaceBucket>();
|
||||
var bucketByMatVal = new Dictionary<(StandardMatKey Key, bool UseVCol), MaterialSurfaceBucket>();
|
||||
var bucketByMatVal = new Dictionary<StandardMatKey, MaterialSurfaceBucket>();
|
||||
MaterialSurfaceBucket? nullMatBucket = null;
|
||||
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
|
|
@ -1510,7 +1503,6 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
}
|
||||
Material? mat = mi.MaterialOverride ?? mi.GetActiveMaterial(s);
|
||||
MaterialSurfaceBucket bucket;
|
||||
Color vTint = Colors.White;
|
||||
if (mat is null)
|
||||
{
|
||||
nullMatBucket ??= new MaterialSurfaceBucket { Material = null };
|
||||
|
|
@ -1520,21 +1512,12 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
}
|
||||
bucket = nullMatBucket;
|
||||
}
|
||||
else if (TryGetMaterialValueKey(mat, coarseMaterials, bakeVertexColor, out var matKey, out vTint))
|
||||
else if (TryGetMaterialValueKey(mat, coarseMaterials, out var matKey))
|
||||
{
|
||||
bool useVCol = bakeVertexColor && matKey.PaintTag == 0;
|
||||
if (!bucketByMatVal.TryGetValue((matKey, useVCol), out bucket!))
|
||||
if (!bucketByMatVal.TryGetValue(matKey, out bucket!))
|
||||
{
|
||||
Material bucketMat = mat;
|
||||
if (useVCol && mat is StandardMaterial3D sm)
|
||||
{
|
||||
var vcMat = (StandardMaterial3D)sm.Duplicate();
|
||||
vcMat.AlbedoColor = Colors.White;
|
||||
vcMat.VertexColorUseAsAlbedo = true;
|
||||
bucketMat = vcMat;
|
||||
}
|
||||
bucket = new MaterialSurfaceBucket { Material = bucketMat, UsesVertexColor = useVCol };
|
||||
bucketByMatVal[(matKey, useVCol)] = bucket;
|
||||
bucket = new MaterialSurfaceBucket { Material = mat };
|
||||
bucketByMatVal[matKey] = bucket;
|
||||
buckets.Add(bucket);
|
||||
}
|
||||
}
|
||||
|
|
@ -1548,7 +1531,7 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
buckets.Add(bucket);
|
||||
}
|
||||
}
|
||||
bucket.Sources.Add((mesh, s, relXf, vTint));
|
||||
bucket.Sources.Add((mesh, s, relXf));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1565,14 +1548,14 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
bool anyTangent = false;
|
||||
bool anyUv = false;
|
||||
bool anyUv2 = false;
|
||||
bool anyColor = bucket.UsesVertexColor;
|
||||
bool anyColor = false;
|
||||
int totalVerts = 0;
|
||||
int totalIndices = 0;
|
||||
|
||||
var cachedArrays = new List<(Godot.Collections.Array Arrays, Transform3D RelXf, Color VTint, int VertCount, int IndexCount)>(bucket.Sources.Count);
|
||||
var cachedArrays = new List<(Godot.Collections.Array Arrays, Transform3D RelXf, int VertCount, int IndexCount)>(bucket.Sources.Count);
|
||||
for (int s = 0; s < bucket.Sources.Count; s++)
|
||||
{
|
||||
var (mesh, surfIdx, relXf, vTint) = bucket.Sources[s];
|
||||
var (mesh, surfIdx, relXf) = bucket.Sources[s];
|
||||
var arr = mesh.SurfaceGetArrays(surfIdx);
|
||||
if (arr.Count <= (int)Mesh.ArrayType.Vertex ||
|
||||
arr[(int)Mesh.ArrayType.Vertex].VariantType != Variant.Type.PackedVector3Array)
|
||||
|
|
@ -1599,7 +1582,7 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
|
||||
totalVerts += verts.Length;
|
||||
totalIndices += idxCount;
|
||||
cachedArrays.Add((arr, relXf, vTint, verts.Length, idxCount));
|
||||
cachedArrays.Add((arr, relXf, verts.Length, idxCount));
|
||||
}
|
||||
|
||||
if (totalVerts == 0 || totalIndices == 0)
|
||||
|
|
@ -1619,7 +1602,7 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
int iOffset = 0;
|
||||
for (int c = 0; c < cachedArrays.Count; c++)
|
||||
{
|
||||
var (arr, relXf, vTint, vCount, idxCount) = cachedArrays[c];
|
||||
var (arr, relXf, vCount, idxCount) = cachedArrays[c];
|
||||
Vector3[] srcVerts = arr[(int)Mesh.ArrayType.Vertex].AsVector3Array();
|
||||
bool flipWinding = relXf.Basis.Determinant() < 0f;
|
||||
Basis normBasis = relXf.Basis.Inverse().Transposed();
|
||||
|
|
@ -1695,19 +1678,11 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
if (arr.Count > (int)Mesh.ArrayType.Color && arr[(int)Mesh.ArrayType.Color].VariantType == Variant.Type.PackedColorArray)
|
||||
{
|
||||
Color[] srcC = arr[(int)Mesh.ArrayType.Color].AsColorArray();
|
||||
if (bucket.UsesVertexColor)
|
||||
{
|
||||
for (int v = 0; v < vCount; v++) outColors[vOffset + v] = srcC[v] * vTint;
|
||||
}
|
||||
else
|
||||
{
|
||||
Array.Copy(srcC, 0, outColors, vOffset, vCount);
|
||||
}
|
||||
Array.Copy(srcC, 0, outColors, vOffset, vCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
Color fill = bucket.UsesVertexColor ? vTint : Colors.White;
|
||||
for (int v = 0; v < vCount; v++) outColors[vOffset + v] = fill;
|
||||
for (int v = 0; v < vCount; v++) outColors[vOffset + v] = Colors.White;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue