Refactor: extract shared helpers across scripts, trim remaining doc redundancy
Deduplication pass (44 extractions): - New SmoothedLook: shared smoothed yaw/pitch look tick + view seeding (FirstPersonController, FreeCamController) - New CharacterTeleport: disable-CC-around-teleport idiom (rescue, owner position apply, free-cam sync) - New GeometryUtil: RescaleToUnitScale + TransformBounds (concealment meter/volume, skinned collider baker) - Paint family: canonical map read/write shared between Net and Persistence, snapshot decode, backend stroke dispatch, RebuildBackend, ResolveSeed, chunked RPC send/gate/copy, CamoKnobs/HeightKnobs aggregates, SanitizeFileKey, NewMaskTexture, AdoptAlbedo, FindSlider - Player/modes: GameMode SetPlayerControl/SetPainting/SetOrbitInputEnabled, InputUtil.GameplayKeyPressed, NearestClimbHit, ComputeXRay delegates to ComputeResolutionFreeze, FingerIK TryInPlaneAngle - Match/misc: UnhookSessionCallbacks, SendEmptyNamedMessage, SwapScenes, RunSessionOpAsync, CovarianceEigen, CollectClusterPoints, MatchHud GUIStyle cache, HsvColorPicker rehook, VoxelCenter Documentation pass: remove 6 triplicated doc blocks and 2 restating inline comments left after the previous reduction. Behavior-neutral; hot-path rasterizer loops intentionally untouched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
066e308cde
commit
2243cc823e
40 files changed
+681
-724
No files matched your search
@@ -36,13 +36,16 @@ public partial class MeshPainter
|
||||
private static string PaintLibraryDir =>
|
||||
Path.Combine(Application.persistentDataPath, "MeshPaint", "Saved");
|
||||
|
||||
private static string SanitizeKey(string s)
|
||||
/// <summary>Filesystem-safe key: invalid filename characters and spaces become underscores.</summary>
|
||||
internal static string SanitizeFileKey(string s)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s)) return "unnamed";
|
||||
foreach (char c in Path.GetInvalidFileNameChars()) s = s.Replace(c, '_');
|
||||
return s.Replace(' ', '_');
|
||||
}
|
||||
|
||||
private static string SanitizeKey(string s) =>
|
||||
string.IsNullOrEmpty(s) ? "unnamed" : SanitizeFileKey(s);
|
||||
|
||||
/// <summary>Disk path for a slot. The display name lives inside the file; the file name is a sanitized key.</summary>
|
||||
private static string PathForName(string name) =>
|
||||
Path.Combine(PaintLibraryDir, SanitizeKey(name) + PaintFileExt);
|
||||
@@ -86,7 +89,6 @@ public partial class MeshPainter
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(PaintLibraryDir);
|
||||
int n = textureSize * textureSize;
|
||||
|
||||
using (var fs = new FileStream(PathForName(name), FileMode.Create, FileAccess.Write))
|
||||
using (var w = new BinaryWriter(fs))
|
||||
@@ -111,21 +113,7 @@ public partial class MeshPainter
|
||||
w.Write(HeightNormalIntensity);
|
||||
w.Write(ParallaxIntensity);
|
||||
|
||||
var bytes = new byte[n * 4];
|
||||
for (int mi = 0; mi < MAP_COUNT; mi++)
|
||||
{
|
||||
Color32[] px = ReadCanonical(mi);
|
||||
int count = Mathf.Min(n, px.Length);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int o = i * 4;
|
||||
bytes[o] = px[i].r;
|
||||
bytes[o + 1] = px[i].g;
|
||||
bytes[o + 2] = px[i].b;
|
||||
bytes[o + 3] = px[i].a;
|
||||
}
|
||||
w.Write(bytes, 0, count * 4);
|
||||
}
|
||||
WriteCanonicalMaps(w);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -147,8 +135,6 @@ public partial class MeshPainter
|
||||
Color32[][] canonical = ReadMaps(PathForName(name), out PaintScalars scalars);
|
||||
if (canonical == null) return false;
|
||||
|
||||
// Re-seed exactly like SwitchBackend / ApplyPaintSnapshot, so the island/dilation seeding path
|
||||
// runs and the edge padding is rebuilt correctly for the loaded content.
|
||||
ReseedCanonical(canonical);
|
||||
|
||||
// A load replaces the whole painting and is NOT undoable: the loaded maps become the new history
|
||||
@@ -202,9 +188,7 @@ public partial class MeshPainter
|
||||
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read))
|
||||
using (var r = new BinaryReader(fs, Encoding.UTF8))
|
||||
{
|
||||
if (r.ReadUInt32() != PaintFileMagic) return null;
|
||||
int ver = r.ReadInt32();
|
||||
if (ver < 2 || ver > PaintFileVersion) return null; // list legacy v2..v3 slots + current
|
||||
if (!TryReadPaintVersion(r, out _)) return null;
|
||||
return r.ReadString();
|
||||
}
|
||||
}
|
||||
@@ -228,9 +212,7 @@ public partial class MeshPainter
|
||||
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read))
|
||||
using (var r = new BinaryReader(fs, Encoding.UTF8))
|
||||
{
|
||||
if (r.ReadUInt32() != PaintFileMagic) return null;
|
||||
int ver = r.ReadInt32();
|
||||
if (ver < 2 || ver > PaintFileVersion) return null; // read legacy v2..v3 + current
|
||||
if (!TryReadPaintVersion(r, out int ver)) return null;
|
||||
r.ReadString(); // display name (header only; not needed for the pixel load)
|
||||
int w = r.ReadInt32();
|
||||
int h = r.ReadInt32();
|
||||
@@ -264,23 +246,7 @@ public partial class MeshPainter
|
||||
return null;
|
||||
}
|
||||
|
||||
int n = textureSize * textureSize;
|
||||
var result = new Color32[MAP_COUNT][];
|
||||
int load = Mathf.Min(maps, MAP_COUNT);
|
||||
for (int mi = 0; mi < load; mi++)
|
||||
{
|
||||
byte[] raw = r.ReadBytes(n * 4);
|
||||
if (raw.Length != n * 4) break; // truncated file -> remaining maps stay seeded
|
||||
|
||||
var px = new Color32[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int o = i * 4;
|
||||
px[i] = new Color32(raw[o], raw[o + 1], raw[o + 2], raw[o + 3]);
|
||||
}
|
||||
result[mi] = px;
|
||||
}
|
||||
return result;
|
||||
return ReadCanonicalMaps(r, maps);
|
||||
}
|
||||
}
|
||||
catch (System.Exception e)
|
||||
@@ -289,4 +255,55 @@ public partial class MeshPainter
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Validates the paint-file magic and version range (legacy v2 .. current).</summary>
|
||||
private static bool TryReadPaintVersion(BinaryReader r, out int ver)
|
||||
{
|
||||
if (r.ReadUInt32() != PaintFileMagic) { ver = 0; return false; }
|
||||
ver = r.ReadInt32();
|
||||
return ver >= 2 && ver <= PaintFileVersion;
|
||||
}
|
||||
|
||||
/// <summary>Writes every map's canonical Color32 bytes to the stream (shared by slot save + net snapshot).</summary>
|
||||
private void WriteCanonicalMaps(BinaryWriter w)
|
||||
{
|
||||
int n = textureSize * textureSize;
|
||||
var bytes = new byte[n * 4];
|
||||
for (int mi = 0; mi < MAP_COUNT; mi++)
|
||||
{
|
||||
Color32[] px = ReadCanonical(mi);
|
||||
int count = Mathf.Min(n, px.Length);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int o = i * 4;
|
||||
bytes[o] = px[i].r;
|
||||
bytes[o + 1] = px[i].g;
|
||||
bytes[o + 2] = px[i].b;
|
||||
bytes[o + 3] = px[i].a;
|
||||
}
|
||||
w.Write(bytes, 0, count * 4);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Reads up to MAP_COUNT canonical map blocks; a truncated stream leaves the remaining maps null (seeded).</summary>
|
||||
private Color32[][] ReadCanonicalMaps(BinaryReader r, int mapsInFile)
|
||||
{
|
||||
int n = textureSize * textureSize;
|
||||
var result = new Color32[MAP_COUNT][];
|
||||
int load = Mathf.Min(mapsInFile, MAP_COUNT);
|
||||
for (int mi = 0; mi < load; mi++)
|
||||
{
|
||||
byte[] raw = r.ReadBytes(n * 4);
|
||||
if (raw.Length != n * 4) break; // truncated -> remaining maps stay at the material seed
|
||||
|
||||
var px = new Color32[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int o = i * 4;
|
||||
px[i] = new Color32(raw[o], raw[o + 1], raw[o + 2], raw[o + 3]);
|
||||
}
|
||||
result[mi] = px;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user