Search Unity

RaycastCommand version of collider.Raycast

Discussion in 'Physics for ECS' started by Inter-Illusion, May 23, 2021.

  1. Inter-Illusion

    Inter-Illusion

    Joined:
    Jan 5, 2014
    Posts:
    598
    It will be really useful, if we could get a a multithreaded version of collider.Raycast.
    Similar to RaycastCommand but not raycasting the entire scene, just against an specified collider.
     
  2. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    The BuildPhysicsWorld system sets up the CollisionWorld. If you have a job running after or before it you should be able to fire of raycasts willy nilly. For example, the RayTracerSystem throws a ton of rays each frame. It calls CollisionWorld.CastRay but I don't know why it could not call Collider->CastRay on a specified collider instead of the world.

    Are you getting errors at the minute with your own implementation, or are you suggesting a package interface extension?
     
  3. Inter-Illusion

    Inter-Illusion

    Joined:
    Jan 5, 2014
    Posts:
    598
    Oh, I may have posted this in the wrong forum.
    I'm in the gray area where I'm using the job system, but not DOT systems and instead using the regular/old Physics.

    When not using DOT Physics, the option to multithread raycast is by using RaycastCommands.
    https://docs.unity3d.com/ScriptReference/RaycastCommand.html

    The problem I'm having is that RaycastCommand does the raycast against the entire world, but I want to raycast only against an specific collider.
    Thats why I was suggesting adding in a future a version of RaycastCommand where you could specify a collider.

    For context, what I'm trying to accomplish is to find an accurate distance between two non convex mesh colliders.
    So, I'm sending raycasts from the vertices of each of those meshes to the other one, to find out the closest intersection.

    That's the reason, why I don't need to raycast against the whole world.

    I could simplify that distance check if I turn the models into convex and do a penetration test, but for my specific app, I need a very accurate distance.
     
  4. Inter-Illusion

    Inter-Illusion

    Joined:
    Jan 5, 2014
    Posts:
    598
    I have to try this, but posting it in case someone have tried before and know if it will work:

    Given that for my project I just need to do raycasts, no other physics simulation (gravity, forces, etc).
    Would it be possible to set a DOTS Physics collider in a gameobject without converting the GameObject to an entity?

    That way I could replace my normal colliders by DOTS Physics colliders but without adding a ConvertToEntity component. And just manually do the raycasts in a job as that's allowed in DOTS Physics.

    Would that work? Or does the DOTS Physics colliders only get added to the Physics world once the ConvertToEntity is applied?
     
  5. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    You can create DOTS Physics colliders directly in code without having to touch Entities at all. You might like to check out the Query sample scenes and the associated script. Rather than casting a ray, there is a specific query in DOTS Physics for the shortest distance between two Colliders. See the CalculateDistance function in that sample scene or on the Collider Interface.
     
  6. Inter-Illusion

    Inter-Illusion

    Joined:
    Jan 5, 2014
    Posts:
    598
    Thanks for the suggestions!
    I played a bit with the sample project and it seems I can make it work in my project by creating the collider by code as you suggested.

    I got excited that maybe the ColliderCast would also allow me to send a NonConvex mesh into another NonConvex mesh. But that functionality is not implemented yet. Just Convex to Mesh.
    Well, at least I would be able to multithread the regular raycast. That will be a good boost!

    Thanks,
    Frank
     
  7. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    Implemented, just not released yet ;-)
     
  8. Inter-Illusion

    Inter-Illusion

    Joined:
    Jan 5, 2014
    Posts:
    598
    You just made my day!!
    My app really relies on accurate collisions/distance between non convex meshes and I have been struggling implementing hacks to make it happen.
    Any idea on how long before it gets released?

    Again, Thanks a lot!
     
  9. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    I don't have a time frame on the next release unfortunately. That's that my call.
    Out of interest, what is your usecase?
     
  10. Inter-Illusion

    Inter-Illusion

    Joined:
    Jan 5, 2014
    Posts:
    598
    Thanks for the update. I understand there is always lots of features/fixes to prioritize and most games work just fine by decomposing the meshes into convex colliders.

    In my case, I'm working in a dental software to assist planning teeth movements and placing dental implants.
    That's why accurate collision and distance between non-convex meshes is really important for me.
    I have been hacking it by doing raycasts from vertices, which works given that this models come from a dental scan, so, millions of polygons everywhere you look!
     
    steveeHavok likes this.