Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of Field-of-View Hook and switched to CombinedCamera #40

Merged
merged 7 commits into from
Aug 2, 2017

Conversation

chrisjsewell
Copy link
Contributor

Hows this for a first stab?

  • I've added a camera_fov trait and also some math so that, when changing fov, you maintain the same zoom level.
  • I've switched out the Perspective Camera for the Combined Camera, to check that it still works the same in perspective mode. But haven't yet added any traits/logic for switching to/from orthographic mode

Copy link
Collaborator

@maartenbreddels maartenbreddels left a comment

Choose a reason for hiding this comment

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

Excellent, and a good start for making the camera more flexible.

@@ -20,6 +20,7 @@ var ScatterView = widgets.WidgetView.extend( {

this.geo_diamond = new THREE.SphereGeometry(1, 2, 2)
this.geo_sphere = new THREE.SphereGeometry(1, 12, 12)
this.geo_sphere_hres = new THREE.SphereGeometry(1, 48, 48)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you remove this, to keep this PR cleaner?

@@ -53,6 +54,7 @@ var ScatterView = widgets.WidgetView.extend( {
box: this.geo_box,
arrow: this.geo_arrow,
sphere: this.geo_sphere,
sphere_hres:this.geo_sphere_hres,
Copy link
Collaborator

Choose a reason for hiding this comment

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

And this as well.

@@ -142,7 +150,8 @@ var FigureView = widgets.DOMWidgetView.extend( {
this.wire_box.add(make_line(-0.5, -0.5+1, -0.5, -0.5, -0.5+1, -0.5+1, this.axes_material))
this.wire_box.add(make_line(-0.5+1, -0.5+1, -0.5, -0.5+1, -0.5+1, -0.5+1, this.axes_material))

this.camera.position.z = 2
// set a good intial z for any fov angle
this.camera.position.z = 2 * this.getTanDeg(45/2) / this.getTanDeg(this.model.get("camera_fov")/2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the idea behind this? Can you link to sth or provide a hint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just some 'back of an envelope' trigonometry:

fullsizerender

Since the camera is intialized at (0,0,z) (i.e. a=z) and we know that theta=45 and z=2 provides a good initial view (as is currently hard coded), hence the new code.

Make sense?

Copy link
Collaborator

Choose a reason for hiding this comment

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

perfect, maybe put a link to this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

(Updated) Maybe add 45 as a constant INITIAL_VIEW_ANGLE (or more descriptive) to avoid magic numbers?

Copy link
Collaborator

Choose a reason for hiding this comment

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

well, it's not really a fov anymore... it sets the initial distance. I'll think about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey vidarf, I'll leave your suggestion to maarten. But, for future knowledge, what do you mean by magic numbers?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, by magic numbers I mean any number that appears in code without explanation (e.g. 3.14...). These should typically be replaced by constant vars, or at least commented.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah ok ta, just wanted to check it wasn't some obscure javascript issue lol

@maartenbreddels
Copy link
Collaborator

Btw, what about the camera license, I guess it's the same as three, since it is in the threejs repo: https://github.com/mrdoob/three.js/blob/master/examples/js/cameras/CombinedCamera.js

Also, we could make pythreejs a hard dependency, so we expose the cameras object as pythreejs objects instead. What do you think about that? That would mean that you always need to install pythreejs, which would be an extra possible point of failure, which I don't like.

@chrisjsewell
Copy link
Contributor Author

I copied it directly from there, so I assume its covered by the three.js license, since there is no sub licences in any of the directory path.

For the pythreejs integration, I think its a good long term goal. But, I guess, hold off on that until it is closer to a version 1.0

@maartenbreddels
Copy link
Collaborator

Yup, I agree. If you remove the high res spheres, happy to merge.

@maartenbreddels maartenbreddels merged commit 04a4199 into widgetti:master Aug 2, 2017
@chrisjsewell
Copy link
Contributor Author

cheers

@maartenbreddels
Copy link
Collaborator

Thanks for you first contribution! 👍
I'm not sure about the sphere_highres, another option would be to include support for pythreejs, but again, that would depend on pythreejs, and I see no other reason to include high res versions of other glyphs, so why not. Using normals would also make them look more smooth btw.

@chrisjsewell
Copy link
Contributor Author

Yeh no problem, sphere_hres was obviously just a quick fix and a more comprehensive solution would be best

mpu-creare pushed a commit to mpu-creare/ipyvolume that referenced this pull request Mar 26, 2018
…ti#40)

added hook for camera fov, changed camera from perspective to combined
not yet implemented switching of combined camera to orthographic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants