elkyu Posted July 7, 2015 Share Posted July 7, 2015 Hi ! I have a plane with several faces. I want to do a random scene pick on my mesh. With the picking info I want to get the faceId (pickingInfo.faceId). I tried with scene.pick() with random x and y parameter but it's not working. It always returns me the same face of my plane. How to generate a random scene pick ? (without mouse click)I think it's very simple but .. my method does'nt work Thanks Quote Link to comment Share on other sites More sharing options...
iiceman Posted July 7, 2015 Share Posted July 7, 2015 Well... why? Why not use Math.random to get a random face id? Quote Link to comment Share on other sites More sharing options...
elkyu Posted July 7, 2015 Author Share Posted July 7, 2015 because I divide my plane in 4 part and I want to pick a face in a part. And the faceId are placed completely randomly in the plane.Oh, the x and y coordinate are the screen coordinate .. that's why I find always the same face .. (coordinate of my plane its between -1 and 1 ...)There is a way to do the pick with the plane coordinate ?I can get a random face id with Math.random, get the 3 vertices of this face and check if it is in the correct part of the plane and try again if not.But it's very .. painful I think there is a better way to do that Quote Link to comment Share on other sites More sharing options...
jahow Posted July 7, 2015 Share Posted July 7, 2015 If you want to pick a face, and not a point in a face, you can do as iiceman suggested:var indices = mesh.getIndices();var face_count = indices.length/3;var selected_face = Math.floor(Math.random() * face_count); Quote Link to comment Share on other sites More sharing options...
elkyu Posted July 7, 2015 Author Share Posted July 7, 2015 If you want to pick a face, and not a point in a face, you can do as iiceman suggested:var indices = mesh.getIndices();var face_count = indices.length/3;var selected_face = Math.floor(Math.random() * face_count);Read my last post (We posted at the same time, I think ) , So, I can't really do that Quote Link to comment Share on other sites More sharing options...
adam Posted July 7, 2015 Share Posted July 7, 2015 Do a playground. Someone might be able to easily see what you are doing wrong. Quote Link to comment Share on other sites More sharing options...
iiceman Posted July 7, 2015 Share Posted July 7, 2015 Well, I am still not convinced that this approach is the best way, but here is how you do basic ray picking (from a position in a certain direction): http://www.babylonjs-playground.com/#1WI0CZ 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.