using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; using CScript.Net; using OpenCVForUnity.UnityUtils; using OpenCVForUnity.CoreModule; using OpenCVForUnity.ImgprocModule; namespace CScript.Entity { [System.Serializable] public class MeshData { public List frontDataList; public List sideDataList; public Texture2D texture; public int[] frontTriangles; public int[] sideTriangles; private Vector3[] _frontVertexList; private Vector3[] _sideVertexList; private Vector2[] _uvList; private Color[] _colorList; public MeshData(NetMeshData netMeshData) { //Debug.Log("new meshData "); if (netMeshData == null) return; texture = Utilities.AppUtil.ByteToTex2d(netMeshData.netTexture.ToArray()); // OpenCVForUnity.CoreModule.Mat ymat = new OpenCVForUnity.CoreModule.Mat(1280, 720, CvType.CV_8UC3); //ymat.put(0,0, netMeshData.texture.ToArray()); //Imgproc.cvtColor(ymat, uvMat, Imgproc.COLOR_YUV2BGR_I420); //Utils.matToTexture2D(uvMat, texture); //texture = netMeshData.texture1; //texture = netMeshData.texture; frontTriangles = netMeshData.netFrontTriangles.ToArray(); sideTriangles = netMeshData.netSideTriangles.ToArray(); _frontVertexList = GetVector3(netMeshData.netFrontVertexList); _sideVertexList = GetVector3(netMeshData.netSideVertexList); _uvList = GetVector2(netMeshData.netUvList); _colorList = GetColor(netMeshData.netColorList); } public MeshData(NetMessage nm) { //CaoTintRequest caoTintRequest = nm.Request.Caoting; //texture = Utilities.AppUtil.ByteToTex2d(caoTintRequest.Texture); ////texture = netMeshData.texture; //frontTriangles = caoTintRequest.frontTriangles; //sideTriangles = caoTintRequest.sideTriangles; //_frontVertexList = GetVector3(caoTintRequest.frontVertexLists); //_sideVertexList = GetVector3(caoTintRequest.sideVertexLists); //_uvList = GetVector2(caoTintRequest.uvLists); ////_colorList = GetColor(caoTintRequest.colorList); } 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 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; } public Vector3[] frontVertexList { get { if (_frontVertexList == null) { _frontVertexList = new Vector3[frontDataList.Count]; for (int i = 0, count = frontDataList.Count; i < count; i++) { _frontVertexList[i] = frontDataList[i].vertex; } } return _frontVertexList; } } public Vector3[] sideVertexList { get { if (_sideVertexList == null) { _sideVertexList = new Vector3[sideDataList.Count]; for (int i = 0, count = sideDataList.Count; i < count; i++) { _sideVertexList[i] = sideDataList[i].vertex; } } return _sideVertexList; } } public Color[] colorList { get { if (_colorList == null) { _colorList = new Color[sideDataList.Count]; for (int i = 0, count = sideDataList.Count; i < count; i++) { _colorList[i] = sideDataList[i].vertexColor; } } return _colorList; } } public Vector2[] uvList { get { if (_uvList == null) { _uvList = new Vector2[frontDataList.Count]; for (int i = 0, count = frontDataList.Count; i < count; i++) { _uvList[i] = frontDataList[i].uv; } } return _uvList; } } public MeshData() { frontDataList = new List(); sideDataList = new List(); } } }