Get nearest verticle on MouseClick

Software: Away3D 4.x

Avatar
80prozent, Sr. Member
Posted: 23 October 2011 01:27 PM   Total Posts: 430

Hi

when clicking on a Mesh, i know i can get a Vector3d (in World Space), that tells me the position off the Mouse in my scene.

I would like to know which verticle of the mesh, is nearest to the mouse position. (getting the verticle clicked on)

how would i do that?

I know i could loop through all verticles oft the mesh and calculate the distance to the mouse-clicked Vector3d, but for big meshes, that would take some time….

so is there anything set up in away3d 4 that would make this possible / faster ?
i guess one would have to build some kind of LOD-Logic….


thanks for any infos about this.

80

 Signature 

sorry…i hope my actionscript is better than my english…

   

John Brookes, Moderator
Posted: 23 October 2011 02:28 PM   Total Posts: 732   [ # 1 ]

Thats what hittestrenderer does. Loops through the vertices.

In HitTestRenderer I think after line 373, then I think your in the traingle
So line 374
trace(“Tri vertices\n” + x1, y1, z1 + “\n” + x2, y2, z2 + “\n” + x3, y3, z3);
would be that triangle.

The easy option would be if they (devs) added clicked face vertices to the mouseDetails

   

Avatar
80prozent, Sr. Member
Posted: 23 October 2011 02:38 PM   Total Posts: 430   [ # 2 ]

yeah

thank you so much for the reminder about HitTestRenderer.as

had completly forgotten it was there smile

will try how it works with larger meshes.

 

 Signature 

sorry…i hope my actionscript is better than my english…

   

Avatar
80prozent, Sr. Member
Posted: 23 October 2011 05:44 PM   Total Posts: 430   [ # 3 ]

after doing some basics test with the hittestRenderer, i noticed that it works very fast, and getting a triangle or a point in a mesh (i am using the head obj from the examples) works fine (i modified MouseEvent3d and HitTestRenderer to output face/verticles data).

one issue is left:

it is not allways given me back the correct object.
when clicking in the scene, most times it will give me the correct object, but sometimes it will give me back a object thats behind the object it should give me back.

is there anything i can do to make shure the z-sorting of the HitTestRenderer is done correctly ?

 Signature 

sorry…i hope my actionscript is better than my english…

   

John Brookes, Moderator
Posted: 23 October 2011 07:20 PM   Total Posts: 732   [ # 4 ]

I did the exact same earlier, added a getter for each vertice in hitetst and mouse manager.

Then checked for the closest one in the mouse event

When you get the vertice position, are you actually also adding the position of the object to the vertices position.

Made that mistake earlier.
I had a sphere at 0,0,0 and one at 500,0,0
S0 would seem as though it was picking the wrong mesh vertce. ( the origin one)
added position and all seems to work.

http://www.shrewballooba.co.uk/nearestVertice/

   

Avatar
80prozent, Sr. Member
Posted: 23 October 2011 09:05 PM   Total Posts: 430   [ # 5 ]

yes, i took care of the objects position (and rotation).

i use three spheres to display the current “selected” triangle, and another sphere to display the current local-Hittest-Position.

On Primitives like Spheres, Cubes and Planes this works fine. But on a Mesh like the Head.obj from the examples it works for only ca. 90% of the triangels.

the local-HitTest-Position on the Mesh seams always to be right, while it is not always inside of the triangel the HitTestRenderer says it should be in.

to me this seams to be a bug…

 Signature 

sorry…i hope my actionscript is better than my english…

   

John Brookes, Moderator
Posted: 23 October 2011 10:07 PM   Total Posts: 732   [ # 6 ]

Just tried the head.
On the tiny triangles in the nose and ear it sometimes loses position for me. But all others its fine.
I know when I played with the barycentric thing I noticed it didnt like it when the mouse was exactly on an edge.

Dont know smile

   

Avatar
80prozent, Sr. Member
Posted: 23 October 2011 10:47 PM   Total Posts: 430   [ # 7 ]

yes, thats the areas i have issues with too.

for me it also doesnt work for some triangles between the eyes and on the side of the neck…

some of the errors can not be seen the way you use to display the hitTest-results, since if the HitTestRender gives you back a triangle that is not actually the triangle the mouse hits, but one of its verticles is still the nearest Verticle to the local Vector3D the HitTestRenderer provides, it would still look correct in your demo.

could you please try to display the “selected” triangle, and see if it is always the correct one?

 Signature 

sorry…i hope my actionscript is better than my english…

   

John Brookes, Moderator
Posted: 24 October 2011 10:38 AM   Total Posts: 732   [ # 8 ]

Yeah sometimes it is picking the next triangle also the localXYZ can be off from the mouse position.

   

Avatar
80prozent, Sr. Member
Posted: 24 October 2011 02:24 PM   Total Posts: 430   [ # 9 ]

i reported this issue on git.

hope it will be improved soon.

 Signature 

sorry…i hope my actionscript is better than my english…

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X