Exemple #1
0
    private void SetPinConstraints(ObiCollider objectToStick, Vector3 normal)
    {
        pinConstraintBatch.RemoveConstraint(contraintIndexOne);
        UpdateIndex();
        pinConstraintBatch.RemoveConstraint(contraintIndexTwo);
        UpdateIndex();
        gameObject.SetActive(false);
        pinConstraintBatch.AddConstraint(particleIndexOne, objectToStick,
                                         objectToStick.transform.InverseTransformPoint(obiRope.GetParticlePosition(particleIndexOne) - transform.lossyScale.x * normal), Quaternion.identity, 0);

        //UpdateIndex();

        pinConstraintBatch.AddConstraint(particleIndexTwo, objectToStick,
                                         objectToStick.transform.InverseTransformPoint(obiRope.GetParticlePosition(particleIndexOne) - transform.lossyScale.x * normal + particlesDistance * normal), Quaternion.identity, 0);
        UpdateIndex();
        //obiCollider.ParentChange();
    }
Exemple #2
0
    private void RemovePinConstraint(GameObject CableEnd, bool isSnap, ref int ConstraintIndexOne, ref int ConstrainIndexTwo)
    {
        pinConstraintBatch.RemoveConstraint(ConstraintIndexOne);

        UpdateIndex();

        pinConstraintBatch.RemoveConstraint(ConstrainIndexTwo);

        UpdateIndex();

        if (isSnap == true)
        {
            Destroy(CableEnd.GetComponent <ObiRigidbody>());
        }
        else
        {
            if (CableEnd.GetComponent <ObiRigidbody>() == null)
            {
                CableEnd.AddComponent <ObiRigidbody>();
            }
        }
    }
    void release_pin_right()
    {
        rightpin = 0;
        ObiPinConstraints pins = this.GetComponent <ObiPinConstraints>();

        pins.RemoveFromSolver(null);
        ObiPinConstraintBatch batch = pins.GetFirstBatch() as ObiPinConstraintBatch;

        for (int i = 0; i < 17; i++)
        {
            batch.RemoveConstraint(0);
        }
        pins.AddToSolver(null);
        Debug.Log("leave_right");
    }
Exemple #4
0
    public void ReleaseRope(InteractingInfo interactingInfo)
    {
        if (!isGrabbable)
        {
            return;
        }

        ObiPinConstraintBatch batch = pinConstraints.GetBatches()[0] as ObiPinConstraintBatch;

        pinConstraints.RemoveFromSolver(null);

        if (interactingInfo.pinIndex.HasValue)
        {
            batch.RemoveConstraint(interactingInfo.pinIndex.Value);
        }

        pinConstraints.AddToSolver(null);

        pinConstraints.PushDataToSolver();
    }
    IEnumerator DeployExtractionChute()
    {
        print("Deploy Extraction Chute");
        //add force component to extraction bag
        rbChuteBag             = chutes[0].AddComponent <Rigidbody>();
        rbChuteBag.useGravity  = true;
        rbChuteBag.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY;
        deploy = true;

        yield return(new WaitForSeconds(0.8f));

        pullChute = true;
        // remove the constraints from the solver, because we cannot modify the constraints list while the solver is using it.
        //detach rope from extraction bag
        ObiPinConstraintBatch constraintsBatch = rope.PinConstraints.GetFirstBatch();

        rope.PinConstraints.RemoveFromSolver(null);
        constraintsBatch.RemoveConstraint(0);
        rope.PinConstraints.AddToSolver(null);

        //create open parachute
        chutes[1] = (GameObject)Instantiate(models[2]);
        chutes[1].transform.parent     = payloads[0].transform;
        chutes[1].transform.position   = chutes[0].transform.position - new Vector3(0.0f, 0.0f, 0.0f);
        chutes[1].transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);

        //add box collider and obi collider components to parachute
        BoxCollider chuteBoxCollider = chutes[1].AddComponent <BoxCollider>();

        chuteBoxCollider.size   = new Vector3(1.0f, 1.0f, 0.2f);
        chuteBoxCollider.center = new Vector3(0, 0, -0.1f);

        //chuteObiCollider = new ObiCollider();
        chuteObiCollider = chutes[1].AddComponent <ObiCollider>();

        //attach rope to parachute
        constraintsBatch = rope.PinConstraints.GetFirstBatch();
        rope.PinConstraints.RemoveFromSolver(null);
        constraintsBatch.AddConstraint(0, chuteObiCollider, new Vector3(0, 0, -0.1f), 0.0f);
        rope.PinConstraints.AddToSolver(null);
        rope.PinConstraints.PushDataToSolver();

        //extraction bag falls after parachute is attached
        rbChuteBag.useGravity = true;

        rbParachute = chutes[1].AddComponent <Rigidbody>();
        rbParachute.AddForce(0.0f, 0.0f, -10.0f);
        rbParachute.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY |
                                  RigidbodyConstraints.FreezePositionY;

        yield return(new WaitForSeconds(1));

        Destroy(chutes[0]);

        rbParachute.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezeRotationY |
                                  RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ;

        deploy    = false;
        deployed  = true;
        pullChute = false;

        chutes[1].transform.parent = container;
    }
