Skip to content

Instantly share code, notes, and snippets.

@mflux
Created September 21, 2015 20:01
Show Gist options
  • Select an option

  • Save mflux/19e5a09fedcb3b43b150 to your computer and use it in GitHub Desktop.

Select an option

Save mflux/19e5a09fedcb3b43b150 to your computer and use it in GitHub Desktop.
// save camera views
const savedCamera = JSON.parse( localStorage.getItem( 'savedCamera' ) );
if( savedCamera ){
camera.position.copy( savedCamera.cameraPosition );
orbitControls.target.copy( savedCamera.targetPosition );
}
$(window).unload( function(){
localStorage.savedCamera = JSON.stringify({
cameraPosition: camera.position,
targetPosition: orbitControls.target
});
});
@mflux
Copy link
Copy Markdown
Author

mflux commented Sep 21, 2015

Jquery dependency could be left out as well.

This version assumes orbitControls exists as well, and would save its target.

@spite
Copy link
Copy Markdown

spite commented Sep 21, 2015

//  save camera views
const savedCamera = JSON.parse( localStorage.getItem( 'savedCamera' ) );
if( savedCamera ){
    camera.position.copy( savedCamera.cameraPosition );
    controls.target.copy( savedCamera.targetPosition );
}

window.addEventListener( 'unload', function(){
    localStorage.savedCamera = JSON.stringify({
        cameraPosition: camera.position,
        targetPosition: controls.target
    });
});

Depending on who, the controls are called controls.
And removed the jQuery dependency.

Very useful!

@joldibaev
Copy link
Copy Markdown

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment