Skip to content

Commit

Permalink
Examples: Enhance env maps demo. (#27787)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Feb 21, 2024
1 parent 88f5aaa commit bbe78fe
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions examples/webgl_materials_envmaps.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

let controls, camera, scene, renderer;
let textureEquirec, textureCube;
let sphereMesh, sphereMaterial;
let sphereMesh, sphereMaterial, params;

init();
animate();
Expand Down Expand Up @@ -84,7 +84,7 @@

//

const params = {
params = {
Cube: function () {

scene.background = textureCube;
Expand All @@ -101,10 +101,14 @@
sphereMaterial.needsUpdate = true;

},
Refraction: false
Refraction: false,
backgroundRotationX: false,
backgroundRotationY: false,
backgroundRotationZ: false,
syncMaterial: false
};

const gui = new GUI();
const gui = new GUI( { width: 300 } );
gui.add( params, 'Cube' );
gui.add( params, 'Equirectangular' );
gui.add( params, 'Refraction' ).onChange( function ( value ) {
Expand All @@ -124,6 +128,10 @@
sphereMaterial.needsUpdate = true;

} );
gui.add( params, 'backgroundRotationX' );
gui.add( params, 'backgroundRotationY' );
gui.add( params, 'backgroundRotationZ' );
gui.add( params, 'syncMaterial' );
gui.open();

window.addEventListener( 'resize', onWindowResize );
Expand Down Expand Up @@ -151,6 +159,30 @@

function render() {

if ( params.backgroundRotationX ) {

scene.backgroundRotation.x += 0.001;

}

if ( params.backgroundRotationY ) {

scene.backgroundRotation.y += 0.001;

}

if ( params.backgroundRotationZ ) {

scene.backgroundRotation.z += 0.001;

}

if ( params.syncMaterial ) {

sphereMesh.material.envMapRotation.copy( scene.backgroundRotation );

}

camera.lookAt( scene.position );
renderer.render( scene, camera );

Expand All @@ -159,4 +191,4 @@
</script>

</body>
</html>
</html>

0 comments on commit bbe78fe

Please sign in to comment.