Upload project files

This commit is contained in:
Misaki
2024-09-16 00:08:10 +09:00
commit 0a4745662a
218 changed files with 13387 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
using UnityEngine;
namespace Misaki.ArtToolEditor
{
internal class BoundUtilities
{
internal struct SphereBounds
{
internal Vector3 position;
internal float radius;
/// <summary>
/// Create a sphere bound based on a position and a radius.
/// </summary>
/// <param name="p">Position</param>
/// <param name="r">Radius</param>
internal SphereBounds(Vector3 p, float r)
{
position = p;
radius = r;
}
/// <summary>
/// Return true if the other sphere is in the radius of this sphere bound.
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
internal bool Intersects(SphereBounds other)
{
return Vector3.Distance(position, other.position) < (radius + other.radius);
}
}
/// <summary>
/// Create a spherical bounds inside of a Renderer bounds.
/// It'll take every meshes found in the hierarchy into account.
/// </summary>
/// <param name="go">GameObject having Renderer component(s).</param>
/// <param name="bounds">Sphere bounds instance in which sphere information will be store.</param>
/// <returns>True if bounds data has been set.</returns>
internal static bool GetSphereBounds(GameObject go, out SphereBounds bounds)
{
var entireObjectBounds = GetHierarchyBounds(go);
bounds = default(SphereBounds);
if (entireObjectBounds.size == Vector3.zero)
return false;
bounds.position = entireObjectBounds.center;
bounds.radius = Mathf.Max(entireObjectBounds.extents.x, entireObjectBounds.extents.z);
return true;
}
/// <summary>
/// Create bounds based on meshes found in the given GameObject hierarchy.
/// </summary>
/// <param name="parent">Root object.</param>
/// <returns>New bounds around the given GameObject.
/// If GameObject has no Renderer, bounds will have a size of zero.</returns>
internal static Bounds GetHierarchyBounds(GameObject parent)
{
var renderers = parent.GetComponentsInChildren<Renderer>();
var bounds = default(Bounds);
if (renderers.Length == 0)
return bounds;
for (var i = 0; i < renderers.Length; ++i)
{
var it = renderers[i].bounds;
if (i == 0)
{
// World position
bounds.center = it.center;
}
bounds.Encapsulate(it.max);
bounds.Encapsulate(it.min);
}
return bounds;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 8b26f9e24f955774aa8129e3cf5e6b4f