Remove duplicate classes (#1025)

## Bug fixes

- removed duplicate methods and classes involving quantum stuff
This commit is contained in:
xen-42 2025-01-13 20:06:15 -05:00 committed by GitHub
commit ffe41747fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 130 deletions

View File

@ -223,111 +223,8 @@ namespace NewHorizons.Builder.Props
shuffle._shuffledObjects = propsInGroup.Select(p => p.transform).ToArray(); shuffle._shuffledObjects = propsInGroup.Select(p => p.transform).ToArray();
shuffle.Awake(); // this doesn't get called on its own for some reason. what? how? shuffle.Awake(); // this doesn't get called on its own for some reason. what? how?
AddBoundsVisibility(shuffleParent); BoundsUtilities.AddBoundsVisibility(shuffleParent);
shuffleParent.SetActive(true); shuffleParent.SetActive(true);
} }
struct BoxShapeReciever
{
public MeshFilter f;
public SkinnedMeshRenderer s;
public GameObject gameObject;
}
public static void AddBoundsVisibility(GameObject g)
{
var meshFilters = g.GetComponentsInChildren<MeshFilter>();
var skinnedMeshRenderers = g.GetComponentsInChildren<SkinnedMeshRenderer>();
var boxShapeRecievers = meshFilters
.Select(f => new BoxShapeReciever() { f = f, gameObject = f.gameObject })
.Concat(
skinnedMeshRenderers.Select(s => new BoxShapeReciever() { s = s, gameObject = s.gameObject })
)
.ToList();
foreach (var boxshapeReciever in boxShapeRecievers)
{
var box = boxshapeReciever.gameObject.AddComponent<BoxShape>();
boxshapeReciever.gameObject.AddComponent<ShapeVisibilityTracker>();
boxshapeReciever.gameObject.AddComponent<BoxShapeVisualizer>();
var fixer = boxshapeReciever.gameObject.AddComponent<BoxShapeFixer>();
fixer.shape = box;
fixer.meshFilter = boxshapeReciever.f;
fixer.skinnedMeshRenderer = boxshapeReciever.s;
}
}
// BUG: ignores skinned guys. this coincidentally makes it work without BoxShapeFixer
public static Bounds GetBoundsOfSelfAndChildMeshes(GameObject g)
{
var meshFilters = g.GetComponentsInChildren<MeshFilter>();
var corners = meshFilters.SelectMany(m => GetMeshCorners(m, g)).ToList();
Bounds b = new Bounds(corners[0], Vector3.zero);
corners.ForEach(corner => b.Encapsulate(corner));
return b;
}
public static Vector3[] GetMeshCorners(MeshFilter m, GameObject relativeTo = null)
{
var bounds = m.mesh.bounds;
var localCorners = new Vector3[]
{
bounds.min,
bounds.max,
new Vector3(bounds.min.x, bounds.min.y, bounds.max.z),
new Vector3(bounds.min.x, bounds.max.y, bounds.min.z),
new Vector3(bounds.max.x, bounds.min.y, bounds.min.z),
new Vector3(bounds.min.x, bounds.max.y, bounds.max.z),
new Vector3(bounds.max.x, bounds.min.y, bounds.max.z),
new Vector3(bounds.max.x, bounds.max.y, bounds.min.z),
};
var globalCorners = localCorners.Select(localCorner => m.transform.TransformPoint(localCorner)).ToArray();
if (relativeTo == null) return globalCorners;
return globalCorners.Select(globalCorner => relativeTo.transform.InverseTransformPoint(globalCorner)).ToArray();
}
}
/// <summary>
/// for some reason mesh bounds are wrong unless we wait a bit
/// so this script contiously checks everything until it is correct
///
/// this actually only seems to be a problem with skinned renderers. normal ones work fine
/// TODO: at some point narrow this down to just skinned, instead of doing everything and checking every frame
/// </summary>
public class BoxShapeFixer : MonoBehaviour
{
public BoxShape shape;
public MeshFilter meshFilter;
public SkinnedMeshRenderer skinnedMeshRenderer;
public void Update()
{
if (meshFilter == null && skinnedMeshRenderer == null)
{
NHLogger.LogVerbose("Useless BoxShapeFixer, destroying");
DestroyImmediate(this);
}
Mesh sharedMesh = null;
if (meshFilter != null) sharedMesh = meshFilter.sharedMesh;
if (skinnedMeshRenderer != null) sharedMesh = skinnedMeshRenderer.sharedMesh;
if (sharedMesh == null) return;
if (sharedMesh.bounds.size == Vector3.zero) return;
shape.size = sharedMesh.bounds.size;
shape.center = sharedMesh.bounds.center;
DestroyImmediate(this);
}
} }
} }

View File

@ -40,6 +40,7 @@ public static class BoundsUtilities
} }
} }
// BUG: ignores skinned guys. this coincidentally makes it work without BoxShapeFixer
public static Bounds GetBoundsOfSelfAndChildMeshes(GameObject gameObject) public static Bounds GetBoundsOfSelfAndChildMeshes(GameObject gameObject)
{ {
var meshFilters = gameObject.GetComponentsInChildren<MeshFilter>(); var meshFilters = gameObject.GetComponentsInChildren<MeshFilter>();

View File

@ -3,7 +3,14 @@ using UnityEngine;
namespace NewHorizons.Utility.Geometry; namespace NewHorizons.Utility.Geometry;
internal class BoxShapeFixer : MonoBehaviour /// <summary>
/// for some reason mesh bounds are wrong unless we wait a bit
/// so this script contiously checks everything until it is correct
///
/// this actually only seems to be a problem with skinned renderers. normal ones work fine
/// TODO: at some point narrow this down to just skinned, instead of doing everything and checking every frame
/// </summary>
public class BoxShapeFixer : MonoBehaviour
{ {
public BoxShape shape; public BoxShape shape;
public MeshFilter meshFilter; public MeshFilter meshFilter;
@ -13,27 +20,16 @@ internal class BoxShapeFixer : MonoBehaviour
{ {
if (meshFilter == null && skinnedMeshRenderer == null) if (meshFilter == null && skinnedMeshRenderer == null)
{ {
NHLogger.LogVerbose("Useless BoxShapeFixer, destroying"); DestroyImmediate(this); NHLogger.LogVerbose("Useless BoxShapeFixer, destroying");
DestroyImmediate(this);
} }
Mesh sharedMesh = null; Mesh sharedMesh = null;
if (meshFilter != null) if (meshFilter != null) sharedMesh = meshFilter.sharedMesh;
{ if (skinnedMeshRenderer != null) sharedMesh = skinnedMeshRenderer.sharedMesh;
sharedMesh = meshFilter.sharedMesh;
}
if (skinnedMeshRenderer != null)
{
sharedMesh = skinnedMeshRenderer.sharedMesh;
}
if (sharedMesh == null) if (sharedMesh == null) return;
{ if (sharedMesh.bounds.size == Vector3.zero) return;
return;
}
if (sharedMesh.bounds.size == Vector3.zero)
{
return;
}
shape.size = sharedMesh.bounds.size; shape.size = sharedMesh.bounds.size;
shape.center = sharedMesh.bounds.center; shape.center = sharedMesh.bounds.center;