Jump to content

How to do a random "scene.pick" on a mesh


elkyu
 Share

Recommended Posts

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  :huh:

 

 

Thanks

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);
Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...