Exemple #6
0
    // Update is called once per frame
    void Update()
    {
        if (!StaticData.isTapeAttachBothHands() && StaticData.getIsCut())
        {
            setControllerHighlight(CurState.singleAttach);
        }

        // after attach to both hands, show the first hint
        if (StaticData.isTapeAttachBothHands() && cur == 0)
        {
            // TODO: modify to handle different model

            // turn on the hint of trail renderer
            string modelName = StaticData.getTargetNumName();
            // GameObject.Find("fcum").transform.GetChild(0).gameObject.SetActive(true);
            GameObject.Find(modelName).transform.GetChild(0).gameObject.SetActive(true);

            // turn on step buttons
            hint[cur].GetComponent <MeshRenderer>().enabled = true;
            ParticleSystem particleSystem = hint[cur].GetComponent <ParticleSystem>();
            if (!particleSystem.isPlaying)
            {
                particleSystem.Play();
            }

            // turn on tooltips
            hint[cur].transform.GetChild(0).gameObject.SetActive(true);

            // turn on audio hint
            if (!audioHint[cur])
            {
                hint[cur].GetComponent <AudioSource>().Play(0);
                audioHint[cur] = true;
            }

            // set up highlighter
            setControllerHighlight(CurState.leftStep);
        }

        if (StaticData.isTapeAttachBothHands() && cur < hint.Length)
        {
            // set up highlighter
            if (cur < hint.Length - 1)
            {
                setControllerHighlight(CurState.leftStep);
            }
            else
            {
                setControllerHighlight(CurState.rightStep);
            }

            VRTK_InteractableObject stickBtn = hint[cur].GetComponent <VRTK_InteractableObject>();
            if (stickBtn.IsTouched())
            {
                ParticleSystem particleSystem = hint[cur].GetComponent <ParticleSystem>();
                if (!particleSystem.isStopped)
                {
                    particleSystem.Stop();
                }
                MeshRenderer color = stickBtn.GetComponent <MeshRenderer>();
                color.material = Resources.Load("activeBtn") as Material;
            }
            else
            {
                ParticleSystem particleSystem = hint[cur].GetComponent <ParticleSystem>();
                if (!particleSystem.isPlaying)
                {
                    particleSystem.Play();
                }
                MeshRenderer color = stickBtn.GetComponent <MeshRenderer>();
                color.material = Resources.Load("orange") as Material;
            }

            if (stickBtn != null && stickBtn.IsUsing())
            {
                // fix current position
                GameObject handler = getCurHandler();


                handler.transform.SetParent(stickPos[cur].transform);
                handler.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
                if (cur != hint.Length - 1)
                {
                    handler.transform.localRotation = Quaternion.Euler(new Vector3(0.0f, 0.0f, 0.0f));
                }
                handler.GetComponent <ObiParticleHandle>().enabled = true;


                // move on to next position
                leftController       = GameObject.Find("left_hand");
                leftCollider.enabled = true;


                ObiPinConstraints     pinConstraints     = obiCloth.GetComponent <ObiPinConstraints>();
                ObiPinConstraintBatch pinConstraintBatch = pinConstraints.GetFirstBatch();

                pinConstraints.RemoveFromSolver(null);


                // remove previous position constraints first
                // if (cur == 0)
                // {
                // do nothing
                // no constraint at the left hand side
                // }
                if (cur == 1)
                {
                    pinConstraintBatch.RemoveConstraint(3);
                    pinConstraintBatch.RemoveConstraint(2);
                }
                if (cur == 2)
                {
                    pinConstraintBatch.RemoveConstraint(3);
                    pinConstraintBatch.RemoveConstraint(2);
                }
                if (cur == 3)
                {
                    pinConstraintBatch.RemoveConstraint(1);
                    pinConstraintBatch.RemoveConstraint(0);
                }

                // add next position constraint
                if (cur == 0 || cur == 1)
                {
                    pinConstraintBatch.AddConstraint(leftAttachNode[cur * 2], leftCollider, offset, restDarboux, 1);
                    pinConstraintBatch.AddConstraint(leftAttachNode[cur * 2 + 1], leftCollider, offsetNeg, restDarboux, 1);
                }

                pinConstraints.AddToSolver(null);

                // turn off the current hint
                hint[cur].GetComponent <MeshRenderer>().enabled = false;
                ParticleSystem ps = hint[cur].GetComponent <ParticleSystem>();
                if (!ps.isStopped)
                {
                    ps.Stop();
                }
                hint[cur].transform.GetChild(0).gameObject.SetActive(false);

                ++cur;
                StaticData.setCurTapingStep(cur);

                // set up last step highlight
                if (cur == hint.Length - 1)
                {
                    setControllerHighlight(CurState.rightStep);
                }

                // turn on the next hint
                if (cur < hint.Length)
                {
                    hint[cur].GetComponent <MeshRenderer>().enabled = true;
                    ParticleSystem particleSystem = hint[cur].GetComponent <ParticleSystem>();
                    if (!particleSystem.isPlaying)
                    {
                        particleSystem.Play();
                    }

                    // turn on tooltip
                    hint[cur].transform.GetChild(0).gameObject.SetActive(true);

                    // turn on audio hint
                    if (!audioHint[cur])
                    {
                        hint[cur].GetComponent <AudioSource>().Play(0);
                        audioHint[cur] = true;
                    }
                }

                // Last step: use right hand to attach
                if (cur == hint.Length - 1)
                {
                    // set lefthand gesture unhold
                    setHandUnhold("[VRTK_SDKManager]/SDKSetups/SteamVR/[CameraRig]/Controller (left)/LeftController/VRTK_BasicHand/LeftHand");

                    rightHandler    = GameObject.Find("right_hand");
                    rightController = VRTK_DeviceFinder.GetControllerRightHand();
                }
            }
        }
        else if (StaticData.isTapeAttachBothHands() && cur >= hint.Length)
        {  // finish all steps
            // clear highlighter
            setControllerHighlight(CurState.finished);

            // set rightHand gesture unhold
            setHandUnhold("[VRTK_SDKManager]/SDKSetups/SteamVR/[CameraRig]/Controller (right)/RightController/VRTK_BasicHand/RightHand");

            // count 5 secs to reload main scene
            timeRemaining -= Time.deltaTime;
            if (timeRemaining <= 0)
            {
                Debug.Log("finish taping");
                SceneManager.LoadScene("testMain");
            }
        }
    }
