Browse Source

新增公式

胡佳骏 1 year ago
parent
commit
f69cfc0bd4

+ 0 - 0
Assets/CheckIsUse.cs → Assets/Script/CheckIsUse.cs


+ 0 - 0
Assets/CheckIsUse.cs.meta → Assets/Script/CheckIsUse.cs.meta


+ 42 - 0
Assets/Script/GetZeroPos.cs

@@ -0,0 +1,42 @@
+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);
+
+    }
+}

+ 11 - 0
Assets/Script/GetZeroPos.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: a2ee836adfd28b44fb9f7a75b4139e96
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 88 - 0
Assets/Script/GongShi2.cs

@@ -0,0 +1,88 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+
+public class GongShi2 : MonoBehaviour
+{
+    public static float ff = 0;
+    public static Vector3 vp3;
+
+    public static Vector3 ve3;
+    public static void F2Dto3D(float x2, float y2, float th,float tw, float x22, float y22,float sceneLength, float sceneWidth)
+    {
+        GameManager.Instance.StartCoroutine(startjisuan(x2,y2,th,tw,x22,y22, sceneLength, sceneWidth));
+
+
+
+    }
+    public static GameObject WebPosObj;
+    public static GameObject WebPosObj2;
+    static IEnumerator startjisuan(float x2, float y2, float th, float tw, float x22, float y22, float sceneLength, float sceneWidth)
+    {
+        Transform parent = (SceneIOCContainer.Instance.Pull("mesh_test") as GameObject).transform;
+
+        parent.transform.localPosition = Vector3.zero;
+        parent.transform.eulerAngles = Vector3.zero;
+
+        if (WebPosObj == null)
+            WebPosObj = new GameObject();
+
+        if (WebPosObj2 == null)
+            WebPosObj2 = new GameObject();
+
+        //  Transform meshTestParent =(SceneIOCContainer.Instance.Pull("ARSpaceForAll") as GameObject).transform;
+        //创建空锚点GameObject
+        GameObject go = WebPosObj;
+        go.transform.parent = parent.parent;
+        Vector2 p1 = new Vector2(x2 / tw * sceneLength, (th - (y2)) / th * sceneWidth);
+        Vector2 p2 = Vector2.zero - p1;
+        Vector3 newPosition = new Vector3(p2.x, 0, p2.y);
+        parent.localPosition = newPosition;
+        yield return new WaitForSeconds(0.1f);
+        go.transform.localPosition = Vector3.zero;
+        parent.parent = go.transform;
+        yield return new WaitForSeconds(0.1f);
+        //创建空锚点 朝向
+        p1 = new Vector2(x22 / tw * sceneLength, (th - (y22)) / th * sceneWidth);
+        p2 = Vector2.zero - p1;
+        newPosition = new Vector3(-p2.x, 0, -p2.y);
+        GameObject go2 = WebPosObj2;
+        go2.transform.parent = parent;
+        go2.transform.localPosition = newPosition;
+        yield return new WaitForSeconds(0.1f);
+        go2.transform.parent = go.transform.parent;
+        yield return new WaitForSeconds(0.1f);
+      //  go.transform.parent = parent.parent;
+     //   yield return new WaitForSeconds(0.1f);
+        //把当前物体设置到锚点内
+      //  yield return new WaitForSeconds(0.1f);
+        go.transform.LookAt(go2.transform);
+        go.transform.localEulerAngles = new Vector3(0, 360-go.transform.localEulerAngles.y, 0);
+        yield return new WaitForSeconds(0.1f);
+        //设置回来
+        parent.parent = go.transform.parent;
+
+        yield return new WaitForSeconds(0.1f);
+        //  Destroy(go);
+        //  Destroy(go2);
+        WebPosObj.transform.parent = parent;
+        WebPosObj2.transform.parent = parent;
+    }
+
+
+    public static List<Vector2> GetWebPos(float th, float tw, float sceneLength, float sceneWidth)
+    {
+        Transform parent = (SceneIOCContainer.Instance.Pull("mesh_test") as GameObject).transform;
+      //  WebPosObj.transform.parent = parent.parent;
+      //  WebPosObj2.transform.parent = parent.parent;
+        List<Vector2> lvlist = new List<Vector2>();
+        Vector2 p1 = new Vector2(Mathf.Abs(WebPosObj.transform.localPosition.x / sceneLength * tw  ), Mathf.Abs(th-((WebPosObj.transform.localPosition.z) / sceneWidth * th  )));
+        lvlist.Add(p1);
+        Vector2 p2 = new Vector2(Mathf.Abs(WebPosObj2.transform.localPosition.x / sceneLength * tw ), Mathf.Abs(th-((WebPosObj2.transform.localPosition.z )/ sceneWidth * th  )));
+        lvlist.Add(p2);
+        Debug.Log("Web端Pos  :" + p1);
+        Debug.Log("Web端Pos 2 :" + p2);
+        return lvlist;
+    }
+}

+ 11 - 0
Assets/Script/GongShi2.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 3ce90193f496eab4a99c6193ac0b16da
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 0 - 0
Assets/ShowTipTime.cs → Assets/Script/ShowTipTime.cs


