public void ReplaceVertex(ref NativeHeap <VertexStruct> vertexHeap, VertexStruct vold, ref VertexStruct vNew, NativeArray <int> idToHeapIndex) { int idx; for (idx = 0; idx < 3; idx++) { if (vold.ID == vertexs[idx]) { for (int i = 0; i < 3; i++) { if (i == idx) { continue; } VertexStruct v = vertexHeap[idToHeapIndex[vertexs[i]]]; v.RemoveAtVertex(vold); if (!v.Contains(vNew.ID)) { v.AddNeighborVertex(vNew.ID); } if (!vNew.Contains(vertexs[i])) { vNew.AddNeighborVertex(vertexs[i]); } vertexHeap[idToHeapIndex[vertexs[i]]] = v; } vertexs[idx] = vNew.ID; break; } } faceIndex[idx] = vNew.currentFaceCount; vNew.AddFaceTriangle(Index); ComputeNormal(vertexHeap, vold, idToHeapIndex); }
public unsafe void Compute(List <Vertex> vertices, Mesh m_OriginalMesh, TriangleList[] triangleArray, RelevanceSphere[] aRelevanceSpheres, float[] costs, int[] collapses, int[] m_aVertexPermutation, int[] m_VertexHeap, bool bUseEdgeLength, bool bUseCurvature, float bBorderCurvature, float fOriginalMeshSize) { computerHeapJob = new ComputeHeapJob(); this.m_aVertexPermutation = m_aVertexPermutation; this.m_VertexHeap = m_VertexHeap; computerHeapJob.UseEdgeLength = bUseEdgeLength; computerHeapJob.UseCurvature = bUseCurvature; computerHeapJob.fBorderCurvature = bBorderCurvature; computerHeapJob.OriginalMeshSize = fOriginalMeshSize; computerHeapJob.m_aVertexPermutation = new NativeArray <int>(m_aVertexPermutation, Allocator.TempJob); computerHeapJob.m_aVertexMap = new NativeArray <int>(m_VertexHeap, Allocator.TempJob); computerHeapJob.idToHeapIndex = new NativeArray <int>(vertices.Count, Allocator.TempJob); computerHeapJob.tempTriangleList = new NativeList <int>(Allocator.TempJob); computerHeapJob.tmpVerticesList = new NativeList <int>(Allocator.TempJob); NativeHeap <VertexStruct> minNativeHeap = NativeHeap <VertexStruct> .CreateMinHeap(vertices.Count, Allocator.TempJob); int intSize = UnsafeUtility.SizeOf <int>(); int intAlignment = UnsafeUtility.AlignOf <int>(); //------------------------顶点数据--------------------------------- for (int i = 0; i < vertices.Count; i++) { Vertex v = vertices[i]; VertexStruct sv = new VertexStruct() { ID = v.m_nID, m_fObjDist = costs[i], Position = v.m_v3Position, collapse = collapses[i] == -1 ? -1 : vertices[collapses[i]].m_nID, isBorder = v.IsBorder() ? 1 : 0, Normal = v.Normal, UV = v.UV, }; sv.NewVertexNeighbors(v.m_listNeighbors.Count, intSize, intAlignment, Allocator.TempJob); sv.NewFaceTriangle(v.m_listFaces.Count, intSize, intAlignment, Allocator.TempJob); sv.idToHeapIndex = computerHeapJob.idToHeapIndex; for (int j = 0; j < v.m_listNeighbors.Count; j++) { sv.AddNeighborVertex(v.m_listNeighbors[j].m_nID); } for (int j = 0; j < v.m_listFaces.Count; j++) { sv.AddFaceTriangle(v.m_listFaces[j].Index); } minNativeHeap.Insert(sv); } //------------------------顶点数据结束----------------------------- //------------------------三角形数据------------------------------- List <TriangleStruct> structTrangle = new List <TriangleStruct>(); for (int n = 0; n < triangleArray.Length; n++) { List <Triangle> triangles = triangleArray[n].m_listTriangles; for (int i = 0; i < triangles.Count; i++) { Triangle t = triangles[i]; TriangleStruct st = new TriangleStruct() { Index = t.Index, Indices = (int *)UnsafeUtility.Malloc(t.Indices.Length * intAlignment, intAlignment, Allocator.TempJob), Normal = t.Normal, faceIndex = (int *)UnsafeUtility.Malloc(t.FaceIndex.Length * intSize, intAlignment, Allocator.TempJob), vertexs = t.Vertices.Length == 0 ? null : (int *)UnsafeUtility.Malloc(t.Vertices.Length * intSize, intAlignment, Allocator.TempJob), }; for (int j = 0; j < t.Indices.Length; j++) { st.Indices[j] = t.Indices[j]; } for (int j = 0; j < t.FaceIndex.Length; j++) { st.faceIndex[j] = t.FaceIndex[j]; } for (int j = 0; j < t.Vertices.Length; j++) { st.vertexs[j] = t.Vertices[j].m_nID; } structTrangle.Add(st); } } //------------------------三角形数据结束 computerHeapJob.Spheres = new NativeArray <StructRelevanceSphere>(aRelevanceSpheres.Length, Allocator.TempJob); for (int i = 0; i < aRelevanceSpheres.Length; i++) { RelevanceSphere rs = aRelevanceSpheres[i]; StructRelevanceSphere srs = new StructRelevanceSphere() { Transformation = Matrix4x4.TRS(rs.m_v3Position, rs.m_q4Rotation, rs.m_v3Scale), Relevance = rs.m_fRelevance, }; computerHeapJob.Spheres[i] = srs; } computerHeapJob.triangles = new NativeArray <TriangleStruct>(structTrangle.ToArray(), Allocator.TempJob); computerHeapJob.m_VertexHeap = minNativeHeap; handle = computerHeapJob.Schedule(); //Debug.Log(" computerHeapJob.m_VertexHeap.Length" + computerHeapJob.m_VertexHeap.Length); }