GetZeroPos.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using UnityEngine;
  2. using XRTool.Util;
  3. public class GetZeroPos : MonoBehaviour
  4. {
  5. public Transform arMap;
  6. void Start()
  7. {
  8. TimerMgr.Instance.CreateTimer(()=> { // 获取MeshFilter组件
  9. MeshFilter meshFilter = arMap.GetComponent<MeshFilter>();
  10. if (meshFilter != null)
  11. {
  12. // 获取Mesh
  13. Mesh mesh = meshFilter.mesh;
  14. // 获取所有顶点
  15. Vector3[] vertices = mesh.vertices;
  16. // 初始化最小坐标值为第一个顶点的坐标
  17. Vector3 minPoint = vertices[0];
  18. // 找到最小的X、Y和Z坐标值
  19. for (int i = 1; i < vertices.Length; i++)
  20. {
  21. Vector3 vertex = vertices[i];
  22. minPoint.x = Mathf.Min(minPoint.x, vertex.x);
  23. minPoint.y = Mathf.Min(minPoint.y, vertex.y);
  24. minPoint.z = Mathf.Min(minPoint.z, vertex.z);
  25. }
  26. // 最小坐标值就是网格的零点
  27. Debug.Log("Mesh的零点:" + minPoint);
  28. }
  29. else
  30. {
  31. Debug.LogError("未找到MeshFilter组件");
  32. }
  33. },1,-1);
  34. }
  35. }