Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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

This comment has been minimized.

Copy link
Owner Author

@mflux 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

This comment has been minimized.

Copy link

@spite 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

This comment has been minimized.

Copy link

@joldibaev joldibaev commented Mar 23, 2021

Thank you!

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