void pin_rotate_ready()
    {
        //GameObject[] twoparticle = new GameObject[2];
        // Debug.Log("wang");
        ObiPinConstraints pins = this.GetComponent <ObiPinConstraints>();

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

        //attach more particle to pin
        kdtreesearch_left();
        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 26; j++)
            {
                batch.AddConstraint(particleindexsphere[i][j], twoobject[i].GetComponent <ObiCollider>(), Vector3.zero, 1.0f);
            }
            twoobject[i].GetComponent <ObiCollider>().Phase = 1;
            twoobject[i].AddComponent <ObjectDragger>();
            //Debug.Log(twoobject[i].transform.position);
        }
        batch.AddConstraint(centerparciel[0], twoobject[0].GetComponent <ObiCollider>(), Vector3.zero, 1.0f);
        batch.AddConstraint(centerparciel[1], twoobject[1].GetComponent <ObiCollider>(), Vector3.zero, 1.0f);
        pins.AddToSolver(null);
    }
    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");
    }
Beispiel #3
0
    private void Awake()
    {
        InteractableObjects = GetComponentsInChildren <VRTK_InteractableObject>();
        obiRope             = GetComponentInChildren <ObiRope>();
        pinConstrain        = GetComponentInChildren <ObiPinConstraints>();
        pinConstraintBatch  = pinConstrain.GetFirstBatch();
        obiSolver           = GetComponentInChildren <ObiSolver>();
        UpdateIndex();
        NameOfParticleLast  = pinConstraintBatch.pinBodies[LastParticleConstrainIndex].gameObject.name;
        NameOfParticleFirst = pinConstraintBatch.pinBodies[FirstParticleConstrainIndex].gameObject.name;

        foreach (var interactObject in InteractableObjects)
        {
            interactObject.InteractableObjectGrabbed   += InteractObject_InteractableObjectGrabbed;
            interactObject.InteractableObjectUngrabbed += InteractObject_InteractableObjectUngrabbed;
        }
    }
    void pin_right()
    {
        rightpin++;
        ObiPinConstraints pins = this.GetComponent <ObiPinConstraints>();

        Debug.Log(pins.gameObject);
        pins.RemoveFromSolver(null);
        kdtreesearch_right();
        ObiPinConstraintBatch batch = pins.GetFirstBatch() as ObiPinConstraintBatch;

        for (int j = 0; j < 16; j++)
        {
            batch.AddConstraint(particleindexsphere[1][j], twoobject[1].GetComponent <ObiCollider>(), Vector3.zero, 1.0f);
        }
        //twoobject[0].GetComponent<ObiCollider>().Phase = 1;
        //twoobject[0].AddComponent<ObjectDragger>();
        batch.AddConstraint(centerparciel[1], twoobject[1].GetComponent <ObiCollider>(), Vector3.zero, 1.0f);
        pins.AddToSolver(null);
    }
Beispiel #5
0
    void pinrotate_ready()
    {
        ObiPinConstraints pins = this.GetComponent <ObiPinConstraints>();

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

        kdtreesearch();
        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 16; j++)   //16 or 36 further testing
            {
                batch.AddConstraint(particleindexsphere[i][j], twoobject[i].GetComponent <ObiCollider>(), Vector3.zero, 1.0f);
            }
            twoobject[i].GetComponent <ObiCollider>().Phase = 1;
            //twoobject[i].AddComponent<ObjectDragger>();
            //Debug.Log(twoobject[i].transform.position);
        }
        batch.AddConstraint(centerparciel[0], twoobject[0].GetComponent <ObiCollider>(), Vector3.zero, 1.0f);
        batch.AddConstraint(centerparciel[1], twoobject[1].GetComponent <ObiCollider>(), Vector3.zero, 1.0f);
        pins.AddToSolver(null);
    }
Beispiel #6
0
    private void Start()
    {
        obiRope            = transform.parent.GetComponentInChildren <ObiRope>();
        pinConstrain       = transform.parent.GetComponentInChildren <ObiPinConstraints>();
        pinConstraintBatch = pinConstrain.GetFirstBatch();
        obiSolver          = transform.parent.GetComponentInChildren <ObiSolver>();
        int LastParticleConstrainIndex = pinConstraintBatch.GetConstraintsInvolvingParticle(obiRope.UsedParticles - 1).Count != 0 ?
                                         pinConstraintBatch.GetConstraintsInvolvingParticle(obiRope.UsedParticles - 1)[0] : -1;
        int FirstParticleConstrainIndex = pinConstraintBatch.GetConstraintsInvolvingParticle(0).Count != 0 ?
                                          pinConstraintBatch.GetConstraintsInvolvingParticle(0)[0] : -1;

        if (gameObject == pinConstraintBatch.pinBodies[LastParticleConstrainIndex].gameObject)
        {
            particleIndexOne = obiRope.UsedParticles - 1;
            particleIndexTwo = particleIndexOne - 1;
        }
        else if (gameObject == pinConstraintBatch.pinBodies[FirstParticleConstrainIndex].gameObject)
        {
            particleIndexOne = 0;
            particleIndexTwo = 1;
        }
        else
        {
            particleIndexOne = -1;
            particleIndexTwo = -1;
        }

        if (m_Handle != null)
        {
            m_Handle.InteractableObjectUsed   += M_Handle_InteractableObjectUsed;
            m_Handle.InteractableObjectUnused += M_Handle_InteractableObjectUnused;
        }
        UpdateIndex();
        particleOffsetOne = pinConstraintBatch.pinOffsets[contraintIndexOne];
        particleOffsetTwo = pinConstraintBatch.pinOffsets[contraintIndexTwo];
        Debug.Log(particleOffsetOne);
        Debug.Log(particleOffsetTwo);
        GetComponent <MeshRenderer>().material.color = m_ColorInactive;
    }
Beispiel #7
0
 private void Awake()
 {
     pinConstraints = GetComponent <ObiPinConstraints>();
 }
    IEnumerator Setup()
    {
        extractionObject = (GameObject)Instantiate(models[0]);
        heavyCargoObject = (GameObject)Instantiate(models[1]);

        extractionObject.transform.position = initialExtractionPos;
        heavyCargoObject.transform.position = initialHeavyCargoPos;

        start = extractionObject.transform;
        end   = heavyCargoObject.transform;

        // Get all needed components and interconnect them:
        rope          = GetComponent <ObiRope>();
        path          = GetComponent <ObiCatmullRomCurve>();
        rope.Solver   = (ObiSolver)Instantiate(solver);
        rope.ropePath = path;
        rope.section  = section;
        GetComponent <MeshRenderer>().material = material;

        // Calculate rope start/end and direction in local space: (plus offset)
        Vector3 localStart = transform.InverseTransformPoint(start.position + new Vector3(0, 0.2f, 0));
        Vector3 localEnd   = transform.InverseTransformPoint(end.position + new Vector3(0, 0.5f, 0));
        Vector3 direction  = (localEnd - localStart).normalized;

        // Generate rope path:
        path.controlPoints.Clear();
        path.controlPoints.Add(localStart - direction);
        path.controlPoints.Add(localStart);
        path.controlPoints.Add(localEnd);
        path.controlPoints.Add(localEnd + direction);

        //correct thickness, particle resolution, and parenting
        rope.thickness        = 0.025f;
        rope.resolution       = 0.05f;
        rope.transform.parent = heavyCargoObject.transform;

        // Generate particles and add them to solver:
        yield return(StartCoroutine(rope.GeneratePhysicRepresentationForMesh()));

        rope.AddToSolver(null);

        // Fix first and last particle in place:
        //rope.invMasses[0] = 0;
        //rope.invMasses[rope.UsedParticles-1] = 0;
        //Oni.SetParticleInverseMasses(solver.OniSolver,new float[]{0},1,rope.particleIndices[0]);
        //Oni.SetParticleInverseMasses(solver.OniSolver,new float[]{0},1,rope.particleIndices[rope.UsedParticles-1]);

        constraints      = rope.GetComponent <ObiPinConstraints>();
        constraintsBatch = rope.PinConstraints.GetFirstBatch();

        extractionCollider = new ObiCollider();
        cargoCollider      = new ObiCollider();

        BoxCollider extractionBox = extractionObject.AddComponent <BoxCollider>();

        extractionBox.size = Vector3.zero;
        BoxCollider cargoBox = heavyCargoObject.AddComponent <BoxCollider>();

        cargoBox.center = new Vector3(0.0f, 0.5f, 0.0f);

        extractionCollider = extractionObject.AddComponent(typeof(ObiCollider)) as ObiCollider;
        cargoCollider      = heavyCargoObject.AddComponent(typeof(ObiCollider)) as ObiCollider;

        // remove the constraints from the solver, because we cannot modify the constraints list while the solver is using it.
        constraints.RemoveFromSolver(null);
        constraintsBatch.AddConstraint(0, extractionCollider, Vector3.zero, 0.0f);
        constraintsBatch.AddConstraint(rope.UsedParticles - 1, cargoCollider, Vector3.zero, 0.0f);
        constraints.AddToSolver(null);
        constraints.PushDataToSolver();
    }
Beispiel #9
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");
            }
        }
    }
Beispiel #10
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);
    }