Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Collider creation speed.

Discussion in 'Scripting' started by stanislavdol, Jun 19, 2014.

  1. stanislavdol

    stanislavdol

    Joined:
    Aug 3, 2013
    Posts:
    282
    Good evening.
    Working on a planet terrain editor, I noticed a very interesting thing:
    It take much more time to generate a mesh collider for an ideal sphere, than for planet with a randomly genereated surface. And the curvier surface is,the faster collider is being created.This difference is easy to notice if the number of vetices is higher than 30k.

    Do you know whats the reason for this?

    Thanks.
    Best regards, Stanislav.
     
  2. Sharp-Development

    Sharp-Development

    Joined:
    Nov 14, 2013
    Posts:
    353
    As of normal TriMesh colliders, it shouldnt make a difference. However, when using convex mesh colliders, the physics engine uses an algorythm to build a convex hull. Building a convex hull in general is a topic of itself. However, the basic and used approch in physx does nothing more than finding extrem points and therefore approches closer to a convex hull each iteration. The more extrem points there are, the longer the algorythm will take since less points can be simply discarded due to not being inside the current hull. As of shapes approaching close to a sphere, the extrema's are close to infinity and basically close to all points will be part of the final convex hull.
     
  3. stanislavdol

    stanislavdol

    Joined:
    Aug 3, 2013
    Posts:
    282
    Thanks for the fast reply. However, convex is switched off and, i think, it's impossible to switch it on for such high poly models?
     
  4. Sharp-Development

    Sharp-Development

    Joined:
    Nov 14, 2013
    Posts:
    353
    I dont see a problem why it shouldnt be possible to turn it on. Tho, if convex is turned off, my explanation does still not explain the overhead.
     
  5. Sharp-Development

    Sharp-Development

    Joined:
    Nov 14, 2013
    Posts:
    353

    /E: Well, wrapped my head around this fast. There might be an considerable overhead when dealing with dense polygon TriMeshes since the Octree, which needs to be created, is way greater than for a meshes with distributed triangles.

    /E2: Woops, this was meant as an edit of aboves post. --