123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- 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<VertexColorData> frontDataList;
- public List<VertexColorData> 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<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 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 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.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<VertexColorData>();
- sideDataList = new List<VertexColorData>();
- }
- }
- }
|