Update examples to use renderer.setAnimationLoop
See original GitHub issueSince renderer.setAnimationLoop
was added a few months back, we should update most of the examples to use this.
It’s cleaner, since it abstracts away the call to requestAnimationFrame
and means that a minimal loop now can be done like this:
function init() {
var scene = ...
var camera = ...
var renderer = ...
renderer.setAnimationLoop( function () {
renderer.render( scene, camera );
} );
}
init();
Instead of the current way:
var scene, camera, renderer;
function init() {
scene = ...
camera = ...
renderer = ...
}
function animate() {
requestAnimationFrame( animate );
renderer.render( scene, camera );
}
init();
animate();
If people agree, I’ll start to work on converting the examples over the next couple of weeks.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:6 (2 by maintainers)
Top Results From Across the Web
WebGLRenderer#setAnimationLoop – three.js docs
The WebGL renderer displays your beautifully crafted scenes using WebGL. Constructor. WebGLRenderer( parameters : Object ). parameters - (optional) object with ...
Read more >The Animation Loop | Discover three.js
We're using the renderer.render method to draw the scene. ... setAnimationLoop was added fairly recently, older three.js examples and tutorials often use ....
Read more >three.WebGLRenderer.render JavaScript and Node.js code ...
setAnimationLoop (() => { this.renderer.render(this.scene, this.camera); }); } ... function update() { cube.rotation.x += 0.01; cube.rotation.y += 0.01; ...
Read more >ThreeJS Stop Rendering - javascript - Stack Overflow
function animate() { renderer.render(scene, camera); controls.update(); } renderer.setAnimationLoop(animate);.
Read more >Adding a Persistence Effect to Three.js Scenes - Codrops
We will render to Framebuffer 2 and update its corresponding THREE.Texture . We will use ... here is our updated example using persistence:....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think I like this. But I prefer this pattern:
Oh yes, sorry. I meant to move the declarations outside.