예제 #1
0
        public void updateAdjacentFaceHandles(int face)
        {
            Manifold manifold = Extrudable._manifold;

            //Use average of edgecenters if we have more than 4 edges.
            var temp = manifold.GetAdjacentFaceIdsAndEdgeCenters(face);

            foreach (int faceHandleId in temp.faceId)
            {
                var center = manifold.GetCenterTriangulated(faceHandleId);
                FaceHandleController faceHandleController = _faceHandles[faceHandleId];

                if (temp.edgeCenter.Length > 4)
                {
                    Vector3 cent = new Vector3();
                    foreach (Vector3 v in temp.edgeCenter)
                    {
                        cent[0] += v[0];
                        cent[1] += v[1];
                        cent[2] += v[2];
                    }
                    cent[0] /= temp.edgeCenter.Length;
                    cent[1] /= temp.edgeCenter.Length;
                    cent[2] /= temp.edgeCenter.Length;

                    center = cent;
                }

                // Rotate the handle to look in the opposite direction of face's normal
                var normal     = manifold.GetFaceNormal(faceHandleId);
                var edgeNormal = manifold.GetFirstEdgeDirection(faceHandleId);
                faceHandleController.UpdatePositionAndRotation(center, normal, edgeNormal);
            }
        }
예제 #2
0
        public FaceHandleController GetHandle(int faceId)
        {
            FaceHandleController reqHandle = null;

            _faceHandles.TryGetValue(faceId, out reqHandle);
            return(reqHandle);
        }
예제 #3
0
 void OnTriggerExit(Collider collider)
 {
     if (collidedFaceHandle != null)
     {
         collidedFaceHandle.EndHighlight();
         collidedFaceHandle = null;
         collision          = false;
     }
 }
예제 #4
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);
                }
            }
        }
예제 #5
0
 void OnTriggerEnter(Collider collider)
 {
     if (IsDragged)
     {
         if (collider.GetComponent <FaceHandleController>() != null)
         {
             collision          = true;
             collidedFaceHandle = collider.GetComponent <FaceHandleController>();
             collidedFaceID     = collidedFaceHandle.AssociatedFaceID;
             collidedFaceHandle.StartHighlight();
         }
     }
 }
예제 #6
0
 public bool hasDistinctAdjacentFaces(FaceHandleController faceHandle)
 {
     foreach (int face1 in initialManifold.GetAdjacentFaceIdsAndEdgeCenters(AssociatedFaceID).faceId)
     {
         foreach (int face2 in initialManifold.GetAdjacentFaceIdsAndEdgeCenters(faceHandle.AssociatedFaceID).faceId)
         {
             if (face1 == face2 || AssociatedFaceID == face2) // if neighbours, then false
             {
                 return(false);
             }
         }
     }
     return(true);
 }
예제 #7
0
        public void UpdateControls()
        {
            Manifold manifold    = Extrudable._manifold;
            var      faceIds     = new int[manifold.NumberOfFaces()];
            var      vertexIds   = new int[manifold.NumberOfVertices()];
            var      halfedgeIds = new int[manifold.NumberOfHalfEdges()];

            manifold.GetHMeshIds(vertexIds, halfedgeIds, faceIds);

            // update face handles
            foreach (var faceHandleController in _faceHandles)
            {
                var handleFace = faceHandleController.Value.AssociatedFaceID;

                if (!faceHandleController.Value.IsDragged)
                {
                    var center = manifold.GetCenterTriangulated(handleFace);

                    //Use average of edgecenters if we have more than 4 edges.
                    var temp = manifold.GetAdjacentFaceIdsAndEdgeCenters(handleFace);
                    if (temp.edgeCenter.Length > 4)
                    {
                        Vector3 cent = new Vector3();
                        foreach (Vector3 v in temp.edgeCenter)
                        {
                            cent[0] += v[0];
                            cent[1] += v[1];
                            cent[2] += v[2];
                        }
                        cent[0] /= temp.edgeCenter.Length;
                        cent[1] /= temp.edgeCenter.Length;
                        cent[2] /= temp.edgeCenter.Length;

                        center = cent;
                    }

                    // Rotate the handle to look in the opposite direction of face's normal
                    var normal     = manifold.GetFaceNormal(handleFace);
                    var edgeNormal = manifold.GetFirstEdgeDirection(handleFace);
                    faceHandleController.Value.UpdatePositionAndRotation(center, normal, edgeNormal);
                    faceHandleController.Value.gameObject.SetActive(true);
                }

                var adjacentFaces = manifold.GetAdjacentFaceIdsAndEdgeCenters(handleFace);

                for (int j = 0; j < adjacentFaces.edgeId.Length; j++)
                {
                    EdgeHandleController latch;
                    if (_edgeHandles.TryGetValue(adjacentFaces.edgeId[j], out latch))
                    {
                        var otherFace = latch.GetOtherFace(handleFace);

                        var edgeCenter         = adjacentFaces.edgeCenter[j];
                        var normal             = manifold.GetFaceNormal(handleFace);
                        var adjacentFaceNormal = manifold.GetFaceNormal(otherFace);

                        latch.UpdatePositionAndRotation(edgeCenter, adjacentFaces.edgeNormals[j],
                                                        adjacentFaceNormal + normal);
                        latch.gameObject.SetActive(true);
                    }
                }
            }

            for (int i = 0; i < faceIds.Length; i++)
            {
                int id = faceIds[i];
                FaceHandleController visitedHandleController = null;
                _faceHandles.TryGetValue(id, out visitedHandleController);

                var newHandle = visitedHandleController != null
                    ? visitedHandleController
                    : InstantiateFaceHandle(manifold, id);
                InstantiateLatches(manifold, newHandle);
            }

            foreach (var vertexHandleController in _vertexHandles)
            {
                if (!vertexHandleController.Value.IsDragged)
                {
                    Vector3 vertexPosition = manifold.VertexPosition(vertexHandleController.Key);
                    vertexHandleController.Value.transform.localPosition = vertexPosition;

                    Vector3 vertexNormal = manifold.GetVertexNormal(vertexHandleController.Key);
                    //Debug.Log("VertexHandleNormal: " + vertexNormal);
                    Quaternion handleRotation = Quaternion.LookRotation(-vertexNormal);
                    vertexHandleController.Value.transform.localRotation = handleRotation;
                }
                vertexHandleController.Value.gameObject.SetActive(true);
            }

            for (int i = 0; i < vertexIds.Length; i++)
            {
                int id = vertexIds[i];
                VertexHandleController vertexHandle = null;
                _vertexHandles.TryGetValue(id, out vertexHandle);
                if (!manifold.IsVertexInUse(id) || vertexHandle != null)
                {
                    continue;
                }

                InstantiateVertexHandle(manifold, id);
            }

            //update sizes
            foreach (var faceHandleController in _faceHandles.Values)
            {
                faceHandleController.UpdateHandleSize();
            }
            foreach (var edgeHandleController in _edgeHandles.Values)
            {
                edgeHandleController.UpdateHandleSize();
            }
            foreach (var vertexHandleController in _vertexHandles.Values)
            {
                vertexHandleController.UpdateHandleSize();
            }
        }