123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424 |
- using OpenCVForUnity.CoreModule;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace CScript.Entity
- {
- [System.Serializable]
- public class NetMeshData
- {
- public List<int> netColorList;
- public List<int> netFrontVertexList;
- public List<int> netSideVertexList;
- public List<int> netUvList;
- public List<byte> netTexture;
- public List<int> netFrontTriangles;
- public List<int> 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 ;
- /// <summary>
- /// 顶点
- /// </summary>
- public List<short> netAtlasVertexList;
- /// <summary>
- /// uv
- /// </summary>
- public List<ushort> netAtlasUVList;
- /// <summary>
- /// 三角形
- /// </summary>
- public List<int> netTrianglesList;
- /// <summary>
- /// nose顶点
- /// </summary>
- public List<short> netNoseVertexList;
- /// <summary>
- /// nose 颜色
- /// </summary>
- public List<short> netNoseColorList;
- /// <summary>
- /// nose三角顺序
- /// </summary>
- public List<int> netNoseTriangles;
- public NetMeshData()
- {
- netColorList = new List<int>();
- netFrontVertexList = new List<int>();
- netSideVertexList = new List<int>();
- netUvList = new List<int>();
- netTexture = new List<byte>();
- netFrontTriangles = new List<int>();
- netSideTriangles = new List<int>();
- netAtlasVertexList = new List<short>();
- netAtlasUVList = new List<ushort>();
- netTrianglesList = new List<int>();
- netNoseVertexList = new List<short>();
- netNoseColorList = new List<short>();
- netNoseTriangles = new List<int>();
- }
- 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<int> 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<short> 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<ushort> 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<int> 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<short> 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<ushort> 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<int> 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<ushort> 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<short> 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<int> atlasXyzRe = new List<int>();
- List<int> atlasIndRe = new List<int>();
- private (int[], int[]) SetVertexAndTriangle(List<short> atlasXyz,List<int> 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());
- }
-
- }
- }
|