@@ -261,14 +261,17 @@ function initializeGLPlot(scene, pixelRatio, canvas, gl) {
261
261
if ( ! success ) return showNoWebGlMsg ( scene ) ;
262
262
263
263
var gd = scene . graphDiv ;
264
+ var layout = gd . layout ;
264
265
265
266
var makeUpdate = function ( ) {
266
267
var update = { } ;
267
268
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
+ }
270
273
271
- if ( scene . camera . _ortho === true ) {
274
+ if ( scene . isAspectChanged ( layout ) ) {
272
275
// scene updates
273
276
update [ scene . id + '.aspectratio' ] = scene . glplot . getAspectratio ( ) ;
274
277
}
@@ -280,7 +283,7 @@ function initializeGLPlot(scene, pixelRatio, canvas, gl) {
280
283
if ( scene . fullSceneLayout . dragmode === false ) return ;
281
284
282
285
var update = makeUpdate ( ) ;
283
- scene . saveLayout ( gd . layout ) ;
286
+ scene . saveLayout ( layout ) ;
284
287
scene . graphDiv . emit ( 'plotly_relayout' , update ) ;
285
288
} ;
286
289
@@ -783,7 +786,7 @@ proto.destroy = function() {
783
786
this . glplot = null ;
784
787
} ;
785
788
786
- // getCameraArrays :: plotly_coords -> orbit_camera_coords
789
+ // getCameraArrays :: plotly_coords -> gl-plot3d_coords
787
790
// inverse of getLayoutCamera
788
791
function getCameraArrays ( camera ) {
789
792
return [
@@ -793,7 +796,7 @@ function getCameraArrays(camera) {
793
796
] ;
794
797
}
795
798
796
- // getLayoutCamera :: orbit_camera_coords -> plotly_coords
799
+ // getLayoutCamera :: gl-plot3d_coords -> plotly_coords
797
800
// inverse of getCameraArrays
798
801
function getLayoutCamera ( camera ) {
799
802
return {
@@ -804,14 +807,14 @@ function getLayoutCamera(camera) {
804
807
} ;
805
808
}
806
809
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 ( ) {
809
812
this . glplot . camera . view . recalcMatrix ( this . camera . view . lastT ( ) ) ;
810
813
return getLayoutCamera ( this . glplot . camera ) ;
811
814
} ;
812
815
813
816
// 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 ) {
815
818
var cameraData = sceneLayout . camera ;
816
819
817
820
this . glplot . camera . lookAt . apply ( this , getCameraArrays ( cameraData ) ) ;
@@ -841,33 +844,25 @@ proto.setViewport = function setViewport(sceneLayout) {
841
844
}
842
845
} ;
843
846
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 ) {
848
848
var cameraData = this . getCamera ( ) ;
849
849
var cameraNestedProp = Lib . nestedProperty ( layout , this . id + '.camera' ) ;
850
850
var cameraDataLastSave = cameraNestedProp . get ( ) ;
851
851
852
-
853
- var aspectData = this . glplot . getAspectratio ( ) ;
854
- var aspectNestedProp = Lib . nestedProperty ( layout , this . id + '.aspectratio' ) ;
855
- var aspectDataLastSave = aspectNestedProp . get ( ) ;
856
-
857
852
function same ( x , y , i , j ) {
858
853
var vectors = [ 'up' , 'center' , 'eye' ] ;
859
854
var components = [ 'x' , 'y' , 'z' ] ;
860
855
return y [ vectors [ i ] ] && ( x [ vectors [ i ] ] [ components [ j ] ] === y [ vectors [ i ] ] [ components [ j ] ] ) ;
861
856
}
862
857
863
- var cameraChanged = false ;
858
+ var changed = false ;
864
859
if ( cameraDataLastSave === undefined ) {
865
- cameraChanged = true ;
860
+ changed = true ;
866
861
} else {
867
862
for ( var i = 0 ; i < 3 ; i ++ ) {
868
863
for ( var j = 0 ; j < 3 ; j ++ ) {
869
864
if ( ! same ( cameraData , cameraDataLastSave , i , j ) ) {
870
- cameraChanged = true ;
865
+ changed = true ;
871
866
break ;
872
867
}
873
868
}
@@ -876,22 +871,58 @@ proto.saveLayout = function saveLayout(layout) {
876
871
if ( ! cameraDataLastSave . projection || (
877
872
cameraData . projection &&
878
873
cameraData . projection . type !== cameraDataLastSave . projection . type ) ) {
879
- cameraChanged = true ;
874
+ changed = true ;
880
875
}
881
876
}
882
877
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 (
884
887
aspectDataLastSave === undefined || (
885
888
aspectDataLastSave . x !== aspectData . x ||
886
889
aspectDataLastSave . y !== aspectData . y ||
887
890
aspectDataLastSave . z !== aspectData . z
888
891
) ) ;
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 ) ;
889
908
890
909
var hasChanged = cameraChanged || aspectChanged ;
891
910
if ( hasChanged ) {
892
911
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
+ }
895
926
Registry . call ( '_storeDirectGUIEdit' , layout , fullLayout . _preGUI , preGUI ) ;
896
927
897
928
if ( cameraChanged ) {
0 commit comments