void Awake()
    {
        // Create both the rope and the solver:
        rope   = gameObject.AddComponent <ObiRope>();
        curve  = gameObject.AddComponent <ObiCatmullRomCurve>();
        solver = gameObject.AddComponent <ObiSolver>();

        // Provide a solver and a curve:
        rope.Solver   = solver;
        rope.ropePath = curve;
        rope.GetComponent <MeshRenderer>().material = material;

        // Configure rope and solver parameters:
        rope.resolution = 0.1f;
        rope.BendingConstraints.stiffness = 0.2f;
        rope.uvScale    = new Vector2(1, 5);
        rope.normalizeV = false;
        rope.uvAnchor   = 1;

        solver.substeps = 3;
        solver.distanceConstraintParameters.iterations       = 5;
        solver.pinConstraintParameters.iterations            = 5;
        solver.bendingConstraintParameters.iterations        = 1;
        solver.particleCollisionConstraintParameters.enabled = false;
        solver.volumeConstraintParameters.enabled            = false;
        solver.densityConstraintParameters.enabled           = false;
        solver.stitchConstraintParameters.enabled            = false;
        solver.skinConstraintParameters.enabled   = false;
        solver.tetherConstraintParameters.enabled = false;

        // Add a cursor to be able to change rope length:
        cursor = rope.gameObject.AddComponent <ObiRopeCursor>();
        cursor.normalizedCoord = 0;
        cursor.direction       = true;
    }
Example #2
0
    private void ObiSolverOnOnCollision(ObiSolver solver, ObiSolver.ObiCollisionEventArgs contacts)
    {
        //   var contact = contacts.contacts[0];


        foreach (var contact in contacts.contacts)
        {
            // this one is an actual collision:
            if (contact.distance < 0.01)
            {
                ObiCollider.idToCollider.TryGetValue(contact.other, out var collider);
                if (collider != null)
                {
                    if (collider.tag == "GameOverTrigger")
                    {
                        var emitter = (ObiEmitter)solver.particleToActor[contact.particle].actor;
                        emitter.life[solver.particleToActor[contact.particle].indexInActor] = 0;

                        if (_solverStore.IsAllPlayerPuddlesDied())
                        {
                            OnDied?.Invoke();
                        }
                    }

                    if (collider.tag == "Connectable")
                    {
                        var puddle = collider.GetComponent <Puddle>();
                        puddle.Join(_obiEmitter);
                        _source.PlayOneShot(_source.clip);
                    }
                }
            }
        }
    }
 public ObiBendingConstraintGroup(ObiSolver solver)
     : base(solver)
 {
     bendingIndices = new int[0];
     restBends = new float[0];
     bendingStiffnesses = new Vector2[0];
 }
    private void Solver_OnCollision(ObiSolver s, ObiSolver.ObiCollisionEventArgs e)
    {
        // reset to unwrapped state:
        foreach (var wrappable in wrappables)
        {
            wrappable.Reset();
        }

        var world = ObiColliderWorld.GetInstance();

        foreach (Oni.Contact contact in e.contacts)
        {
            // look for actual contacts only:
            if (contact.distance < 0.025f)
            {
                var col = world.colliderHandles[contact.bodyB].owner;
                if (col != null)
                {
                    var wrappable = col.GetComponent <Wrappable>();
                    if (wrappable != null)
                    {
                        wrappable.SetWrapped();
                    }
                }
            }
        }
    }
 public ObiSkinConstraintGroup(ObiSolver solver)
     : base(solver)
 {
     skinIndices = new int[0];
     skinPoints = new Vector3[0];
     skinNormals = new Vector3[0];
     skinRadiiBackstops = new float[0];
     skinStiffnesses = new float[0];
 }
    /// <summary>
    /// Creates a straight rope anchored to a transform at the top.
    /// Transform may or may not move around and may or may not have a rigidbody.
    /// When you call this the rope will appear in the scene and immediately interact with gravity and objects with ObiColliders.
    /// Called from anywhere (main thread only)
    /// </summary>
    public IEnumerator MakeRope(Transform anchoredTo, Vector3 attachmentOffset, float ropeLength)
    {
        // create a new GameObject with the required components: a solver, a rope, and a curve.
        // we also throw a cursor in to be able to change its length.
        GameObject ropeObject = new GameObject("rope", typeof(ObiSolver),
                                               typeof(ObiRope),
                                               typeof(ObiCatmullRomCurve),
                                               typeof(ObiRopeCursor));

        // get references to all components:
        rope   = ropeObject.GetComponent <ObiRope>();
        cursor = ropeObject.GetComponent <ObiRopeCursor>();
        solver = ropeObject.GetComponent <ObiSolver>();
        ObiCatmullRomCurve path = ropeObject.GetComponent <ObiCatmullRomCurve>();

        // set up component references (see ObiRopeHelper.cs)
        rope.Solver   = solver;
        rope.ropePath = path;
        rope.section  = Resources.Load <ObiRopeSection>("DefaultRopeSection");

        // set path control points (duplicate end points, to set curvature as required by CatmullRom splines):
        path.controlPoints.Clear();
        path.controlPoints.Add(Vector3.zero);
        path.controlPoints.Add(Vector3.zero);
        path.controlPoints.Add(Vector3.down * ropeLength);
        path.controlPoints.Add(Vector3.down * ropeLength);

        rope.pooledParticles = 2000;

        // parent the rope to the anchor transform:
        rope.transform.SetParent(anchoredTo, false);
        rope.transform.localPosition = attachmentOffset;

        // generate particles/constraints and add them to the solver (see ObiRopeHelper.cs)
        yield return(rope.StartCoroutine(rope.GeneratePhysicRepresentationForMesh()));

        rope.AddToSolver(null);

        // get the last particle in the rope at its rest state.
        pinnedParticle = rope.UsedParticles - 1;

        // add a tethers batch:
        ObiTetherConstraintBatch tetherBatch = new ObiTetherConstraintBatch(true, false, 0, 1);

        rope.TetherConstraints.AddBatch(tetherBatch);
        //UpdateTethers();

        // fix first particle in place (see http://obi.virtualmethodstudio.com/tutorials/scriptingparticles.html)
        rope.invMasses[0] = 0;
        Oni.SetParticleInverseMasses(solver.OniSolver, new float[] { 0 }, 1, rope.particleIndices[0]);
    }
