@@ -261,14 +261,17 @@ function initializeGLPlot(scene, pixelRatio, canvas, gl) {
261261 if ( ! success ) return showNoWebGlMsg ( scene ) ;
262262
263263 var gd = scene . graphDiv ;
264+ var layout = gd . layout ;
264265
265266 var makeUpdate = function ( ) {
266267 var update = { } ;
267268
268- // camera updates
269- update [ scene . id + '.camera' ] = getLayoutCamera ( scene . camera ) ;
269+ if ( scene . isCameraChanged ( layout ) ) {
270+ // camera updates
271+ update [ scene . id + '.camera' ] = scene . getCamera ( ) ;
272+ }
270273
271- if ( scene . camera . _ortho === true ) {
274+ if ( scene . isAspectChanged ( layout ) ) {
272275 // scene updates
273276 update [ scene . id + '.aspectratio' ] = scene . glplot . getAspectratio ( ) ;
274277 }
@@ -280,7 +283,7 @@ function initializeGLPlot(scene, pixelRatio, canvas, gl) {
280283 if ( scene . fullSceneLayout . dragmode === false ) return ;
281284
282285 var update = makeUpdate ( ) ;
283- scene . saveLayout ( gd . layout ) ;
286+ scene . saveLayout ( layout ) ;
284287 scene . graphDiv . emit ( 'plotly_relayout' , update ) ;
285288 } ;
286289
@@ -783,7 +786,7 @@ proto.destroy = function() {
783786 this . glplot = null ;
784787} ;
785788
786- // getCameraArrays :: plotly_coords -> orbit_camera_coords
789+ // getCameraArrays :: plotly_coords -> gl-plot3d_coords
787790// inverse of getLayoutCamera
788791function getCameraArrays ( camera ) {
789792 return [
@@ -793,7 +796,7 @@ function getCameraArrays(camera) {
793796 ] ;
794797}
795798
796- // getLayoutCamera :: orbit_camera_coords -> plotly_coords
799+ // getLayoutCamera :: gl-plot3d_coords -> plotly_coords
797800// inverse of getCameraArrays
798801function getLayoutCamera ( camera ) {
799802 return {
@@ -804,14 +807,14 @@ function getLayoutCamera(camera) {
804807 } ;
805808}
806809
807- // get camera position in plotly coords from 'orbit-camera ' coords
808- proto . getCamera = function getCamera ( ) {
810+ // get camera position in plotly coords from 'gl-plot3d ' coords
811+ proto . getCamera = function ( ) {
809812 this . glplot . camera . view . recalcMatrix ( this . camera . view . lastT ( ) ) ;
810813 return getLayoutCamera ( this . glplot . camera ) ;
811814} ;
812815
813816// set gl-plot3d camera position and scene aspects with a set of plotly coords
814- proto . setViewport = function setViewport ( sceneLayout ) {
817+ proto . setViewport = function ( sceneLayout ) {
815818 var cameraData = sceneLayout . camera ;
816819
817820 this . glplot . camera . lookAt . apply ( this , getCameraArrays ( cameraData ) ) ;
@@ -841,33 +844,25 @@ proto.setViewport = function setViewport(sceneLayout) {
841844 }
842845} ;
843846
844- // save camera to user layout (i.e. gd.layout)
845- proto . saveLayout = function saveLayout ( layout ) {
846- var fullLayout = this . fullLayout ;
847-
847+ proto . isCameraChanged = function ( layout ) {
848848 var cameraData = this . getCamera ( ) ;
849849 var cameraNestedProp = Lib . nestedProperty ( layout , this . id + '.camera' ) ;
850850 var cameraDataLastSave = cameraNestedProp . get ( ) ;
851851
852-
853- var aspectData = this . glplot . getAspectratio ( ) ;
854- var aspectNestedProp = Lib . nestedProperty ( layout , this . id + '.aspectratio' ) ;
855- var aspectDataLastSave = aspectNestedProp . get ( ) ;
856-
857852 function same ( x , y , i , j ) {
858853 var vectors = [ 'up' , 'center' , 'eye' ] ;
859854 var components = [ 'x' , 'y' , 'z' ] ;
860855 return y [ vectors [ i ] ] && ( x [ vectors [ i ] ] [ components [ j ] ] === y [ vectors [ i ] ] [ components [ j ] ] ) ;
861856 }
862857
863- var cameraChanged = false ;
858+ var changed = false ;
864859 if ( cameraDataLastSave === undefined ) {
865- cameraChanged = true ;
860+ changed = true ;
866861 } else {
867862 for ( var i = 0 ; i < 3 ; i ++ ) {
868863 for ( var j = 0 ; j < 3 ; j ++ ) {
869864 if ( ! same ( cameraData , cameraDataLastSave , i , j ) ) {
870- cameraChanged = true ;
865+ changed = true ;
871866 break ;
872867 }
873868 }
@@ -876,22 +871,58 @@ proto.saveLayout = function saveLayout(layout) {
876871 if ( ! cameraDataLastSave . projection || (
877872 cameraData . projection &&
878873 cameraData . projection . type !== cameraDataLastSave . projection . type ) ) {
879- cameraChanged = true ;
874+ changed = true ;
880875 }
881876 }
882877
883- var aspectChanged = (
878+ return changed ;
879+ } ;
880+
881+ proto . isAspectChanged = function ( layout ) {
882+ var aspectData = this . glplot . getAspectratio ( ) ;
883+ var aspectNestedProp = Lib . nestedProperty ( layout , this . id + '.aspectratio' ) ;
884+ var aspectDataLastSave = aspectNestedProp . get ( ) ;
885+
886+ return (
884887 aspectDataLastSave === undefined || (
885888 aspectDataLastSave . x !== aspectData . x ||
886889 aspectDataLastSave . y !== aspectData . y ||
887890 aspectDataLastSave . z !== aspectData . z
888891 ) ) ;
892+ } ;
893+
894+ // save camera to user layout (i.e. gd.layout)
895+ proto . saveLayout = function ( layout ) {
896+ var fullLayout = this . fullLayout ;
897+
898+ var cameraData ;
899+ var cameraNestedProp ;
900+ var cameraDataLastSave ;
901+
902+ var aspectData ;
903+ var aspectNestedProp ;
904+ var aspectDataLastSave ;
905+
906+ var cameraChanged = this . isCameraChanged ( layout ) ;
907+ var aspectChanged = this . isAspectChanged ( layout ) ;
889908
890909 var hasChanged = cameraChanged || aspectChanged ;
891910 if ( hasChanged ) {
892911 var preGUI = { } ;
893- if ( cameraChanged ) preGUI [ this . id + '.camera' ] = cameraDataLastSave ;
894- if ( aspectChanged ) preGUI [ this . id + '.aspectratio' ] = aspectDataLastSave ;
912+ if ( cameraChanged ) {
913+ cameraData = this . getCamera ( ) ;
914+ cameraNestedProp = Lib . nestedProperty ( layout , this . id + '.camera' ) ;
915+ cameraDataLastSave = cameraNestedProp . get ( ) ;
916+
917+ preGUI [ this . id + '.camera' ] = cameraDataLastSave ;
918+ }
919+ if ( aspectChanged ) {
920+ aspectData = this . glplot . getAspectratio ( ) ;
921+ aspectNestedProp = Lib . nestedProperty ( layout , this . id + '.aspectratio' ) ;
922+ aspectDataLastSave = aspectNestedProp . get ( ) ;
923+
924+ preGUI [ this . id + '.aspectratio' ] = aspectDataLastSave ;
925+ }
895926 Registry . call ( '_storeDirectGUIEdit' , layout , fullLayout . _preGUI , preGUI ) ;
896927
897928 if ( cameraChanged ) {
0 commit comments