Search Unity

Resolved Get Mesh from physicsShape

Discussion in 'Physics for ECS' started by CookieStealer2, Aug 5, 2021.

  1. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    Hi there,

    I'm looking into possible solutions for constructing a navmesh in DOTS. I think it will be possible if I can translate a RigidBody/PhysicsCollider with meshcollider to UnityEngine.Mesh. Is this possible? If so, how can it be done?

    Regards
     
  2. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    There is a CreateRenderMeshFromCollider function in SceneCreationSystem.cs which hijacks one of the DebugDraw functions. It's not fast but it might suit your needs.
     
  3. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    Thanks, that's good to know. What I ended up doing was to collect all vertices in the GetLeaves() method. Its inconvenient but works. Why don't you expose the internal mesh of mesh colliders?
     
  4. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    By navmesh you mean your own navmesh implementation or Unity's?

    In either case going through Unity.Physics is really doing this the hard way. You bake physics colliders from a source, just use that source. Or in the case of box/sphere/capsule just use the matching primitive mesh.
     
  5. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    I'm using unity's implementation. I've already got it sort of figured out for baking from colliders. The advantage compared to using the rendermesh, is that I can have complex render meshes but use simple colliders for navigation. Besides, my movement is based on physics so it makes sense to use the colliders for this.