Example #7
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;
        }
    }
Example #8
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));
                }
            }
        }
    }
Example #9
0
    public IEnumerator MakeCloth(Vector3 attachmentOffset)//Transform anchoredTo, Vector3 attachmentOffset
    {
        /*生成方形碰撞体*/
        myCube      = GameObject.CreatePrimitive(PrimitiveType.Cube);
        myCube.name = "myCube";
        myCube.transform.position = attachmentOffset;

        /*生成平面布料*/
        myPlane      = GameObject.CreatePrimitive(PrimitiveType.Plane);
        myPlane.name = "myPlane";
        myPlane.AddComponent <ObiCloth>();
        myPlane.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
        myPlane.transform.position   = new Vector3(attachmentOffset.x, attachmentOffset.y + 2, attachmentOffset.z);


        /*生成求解器*/
        mySolver = new GameObject("mySolver", typeof(ObiSolver));


        /*各组件绑定*/
        cloth  = myPlane.GetComponent <ObiCloth>();
        solver = mySolver.GetComponent <ObiSolver>();

        /*生成拓扑*/
        topology           = ScriptableObject.CreateInstance <ObiMeshTopology>();
        topology.InputMesh = myPlane.GetComponent <MeshCollider>().sharedMesh;
        topology.scale     = new Vector3(0.3f, 0.3f, 0.3f);
        topology.Generate();

        /*衣服组件绑定求解器和拓扑*/
        cloth.Solver         = solver;
        cloth.SharedTopology = topology;

        //不需要Init?

        //碰撞处理
        addCollision();

        //多线程
        yield return(cloth.StartCoroutine(cloth.GeneratePhysicRepresentationForMesh()));

        cloth.AddToSolver(null);
    }
    private void Solver_OnCollision(ObiSolver solver, ObiSolver.ObiCollisionEventArgs e)
    {
        onGround = false;

        var world = ObiColliderWorld.GetInstance();

        foreach (Oni.Contact contact in e.contacts)
        {
            // look for actual contacts only:
            if (contact.distance > 0.01)
            {
                var col = world.colliderHandles[contact.other].owner;
                if (col != null)
                {
                    onGround = true;
                    return;
                }
            }
        }
    }
