コード例 #1
0
        private void OnMergeButtonPressed(object sender, ControllerInteractionEventArgs e)
        {
            VRTK_InteractGrab grabbingController = e.controllerReference.actual.GetComponentInChildren <VRTK_InteractGrab>();
            Plug grabbedPlug = grabbingController.GetGrabbedObject().GetComponent <Plug>();

            Cord connectedCord    = grabbedPlug.ConnectedCord;
            bool replaceCordStart = connectedCord.StartNode.Equals(grabbedPlug.CordAttachPoint);

            if (replaceCordStart)
            {
                connectedCord.Connect(transform, connectedCord.EndNode);
                if (connectedCord.EndNode.GetComponent <BranchHandle>() != null)
                {
                    connectedCord.Flow = -1;
                }
            }
            else
            {
                connectedCord.Connect(connectedCord.StartNode, transform);
                if (connectedCord.StartNode.GetComponent <BranchHandle>() != null)
                {
                    connectedCord.Flow = 1;
                }
            }

            branchNode = new CordNode(connectedCord, transform);

            grabbingController.ForceRelease();
            grabbedPlug.DestroyPlug();

            cordJunction = SplitCord(sourceCord);
            StopMovementAlongCord();

            ConnectBranchToJunction();
        }
コード例 #2
0
        public CordJunction(CordNode A, CordNode B, float Flow)
        {
            this.A = A;
            this.B = B;

            this.Flow = Flow;
        }
コード例 #3
0
        private void OnGrabbed(object sender, InteractableObjectEventArgs e)
        {
            grabber = e.interactingObject.GetComponent <VRTK_InteractGrab>();
            if (branchNode != null)
            {
                VRTK_ControllerEvents controllerEvents = e.interactingObject.GetComponent <VRTK_ControllerEvents>();
                controllerEvents.ButtonOnePressed += OnDisconnectButtonPressed;
            }
            else
            {
                //Force the controller to let go of the branch handle
                grabber.ForceRelease();
                GetComponent <VRTK_InteractableObject>().isGrabbable = false;

                Plug branchPlug = CreatePlug();
                Cord branchCord;

                //Create a cord between the plug and the branch handle
                branchCord       = Instantiate(CordPrefab).GetComponent <Cord>();
                branchCord.Color = sourceCord.Color;
                branchCord.Connect(transform, branchPlug.CordAttachPoint);
                branchCord.Flow = 0;
                branchNode      = new CordNode(branchCord, transform);

                cordJunction = SplitCord(sourceCord);
                StopMovementAlongCord();

                grabber.ForceGrab(branchPlug.GetComponent <VRTK_InteractableObject>(), () =>
                {
                    GetComponent <VRTK_InteractableObject>().isGrabbable = true;
                    branchPlug.EnableSnapping();
                });
            }
        }
コード例 #4
0
        private HashSet <PhysicalDataEndpoint> GetEndpointsConnectedToHandle(bool reverseFlow, BranchHandle handle)
        {
            HashSet <PhysicalDataEndpoint> results = new HashSet <PhysicalDataEndpoint>();

            if (handle != null)
            {
                CordNode  downstreamJunctionNode = handle.GetDownstreamJunctionNode(reverseFlow);
                Transform other = downstreamJunctionNode.Cord.GetOppositeEnd(downstreamJunctionNode.transform);

                results.UnionWith(GetEndpointsConnectedToNode(reverseFlow, downstreamJunctionNode));

                CordNode branchNode = handle.BranchNode;
                results.UnionWith(GetEndpointsConnectedToNode(reverseFlow, branchNode));
            }

            return(results);
        }
コード例 #5
0
        /// <summary>
        /// Splits the cord so that this cord contains the points before splitPoint and splitCord contains the points after splitPoint
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="splitPointIndex"></param>
        /// <param name="splitCord"></param>
        /// <returns></returns>
        public CordJunction SplitByBranchHandle(BranchHandle handle, int splitPointIndex, Cord splitCord)
        {
            //Get the points after the splitPoint and assign them to the splitCord
            List <Vector3> splitPath = new List <Vector3>();

            for (int i = splitPointIndex; i < path.Count; i++)
            {
                splitPath.Add(path[i]);
            }

            splitCord.Color = Color;
            splitCord.Flow  = Flow;
            splitCord.Connect(handle.transform, B);
            if (B.GetComponent <BranchHandle>() != null)
            {
                B.GetComponent <BranchHandle>().ReplaceCord(this, splitCord);
            }

            splitCord.Path = splitPath;
            splitCord.AllowBranching(true);

            int combinedPathLength = path.Count;

            //Exclude the points in the splitCord from this cord
            for (int i = 0; i < combinedPathLength - splitPointIndex; i++)
            {
                path.RemoveAt(path.Count - 1);
            }
            B = handle.transform;

            branchHandles.Remove(handle);
            CreateBranchHandles(handle.TrackedController);
            UpdateBoundingBox();

            CordNode JunctionA = new CordNode(this, handle.transform);
            CordNode JunctionB = new CordNode(splitCord, handle.transform);

            return(new CordJunction(JunctionA, JunctionB, Flow));
        }
コード例 #6
0
        /// <summary>
        /// A BranchHandle exists at the intersection of three cords:
        /// The two cords in the CordJunction that was formed by splitting the source cord as well as the newly created branch cord
        ///
        /// This method takes a cord that is about to collapse as the parameter and merges the other two cords of the handle together.
        /// </summary>
        /// <param name="collapsedCord"></param>
        public void MergeRemainingCords(Cord collapsedCord)
        {
            if (collapsedCord.Equals(branchNode.Cord))
            {
                //If the branch cord has collapsed we merge the junction and end up with the same cord that was split by the BranchHandle
                MergeJunction();
            }
            else
            {
                //Otherwise one side of the junction has collapsed so we merge the branch cord with the other side of the junction
                List <Vector3> mergedPath = new List <Vector3>();
                CordNode       toMerge    = collapsedCord.Equals(cordJunction.A.Cord) ? cordJunction.B : cordJunction.A;

                Transform branchEnd = branchNode.transform.Equals(branchNode.Cord.StartNode) ? branchNode.Cord.EndNode : branchNode.Cord.StartNode;

                if (toMerge.transform.Equals(toMerge.Cord.StartNode))
                {
                    toMerge.Cord.Connect(branchEnd, toMerge.Cord.EndNode);
                    mergedPath.AddRange(branchNode.Cord.Path);
                    mergedPath.AddRange(toMerge.Cord.Path);
                }
                else
                {
                    toMerge.Cord.Connect(toMerge.Cord.StartNode, branchEnd);
                    mergedPath.AddRange(toMerge.Cord.Path);
                    mergedPath.AddRange(branchNode.Cord.Path);
                }

                toMerge.Cord.Path = mergedPath;

                if (branchEnd.GetComponent <BranchHandle>())
                {
                    BranchHandle startHandle = branchEnd.GetComponent <BranchHandle>();
                    startHandle.ReplaceCord(branchNode.Cord, toMerge.Cord);
                }

                branchNode.Cord.DestroyCord();
            }
        }
コード例 #7
0
 private HashSet <PhysicalDataEndpoint> GetEndpointsConnectedToNode(bool reverseFlow, CordNode node)
 {
     return(node.Cord.GetConnectedEndpoints(reverseFlow, node.transform));
 }