示例#1
0
 public void AttachLatch(EdgeHandleController edgeHandle)
 {
     if (!ConnectedLatches.Contains(edgeHandle))
     {
         ConnectedLatches.Add(edgeHandle);
     }
 }
示例#2
0
        public void InstantiateLatches(Manifold manifold, FaceHandleController handleController)
        {
            var neighbourFaces = manifold.GetAdjacentFaceIdsAndEdgeCenters(handleController.AssociatedFaceID);
            var edgeCenters    = neighbourFaces.edgeCenter;

            for (int j = 0; j < neighbourFaces.edgeId.Length; j++)
            {
                var adjacentFace = neighbourFaces.faceId[j];

                int uniqueHalfedgeId = Mathf.Max(manifold.GetOppHalfEdge(neighbourFaces.edgeId[j]), neighbourFaces.edgeId[j]);

                EdgeHandleController existingEdgeHandle = null;
                var latchExists = _edgeHandles.TryGetValue(uniqueHalfedgeId, out existingEdgeHandle);

                if (latchExists)
                {
                    handleController.AttachLatch(existingEdgeHandle);
                }
                else
                {
                    var newLatch = Instantiate(LatchPrefab, transform, false);
                    //newLatch.transform.localScale = Vector3.Scale(transform.lossyScale, newLatch.transform.localScale);
                    newLatch.transform.SetParent(transform);

                    var edgeCenter = edgeCenters[j];

                    var edgeHandleController = newLatch.GetComponent <EdgeHandleController>();

                    var adjacentFaceNormal = manifold.GetFaceNormal(adjacentFace);
                    var normal             = manifold.GetFaceNormal(handleController.AssociatedFaceID);

                    edgeHandleController.UpdatePositionAndRotation(edgeCenter, neighbourFaces.edgeNormals[j],
                                                                   adjacentFaceNormal + normal);

                    edgeHandleController.FirstFace  = handleController.AssociatedFaceID;
                    edgeHandleController.SecondFace = adjacentFace;
                    // always use max halfedge id - to uniquely identify halfedge
                    edgeHandleController.AssociatedEdgeID = uniqueHalfedgeId;

                    KeyValuePair <int, int> pairToRemove = new KeyValuePair <int, int>();
                    foreach (var pair in _closedEdgeBackup)
                    {
                        if (edgeHandleController.IsAdjacent(pair.Key, pair.Value))
                        {
                            pairToRemove = pair;
                            edgeHandleController.Locked = true;
                            break;
                        }
                    }

                    _closedEdgeBackup.Remove(pairToRemove);

                    handleController.AttachLatch(edgeHandleController);
                    _edgeHandles.Add(edgeHandleController.AssociatedEdgeID, edgeHandleController);
                }
            }
        }