Example #11
0
    /**
     * Creates and stores a GrabbedParticle from the particle at the given index.
     * Returns true if we sucessfully grabbed a particle, false if the particle was already grabbed.
     */
    private bool GrabParticle(ObiSolver solver, int index)
    {
        GrabbedParticle p = new GrabbedParticle(solver, index, solver.invMasses[index]);

        // in case this particle has not been grabbed yet:
        if (!grabbedParticles.Contains(p))
        {
            Matrix4x4 solver2Grabber = transform.worldToLocalMatrix * solver.transform.localToWorldMatrix;

            // record the particle's position relative to the grabber, and store it.
            p.localPosition = solver2Grabber.MultiplyPoint3x4(solver.positions[index]);
            grabbedParticles.Add(p);

            // Set inv mass and velocity to zero:
            solver.invMasses[index]  = 0;
            solver.velocities[index] = Vector4.zero;

            return(true);
        }
        return(false);
    }
Example #12
0
    void Awake()
    {
        // create an object containing both the solver and the updater:
        GameObject      solverObject = new GameObject("solver", typeof(ObiSolver), typeof(ObiFixedUpdater));
        ObiSolver       solver       = solverObject.GetComponent <ObiSolver>();
        ObiFixedUpdater updater      = solverObject.GetComponent <ObiFixedUpdater>();

        updater.substeps = 2;

        // adjust solver settings:
        solver.particleCollisionConstraintParameters.enabled = false;
        solver.distanceConstraintParameters.iterations       = 8;
        solver.pinConstraintParameters.iterations            = 4;
        solver.parameters.sleepThreshold = 0.001f;
        solver.PushSolverParameters();

        // add the solver to the updater:
        updater.solvers.Add(solver);

        // create the net (ropes + rigidbodies)
        CreateNet(solver);
    }
Example #13
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;
    }
Example #14
0
    private void Solver_OnCollision(ObiSolver s, ObiSolver.ObiCollisionEventArgs e)
    {
        var world = ObiColliderWorld.GetInstance();

        foreach (Oni.Contact contact in e.contacts)
        {
            // look for actual contacts only:
            if (contact.distance > 0.01)
            {
                var col = world.colliderHandles[contact.other].owner;
                if (col == deathPitCollider)
                {
                    onDeath.Invoke();
                    return;
                }
                if (col == finishCollider)
                {
                    onFinish.Invoke();
                    return;
                }
            }
        }
    }
Example #15
0
    private void Solver_OnCollision(ObiSolver s, ObiSolver.ObiCollisionEventArgs e)
    {
        var world = ObiColliderWorld.GetInstance();

        foreach (Oni.Contact contact in e.contacts)
        {
            // look for actual contacts only:
            if (contact.distance < 0.01f)
            {
                var col = world.colliderHandles[contact.bodyB].owner;
                if (colorizers[0].collider == col)
                {
                    solver.userData[contact.bodyA] = colorizers[0].color;
                    if (coloredParticles.Add(contact.bodyA))
                    {
                        UpdateScore(finishedParticles.Count, coloredParticles.Count);
                    }
                }
                else if (colorizers[1].collider == col)
                {
                    solver.userData[contact.bodyA] = colorizers[1].color;
                    if (coloredParticles.Add(contact.bodyA))
                    {
                        UpdateScore(finishedParticles.Count, coloredParticles.Count);
                    }
                }
                else if (finishLine == col)
                {
                    if (finishedParticles.Add(contact.bodyA))
                    {
                        UpdateScore(finishedParticles.Count, coloredParticles.Count);
                    }
                }
            }
        }
    }
    private void Awake()
    {
        solver = GetComponent <ObiSolver>();

        VRTK_SDKManager.instance.AddBehaviourToToggleOnLoadedSetupChange(this);
    }
 void Awake()
 {
     solver = GetComponent <Obi.ObiSolver>();
 }
