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
@@ -198,16 +198,7 @@ public class ConcealmentColliderBaker : MonoBehaviour
|
||||
int made = 0;
|
||||
for (int ci = 0; ci < clusters.Count; ci++)
|
||||
{
|
||||
var pset = new HashSet<int>();
|
||||
var pts = new List<Vector3>();
|
||||
List<int> cl = clusters[ci];
|
||||
for (int j = 0; j < cl.Count; j++)
|
||||
{
|
||||
int t = cl[j];
|
||||
if (pset.Add(triA[t])) pts.Add(wv[triA[t]]);
|
||||
if (pset.Add(triB[t])) pts.Add(wv[triB[t]]);
|
||||
if (pset.Add(triC[t])) pts.Add(wv[triC[t]]);
|
||||
}
|
||||
List<Vector3> pts = CollectClusterPoints(clusters[ci], wv, triA, triB, triC);
|
||||
|
||||
float thick = SlabThickness(pts, out Vector3 normal);
|
||||
List<Vector3> hullPts;
|
||||
@@ -389,13 +380,25 @@ public class ConcealmentColliderBaker : MonoBehaviour
|
||||
if (set.Add(c)) { pos.Add(wv[c]); addedOut?.Add(c); }
|
||||
}
|
||||
|
||||
/// <summary>Extent of the point cloud along its PCA minor axis (= slab thickness), plus that axis.</summary>
|
||||
private static float SlabThickness(List<Vector3> pts, out Vector3 normal)
|
||||
/// <summary>Unique welded vertex positions of a triangle cluster.</summary>
|
||||
private static List<Vector3> CollectClusterPoints(List<int> cluster, List<Vector3> wv, List<int> triA, List<int> triB, List<int> triC)
|
||||
{
|
||||
normal = Vector3.up;
|
||||
int n = pts.Count;
|
||||
if (n < 2) return 0f;
|
||||
var pts = new List<Vector3>(cluster.Count * 3);
|
||||
var seen = new HashSet<int>();
|
||||
for (int j = 0; j < cluster.Count; j++)
|
||||
{
|
||||
int t = cluster[j];
|
||||
if (seen.Add(triA[t])) pts.Add(wv[triA[t]]);
|
||||
if (seen.Add(triB[t])) pts.Add(wv[triB[t]]);
|
||||
if (seen.Add(triC[t])) pts.Add(wv[triC[t]]);
|
||||
}
|
||||
return pts;
|
||||
}
|
||||
|
||||
/// <summary>Mean-centered 3x3 covariance of the point cloud, eigendecomposed via <see cref="Jacobi3"/>.</summary>
|
||||
private static void CovarianceEigen(List<Vector3> pts, out double[,] vec, out double[] d)
|
||||
{
|
||||
int n = pts.Count;
|
||||
Vector3 mean = Vector3.zero;
|
||||
for (int i = 0; i < n; i++) mean += pts[i];
|
||||
mean /= n;
|
||||
@@ -409,7 +412,17 @@ public class ConcealmentColliderBaker : MonoBehaviour
|
||||
}
|
||||
|
||||
var a = new double[3, 3] { { c00, c01, c02 }, { c01, c11, c12 }, { c02, c12, c22 } };
|
||||
Jacobi3(a, out double[,] v, out double[] d);
|
||||
Jacobi3(a, out vec, out d);
|
||||
}
|
||||
|
||||
/// <summary>Extent of the point cloud along its PCA minor axis (= slab thickness), plus that axis.</summary>
|
||||
private static float SlabThickness(List<Vector3> pts, out Vector3 normal)
|
||||
{
|
||||
normal = Vector3.up;
|
||||
int n = pts.Count;
|
||||
if (n < 2) return 0f;
|
||||
|
||||
CovarianceEigen(pts, out double[,] v, out double[] d);
|
||||
|
||||
int mi = 0;
|
||||
if (d[1] < d[mi]) mi = 1;
|
||||
@@ -483,15 +496,7 @@ public class ConcealmentColliderBaker : MonoBehaviour
|
||||
/// </summary>
|
||||
private static float ClusterFill(List<int> cluster, List<Vector3> wv, List<int> triA, List<int> triB, List<int> triC, out Vector3 splitAxis)
|
||||
{
|
||||
var pts = new List<Vector3>(cluster.Count * 3);
|
||||
var seen = new HashSet<int>();
|
||||
for (int j = 0; j < cluster.Count; j++)
|
||||
{
|
||||
int t = cluster[j];
|
||||
if (seen.Add(triA[t])) pts.Add(wv[triA[t]]);
|
||||
if (seen.Add(triB[t])) pts.Add(wv[triB[t]]);
|
||||
if (seen.Add(triC[t])) pts.Add(wv[triC[t]]);
|
||||
}
|
||||
List<Vector3> pts = CollectClusterPoints(cluster, wv, triA, triB, triC);
|
||||
|
||||
PcaFrame(pts, out Vector3 u, out Vector3 v, out _);
|
||||
|
||||
@@ -555,23 +560,9 @@ public class ConcealmentColliderBaker : MonoBehaviour
|
||||
private static void PcaFrame(List<Vector3> pts, out Vector3 u, out Vector3 v, out Vector3 n)
|
||||
{
|
||||
u = Vector3.right; v = Vector3.up; n = Vector3.forward;
|
||||
int cnt = pts.Count;
|
||||
if (cnt < 2) return;
|
||||
if (pts.Count < 2) return;
|
||||
|
||||
Vector3 mean = Vector3.zero;
|
||||
for (int i = 0; i < cnt; i++) mean += pts[i];
|
||||
mean /= cnt;
|
||||
|
||||
double c00 = 0, c01 = 0, c02 = 0, c11 = 0, c12 = 0, c22 = 0;
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
double x = pts[i].x - mean.x, y = pts[i].y - mean.y, z = pts[i].z - mean.z;
|
||||
c00 += x * x; c01 += x * y; c02 += x * z;
|
||||
c11 += y * y; c12 += y * z; c22 += z * z;
|
||||
}
|
||||
|
||||
var mat = new double[3, 3] { { c00, c01, c02 }, { c01, c11, c12 }, { c02, c12, c22 } };
|
||||
Jacobi3(mat, out double[,] vec, out double[] d);
|
||||
CovarianceEigen(pts, out double[,] vec, out double[] d);
|
||||
|
||||
int hi = 0, mid = 1, lo = 2;
|
||||
if (d[hi] < d[mid]) { int t = hi; hi = mid; mid = t; }
|
||||
|
||||
Reference in new issue
Block a user