private void ConManager_ToCellMode() { showMode = Enums.ShowMode.Cell; }
private void DrawLine() { if (vtkAllFrame.loadFile.dataType == Enums.DataType.Water) { return; } int index = GlobalVariableBackground.Instance.FrameAllIndex % GlobalVariableBackground.Instance.modelCacheCount; if (lineModeIndex == GlobalVariableBackground.Instance.FrameAllIndex && listLineMesh.Count > 0 && isLineAndCell == false) { showMode = Enums.ShowMode.Line; return; } else if (lineModeIndex == GlobalVariableBackground.Instance.FrameAllIndex && listLineMesh.Count > 0 && isLineAndCell == true) { showMode = Enums.ShowMode.CellAndLine; return; } else { listLineMesh.Clear(); ms = new Mesh(); } lineModeIndex = GlobalVariableBackground.Instance.FrameAllIndex; Mesh mesh; for (int i = 0; i < vtkAllFrame.listFrame[index].meshArray.Length; i++) { mesh = vtkAllFrame.listFrame[index].go.transform.GetChild(i).GetComponent <MeshFilter>().mesh; int[] triArray = mesh.triangles; Vector3[] vecArray = mesh.vertices; for (int j = 0; j < triArray.Length;) { if (meshVec.Count > 65001 || meshTri.Count > 65001) { ms.SetVertices(meshVec); ms.triangles = meshTri.ToArray(); listLineMesh.Add(ms); meshVec = null; meshTri = null; ms = new Mesh(); meshVec = new List <Vector3>(); meshTri = new List <int>(); } //if ((j + 1) % 3 == 0) //{ // //画第三点与第一点之间的连线 // AddLineArray(meshVec, meshTri, MakeQuad(vecArray[triArray[j]], vecArray[triArray[j - 2]], 0.001f)); //} //else //{ // //画 第一点和第二点之间的连线或第二点与第三点之间的连线 // AddLineArray(meshVec, meshTri, MakeQuad(vecArray[triArray[j]], vecArray[triArray[j + 1]], 0.001f)); //} Vector3 v1 = transform.TransformPoint(vecArray[triArray[j++]]); Vector3 v2 = transform.TransformPoint(vecArray[triArray[j++]]); Vector3 v3 = transform.TransformPoint(vecArray[triArray[j++]]); //if (v1 != v2 && v2 != v3 && v3 != v1) //{ // GlobalVariableBackground.Instance.conManager.WriteLog(v1.x+","+v1.y+","+v1.z+" "+ v2.x + "," + v2.y + "," + v2.z + " "+v3.x + "," + v3.y + "," + v3.z + " "); //} AddLineArray3(meshVec, meshTri, MakeQuad(v1, v2, v3, GlobalVariableBackground.Instance.Linewight)); } } ms.SetVertices(meshVec); ms.triangles = meshTri.ToArray(); listLineMesh.Add(ms); meshVec = null; meshVec = new List <Vector3>(); meshTri = null; meshTri = new List <int>(); foreach (var item in listLineMesh) { //item.RecalculateBounds(); item.bounds = new Bounds(Vector3.zero, Vector3.one * 100000f); //avoid culling item.RecalculateNormals(); } if (isLineAndCell) { showMode = Enums.ShowMode.CellAndLine; } else { showMode = Enums.ShowMode.Line; } }
private void ConManager_ToPointMode() { int index = GlobalVariableBackground.Instance.FrameAllIndex % GlobalVariableBackground.Instance.modelCacheCount; if (vtkAllFrame.loadFile.dataType != Enums.DataType.Default) { return; } if (pointModeIndex == GlobalVariableBackground.Instance.FrameAllIndex && args[1] != 0 && vtkAllFrame.modelState.isUsecolor == isPointHaveColor) { showMode = Enums.ShowMode.Point; return; } pointModeIndex = GlobalVariableBackground.Instance.FrameAllIndex; instanceMesh = GlobalVariableBackground.Instance.miniCubeMesh; instanceMaterial = GlobalVariableBackground.Instance.MaterialGPURows; argsBuffer = new ComputeBuffer(5, sizeof(uint), ComputeBufferType.IndirectArguments); instanceMesh.bounds = new Bounds(Vector3.zero, Vector3.one * 100000f); //avoid culling if (positionBuffer != null) { positionBuffer.Release(); } List <Vector4> listVec = new List <Vector4>(); //List<Vector4> listVTKVec = new List<Vector4>(); List <Vector4> listColor = new List <Vector4>(); Mesh mesh; //System.DateTime dtStart = DateTime.Now; //System.DateTime dtEnd01 = DateTime.Now; //System.DateTime dtEnd02 = DateTime.Now; //dtStart = DateTime.Now; for (int i = 0; i < vtkAllFrame.listFrame[index].meshArray.Length; i++) { mesh = vtkAllFrame.listFrame[index].go.transform.GetChild(i).GetComponent <MeshFilter>().mesh; Vector3[] vecTemp = mesh.vertices; Color[] tempColor = mesh.colors; for (int j = 0; j < tempColor.Length; j++) { listColor.Add(tempColor[j]); } tempColor = null; for (int j = 0; j < vecTemp.Length; j++) { Vector3 vec = transform.TransformPoint(vecTemp[j]); listVec.Add(new Vector4(vec.x, vec.y, vec.z, 1)); } vecTemp = null; //for (int j = 0; j < mesh.vertices.Length; j++) //{ // vec = mesh.vertices[j]; // listVec.Add(new Vector4(vec.x,vec.y,vec.z,1)); // //listVec.Add(new Vector4(mesh.vertices[j].x, mesh.vertices[j].y, mesh.vertices[j].z, 1)); // //listColor.Add(mesh.colors[j]); // if (j == 1) // { // break; // } //} //break; } //dtEnd01 = DateTime.Now; //GlobalVariableBackground.Instance.conManager.WriteLog((dtEnd01 - dtStart).TotalMilliseconds + "ms"); //dtEnd01 = DateTime.Now; //for (int i = 0; i < vtkAllFrame.listFrame[index].meshArray.Length; i++) //{ // vtkMesh = vtkAllFrame.listFrame[index].meshArray[i]; // for (int j = 0; j < vtkMesh.vec3Array.Length; j++) // { // vec = vtkMesh.vec3Array[j]; // listVTKVec.Add(vec); // //listVTKVec.Add(new Vector4(vtkMesh.vec3Array[j].x, vtkMesh.vec3Array[j].y, vtkMesh.vec3Array[j].z, 1)); // //listColor.Add(mesh.colors[j]); // } //} //dtEnd02 = DateTime.Now; //GlobalVariableBackground.Instance.conManager.WriteLog((dtEnd01 - dtStart).TotalMilliseconds + " , " + (dtEnd02 - dtEnd01).TotalMilliseconds); Vector4[] buffer = listVec.ToArray(); listVec.Clear(); instanceCount = buffer.Length; if (positionBuffer != null) { positionBuffer.Release(); } positionBuffer = new ComputeBuffer(instanceCount, 16); if (colorBuffer != null) { colorBuffer.Release(); } colorBuffer = new ComputeBuffer(instanceCount, 16); //if (rotationBuffer != null) rotationBuffer.Release(); //rotationBuffer = new ComputeBuffer(instanceCount, 16); positionBuffer.SetData(buffer); instanceMaterial.SetBuffer("positionBuffer", positionBuffer); //buffer = new Vector4[instanceCount]; //for (int i = 0; i < instanceCount; i++) //{ // buffer[i] = UnityEngine.Random.ColorHSV(); //} //for (int i = 0; i < vtkAllFrame.listFrame[index].meshArray.Length; i++) //{ // mesh = vtkAllFrame.listFrame[index].meshArray[i]; // for (int j = 0; j < mesh.vec3Array.Length; j++) // { // buffer[i] = mesh. // list.Add(new Vector4(mesh.vec3Array[j].x, mesh.vec3Array[j].y, mesh.vec3Array[j].z, 1)); // } //} buffer = listColor.ToArray(); if (buffer.Length != 0) { isPointHaveColor = true; } else { isPointHaveColor = false; } colorBuffer.SetData(buffer); instanceMaterial.SetBuffer("colorBuffer", colorBuffer); uint numIndices = (instanceMesh != null) ? (uint)instanceMesh.GetIndexCount(0) : 0; args[0] = numIndices; args[1] = (uint)instanceCount; argsBuffer.SetData(args); showMode = Enums.ShowMode.Point; }