Ejemplo n.º 1
0
        public override void StopInteraction()
        {
            if (IsDragged)
            {
                destroyMeasuringBands();
                IsDragged = false;

                if (collision == false && !planeSnap)
                {
                    Extrudable.MoveTo(
                        AssociatedFaceID,
                        extrudingFaces.ToArray(),
                        transform.localPosition, translateSnap && isExtruding, tickState);
                }
                else if (!planeSnap)
                //else if (extrudingFaces.Count == 1) // yes/no maybe
                {
                    Debug.Log("Attempting face bridging");
                    if (true)//(hasDistinctAdjacentFaces(collidedFaceHandle))
                    {
                        //collidedFaceHandleVertexPositions = controlsManager.GetVertexPositionsFromFaces(new List<int> { collidedFaceID });
                        collidedFaceHandleVertexPositions = initialManifold.GetVertexPositionsFromFace(collidedFaceID);

                        if (collidedFaceHandleVertexPositions.Count() == initialVertexPositions.Count() && extrudingFaces.Count == 1)
                        {
                            var matches = faceBridgingVertexAssignment(initialVertexPositions, collidedFaceHandleVertexPositions);

                            if (/*facingFaces(matches, AssociatedFaceID, initialVertexPositions, collidedFaceID, collidedFaceHandleVertexPositions)*/ true)
                            {
                                Extrudable.ChangeManifold(initialManifold.Copy());
                                Debug.Log("Applying face bridging");
                                if (matches.Length == 6)
                                {
                                    Extrudable.bridgeFaces(AssociatedFaceID, collidedFaceID, new int[] { matches[0], matches[1], matches[2] }, new int[] { matches[3], matches[4], matches[5] }, 3);
                                    ControlsManager.Instance.UpdateControls();
                                }
                                else if (matches.Length == 8)
                                {
                                    Extrudable.bridgeFaces(AssociatedFaceID, collidedFaceID, new int[] { matches[0], matches[1], matches[2], matches[3] }, new int[] { matches[4], matches[5], matches[6], matches[7] }, 4);
                                    ControlsManager.Instance.UpdateControls();
                                }
                            }
                        }
                    }
                    collidedFaceHandleVertexPositions = null;
                }


                MergeWithCollidingFaces(); //Merge extrusion if done up against other faces.

                //Check if mesh is valid
                extrudingFaces = new List <int>(); // create new list (may be referenced by other hand)

                int collapsed = Extrudable.CollapseShortEdges(0.019f);
                Extrudable.TriangulateAndDrawManifold(); // needed for collision detection in isValidMesh



                if (Extrudable.isValidMesh())
                {
                    ControlsManager.Instance.DestroyInvalidObjects();
                    ControlsManager.Instance.Extrudable.rebuild = true;
                    //ControlsManager.Instance.UpdateControls();
                    ControlsManager.FireUndoEndEvent(mesh, this, initialPosition, initialRotation);
                }
                else
                {
                    Extrudable.ChangeManifold(initialManifold);
                }

/*
 *              if (collapsed > 0)
 *              {
 *
 *              }
 *              else if (Extrudable.isValidMesh())
 *              {
 *                  //ControlsManager.Instance.DestroyInvalidObjects();
 *                  ControlsManager.Instance.Extrudable.rebuild = true;
 *                  //ControlsManager.Instance.UpdateControls();
 *                  ControlsManager.FireUndoEndEvent(mesh, this, initialPosition, initialRotation);
 *
 *
 *
 *
 *              }
 *              else
 *              {
 *                  Extrudable.ChangeManifold(initialManifold);
 *              }*/
                DisableSBSPlane();
            }
        }