当前位置:   article > 正文

Unity【Bounds & Vector3 Cross】- 如何判断一个物体是否在一个凸边体三维区域内_unity bounds检测

unity bounds检测

如图所示,本文介绍如何判断一个物体是否被一个凸边体区域所囊括,本文将该功能的实现拆分成了如下步骤:

1.如何判断两条线段是否相交

2.如何判断一个点是否在一个凸边形范围内(2D、xz轴构成的平面)

3.如何判断一个点是否在一个凸边体范围内(3D)

4.如何判断一个物体是否在一个凸边体范围内

依次实现:

1.如何判断两条线段是否相交:

通过矢量叉积的符号可以判断两矢量相互之间的顺逆时针关系,如下图所示,点A和点B分别在线段CD两侧,点C和点D分别在线段AB两侧,这时可以判断它们相交。判断点A和点B是否在线段CD两侧,也就是判断向量A-D和向量B-D在向量C-D的两侧,也就是叉积的结果是异号的,即:(A-D)X(C-D)*(B-D)X(C-D)< 0。同样的,判断点C和点B是否在线段AB的两侧:(D-A)X(B-A)*(C-A)X(B-A)< 0,以上这两个条件成立时,可判断两线段相交。

当然,出现以下这种情况,即(A-D)X(C-D)*(B-D)X(C-D)= 0时,两条线段也是相交的:

Unity中封装该判断函数:

  1. //判断AB与CD是否相交
  2. private bool IsIntersection(Vector3 A, Vector3 B, Vector3 C, Vector3 D)
  3. {
  4. //A-D与C-D叉积结果大等于0时返回1 小于0时返回-1
  5. float sign1 = Mathf.Sign(Vector3.Cross(A - D, C - D).y);
  6. //B-D与C-D叉积结果大等于0时返回1 小于0时返回-1
  7. float sign2 = Mathf.Sign(Vector3.Cross(B - D, C - D).y);
  8. //C-A与B-A叉积结果大等于0时返回1 小于0时返回-1
  9. float sign3 = Mathf.Sign(Vector3.Cross(C - A, B - A).y);
  10. //D-A与B-A叉积结果大等于0时返回1 小于0时返回-1
  11. float sign4 = Mathf.Sign(Vector3.Cross(D - A, B - A).y);
  12. //AB与CD相交返回true 否则返回false
  13. return !Mathf.Approximately(sign1, sign2) && !Mathf.Approximately(sign3, sign4);
  14. }

 

 测试脚本如下:

  1. using UnityEngine;
  2. using UnityEditor;
  3. public class Example : MonoBehaviour
  4. {
  5. [SerializeField] private Transform a;
  6. [SerializeField] private Transform b;
  7. [SerializeField] private Transform c;
  8. [SerializeField] private Transform d;
  9. //判断AB与CD是否相交
  10. private bool IsIntersection(Vector3 A, Vector3 B, Vector3 C, Vector3 D)
  11. {
  12. //A-D与C-D叉积结果大等于0时返回1 小于0时返回-1
  13. float sign1 = Mathf.Sign(Vector3.Cross(A - D, C - D).y);
  14. //B-D与C-D叉积结果大等于0时返回1 小于0时返回-1
  15. float sign2 = Mathf.Sign(Vector3.Cross(B - D, C - D).y);
  16. //C-A与B-A叉积结果大等于0时返回1 小于0时返回-1
  17. float sign3 = Mathf.Sign(Vector3.Cross(C - A, B - A).y);
  18. //D-A与B-A叉积结果大等于0时返回1 小于0时返回-1
  19. float sign4 = Mathf.Sign(Vector3.Cross(D - A, B - A).y);
  20. //AB与CD相交返回true 否则返回false
  21. return !Mathf.Approximately(sign1, sign2) && !Mathf.Approximately(sign3, sign4);
  22. }
  23. private void OnDrawGizmos()
  24. {
  25. if (a == null || b == null || c == null || d == null) return;
  26. Handles.Label(a.position, "A");
  27. Handles.Label(b.position, "B");
  28. Handles.Label(c.position, "C");
  29. Handles.Label(d.position, "D");
  30. bool flag = IsIntersection(a.position, b.position, c.position, d.position);
  31. Handles.color = flag ? Color.cyan : Color.red;
  32. Handles.DrawLine(a.position, b.position);
  33. Handles.DrawLine(c.position, d.position);
  34. }
  35. }

