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

Orthographic projection for 3D plots - finalist #3550

Merged
merged 17 commits into from
Feb 20, 2019
Merged

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Feb 18, 2019

Supersedes #3331.
Fixes #2611 by adding orthographic views to Plotly graphs.
A new attribute ortho is defined on the camera object (defaulted to false) and passed to gl-plot3d and gl-axes3d modules.
The scene initialisation now uses the camera initial vectors as well as ortho attribute.
The createCamera function needed in plot/gl3d/scene.js and gl-vis/gl-plot3d is centralised in a separate module (i.e. a fork of 3d-view-controls while applying Plotly.js camera.js latest changes).
Interactive demo.

TODO:

  • Fix relayout path to start new scene when switching between orthographic and perspective projections.
  • Fix orthographic scales for zoom and save image.
    plotly_orthographic_projection

@plotly/plotly_js
@jackparmer

adjust ortho camera dist in module and added orthographic mocks
adjust camera structure in jasmine test & corrected baselines
package.json Outdated
@@ -81,7 +81,7 @@
"gl-mat4": "^1.2.0",
"gl-mesh3d": "^2.0.7",
"gl-plot2d": "^1.4.2",
"gl-plot3d": "^1.6.3",
"gl-plot3d": "git://github.com/gl-vis/gl-plot3d.git#33d5169a62d9b903a8f3a4607f4dae726c4bb57b",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also regarding gl-axes3d changes... https://github.com/gl-vis/gl-axes3d/compare/ortho-view1

package.json Outdated Show resolved Hide resolved
@etpinard
Copy link
Contributor

@archmoj this is starting to look good! Nice work!

About

  • Fix relayout path to start new scene when switching between orthographic and perspective projections.

First you'll need to change the scene.projection.type editType to 'calc' (we could eventually try 'plot' and even 'modebar', but we should start with 'calc'). Then maybe you could try adding some code to

proto.updateFx = function(dragmode, hovermode) {
var camera = this.camera;
if(camera) {
// rotate and orbital are synonymous
if(dragmode === 'orbit') {
camera.mode = 'orbit';
camera.keyBindingMode = 'rotate';
} else if(dragmode === 'turntable') {
camera.up = [0, 0, 1];
camera.mode = 'turntable';
camera.keyBindingMode = 'rotate';
// The setter for camera.mode animates the transition to z-up,
// but only if we *don't* explicitly set z-up earlier via the
// relayout. So push `up` back to layout & fullLayout manually now.
var gd = this.graphDiv;
var fullLayout = gd._fullLayout;
var fullCamera = this.fullSceneLayout.camera;
var x = fullCamera.up.x;
var y = fullCamera.up.y;
var z = fullCamera.up.z;
// only push `up` back to (full)layout if it's going to change
if(z / Math.sqrt(x * x + y * y + z * z) > 0.999) return;
var attr = this.id + '.camera.up';
var zUp = {x: 0, y: 0, z: 1};
var edits = {};
edits[attr] = zUp;
var layout = gd.layout;
Registry.call('_storeDirectGUIEdit', layout, fullLayout._preGUI, edits);
fullCamera.up = zUp;
Lib.nestedProperty(layout, attr).set(zUp);
} else {
// none rotation modes [pan or zoom]
camera.keyBindingMode = dragmode;
}
}
// to put dragmode and hovermode on the same grounds from relayout
this.fullSceneLayout.hovermode = hovermode;
};

to update the projection?

@etpinard etpinard added this to the v1.45.0 milestone Feb 20, 2019
@etpinard
Copy link
Contributor

Awesome work @archmoj !!

Adding this to v1.45.0 - might as well 😄 right?

💃 💃 💃

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

Successfully merging this pull request may close these issues.

None yet

2 participants