mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
delete duplicate BoundsUtilities stuff
This commit is contained in:
parent
ed4e43a044
commit
06023b7754
@ -223,76 +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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user