Browse Source

增加模拟墙体属性

DGJ 1 year ago
parent
commit
646230c6d9

+ 86 - 1
Assets/FrameWork/ProjectManager/Scripts/Project/XunJian/XunJianDataManager.cs

@@ -64,7 +64,7 @@ public class XunJianDataManager : Singleton<XunJianDataManager>
         xj.projectTime = "2023/11/23 10:53 ";
         xj.renwuModelType = RenWuModelType.None;
         xj.itemList = getRenwuData();
-
+        xj.listWall = getWallData();
         return xj;
     }
     List<RenWuItem> getRenwuData()
@@ -242,6 +242,76 @@ public class XunJianDataManager : Singleton<XunJianDataManager>
         }
         return itemlist;
     }
+
+    List<Wall> getWallData()
+    {
+        List<Wall> listWall = new List<Wall>();
+
+        for (int i = 0; i < 6; i++)
+        {
+            switch (i)
+            {
+                case 0:
+                    Wall wall = new Wall();
+                    wall.listPoint.Add(new Vector3(-5, 0, 0.25f));
+                    wall.listPoint.Add(new Vector3(5, 0, 0.25f));
+                    wall.listPoint.Add(new Vector3(5, 0, -0.25f));
+                    wall.listPoint.Add(new Vector3(-5, 0, -0.25f));
+                    listWall.Add(wall);
+                    break;
+
+                case 1:
+                    Wall wall1 = new Wall();
+                    wall1.listPoint.Add(new Vector3(-5, 0, -4.75f));
+                    wall1.listPoint.Add(new Vector3(5, 0, -4.75f));
+                    wall1.listPoint.Add(new Vector3(5, 0, -5.25f));
+                    wall1.listPoint.Add(new Vector3(-5, 0, -5.25f));
+                    listWall.Add(wall1);
+                    break;
+
+                case 2:
+                    Wall wall2 = new Wall();
+                    wall2.listPoint.Add(new Vector3(-5.25f, 0, 0));
+                    wall2.listPoint.Add(new Vector3(-4.75f, 0, 0));
+                    wall2.listPoint.Add(new Vector3(-4.75f, 0, -5));
+                    wall2.listPoint.Add(new Vector3(-5.25f, 0, -5));
+                    listWall.Add(wall2);
+                    break;
+
+                case 3:
+                    Wall wall3 = new Wall();
+                    wall3.listPoint.Add(new Vector3(4.75f, 0, 0));
+                    wall3.listPoint.Add(new Vector3(5.25f, 0, 0));
+                    wall3.listPoint.Add(new Vector3(5.25f, 0, -5));
+                    wall3.listPoint.Add(new Vector3(4.75f, 0, -5));
+                    listWall.Add(wall3);
+                    break;
+
+                case 4:
+                    Wall wall4 = new Wall();
+                    wall4.listPoint.Add(new Vector3(-2.75f, 0, -1f));
+                    wall4.listPoint.Add(new Vector3(-2.25f, 0, -1f));
+                    wall4.listPoint.Add(new Vector3(-2.25f, 0, -3f));
+                    wall4.listPoint.Add(new Vector3(-2.75f, 0, -3f));
+                    listWall.Add(wall4);
+                    break;
+
+                case 5:
+                    Wall wall5 = new Wall();
+                    wall5.listPoint.Add(new Vector3(2.25f, 0, -2));
+                    wall5.listPoint.Add(new Vector3(2.75f, 0, -2));
+                    wall5.listPoint.Add(new Vector3(2.75f, 0, -4));
+                    wall5.listPoint.Add(new Vector3(2.25f, 0, -4));
+                    listWall.Add(wall5);
+                    break;
+
+                default:
+                    break;
+            }
+        }
+
+        return listWall;
+    }
     IEnumerator testBack(Action<List<XunJianListData>> callback)
     {
         yield return WindowsManager.Instance.StartCoroutine(HttpTool.Instance.SendHttp(HttpEdustryAction.InspectionList, "", (string msg) =>
@@ -289,6 +359,7 @@ public class XunJianDataManager : Singleton<XunJianDataManager>
             xj.projectType = ((ProjectType)data[i].type).ToString();
             xj.projectTime = data[i].inspectionTime.ToString();
             xj.updateState = data[i].status > 2 ? "已更新" : "新项目";
+            xj.listWall = data[i].listWall;
             listData.Add(xj);
         }
 
@@ -308,6 +379,7 @@ public class XunJianDataManager : Singleton<XunJianDataManager>
         public List<RenWuItem> itemList;
         public RenWuModelType renwuModelType;
         public string url;
+        public List<Wall> listWall;
     }
 
     public class XunJianData
@@ -320,6 +392,8 @@ public class XunJianDataManager : Singleton<XunJianDataManager>
         public int status { get; set; }
         public int inspectionTime { get; set; }
         public List<EmployeesData> listEmployees { get; set; }
+
+        public List<Wall> listWall { get; set; }
     }
     public class EmployeesData
     {
@@ -391,6 +465,8 @@ public class XunJianDataManager : Singleton<XunJianDataManager>
         public string imageUrl;
         public ImageFileSourceData imageData;
         public RenWuState state = RenWuState.None;
+
+        
     }
     public class RenWuTypeModel
     {
@@ -399,6 +475,15 @@ public class XunJianDataManager : Singleton<XunJianDataManager>
         public string url;
         public string info;
     }
