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

Revise gl3d scene initialization #5233

Merged
merged 2 commits into from
Oct 26, 2020
Merged
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
77 changes: 44 additions & 33 deletions src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ proto.prepareOptions = function() {
return opts;
};

var firstInit = true;

proto.tryCreatePlot = function() {
var scene = this;

Expand All @@ -146,7 +148,7 @@ proto.tryCreatePlot = function() {
try {
scene.glplot = createPlot(opts);
} catch(e) {
if(scene.staticMode) {
if(scene.staticMode || !firstInit) {
success = false;
} else { // try second time
try {
Expand All @@ -158,15 +160,22 @@ proto.tryCreatePlot = function() {
'The device may not be supported by is-mobile module!',
'Inverting preserveDrawingBuffer option in second attempt to create webgl scene.'
].join(' '));

// invert is-mobile
isMobile = opts.glOptions.preserveDrawingBuffer = !opts.glOptions.preserveDrawingBuffer;

scene.glplot = createPlot(opts);
} catch(e) {
// revert changes to is-mobile
isMobile = opts.glOptions.preserveDrawingBuffer = !opts.glOptions.preserveDrawingBuffer;

success = false;
}
}
}

firstInit = false;

return success;
};

Expand Down Expand Up @@ -238,43 +247,45 @@ proto.initializeGLPlot = function() {
scene.graphDiv.emit('plotly_relayout', update);
};

scene.glplot.canvas.addEventListener('mouseup', function() {
relayoutCallback(scene);
});
if(scene.glplot.canvas) {
scene.glplot.canvas.addEventListener('mouseup', function() {
relayoutCallback(scene);
});

scene.glplot.canvas.addEventListener('wheel', function(e) {
if(gd._context._scrollZoom.gl3d) {
if(scene.camera._ortho) {
var s = (e.deltaX > e.deltaY) ? 1.1 : 1.0 / 1.1;
var o = scene.glplot.getAspectratio();
scene.glplot.setAspectratio({
x: s * o.x,
y: s * o.y,
z: s * o.z
});
}
scene.glplot.canvas.addEventListener('wheel', function(e) {
if(gd._context._scrollZoom.gl3d) {
if(scene.camera._ortho) {
var s = (e.deltaX > e.deltaY) ? 1.1 : 1.0 / 1.1;
var o = scene.glplot.getAspectratio();
scene.glplot.setAspectratio({
x: s * o.x,
y: s * o.y,
z: s * o.z
});
}

relayoutCallback(scene);
}
}, passiveSupported ? {passive: false} : false);
relayoutCallback(scene);
}
}, passiveSupported ? {passive: false} : false);

scene.glplot.canvas.addEventListener('mousemove', function() {
if(scene.fullSceneLayout.dragmode === false) return;
if(scene.camera.mouseListener.buttons === 0) return;
scene.glplot.canvas.addEventListener('mousemove', function() {
if(scene.fullSceneLayout.dragmode === false) return;
if(scene.camera.mouseListener.buttons === 0) return;

var update = makeUpdate();
scene.graphDiv.emit('plotly_relayouting', update);
});
var update = makeUpdate();
scene.graphDiv.emit('plotly_relayouting', update);
});

if(!scene.staticMode) {
scene.glplot.canvas.addEventListener('webglcontextlost', function(event) {
if(gd && gd.emit) {
gd.emit('plotly_webglcontextlost', {
event: event,
layer: scene.id
});
}
}, false);
if(!scene.staticMode) {
scene.glplot.canvas.addEventListener('webglcontextlost', function(event) {
if(gd && gd.emit) {
gd.emit('plotly_webglcontextlost', {
event: event,
layer: scene.id
});
}
}, false);
}
}

scene.glplot.oncontextloss = function() {
Expand Down