mirror of
https://github.com/mob-sakai/UIEffect.git
synced 2026-11-21 10:22:37 +08:00
feat: add GradationMode.Angle and GradationMode.AngleGradient
This commit is contained in:
@@ -66,6 +66,7 @@ namespace Coffee.UIEffects.Editors
|
|||||||
private SerializedProperty _gradationGradient;
|
private SerializedProperty _gradationGradient;
|
||||||
private SerializedProperty _gradationOffset;
|
private SerializedProperty _gradationOffset;
|
||||||
private SerializedProperty _gradationScale;
|
private SerializedProperty _gradationScale;
|
||||||
|
private SerializedProperty _gradationRotation;
|
||||||
|
|
||||||
private bool _expandOthers;
|
private bool _expandOthers;
|
||||||
private SerializedProperty _allowToModifyMeshShape;
|
private SerializedProperty _allowToModifyMeshShape;
|
||||||
@@ -128,6 +129,7 @@ namespace Coffee.UIEffects.Editors
|
|||||||
_gradationGradient = serializedObject.FindProperty("m_GradationGradient");
|
_gradationGradient = serializedObject.FindProperty("m_GradationGradient");
|
||||||
_gradationOffset = serializedObject.FindProperty("m_GradationOffset");
|
_gradationOffset = serializedObject.FindProperty("m_GradationOffset");
|
||||||
_gradationScale = serializedObject.FindProperty("m_GradationScale");
|
_gradationScale = serializedObject.FindProperty("m_GradationScale");
|
||||||
|
_gradationRotation = serializedObject.FindProperty("m_GradationRotation");
|
||||||
|
|
||||||
_allowToModifyMeshShape = serializedObject.FindProperty("m_AllowToModifyMeshShape");
|
_allowToModifyMeshShape = serializedObject.FindProperty("m_AllowToModifyMeshShape");
|
||||||
}
|
}
|
||||||
@@ -283,10 +285,10 @@ namespace Coffee.UIEffects.Editors
|
|||||||
{
|
{
|
||||||
case GradationMode.HorizontalGradient:
|
case GradationMode.HorizontalGradient:
|
||||||
case GradationMode.VerticalGradient:
|
case GradationMode.VerticalGradient:
|
||||||
|
case GradationMode.AngleGradient:
|
||||||
EditorGUILayout.PropertyField(_gradationGradient);
|
EditorGUILayout.PropertyField(_gradationGradient);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
|
||||||
EditorGUILayout.PropertyField(_gradationColor1);
|
EditorGUILayout.PropertyField(_gradationColor1);
|
||||||
var r = EditorGUILayout.GetControlRect();
|
var r = EditorGUILayout.GetControlRect();
|
||||||
r.width -= 20;
|
r.width -= 20;
|
||||||
@@ -302,11 +304,17 @@ namespace Coffee.UIEffects.Editors
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(_gradationOffset);
|
EditorGUILayout.PropertyField(_gradationOffset);
|
||||||
EditorGUILayout.PropertyField(_gradationScale);
|
EditorGUILayout.PropertyField(_gradationScale);
|
||||||
|
|
||||||
|
if ((GradationMode)_gradationMode.intValue == GradationMode.Angle
|
||||||
|
|| (GradationMode)_gradationMode.intValue == GradationMode.AngleGradient)
|
||||||
|
{
|
||||||
|
EditorGUILayout.PropertyField(_gradationRotation);
|
||||||
|
}
|
||||||
|
|
||||||
EditorGUI.indentLevel--;
|
EditorGUI.indentLevel--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,9 @@ namespace Coffee.UIEffects
|
|||||||
RadialFast,
|
RadialFast,
|
||||||
RadialDetail,
|
RadialDetail,
|
||||||
DiagonalToRightBottom,
|
DiagonalToRightBottom,
|
||||||
DiagonalToLeftBottom
|
DiagonalToLeftBottom,
|
||||||
|
Angle,
|
||||||
|
AngleGradient
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class BlendTypeConverter
|
internal static class BlendTypeConverter
|
||||||
|
|||||||
@@ -148,9 +148,11 @@ namespace Coffee.UIEffects
|
|||||||
protected GradationMode m_GradationMode = GradationMode.None;
|
protected GradationMode m_GradationMode = GradationMode.None;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
|
[ColorUsage(true, true)]
|
||||||
protected Color m_GradationColor1 = Color.white;
|
protected Color m_GradationColor1 = Color.white;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
|
[ColorUsage(true, true)]
|
||||||
protected Color m_GradationColor2 = Color.white;
|
protected Color m_GradationColor2 = Color.white;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
@@ -164,6 +166,10 @@ namespace Coffee.UIEffects
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
protected float m_GradationScale = 1;
|
protected float m_GradationScale = 1;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
[Range(0, 360)]
|
||||||
|
private float m_GradationRotation = 0;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
protected bool m_AllowToModifyMeshShape = true;
|
protected bool m_AllowToModifyMeshShape = true;
|
||||||
|
|
||||||
@@ -696,6 +702,18 @@ namespace Coffee.UIEffects
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float gradationRotation
|
||||||
|
{
|
||||||
|
get => m_GradationRotation;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
value = Mathf.Repeat(value, 360);
|
||||||
|
if (Mathf.Approximately(m_GradationRotation, value)) return;
|
||||||
|
context.gradationRotation = m_GradationRotation = value;
|
||||||
|
SetVerticesDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool allowToModifyMeshShape
|
public bool allowToModifyMeshShape
|
||||||
{
|
{
|
||||||
get => m_AllowToModifyMeshShape;
|
get => m_AllowToModifyMeshShape;
|
||||||
@@ -819,6 +837,7 @@ namespace Coffee.UIEffects
|
|||||||
c.gradationGradient = m_GradationGradient;
|
c.gradationGradient = m_GradationGradient;
|
||||||
c.gradationOffset = m_GradationOffset;
|
c.gradationOffset = m_GradationOffset;
|
||||||
c.gradationScale = m_GradationScale;
|
c.gradationScale = m_GradationScale;
|
||||||
|
c.gradationRotation = m_GradationRotation;
|
||||||
|
|
||||||
c.allowToModifyMeshShape = m_AllowToModifyMeshShape;
|
c.allowToModifyMeshShape = m_AllowToModifyMeshShape;
|
||||||
}
|
}
|
||||||
@@ -855,10 +874,16 @@ namespace Coffee.UIEffects
|
|||||||
transitionRate = rate;
|
transitionRate = rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gradationMode != GradationMode.None && 0 < (mask & UIEffectTweener.CullingMask.Gradiation))
|
if (gradationMode != GradationMode.None && 0 < (mask & UIEffectTweener.CullingMask.GradiationOffset))
|
||||||
{
|
{
|
||||||
gradationOffset = Mathf.Lerp(-1f, 1f, rate);
|
gradationOffset = Mathf.Lerp(-1f, 1f, rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((gradationMode == GradationMode.Angle || gradationMode == GradationMode.AngleGradient)
|
||||||
|
&& 0 < (mask & UIEffectTweener.CullingMask.GradiationRotation))
|
||||||
|
{
|
||||||
|
gradationRotation = Mathf.Lerp(0f, 360f, rate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
|
public override bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
|
||||||
@@ -993,6 +1018,7 @@ namespace Coffee.UIEffects
|
|||||||
m_GradationGradient = c.gradationGradient;
|
m_GradationGradient = c.gradationGradient;
|
||||||
m_GradationOffset = c.gradationOffset;
|
m_GradationOffset = c.gradationOffset;
|
||||||
m_GradationScale = c.gradationScale;
|
m_GradationScale = c.gradationScale;
|
||||||
|
m_GradationRotation = c.gradationRotation;
|
||||||
|
|
||||||
m_AllowToModifyMeshShape = c.allowToModifyMeshShape;
|
m_AllowToModifyMeshShape = c.allowToModifyMeshShape;
|
||||||
|
|
||||||
|
|||||||
@@ -181,8 +181,8 @@ namespace Coffee.UIEffects
|
|||||||
public Gradient gradationGradient;
|
public Gradient gradationGradient;
|
||||||
public float gradationOffset;
|
public float gradationOffset;
|
||||||
public float gradationScale;
|
public float gradationScale;
|
||||||
|
public float gradationRotation;
|
||||||
private List<float> _keyTimes;
|
private List<float> _keyTimes;
|
||||||
private List<float> _splitTimes;
|
|
||||||
|
|
||||||
public bool allowToModifyMeshShape;
|
public bool allowToModifyMeshShape;
|
||||||
|
|
||||||
@@ -253,6 +253,7 @@ namespace Coffee.UIEffects
|
|||||||
gradationGradient = preset.gradationGradient;
|
gradationGradient = preset.gradationGradient;
|
||||||
gradationOffset = preset.gradationOffset;
|
gradationOffset = preset.gradationOffset;
|
||||||
gradationScale = preset.gradationScale;
|
gradationScale = preset.gradationScale;
|
||||||
|
gradationRotation = preset.gradationRotation;
|
||||||
|
|
||||||
allowToModifyMeshShape = preset.allowToModifyMeshShape;
|
allowToModifyMeshShape = preset.allowToModifyMeshShape;
|
||||||
}
|
}
|
||||||
@@ -442,6 +443,7 @@ namespace Coffee.UIEffects
|
|||||||
var offset = gradationOffset;
|
var offset = gradationOffset;
|
||||||
var scale = gradationScale;
|
var scale = gradationScale;
|
||||||
var grad = gradationGradient;
|
var grad = gradationGradient;
|
||||||
|
var rot = gradationRotation;
|
||||||
switch (gradationMode)
|
switch (gradationMode)
|
||||||
{
|
{
|
||||||
case GradationMode.Horizontal:
|
case GradationMode.Horizontal:
|
||||||
@@ -462,6 +464,10 @@ namespace Coffee.UIEffects
|
|||||||
case GradationMode.RadialDetail:
|
case GradationMode.RadialDetail:
|
||||||
GradientUtil.DoRadialGradient(verts, a, b, offset, scale, rect, m, 12);
|
GradientUtil.DoRadialGradient(verts, a, b, offset, scale, rect, m, 12);
|
||||||
break;
|
break;
|
||||||
|
case GradationMode.Angle:
|
||||||
|
m = Matrix4x4.Rotate(Quaternion.Euler(0, 0, rot)) * m;
|
||||||
|
GradientUtil.DoHorizontalGradient(verts, a, b, offset, scale, rect, m);
|
||||||
|
break;
|
||||||
case GradationMode.HorizontalGradient:
|
case GradationMode.HorizontalGradient:
|
||||||
{
|
{
|
||||||
if (_keyTimes == null)
|
if (_keyTimes == null)
|
||||||
@@ -503,6 +509,30 @@ namespace Coffee.UIEffects
|
|||||||
{
|
{
|
||||||
GradientUtil.DoVerticalGradient(verts, grad, offset, scale, rect, m);
|
GradientUtil.DoVerticalGradient(verts, grad, offset, scale, rect, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GradationMode.AngleGradient:
|
||||||
|
{
|
||||||
|
if (_keyTimes == null)
|
||||||
|
{
|
||||||
|
_keyTimes = InternalListPool<float>.Rent();
|
||||||
|
GradientUtil.GetKeyTimes(grad, _keyTimes);
|
||||||
|
}
|
||||||
|
|
||||||
|
m = Matrix4x4.Rotate(Quaternion.Euler(0, 0, rot)) * m;
|
||||||
|
if (allowToModifyMeshShape)
|
||||||
|
{
|
||||||
|
var splitTimes = InternalListPool<float>.Rent();
|
||||||
|
GradientUtil.SplitKeyTimes(_keyTimes, splitTimes, offset, scale);
|
||||||
|
GradientUtil.DoAngleGradient(verts, grad, splitTimes, offset, scale, rect, m);
|
||||||
|
InternalListPool<float>.Return(ref splitTimes);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GradientUtil.DoHorizontalGradient(verts, grad, offset, scale, rect, m);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ namespace Coffee.UIEffects
|
|||||||
Color = 1 << 1,
|
Color = 1 << 1,
|
||||||
Sampling = 1 << 2,
|
Sampling = 1 << 2,
|
||||||
Transition = 1 << 3,
|
Transition = 1 << 3,
|
||||||
Gradiation = 1 << 5
|
GradiationOffset = 1 << 5,
|
||||||
|
GradiationRotation = 1 << 6
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum UpdateMode
|
public enum UpdateMode
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace Coffee.UIEffects
|
|||||||
UIVertexUtil.GetQuad(verts, i, out var lb, out var lt, out var rt, out var rb);
|
UIVertexUtil.GetQuad(verts, i, out var lb, out var lt, out var rt, out var rb);
|
||||||
if (i + 5 < count)
|
if (i + 5 < count)
|
||||||
{
|
{
|
||||||
UIVertexUtil.SplitHorizontal(verts, splitTimes, lb, lt, ref rb, ref rt, rect, m);
|
UIVertexUtil.SplitHorizontalFast(verts, splitTimes, lb, lt, ref rb, ref rt, rect, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
lb.color *= Evaluate(gradient, rect, m.MultiplyPoint3x4(lb.position).x + 0.0005f, offset, scale);
|
lb.color *= Evaluate(gradient, rect, m.MultiplyPoint3x4(lb.position).x + 0.0005f, offset, scale);
|
||||||
@@ -51,7 +51,7 @@ namespace Coffee.UIEffects
|
|||||||
Rect rect, Matrix4x4 m)
|
Rect rect, Matrix4x4 m)
|
||||||
{
|
{
|
||||||
var count = verts.Count;
|
var count = verts.Count;
|
||||||
for (var i = 0; i < count; i ++)
|
for (var i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
var vt = verts[i];
|
var vt = verts[i];
|
||||||
vt.color *= Evaluate(gradient, rect, m.MultiplyPoint3x4(vt.position).x, offset, scale);
|
vt.color *= Evaluate(gradient, rect, m.MultiplyPoint3x4(vt.position).x, offset, scale);
|
||||||
@@ -90,7 +90,7 @@ namespace Coffee.UIEffects
|
|||||||
UIVertexUtil.GetQuad(verts, i, out var lb, out var lt, out var rt, out var rb);
|
UIVertexUtil.GetQuad(verts, i, out var lb, out var lt, out var rt, out var rb);
|
||||||
if (i + 5 < count)
|
if (i + 5 < count)
|
||||||
{
|
{
|
||||||
UIVertexUtil.SplitVertical(verts, splitTimes, lb, ref lt, rb, ref rt, rect, m);
|
UIVertexUtil.SplitVerticalFast(verts, splitTimes, lb, ref lt, rb, ref rt, rect, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
lb.color *= Evaluate(gradient, rect, m.MultiplyPoint3x4(lb.position).y + 0.0005f, offset, scale);
|
lb.color *= Evaluate(gradient, rect, m.MultiplyPoint3x4(lb.position).y + 0.0005f, offset, scale);
|
||||||
@@ -114,7 +114,7 @@ namespace Coffee.UIEffects
|
|||||||
Rect rect, Matrix4x4 m)
|
Rect rect, Matrix4x4 m)
|
||||||
{
|
{
|
||||||
var count = verts.Count;
|
var count = verts.Count;
|
||||||
for (var i = 0; i < count; i ++)
|
for (var i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
var vt = verts[i];
|
var vt = verts[i];
|
||||||
vt.color *= Evaluate(gradient, rect, m.MultiplyPoint3x4(vt.position).y, offset, scale);
|
vt.color *= Evaluate(gradient, rect, m.MultiplyPoint3x4(vt.position).y, offset, scale);
|
||||||
@@ -215,6 +215,13 @@ namespace Coffee.UIEffects
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void DoAngleGradient(List<UIVertex> verts, Gradient gradient, List<float> splitTimes,
|
||||||
|
float offset, float scale, Rect rect, Matrix4x4 m)
|
||||||
|
{
|
||||||
|
UIVertexUtil.SplitAngle(verts, splitTimes, rect, m);
|
||||||
|
DoHorizontalGradient(verts, gradient, offset, scale, rect, m);
|
||||||
|
}
|
||||||
|
|
||||||
public static void GetKeyTimes(Gradient gradient, List<float> results)
|
public static void GetKeyTimes(Gradient gradient, List<float> results)
|
||||||
{
|
{
|
||||||
results.Clear();
|
results.Clear();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Coffee.UIEffectInternal;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Coffee.UIEffects
|
namespace Coffee.UIEffects
|
||||||
@@ -79,14 +80,16 @@ namespace Coffee.UIEffects
|
|||||||
|
|
||||||
public static UIVertex VertexLerp(UIVertex a, UIVertex b, float t)
|
public static UIVertex VertexLerp(UIVertex a, UIVertex b, float t)
|
||||||
{
|
{
|
||||||
var vt = new UIVertex();
|
var vt = new UIVertex
|
||||||
vt.position = Vector3.Lerp(a.position, b.position, t);
|
{
|
||||||
vt.normal = Vector3.Lerp(a.normal, b.normal, t);
|
position = Vector3.Lerp(a.position, b.position, t),
|
||||||
vt.tangent = Vector4.Lerp(a.tangent, b.tangent, t);
|
normal = Vector3.Lerp(a.normal, b.normal, t),
|
||||||
vt.color = Color.Lerp(a.color, b.color, t);
|
tangent = Vector4.Lerp(a.tangent, b.tangent, t),
|
||||||
vt.uv0 = Vector4.Lerp(a.uv0, b.uv0, t);
|
color = Color.Lerp(a.color, b.color, t),
|
||||||
vt.uv1 = Vector4.Lerp(a.uv1, b.uv1, t);
|
uv0 = Vector4.Lerp(a.uv0, b.uv0, t),
|
||||||
vt.uv2 = Vector4.Lerp(a.uv2, b.uv2, t);
|
uv1 = Vector4.Lerp(a.uv1, b.uv1, t),
|
||||||
|
uv2 = Vector4.Lerp(a.uv2, b.uv2, t)
|
||||||
|
};
|
||||||
|
|
||||||
if (onLerpVertex != null)
|
if (onLerpVertex != null)
|
||||||
{
|
{
|
||||||
@@ -143,7 +146,7 @@ namespace Coffee.UIEffects
|
|||||||
verts[i + 4] = rb;
|
verts[i + 4] = rb;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SplitHorizontal(List<UIVertex> verts, List<float> times, UIVertex lb, UIVertex lt,
|
public static void SplitHorizontalFast(List<UIVertex> verts, List<float> times, UIVertex lb, UIVertex lt,
|
||||||
ref UIVertex rb, ref UIVertex rt, Rect rect, Matrix4x4 m)
|
ref UIVertex rb, ref UIVertex rt, Rect rect, Matrix4x4 m)
|
||||||
{
|
{
|
||||||
if (times == null || times.Count == 0) return;
|
if (times == null || times.Count == 0) return;
|
||||||
@@ -176,7 +179,7 @@ namespace Coffee.UIEffects
|
|||||||
rb = mb;
|
rb = mb;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SplitVertical(List<UIVertex> verts, List<float> times, UIVertex lb, ref UIVertex lt,
|
public static void SplitVerticalFast(List<UIVertex> verts, List<float> times, UIVertex lb, ref UIVertex lt,
|
||||||
UIVertex rb, ref UIVertex rt, Rect rect, Matrix4x4 m)
|
UIVertex rb, ref UIVertex rt, Rect rect, Matrix4x4 m)
|
||||||
{
|
{
|
||||||
if (times == null || times.Count == 0) return;
|
if (times == null || times.Count == 0) return;
|
||||||
@@ -206,5 +209,94 @@ namespace Coffee.UIEffects
|
|||||||
lt = lm;
|
lt = lm;
|
||||||
rt = rm;
|
rt = rm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SplitAngle(List<UIVertex> verts, List<float> times, Rect rect, Matrix4x4 m)
|
||||||
|
{
|
||||||
|
if (times == null || times.Count == 0) return;
|
||||||
|
|
||||||
|
for (var i = 0; i < times.Count; i++)
|
||||||
|
{
|
||||||
|
var x = Mathf.Lerp(rect.xMin, rect.xMax, times[i]);
|
||||||
|
Split(verts, new Vector2(x, 0), new Vector2(0, 1), m);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
static void Split(List<UIVertex> verts, Vector2 p, Vector2 dir, Matrix4x4 m)
|
||||||
|
{
|
||||||
|
// Each triangle
|
||||||
|
var intersections = InternalListPool<UIVertex>.Rent();
|
||||||
|
var count = verts.Count;
|
||||||
|
for (var i = 0; i < count; i += 3)
|
||||||
|
{
|
||||||
|
intersections.Clear();
|
||||||
|
var n = -1;
|
||||||
|
// Each edge
|
||||||
|
for (var j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
var start = verts[i + j];
|
||||||
|
var end = verts[i + (j + 1) % 3];
|
||||||
|
|
||||||
|
if (DoesIntersect(start, end, p, dir, m, out var intersection))
|
||||||
|
{
|
||||||
|
intersections.Add(intersection);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
n = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (intersections.Count == 2)
|
||||||
|
{
|
||||||
|
var vt0 = verts[i + (n + 2) % 3];
|
||||||
|
var vt1 = verts[i + (n + 0) % 3];
|
||||||
|
var vt2 = verts[i + (n + 1) % 3];
|
||||||
|
var it0 = intersections[0];
|
||||||
|
var it1 = intersections[1];
|
||||||
|
var it2 = intersections[(n + 1) % 2];
|
||||||
|
verts[i + 0] = vt0;
|
||||||
|
verts[i + 1] = it0;
|
||||||
|
verts[i + 2] = it1;
|
||||||
|
verts.Add(it2);
|
||||||
|
verts.Add(vt1);
|
||||||
|
verts.Add(vt2);
|
||||||
|
verts.Add(vt2);
|
||||||
|
verts.Add(it0);
|
||||||
|
verts.Add(it1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
InternalListPool<UIVertex>.Return(ref intersections);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool DoesIntersect(UIVertex start, UIVertex end, Vector2 p, Vector2 dir, Matrix4x4 m,
|
||||||
|
out UIVertex intersection)
|
||||||
|
{
|
||||||
|
intersection = default;
|
||||||
|
var startPosition = (Vector2)m.MultiplyPoint3x4(start.position);
|
||||||
|
var endPosition = (Vector2)m.MultiplyPoint3x4(end.position);
|
||||||
|
var segDir = endPosition - startPosition;
|
||||||
|
var cross = Vector3.Cross(segDir, dir);
|
||||||
|
|
||||||
|
// Parallel.
|
||||||
|
if (cross.magnitude < Mathf.Epsilon)
|
||||||
|
{
|
||||||
|
return false; // 線と線分が平行
|
||||||
|
}
|
||||||
|
|
||||||
|
var diff = p - startPosition;
|
||||||
|
var determinant = Vector3.Dot(cross, cross);
|
||||||
|
var t = Vector3.Dot(Vector3.Cross(diff, dir), cross) / determinant;
|
||||||
|
|
||||||
|
if (0 <= t && t <= 1)
|
||||||
|
{
|
||||||
|
intersection = VertexLerp(start, end, t);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user