2.如何判断一个点是否在一个凸边形范围内(2D、xz轴构成的平面):

若从该点发出的射线与平面内凸边形的交点的个数为偶数,则点在凸边形外,若为奇数,则点在凸边形内。因此取一条从该点向凸边形发出的射线,遍历凸边形的每一条边,判断射线与边的交点个数,若个数为奇数,则可以判断该点在凸边形范围内。

  1. //判断点A是否在凸边型范围内
  2. private bool IsInRange(Transform[] points, Vector3 A)
  3. {
  4. //取第一条边中点
  5. Vector3 half01 = (points[0].position + points[1].position) * .5f;
  6. //中点延伸(射线)
  7. half01 += (half01 - A).normalized * 100000;
  8. //用于记录交点的个数
  9. int count = 0;
  10. //遍历
  11. for (int i = 0; i < points.Length; i++)
  12. {
  13. var a = points[i % points.Length];
  14. var b = points[(i + 1) % points.Length];
  15. //判断是否相交
  16. if (IsIntersection(a.position, b.position, A, half01)) count++;
  17. }
  18. //交点个数为奇数则表示点A在凸边型范围内
  19. return count % 2 == 1;
  20. }

测试代码如下:

  1. using UnityEngine;
  2. using UnityEditor;
  3. public class Example : MonoBehaviour
  4. {
  5. [SerializeField] private Transform point;
  6. [SerializeField] private Transform[] points; //凸边型顶点集合
  7. //判断点A是否在凸边型范围内
  8. private bool IsInRange(Transform[] points, Vector3 A)
  9. {
  10. //取第一条边中点
  11. Vector3 half01 = (points[0].position + points[1].position) * .5f;
  12. //中点延伸(射线)
  13. half01 += (half01 - A).normalized * 100000;
  14. //用于记录交点的个数
  15. int count = 0;
  16. //遍历
  17. for (int i = 0; i < points.Length; i++)
  18. {
  19. var a = points[i % points.Length];
  20. var b = points[(i + 1) % points.Length];
  21. //判断是否相交
  22. if (IsIntersection(a.position, b.position, A, half01)) count++;
  23. }
  24. //交点个数为奇数则表示点A在凸边型范围内
  25. return count % 2 == 1;
  26. }
  27. //判断AB与CD是否相交
  28. private bool IsIntersection(Vector3 A, Vector3 B, Vector3 C, Vector3 D)
  29. {
  30. //A-D与C-D叉积结果大等于0时返回1 小于0时返回-1
  31. float sign1 = Mathf.Sign(Vector3.Cross(A - D, C - D).y);
  32. //B-D与C-D叉积结果大等于0时返回1 小于0时返回-1
  33. float sign2 = Mathf.Sign(Vector3.Cross(B - D, C - D).y);
  34. //C-A与B-A叉积结果大等于0时返回1 小于0时返回-1
  35. float sign3 = Mathf.Sign(Vector3.Cross(C - A, B - A).y);
  36. //D-A与B-A叉积结果大等于0时返回1 小于0时返回-1
  37. float sign4 = Mathf.Sign(Vector3.Cross(D - A, B - A).y);
  38. //AB与CD相交返回true 否则返回false
  39. return !Mathf.Approximately(sign1, sign2) && !Mathf.Approximately(sign3, sign4);
  40. }
  41. private void OnDrawGizmos()
  42. {
  43. if (points.Length < 3 || point == null) return;
  44. bool flag = IsInRange(points, point.position);
  45. Handles.Label(point.position, "A");
  46. Vector3 half01 = (points[0].position + points[1].position) * .5f;
  47. half01 += (half01 - point.position).normalized * 100000;
  48. for (int i = 0; i < points.Length; i++)
  49. {
  50. var a = points[i % points.Length];
  51. var b = points[(i + 1) % points.Length];
  52. Handles.color = flag ? Color.cyan : Color.red;
  53. Handles.DrawLine(a.position, b.position);
  54. Handles.Label(points[i].position, $"顶点{i + 1}");
  55. Handles.color = Color.yellow;
  56. if (IsIntersection(a.position, b.position, point.position, half01))
  57. {
  58. Handles.DrawLine(point.position, half01);
  59. }
  60. }
  61. }
  62. }

3.如何判断一个点是否在一个凸边体范围内(3D):

上述部分我们在xz轴所在的平面构建了一个凸边形,现在我们给其一个高度,即可构成一个凸边体空间区域:

