/// <summary>
    /// MakeRope and AddPendulum may NOT be called on the same frame. You must wait for the MakeRope coroutine to finish first, as creating a rope is an asynchronous operation.
    /// Just adds a pendulum to the rope on the un-anchored end.
    /// </summary>
    public void AddPendulum(ObiCollider pendulum, Vector3 attachmentOffset)
    {
        // simply add a new pin constraint (see http://obi.virtualmethodstudio.com/tutorials/scriptingconstraints.html)

        /*rope.PinConstraints.RemoveFromSolver(null);
         * ObiPinConstraintBatch batch = (ObiPinConstraintBatch)rope.PinConstraints.GetFirstBatch();
         * batch.AddConstraint(pinnedParticle, pendulum, attachmentOffset,Quaternion.identity, 1);
         * rope.PinConstraints.AddToSolver(null);*/
    }
Ejemplo n.º 2
0
    private void PinRope(ObiRope rope, ObiCollider bodyA, ObiCollider bodyB, Vector3 offsetA, Vector3 offsetB)
    {
        // Pin both ends of the rope (this enables two-way interaction between character and rope):
        var pinConstraints = rope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints <ObiPinConstraintsBatch>;

        pinConstraints.Clear();
        var batch = new ObiPinConstraintsBatch();

        batch.AddConstraint(rope.solverIndices[0], bodyA, offsetA, Quaternion.identity, 0, 999, float.PositiveInfinity);
        batch.AddConstraint(rope.solverIndices[rope.activeParticleCount - 1], bodyB, offsetB, Quaternion.identity, 0, 999, float.PositiveInfinity);
        batch.activeConstraintCount = 2;
        pinConstraints.AddBatch(batch);
    }
Ejemplo n.º 3
0
    private void CreateNet(ObiSolver solver)
    {
        ObiCollider[,] nodes = new ObiCollider[resolution.x + 1, resolution.y + 1];

        for (int x = 0; x <= resolution.x; ++x)
        {
            for (int y = 0; y <= resolution.y; ++y)
            {
                GameObject rb = GameObject.CreatePrimitive(PrimitiveType.Cube);
                rb.AddComponent <Rigidbody>();
                rb.transform.position   = new Vector3(x, y, 0) * size;
                rb.transform.localScale = new Vector3(nodeSize, nodeSize, nodeSize);

                nodes[x, y]       = rb.AddComponent <ObiCollider>();
                nodes[x, y].Phase = 1;
            }
        }

        nodes[0, resolution.y].GetComponent <Rigidbody>().isKinematic            = true;
        nodes[resolution.x, resolution.y].GetComponent <Rigidbody>().isKinematic = true;

        for (int x = 0; x <= resolution.x; ++x)
        {
            for (int y = 0; y <= resolution.y; ++y)
            {
                Vector3 pos = new Vector3(x, y, 0) * size;
                if (x < resolution.x)
                {
                    Vector3 offset = new Vector3(nodeSize * 0.5f, 0, 0);
                    var     rope   = CreateRope(pos + offset, pos + new Vector3(size.x, 0, 0) - offset);
                    rope.transform.parent = solver.transform;

                    PinRope(rope, nodes[x, y], nodes[x + 1, y], new Vector3(0.5f, 0, 0), -new Vector3(0.5f, 0, 0));
                }

                if (y < resolution.y)
                {
                    Vector3 offset = new Vector3(0, nodeSize * 0.5f, 0);
                    var     rope   = CreateRope(pos + offset, pos + new Vector3(0, size.y, 0) - offset);
                    rope.transform.parent = solver.transform;

                    PinRope(rope, nodes[x, y], nodes[x, y + 1], new Vector3(0, 0.5f, 0), -new Vector3(0, 0.5f, 0));
                }
            }
        }
    }
Ejemplo n.º 4
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();
    }
Ejemplo n.º 5
0
    // Use this for initialization
    void Start()
    {
        restDarboux = new Quaternion(0.7f, 0.0f, 0.0f, 0.7f);       // constant
        offset      = new Vector3(0.2f, -1.0f, -0.3f);
        offsetNeg   = new Vector3(-0.2f, -1.0f, -0.3f);

        leftController  = VRTK_DeviceFinder.GetControllerLeftHand();
        rightController = VRTK_DeviceFinder.GetControllerRightHand();
        leftHandler     = GameObject.Find("left_hand");
        rightHandler    = GameObject.Find("right_hand");
        tapeSection     = GameObject.Find("clothPart");
        obiCloth        = tapeSection.GetComponent <ObiCloth>();

        leftCollider  = leftHandler.GetComponent <ObiCollider>();
        rightCollider = rightHandler.GetComponent <ObiCollider>();

        hint = GameObject.FindGameObjectsWithTag("Hint");

        audioHint[0] = false;
        audioHint[1] = false;
        audioHint[2] = false;
        audioHint[3] = false;

        stickPos[0] = GameObject.Find("StickPos_1");
        stickPos[1] = GameObject.Find("StickPos_2");
        stickPos[2] = GameObject.Find("StickPos_3");
        stickPos[3] = GameObject.Find("StickPos_4");

        foreach (var item in hint)
        {
            ParticleSystem particleSystem = item.GetComponent <ParticleSystem>();
            if (!particleSystem.isStopped)
            {
                particleSystem.Stop();
            }
        }

        Debug.Log("current part: " + StaticData.getTargetNum());

        string leftPath = "[VRTK_SDKManager]/SDKSetups/SteamVR/[CameraRig]/Controller (left)/Model";

        rightHighlighter = GameObject.Find(leftPath).GetComponent <VRTK_ControllerHighlighter>();
        string rightPath = "[VRTK_SDKManager]/SDKSetups/SteamVR/[CameraRig]/Controller (right)/Model";

        rightHighlighter = GameObject.Find(rightPath).GetComponent <VRTK_ControllerHighlighter>();
    }
