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

WIP: point z-axis up, change some settings for OrbitControls #272

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ipyvolume/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ class Figure(ipywebrtc.MediaStream):
def _default_camera(self):
# see https://github.com/maartenbreddels/ipyvolume/pull/40 for an explanation
z = 2 * np.tan(45.0 / 2.0 * np.pi / 180) / np.tan(self.camera_fov / 2.0 * np.pi / 180)
return pythreejs.PerspectiveCamera(fov=self.camera_fov, position=(0, 0, z), width=400, height=500)
camera = pythreejs.PerspectiveCamera(fov=self.camera_fov, width=400, height=500)
#camera.position = 0, 0, z
camera.position = z, z, z
camera.up = 0, 0, 1
return camera

scene = traitlets.Instance(pythreejs.Scene, allow_none=True).tag(sync=True, **widgets.widget_serialization)

Expand Down
27 changes: 15 additions & 12 deletions js/src/figure.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,19 +395,16 @@ var FigureView = widgets.DOMWidgetView.extend({
if (this.model.get('camera')) {
this.camera = this.model.get('camera').obj
this.model.get('camera').on('change', () => {
// the threejs' lookAt ignore the quaternion, and uses the up vector
// we manually set it ourselve
var up = new THREE.Vector3(0, 1, 0);
up.applyQuaternion(this.camera.quaternion);
this.camera.up = up;
this.camera.lookAt(0, 0, 0);
// TODO: shouldn't we do the same with the orbit control?
this.control_trackball.position0 = this.camera.position.clone();
this.control_trackball.up0 = this.camera.up.clone();
// TODO: if we implement figure.look_at, we should update control's target as well
this.update();
});
} else {
// NB: Default camera is set in ipyvolume/widgets.py
/////////////////////////////
alert('this never happens?');
/////////////////////////////
this.camera = new THREE.PerspectiveCamera(46, 1, NEAR, FAR);
// same default as the Python version
var z = 2 * Math.tan(45. / 2. * Math.PI / 180.) / Math.tan(this.model.get('camera_fov') / 2. * Math.PI / 180.);
Expand Down Expand Up @@ -634,14 +631,21 @@ var FigureView = widgets.DOMWidgetView.extend({
this.control_orbit = new THREE.OrbitControls(this.camera, this.renderer.domElement);
this.control_trackball.dynamicDampingFactor = 1.
this.control_trackball.noPan = true;
this.control_orbit.enablePan = false;
this.control_orbit.dampingFactor = 1.

this.update_mouse_mode()

this.control_orbit.rotateSpeed = 0.5
this.control_trackball.rotateSpeed = 0.5
this.control_trackball.zoomSpeed = 3.

// All widgets on the page would receive those keypresses all the time:
this.control_orbit.enableKeys = false;
this.control_orbit.panSpeed = 1.0;
this.control_orbit.rotateSpeed = 0.5;
this.control_orbit.zoomSpeed = 2.0;
this.control_orbit.screenSpacePanning = true;

// TODO: minDistance, maxDistance, target

window.addEventListener('deviceorientation', _.bind(this.on_orientationchange, this), false);

var render_size = this.getRenderSize()
Expand Down Expand Up @@ -1464,7 +1468,6 @@ var FigureView = widgets.DOMWidgetView.extend({
this._update_requested = false
// since the threejs animation system can update the camera,
// make sure we keep looking at the center
this.camera.lookAt(0, 0, 0)

this.renderer.setClearColor(this.get_style_color('background-color'))
this.x_axis.visible = this.get_style('axes.x.visible axes.visible')
Expand Down Expand Up @@ -2032,4 +2035,4 @@ var WidgetManagerHackModel = widgets.WidgetModel.extend({
// WEBPACK FOOTER
// ./src/volume.js
// module id = 1
// module chunks = 0
// module chunks = 0