Skip to content

Improve camera init #3585

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

Merged
merged 16 commits into from
Mar 20, 2019
Merged
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: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"gl-mat4": "^1.2.0",
"gl-mesh3d": "^2.0.8",
"gl-plot2d": "^1.4.2",
"gl-plot3d": "^2.1.2",
"gl-plot3d": "^2.2.0",
"gl-pointcloud2d": "^1.0.2",
"gl-scatter3d": "^1.2.0",
"gl-select-box": "^1.0.3",
Expand Down
39 changes: 18 additions & 21 deletions src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function render(scene) {
scene.drawAnnotations(scene);
}

function tryCreatePlot(scene, camera, pixelRatio, canvas, gl) {
function tryCreatePlot(scene, cameraObject, pixelRatio, canvas, gl) {

var glplotOptions = {
canvas: canvas,
Expand All @@ -204,7 +204,7 @@ function tryCreatePlot(scene, camera, pixelRatio, canvas, gl) {
snapToData: true,
autoScale: true,
autoBounds: false,
camera: camera,
cameraObject: cameraObject,
pixelRatio: pixelRatio
};

Expand Down Expand Up @@ -238,9 +238,11 @@ function tryCreatePlot(scene, camera, pixelRatio, canvas, gl) {
return true;
}

function initializeGLPlot(scene, camera, pixelRatio, canvas, gl) {
function initializeGLPlot(scene, pixelRatio, canvas, gl) {

var success = tryCreatePlot(scene, camera, pixelRatio, canvas, gl);
scene.initializeGLCamera();

var success = tryCreatePlot(scene, scene.camera, pixelRatio, canvas, gl);
/*
* createPlot will throw when webgl is not enabled in the client.
* Lets return an instance of the module with all functions noop'd.
Expand Down Expand Up @@ -281,8 +283,6 @@ function initializeGLPlot(scene, camera, pixelRatio, canvas, gl) {
}, false);
}

if(!scene.camera) scene.initializeGLCamera();

scene.glplot.camera = scene.camera;

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

var camera = fullLayout.scene.camera;

initializeGLPlot(this, camera, this.pixelRatio);
initializeGLPlot(this, this.pixelRatio);
}

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

this.glplot.dispose();

initializeGLPlot(this, cameraData, pixelRatio);
initializeGLPlot(this, pixelRatio);
this.glplot.camera._ortho = newOrtho;
}
};
Expand Down Expand Up @@ -851,7 +849,6 @@ proto.saveCamera = function saveCamera(layout) {

proto.updateFx = function(dragmode, hovermode) {
var camera = this.camera;

if(camera) {
// rotate and orbital are synonymous
if(dragmode === 'orbit') {
Expand All @@ -873,16 +870,16 @@ proto.updateFx = function(dragmode, hovermode) {
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);
if(z / Math.sqrt(x * x + y * y + z * z) < 0.999) {
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;
Expand Down
Loading