Exemple #7
0
    private void OnTriggerEnter(Collider other)
    {
        if (!other.CompareTag("Cable"))
        {
            return;
        }
        ObiCollider obicollider = other.GetComponent <ObiCollider>();

        obiRope = other.transform.parent.GetComponentInChildren <ObiRope>();
        ObiPinConstraints pinConstrain = other.transform.parent.GetComponentInChildren <ObiPinConstraints>();

        pinConstraintBatch = pinConstrain.GetFirstBatch();

        Debug.Log("Total Particle" + obiRope.TotalParticles);
        Debug.Log("Used Particle" + obiRope.UsedParticles);
        Debug.Log("Pooled Particle" + obiRope.PooledParticles);

        foreach (var item in pinConstraintBatch.pinBodies)
        {
            Debug.Log(item.gameObject.name);
        }

        foreach (var item in pinConstraintBatch.pinIndices)
        {
            Debug.Log(item);
        }

        foreach (var item in pinConstraintBatch.GetConstraintsInvolvingParticle(particledex))
        {
            Debug.Log("Constrain of Last pariticle" + item);
        }

        pinConstrain.RemoveFromSolver(null);
        UpdateIndex();

        int CheckPoint = 0;

        Debug.Log("CheckPoin" + CheckPoint++);
        UpdateIndex();
        NameOfParticleLast  = pinConstraintBatch.pinBodies[LastParticleConstrainIndex].gameObject.name;
        NameOfParticleFirst = pinConstraintBatch.pinBodies[FirstParticleConstrainIndex].gameObject.name;

        if (other.name == NameOfParticleLast)
        {
            pinConstraintBatch.RemoveConstraint(LastParticleConstrainIndex);
            pinConstraintBatch.AddConstraint(obiRope.UsedParticles - 1, GetComponent <ObiColliderBase>(),
                                             transform.InverseTransformPoint(obiRope.GetParticlePosition(TestRope.UsedParticles - 1)), Quaternion.identity, 0);
            UpdateIndex();
            Debug.Log("CheckPoin" + CheckPoint++);
            pinConstraintBatch.RemoveConstraint(SecondLastParticleConstrainIndex);
            pinConstraintBatch.AddConstraint(obiRope.UsedParticles - 2, GetComponent <ObiColliderBase>(),
                                             transform.InverseTransformPoint(obiRope.GetParticlePosition(TestRope.UsedParticles - 2)), Quaternion.identity, 0);
            Debug.Log("CheckPoin" + CheckPoint++);
        }
        else if (other.name == NameOfParticleFirst)
        {
            pinConstraintBatch.RemoveConstraint(FirstParticleConstrainIndex);
            pinConstraintBatch.AddConstraint(0, GetComponent <ObiColliderBase>(),
                                             transform.InverseTransformPoint(obiRope.GetParticlePosition(0)), Quaternion.identity, 0);
            Debug.Log("CheckPoin" + CheckPoint++);
            UpdateIndex();
            pinConstraintBatch.RemoveConstraint(SecondParticleConstrainIndex);
            pinConstraintBatch.AddConstraint(1, GetComponent <ObiColliderBase>(),
                                             transform.InverseTransformPoint(obiRope.GetParticlePosition(1)), Quaternion.identity, 0);
        }

        pinConstrain.AddToSolver(null);
    }