123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using UnityEngine;
- using XRTool.Util;
- public class GetZeroPos : MonoBehaviour
- {
- public Transform arMap;
- void Start()
- {
- TimerMgr.Instance.CreateTimer(()=> { // 获取MeshFilter组件
- MeshFilter meshFilter = arMap.GetComponent<MeshFilter>();
- if (meshFilter != null)
- {
- // 获取Mesh
- Mesh mesh = meshFilter.mesh;
- // 获取所有顶点
- Vector3[] vertices = mesh.vertices;
- // 初始化最小坐标值为第一个顶点的坐标
- Vector3 minPoint = vertices[0];
- // 找到最小的X、Y和Z坐标值
- for (int i = 1; i < vertices.Length; i++)
- {
- Vector3 vertex = vertices[i];
- minPoint.x = Mathf.Min(minPoint.x, vertex.x);
- minPoint.y = Mathf.Min(minPoint.y, vertex.y);
- minPoint.z = Mathf.Min(minPoint.z, vertex.z);
- }
- // 最小坐标值就是网格的零点
- Debug.Log("Mesh的零点:" + minPoint);
- }
- else
- {
- Debug.LogError("未找到MeshFilter组件");
- }
- },1,-1);
- }
- }
|