要判断一个点是否在该凸边体范围内,只需要在满足处于xz轴所在的凸边形范围内的同时,其坐标点的y值既小等于凸边体height高度值的一半,又大等于负的高度值的一半:

封装判断函数:

  1. //判断点A是否在凸边体范围内
  2. private bool IsInRange(Transform[] points, float height, Vector3 A)
  3. {
  4. bool flag = true;
  5. flag &= A.y <= height * .5f;
  6. flag &= A.y >= -height * .5f;
  7. flag &= IsInRange(points, A);
  8. return flag;
  9. }

 

测试代码如下:

  1. using UnityEngine;
  2. using UnityEditor;
  3. public class Example : MonoBehaviour
  4. {
  5. [SerializeField] private Transform point;
  6. [SerializeField] private Transform[] points; //凸边型顶点集合
  7. [SerializeField] private float height = 1f;
  8. //判断点A是否在凸边体范围内
  9. private bool IsInRange(Transform[] points, float height, Vector3 A)
  10. {
  11. bool flag = true;
  12. flag &= A.y <= height * .5f;
  13. flag &= A.y >= -height * .5f;
  14. flag &= IsInRange(points, A);
  15. return flag;
  16. }
  17. //判断点A是否在凸边型范围内
  18. private bool IsInRange(Transform[] points, Vector3 A)
  19. {
  20. //取第一条边中点
  21. Vector3 half01 = (points[0].position + points[1].position) * .5f;
  22. //中点延伸(射线)
  23. half01 += (half01 - A).normalized * 100000;
  24. //用于记录交点的个数
  25. int count = 0;
  26. //遍历
  27. for (int i = 0; i < points.Length; i++)
  28. {
  29. var a = points[i % points.Length];
  30. var b = points[(i + 1) % points.Length];
  31. //判断是否相交
  32. if (IsIntersection(a.position, b.position, A, half01)) count++;
  33. }
  34. //交点个数为奇数则表示点A在凸边型范围内
  35. return count % 2 == 1;
  36. }
  37. //判断AB与CD是否相交
  38. private bool IsIntersection(Vector3 A, Vector3 B, Vector3 C, Vector3 D)
  39. {
  40. //A-D与C-D叉积结果大等于0时返回1 小于0时返回-1
  41. float sign1 = Mathf.Sign(Vector3.Cross(A - D, C - D).y);
  42. //B-D与C-D叉积结果大等于0时返回1 小于0时返回-1
  43. float sign2 = Mathf.Sign(Vector3.Cross(B - D, C - D).y);
  44. //C-A与B-A叉积结果大等于0时返回1 小于0时返回-1
  45. float sign3 = Mathf.Sign(Vector3.Cross(C - A, B - A).y);
  46. //D-A与B-A叉积结果大等于0时返回1 小于0时返回-1
  47. float sign4 = Mathf.Sign(Vector3.Cross(D - A, B - A).y);
  48. //AB与CD相交返回true 否则返回false
  49. return !Mathf.Approximately(sign1, sign2) && !Mathf.Approximately(sign3, sign4);
  50. }
  51. private void OnDrawGizmos()
  52. {
  53. if (points.Length < 3 || point == null) return;
  54. bool flag = IsInRange(points, height, point.position);
  55. Handles.color = flag ? Color.cyan : Color.red;
  56. Handles.Label(point.position, "A");
  57. for (int i = 0; i < points.Length; i++)
  58. {
  59. Handles.Label(points[i].position - new Vector3(0, height * .5f, 0), $"顶点{i + 1}");
  60. Handles.Label(points[i].position + new Vector3(0, height * .5f, 0), $"顶点{i + 1 + points.Length}");
  61. var a = points[i % points.Length];
  62. var b = points[(i + 1) % points.Length];
  63. var minA = a.position - new Vector3(0, height * .5f, 0);
  64. var maxA = a.position + new Vector3(0, height * .5f, 0);
  65. var minB = b.position - new Vector3(0, height * .5f, 0);
  66. var maxB = b.position + new Vector3(0, height * .5f, 0);
  67. Handles.DrawAAPolyLine(minA, minB);
  68. Handles.DrawAAPolyLine(maxA, maxB);
  69. Handles.DrawAAPolyLine(minA, maxA);
  70. Handles.DrawAAPolyLine(minB, maxB);
  71. }
  72. }
  73. }

4.如何判断一个物体是否在一个凸边体范围内: 

