07-08-2020, 02:36 PM
(This post was last modified: 07-08-2020, 02:38 PM by josemendez.)
(07-08-2020, 01:32 PM)jackdos Wrote: Hi,
this is some setup of my Obi Cloth
https://drive.google.com/drive/folders/1...sp=sharing
Some codes:
Code:private IEnumerator StitchCloth()
{
if (sewingIndexA != null
&& sewingIndexB != null
&& sewingIndexA.Count > 0
&& sewingIndexB.Count > 0)
{
GameObject stitchObj = new GameObject("Stitch Object");
stitchObj.transform.SetParent(transform);
meshA.transform.SetParent(stitchObj.transform);
meshB.transform.SetParent(stitchObj.transform);
meshA.gameObject.AddComponent<ObiCloth>();
meshA.gameObject.AddComponent<ObiClothRenderer>();
meshB.gameObject.AddComponent<ObiCloth>();
meshB.gameObject.AddComponent<ObiClothRenderer>();
// generate blueprintA:
var blueprintA = ScriptableObject.CreateInstance<ObiClothBlueprint>();
blueprintA.inputMesh = meshA.mesh;
yield return StartCoroutine(blueprintA.Generate());
ObiCloth clothA = meshA.GetComponent<ObiCloth>();
clothA.clothBlueprint = blueprintA;
// generate blueprintB:
var blueprintB = ScriptableObject.CreateInstance<ObiClothBlueprint>();
blueprintB.inputMesh = meshB.mesh;
yield return StartCoroutine(blueprintB.Generate());
ObiCloth clothB = meshB.GetComponent<ObiCloth>();
clothB.clothBlueprint = blueprintB;
// sew both sides together:
ObiStitcher stitcher = stitchObj.AddComponent<ObiStitcher>();
stitcher.Actor1 = clothA;
stitcher.Actor2 = clothB;
for (int i = 0; i < sewingIndexA.Count; i++)
{
stitcher.AddStitch(sewingIndexA[i], sewingIndexB[i]);
}
// adjust bending constraints to obtain a little less rigid fabric:
InitClothParameters(clothA);
InitClothParameters(clothB);
// push stitcher index to the solver
stitcher.PushDataToSolver();
}
}
private void InitClothParameters(ObiCloth cloth)
{
ObiParticleRenderer particleRD = cloth.gameObject.AddComponent<ObiParticleRenderer>();
particleRD.shader = Shader.Find("Obi/Particles");
cloth.selfCollisions = true;
cloth.maxBending = 0.04f;
cloth.volumeConstraintsEnabled = false;
cloth.aerodynamicsEnabled = false;
cloth.tetherConstraintsEnabled = false;
cloth.maxCompression = 0.2f;
for (int i = 0; i < cloth.blueprint.principalRadii.Length; i++)
{
cloth.blueprint.principalRadii[i] = Vector3.one * 0.3f;
}
}
I don't think there's a problem with that.
Hi there,
There seems to be nothing wring with your setup, or with the code you shared. Except that changing the blueprint once you've instantiated the cloth objects will have no effect at all (like you do here):
Code:
for (int i = 0; i < cloth.blueprint.principalRadii.Length; i++)
{
cloth.blueprint.principalRadii[i] = Vector3.one * 0.3f;
}
Can you share the full source code of your CursorStitch component?
Also, are there any errors popping up in the console?