Search Unity

Dynamic RayCast System - C# Jobs upgrade is available !

Discussion in 'Assets and Asset Store' started by Vagabond_, Aug 27, 2014.

  1. MarkHenryC

    MarkHenryC

    Joined:
    Nov 30, 2009
    Posts:
    67
    OK, thanks for the response. One further question: does the hit return a reasonably accurate uv coord?
     
  2. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi yes it does, unless there is no any uncaught bug :)
    It should be matching the Unity's mesh raycast data !
     
  3. MarkHenryC

    MarkHenryC

    Joined:
    Nov 30, 2009
    Posts:
    67
    It appears not to work with skinned mesh renderers with cloth physics. Have you tested it with cloth? Is there some special setup I need to do?

    UPDATE: I think I've answered that; just drop in the AddDRCMComponentAtRuntime script instead.
     
    Last edited: Apr 2, 2019
    Vagabond_ likes this.
  4. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi everybody,

    i am on the way of releasing a Jobs based version of the system where i have a custom mesh bake function and RayCast and SphereCast job methods as well.

    The Job based mesh skinning algorithm is about 2 times faster then Unity's mesh bake function in my tests which is good i believe. So generally speaking the Job based system should be quite faster !

    So, as i am having now a custom mesh skinning method, there is no way to use it for in case the model uses blend shapes and in which case the only option left is to use the MeshBake() method from the SkinnedMeshComponent().

    However i am amazed for how long Unity has these issues with blendshapes which i think are getting even worse. So the skin mesh renderer bounds does not even respect blend shapes when there is only blend shapes exported from 3d package without any skinbones, nor i can detect it with a ray. There are still issues even when the mesh is skinned to bones but have blendshapes. Other thing is that blend shapes required a custom matrix ( i think one without including scaling ) in order to transform the rays correctly and the BakeMesh() also does not return correct snapshot of the mesh.

    So i am wondering if i should drop the blendshape support as there seems to be so much issues with it !

    Are there people using blendshapes and would like still to have support for them or you would accept the system without blendshapes support !?

    Thank you !
     
  5. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi to all,

    the upgrade to the C# Jobs version is now available.
    It is a paid upgrade, but this will help me maintain/update the asset !
    You can find it here DRCS C# Jobs link !

    The standard version of the system is also included inside as a separate package !


    Now a couple of notes about the C# Jobs version:

    Upgrade it's not supported in general, however i eventually did successfully upgraded a test project and it seems to work with previously setup prefabs and mesh data objects as all previous used serialized data seems to be still valid after the upgrade !

    Please for all of you that would like to upgrade, be sure to backup your projects, because i am not sure it this will work for any project. It seems that all the serialized data from the previous versions is still valid if you follow the steps.

    Also before continue you projects be sure to give a good testing on the system before continue working on other stuff !

    Steps to upgrade :
    1. Open you project and install all the required packages from the package manager ( jobs, burst etc... )
    2. Switch the "Scripting Runtime Version" to .NET 4.x Equivalent and set API compatibility level to .NET 4.x as well ( it should be working with .NET Standard 2.0 though )
    3. then i download the DRCS C# Jobs version pack and imported only the "DRCS" folder from the new pack with the "Resources" folder excluded, because it contains all the tags that you have already created ! Just refer to the attached image !

    * Be sure to keep all of your "MeshDataObjects" that you have already created !
    * The new version is using the DynamicRaycastJobs namespace, so if you have reference to the previous "DynamicRaycast" simply change it to the new namespace.

    This should be enough to upgrade the system itself. However if you have any reference to stuff from the previous version you will have to fix it yourself and you can contact me for assistance of course !

    If you have any more questions let me know !

    Best Regards to all !

    upload_2019-5-5_11-0-42.png
     
  6. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi to all,

    just a few notes for users using the C# Jobs version. You may experience some of the issues described below.
    These are already fixed and i should be able to upload the update today !

    * ( fixed ) there was a bug reported to me where only the first ray when casting multiple rays per frame was respected. This is now fixed and in a matter of fact allocating a native containers for the transformed vertices every time is removed which should give some small speed improvements on the methods and improves the managed memory allocation as well !

    * ( fixed ) another bug where native containers have not been allocated in builds for some objects was also fixed

    Cheers !
     
  7. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi guys,

    an update ( C# Jobs version ) with some fixes is available !

    Best Regards !
     
  8. JeffreyStrate

    JeffreyStrate

    Joined:
    Jul 27, 2016
    Posts:
    32
    Ich hab das Problem
    Microsoft (R) Visual C# Compiler version 2.9.1.65535 (9d34608e)
    Copyright (C) Microsoft Corporation. All rights reserved.

    error CS2015: 'D:\Recurce Timer\Library\PackageCache\com.unity.render-pipelines.core@5.7.2\Runtime\Volume\Volume.cs' is a binary file instead of a text file
    error CS2015: 'D:\Recurce Timer\Library\PackageCache\com.unity.render-pipelines.core@5.7.2\Runtime\Volume\VolumeProfile.cs' is a binary file instead of a text file


    Was soll das bedeuten... ???
     
  9. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi, this does not seem to be related to DRCS !
     
  10. JeffreyStrate

    JeffreyStrate

    Joined:
    Jul 27, 2016
    Posts:
    32
    Ja doch das habe ich grade Insterlliert und sofort tauchte es auf..meinen es ist eine art conflicht mit etwas anderem oky dann mus 50 PLugins etc prüfen


    Yes, but I have just Installed and immediately appeared on it..meinen it is a kind of conflicht with something else oky then mus 50 PLugins etc check

    Ich habe ein Leere Projeckt gemacht und es läuft 999 ERROR
    Assets\Dynamic RayCast System\DRCS\DRCM.cs(10,13): error CS0234: The type or namespace name 'Mathematics' does not exist in the namespace 'Unity' (are you missing an assembly reference?)

    was fehlt noch ?
     
    Last edited: May 28, 2019
  11. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Sorry i will have to write in English because i can't speak German ! Hopefully you can translate from English in translator !

    So, i haven't seen such error before but it looks it might be related to the type of the serialization files. Have you tried the system in a new project or you imported it in an existing one ?

    Did you change for some reason this option in "Editor" settings like in the image !? It should be text by default and it seems packages do not like binary files ( at least i guess so )...

    upload_2019-5-28_18-17-12.png
     
  12. JeffreyStrate

    JeffreyStrate

    Joined:
    Jul 27, 2016
    Posts:
    32

    Jetzt ist alles kapput..mus ich leider rückgabe machen 999+ fehler . Mysteriös
    Now everything is kapput..mus unfortunately return I make 999+ errors. Mysterious
     
  13. JeffreyStrate

    JeffreyStrate

    Joined:
    Jul 27, 2016
    Posts:
    32
     

    Attached Files:

  14. JeffreyStrate

    JeffreyStrate

    Joined:
    Jul 27, 2016
    Posts:
    32
    Ich habe jetzt diesen fehler noch, sobald ich die datein Lösche geht nichts mehr weil Dynamic RayCast System insterlliert ist, also helft mal den einen fehler zu fixen

    I have this error now, as soon as I delete the files is no longer because Dynamic RayCast system is insterlliert, so help fix one error

    dann sollte es laufen

    Assets\Standard Assets\Characters\FirstPersonCharacter\Scripts\FirstPersonController.cs(21,34): error CS0246: The type or namespace name 'MouseLook' could not be found (are you missing a using directive or an assembly reference?)
     

    Attached Files:

  15. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi, again sorry but it is hard to me to understand you correctly !
    I did try import the package in v2019.2.0b3 and it works !
    Be sure to follow up the requirements described in the asset description.

    I think you are may be having the standard FPS controller also imported in StandardAssets folder. Please delete the SimpleFPSController folder in DRCS because it is using the same MouseLook class !
     
  16. JeffreyStrate

    JeffreyStrate

    Joined:
    Jul 27, 2016
    Posts:
    32
    NOPE
    THEN
    Assembly has reference to non-existent assembly 'Unity.Collections' (Assets/Dynamic RayCast System/DRCS/Utilities/NativeArrayExtensions/NativeArrayExtensionsDef.asmdef)
     
  17. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Please read the asset description and the "read me" file included in the package. You have to install all required packages from package manager, to set .Net to v4 and be sure that the the reference to the "Collestion" assembly is not missing from the "NativeArrayExtensionsDef.asmdef" file...

    All this is explained in both asset page and in the ReadMe file !
     
  18. JeffreyStrate

    JeffreyStrate

    Joined:
    Jul 27, 2016
    Posts:
    32
    Hab ich doch...
     
    Last edited: Jun 3, 2019
  19. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi, is it now OK ?
     
  20. JeffreyStrate

    JeffreyStrate

    Joined:
    Jul 27, 2016
    Posts:
    32
    so it does not work ...
     

    Attached Files:

  21. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    I think you do not have "Show preview packages" option enabled. So do the steps below to show the Collections package...

    1. So open package manager and click "Advanced" tab like in the image...

    upload_2019-6-3_11-42-59.png

    2. And enable "Show preview packages" like in the image below

    upload_2019-6-3_11-44-39.png
     
  22. JeffreyStrate

    JeffreyStrate

    Joined:
    Jul 27, 2016
    Posts:
    32
    LOL--- S*** DANKE.-TANKYOU
     
    Vagabond_ likes this.
  23. Deleted User

    Deleted User

    Guest

    Hey, i having an issue with this system.

    I casting an RayCarstAll on my Animal to climb on it, well the problem is that i want transform the player at the first Hit of this RayCarstAll, so i created the raycarst then get the first hit then storing the triangle index and the barycentric Coordinate into a class.

    Code (csharp):
    1.  
    2. Ray hipsRay = new Ray( CharacterHipsMuscle.colliders[ 0 ].bounds.center + playerConnection.m_Player.transform.TransformDirection(Vector3.forward * -0.5f), playerConnection.m_Player.transform.forward );
    3.                 DynamicRaycast.DRCHitInfo[] hitInfos1 = new DynamicRaycast.DRCHitInfo[ 0 ];
    4.                 if ( DynamicRaycast.DRCS.RayCastAll( new DynamicRaycast.DRCRay( hipsRay ), 1.6f, ref hitInfos1, true, new string[] { "Animals" } ) )
    5.                 {
    6.                     var hits = hitInfos1.ToList().FindAll( x => FindBehaviourInParents<PlayerConnection>( x.hitObject ) == CurrentClimbAnimal.animal.playerConnection );
    7.                     if ( hits != null )
    8.                     {
    9.                         if ( hits.Count != 0 )
    10.                         {
    11.                             var firstHit = hits.OrderBy( x => x.hitDistance ).First();
    12.                             CurrentClimbAnimal.hipsBarycentricCoordinate = firstHit.barycentricCoordinate;
    13.                             CurrentClimbAnimal.hipsTriangleIndex = firstHit.triangleIndex;
    14.                            // ...
    15.                             CurrentClimbAnimal.haveHitHips = true;
    16.                         }
    17.                         else
    18.                         {
    19.                             CurrentClimbAnimal.haveHitHips = false;
    20.                         }
    21.                     }
    22.                     else
    23.                     {
    24.                         CurrentClimbAnimal.haveHitHips = false;
    25.                     }
    26.                 }
    27.                 else
    28.                 {
    29.                     CurrentClimbAnimal.haveHitHips = false;
    30.                 }
    31.  
    Then i create a similar code like in the StickyObject to transform this position of the character at the hit point.

    Code (csharp):
    1.  
    2. if ( CurrentClimbAnimal != null )
    3.             {
    4.                 if ( CurrentClimbAnimal.mesh != null )
    5.                 {
    6.                     var meshObject = CurrentClimbAnimal.mesh;
    7.                     var triangleIndexHips = CurrentClimbAnimal.hipsTriangleIndex;
    8.                     var barycentricCoordinateHips = CurrentClimbAnimal.hipsBarycentricCoordinate;
    9.                
    10.                     DRCFace meshFaceHips = null;
    11.                
    12.                     Debug.Log( triangleIndexHead + " " + triangleIndexHips + " " + triangleIndexSpine );
    13.                     var haveHitHips = false;
    14.                     if ( CurrentClimbAnimal.haveHitHips )
    15.                     {
    16.                         haveHitHips = meshObject.GetPointOnSkinnedMesh( triangleIndexHips, barycentricCoordinateHips, out meshFaceHips ) && CurrentClimbAnimal.haveHitHips;
    17.                     }
    18.                 }
    19.             }
    20.  
    The problem is sometimes is the Triangle Index -1 which gives me an error in meshObject.GetPointOnSkinnedMesh and for this reason the character does not follow the animal but it should not be -1 when he actually hit the animal with the ray or i am wrong there?

    And it's just sometimes -1

    Did i break the code because im carsting like 20 Raycarst All on the climb start at this animal?

    Already fixed it i looks like i have to just check first var hits = hitInfos1.ToList().FindAll( x => x.triangleIndex != -1 ); before i count it as a hit
     
    Last edited by a moderator: Jun 4, 2019
  24. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi, can i ask you to check something ?

    In general the only time the index is set to -1 is when a Unity collider is detected.
    Can you please do a debug and check if the object is not of a type "ObjectType.Collider" when the index is -1 and let me know.
    I am looking into this but if there is some bug i may need to reproduce the scenario, so i may need some further assistance from you ! But first if you can do the debug will be great !
     
  25. Deleted User

    Deleted User

    Guest

    Sure, i can test it tomorrow, i tell you the result.
     
  26. Deleted User

    Deleted User

    Guest

    I was able to reproduce the situation:
    The Ray is carsting through collider and mesh like you can see in this picture:
    2019-06-06 02_50_17.png

    The Box Colliders getting runtime generated

    There is the Debug:
    2019-06-06 02_58_53.png

    I just deleted the old debug picture because i was using the same Object Type for each ray which was not correct but now each ray have his own Object Type so the log should be correct, i just wonder why the ray is still carsting to colliders when i set ignoreColliders to true on the RayCarstAll, also i especially specify the Animals group on the RayCarstAll and still i getting some other objects in the hits, i mean it's okay for me i just make an check first but it's maybe confusing for new Unity users or people which are not trusted with your system
     
    Last edited by a moderator: Jun 6, 2019
  27. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    There might be a bug. It should ignore the colliders. I will have a good look into the case and will write back !

    EDIT : i forgot to ask, are you using the standard or the C# Jobs version ?
     
  28. Deleted User

    Deleted User

    Guest

    ow i use the Standard version, but probably switching soon to the Job version, thank you for telling me this.
     
  29. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    The C# version should be alright because i know i did some changes there, but i eventually fixed the bug for the ignore colliders in standard and should now check if groups are respected correctly, and will push an update as soon as i fix it !

    Btw if you switch to C# Jobs, be sure to backup project and check the docs which will lead you to this thread to an older post to see how you can try to upgrade project successfully ( as mentioned, project upgrade is not officially supported but it's possible ) !
     
  30. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi @flow- , i pushed an update and it was surprisingly fast accepted like in an hour.

    So you can test it if you decide. You also mentioned that the system detects also object that are not in the group list. I did test that a lot and all was correct. If you still experience any issue like this i will have to dig more into it !

    Thanks for the catching the bug !
     
  31. Deleted User

    Deleted User

    Guest

    Alright, looks perfect I just tested it and it works out of the box, thank you.
     
    Vagabond_ likes this.
  32. RichardRevesz

    RichardRevesz

    Joined:
    Jul 4, 2018
    Posts:
    12
    Hi,
    does this asset support HDRP?

    Best,
    Richard
     
  33. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi, i haven't tested but it only requires meshes and skinned mesh renderers so it should be ok !
    However i will simply test it in an HDRP project and will get back with an answer !

    Cheers !
     
    RichardRevesz likes this.
  34. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi, yes it's all good. Only demo assets are pink upon importing because are using the standard material by default, but the system itself is working !

    EDIT : tested in Unity 2019.2b10 and latest HDRP 6.9.0

    Cheers !
     
    RichardRevesz likes this.
  35. RichardRevesz

    RichardRevesz

    Joined:
    Jul 4, 2018
    Posts:
    12
    Great, thank you!
     
  36. Deleted User

    Deleted User

    Guest

    Hey,
    I have a question about the c# Jobs version:

    Is the default RayCast c# Jobs ready and multithreaded, ( When you search with colliders )?
    If so I am planning to convert some default RayCarst variables to DynamicRaycast variables but I need to know how I make an optimized Layer Detection because DynamicRaycast works with string groups but how do I filter the hits via Layer in an optimized way?

    I see there is a Layer Option in the Manager but some RayCasts require different Layers than others.

    Overall the C# Jobs version is amazing, I saved around 30 FPS with the Burst Compiler and the RayCarsts.
     
  37. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi, sorry for the late response !
    Layer detection is not implemented in DRCS. The method that takes tags does actually a similar thing and it was implemented after a user request. The layer in the DRCS manager is there for a purpose explained in the documentation. It is used with the Physics.Raycast() done internally for the purpose of being able to detect obstacles but ignore certain colliders attached to enemies for example. I am not sure if a layer filtering will be implemented. However i was thinking about this and i might add this as an optional parameter.

    There is one major problem in Unity that prevents DRCS and similar systems that need to do many ( and heavy ) calculations and this is the fact that the Unity API is not thread safe. Currently the fact that a mesh can not be Baked in a job prevents me from making the system take full advantage of the C# Job system. In other words i am forces to iterate objects one by one and bake meshes on the main thread and test for intersection on the main thread.

    There is still a way to create a jobs that will at least make the raycast park ( after baking ) run on multiple threads but the preparation of the data will have an overhead and potentially a lot of memory allocation which makes it pointless !

    Imagine the Bake method could have been called in a Job, that would be perfect - but no we can't do this.

    No matter what i attempt to do - it will have an overhead because objects will have to be iterated multiple times and additional operations will have to be done as well !

    I am as well amazed how fast the intersection is actually, even though it is done on a single thread !
     
    Last edited: Aug 30, 2019
  38. Deleted User

    Deleted User

    Guest

    Thank you for the response,

    This is great to hear, I really like to see this feature.
    We have a really large procedurally generated infinity terrain where we have to place animals on it, I am currently looking into NavMesh streaming where I hope to find a solution for our AI problem because we can't bake this large terrain so we have to figure out another way to make the Animals move on the map.... if this NavMesh Streaming does not work we have make our own AI Pathfinding with RayCasts where we need the performance.
     
  39. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi, i just uploaded a small update with LayerMasks implemented for the methods that are not using grouping tags. The Layer mask is optional parameter and the method can be called with the layer mask or without it. If they are called without the layermask, it means that all the object in the system list will be tested.

    There is something to keep in mind also. As the LayerMask is an optional parameter, its default value is 0 which means that it will skip all the layers and the system sets its value to -1 which will include all the layers. This is in case you call the methods without the layer mask parameter. However if you call the methods with a layer mask parameter set to "Nothing", the system will change the layer mask to Everything because of the reason mentioned above. The point is that you probably don't have a reason to call the methods with an empty mask so this should be ok !

    I would like to give me some feedback on the feature when it comes out probably in a couple of days ( if you would like to test it of course ) !

    Cheers !
     
    Deleted User likes this.
  40. Deleted User

    Deleted User

    Guest

    It's great, in future I just use your framework for the ray detection, havent test it now in terms of performance but I am sure it's worth it, we probably just use A* for our pathfinding, there are already great solutions so no need for us to make our own pathfinding which saves us a lot of time.

    All the best, flow!
     
  41. Deleted User

    Deleted User

    Guest

    Hey, I have a question:
    I want to use the DRCS.SphereCast but I don't know what do you mean by oldPosition and currentPosition, that's not really clear for me, for example, I have an origin and a direction, what would I assign to it?
     
  42. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Raycast has origin and direction.

    The spherecast needs a starting point and end point - if you want to use it as a projectile which flies through the scene, it needs the position from the last frame and the position in the current frame to be able to check if some object is between these two points, or just give it a starting point and end point and it will check if something is between these two points !

    P.S. for example create a start point and use the direction vector you have to get a point on this vector with a distance. The Vector3 class has a method for that, and use that point as an end point !
     
    Deleted User likes this.
  43. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi, i just wanted to note something about DRCS and Unity 2019.3

    If you add the package to this version of Unity, the 3D models in the demo scene seem to be broken for some reason ( intersection is not correct), however if you setup a new model the system works correctly. May be 19.3 just mess up the prefabs !

    Cheers !
     
    C_p_H likes this.
  44. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi,
    if you have interest in DRCS C# Jobs, it is set to 15$ for a while !
     
    C_p_H likes this.
  45. RAGE778

    RAGE778

    Joined:
    Aug 5, 2017
    Posts:
    1
    Hello some colleagues and I are working on a VR unity project and have run into an issue.What we have is a model that we are importing from blender and creating an environment where you can observe and manipulate the model.

    One of those features involves shooting a sphere with a raycast from our controller to place said sphere onto the model where we were pointing.The problem is that the model is much larger than we need it to be so we scale it down in the scene to what we need.

    However, when we do so It seems that the raycast is colliding with the original sized mesh and not the scaled down version.Is there a way to generate a mesh group on the scaled down mesh?

    Any advice you could give us would be greatly appreciated.
     
  46. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi, you should be having an email !

    Cheers !
     
  47. Elyaradine

    Elyaradine

    Joined:
    Aug 13, 2015
    Posts:
    27
    Hi there,

    I was wondering if you ever implemented raycasting blend shapes?
     
  48. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi, yes, bland shapes are supported !

    The mesh assets that are holding the mesh data automatically detect if blend shapes are present for that mesh and then the system uses Unity's baking method which bakes the mesh respecting the current state of the shapes !
    Otherwise the system is using a custom bake mesh using jobs. All this is automatic !
     
  49. Elyaradine

    Elyaradine

    Joined:
    Aug 13, 2015
    Posts:
    27
    Great, I'll be picking this up then! Thank you for the quick reply.
     
  50. pk1234dva

    pk1234dva

    Joined:
    May 27, 2019
    Posts:
    84
    Hi, I'm considering buying your asset, I was wondering - would you mind explaining/giving a little basic description of your approach to testing an intersection of a skinned mesh and a ray? Are you checking each triangle, or are you creating some type of structure (say oct tree) to cluster the triangles, and make the raycast checks more efficient? Such an approach is certainly more efficient for non-skinned meshes, but implementing it for a skinned mesh seems tricky.