上述部分判断的是一个坐标点是否在一个凸边体范围内,要判断一个物体是否被该凸边体区域所囊括,需要获取该物体及其子物体构成的Bounds边界盒,如果Bounds边界盒的每一个顶点都在该凸边体范围内,则可以大致推断该物体被这个凸边体所囊括,当然要想更精确还是要获取该物体的更为精确的边界点,在这里不做延申。

首先来看Unity圣典中关于Bounds边界盒及其核心变量的介绍:

其中max、min分别是最大、最小点,可以通过这两点获取到其它各顶点的坐标,测试代码如下:

  1. using UnityEngine;
  2. using UnityEditor;
  3. public class Example : MonoBehaviour
  4. {
  5. [SerializeField] private GameObject obj;
  6. private void OnDrawGizmos()
  7. {
  8. if (obj == null) return;
  9. Bounds bounds = obj.GetComponent<MeshRenderer>().bounds;
  10. Vector3 point1 = bounds.min;
  11. Vector3 point2 = bounds.max;
  12. Vector3 point3 = new Vector3(point1.x, point1.y, point2.z);
  13. Vector3 point4 = new Vector3(point1.x, point2.y, point1.z);
  14. Vector3 point5 = new Vector3(point2.x, point1.y, point1.z);
  15. Vector3 point6 = new Vector3(point1.x, point2.y, point2.z);
  16. Vector3 point7 = new Vector3(point2.x, point1.y, point2.z);
  17. Vector3 point8 = new Vector3(point2.x, point2.y, point1.z);
  18. Handles.DrawLine(point6, point2);
  19. Handles.DrawLine(point2, point8);
  20. Handles.DrawLine(point8, point4);
  21. Handles.DrawLine(point4, point6);
  22. Handles.DrawLine(point3, point7);
  23. Handles.DrawLine(point7, point5);
  24. Handles.DrawLine(point5, point1);
  25. Handles.DrawLine(point1, point3);
  26. Handles.DrawLine(point6, point3);
  27. Handles.DrawLine(point2, point7);
  28. Handles.DrawLine(point8, point5);
  29. Handles.DrawLine(point4, point1);
  30. Handles.Label(point1, "顶点1");
  31. Handles.Label(point2, "顶点2");
  32. Handles.Label(point3, "顶点3");
  33. Handles.Label(point4, "顶点4");
  34. Handles.Label(point5, "顶点5");
  35. Handles.Label(point6, "顶点6");
  36. Handles.Label(point7, "顶点7");
  37. Handles.Label(point8, "顶点8");
  38. }
  39. }

一个物体可能包含若干个带有MeshRenderer组件的子物体,因此我们要获取一个囊括所有的Bounds边界盒,要使用到Bounds类中的Encapsulate函数:

  1. using UnityEngine;
  2. using UnityEditor;
  3. public class Example : MonoBehaviour
  4. {
  5. [SerializeField] private GameObject obj;
  6. private void OnDrawGizmos()
  7. {
  8. if (obj == null) return;
  9. Bounds bounds = new Bounds(Vector3.zero, Vector3.zero);
  10. //获取所有MeshRenderer 包括子物体
  11. var mrs = obj.GetComponentsInChildren<MeshRenderer>(true);
  12. Vector3 center = Vector3.zero;
  13. for (int i = 0; i < mrs.Length; i++)
  14. {
  15. center += mrs[i].bounds.center;
  16. //Encapsulate函数重新计算bounds
  17. bounds.Encapsulate(mrs[i].bounds);
  18. }
  19. Vector3 point1 = bounds.min;
  20. Vector3 point2 = bounds.max;
  21. Vector3 point3 = new Vector3(point1.x, point1.y, point2.z);
  22. Vector3 point4 = new Vector3(point1.x, point2.y, point1.z);
  23. Vector3 point5 = new Vector3(point2.x, point1.y, point1.z);
  24. Vector3 point6 = new Vector3(point1.x, point2.y, point2.z);
  25. Vector3 point7 = new Vector3(point2.x, point1.y, point2.z);
  26. Vector3 point8 = new Vector3(point2.x, point2.y, point1.z);
  27. Handles.DrawLine(point6, point2);
  28. Handles.DrawLine(point2, point8);
  29. Handles.DrawLine(point8, point4);
  30. Handles.DrawLine(point4, point6);
  31. Handles.DrawLine(point3, point7);
  32. Handles.DrawLine(point7, point5);
  33. Handles.DrawLine(point5, point1);
  34. Handles.DrawLine(point1, point3);
  35. Handles.DrawLine(point6, point3);
  36. Handles.DrawLine(point2, point7);
  37. Handles.DrawLine(point8, point5);
  38. Handles.DrawLine(point4, point1);
  39. Handles.Label(point1, "顶点1");
  40. Handles.Label(point2, "顶点2");
  41. Handles.Label(point3, "顶点3");
  42. Handles.Label(point4, "顶点4");
  43. Handles.Label(point5, "顶点5");
  44. Handles.Label(point6, "顶点6");
  45. Handles.Label(point7, "顶点7");
  46. Handles.Label(point8, "顶点8");
  47. }
  48. }

