Files
adminandClaude Opus 4.8 e23fae0c50 Reorganize scripts into subfolders by responsibility
Move scripts under Assets/Scripts/ into Components, GameMode, Helper,
Network, Enum, Struct and ScriptableObject folders. Pure file moves
(plus folder .meta files); no code changes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 15:02:15 +02:00

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;
}
}