Skip to content

Conversation

@matthewturk
Copy link
Contributor

This adds on parameters to the Picker object so that the pick-threshold for points and lines can be adjusted, and so that it will return the instanceId of an instanced mesh as well as the index when picking on a Points object. This enables the Picker object to work with Points and PointClouds, where it returns the index into a BufferGeometry corresponding to the picked (sub)instance.

I believe this is relevant to #333, as it should enable indexing into a BufferGeometry and the corresponding attributes to retrieve the color (or other attributes of the source array).

Copy link
Member

@vidartf vidartf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a little annoying that the index field is not documented in the Threejs docs. Did you find a reference to it, or did you find out about index from examples or reading the source code?

@matthewturk
Copy link
Contributor Author

Sadly, I did find it in the source and not the docs.

@vidartf vidartf merged commit 2c3c66a into jupyter-widgets:master Aug 10, 2022
@vidartf
Copy link
Member

vidartf commented Aug 10, 2022

Thanks! :)

@anadodik
Copy link

Hi, thanks for this amazing library!

I've been trying to get a Picker to work with a Points object and haven't been able to get it to work. Would it be possible to give an example of how this is supposed to work?

@matthewturk
Copy link
Contributor Author

@anadodik Hi! Sorry for not replying sooner. Here's how I have used it in my library; here, pc.particle_view is of type pythreejs.objects.Points_autogen.Points (i.e., Points) and dsv.components[0].renderer is a standard Renderer object.

picker = pythreejs.Picker(controlling = pc.particle_view, all=True, event='mousemove', pointThreshold = 0.01) ren = dsv.components[0].renderer ren.controls = ren.controls + [picker] hover_point = pythreejs.Mesh(geometry=pythreejs.SphereGeometry(radius=0.05), material=pythreejs.MeshLambertMaterial(color='hotpink')) ren.scene.add(hover_point) ipywidgets.jslink((hover_point, 'position'), (picker, 'point'))

Now, whenever my mouse is within a threshold distance of a point, that point is highlighted with a pink, translucent sphere. You can also watch the index property of the picker, like:

picker.observe(update_label, "index")

For instance, my update_label function might look like:

def update_label(change): ind = change['new'] if ind is not None: labels[0].value = f"Picked index {ind} corresponds to {pos[ind,:]} with point set to {picker.point}"

I hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants