Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Stitch Rope and Cloth
#3
Hi,

Thanks for the reply.

Yeah I am trying to join them at runtime. But I'm facing the same issue where they don't stitch. Here is the code:

Code:
public ObiRope GenerateRope(Vector3 pointA, ObiCollider start, GameObject cloth)
{
        // Create a rope
        var ropeObject = new GameObject("rope", typeof(ObiRope), typeof(ObiRopeLineRenderer));
        rope = ropeObject.GetComponent<ObiRope>();
        var ropeRenderer = ropeObject.GetComponent<ObiRopeLineRenderer>();
        rope.GetComponent<MeshRenderer>().material = material;
        rope.GetComponent<ObiPathSmoother>().decimation = 0.1f;
        ropeRenderer.uvScale = new Vector2(1, 5);

        obiRopeExtrudedRenderer = ropeObject.AddComponent<ObiRopeExtrudedRenderer>();
        obiRopeExtrudedRenderer.section = section;
        obiRopeExtrudedRenderer.thicknessScale = ropeThicknessMax;

        // Setup a blueprint for the rope:
        var blueprint = ScriptableObject.CreateInstance<ObiRopeBlueprint>();
        blueprint.resolution = blueprintResolution;
        blueprint.thickness = blueprintThickness;
        blueprint.pooledParticles = blueprintPooledParticles;

        // convert both points to the rope's local space:
        pointA = rope.transform.InverseTransformPoint(pointA);
        Vector3 pointB = cloth.GetComponent<ObiActor>().GetParticlePosition(1);
        pointB = rope.transform.InverseTransformPoint(pointB);

        // Procedurally generate the rope path (a simple straight line):
        Vector3 direction = (pointB - pointA) * 0.25f;
        blueprint.path.Clear();
        blueprint.path.AddControlPoint(pointA, -direction, direction, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "A");
        blueprint.path.AddControlPoint(pointB, -direction, direction, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "B");
        blueprint.path.FlushEvents();

        rope.ropeBlueprint = blueprint;

        rope.transform.parent = solver.transform;

        Material localMaterial = rope.GetComponent<MeshRenderer>().material;
        localMaterial.color = normalColor;

        ObiRopeCursor obiRopeCursor = ropeObject.AddComponent<ObiRopeCursor>();
        obiRopeCursor.cursorMu = 0;

        var myFilter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0);
        for (int i = 0; i < rope.solverIndices.Length; ++i)
            rope.solver.filters[rope.solverIndices[i]] = myFilter;

        PinRopeToWall(start, new Vector3(0, 0.5f, 0));
        StitchRopeTo(cloth);

        return rope;
}
   

private void PinRopeToWall(ObiCollider bodyA, Vector3 offsetA)
{
        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.activeConstraintCount = 1;
        pinConstraints.AddBatch(batch);
}

private void StitchRopeTo(GameObject cloth)
{
        ObiStitcher stitcher = gameObject.AddComponent<ObiStitcher>();
        stitcher.Actor1 = rope.GetComponent<ObiRope>();
        stitcher.Actor2 = cloth.GetComponent<ObiCloth>();
        stitcher.AddStitch(rope.solverIndices.Length - 1, 0);

        stitcher.PushDataToSolver();
}
Reply


Messages In This Thread
Stitch Rope and Cloth - by bubbbles - 21-01-2022, 06:15 AM
RE: Stitch Rope and Cloth - by josemendez - 21-01-2022, 08:41 AM
RE: Stitch Rope and Cloth - by bubbbles - 21-01-2022, 09:09 AM
RE: Stitch Rope and Cloth - by josemendez - 21-01-2022, 09:40 AM