Iteration 4 over Assets/Scripts (no component/file splits, no Unity assets touched): Dedup: - Route inline cursor-release, material guards, Ctrl-held and undo/redo input through existing InputUtil / SetMatFloat helpers - Add ungated InputUtil.KeyPressedThisFrame; GameplayKeyPressed builds on it - Unify FindDeep/FindDeepChild into GeometryUtil.FindDeep Dead code / stale docs: - Remove unused code-gen bake path (HsvColorPicker.Build, PaintHud factory) - Drop unreferenced symbols (SubPhaseChanged event, LocalPhaseDuration, IsLocalSceneMain, MouseSensitivity.Changed, IsPaused, InSession, NetworkControlled, PreviousPose, JointCount, voxel-count accessors) - Fix incorrect PlayerRole / PaintHud / Pick / PlayerPose docs Perf / robustness (behaviour-neutral): - ConcealmentMeter.Evaluate: reuse vertex/topology buffers, two-pointer crossing count - BuildMeshCaches: alloc-free vertex copy, cached topology/UVs - Guard all PlayerPaintSync LogSync sites behind logSync - Cache LocalViewerIsHunter / controller / CanShoot / TypingGuard lookups; dedup LocalIsHunter with MatchHud - Change-guard RefreshEmissionColor and HeroCutout.Disarm - Cache scene/countdown string comparisons per frame - Grow NonAlloc buffers and log-once on saturation Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
56 lines
2.3 KiB
C#
56 lines
2.3 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>Shared mesh/bounds/hierarchy helpers.</summary>
|
|
public static class GeometryUtil
|
|
{
|
|
/// <summary>Depth-first hierarchy search by name; checks <paramref name="root"/> itself first.</summary>
|
|
public static Transform FindDeep(Transform root, string name)
|
|
{
|
|
if (root.name == name) return root;
|
|
for (int i = 0; i < root.childCount; i++)
|
|
{
|
|
var found = FindDeep(root.GetChild(i), name);
|
|
if (found) return found;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/// <summary>Divides a world scale back out of a freshly baked mesh so it is true unit-scale local
|
|
/// geometry (BakeMesh freezes the transform's lossyScale into the vertices). No-op at scale 1;
|
|
/// <paramref name="scratch"/> is reused so nothing is allocated per bake.</summary>
|
|
public static void RescaleToUnitScale(Mesh baked, Vector3 lossyScale, List<Vector3> scratch)
|
|
{
|
|
if (lossyScale.x == 1f && lossyScale.y == 1f && lossyScale.z == 1f) return;
|
|
|
|
float ix = lossyScale.x != 0f ? 1f / lossyScale.x : 0f;
|
|
float iy = lossyScale.y != 0f ? 1f / lossyScale.y : 0f;
|
|
float iz = lossyScale.z != 0f ? 1f / lossyScale.z : 0f;
|
|
baked.GetVertices(scratch);
|
|
for (int i = 0; i < scratch.Count; i++)
|
|
{
|
|
Vector3 v = scratch[i];
|
|
v.x *= ix; v.y *= iy; v.z *= iz;
|
|
scratch[i] = v;
|
|
}
|
|
baked.SetVertices(scratch);
|
|
baked.RecalculateBounds();
|
|
}
|
|
|
|
/// <summary>World AABB enclosing a local AABB after an affine transform (encapsulates the 8 transformed corners).</summary>
|
|
public static Bounds TransformBounds(Matrix4x4 m, Bounds local)
|
|
{
|
|
Vector3 mn = local.min, mx = local.max;
|
|
Vector3 c0 = m.MultiplyPoint3x4(mn);
|
|
Bounds b = new Bounds(c0, Vector3.zero);
|
|
b.Encapsulate(m.MultiplyPoint3x4(new Vector3(mx.x, mn.y, mn.z)));
|
|
b.Encapsulate(m.MultiplyPoint3x4(new Vector3(mn.x, mx.y, mn.z)));
|
|
b.Encapsulate(m.MultiplyPoint3x4(new Vector3(mn.x, mn.y, mx.z)));
|
|
b.Encapsulate(m.MultiplyPoint3x4(new Vector3(mx.x, mx.y, mn.z)));
|
|
b.Encapsulate(m.MultiplyPoint3x4(new Vector3(mx.x, mn.y, mx.z)));
|
|
b.Encapsulate(m.MultiplyPoint3x4(new Vector3(mn.x, mx.y, mx.z)));
|
|
b.Encapsulate(m.MultiplyPoint3x4(mx));
|
|
return b;
|
|
}
|
|
}
|