|
@@ -43,25 +43,26 @@
|
|
|
|
|
|
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
|
|
|
|
|
|
+ let camera, scene, renderer, stats, mixer, clock, controls;
|
|
|
+
|
|
|
init();
|
|
|
|
|
|
function init() {
|
|
|
|
|
|
- let mixer;
|
|
|
-
|
|
|
- const clock = new THREE.Clock();
|
|
|
+ clock = new THREE.Clock();
|
|
|
|
|
|
const container = document.createElement( 'div' );
|
|
|
document.body.appendChild( container );
|
|
|
|
|
|
- const camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 20 );
|
|
|
+ camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 20 );
|
|
|
camera.position.set( - 1.8, 0.8, 3 );
|
|
|
|
|
|
- const scene = new THREE.Scene();
|
|
|
+ scene = new THREE.Scene();
|
|
|
|
|
|
- const renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
|
+ renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
|
renderer.setPixelRatio( window.devicePixelRatio );
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
+ renderer.setAnimationLoop( animate );
|
|
|
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
|
|
|
|
|
container.appendChild( renderer.domElement );
|
|
@@ -107,7 +108,7 @@
|
|
|
scene.background = new THREE.Color( 0x666666 );
|
|
|
scene.environment = pmremGenerator.fromScene( environment ).texture;
|
|
|
|
|
|
- const controls = new OrbitControls( camera, renderer.domElement );
|
|
|
+ controls = new OrbitControls( camera, renderer.domElement );
|
|
|
controls.enableDamping = true;
|
|
|
controls.minDistance = 2.5;
|
|
|
controls.maxDistance = 5;
|
|
@@ -116,37 +117,40 @@
|
|
|
controls.maxPolarAngle = Math.PI / 1.8;
|
|
|
controls.target.set( 0, 0.15, - 0.2 );
|
|
|
|
|
|
- const stats = new Stats();
|
|
|
+ stats = new Stats();
|
|
|
container.appendChild( stats.dom );
|
|
|
|
|
|
- renderer.setAnimationLoop( () => {
|
|
|
+ window.addEventListener( 'resize', onWindowResize );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- const delta = clock.getDelta();
|
|
|
+ function onWindowResize() {
|
|
|
|
|
|
- if ( mixer ) {
|
|
|
+ camera.aspect = window.innerWidth / window.innerHeight;
|
|
|
+ camera.updateProjectionMatrix();
|
|
|
|
|
|
- mixer.update( delta );
|
|
|
+ renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- renderer.render( scene, camera );
|
|
|
+ function animate() {
|
|
|
|
|
|
- controls.update();
|
|
|
+ const delta = clock.getDelta();
|
|
|
|
|
|
- stats.update();
|
|
|
+ if ( mixer ) {
|
|
|
|
|
|
- } );
|
|
|
+ mixer.update( delta );
|
|
|
|
|
|
- window.addEventListener( 'resize', () => {
|
|
|
+ }
|
|
|
|
|
|
- camera.aspect = window.innerWidth / window.innerHeight;
|
|
|
- camera.updateProjectionMatrix();
|
|
|
+ renderer.render( scene, camera );
|
|
|
|
|
|
- renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
+ controls.update();
|
|
|
|
|
|
- } );
|
|
|
+ stats.update();
|
|
|
|
|
|
}
|
|
|
+
|
|
|
</script>
|
|
|
</body>
|
|
|
</html>
|