封装判断函数:

  1. //判断一个物体是否在凸边体范围内
  2. private bool IsInRange(Transform[] points, float height, GameObject obj)
  3. {
  4. Bounds bounds = new Bounds(Vector3.zero, Vector3.zero);
  5. //获取所有MeshRenderer 包括子物体
  6. var mrs = obj.GetComponentsInChildren<MeshRenderer>(true);
  7. Vector3 center = Vector3.zero;
  8. for (int i = 0; i < mrs.Length; i++)
  9. {
  10. center += mrs[i].bounds.center;
  11. //Encapsulate函数重新计算bounds
  12. bounds.Encapsulate(mrs[i].bounds);
  13. }
  14. Vector3 min = bounds.min;
  15. Vector3 max = bounds.max;
  16. return IsInRange(points, height, min)
  17. && IsInRange(points, height, max)
  18. && IsInRange(points, height, new Vector3(min.x, min.y, max.z))
  19. && IsInRange(points, height, new Vector3(min.x, max.y, min.z))
  20. && IsInRange(points, height, new Vector3(max.x, min.y, min.z))
  21. && IsInRange(points, height, new Vector3(min.x, max.y, max.z))
  22. && IsInRange(points, height, new Vector3(max.x, min.y, max.z))
  23. && IsInRange(points, height, new Vector3(max.x, max.y, min.z));
  24. }

