raycast issue

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

raycast issue

Postby blackbird_dream » Tue Aug 28, 2018 4:28 am

Here is an issue raised with the raycast function.
I've observed some strange behavior using the raycaster and the treecollider.
It seems the raycast is not accurate. I'm using a mesh for the floor as you can try in the demo attached.
Using left and right arrows moves a cube at constant height from the floor over a locally flat and horizontal meshed surface.
As you can observe the distance cast is not constant:
https://www.youtube.com/watch?v=BJIeNBDO3Qk
It works if I remove all faces from the mesh except the local faces:
https://youtu.be/bljk665v4i4

the model here with the mesh:
https://ufile.io/ww0ux
Last edited by blackbird_dream on Wed Aug 29, 2018 5:14 am, edited 1 time in total.
User avatar
blackbird_dream
 
Posts: 279
Joined: Wed Jun 07, 2006 3:08 pm
Location: Italy

Re: raycast issue

Postby Julio Jerez » Tue Aug 28, 2018 11:57 am

a ray cast is influenced heavy by the face normal.
can you trace the normal reported by the day, I am guessing they change from face to face.
Julio Jerez
Moderator
Moderator
 
Posts: 11045
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: raycast issue

Postby blackbird_dream » Wed Aug 29, 2018 5:01 am

the normals seem oriented correctly:
https://youtu.be/NAAe3zd2K6o

the faces are slim triangles. The barycentres are then distant from one face to the adjacent one.
User avatar
blackbird_dream
 
Posts: 279
Joined: Wed Jun 07, 2006 3:08 pm
Location: Italy

Re: raycast issue

Postby blackbird_dream » Wed Aug 29, 2018 8:22 am

I tried to tesselate locally but nothing changed:
https://youtu.be/ckD35vq-_ts
Last edited by blackbird_dream on Thu Aug 30, 2018 2:34 am, edited 1 time in total.
User avatar
blackbird_dream
 
Posts: 279
Joined: Wed Jun 07, 2006 3:08 pm
Location: Italy

Re: raycast issue

Postby Julio Jerez » Wed Aug 29, 2018 11:04 am

the error seems too large to be a bug, it looks as if is using a single precision function.
I had accuracy problems in the pass with ray casting of convex polygon using single precision but the function was converted to double precision, in fact all collision routine since newton 3.13 where converted to double where is count.

This is the function that calculate the ray intersection.
Code: Select all
dgFloat32 dgFastRayTest::PolygonIntersect (const dgVector& normal, dgFloat32 maxT, const dgFloat32* const polygon, dgInt32 strideInBytes, const dgInt32* const indexArray, dgInt32 indexCount) const


It still has the single presition in it, see if your version is doing the single.

else. Iwill see why is that, if the mesh is toally flat, the hit distance should be constant.
an error of 0.01 is too great even for single precision.
I am busy at work this week, it will have to be the weekend.

There are other rountine that are more acurate in single precision that the one I use, but they are all for triangles, the newton one work on general polygons so for optimized threes the newtion one is faster and by using double it can make up for the inaccuracy of calcualtion volumes with floats.

basically the newton function calcuales the three varicentric volumes and is they all are positive, it means the point intesect the triangle.
It is the volume calculation that the error is because is a cubic quiantity.

the more acurate routines use a projection over the plane and calcutale three varicentric areas, since area are quadratic values they lose fewer significant bits than calculating volumes.

anyway I will debug it, my guess is that there must be an error on the data. some of the point on the input mesh must not be lining on the plane.
Julio Jerez
Moderator
Moderator
 
Posts: 11045
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: raycast issue

Postby Julio Jerez » Wed Aug 29, 2018 12:07 pm

I look at the function and I believe I can make an improvement.
are you on the latest version?
Julio Jerez
Moderator
Moderator
 
Posts: 11045
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: raycast issue

Postby blackbird_dream » Thu Aug 30, 2018 2:23 am

thks for your reply.
I'm currently using newton-dynamics-c570f450f56d7cfb4febaca9e971877fd5cc045f
The mesh seems locally exactly flat as the raycast is correct when the whole mesh is replaced by it
see https://youtu.be/bljk665v4i4
Last edited by blackbird_dream on Thu Aug 30, 2018 3:57 am, edited 1 time in total.
User avatar
blackbird_dream
 
Posts: 279
Joined: Wed Jun 07, 2006 3:08 pm
Location: Italy

Re: raycast issue

Postby Sweenie » Thu Aug 30, 2018 3:41 am

