@@ -192,8 +192,7 @@ function render(scene) {
192192 scene . drawAnnotations ( scene ) ;
193193}
194194
195- function initializeGLPlot ( scene , camera , canvas , gl ) {
196- var gd = scene . graphDiv ;
195+ function tryCreatePlot ( scene , camera , canvas , gl ) {
197196
198197 var glplotOptions = {
199198 canvas : canvas ,
@@ -240,12 +239,19 @@ function initializeGLPlot(scene, camera, canvas, gl) {
240239 */
241240 return showNoWebGlMsg ( scene ) ;
242241 }
242+ }
243+
244+ function initializeGLPlot ( scene , camera , canvas , gl ) {
245+
246+ tryCreatePlot ( scene , camera , canvas , gl ) ;
247+
248+ var gd = scene . graphDiv ;
243249
244250 var relayoutCallback = function ( scene ) {
245251 if ( scene . fullSceneLayout . dragmode === false ) return ;
246252
247253 var update = { } ;
248- update [ scene . id + '.camera' ] = getLayoutCamera ( scene . camera ) ;
254+ update [ scene . id + '.camera' ] = getLayoutCamera ( scene . camera , scene . camera . _ortho ) ;
249255 scene . saveCamera ( gd . layout ) ;
250256 scene . graphDiv . emit ( 'plotly_relayout' , update ) ;
251257 } ;
@@ -350,7 +356,7 @@ var proto = Scene.prototype;
350356proto . initializeGLCamera = function ( ) {
351357
352358 var cameraData = this . fullSceneLayout . camera ;
353- var isOrtho = ( cameraData . projection && cameraData . projection . type === 'orthographic' ) ;
359+ var isOrtho = ( cameraData . projection . type === 'orthographic' ) ;
354360
355361 this . camera = createCamera ( this . container , {
356362 center : [ cameraData . center . x , cameraData . center . y , cameraData . center . z ] ,
@@ -746,32 +752,38 @@ function getOrbitCamera(camera) {
746752
747753// getLayoutCamera :: orbit_camera_coords -> plotly_coords
748754// 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 ) {
758756 return {
759757 up : { x : camera . up [ 0 ] , y : camera . up [ 1 ] , z : camera . up [ 2 ] } ,
760758 center : { x : camera . center [ 0 ] , y : camera . center [ 1 ] , z : camera . center [ 2 ] } ,
761759 eye : { x : camera . eye [ 0 ] , y : camera . eye [ 1 ] , z : camera . eye [ 2 ] } ,
762- projection : { type : cameraProjectionType }
760+ projection : { type : ( isOrtho === true ) ? 'orthographic' : 'perspective' }
763761 } ;
764762}
765763
766764// get camera position in plotly coords from 'orbit-camera' coords
767765proto . getCamera = function getCamera ( ) {
768766 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 ) ;
770768} ;
771769
772770// set camera position with a set of plotly coords
773771proto . setCamera = function setCamera ( cameraData ) {
774772 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+ }
775787} ;
776788
777789// save camera to user layout (i.e. gd.layout)
0 commit comments