using OpenCVForUnity.CoreModule; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace CScript.Entity { [System.Serializable] public class NetMeshData { public List netColorList; public List netFrontVertexList; public List netSideVertexList; public List netUvList; public List netTexture; public List netFrontTriangles; public List netSideTriangles; private Vector3[] _frontVertexList; private Vector3[] _sideVertexList; private Vector2[] _uvList; private Color[] _colorList; private int[] _triangles1; private int[] _triangles2; public int width ; public int height ; /// /// 顶点 /// public List netAtlasVertexList; /// /// uv /// public List netAtlasUVList; /// /// 三角形 /// public List netTrianglesList; /// /// nose顶点 /// public List netNoseVertexList; /// /// nose 颜色 /// public List netNoseColorList; /// /// nose三角顺序 /// public List netNoseTriangles; public NetMeshData() { netColorList = new List(); netFrontVertexList = new List(); netSideVertexList = new List(); netUvList = new List(); netTexture = new List(); netFrontTriangles = new List(); netSideTriangles = new List(); netAtlasVertexList = new List(); netAtlasUVList = new List(); netTrianglesList = new List(); netNoseVertexList = new List(); netNoseColorList = new List(); netNoseTriangles = new List(); } public void Clear() { netColorList.Clear(); netColorList.TrimExcess(); netFrontVertexList.Clear(); netFrontVertexList.TrimExcess(); netSideVertexList.Clear(); netSideVertexList.TrimExcess(); netUvList.Clear(); netUvList.TrimExcess(); netTexture.Clear(); netTexture.TrimExcess(); netFrontTriangles.Clear(); netFrontTriangles.TrimExcess(); netSideTriangles.Clear(); netSideTriangles.TrimExcess(); _frontVertexList = null; _sideVertexList = null; _uvList = null; _colorList = null; _triangles1 = null; _triangles2 = null; netAtlasVertexList.Clear(); netAtlasVertexList.TrimExcess(); netAtlasUVList.Clear(); netAtlasUVList.TrimExcess(); netTrianglesList.Clear(); netTrianglesList.TrimExcess(); netNoseVertexList.Clear(); netNoseVertexList.TrimExcess(); netNoseColorList.Clear(); netNoseColorList.TrimExcess(); netNoseTriangles.Clear(); netNoseTriangles.TrimExcess(); } int[] tempIntArray; public Vector3[] frontVertexList { get { if (_frontVertexList == null) { if (App.AppConfig.isNewMeshData) { (tempIntArray, _triangles1) = SetVertexAndTriangle(netAtlasVertexList, netTrianglesList); _frontVertexList = GetVector3(tempIntArray); } else { _frontVertexList = GetVector3(netFrontVertexList); } } return _frontVertexList; } } public Vector3[] sideVertexList { get { if (_sideVertexList == null) { if (App.AppConfig.isNewMeshData) { _sideVertexList = GetVector3(netNoseVertexList); } else { _sideVertexList = GetVector3(netSideVertexList); } } return _sideVertexList; } } public Color[] colorList { get { if (_colorList == null) { if (App.AppConfig.isNewMeshData) { _colorList = GetColor(netNoseColorList); } else { _colorList = GetColor(netColorList); } } return _colorList; } } Vector2[] v2Array; public Vector2[] uvList { get { if (_uvList == null) { if (App.AppConfig.isNewMeshData) { v2Array = GetVector2(netAtlasUVList); //_uvList = GetVector2(netAtlasUVList); _uvList = new Vector2[v2Array.Length]; for (int i = 0, count = v2Array.Length; i < count; i++) { if (i % 3 == 0) { _uvList[i] = v2Array[i + 2]; } else if (i % 3 == 1) { _uvList[i] = v2Array[i - 1]; } else if (i % 3 == 2) { _uvList[i] = v2Array[i - 1]; } } } else { _uvList = GetVector2(netUvList); } } return _uvList; } } public int[] Triangles1 { get { if (_triangles1 == null || _triangles1.Length==0) { if (App.AppConfig.isNewMeshData) { (tempIntArray, _triangles1) = SetVertexAndTriangle(netAtlasVertexList, netTrianglesList); } else { _triangles1 = netFrontTriangles.ToArray(); } } return _triangles1; } } public int[] Triangles2 { get { if (_triangles2 == null || _triangles2.Length ==0) { if (App.AppConfig.isNewMeshData) { _triangles2 = netNoseTriangles.ToArray(); } else { _triangles2 = netSideTriangles.ToArray(); } } return _triangles2; } } private Vector3[] GetVector3(IList vales) { Vector3[] vector3s = new Vector3[vales.Count / 3]; for (int index = 0; index < vales.Count / 3; index++) { Vector3 vector3 = new Vector3(); vector3.x = vales[index * 3 + 0] / 10000.0f; vector3.y = vales[index * 3 + 1] / 10000.0f; vector3.z = vales[index * 3 + 2] / 10000.0f; vector3s[index] = vector3; } return vector3s; } private Vector3[] GetVector3(int[] vales) { Vector3[] vector3s = new Vector3[vales.Length / 3]; for (int index = 0; index < vales.Length / 3; index++) { Vector3 vector3 = new Vector3(); vector3.x = vales[index * 3 + 0] / 10000.0f; vector3.y = vales[index * 3 + 1] / 10000.0f; vector3.z = vales[index * 3 + 2] / 10000.0f; vector3s[index] = vector3; } return vector3s; } private Vector3[] GetVector3(List vales) { Vector3[] vector3s = new Vector3[vales.Count / 3]; for (int index = 0; index < vales.Count / 3; index++) { Vector3 vector3 = new Vector3(); vector3.x = vales[index * 3 + 0] / 10000.0f; vector3.y = vales[index * 3 + 1] / 10000.0f; vector3.z = vales[index * 3 + 2] / 10000.0f; vector3s[index] = vector3; } return vector3s; } private Vector3[] GetVector3(List vales) { Vector3[] vector3s = new Vector3[vales.Count / 3]; for (int index = 0; index < vales.Count / 3; index++) { Vector3 vector3 = new Vector3(); vector3.x = vales[index * 3 + 0] / 10000.0f; vector3.y = vales[index * 3 + 1] / 10000.0f; vector3.z = vales[index * 3 + 2] / 10000.0f; vector3s[index] = vector3; } return vector3s; } private Vector2[] GetVector2(List vales) { Vector2[] vector2s = new Vector2[vales.Count / 2]; for (int index = 0; index < vales.Count / 2; index++) { Vector2 vector2 = new Vector2(); vector2.x = vales[index * 2 + 0] / 10000.0f; vector2.y = -vales[index * 2 + 1] / 10000.0f; vector2s[index] = vector2; } return vector2s; } private Vector2[] GetVector2(List vales) { Vector2[] vector2s = new Vector2[vales.Count / 2]; for (int index = 0; index < vales.Count / 2; index++) { Vector2 vector2 = new Vector2(); vector2.x = vales[index * 2 + 0] / 10000.0f; vector2.y = vales[index * 2 + 1] / 10000.0f; vector2s[index] = vector2; } return vector2s; } private Vector2[] GetVector2(List vales) { Vector2[] vector2s = new Vector2[vales.Count / 2]; for (int index = 0; index < vales.Count / 2; index++) { Vector2 vector2 = new Vector2(); vector2.x = vales[index * 2 + 0] / 10000.0f; vector2.y = 1 - (vales[index * 2 + 1] / 10000.0f); vector2s[index] = vector2; } return vector2s; } private Color[] GetColor(List vales) { Color[] colors = new Color[vales.Count / 3]; for (int index = 0; index < vales.Count / 3; index++) { Color color = new Color(); //color.r = vales[index * 3 + 0] / 10000.0f; //color.g = vales[index * 3 + 1] / 10000.0f; //color.b = vales[index * 3 + 2] / 10000.0f; color.b = vales[index * 3 + 0] / 10000.0f; color.g = vales[index * 3 + 1] / 10000.0f; color.r = vales[index * 3 + 2] / 10000.0f; color.a = 1; colors[index]=color; } return colors; } private Color[] GetColor(List vales) { Color[] colors = new Color[vales.Count / 3]; for (int index = 0; index < vales.Count / 3; index++) { Color color = new Color(); color.r = vales[index * 3 + 0] / 10000.0f; color.g = vales[index * 3 + 1] / 10000.0f; color.b = vales[index * 3 + 2] / 10000.0f; color.a = 1; colors[index] = color; } return colors; } private Color[] GetColor(List vales) { Color[] colors = new Color[vales.Count / 3]; for (int index = 0; index < vales.Count / 3; index++) { Color color = new Color(); color.b = vales[index * 3 + 0] / 10000.0f; color.g = vales[index * 3 + 1] / 10000.0f; color.r = vales[index * 3 + 2] / 10000.0f; color.a = 1; colors[index] = color; } return colors; } List atlasXyzRe = new List(); List atlasIndRe = new List(); private (int[], int[]) SetVertexAndTriangle(List atlasXyz,List atlasInd) { atlasXyzRe.Clear(); atlasXyzRe.Capacity = atlasInd.Count * 3; atlasIndRe.Clear(); atlasIndRe.Capacity = atlasInd.Count; for (int i = 0,count= atlasInd.Count; i < count; i++) { atlasXyzRe.Add(atlasXyz[atlasInd[i] * 3 + 0]); atlasXyzRe.Add(atlasXyz[atlasInd[i] * 3 + 1]); atlasXyzRe.Add(atlasXyz[atlasInd[i] * 3 + 2]); atlasIndRe.Add(i); } return (atlasXyzRe.ToArray(),atlasIndRe.ToArray()); } } }