测试代码如下:

  1. using UnityEngine;
  2. using UnityEditor;
  3. public class Example : MonoBehaviour
  4. {
  5. [SerializeField] private GameObject obj;
  6. [SerializeField] private Transform[] points; //凸边型顶点集合
  7. [SerializeField] private float height = 1f;
  8. //判断一个物体是否在凸边体范围内
  9. private bool IsInRange(Transform[] points, float height, GameObject obj)
  10. {
  11. Bounds bounds = new Bounds(Vector3.zero, Vector3.zero);
  12. //获取所有MeshRenderer 包括子物体
  13. var mrs = obj.GetComponentsInChildren<MeshRenderer>(true);
  14. Vector3 center = Vector3.zero;
  15. for (int i = 0; i < mrs.Length; i++)
  16. {
  17. center += mrs[i].bounds.center;
  18. //Encapsulate函数重新计算bounds
  19. bounds.Encapsulate(mrs[i].bounds);
  20. }
  21. Vector3 min = bounds.min;
  22. Vector3 max = bounds.max;
  23. return IsInRange(points, height, min)
  24. && IsInRange(points, height, max)
  25. && IsInRange(points, height, new Vector3(min.x, min.y, max.z))
  26. && IsInRange(points, height, new Vector3(min.x, max.y, min.z))
  27. && IsInRange(points, height, new Vector3(max.x, min.y, min.z))
  28. && IsInRange(points, height, new Vector3(min.x, max.y, max.z))
  29. && IsInRange(points, height, new Vector3(max.x, min.y, max.z))
  30. && IsInRange(points, height, new Vector3(max.x, max.y, min.z));
  31. }
  32. //判断点A是否在凸边体范围内
  33. private bool IsInRange(Transform[] points, float height, Vector3 A)
  34. {
  35. bool flag = true;
  36. flag &= A.y <= height * .5f;
  37. flag &= A.y >= -height * .5f;
  38. flag &= IsInRange(points, A);
  39. return flag;
  40. }
  41. //判断点A是否在凸边型范围内
  42. private bool IsInRange(Transform[] points, Vector3 A)
  43. {
  44. //取第一条边中点
  45. Vector3 half01 = (points[0].position + points[1].position) * .5f;
  46. //中点延伸(射线)
  47. half01 += (half01 - A).normalized * 100000;
  48. //用于记录交点的个数
  49. int count = 0;
  50. //遍历
  51. for (int i = 0; i < points.Length; i++)
  52. {
  53. var a = points[i % points.Length];
  54. var b = points[(i + 1) % points.Length];
  55. //判断是否相交
  56. if (IsIntersection(a.position, b.position, A, half01)) count++;
  57. }
  58. //交点个数为奇数则表示点A在凸边型范围内
  59. return count % 2 == 1;
  60. }
  61. //判断AB与CD是否相交
  62. private bool IsIntersection(Vector3 A, Vector3 B, Vector3 C, Vector3 D)
  63. {
  64. //A-D与C-D叉积结果大等于0时返回1 小于0时返回-1
  65. float sign1 = Mathf.Sign(Vector3.Cross(A - D, C - D).y);
  66. //B-D与C-D叉积结果大等于0时返回1 小于0时返回-1
  67. float sign2 = Mathf.Sign(Vector3.Cross(B - D, C - D).y);
  68. //C-A与B-A叉积结果大等于0时返回1 小于0时返回-1
  69. float sign3 = Mathf.Sign(Vector3.Cross(C - A, B - A).y);
  70. //D-A与B-A叉积结果大等于0时返回1 小于0时返回-1
  71. float sign4 = Mathf.Sign(Vector3.Cross(D - A, B - A).y);
  72. //AB与CD相交返回true 否则返回false
  73. return !Mathf.Approximately(sign1, sign2) && !Mathf.Approximately(sign3, sign4);
  74. }
  75. private void OnDrawGizmos()
  76. {
  77. if (points.Length < 3 || obj == null) return;
  78. bool flag = IsInRange(points, height, obj);
  79. Handles.color = flag ? Color.cyan : Color.red;
  80. for (int i = 0; i < points.Length; i++)
  81. {
  82. Handles.Label(points[i].position - new Vector3(0, height * .5f, 0), $"顶点{i + 1}");
  83. Handles.Label(points[i].position + new Vector3(0, height * .5f, 0), $"顶点{i + 1 + points.Length}");
  84. var a = points[i % points.Length];
  85. var b = points[(i + 1) % points.Length];
  86. var minA = a.position - new Vector3(0, height * .5f, 0);
  87. var maxA = a.position + new Vector3(0, height * .5f, 0);
  88. var minB = b.position - new Vector3(0, height * .5f, 0);
  89. var maxB = b.position + new Vector3(0, height * .5f, 0);
  90. Handles.DrawAAPolyLine(minA, minB);
  91. Handles.DrawAAPolyLine(maxA, maxB);
  92. Handles.DrawAAPolyLine(minA, maxA);
  93. Handles.DrawAAPolyLine(minB, maxB);
  94. }
  95. Bounds bounds = new Bounds(Vector3.zero, Vector3.zero);
  96. //获取所有MeshRenderer 包括子物体
  97. var mrs = obj.GetComponentsInChildren<MeshRenderer>(true);
  98. Vector3 center = Vector3.zero;
  99. for (int i = 0; i < mrs.Length; i++)
  100. {
  101. center += mrs[i].bounds.center;
  102. //Encapsulate函数重新计算bounds
  103. bounds.Encapsulate(mrs[i].bounds);
  104. }
  105. Vector3 point1 = bounds.min;
  106. Vector3 point2 = bounds.max;
  107. Vector3 point3 = new Vector3(point1.x, point1.y, point2.z);
  108. Vector3 point4 = new Vector3(point1.x, point2.y, point1.z);
  109. Vector3 point5 = new Vector3(point2.x, point1.y, point1.z);
  110. Vector3 point6 = new Vector3(point1.x, point2.y, point2.z);
  111. Vector3 point7 = new Vector3(point2.x, point1.y, point2.z);
  112. Vector3 point8 = new Vector3(point2.x, point2.y, point1.z);
  113. Handles.color = Color.yellow;
  114. Handles.DrawLine(point6, point2);
  115. Handles.DrawLine(point2, point8);
  116. Handles.DrawLine(point8, point4);
  117. Handles.DrawLine(point4, point6);
  118. Handles.DrawLine(point3, point7);
  119. Handles.DrawLine(point7, point5);
  120. Handles.DrawLine(point5, point1);
  121. Handles.DrawLine(point1, point3);
  122. Handles.DrawLine(point6, point3);
  123. Handles.DrawLine(point2, point7);
  124. Handles.DrawLine(point8, point5);
  125. Handles.DrawLine(point4, point1);
  126. }
  127. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/390792
推荐阅读
相关标签
  

闽ICP备14008679号