Search Unity

Physics Obi Particle Based Physics (Cloth, Rope, Fluid) thread

Discussion in 'Tools In Progress' started by arkano22, Jun 30, 2015.

?

Performance vs compatibility

Poll closed Oct 9, 2015.
  1. I don't care about performance, keep my data intact please.

    0 vote(s)
    0.0%
  2. I don't care if I have to re-do some stuff, as long as it runs faster.

    14 vote(s)
    100.0%
  1. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    860
    Hi there,

    Please write to our support email (support(at)virtualmethodstudio.com) or forums. Thanks!
     
  2. passeridaepc

    passeridaepc

    Joined:
    Jun 16, 2019
    Posts:
    266
    Hi!
    I'm using the 6.2 version and testing out surface collisions. First of all, do I understand it right, that even with surface collisions enabled, I still have to add a native unity collider component + obi collider component to the object that I want my cloth to collide with?

    And more importantly, why, if I move the cloth and bash it against an object, it collides well even at high speed, but when I do the opposite (move the object against the cloth) it goes through the cloth even at very low movement speed and causes big stutters and fps drops?
     
  3. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    860
    Yes, surface collisions simply extend the collidable surface of cloth/ropes from individual particles to the whole surface. You still need colliders for it to collide against. See:
    http://obi.virtualmethodstudio.com/manual/6.2/surfacecollisions.html

    It shouldn't. There's no difference whatsoever in moving the cloth against a collider or a collider against the cloth. Please write to our support email/forums and provide some more info (a video of the issue, details about your setup) so that I can offer proper help.
     
  4. passeridaepc

    passeridaepc

    Joined:
    Jun 16, 2019
    Posts:
    266
    Thanks!
    I've sent video to support@virtualmethodstudio.com

    Btw, the same behaviour can be observed in your example scene "ClothStaticMeshCollider". If you drag a cloth around the scene it will collide with the body mesh, but if you will move the body mesh it will almost always go through the clothes.
     
    Last edited: Aug 4, 2021
  5. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    860
    Oh ok, I see what you mean. This is just plain old tunneling:

    The mesh in that particular sample scene is a MeshCollider, and MeshColliders are hollow by definition (since they are just a collection of individual triangles, they do not define a “volume”). This means that once a object gets "inside" the mesh, it cannot be projected outside since the engine does not know what's inside or outside of a MeshCollider. It just knows about its surface. Since triangles are infinitely thin and particles very small and fast, this problem is exacerbated.

    Not only that, but you’re probably moving the mesh around by setting its transform position directly (using Unity’s gizmos). This basically teleports the mesh around from frame to frame, ignoring CCD checks. Since the engine cannot predict where you're going to move the transform next, it cannot perform accurate collision detection along the way.

    The reason why moving the cloth against the collider works, is because particles in the cloth move as a result of a physics simulation (unlike setting the transform of a collider), they have a velocity, and CCD (continuous collision detection) is used.

    Note both issues apply to Obi as well as regular Unity physics. At its core, it applies to literally all existing physics engines. Solutions:

    - Use primitive colliders (boxes, spheres, capsules, etc) or at the very least, colliders that define a volume. For Unity rigidbodies this means using convex mesh colliders, and for Obi it means using distance fields (http://obi.virtualmethodstudio.com/manual/6.2/distancefields.html) which are both faster and cheaper than MeshColliders. MeshColliders are the most expensive type of collider by a large margin and should be avoided if at all possible.

    - Move objects around using forces or rigidbody.MovePosition. This imparts a velocity vector to objects, which allows CCD to do its work.

    Again, the common name for this issue you're experiencing is tunneling. Here’s a video I did on this subject:
     
    Last edited: Aug 4, 2021
  6. passeridaepc

    passeridaepc

    Joined:
    Jun 16, 2019
    Posts:
    266
    Thanks! I was indeed moving my meshes using the editor gizmo. Although, I can't find the Obi Kinematics Velocities component you've mentioned in the end of the video.
     
  7. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    860
    Since 6.0 this component is integrated with ObiRigidbody, if you move a kinematic rigidbody a velocity value will be calculated. Note this is just a workaround, ideally you should use forces to move stuff (rigidbodies, actors) around if you intend collisions and other constraints to work properly.
     
  8. passeridaepc

    passeridaepc

    Joined:
    Jun 16, 2019
    Posts:
    266
    Thanks! This helped.

    A couple more questions:
    If I create a curtain and use particle attachment to "close" it, I get this shape:
    upload_2021-8-6_0-24-45.png

    However, if I set Max Compression to ~ 0.5 in the distance constraints, I get the nicely folded curtain (the right one in the screenshot below). Though, I can use it only when it's closed because the open curtain (the left one in the screenshot below) with the same compression looks ugly. Is there any other way to achieve such folds without using the max compression setting? Or can I change its value in runtime via script when the curtain is being closed/opened?

    upload_2021-8-6_0-27-52.png

    And also, I've noticed strange update behaviour. When I move the clothes, its vertices move a bit...sporadically. And they freeze a bit abruptly. Semetimes it may look like unity itself froze, but it's just the simulation decided that it's time to finish. And it always feels like some vertcies could use a few more simulation iterations, because they freeze in such positions that wouldn't be realistically possible because of the gravity and momentum. I can't say that they freeze in mid-air, no, the simulation do looks kinda-sorta finished at the right moment, but there's always the feeling that it needs a bit more movement to get in the right place. If you don't understand what I'm talking about I can try to capture it on a video. Here are gifs:


     
    Last edited: Aug 5, 2021
  9. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    860
    You might want to try and increase bend constraint's "max bending", or "bend compliance". These directly control how the cloth bends and folds. See:
    http://obi.virtualmethodstudio.com/manual/6.2/bendingconstraints.html

    Distance constraint's "max compression" allows particles in the cloth to get closer to each other. This does affect folds but only as a side effect.

    You can change *anything* via script. :). Do:

    Code (CSharp):
    1. cloth.maxCompression = 0.5f;
    See the API docs for details.


    Your solver's sleep threshold is simply too high. Set it to a lower value. See:
    http://obi.virtualmethodstudio.com/manual/6.2/obisolver.html

     
  10. passeridaepc

    passeridaepc

    Joined:
    Jun 16, 2019
    Posts:
    266
    Thanks! Unfortunately, any value of bend constraint's doesn't really affect the folding in comparison to a completely disabled bend constraint's. Moreover, bend constraint's + self-collision in such case cuts fps in half, when the curtain is folded. Bend constraint's + self-collision + surface collisions and I go from 150 fps to 20 fps.
    I noticed that using surface collision + self collision generally results in "the more folds you create the less fps you get". Is there a way to use surface collision for other objects and disable it for self collision?

    Also, is it possible to adjust cloth to a certain position via simulation and somehow store the result (not modifying the initial mesh), so during the next runtime the simulation starts from this state?
    For example I want to pin the curtain in the middle like this
    so when the player first encounters it, it will be in this state. But then it can be unfolded to its initial state (just hanging plain peace of fabric).
     
    Last edited: Aug 14, 2021
unityunity