Just tried with Unitys own raycast function on the same mesh and the hit distance is always between 1.988187 and 1.988182 which I believe is only expected float precision errors. So it doesn't seem like the mesh is causing this.
Sweenie
 
Posts: 490
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: raycast issue

Postby blackbird_dream » Thu Aug 30, 2018 3:44 am

excellent. I forgot to test it !
User avatar
blackbird_dream
 
Posts: 279
Joined: Wed Jun 07, 2006 3:08 pm
Location: Italy

Re: raycast issue

Postby Julio Jerez » Thu Aug 30, 2018 10:08 am

ok without testing the bug, I re wrote the polygon ray function to use area instead of volume.
can you please try again Sweenie or Blackbird?
Julio Jerez
Moderator
Moderator
 
Posts: 11045
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: raycast issue

Postby blackbird_dream » Thu Aug 30, 2018 10:56 am

thks
I get this msg when compiling the plugin NewtonUnityPlugin-024577e2c636f7ee1c00f06f248b5d02df778237:
Code: Select all
Gravité   Code   Description   Projet   Fichier   Ligne   État de la suppression
Erreur   C2664   'void NewtonMaterialSetCompoundCollisionCallback(const NewtonWorld *const ,int,int,NewtonOnCompoundSubCollisionAABBOverlap)' : impossible de convertir l'argument 4 de 'int (__cdecl *)(const NewtonMaterial *const ,const NewtonBody *const ,const void *const ,const NewtonBody *const ,const void *const ,int)' en 'NewtonOnCompoundSubCollisionAABBOverlap'   NewtonWrapper   C:\Users\toto\VSProjects\NewtonUnityPlugin\NewtonWrapper\wrapperSdk\dNewtonWorld.cpp   64   

I don't know if I did something wrong
User avatar
blackbird_dream
 
Posts: 279
Joined: Wed Jun 07, 2006 3:08 pm
Location: Italy

Re: raycast issue

Postby Julio Jerez » Sat Sep 01, 2018 9:48 pm

Ok I am testing this now, I download the archive and opened, I see a unity project how do I run it?
I do not remember testing thing like this.
can anyone tell me what to do?

In any case I fixed the function prototype mismatch, the project build now.

if you get it, it you soudl be able to test the modified ray cast function.
it does not use a volumetric test now, instead use a unit area test.

please see if it work, if not, them please tell me how to hook your test so that I can debug it.
Julio Jerez
Moderator
Moderator
 
Posts: 11045
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: raycast issue

Postby blackbird_dream » Mon Sep 03, 2018 5:43 am

I've tested it.
The hit is still wrong
in Unity you must select 'New project' then select 'Crashtest' in Folder and click on 'Select a Folder'
User avatar
blackbird_dream
 
Posts: 279
Joined: Wed Jun 07, 2006 3:08 pm
Location: Italy

Re: raycast issue

Postby Julio Jerez » Mon Sep 03, 2018 6:35 am

ok I opened the project, but I get thsi errors when try to run it
Is there something else I need to do to run it?
Untitled.png
Untitled.png (103.17 KiB) Viewed 2079 times
Julio Jerez
Moderator
Moderator
 
Posts: 11045
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: raycast issue

Postby blackbird_dream » Mon Sep 03, 2018 7:45 am

have you pasted (from the pluginbin folder of the unity plugin) the dlls NewtonPlugin.dll, NewtonWrapper.dll in the plugin folder and the NewtonPluginEditor.dll file in the editor folder of the project named crash test ?

Using NewtonUnityPlugin

After building the projects there will be three dlls in the PluginBin folder.

NewtonPlugin.dll This managed dll(assembly) contains the runtime components(world, colliders, bodies and joints). In your unity project Assets folder, create a subfolder named Plugins and put it there.

NewtonPluginEditor.dll This is another managed dll that contain editors for the above components. This plugin goes into a subfolder called Editor under the Assets folder.

NewtonWrapper.dll This native dll contains the SWIG-generated C-functions that the managed dlls above use to access the Newton API. This plugin goes into the same folder as NewtonPlugin.dll

The plugins are compiled as 64-bit libraries by default so remember to compile Newton as 64-bit as well.

When Unity detects the plugins you will need to tell Unity if it's 64-bit or not. Just click on the plugin in the Assets view and check the 64-bit option.
User avatar
blackbird_dream
 
Posts: 279
Joined: Wed Jun 07, 2006 3:08 pm
Location: Italy

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests