Skip to content

Commit

Permalink
Examples: More usage of setAnimationLoop(). (#28236)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored Apr 29, 2024
1 parent aedb9c7 commit b8d79b8
Show file tree
Hide file tree
Showing 50 changed files with 156 additions and 355 deletions.
7 changes: 2 additions & 5 deletions examples/games_fps.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
const renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.VSMShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
Expand Down Expand Up @@ -442,9 +443,7 @@
helper.visible = value;

} );

animate();


} );

function teleportPlayerIfOob() {
Expand Down Expand Up @@ -485,8 +484,6 @@

stats.update();

requestAnimationFrame( animate );

}

</script>
Expand Down
10 changes: 1 addition & 9 deletions examples/misc_animation_groups.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
let scene, camera, renderer, mixer;

init();
animate();

function init() {

Expand Down Expand Up @@ -97,6 +96,7 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
document.body.appendChild( renderer.domElement );

//
Expand Down Expand Up @@ -125,14 +125,6 @@

function animate() {

requestAnimationFrame( animate );

render();

}

function render() {

const delta = clock.getDelta();

if ( mixer ) {
Expand Down
10 changes: 1 addition & 9 deletions examples/misc_animation_keys.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
let scene, camera, renderer, mixer;

init();
animate();

function init() {

Expand Down Expand Up @@ -97,6 +96,7 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
document.body.appendChild( renderer.domElement );

//
Expand Down Expand Up @@ -125,14 +125,6 @@

function animate() {

requestAnimationFrame( animate );

render();

}

function render() {

const delta = clock.getDelta();

if ( mixer ) {
Expand Down
11 changes: 2 additions & 9 deletions examples/misc_boxselection.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
let camera, scene, renderer;

init();
animate();

function init() {

Expand Down Expand Up @@ -106,6 +105,7 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFShadowMap;

Expand All @@ -131,19 +131,12 @@

function animate() {

requestAnimationFrame( animate );
renderer.render( scene, camera );

render();
stats.update();

}

function render() {

renderer.render( scene, camera );

}

const selectionBox = new SelectionBox( camera, scene );
const helper = new SelectionHelper( renderer, 'selectBox' );

Expand Down
4 changes: 1 addition & 3 deletions examples/misc_controls_fly.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
const clock = new THREE.Clock();

init();
animate();

function init() {

Expand Down Expand Up @@ -201,6 +200,7 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
renderer.setAnimationLoop( animate );
document.body.appendChild( renderer.domElement );

//
Expand Down Expand Up @@ -249,8 +249,6 @@

function animate() {

requestAnimationFrame( animate );

render();
stats.update();

Expand Down
6 changes: 2 additions & 4 deletions examples/misc_controls_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
let camera, controls, scene, renderer;

init();
//render(); // remove when using next line for animation loop (requestAnimationFrame)
animate();
//render(); // remove when using animation loop

function init() {

Expand All @@ -54,6 +53,7 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
document.body.appendChild( renderer.domElement );

camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
Expand Down Expand Up @@ -131,8 +131,6 @@

function animate() {

requestAnimationFrame( animate );

controls.update(); // only required if controls.enableDamping = true, or if controls.autoRotate = true

render();
Expand Down
6 changes: 2 additions & 4 deletions examples/misc_controls_orbit.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
let camera, controls, scene, renderer;

init();
//render(); // remove when using next line for animation loop (requestAnimationFrame)
animate();
//render(); // remove when using animation loop

function init() {

Expand All @@ -52,6 +51,7 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
document.body.appendChild( renderer.domElement );

camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
Expand Down Expand Up @@ -121,8 +121,6 @@

function animate() {

requestAnimationFrame( animate );

controls.update(); // only required if controls.enableDamping = true, or if controls.autoRotate = true

render();
Expand Down
4 changes: 1 addition & 3 deletions examples/misc_controls_pointerlock.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
const color = new THREE.Color();

init();
animate();

function init() {

Expand Down Expand Up @@ -260,6 +259,7 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
document.body.appendChild( renderer.domElement );

//
Expand All @@ -279,8 +279,6 @@

function animate() {

requestAnimationFrame( animate );

const time = performance.now();

if ( controls.isLocked === true ) {
Expand Down
8 changes: 3 additions & 5 deletions examples/misc_controls_trackball.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
const frustumSize = 400;

init();
animate();

function init() {

Expand Down Expand Up @@ -100,6 +99,7 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
document.body.appendChild( renderer.domElement );

stats = new Stats();
Expand Down Expand Up @@ -157,14 +157,12 @@

function animate() {

requestAnimationFrame( animate );

controls.update();

stats.update();

render();

stats.update();

}

function render() {
Expand Down
3 changes: 1 addition & 2 deletions examples/misc_exporter_draco.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
};

init();
animate();

function init() {

Expand Down Expand Up @@ -91,6 +90,7 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
renderer.shadowMap.enabled = true;
document.body.appendChild( renderer.domElement );

Expand Down Expand Up @@ -123,7 +123,6 @@

function animate() {

requestAnimationFrame( animate );
renderer.render( scene, camera );

}
Expand Down
3 changes: 1 addition & 2 deletions examples/misc_exporter_exr.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
};

init();
animate();

function init() {

renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
document.body.appendChild( renderer.domElement );

//
Expand Down Expand Up @@ -109,7 +109,6 @@

function animate() {

requestAnimationFrame( animate );
controls.update();
renderer.render( scene, camera );

Expand Down
12 changes: 3 additions & 9 deletions examples/misc_exporter_gltf.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
};

init();
animate();

function init() {

Expand Down Expand Up @@ -464,6 +463,7 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1;

Expand Down Expand Up @@ -572,14 +572,6 @@

function animate() {

requestAnimationFrame( animate );

render();

}

function render() {

const timer = Date.now() * 0.0001;

camera.position.x = Math.cos( timer ) * 800;
Expand All @@ -590,6 +582,8 @@

}



</script>

</body>
Expand Down
6 changes: 2 additions & 4 deletions examples/misc_exporter_obj.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
};

init();
animate();

function init() {

renderer = new THREE.WebGLRenderer();
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
document.body.appendChild( renderer.domElement );

camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
Expand Down Expand Up @@ -240,8 +240,6 @@

function animate() {

requestAnimationFrame( animate );

renderer.render( scene, camera );

}
Expand Down
3 changes: 1 addition & 2 deletions examples/misc_exporter_ply.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
};

init();
animate();

function init() {

Expand Down Expand Up @@ -103,6 +102,7 @@
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
renderer.shadowMap.enabled = true;
document.body.appendChild( renderer.domElement );

Expand Down Expand Up @@ -136,7 +136,6 @@

function animate() {

requestAnimationFrame( animate );
renderer.render( scene, camera );

}
Expand Down
Loading

0 comments on commit b8d79b8

Please sign in to comment.