Created
September 21, 2015 20:01
-
-
Save mflux/19e5a09fedcb3b43b150 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
}); | |
}); |
// 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!
Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Jquery dependency could be left out as well.
This version assumes orbitControls exists as well, and would save its target.