+ 0 - 0
Assets/ShowTipTime.cs.meta → Assets/Script/ShowTipTime.cs.meta


+ 11 - 1
Assets/Scripts/Blue/Controller/SavePanel.cs

@@ -49,12 +49,22 @@ public class SavePanel : AbstractController
             posRotlist = new List<ScenePosRotInfo>();
             posRotlist.Add(pos); posRotlist.Add(rot);
         }
-        posRotlist[0].x = meshTest.localPosition.x;
+      /*  posRotlist[0].x = meshTest.localPosition.x;
         posRotlist[0].y = meshTest.localPosition.y;
         posRotlist[0].z = meshTest.localPosition.z;
         posRotlist[1].x = meshTest.localEulerAngles.x;
         posRotlist[1].y = meshTest.localEulerAngles.y;
         posRotlist[1].z = meshTest.localEulerAngles.z;
+        string jsonString = JsonConvert.SerializeObject(posRotlist);*/
+
+        List<Vector2>  poslist=  GongShi2.GetWebPos(GameManager.Instance.WebMapSize.y, GameManager.Instance.WebMapSize.x, DataManager.Instance.CurrentScene.length, DataManager.Instance.CurrentScene.width);
+
+        posRotlist[0].x = poslist[0].x;
+        posRotlist[0].y = poslist[0].y;
+        posRotlist[0].z = 0;
+        posRotlist[1].x = poslist[1].x;
+        posRotlist[1].y = poslist[1].y;
+        posRotlist[1].z = 0;
         string jsonString = JsonConvert.SerializeObject(posRotlist);
         this.SendCommand(new PointPosRotUploadCommand(URL, jsonString));
     }

+ 15 - 5
Assets/Scripts/Blue/Service/IUpOrDownloadService.cs

@@ -7,6 +7,7 @@ using System.Collections.Generic;
 using System.Text;
 using UnityEngine;
 using UnityEngine.Networking;
+using XRTool.Util;
 
 public interface IUpOrDownloadService : IService
 {
@@ -23,12 +24,16 @@ public class UpOrDownloadService : IUpOrDownloadService
 
     public void OnInit()
     {
+       // UrlPointCloudPosRot = "http://192.168.50.114:8888/mr-navigator/v1/project/position";
         UrlPointCloudPosRot = "https://api-fat3.ghz-tech.com/mr-navigator/v1/project/position";
+
     }
 
     void IUpOrDownloadService.GetScenePosRot(int projectID)
     {
+      //  TimerMgr.Instance.CreateTimer(()=> {
         CoroutineSystem.Instance.StartCoroutine(GetScenePosRotRequest(projectID));
+     //   },3,-1);
     }
 
     void IUpOrDownloadService.UploadScenePosRot(string Url, string JsonString)
@@ -43,7 +48,7 @@ public class UpOrDownloadService : IUpOrDownloadService
             ProjectID = projectID;
             ScenePointBodyInfo TestGet = new ScenePointBodyInfo();
             TestGet.id = projectID;
-            TestGet.unity = true;
+            TestGet.unity = false;
             string jsonData = JsonConvert.SerializeObject(TestGet);
             byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonData);
 
@@ -68,9 +73,14 @@ public class UpOrDownloadService : IUpOrDownloadService
                         message = jobject["data"].ToString();
                         if (!string.IsNullOrWhiteSpace(message))
                         {
-                            List<ScenePosRotInfo> ScenePosRotInfoList = JsonConvert.DeserializeObject<List<ScenePosRotInfo>>(message);
-                            PosRot = ScenePosRotInfoList;
-                            this.SendEvent(new GetScenePosRotEvent() { PosRot = PosRot });
+                           // TimerMgr.Instance.CreateTimer(() => {
+                                List<ScenePosRotInfo> ScenePosRotInfoList = JsonConvert.DeserializeObject<List<ScenePosRotInfo>>(message);
+
+                            //  GongShi2.F2Dto3D(ScenePosRotInfoList[0].x, ScenePosRotInfoList[0].y, 643f, 1920f, ScenePosRotInfoList[1].x, ScenePosRotInfoList[1].y, 51f, 17.1f);
+                            
+                                GongShi2.F2Dto3D(ScenePosRotInfoList[0].x, ScenePosRotInfoList[0].y, GameManager.Instance.WebMapSize.y, GameManager.Instance.WebMapSize.x, ScenePosRotInfoList[1].x, ScenePosRotInfoList[1].y, DataManager.Instance.CurrentScene.length, DataManager.Instance.CurrentScene.width);
+                 
+                         //  },0.03f,-1);
                         }
                     }
                 }
@@ -86,7 +96,7 @@ public class UpOrDownloadService : IUpOrDownloadService
             JsonData d2 = new JsonData();
             d2["position"] = data;
             d2["id"] = ProjectID;
-            d2["unity"] = true;
+            d2["unity"] = false;
             byte[] bodyRaw = Encoding.UTF8.GetBytes(d2.ToJson());
 
             webRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);