Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Any tutorial for stitcher?
#1
Hi.
I have been struggling to figure out how to use stitch constraints properly to connect multiple softbodies.
Is there any video or tutorial of stitch constraints?

[EDIT]
Here are some more info regarding the problem I am struggling with.
The obi stitcher has been set as you see in the image below. Each stitch has been set by AutoStitcher.cs which helps me to find indices of particle pairs and set all stitches in the Editor. (For better visualization of each stitch, I set each cube apart along X axis but they were located right next to each other when I set their stitches and hit play.)
[Image: gs9zU7V.png]
They looks ok to me but when I hit play, I get the result like the image below (Shown in wireframe mode). As you can see, the stitched particles are not lined up smoothly and they seem they are fighting (colliding) each other.

[Image: 1wETs54.png]Their softbody surface blueprint's Shape Smoothing and Anisotropy Neighborhood have been set to 0 so that I get all particles right on the mesh vertices.
[Image: USV1hlX.png]What else I should look into to make connect them seamlessly?

By the way, this is the code I use to set stitches. It figure out all pairs and export them to a xml file in the play mode, then use the xml file to set stitches in the Editor. I know the workflow is a bit too cumbersome but I could not figure out how to get particle positions without running it. Is there any better way?
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;
using UnityEditor;

public class AutoStitcher : MonoBehaviour
{
    [System.Serializable]
    public struct STITCH_PAIR
    {
        public int index1;
        public int index2;
    }

    public List<STITCH_PAIR> stitchPairList = new List<STITCH_PAIR>();

    [SerializeField]
    ObiActor actor1;
    [SerializeField]
    ObiActor actor2;

    [SerializeField]
    float stitchMergin = 0.001f;

    private Mesh mesh1;
    private Mesh mesh2;

    // Start is called before the first frame update
    void Start()
    {
        FindPairs();
    }

    public void FindPairs()
    {
        stitchPairList.Clear();

        for (int i = 0; i < actor1.particleCount; i++)
        {
         
            int index1 = actor1.GetParticleRuntimeIndex(i);
            Vector3 pos1 = actor1.GetParticlePosition(index1);

            for ( int l = 0; l < actor2.particleCount; l++)
            {
                int index2 = actor2.GetParticleRuntimeIndex(l);
                Vector3 pos2 = actor2.GetParticlePosition(index2);
                float distance = Vector3.Distance(pos1, pos2);
                if (distance < stitchMergin)
                {
                    //obiStitcher.AddStitch(i, l);

                    STITCH_PAIR newPair;
                    newPair.index1 = i;
                    newPair.index2 = l;
                    stitchPairList.Add(newPair);

                    Debug.Log($"Index1: {i}, Index2: {l} Distance: {distance}");
                }
            }
        }
    }

    public void SaveStitchData()
    {
        string name = actor1.name + "_" + actor2.name;
        XmlUtil.Seialize<List<AutoStitcher.STITCH_PAIR>>("./Assets/" + name + ".xml", stitchPairList);
    }

    public void StitchActors()
    {
        string name = actor1.name + "_" + actor2.name;
        stitchPairList.Clear();
        stitchPairList = XmlUtil.Deserialize<List<AutoStitcher.STITCH_PAIR>>("./Assets/" + name + ".xml");
        ObiStitcher obiStitcher = gameObject.AddComponent<ObiStitcher>();
        obiStitcher.Actor1 = actor1;
        obiStitcher.Actor2 = actor2;

        foreach(STITCH_PAIR pair in stitchPairList)
        {
            obiStitcher.AddStitch(pair.index1, pair.index2);
        }
    }
}

[CustomEditor(typeof(AutoStitcher))]
public class AutoStitcherEditor : Editor
{
    AutoStitcher obj;

    public void OnEnable()
    {
        obj = (AutoStitcher)target;
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        if (GUILayout.Button("Save Stitches(Only in Play Mode"))
        {
            if (!Application.isPlaying)
            {
                Debug.LogError("Only works when editor is playing.");
                return;
            }

            bool go = EditorUtility.DisplayDialog(
                "Save Stitches to xml file.",
                    "This will save particle pairs data to .xml file. " +
                    "Do you wish to continue?",
                    "Go Ahead",
                    "Cancel"
                );

            if (!go)
            {
                return;
            }

            obj.SaveStitchData();
        }

        if (GUILayout.Button("Bake Stitches(Only in Editor Mode"))
        {
            if (Application.isPlaying)
            {
                Debug.LogError("Only works when editor is not playing.");
                return;
            }

            bool go = EditorUtility.DisplayDialog(
                "Bake Stitches from xml file.",
                    "This will add obiStitch constraints to obi actors. " +
                    "Do you wish to continue?",
                    "Go Ahead",
                    "Cancel"
                );

            if (!go)
            {
                return;
            }

            obj.StitchActors();
        }
    }
}
Reply


Messages In This Thread
Any tutorial for stitcher? - by Snail921 - 16-10-2021, 11:23 AM
RE: Any tutorial for stitcher? - by josemendez - 18-10-2021, 07:39 AM
RE: Any tutorial for stitcher? - by Snail921 - 21-10-2021, 06:45 AM
RE: Any tutorial for stitcher? - by josemendez - 21-10-2021, 08:33 AM
RE: Any tutorial for stitcher? - by Snail921 - 21-10-2021, 05:16 PM
RE: Any tutorial for stitcher? - by josemendez - 22-10-2021, 07:44 AM
RE: Any tutorial for stitcher? - by Snail921 - 23-10-2021, 08:36 AM
RE: Any tutorial for stitcher? - by josemendez - 25-10-2021, 09:15 AM