Example #18
0
 void Awake()
 {
     solver                       = GetComponent <Obi.ObiSolver>();
     collidedParticles            = new List <int>();
     numberOfNeededFluidParticles = GetComponent <ObiEmitter>().NumParticles;
 }
Example #19
0
    //follow the same way choose two particle and then form a line. get the vector!     + render differently
    void particle_drawline_initial()
    {
        if (pickArgs != null && drawparticle < 1)
        {
            if (dcounttwo < 2)
            {
                ObiSolver solver         = picker.Cloth.Solver;
                Vector3   targetPosition = pickArgs.worldPosition;
                if (solver.simulateInLocalSpace)
                {
                    targetPosition = solver.transform.InverseTransformPoint(targetPosition);
                }

                // TAG THIS PARTICLE produce a little sphere once click
                Vector4[] positions   = new Vector4[1];
                Vector4[] velocities  = new Vector4[1];
                int       solverIndex = picker.Cloth.particleIndices[pickArgs.particleIndex];
                Oni.GetParticlePositions(solver.OniSolver, positions, 1, solverIndex);
                GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                //Debug.Log(sphere.GetType());
                sphere.transform.position   = positions[0];
                sphere.transform.localScale = new Vector3(0.04f, 0.04f, 0.04f);
                sphere.AddComponent <ObiCollider>();
                Renderer thissphere = sphere.GetComponent <Renderer>();
                if (dcounttwo == 0)
                {
                    thissphere.material.color = Color.red;
                }
                else
                {
                    thissphere.material.color = Color.blue;
                }
                twoobject[dcounttwo] = sphere;
                sphere.GetComponent <ObiCollider>().Phase = 1;
                //particleindexsphere[dcounttwo] = pickArgs.particleIndex;
                drawparticle++;
                dcounttwo++;
            }
            else
            {
                Destroy(twoobject[mod2]);
                mod2++; mod2 %= 2;
                ObiSolver solver         = picker.Cloth.Solver;
                Vector3   targetPosition = pickArgs.worldPosition;
                if (solver.simulateInLocalSpace)
                {
                    targetPosition = solver.transform.InverseTransformPoint(targetPosition);
                }
                // TAG THIS PARTICLE produce a little sphere once click
                Vector4[] positions   = new Vector4[1];
                Vector4[] velocities  = new Vector4[1];
                int       solverIndex = picker.Cloth.particleIndices[pickArgs.particleIndex];
                Oni.GetParticlePositions(solver.OniSolver, positions, 1, solverIndex);
                GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                //Debug.Log(sphere.GetType());
                sphere.transform.position   = positions[0];
                sphere.transform.localScale = new Vector3(0.04f, 0.04f, 0.04f);
                sphere.AddComponent <ObiCollider>();
                sphere.GetComponent <ObiCollider>().Phase = 1;
                Renderer thissphere = sphere.GetComponent <Renderer>();
                if ((mod2 + 1) % 2 == 0)
                {
                    thissphere.material.color = Color.red;
                }
                else
                {
                    thissphere.material.color = Color.blue;
                }
                twoobject[(mod2 + 1) % 2] = sphere;
                // particleindexsphere[(mod2 + 1) % 2] = pickArgs.particleIndex;
                drawparticle++;
            }
        }
        else if (pickArgs == null)    // make one click generate one particle
        {
            drawparticle = 0;
        }
    }
