/// <summary> /// Populates a list with transformed face vertices. /// </summary> public static unsafe void ComputeFaceClippingPolygon(ref NativeList <ClipVertex> output, int faceIndex, RigidTransform t, NativeHull hull) { Debug.Assert(output.IsCreated); NativeFace * face = hull.GetFacePtr(faceIndex); NativePlane plane = hull.GetPlane(faceIndex); NativeHalfEdge *start = hull.GetEdgePtr(face->Edge); NativeHalfEdge *current = start; do { NativeHalfEdge *twin = hull.GetEdgePtr(current->Twin); float3 vertex = hull.GetVertex(current->Origin); float3 P = math.transform(t, vertex); ClipVertex clipVertex; clipVertex.featurePair.InEdge1 = -1; clipVertex.featurePair.OutEdge1 = -1; clipVertex.featurePair.InEdge2 = (sbyte)current->Next; clipVertex.featurePair.OutEdge2 = (sbyte)twin->Twin; clipVertex.position = P; clipVertex.hull2local = vertex; clipVertex.plane = plane; output.Add(clipVertex); current = hull.GetEdgePtr(current->Next); } while (current != start); }
public void Dispose() { if (_isDisposed == 0) { if (verticesNative.IsCreated) { verticesNative.Dispose(); } if (facesNative.IsCreated) { facesNative.Dispose(); } if (facesPlanesNative.IsCreated) { facesPlanesNative.Dispose(); } if (edgesNative.IsCreated) { edgesNative.Dispose(); } vertices = null; faces = null; facesPlanes = null; edges = null; } _isDisposed = 1; }
public static unsafe void ValidateFace(this NativeHull hull, NativeFace *face) { Debug.Assert(hull.faceCount > 0); Debug.Assert(hull.edgeCount > 0); Debug.Assert(face->edge != -1); ValidateEdge(hull, hull.edges + face->edge); }
public unsafe static void SetFromFaces(ref NativeHull hull, NativeHullDef def) { Debug.Assert(def.FaceCount > 0); Debug.Assert(def.VertexCount > 0); hull.VertexCount = def.VertexCount; var arr = def.VerticesNative.ToArray(); hull.VerticesNative = new NativeArrayNoLeakDetection <float3>(arr, Allocator.Persistent); hull.Vertices = (float3 *)hull.VerticesNative.GetUnsafePtr(); hull.FaceCount = def.FaceCount; hull.FacesNative = new NativeArrayNoLeakDetection <NativeFace>(hull.FaceCount, Allocator.Persistent); hull.Faces = (NativeFace *)hull.FacesNative.GetUnsafePtr(); // Initialize all faces by assigning -1 to each edge reference. for (int k = 0; k < def.FaceCount; ++k) { NativeFace *f = hull.Faces + k; f->Edge = -1; } CreateFacesPlanes(ref hull, ref def); var edgeMap = new Dictionary <(int v1, int v2), int>(); var edgesList = new NativeHalfEdge[10000]; // todo lol // Loop through all faces. for (int i = 0; i < def.FaceCount; ++i) { NativeFaceDef face = def.FacesNative[i]; int vertCount = face.VertexCount; Debug.Assert(vertCount >= 3); int *vertices = face.Vertices; var faceHalfEdges = new List <int>(); // Loop through all face edges. for (int j = 0; j < vertCount; ++j) { int v1 = vertices[j]; int v2 = j + 1 < vertCount ? vertices[j + 1] : vertices[0]; bool edgeFound12 = edgeMap.TryGetValue((v1, v2), out int iter12); bool edgeFound21 = edgeMap.ContainsKey((v2, v1)); Debug.Assert(edgeFound12 == edgeFound21); if (edgeFound12) { // The edge is shared by two faces. int e12 = iter12; // Link adjacent face to edge. if (edgesList[e12].Face == -1) { edgesList[e12].Face = i; } else { throw new Exception("Two shared edges can't have the same vertices in the same order"); } if (hull.Faces[i].Edge == -1) { hull.Faces[i].Edge = e12; } faceHalfEdges.Add(e12); } else { // The next edge of the current half edge in the array is the twin edge. int e12 = hull.EdgeCount++; int e21 = hull.EdgeCount++; if (hull.Faces[i].Edge == -1) { hull.Faces[i].Edge = e12; } faceHalfEdges.Add(e12); edgesList[e12].Prev = -1; edgesList[e12].Next = -1; edgesList[e12].Twin = e21; edgesList[e12].Face = i; edgesList[e12].Origin = v1; edgesList[e21].Prev = -1; edgesList[e21].Next = -1; edgesList[e21].Twin = e12; edgesList[e21].Face = -1; edgesList[e21].Origin = v2; // Add edges to map. edgeMap[(v1, v2)] = e12;