Skip to content

Commit e1b1a39

Browse files
committed
avoid low level webgl calls from plotly.js gl3d scene
- make use of new gl-plot3d setters - reduce passing arguments
1 parent 1081e6a commit e1b1a39

File tree

3 files changed

+25
-40
lines changed

3 files changed

+25
-40
lines changed

package-lock.json

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"gl-mat4": "^1.2.0",
8282
"gl-mesh3d": "^2.1.1",
8383
"gl-plot2d": "^1.4.2",
84-
"gl-plot3d": "^2.3.0",
84+
"gl-plot3d": "git://github.com/gl-vis/gl-plot3d.git#8f89fc2ce75dfa8dae8e88ae1bf2849a50e25255",
8585
"gl-pointcloud2d": "^1.0.2",
8686
"gl-scatter3d": "^1.2.2",
8787
"gl-select-box": "^1.0.3",

src/plots/gl3d/scene.js

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function render(scene) {
128128
}
129129
tx = vectorTx.join('<br>');
130130
} else if(trace.type === 'isosurface' || trace.type === 'volume') {
131-
labels.valueLabel = Axes.tickText(scene.mockAxis, scene.mockAxis.d2l(selection.traceCoordinate[3]), 'hover').text;
131+
labels.valueLabel = Axes.tickText(scene._mockAxis, scene._mockAxis.d2l(selection.traceCoordinate[3]), 'hover').text;
132132
vectorTx.push('value: ' + labels.valueLabel);
133133
if(selection.textLabel) {
134134
vectorTx.push(selection.textLabel);
@@ -197,19 +197,19 @@ function render(scene) {
197197
scene.drawAnnotations(scene);
198198
}
199199

200-
function tryCreatePlot(scene, cameraObject, pixelRatio, canvas, gl) {
200+
function tryCreatePlot(scene) {
201201
var glplotOptions = {
202-
canvas: canvas,
203-
gl: gl,
202+
canvas: scene.canvas,
203+
gl: scene.gl,
204204
container: scene.container,
205205
axes: scene.axesOptions,
206206
spikes: scene.spikeOptions,
207207
pickRadius: 10,
208208
snapToData: true,
209209
autoScale: true,
210210
autoBounds: false,
211-
cameraObject: cameraObject,
212-
pixelRatio: pixelRatio
211+
cameraObject: scene.camera,
212+
pixelRatio: scene.pixelRatio
213213
};
214214

215215
// for static plots, we reuse the WebGL context
@@ -248,10 +248,10 @@ function tryCreatePlot(scene, cameraObject, pixelRatio, canvas, gl) {
248248
return failed < 2;
249249
}
250250

251-
function initializeGLPlot(scene, canvas, gl) {
251+
function initializeGLPlot(scene) {
252252
scene.initializeGLCamera();
253253

254-
var success = tryCreatePlot(scene, scene.camera, scene.pixelRatio, canvas, gl);
254+
var success = tryCreatePlot(scene);
255255
/*
256256
* createPlot will throw when webgl is not enabled in the client.
257257
* Lets return an instance of the module with all functions noop'd.
@@ -413,17 +413,15 @@ proto.initializeGLCamera = function() {
413413

414414
proto.recoverContext = function() {
415415
var scene = this;
416-
var gl = this.glplot.gl;
417-
var canvas = this.glplot.canvas;
418416

419-
this.glplot.dispose();
417+
scene.glplot.dispose();
420418

421419
function tryRecover() {
422-
if(gl.isContextLost()) {
420+
if(scene.glplot.gl.isContextLost()) {
423421
requestAnimationFrame(tryRecover);
424422
return;
425423
}
426-
if(!initializeGLPlot(scene, canvas, gl)) {
424+
if(!initializeGLPlot(scene)) {
427425
Lib.error('Catastrophic and unrecoverable WebGL error. Context lost.');
428426
return;
429427
}
@@ -506,10 +504,7 @@ proto.plot = function(sceneData, fullLayout, layout) {
506504
var fullSceneLayout = fullLayout[this.id];
507505
var sceneLayout = layout[this.id];
508506

509-
if(fullSceneLayout.bgcolor) this.glplot.clearColor = str2RGBAarray(fullSceneLayout.bgcolor);
510-
else this.glplot.clearColor = [0, 0, 0, 0];
511-
512-
this.glplot.snapToData = true;
507+
this.glplot.setClearColor(str2RGBAarray(fullSceneLayout.bgcolor));
513508

514509
// Update layout
515510
this.fullLayout = fullLayout;
@@ -688,8 +683,10 @@ proto.plot = function(sceneData, fullLayout, layout) {
688683
axisDataRange[i] = sceneBounds[1][i] - sceneBounds[0][i];
689684

690685
// Update plot bounds
691-
this.glplot.bounds[0][i] = sceneBounds[0][i] * dataScale[i];
692-
this.glplot.bounds[1][i] = sceneBounds[1][i] * dataScale[i];
686+
this.glplot.setBounds(i, {
687+
min: sceneBounds[0][i] * dataScale[i],
688+
max: sceneBounds[1][i] * dataScale[i]
689+
});
693690
}
694691

695692
var axesScaleRatio = [1, 1, 1];
@@ -821,21 +818,10 @@ proto.setViewport = function(sceneLayout) {
821818
var oldOrtho = this.camera._ortho;
822819

823820
if(newOrtho !== oldOrtho) {
824-
this.glplot.redraw();
825-
826-
var RGBA = this.glplot.clearColor;
827-
this.glplot.gl.clearColor(
828-
RGBA[0], RGBA[1], RGBA[2], RGBA[3]
829-
);
830-
this.glplot.gl.clear(
831-
this.glplot.gl.DEPTH_BUFFER_BIT |
832-
this.glplot.gl.COLOR_BUFFER_BIT
833-
);
834-
821+
this.glplot.redraw(); // TODO: figure out why we need to redraw here?
822+
this.glplot.clearRGBA();
835823
this.glplot.dispose();
836-
837824
initializeGLPlot(this);
838-
this.camera._ortho = newOrtho;
839825
}
840826
};
841827

@@ -1046,17 +1032,17 @@ proto.setConvert = function() {
10461032
};
10471033

10481034
proto.make4thDimension = function() {
1049-
var _this = this;
1050-
var gd = _this.graphDiv;
1035+
var scene = this;
1036+
var gd = scene.graphDiv;
10511037
var fullLayout = gd._fullLayout;
10521038

10531039
// mock axis for hover formatting
1054-
_this.mockAxis = {
1040+
scene._mockAxis = {
10551041
type: 'linear',
10561042
showexponent: 'all',
10571043
exponentformat: 'B'
10581044
};
1059-
Axes.setConvert(_this.mockAxis, fullLayout);
1045+
Axes.setConvert(scene._mockAxis, fullLayout);
10601046
};
10611047

10621048
module.exports = Scene;

0 commit comments

Comments
 (0)