Example #20
0
 private void Start()
 {
     // Получить компоненты Rope и Solver
     _obiR   = gameObject.GetComponent <ObiRope>();
     _solver = _obiR.solver;
 }
Example #21
0
 public GrabbedParticle(ObiSolver solver, int index, float invMass)
 {
     this.solver  = solver;
     this.index   = index;
     this.invMass = invMass;
 }
Example #22
0
    void Start()
    {
        GameObject      solverObject = new GameObject("String Solver", typeof(ObiSolver), typeof(ObiFixedUpdater));
        ObiSolver       solver       = solverObject.GetComponent <ObiSolver>();
        ObiFixedUpdater updater      = solverObject.GetComponent <ObiFixedUpdater>();

        updater.solvers.Add(solver);
        solverObject.AddComponent(typeof(HexPathFinder));
        solver.distanceConstraintParameters          = new Oni.ConstraintParameters(true, Oni.ConstraintParameters.EvaluationOrder.Sequential, 100);
        solver.particleCollisionConstraintParameters = new Oni.ConstraintParameters(true, Oni.ConstraintParameters.EvaluationOrder.Sequential, 30);
        solver.collisionConstraintParameters         = new Oni.ConstraintParameters(true, Oni.ConstraintParameters.EvaluationOrder.Sequential, 30);
        solver.tetherConstraintParameters            = new Oni.ConstraintParameters(true, Oni.ConstraintParameters.EvaluationOrder.Sequential, 50);

        // Disable
        solver.skinConstraintParameters          = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1);
        solver.densityConstraintParameters       = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1);
        solver.stretchShearConstraintParameters  = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1);
        solver.stitchConstraintParameters        = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1);
        solver.volumeConstraintParameters        = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1);
        solver.bendTwistConstraintParameters     = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1);
        solver.shapeMatchingConstraintParameters = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1);
        // solver.frictionConstraintParameters = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1);
        // solver.particleFrictionConstraintParameters = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1);

        // create the blueprint: (ltObiRopeBlueprint, ObiRodBlueprint)
        var blueprint = ScriptableObject.CreateInstance <ObiRopeBlueprint>();

        blueprint.pooledParticles = 20000;
        blueprint.resolution      = 1f;

        // Procedurally generate the rope path (a simple straight line):
        blueprint.path.Clear();
        blueprint.path.AddControlPoint(
            new Vector3(0, 0.011f, 0),
            -Vector3.right,
            Vector3.right,
            Vector3.up,
            0.005f,
            0.005f,
            0.03f,
            1,
            Color.white,
            "start"
            );
        blueprint.path.AddControlPoint(
            new Vector3(0, 0.5f, 0),
            -Vector3.right,
            Vector3.right,
            Vector3.up,
            0.005f,
            0.005f,
            0.03f,
            1,
            Color.white,
            "end"
            );
        blueprint.path.FlushEvents();

        blueprint.GenerateImmediate();

        GameObject ropeObject = new GameObject("String", typeof(ObiRope), typeof(ObiRopeExtrudedRenderer));

        ObiRope rope = ropeObject.GetComponent <ObiRope>();
        ObiRopeExtrudedRenderer ropeRenderer = ropeObject.GetComponent <ObiRopeExtrudedRenderer>();
        MeshRenderer            ropeMesh     = ropeObject.GetComponent <MeshRenderer>();

        if (stringMaterial == null)
        {
            ropeMesh.material = new Material(Shader.Find("StringShader"));
        }
        else
        {
            ropeMesh.material = stringMaterial;
        }


        ropeRenderer.section = Resources.Load <ObiRopeSection>("DefaultRopeSection");

        rope.ropeBlueprint = ScriptableObject.Instantiate(blueprint);

        rope.transform.parent = solver.transform;
        // rope.collisionMaterial = collisionMaterial;
        rope.selfCollisions  = false;
        rope.stretchingScale = 1;

        ObiRopeCursor cursor = ropeObject.AddComponent(typeof(ObiRopeCursor)) as ObiRopeCursor;

        cursor.cursorMu = 0.5f;
        cursor.sourceMu = 0.5f;

        ObiParticleAttachment groundAttach = ropeObject.AddComponent(typeof(ObiParticleAttachment)) as ObiParticleAttachment;
        ObiParticleAttachment charAttach   = ropeObject.AddComponent(typeof(ObiParticleAttachment)) as ObiParticleAttachment;

        groundAttach.target = GameObject.Find("Floor").transform;
        // groundAttach.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;
        groundAttach.particleGroup = blueprint.groups[0];
        charAttach.target          = GameObject.Find("Ariadne").transform;
        charAttach.attachmentType  = ObiParticleAttachment.AttachmentType.Dynamic;
        charAttach.particleGroup   = blueprint.groups[1];

        ropeObject.AddComponent(typeof(StringController));
    }
    void choose()   //build pin constraints
    {
        if (pickArgsLeft != null)
        {
            ObiSolver solver         = picker.Cloth.Solver;
            Vector3   targetPosition = pickArgsLeft.worldPosition;
            if (solver.simulateInLocalSpace)
            {
                targetPosition = solver.transform.InverseTransformPoint(targetPosition);
            }

            // TAG THIS PARTICLE produce a little sphere once click
            Vector4[] positions   = new Vector4[1];
            Vector4[] velocities  = new Vector4[1];
            Vector3   position    = new Vector3();
            int       solverIndex = picker.Cloth.particleIndices[pickArgsLeft.particleIndex];
            Oni.GetParticlePositions(solver.OniSolver, positions, 1, solverIndex);
            // Oni.GetParticlePositions()
            // GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            // sphere.transform.position = positions[0];
            // sphere.transform.localScale = new Vector3(0.04f, 0.04f, 0.04f);
            //Debug.Log(sphere.GetType());
            centerparciel[0] = pickArgsLeft.particleIndex;
            position         = positions[0];
            float distance = (leftposition - position).magnitude;
            if (distance < 0.08f)
            {
                if (leftpin == 0)   //pin once
                {
                    twoobejectpositiononcloth[0] = position;
                    pin_left();
                }
            }
        }
        else if (pickArgsLeft == null && leftpin > 0)  //release_pin
        {
            release_pin_left();
        }

        if (pickArgsRight != null)
        {
            //Debug.Log("ppp");
            ObiSolver solver         = picker.Cloth.Solver;
            Vector3   targetPosition = pickArgsRight.worldPosition;
            if (solver.simulateInLocalSpace)
            {
                targetPosition = solver.transform.InverseTransformPoint(targetPosition);
            }

            // TAG THIS PARTICLE produce a little sphere once click
            Vector4[] positions   = new Vector4[1];
            Vector4[] velocities  = new Vector4[1];
            Vector3   position    = new Vector3();
            int       solverIndex = picker.Cloth.particleIndices[pickArgsRight.particleIndex];
            Oni.GetParticlePositions(solver.OniSolver, positions, 1, solverIndex);
            // Oni.GetParticlePositions()
            //GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            //sphere.transform.position = positions[0];
            //sphere.transform.localScale = new Vector3(0.04f, 0.04f, 0.04f);
            //Debug.Log(sphere.GetType());
            centerparciel[1] = pickArgsRight.particleIndex;
            position         = positions[0];
            float distance = (rightposition - position).magnitude;
            if (distance < 0.08f)
            {
                if (rightpin == 0)
                {
                    Debug.Log("sss_1");
                    twoobejectpositiononcloth[1] = position;
                    pin_right();
                }
            }
        }
        else if (pickArgsRight == null && rightpin > 0)
        {
            release_pin_right();
        }

        if (rightpin == 0 && leftpin == 0 && pickArgsRight == null && pickArgsLeft == null)  //kdtree update
        {
            rebuildtree();
        }

        /*
         * switch (button_choose)  //
         * {
         *   // case 0: resetflag = 0; particle_drawline_initial(); break;
         *   case 0: particle_drawline_initial(); break;
         *   case 1: fold_initial(); break;
         * }
         *
         * if (button_choose == 1 && drawlineVR.drawflag == 1 && enterfold == 0)   //record rotating axis
         * {
         *   mod2 = 0; rotateaxis = twoobject[1].transform.position - twoobject[0].transform.position;
         *   rotatepoint = (twoobject[1].transform.position + twoobject[0].transform.position) / 2;
         *   enterfold = 1;
         *   twoobject[0] = twoobject[1] = null;
         * }
         *
         * if (VRTK_ControllerEvents.drawflag == true && button_choose == 1 && enterfold == 1 && lineflag == 1)
         * {
         *   if (twoobject[0] && twoobject[1]) //two object exist
         *   {
         *       pin_rotate_ready();
         *       flag = 1;
         *   }
         * }
         */
    }
 public ObiSolverConstraintGroup(ObiSolver solver)
 {
     this.solver = solver;
     activeConstraints = new HashSet<int>();
 }
