I'm building a series of web apps inside an Angular SPA. Each of these applications sit inside an Angular template, and navigation between them strips and replaces appropriate DOM elements and run scripts from controllers.
My question here is more of a general one: upon navigating away from a Three.js scene and navigating back, obviously the DOM elements and scripts themselves are re-run, resulting in the scene starting from "scratch". Is there a way to keep the scene running in the background, so that the user can navigate back to an app and have it be just where they left off?
Is this even advisable? I'm aware that the requestAnimationFrame method stops animating when a user navigates to another tab, but how does this work in an Angular context?
As an example, here's the WIP web page. Try navigating away from the StarFinder tab and then back, and you'll see what I mean.
EDIT: Here's a JSFiddle to demonstrate what I mean (in this case it modifies the DOM without Angular).
Really, the bit in question is the renderer, which gets re-initiated upon navigating back:
function render() {
requestAnimationFrame(render);
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render(scene, camera);
}
render();