+
+    public class Wall
+    {
+        public List<Vector3> listPoint { get; set; }
+        public Wall()
+        {
+            listPoint = new List<Vector3>();
+        }
+    }
     public enum RenWuState
     {
         None = 100001, // 未处理

+ 1 - 1
Assets/FrameWork/Scenes/Edustry.unity

@@ -38,7 +38,7 @@ RenderSettings:
   m_ReflectionIntensity: 1
   m_CustomReflection: {fileID: 0}
   m_Sun: {fileID: 0}
-  m_IndirectSpecularColor: {r: 0.44402242, g: 0.49316543, b: 0.5722324, a: 1}
+  m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
   m_UseRadianceAmbientProbe: 0
 --- !u!157 &3
 LightmapSettings:

+ 1 - 1
Assets/FrameWork/墙体.prefab

@@ -25,7 +25,7 @@ Transform:
   m_GameObject: {fileID: 3649401808606158665}
   m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
   m_LocalPosition: {x: 0, y: 0, z: 0}
-  m_LocalScale: {x: 7.61, y: 2, z: 5.61}
+  m_LocalScale: {x: 1, y: 2, z: 1}
   m_ConstrainProportionsScale: 0
   m_Children:
   - {fileID: 3649401810370552673}

File diff suppressed because it is too large
+ 3056 - 157
Assets/Scenes/Test.unity


+ 101 - 0
Assets/Scripts/CreateWalls.cs

@@ -0,0 +1,101 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using static XunJianDataManager;
+
+public class CreateWalls : MonoBehaviour
+{
+    public GameObject Wall;
+    public List<Wall> listWall;
+    private void Start()
+    {
+        this.listWall = getWallData();
+
+        CreateWall(listWall);
+    }
+
+    List<Wall> getWallData()
+    {
+        List<Wall> listWall = new List<Wall>();
+
+        for (int i = 0; i < 6; i++)
+        {
+            switch (i)
+            {
+                case 0:
+                    Wall wall = new Wall();
+                    wall.listPoint.Add(new Vector3(-5, 0, 0.25f));
+                    wall.listPoint.Add(new Vector3(5, 0, 0.25f));
+                    wall.listPoint.Add(new Vector3(5, 0, -0.25f));
+                    wall.listPoint.Add(new Vector3(-5, 0, -0.25f));
+                    listWall.Add(wall);
+                    break;
+
+                case 1:
+                    Wall wall1 = new Wall();
+                    wall1.listPoint.Add(new Vector3(-5, 0, -4.75f));
+                    wall1.listPoint.Add(new Vector3(5, 0, -4.75f));
+                    wall1.listPoint.Add(new Vector3(5, 0, -5.25f));
+                    wall1.listPoint.Add(new Vector3(-5, 0, -5.25f));
+                    listWall.Add(wall1);
+                    break;
+
+                case 2:
+                    Wall wall2 = new Wall();
+                    wall2.listPoint.Add(new Vector3(-5.25f, 0, 0));
+                    wall2.listPoint.Add(new Vector3(-4.75f, 0, 0));
+                    wall2.listPoint.Add(new Vector3(-4.75f, 0, -5));
+                    wall2.listPoint.Add(new Vector3(-5.25f, 0, -5));
+                    listWall.Add(wall2);
+                    break;
+
+                case 3:
+                    Wall wall3 = new Wall();
+                    wall3.listPoint.Add(new Vector3(4.75f, 0, 0));
+                    wall3.listPoint.Add(new Vector3(5.25f, 0, 0));
+                    wall3.listPoint.Add(new Vector3(5.25f, 0, -5));
+                    wall3.listPoint.Add(new Vector3(4.75f, 0, -5));
+                    listWall.Add(wall3);
+                    break;
+
+                case 4:
+                    Wall wall4 = new Wall();
+                    wall4.listPoint.Add(new Vector3(-2.75f, 0, -1f));
+                    wall4.listPoint.Add(new Vector3(-2.25f, 0, -1f));
+                    wall4.listPoint.Add(new Vector3(-2.25f, 0, -3f));
+                    wall4.listPoint.Add(new Vector3(-2.75f, 0, -3f));
+                    listWall.Add(wall4);
+                    break;
+
+                case 5:
+                    Wall wall5 = new Wall();
+                    wall5.listPoint.Add(new Vector3(2.25f, 0, -2));
+                    wall5.listPoint.Add(new Vector3(2.75f, 0, -2));
+                    wall5.listPoint.Add(new Vector3(2.75f, 0, -4));
+                    wall5.listPoint.Add(new Vector3(2.25f, 0, -4));
+                    listWall.Add(wall5);
+                    break;
+
+                default:
+                    break;
+            }
+        }
+
+        return listWall;
+    }
+  
+    public void CreateWall( List<Wall> listWall)
+    {
+        for (int i = 0; i < listWall.Count; i++)
+        {
+            Transform wallObj = GameObject.Instantiate(Wall).transform;
+
+            wallObj.position = listWall[i].listPoint[0];
+
+            float x = Vector3.Distance(listWall[i].listPoint[0], listWall[i].listPoint[1]);
+            float y = Vector3.Distance(listWall[i].listPoint[0], listWall[i].listPoint[3]);
+
+            wallObj.localScale = new Vector3(x, 3, y);
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/CreateWalls.cs.meta

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

+ 101 - 0
Assets/Scripts/GameObjectExtensions.cs

@@ -0,0 +1,101 @@
+using UnityEngine;
+
+public static class GameObjectExtensions
+{
+    public static Bounds CalculatePreciseBounds(this GameObject gameObject)
+    {
+        Bounds bounds = new Bounds();
+        bool flag = false;
+        MeshFilter[] componentsInChildren1 = gameObject.GetComponentsInChildren<MeshFilter>();
+        if (componentsInChildren1.Length != 0)
+        {
+            bounds = GetMeshBounds(componentsInChildren1[0].gameObject, componentsInChildren1[0].sharedMesh);
+            flag = true;
+            for (int index = 1; index < componentsInChildren1.Length; ++index)
+                bounds.Encapsulate(GetMeshBounds(componentsInChildren1[index].gameObject,
+                    componentsInChildren1[index].sharedMesh));
+        }
+
+        SkinnedMeshRenderer[] componentsInChildren2 = gameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
+        if (componentsInChildren2.Length != 0)
+        {
+            Mesh mesh = new Mesh();
+            if (!flag)
+            {
+                componentsInChildren2[0].BakeMesh(mesh);
+                bounds = GetMeshBounds(componentsInChildren2[0].gameObject, mesh);
+            }
+
+            for (int index = 1; index < componentsInChildren2.Length; ++index)
+            {
+                componentsInChildren2[index].BakeMesh(mesh);
+                bounds = GetMeshBounds(componentsInChildren2[index].gameObject, mesh);
+            }
+
+            Object.Destroy(mesh);
+        }
+
+        return bounds;
+    }
+
+    private static Bounds GetMeshBounds(GameObject gameObject, Mesh mesh)
+    {
+        Bounds bounds = new Bounds();
+        Vector3[] vertices = mesh.vertices;
+        if (vertices.Length != 0)
+        {
+            bounds = new Bounds(gameObject.transform.TransformPoint(vertices[0]), Vector3.zero);
+            for (int index = 1; index < vertices.Length; ++index)
+                bounds.Encapsulate(gameObject.transform.TransformPoint(vertices[index]));
+        }
+
+        return bounds;
+    }
+
+    public static Bounds CalculateBounds(this GameObject gameObject, bool localSpace = false)
+    {
+        Vector3 position = gameObject.transform.position;
+        Quaternion rotation = gameObject.transform.rotation;
+        Vector3 localScale = gameObject.transform.localScale;
+        if (localSpace)
+        {
+            gameObject.transform.position = Vector3.zero;
+            gameObject.transform.rotation = Quaternion.identity;
+            gameObject.transform.localScale = Vector3.one;
+        }
+
+        Bounds bounds1 = new Bounds();
+        Renderer[] componentsInChildren = gameObject.GetComponentsInChildren<Renderer>();
+        if (componentsInChildren.Length != 0)
+        {
+            Bounds bounds2 = componentsInChildren[0].bounds;
+            bounds1.center = bounds2.center;
+            bounds1.extents = bounds2.extents;
+            for (int index = 1; index < componentsInChildren.Length; ++index)
+            {
+                Bounds bounds3 = componentsInChildren[index].bounds;
+                bounds1.Encapsulate(bounds3);
+            }
+        }
+
+        if (localSpace)
+        {
+            gameObject.transform.position = position;
+            gameObject.transform.rotation = rotation;
+            gameObject.transform.localScale = localScale;
+        }
+
+        return bounds1;
+    }
+
+    /// <summary>
+    /// 获取模型的Bounds
+    /// </summary>
+    /// <param name="gameObject"></param>
+    /// <returns></returns>
+    public static Bounds CalculateModelBounds(GameObject gameObject)
+    {
+        Bounds bounds = gameObject.CalculateBounds(false);
+        return bounds;
+    }
+}

+ 11 - 0
Assets/Scripts/GameObjectExtensions.cs.meta

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

+ 28 - 0
Assets/Scripts/TestWallPoint.cs

@@ -0,0 +1,28 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using static XunJianDataManager;
+
+public class TestWallPoint : MonoBehaviour
+{
+    public List<Transform> listPoint;
+    public List<Vector3> listpos;
+
+
+    private void Update()
+    {
+        if(Input.GetKeyDown(KeyCode.K))
+        {
+            listpos = new List<Vector3>();
+
+            for (int i = 0; i < listPoint.Count; i++)
+            {
+                listpos.Add(listPoint[i].position);
+
+            }
+        }
+    }
+
+
+   
+}

+ 11 - 0
Assets/Scripts/TestWallPoint.cs.meta

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

Some files were not shown because too many files changed in this diff