widgetti / ipyvolume

3d plotting for Python in the Jupyter notebook based on IPython widgets using WebGL
MIT License
1.95k stars 236 forks source link

Additional interactive camera controls #28

Open OliverEvans96 opened 7 years ago

OliverEvans96 commented 7 years ago

Hello!

Thanks for the awesome package! The work you've done is incredible. I have two camera-related feature requests. Perhaps they're already implemented and I haven't found them yet.

The first is panning. For example, shift-LMB & drag to pan? This is a pretty standard feature in 3d viewers which would be very handy.

Second is "turntable rotation" where the z axis is constrained to be pointing up. More info: https://blender.stackexchange.com/questions/657/what-is-the-difference-between-the-trackball-and-turntable-style-view-modes

Turntable is well implemented in plotly: https://help.plot.ly/getting-to-know-the-plotly-modebar/#3d-charts

I'd be happy to help work on this if you point me in the right direction.

Thanks, Oliver

maartenbreddels commented 7 years ago

Hi Oliver,

thanks, great to hear you like it! The panning would be really nice, but I may have a better idea, that involves 'picking' objects to work first. When you zoom, I think it should zoom in on the object the mouse cursor is on, which needs to same functionality as picking (finding the object the mouse is over). If this is implemented, I don't think panning is needed, but still it would be nice to have. Either way, I'm happy to guide you through this if you're willing to contribute, let me know which has your preference, and we can discuss it a bit more.

Regarding the camera modes, check this issue for solving it, it's still undocumented, would be nice to have a function in the pylab module for this, with an api similar to mayavi or matplotlib (if they have this).

cheers,

Maarten

OliverEvans96 commented 7 years ago

Maarten,

Yes, camera_control = 'orbit' is just what I was looking for. Although it maintains the y-axis as vertical as opposed to the z-axis.

I like the idea of zooming to the mouse, but I think it would actually be complemented quite well by panning. Imagine that you've zoomed in, but you're slightly off-centered. Then without panning, you have to zoom back out and try to zoom in with more accuracy.

Why do you suggest zooming to the object under the cursor instead of the cursor itself? I'm imagining that would be confusing to a user trying to zoom to a part of a large object which is not near it's center of mass.

Cheers, Oliver

maartenbreddels commented 7 years ago

True, I think they are complemantary, but I think there is less requirements for panning of zoom to the mouse position would work. What I mean with zoom on the object under the cursor is that the 3d position is taken from where a ray from the camera in the direction of the cursor would intersect the object, not near its center. It is basically to limit you zooming 'throught' the object, which is really annoying. I think it is quite similar to how sketchup behaves.

The camera controls are listed here:

They are currently used in figure.js. If you want to change the constraining behaviour, I think you should change what is the 'up' direction. There is support for panning, but it is using the keyboard I think.

Also, I'm thinking about what we should define as the z axis, now I'm using OpenGL's default, which is z negative points away from the camera, into the screen, but most people prefer pointing it up. Ideas on that are welcome.

OliverEvans96 commented 7 years ago

As a mathematician, my vote definitely goes to +z = up.

Changing ( 0, 1, 0 ) to ( 0, 0, 1) on line 120 of OrbitControls.js definitely changes the rotation constraints appropriately, but it also messes up the rotation control. Somehow, it seems like the cursor interaction is still assuming the other 'up' orientation. I'll have to search around this file to figure out what else would have to change to make up for this.

As for panning, it looks like everything is in place in OrbitControls.js which should allow for panning, yet it doensn't seem possible. Do you know what the keyboard bindings should be?

maartenbreddels commented 7 years ago

Yes, I think we should change it to z up.

Panning was disabled here: https://github.com/maartenbreddels/ipyvolume/blob/2ea543dd600eeaf899487d30633182b6ad04cf08/js/src/figure.js#L198 Since it always listens to key events (arrows I believe), even if you use the keys in a different cell.

maartenbreddels commented 6 years ago

Leaving this issue open for the panning as feature.

mgeier commented 5 years ago

Leaving this issue open for the panning as feature.

Here's a PR for this feature: #273.

@OliverEvans96 Would this work for you?