Ejemplo n.º 6
0
 private void OnCollisionEnter(Collision collision)
 {
     if (!isActivateStick)
     {
         return;
     }
     if (collision.transform.CompareTag("StickcableObject"))
     {
         ObiCollider ObjectToStick = collision.gameObject.GetComponent <ObiCollider>();
         Vector3     Normal        = collision.GetContact(0).normal;
         pinConstrain.RemoveFromSolver(null);
         Vector3 DistanceVector = transform.TransformPoint(particleOffsetOne) -
                                  transform.TransformPoint(particleOffsetTwo);
         particlesDistance = DistanceVector.magnitude;
         SetPinConstraints(ObjectToStick, Normal);
         pinConstrain.AddToSolver(null);
         isStuck = true;
         DisActivateSticky();
     }
 }
Ejemplo n.º 7
0
    private void BuildActionPillar()
    {
        inactiveVector.y   = 2.5f;
        transform.position = inactiveVector;

        string     tileName     = $"[{tile.coordinates[0]},{tile.coordinates[1]},{tile.coordinates[2]}]";
        string     actionName   = $"[{String.Join(",", tile.actions)}]";
        GameObject actionPillar = GameObject.CreatePrimitive(PrimitiveType.Cylinder);

        actionPillar.transform.position = new Vector3(
            transform.position.x,
            0.5f,
            transform.position.z
            );
        actionPillar.transform.localScale = new Vector3(0.5f, 2, 0.5f);
        actionPillar.name = $"{tileName}:{actionName}";

        ObiCollider collider = actionPillar.AddComponent(typeof(ObiCollider)) as ObiCollider;

        collider.Thickness         = 0.2f;
        collider.CollisionMaterial = new ObiCollisionMaterial();
    }
Ejemplo n.º 8
0
 void Awake()
 {
     collider = GetComponent <ObiCollider>();
 }
Ejemplo n.º 9
0
    private HashSet <ObiActor> grabbedActors           = new HashSet <ObiActor>();                                                                   /**< set of softbodies grabbed during this step.*/

    private void Awake()
    {
        localCollider = GetComponent <ObiCollider>();
    }
Ejemplo n.º 10
0
    public IEnumerator MakeRope()
    {
        print("Load Extraction Rope");
        ropeObject = new GameObject("rope",
                                    typeof(ObiSolver),
                                    typeof(ObiRope),
                                    typeof(ObiCatmullRomCurve),
                                    typeof(ObiRopeCursor));

        // get references to all components:
        ObiSolver solver = ropeObject.GetComponent <ObiSolver>();

        rope = ropeObject.GetComponent <ObiRope>();
        ObiCatmullRomCurve path = ropeObject.GetComponent <ObiCatmullRomCurve>();

        //ObiRopeCursor cursor = ropeObject.GetComponent<ObiRopeCursor>();

        // set up component references
        rope.Solver   = solver;
        rope.ropePath = path;
        rope.section  = (ObiRopeSection)Resources.Load("DefaultRopeSection");
        rope.GetComponent <MeshRenderer>().material = material;
        //cursor.rope = rope;

        // Calculate rope start/end and direction in local space: (plus offset)
        Vector3 localStart = transform.InverseTransformPoint(chutes[0].transform.position + new Vector3(0, 0.2f, 0));
        Vector3 localEnd   = transform.InverseTransformPoint(payloads[0].transform.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 = payloads[0].transform;

        yield return(rope.StartCoroutine(rope.GeneratePhysicRepresentationForMesh()));

        rope.AddToSolver(null);

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

        BoxCollider extractionBox = chutes[0].AddComponent <BoxCollider>();

        extractionBox.size = Vector3.zero;
        BoxCollider cargoBox = payloads[0].AddComponent <BoxCollider>();

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

        extractionCollider = chutes[0].AddComponent <ObiCollider>();
        cargoCollider      = payloads[0].AddComponent <ObiCollider>();

        // remove the constraints from the solver, because we cannot modify the constraints list while the solver is using it.
        rope.PinConstraints.RemoveFromSolver(null);
        ObiPinConstraintBatch constraintsBatch = rope.PinConstraints.GetFirstBatch();

        constraintsBatch.AddConstraint(0, extractionCollider, Vector3.zero, 0.0f);
        constraintsBatch.AddConstraint(rope.UsedParticles - 1, cargoCollider, new Vector3(0, 0.5f, -0.25f), 0.0f);
        rope.PinConstraints.AddToSolver(null);
        rope.PinConstraints.PushDataToSolver();
    }
Ejemplo n.º 11
0
    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();
    }
Ejemplo n.º 12
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);
    }