elkyu Posted June 22, 2015 Share Posted June 22, 2015 Hi,I have a mesh (plane) with a multitude of point inside which constitute a grid. When the mouse cursor goes hover a point, I want to pick up its coordinates in the plane. If it’s not possible to do that, maybe it is possible on a mouse click ? Or, this multitude of points consitute a grid with triangles constituted of 3 points (vertex). Is it possible at a mouse click or a mouse hover on a triangle to pick up the 3 points which constitute it ? I look at Ray tracing but i didn't find how to do that. Thank you Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 22, 2015 Share Posted June 22, 2015 Hi elkyu.Quite a lot of picking questions lately, I wonder what everyone's doing :-)Check out the picking demo, http://www.babylonjs-playground.com/?11The pick info returned contains everything you asked for - coordinates of the point, the face id of the picked triangle and texture coordinates, which, in case it stays a plane, can be used to give you the location in your grid (But this would be a hack, there are better ways to solve it)You can attach the pick to the mouse move event (check out the attachControl function in the scene class ), and then always get the current picked point. Quote Link to comment Share on other sites More sharing options...
elkyu Posted June 22, 2015 Author Share Posted June 22, 2015 Hi RaananW, Thank you for your help. I try to do like in the picking demo, but if I want the exact coordinate of a point I have to pick the right pixel it's not very convenient because after that I have to find the point in a array with all point coordinate of my plane ..And If I get the faceId of the picked triangle I don't now If(or how) I can get the 3 vector which constitute it Other problem,My plane with all its points , it's like a grid of triangle, I would like to get the 3 vector which constitute a triangle. In the Babylon documentation I have found "Ray" with a function "intersectsTriangle(vertex0, vertex1, vertex2) -> IntersectionInfo" , but I don't if I can use it .. Quote Link to comment Share on other sites More sharing options...
elkyu Posted June 22, 2015 Author Share Posted June 22, 2015 Oh , like I said I have an array with the coordinates of all points of my plane like that : {P0x, P0y, P0z, P1x ...} The triangle where the faceId = 1 is the first triangle of my array, but It's not the same for the entire array (each vertex are use for several triangle so ..) Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 22, 2015 Share Posted June 22, 2015 I believe you would then need to filter the results you are getting according to the points you predefined.Or better - run the pick function only when the mouse is on one of those points.Another solution would be to define actual Sphere-meshes in the positions and use them in the picking function. Would be the simplest, I believe. You will have to make them correspond to the right section on the plane. About the face ID and the triangle information:The Information returned contains the face id that the picked triangle is on. To get the coordinates of this face (that is constructed out of three positions in space) you can use the same implementation like the getNormal function in the PickingInfo class: https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Collisions/babylon.pickingInfo.ts#L21 : var indices = mesh.getIndices();var positions = mesh.getVerticesData(VertexBuffer.PositionKind);var position0 = BABYLON.Vector3.FromArray(positions , indices[faceId * 3] * 3);var position1 = BABYLON.Vector3.FromArray(positions , indices[faceId * 3 + 1] * 3);var position2 = BABYLON.Vector3.FromArray(positions , indices[faceId * 3 + 2] * 3); Quote Link to comment Share on other sites More sharing options...
elkyu Posted June 29, 2015 Author Share Posted June 29, 2015 it's working very well ! I can found the coordinate of a face with this implementation Thank you ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.