@@ -280,6 +280,9 @@ export class WebGLPreview {
280280 this . resize ( ) ;
281281
282282 this . controls = new OrbitControls ( this . camera , this . renderer . domElement ) ;
283+
284+ this . loadCamera ( ) ;
285+
283286 this . initScene ( ) ;
284287 this . animate ( ) ;
285288
@@ -1023,4 +1026,31 @@ export class WebGLPreview {
10231026 this . initGui ( ) ;
10241027 }
10251028 }
1029+
1030+ saveCamera ( ) {
1031+ localStorage . setItem ( 'cameraPosition' , JSON . stringify ( this . camera . position ) ) ;
1032+ localStorage . setItem ( 'cameraRotation' , JSON . stringify ( this . camera . rotation ) ) ;
1033+ localStorage . setItem ( 'cameraZoom' , JSON . stringify ( this . camera . zoom ) ) ;
1034+ localStorage . setItem ( 'cameraTarget' , JSON . stringify ( this . controls . target ) ) ;
1035+ }
1036+ loadCamera ( ) {
1037+ const position = JSON . parse ( localStorage . getItem ( 'cameraPosition' ) ) ;
1038+ const rotation = JSON . parse ( localStorage . getItem ( 'cameraRotation' ) ) ;
1039+ const zoom = JSON . parse ( localStorage . getItem ( 'cameraZoom' ) ) ;
1040+ const target = JSON . parse ( localStorage . getItem ( 'cameraTarget' ) ) ;
1041+ if ( position && rotation && zoom && target ) {
1042+ this . camera . position . x = position . x ;
1043+ this . camera . position . y = position . y ;
1044+ this . camera . position . z = position . z ;
1045+ this . camera . rotation . x = rotation . x ;
1046+ this . camera . rotation . y = rotation . y ;
1047+ this . camera . rotation . z = rotation . z ;
1048+ this . camera . zoom = zoom ;
1049+ // this.camera.updateProjectionMatrix();
1050+ this . controls . target . x = target . x ;
1051+ this . controls . target . y = target . y ;
1052+ this . controls . target . z = target . z ;
1053+ this . controls . update ( ) ;
1054+ }
1055+ }
10261056}
0 commit comments