@@ -192,8 +192,7 @@ function render(scene) {
192
192
scene . drawAnnotations ( scene ) ;
193
193
}
194
194
195
- function initializeGLPlot ( scene , camera , canvas , gl ) {
196
- var gd = scene . graphDiv ;
195
+ function tryCreatePlot ( scene , camera , canvas , gl ) {
197
196
198
197
var glplotOptions = {
199
198
canvas : canvas ,
@@ -240,12 +239,19 @@ function initializeGLPlot(scene, camera, canvas, gl) {
240
239
*/
241
240
return showNoWebGlMsg ( scene ) ;
242
241
}
242
+ }
243
+
244
+ function initializeGLPlot ( scene , camera , canvas , gl ) {
245
+
246
+ tryCreatePlot ( scene , camera , canvas , gl ) ;
247
+
248
+ var gd = scene . graphDiv ;
243
249
244
250
var relayoutCallback = function ( scene ) {
245
251
if ( scene . fullSceneLayout . dragmode === false ) return ;
246
252
247
253
var update = { } ;
248
- update [ scene . id + '.camera' ] = getLayoutCamera ( scene . camera ) ;
254
+ update [ scene . id + '.camera' ] = getLayoutCamera ( scene . camera , scene . camera . _ortho ) ;
249
255
scene . saveCamera ( gd . layout ) ;
250
256
scene . graphDiv . emit ( 'plotly_relayout' , update ) ;
251
257
} ;
@@ -350,7 +356,7 @@ var proto = Scene.prototype;
350
356
proto . initializeGLCamera = function ( ) {
351
357
352
358
var cameraData = this . fullSceneLayout . camera ;
353
- var isOrtho = ( cameraData . projection && cameraData . projection . type === 'orthographic' ) ;
359
+ var isOrtho = ( cameraData . projection . type === 'orthographic' ) ;
354
360
355
361
this . camera = createCamera ( this . container , {
356
362
center : [ cameraData . center . x , cameraData . center . y , cameraData . center . z ] ,
@@ -746,32 +752,38 @@ function getOrbitCamera(camera) {
746
752
747
753
// getLayoutCamera :: orbit_camera_coords -> plotly_coords
748
754
// inverse of getOrbitCamera
749
- function getLayoutCamera ( camera ) {
750
- var cameraProjectionType ;
751
- if ( camera . _ortho === false ) { cameraProjectionType = 'perspective' ; }
752
- else if ( camera . _ortho === true ) { cameraProjectionType = 'orthographic' ; }
753
- else {
754
- cameraProjectionType = ( camera . projection && camera . projection . type === 'orthographic' ) ?
755
- 'orthographic' : 'perspective' ;
756
- }
757
-
755
+ function getLayoutCamera ( camera , isOrtho ) {
758
756
return {
759
757
up : { x : camera . up [ 0 ] , y : camera . up [ 1 ] , z : camera . up [ 2 ] } ,
760
758
center : { x : camera . center [ 0 ] , y : camera . center [ 1 ] , z : camera . center [ 2 ] } ,
761
759
eye : { x : camera . eye [ 0 ] , y : camera . eye [ 1 ] , z : camera . eye [ 2 ] } ,
762
- projection : { type : cameraProjectionType }
760
+ projection : { type : ( isOrtho === true ) ? 'orthographic' : 'perspective' }
763
761
} ;
764
762
}
765
763
766
764
// get camera position in plotly coords from 'orbit-camera' coords
767
765
proto . getCamera = function getCamera ( ) {
768
766
this . glplot . camera . view . recalcMatrix ( this . camera . view . lastT ( ) ) ;
769
- return getLayoutCamera ( this . glplot . camera ) ;
767
+ return getLayoutCamera ( this . glplot . camera , this . glplot . camera . _ortho ) ;
770
768
} ;
771
769
772
770
// set camera position with a set of plotly coords
773
771
proto . setCamera = function setCamera ( cameraData ) {
774
772
this . glplot . camera . lookAt . apply ( this , getOrbitCamera ( cameraData ) ) ;
773
+
774
+ var newOrtho = ( cameraData . projection . type === 'orthographic' ) ;
775
+ var oldOrtho = this . glplot . camera . _ortho ;
776
+
777
+ if ( newOrtho !== oldOrtho ) {
778
+
779
+ this . glplot . dispose ( ) ;
780
+ this . glplot = null ;
781
+
782
+ // Need to clear gl-container here
783
+
784
+ initializeGLPlot ( this , cameraData ) ;
785
+ this . glplot . camera . _ortho = newOrtho ;
786
+ }
775
787
} ;
776
788
777
789
// save camera to user layout (i.e. gd.layout)
0 commit comments