From 6568595abbd1f5aaec6a9d395735a54c5b9beecf Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Mon, 18 Nov 2024 23:14:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96`Line`=E5=9C=A8=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=82=B9=E8=BF=87=E5=AF=86=E6=97=B6=E6=9C=89=E6=9B=B4?= =?UTF-8?q?=E5=A5=BD=E7=9A=84=E7=BB=98=E5=88=B6=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation~/zh/changelog.md | 1 + Runtime/XUGL/UGLHelper.cs | 92 ++++++++++++++++++++++++++-------- 2 files changed, 73 insertions(+), 20 deletions(-) diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index fffcd187..76cd0c46 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -77,6 +77,7 @@ slug: /changelog ## master +* (2024.11.18) 优化`Line`在数据点过密时有更好的绘制效果 * (2024.11.16) 修复`Animation`无法通过代码开启的问题 (#334) * (2024.11.13) 修复`DataZoom`的start和end在代码动态修改时图表不刷新的问题 * (2024.11.05) 修复`Title`设置隐藏后运行还显示的问题 diff --git a/Runtime/XUGL/UGLHelper.cs b/Runtime/XUGL/UGLHelper.cs index a4d54a0d..07e56538 100644 --- a/Runtime/XUGL/UGLHelper.cs +++ b/Runtime/XUGL/UGLHelper.cs @@ -344,33 +344,85 @@ namespace XUGL return; } - var ldist = (Vector3.Distance(cp, lp) + 1) * dir1; - var rdist = (Vector3.Distance(cp, np) + 1) * dir2; + var ldist = (Vector3.Distance(cp, lp) + width) * dir1; + var rdist = (Vector3.Distance(cp, np) + width) * dir2; - bitp = true; - if (!UGLHelper.GetIntersection(ltp, ltp + ldist, ntp, ntp + rdist, ref itp)) + bitp = UGLHelper.GetIntersection(ltp, ltp + ldist, ntp, ntp + rdist, ref itp); + bibp = UGLHelper.GetIntersection(lbp, lbp + ldist, nbp, nbp + rdist, ref ibp); + if (bitp == bibp) { - itp = cp - dir1v; - clp = cp - dir1v; - crp = cp - dir2v; - bitp = false; + if (!bitp) + { + if (cp == np) + { + ltp = cp - dir1v; + clp = cp + dir1v; + crp = cp + dir1v; + } + else + { + Vector3 ibp2 = Vector3.zero; + if (UGLHelper.GetIntersection(lbp, lbp + ldist, ntp, nbp, ref ibp2)) + { + bibp = true; + ibp = ibp2; + clp = cp - dir1v; + crp = cp - dir2v; + } + else if (UGLHelper.GetIntersection(ltp, ltp + ldist, nbp, ntp, ref ibp2)) + { + bitp = true; + itp = ibp2; + clp = cp + dir1v; + crp = cp + dir2v; + } + else + { + if (IsUp(lp, cp, np)) + { + bibp = true; + + clp = cp - dir1v; + crp = cp - dir2v; + ibp = cp - Vector3.Cross((crp - clp).normalized, Vector3.back).normalized * width * 2f; + } + else + { + bitp = true; + clp = cp + dir1v; + crp = cp + dir2v; + itp = cp + Vector3.Cross((crp - clp).normalized, Vector3.back).normalized * width * 2f; + } + + } + } + } } - bibp = true; - if (!UGLHelper.GetIntersection(lbp, lbp + ldist, nbp, nbp + rdist, ref ibp)) + else { - ibp = cp + dir1v; - clp = cp + dir1v; - crp = cp + dir2v; - bibp = false; - } - if (bitp == false && bibp == false && cp == np) - { - ltp = cp - dir1v; - clp = cp + dir1v; - crp = cp + dir1v; + if (!bitp) + { + itp = cp; + clp = cp - dir1v; + crp = cp - dir2v; + } + else + { + ibp = cp; + clp = cp + dir1v; + crp = cp + dir2v; + } } } + public static bool IsUp(Vector3 p1, Vector3 p2, Vector3 p3) + { + var v1 = p1 - p2; + var v2 = p3 - p2; + var cross = v1.x * v2.y - v1.y * v2.x; + return cross > 0; + } + public static bool IsPointInTriangle(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 check) { var dire1 = check - p1;