Example #25
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();
    }
Example #26
0
 // Start is called before the first frame update
 void Start()
 {
     solver = gameObject.GetComponent <ObiSolver>();
     InvokeRepeating("GetHexList", 2.0f, 1.0f);
 }
        // Use this for initialization
        void Awake()
        {
            solver = GetComponent<ObiSolver>();

            // Only bake/play on awake outside editor.
            if (Application.isPlaying){
                if (bakeOnAwake){
                    playhead = 0;
                    Baking = true;
                }else if (playOnAwake){
                    playhead = 0;
                    Playing = true;
                }
            }
        }
 public ISolverImpl CreateSolver(ObiSolver solver, int capacity)
 {
     return new NullSolverImpl();
 }
 private void Start()
 {
     solver              = GetComponentInParent <ObiSolver> ();
     solver.OnCollision += Solver_OnCollision;
 }
Example #30
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (pickArgs1 != null && cnt1 == 0)
        {
            ObiSolver solver         = picker.Cloth.Solver;
            Vector3   targetPosition = pickArgs1.worldPosition;
            if (solver.simulateInLocalSpace)
            {
                targetPosition = solver.transform.InverseTransformPoint(targetPosition);
            }

            // TAG THIS PARTICLE produce a little sphere once click
            Vector4[] positions   = new Vector4[1];
            Vector4[] velocities  = new Vector4[1];
            int       solverIndex = picker.Cloth.particleIndices[pickArgs1.particleIndex];
            Oni.GetParticlePositions(solver.OniSolver, positions, 1, solverIndex);
            // Oni.GetParticlePositions()
            GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            //Debug.Log(sphere.GetType());
            sphere.transform.position   = positions[0];
            sphere.transform.localScale = new Vector3(0.04f, 0.04f, 0.04f);
            sphere.AddComponent <ObiCollider>();
            Renderer thissphere = sphere.GetComponent <Renderer>();
            thissphere.material.color = Color.red;
            tmptwoobjectfordraw[0]    = sphere;
            sphere.GetComponent <ObiCollider>().Phase = 1;
            // particleindexsphere[counttwo][4] = pickArgs.particleIndex;
            // centerparciel[0] = pickArgs1.particleIndex;
            countparticle++;
            cnt1++;
        }
        else if (pickArgs2 != null && cnt2 == 0)
        {
            ObiSolver solver         = picker.Cloth.Solver;
            Vector3   targetPosition = pickArgs2.worldPosition;
            if (solver.simulateInLocalSpace)
            {
                targetPosition = solver.transform.InverseTransformPoint(targetPosition);
            }

            // TAG THIS PARTICLE produce a little sphere once click
            Vector4[] positions   = new Vector4[1];
            Vector4[] velocities  = new Vector4[1];
            int       solverIndex = picker.Cloth.particleIndices[pickArgs2.particleIndex];
            Oni.GetParticlePositions(solver.OniSolver, positions, 1, solverIndex);
            // Oni.GetParticlePositions()
            GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            //Debug.Log(sphere.GetType());
            sphere.transform.position   = positions[0];
            sphere.transform.localScale = new Vector3(0.04f, 0.04f, 0.04f);
            sphere.AddComponent <ObiCollider>();
            Renderer thissphere = sphere.GetComponent <Renderer>();
            thissphere.material.color = Color.blue;
            tmptwoobjectfordraw[1]    = sphere;
            sphere.GetComponent <ObiCollider>().Phase = 1;
            // particleindexsphere[counttwo][4] = pickArgs.particleIndex;
            //centerparciel[1] = pickArgs2.particleIndex;
            countparticle++;
            cnt2++;
            rotateaxis  = tmptwoobjectfordraw[1].transform.position - tmptwoobjectfordraw[0].transform.position;
            rotatepoint = (tmptwoobjectfordraw[1].transform.position + tmptwoobjectfordraw[0].transform.position) / 2;
        }

        if (cnt1 == 1 && cnt2 == 1 && dflag == 0)
        {
            dflag = 1;
        }

        if (draw_line_instruction.flag == 2 && flag == 0)  //two black
        {
            //Debug.Log("pos");
            if (pickArgs3 != null && cnt3 == 0)
            {
                //Debug.Log("pos===");
                ObiSolver solver         = picker.Cloth.Solver;
                Vector3   targetPosition = pickArgs3.worldPosition;
                if (solver.simulateInLocalSpace)
                {
                    targetPosition = solver.transform.InverseTransformPoint(targetPosition);
                }

                // TAG THIS PARTICLE produce a little sphere once click
                Vector4[] positions   = new Vector4[1];
                Vector4[] velocities  = new Vector4[1];
                int       solverIndex = picker.Cloth.particleIndices[pickArgs3.particleIndex];
                Oni.GetParticlePositions(solver.OniSolver, positions, 1, solverIndex);
                // Oni.GetParticlePositions()
                GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                //Debug.Log(sphere.GetType());
                sphere.transform.position   = positions[0];
                sphere.transform.localScale = new Vector3(0.04f, 0.04f, 0.04f);
                sphere.AddComponent <ObiCollider>();
                Renderer thissphere = sphere.GetComponent <Renderer>();
                thissphere.material.color = Color.black;
                twoobject[0] = sphere;
                sphere.GetComponent <ObiCollider>().Phase = 1;
                // particleindexsphere[counttwo][4] = pickArgs.particleIndex;
                centerparciel[0] = pickArgs3.particleIndex;
                countparticle++;
                cnt3++;
            }

            if (pickArgs4 != null && cnt4 == 0)
            {
                ObiSolver solver         = picker.Cloth.Solver;
                Vector3   targetPosition = pickArgs4.worldPosition;
                if (solver.simulateInLocalSpace)
                {
                    targetPosition = solver.transform.InverseTransformPoint(targetPosition);
                }

                // TAG THIS PARTICLE produce a little sphere once click
                Vector4[] positions   = new Vector4[1];
                Vector4[] velocities  = new Vector4[1];
                int       solverIndex = picker.Cloth.particleIndices[pickArgs4.particleIndex];
                Oni.GetParticlePositions(solver.OniSolver, positions, 1, solverIndex);
                // Oni.GetParticlePositions()
                GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                //Debug.Log(sphere.GetType());
                sphere.transform.position   = positions[0];
                sphere.transform.localScale = new Vector3(0.04f, 0.04f, 0.04f);
                sphere.AddComponent <ObiCollider>();
                Renderer thissphere = sphere.GetComponent <Renderer>();
                thissphere.material.color = Color.black;
                twoobject[1] = sphere;
                sphere.GetComponent <ObiCollider>().Phase = 1;
                // particleindexsphere[counttwo][4] = pickArgs.particleIndex;
                centerparciel[1] = pickArgs4.particleIndex;
                countparticle++;
                cnt4++;
            }
            flag = 1;
            pinrotate_ready();
        }
        else if (draw_line_instruction.flag == 2 && flag == 1)
        {
            rotatenow();
        }
    }