Posts: 8
Threads: 3
Joined: Apr 2022
Reputation:
0
Hi i've been trying to tear a cloth with a gameobject but i came across to a bug which makes the cloth look like this:
If i change the tear resistance the bug doesn't happen all the time and i can cut the flag succesfully most of the time. However this is not the definite solution.
Can you help me with that?
Here where i call the Tear() method:
void ModifyConstraints(int collisionParticleIndex)
{
var distanceConstraints =
flag.GetConstraintsByType(Oni.ConstraintType.Distance) as ObiConstraints<ObiDistanceConstraintsBatch>;
if (distanceConstraints == null) return;
IterateAllConstraints(distanceConstraints, collisionParticleIndex);
}
void IterateAllConstraints(ObiConstraints<ObiDistanceConstraintsBatch> distanceConstraints, int particleToTear)
{
IStructuralConstraintBatch currentBatch;
foreach (var batch in distanceConstraints.batches)
{
currentBatch = (IStructuralConstraintBatch) batch;
for (int i = 0; i < batch.activeConstraintCount; i++)
{
if (batch.particleIndices[i * 2] == particleToTear)
{
StructuralConstraint sc =
new StructuralConstraint(currentBatch, batch.GetConstraintIndex(i), tearForce);
flag.Tear(sc);
flag.solver.PushSolverParameters();
}
}
}
}
Posts: 6,346
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
27-04-2022, 07:42 AM
(This post was last modified: 27-04-2022, 07:47 AM by josemendez.)
Hi!
Your code has many bugs:
- You're iterating trough actor constraints (whose indices reference actor particles), but you're passing a "collisionParticleIndex" which quite probably is solver index, if you're retrieving it directly from the solver.OnCollision event.
- You're passing batch.GetConstraintIndex(i) to the StructuralConstraint constructor, but "i" is already a constraint index (remember that you're iterating trough all constraints from 0 to activeConstraintCount). GetConstraintIndex() takes a constraint id and returns the index of the constraint in the internal arrays. You already have the constraint index "i", so no need to call GetConstraintIndex().
- You're calling flag.solver.PushSolverParameters(); but haven't modified any solver parameter. This call does nothing - except negatively affect performance.
- You're missing a call to cloth.UpdateDeformableTriangles(); after all Tear() operations. The mesh topology isn't be updated at all right now, so any tears will turn the cloth into a triangle mess since particles/constraints are updated but the mesh is not.
I'd recommend taking a look at ObiTearableCloth.cs ApplyTearing() method as reference. You can basically copy/paste all of it and repurpose some bits.
Let me know if I can be of further help,
Posts: 8
Threads: 3
Joined: Apr 2022
Reputation:
0
(27-04-2022, 07:42 AM)josemendez Wrote: Hi!
Your code has many bugs:
- You're iterating trough actor constraints (whose indices reference actor particles), but you're passing a "collisionParticleIndex" which quite probably is solver index, if you're retrieving it directly from the solver.OnCollision event.
- You're passing batch.GetConstraintIndex(i) to the StructuralConstraint constructor, but "i" is already a constraint index (remember that you're iterating trough all constraints from 0 to activeConstraintCount). GetConstraintIndex() takes a constraint id and returns the index of the constraint in the internal arrays. You already have the constraint index "i", so no need to call GetConstraintIndex().
- You're calling flag.solver.PushSolverParameters(); but haven't modified any solver parameter. This call does nothing - except negatively affect performance.
- You're missing a call to cloth.UpdateDeformableTriangles(); after all Tear() operations. The mesh topology isn't be updated at all right now, so any tears will turn the cloth into a triangle mess since particles/constraints are updated but the mesh is not.
I'd recommend taking a look at ObiTearableCloth.cs ApplyTearing() method as reference. You can basically copy/paste all of it and repurpose some bits.
Let me know if I can be of further help, Thanks a lot for your help :)
I was actually converting solver index to particle index in a loop so i don't think the problem arised from that:
int solverIndex = flag.solver.simplices[contact.bodyA];
ObiSolver.ParticleInActor pa = flag.solver.particleToActor[solverIndex];
int collisionParticleIndex = pa.indexInActor;
But changing the "GetConstraintIndex(i)" to simpy "i" and calling "cloth.UpdateDeformableTriangles()" seems to fix my issue.
Posts: 6,346
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
(27-04-2022, 09:10 AM)charlotte Wrote: But changing the "GetConstraintIndex(i)" to simpy "i" and calling "cloth.UpdateDeformableTriangles()" seems to fix my issue.
Glad to help! let me know if you need anything.
kind regards,
Posts: 8
Threads: 3
Joined: Apr 2022
Reputation:
0
(27-04-2022, 09:12 AM)josemendez Wrote: Glad to help! let me know if you need anything.
kind regards, Well actually i have another problem which is not relevant to tear.
The wind(obi ambient force zone) is not working for most of the meshes that i used, even though i added the affected solvers to the wind.
It only worked with unity's standard plane mesh. Which settings should you recommend me to manipulate in order to make the wind work?
Posts: 6,346
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
27-04-2022, 03:46 PM
(This post was last modified: 27-04-2022, 03:48 PM by josemendez.)
(27-04-2022, 03:25 PM)charlotte Wrote: Well actually i have another problem which is not relevant to tear.
The wind(obi ambient force zone) is not working for most of the meshes that i used, even though i added the affected solvers to the wind.
It only worked with unity's standard plane mesh. Which settings should you recommend me to manipulate in order to make the wind work?
Hi!
Wind is a force, so a wind of the same intensity will have stronger/weaker effect on objects of lower/higher mass respectively. F=ma, so a = F/m, this means the velocity change in any object given a wind force is inversely proportional to its mass.
Make sure the mass of your particles is low enough for it to be affected by wind. You can view/change/paint mass on a per-particle basis in the cloth blueprint editor. By default, the mass of each particle is proportional to the surface area of all triangles incident to it. This explains why some meshes are affected by wind and others aren't: they just have different mass.
kind regards,
Posts: 8
Threads: 3
Joined: Apr 2022
Reputation:
0
27-04-2022, 03:49 PM
(This post was last modified: 27-04-2022, 03:51 PM by charlotte.)
(27-04-2022, 09:12 AM)josemendez Wrote: Glad to help! let me know if you need anything.
kind regards,
Well i have another problem related to wind.
Im actually creating the solver and cloth through scripting, not from editor. How can i add that new solver to affected solvers list of the wind?
To solve that, I tried to create the solver on the editor and then add the cloth via scripting, but this time the cloth didn't act the same way it was the first version even though the setting are the same.
Can you help me with that?
thanks for your response above by the way
Posts: 6,346
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
(27-04-2022, 03:49 PM)charlotte Wrote: Im actually creating the solver and cloth through scripting, not from editor. How can i add that new solver to affected solvers list of the wind?
You can do it like this:
Code: ambientForceZone.enabled = false;
ambientForceZone.affectedSolvers = new ObiSolver[]{yourSolvers};
ambientForceZone.enabled = true;
Note it is necessary to disable/then reenable the force zone because the list of solvers is only updated in OnEnable().
kind regards,
Posts: 8
Threads: 3
Joined: Apr 2022
Reputation:
0
(27-04-2022, 04:08 PM)josemendez Wrote: You can do it like this:
Code: ambientForceZone.enabled = false;
ambientForceZone.affectedSolvers = new ObiSolver[]{yourSolvers};
ambientForceZone.enabled = true;
Note it is necessary to disable/then reenable the force zone because the list of solvers is only updated in OnEnable().
kind regards,
Thanks for your help, that helped me a lot
|