Search Unity

Mesh.Bake Scaled Mesh PhysX CollisionData

Discussion in 'Editor & General Support' started by sstephane, May 31, 2011.

  1. sstephane

    sstephane

    Joined:
    Nov 5, 2009
    Posts:
    30
    Hi,

    I am working on project where i have to move (drag and drop) many items (3d meshes). It may move just one or hundreds at once. Each item is a GameObject with a collider and a kinematic rigidbody. The collider is a MeshCollider which is using in most of the cases the rendered mesh which could be quite complex and not suitable for PhysX calculations. I can't ask the artists for optimize each mesh collider for each item as we are working on a huge bank of 3d models and don't have time for that.

    Actually, i do not need Physics at all as i am only using raycasting. However to prevent unity to consider each item as a static collider, I must attach a kinematic rigidbody to each one which somehow, turn them as a physical objects.

    In this configuration, while moving many objects (hundreds) onto another scaled one, all these ones are set children of it (and must be) and consequently unity via PhysX recompute CollisionData and it takes a lot of time (dozens of seconds). I can see it on the profiler. (Mesh.Bake Scaled Mesh PhysX CollisionData)

    I also tried to turn the meshCollider to a trigger but it stills recompute collisionData. I think that unity should provide the ability to disable these physX calculations when needed or maybe am I missing something?

    I am quite running out of ideas, any help would be greatly appreciated.

    Thx.
     
    Last edited: May 31, 2011
  2. Chris-Mosely

    Chris-Mosely

    Joined:
    Oct 5, 2010
    Posts:
    7
    Same problem here.

    We have a large mesh wich we use as a collider. On starting up our game, it waits for around 300 seconds before the game starts. There's pre-processing on the mesh every single time the game runs, it's not caching the results even though the mesh isn't moved or altered in any way.

    One thing we did discover was that if you load the collision mesh as a prefab, the problem goes away, loads in seconds. Very strange, you should be able to bake in the collision optimisation calculations procedurally if you can load them in from a prefab i would have thought.

    There's definatley a bit of information missing here from Unity. Can't seem to find out how to bake in the collision mesh data so it doesn't process it every time the game runs.
     
  3. Jeremy-Hindle

    Jeremy-Hindle

    Joined:
    Oct 27, 2012
    Posts:
    8
    Slightly different problem here but the same issue is causing it.

    In our game players are able to scale objects however they like and unfortunately performance just goes through the floor as soon as anyone scales more that 2 or three simple shapes at the same time.

    Our current work around is that while an object is being scaled we remove the mesh collider component form the gameobject and the add it back after the scaling has been finished (of every second or so).

    The meshes are not complicated so the generation of the CollisionData isn't too much trouble like it is for those above.. Our issue is that it has to generate this data so often unless we delete the mesh collider and then add it back afterwards.

    (Notably it still does these calculations even if that component is disabled.)

    Is there a way to just disable the CollisionData baking on a particular game object instead?
     
  4. dasbin

    dasbin

    Joined:
    Jan 14, 2012
    Posts:
    261
    The problem is you are expecting to not use the physics engine but want to use Unity's collision system. They are one and the same.

    I would suggest that if you want to avoid importing colliders at all then you write your own simplified collision system.

    You probably could, honestly. In Blender there is a built-in function called Decimate that takes about two seconds per mesh to get the complexity level down to whatever you want.
     
  5. Jeremy-Hindle

    Jeremy-Hindle

    Joined:
    Oct 27, 2012
    Posts:
    8
    Makes sense. I might just have to suck it up and use the workaround for now. Thanks though.


    On that point I agree totally with @dasbin - On my last project every complex environment model which was made by the artists had a simplified mesh for the ColliderData to be calculated with.