Skip to content

Commit 50da961

Browse files
authored
Merge pull request #3573 from plotly/fixup-pixelratio-3d
Revised pixelRatio in 3D plots to address multiple bugs
2 parents db54ced + 5096f4f commit 50da961

File tree

65 files changed

+92
-86
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+92
-86
lines changed

package-lock.json

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

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,21 @@
7272
"es6-promise": "^3.0.2",
7373
"fast-isnumeric": "^1.1.2",
7474
"font-atlas-sdf": "^1.3.3",
75-
"gl-cone3d": "^1.2.2",
75+
"gl-cone3d": "^1.2.3",
7676
"gl-contour2d": "^1.1.5",
77-
"gl-error3d": "^1.0.13",
77+
"gl-error3d": "^1.0.14",
7878
"gl-heatmap2d": "^1.0.5",
7979
"gl-line3d": "^1.1.10",
8080
"gl-mat4": "^1.2.0",
81-
"gl-mesh3d": "^2.0.7",
81+
"gl-mesh3d": "^2.0.8",
8282
"gl-plot2d": "^1.4.2",
83-
"gl-plot3d": "^2.0.0",
83+
"gl-plot3d": "^2.1.1",
8484
"gl-pointcloud2d": "^1.0.2",
85-
"gl-scatter3d": "^1.1.6",
85+
"gl-scatter3d": "^1.2.0",
8686
"gl-select-box": "^1.0.3",
8787
"gl-spikes2d": "^1.0.2",
88-
"gl-streamtube3d": "^1.1.2",
89-
"gl-surface3d": "^1.4.1",
88+
"gl-streamtube3d": "^1.1.3",
89+
"gl-surface3d": "^1.4.2",
9090
"gl-text": "^1.1.6",
9191
"glslify": "^7.0.0",
9292
"has-hover": "^1.0.1",

src/plot_api/subroutines.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,7 @@ exports.doCamera = function(gd) {
601601
var scene = sceneLayout._scene;
602602

603603
var cameraData = sceneLayout.camera;
604-
var isOrtho = !!(cameraData && cameraData.projection && cameraData.projection.type === 'orthographic');
605-
606-
scene.setCamera(cameraData, isOrtho);
604+
scene.setCamera(cameraData);
607605
}
608606
};
609607

src/plots/gl3d/scene.js

+13-8
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, canvas, gl) {
195+
function tryCreatePlot(scene, camera, pixelRatio, canvas, gl) {
196196

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

210211
// for static plots, we reuse the WebGL context
@@ -237,9 +238,9 @@ function tryCreatePlot(scene, camera, canvas, gl) {
237238
return true;
238239
}
239240

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

242-
var success = tryCreatePlot(scene, camera, canvas, gl);
243+
var success = tryCreatePlot(scene, camera, pixelRatio, canvas, gl);
243244
/*
244245
* createPlot will throw when webgl is not enabled in the client.
245246
* Lets return an instance of the module with all functions noop'd.
@@ -340,7 +341,7 @@ function Scene(options, fullLayout) {
340341
this.spikeOptions = createSpikeOptions(fullLayout[this.id]);
341342
this.container = sceneContainer;
342343
this.staticMode = !!options.staticPlot;
343-
this.pixelRatio = options.plotGlPixelRatio || 2;
344+
this.pixelRatio = this.pixelRatio || options.plotGlPixelRatio || 2;
344345

345346
// Coordinate rescaling
346347
this.dataScale = [1, 1, 1];
@@ -351,7 +352,8 @@ function Scene(options, fullLayout) {
351352
this.drawAnnotations = Registry.getComponentMethod('annotations3d', 'draw');
352353

353354
var camera = fullLayout.scene.camera;
354-
initializeGLPlot(this, camera);
355+
356+
initializeGLPlot(this, camera, this.pixelRatio);
355357
}
356358

357359
var proto = Scene.prototype;
@@ -377,14 +379,15 @@ proto.recoverContext = function() {
377379
var gl = this.glplot.gl;
378380
var canvas = this.glplot.canvas;
379381
var camera = this.glplot.camera;
382+
var pixelRatio = this.glplot.pixelRatio;
380383
this.glplot.dispose();
381384

382385
function tryRecover() {
383386
if(gl.isContextLost()) {
384387
requestAnimationFrame(tryRecover);
385388
return;
386389
}
387-
if(!initializeGLPlot(scene, camera, canvas, gl)) {
390+
if(!initializeGLPlot(scene, camera, pixelRatio, canvas, gl)) {
388391
Lib.error('Catastrophic and unrecoverable WebGL error. Context lost.');
389392
return;
390393
}
@@ -780,6 +783,8 @@ proto.setCamera = function setCamera(cameraData) {
780783
if(newOrtho !== oldOrtho) {
781784
this.glplot.redraw();
782785

786+
var pixelRatio = this.glplot.pixelRatio;
787+
783788
var RGBA = this.glplot.clearColor;
784789
this.glplot.gl.clearColor(
785790
RGBA[0], RGBA[1], RGBA[2], RGBA[3]
@@ -791,7 +796,7 @@ proto.setCamera = function setCamera(cameraData) {
791796

792797
this.glplot.dispose();
793798

794-
initializeGLPlot(this, cameraData);
799+
initializeGLPlot(this, cameraData, pixelRatio);
795800
this.glplot.camera._ortho = newOrtho;
796801
}
797802
};

src/traces/scatter3d/convert.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ proto.update = function(data) {
343343
this.dataPoints = options.position;
344344

345345
lineOptions = {
346-
gl: gl,
346+
gl: this.scene.glplot.gl,
347347
position: options.position,
348348
color: options.lineColor,
349349
lineWidth: options.lineWidth || 1,
@@ -371,7 +371,7 @@ proto.update = function(data) {
371371
if(data.marker && data.marker.opacity) scatterOpacity *= data.marker.opacity;
372372

373373
scatterOptions = {
374-
gl: gl,
374+
gl: this.scene.glplot.gl,
375375
position: options.position,
376376
color: options.scatterColor,
377377
size: options.scatterSize,
@@ -400,7 +400,7 @@ proto.update = function(data) {
400400
}
401401

402402
textOptions = {
403-
gl: gl,
403+
gl: this.scene.glplot.gl,
404404
position: options.position,
405405
glyph: options.text,
406406
color: options.textColor,
@@ -431,7 +431,7 @@ proto.update = function(data) {
431431
}
432432

433433
errorOptions = {
434-
gl: gl,
434+
gl: this.scene.glplot.gl,
435435
position: options.position,
436436
color: options.errorColor,
437437
error: options.errorBounds,
8 Bytes
79 Bytes
28 Bytes
191 Bytes

test/image/baselines/gl3d_bunny.png

60 Bytes
53 Bytes
-1.58 KB
9.01 KB
60 Bytes

test/image/baselines/gl3d_cube.png

-2.12 KB
19 Bytes
-253 Bytes
22 Bytes
23 Bytes
289 Bytes
-62 Bytes
244 Bytes
-118 Bytes
4 Bytes
6 Bytes
111 Bytes
61 Bytes
-392 Bytes
5 Bytes
-1 Bytes
-40 Bytes
1.02 KB
12 Bytes
149 Bytes
-1 Bytes
-12 Bytes
-10 Bytes
5 Bytes
-355 Bytes
3.88 KB
-1 Bytes

test/image/baselines/gl3d_z-range.png

1 Byte
-2 Bytes

0 commit comments

Comments
 (0)