mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Remove duplicate classes (#1025)
## Bug fixes - removed duplicate methods and classes involving quantum stuff
This commit is contained in:
commit
ffe41747fb
@ -223,111 +223,8 @@ namespace NewHorizons.Builder.Props
|
||||
shuffle._shuffledObjects = propsInGroup.Select(p => p.transform).ToArray();
|
||||
shuffle.Awake(); // this doesn't get called on its own for some reason. what? how?
|
||||
|
||||
AddBoundsVisibility(shuffleParent);
|
||||
BoundsUtilities.AddBoundsVisibility(shuffleParent);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
var meshFilters = gameObject.GetComponentsInChildren<MeshFilter>();
|
||||
@ -57,14 +58,14 @@ public static class BoundsUtilities
|
||||
|
||||
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),
|
||||
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(meshFilter.transform.TransformPoint).ToArray();
|
||||
|
||||
@ -3,7 +3,14 @@ using UnityEngine;
|
||||
|
||||
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 MeshFilter meshFilter;
|
||||
@ -13,27 +20,16 @@ internal class BoxShapeFixer : MonoBehaviour
|
||||
{
|
||||
if (meshFilter == null && skinnedMeshRenderer == null)
|
||||
{
|
||||
NHLogger.LogVerbose("Useless BoxShapeFixer, destroying"); DestroyImmediate(this);
|
||||
NHLogger.LogVerbose("Useless BoxShapeFixer, destroying");
|
||||
DestroyImmediate(this);
|
||||
}
|
||||
|
||||
Mesh sharedMesh = null;
|
||||
if (meshFilter != null)
|
||||
{
|
||||
sharedMesh = meshFilter.sharedMesh;
|
||||
}
|
||||
if (skinnedMeshRenderer != null)
|
||||
{
|
||||
sharedMesh = skinnedMeshRenderer.sharedMesh;
|
||||
}
|
||||
if (meshFilter != null) sharedMesh = meshFilter.sharedMesh;
|
||||
if (skinnedMeshRenderer != null) sharedMesh = skinnedMeshRenderer.sharedMesh;
|
||||
|
||||
if (sharedMesh == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (sharedMesh.bounds.size == Vector3.zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (sharedMesh == null) return;
|
||||
if (sharedMesh.bounds.size == Vector3.zero) return;
|
||||
|
||||
shape.size = sharedMesh.bounds.size;
|
||||
shape.center = sharedMesh.bounds.center;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user