Skip to content

Commit 12ce725

Browse files
authored
Merge pull request #3585 from plotly/fix3576-no-rotate-camera-before-modebar
Improve camera init
2 parents e1cfd70 + 6f0330b commit 12ce725

File tree

6 files changed

+180
-61
lines changed

6 files changed

+180
-61
lines changed

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"gl-mat4": "^1.2.0",
8181
"gl-mesh3d": "^2.0.8",
8282
"gl-plot2d": "^1.4.2",
83-
"gl-plot3d": "^2.1.2",
83+
"gl-plot3d": "^2.2.0",
8484
"gl-pointcloud2d": "^1.0.2",
8585
"gl-scatter3d": "^1.2.0",
8686
"gl-select-box": "^1.0.3",

src/plots/gl3d/scene.js

+18-21
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function render(scene) {
192192
scene.drawAnnotations(scene);
193193
}
194194

195-
function tryCreatePlot(scene, camera, pixelRatio, canvas, gl) {
195+
function tryCreatePlot(scene, cameraObject, pixelRatio, canvas, gl) {
196196

197197
var glplotOptions = {
198198
canvas: canvas,
@@ -204,7 +204,7 @@ function tryCreatePlot(scene, camera, pixelRatio, canvas, gl) {
204204
snapToData: true,
205205
autoScale: true,
206206
autoBounds: false,
207-
camera: camera,
207+
cameraObject: cameraObject,
208208
pixelRatio: pixelRatio
209209
};
210210

@@ -238,9 +238,11 @@ function tryCreatePlot(scene, camera, pixelRatio, canvas, gl) {
238238
return true;
239239
}
240240

241-
function initializeGLPlot(scene, camera, pixelRatio, canvas, gl) {
241+
function initializeGLPlot(scene, pixelRatio, canvas, gl) {
242242

243-
var success = tryCreatePlot(scene, camera, pixelRatio, canvas, gl);
243+
scene.initializeGLCamera();
244+
245+
var success = tryCreatePlot(scene, scene.camera, pixelRatio, canvas, gl);
244246
/*
245247
* createPlot will throw when webgl is not enabled in the client.
246248
* Lets return an instance of the module with all functions noop'd.
@@ -281,8 +283,6 @@ function initializeGLPlot(scene, camera, pixelRatio, canvas, gl) {
281283
}, false);
282284
}
283285

284-
if(!scene.camera) scene.initializeGLCamera();
285-
286286
scene.glplot.camera = scene.camera;
287287

288288
scene.glplot.oncontextloss = function() {
@@ -351,9 +351,7 @@ function Scene(options, fullLayout) {
351351
this.convertAnnotations = Registry.getComponentMethod('annotations3d', 'convert');
352352
this.drawAnnotations = Registry.getComponentMethod('annotations3d', 'draw');
353353

354-
var camera = fullLayout.scene.camera;
355-
356-
initializeGLPlot(this, camera, this.pixelRatio);
354+
initializeGLPlot(this, this.pixelRatio);
357355
}
358356

359357
var proto = Scene.prototype;
@@ -796,7 +794,7 @@ proto.setCamera = function setCamera(cameraData) {
796794

797795
this.glplot.dispose();
798796

799-
initializeGLPlot(this, cameraData, pixelRatio);
797+
initializeGLPlot(this, pixelRatio);
800798
this.glplot.camera._ortho = newOrtho;
801799
}
802800
};
@@ -851,7 +849,6 @@ proto.saveCamera = function saveCamera(layout) {
851849

852850
proto.updateFx = function(dragmode, hovermode) {
853851
var camera = this.camera;
854-
855852
if(camera) {
856853
// rotate and orbital are synonymous
857854
if(dragmode === 'orbit') {
@@ -873,16 +870,16 @@ proto.updateFx = function(dragmode, hovermode) {
873870
var y = fullCamera.up.y;
874871
var z = fullCamera.up.z;
875872
// only push `up` back to (full)layout if it's going to change
876-
if(z / Math.sqrt(x * x + y * y + z * z) > 0.999) return;
877-
878-
var attr = this.id + '.camera.up';
879-
var zUp = {x: 0, y: 0, z: 1};
880-
var edits = {};
881-
edits[attr] = zUp;
882-
var layout = gd.layout;
883-
Registry.call('_storeDirectGUIEdit', layout, fullLayout._preGUI, edits);
884-
fullCamera.up = zUp;
885-
Lib.nestedProperty(layout, attr).set(zUp);
873+
if(z / Math.sqrt(x * x + y * y + z * z) < 0.999) {
874+
var attr = this.id + '.camera.up';
875+
var zUp = {x: 0, y: 0, z: 1};
876+
var edits = {};
877+
edits[attr] = zUp;
878+
var layout = gd.layout;
879+
Registry.call('_storeDirectGUIEdit', layout, fullLayout._preGUI, edits);
880+
fullCamera.up = zUp;
881+
Lib.nestedProperty(layout, attr).set(zUp);
882+
}
886883
} else {
887884
// none rotation modes [pan or zoom]
888885
camera.keyBindingMode = dragmode;

0 commit comments

Comments
 (0)