|
1 |
| -import * as THREE from 'three'; |
| 1 | +import * as THREE from 'three' |
2 | 2 | import { OrbitControls } from 'three/addons/controls/OrbitControls.js'
|
3 | 3 | import Stats from 'three/addons/libs/stats.module.js'
|
4 | 4 |
|
5 | 5 | import { Stencil } from './scenes/stencil'
|
6 | 6 | import { StencilBLue } from './scenes/stencil-blue'
|
7 | 7 |
|
8 |
| -let scene, renderer, stats, controls; |
9 |
| - |
10 |
| -init(); |
11 |
| -animate(); |
12 |
| - |
13 |
| -function init() { |
14 |
| - |
15 |
| - scene = new Stencil(); |
16 |
| - |
17 |
| - // Stats |
18 |
| - stats = new Stats(); |
19 |
| - document.body.appendChild( stats.dom ); |
20 |
| - |
21 |
| - // Renderer |
22 |
| - renderer = new THREE.WebGLRenderer( { antialias: true } ); |
23 |
| - renderer.shadowMap.enabled = true; |
24 |
| - renderer.setPixelRatio( window.devicePixelRatio ); |
25 |
| - renderer.setSize( window.innerWidth, window.innerHeight ); |
26 |
| - renderer.setClearColor( 0x263238 ); |
27 |
| - |
28 |
| - window.addEventListener( 'resize', onWindowResize ); |
29 |
| - document.body.appendChild( renderer.domElement ); |
30 |
| - |
31 |
| - renderer.localClippingEnabled = true; |
32 |
| - |
33 |
| - setTimeout(() => { |
34 |
| - scene = new StencilBLue(); |
35 |
| - const controls = new OrbitControls( scene.getCamera, renderer.domElement ); |
36 |
| - controls.minDistance = 2; |
37 |
| - controls.maxDistance = 20; |
38 |
| - controls.enabled = false; |
39 |
| - controls.update(); |
40 |
| - }, 5000); |
41 |
| - |
42 |
| - // Controls |
43 |
| - const controls = new OrbitControls( scene.getCamera, renderer.domElement ); |
44 |
| - controls.minDistance = 2; |
45 |
| - controls.maxDistance = 20; |
46 |
| - controls.enabled = false; |
47 |
| - controls.update(); |
48 |
| - |
| 8 | +let scene, renderer, stats |
| 9 | + |
| 10 | +init() |
| 11 | +animate() |
| 12 | + |
| 13 | +function init () { |
| 14 | + scene = new Stencil() |
| 15 | + |
| 16 | + // Stats |
| 17 | + stats = new Stats() |
| 18 | + document.body.appendChild(stats.dom) |
| 19 | + |
| 20 | + // Renderer |
| 21 | + renderer = new THREE.WebGLRenderer({ antialias: true }) |
| 22 | + renderer.shadowMap.enabled = true |
| 23 | + renderer.setPixelRatio(window.devicePixelRatio) |
| 24 | + renderer.setSize(window.innerWidth, window.innerHeight) |
| 25 | + renderer.setClearColor(0x263238) |
| 26 | + |
| 27 | + window.addEventListener('resize', onWindowResize) |
| 28 | + document.body.appendChild(renderer.domElement) |
| 29 | + |
| 30 | + renderer.localClippingEnabled = true |
| 31 | + |
| 32 | + setTimeout(() => { |
| 33 | + scene = new StencilBLue() |
| 34 | + const controls = new OrbitControls(scene.getCamera, renderer.domElement) |
| 35 | + controls.minDistance = 2 |
| 36 | + controls.maxDistance = 20 |
| 37 | + controls.enabled = false |
| 38 | + controls.update() |
| 39 | + }, 5000) |
| 40 | + |
| 41 | + // Controls |
| 42 | + const controls = new OrbitControls(scene.getCamera, renderer.domElement) |
| 43 | + controls.minDistance = 2 |
| 44 | + controls.maxDistance = 20 |
| 45 | + controls.enabled = false |
| 46 | + controls.update() |
49 | 47 | }
|
50 | 48 |
|
51 |
| -function onWindowResize() { |
52 |
| - |
53 |
| - scene.getCamera.aspect = window.innerWidth / window.innerHeight; |
54 |
| - scene.getCamera.updateProjectionMatrix(); |
55 |
| - |
56 |
| - renderer.setSize( window.innerWidth, window.innerHeight ); |
| 49 | +function onWindowResize () { |
| 50 | + scene.getCamera.aspect = window.innerWidth / window.innerHeight |
| 51 | + scene.getCamera.updateProjectionMatrix() |
57 | 52 |
|
| 53 | + renderer.setSize(window.innerWidth, window.innerHeight) |
58 | 54 | }
|
59 | 55 |
|
60 |
| -function animate() { |
61 |
| - |
62 |
| - requestAnimationFrame( animate ); |
63 |
| - |
64 |
| - scene.animate() |
| 56 | +function animate () { |
| 57 | + window.requestAnimationFrame(animate) |
65 | 58 |
|
66 |
| - stats.begin(); |
67 |
| - renderer.render( scene.getScene, scene.getCamera ); |
68 |
| - stats.end(); |
| 59 | + scene.animate() |
69 | 60 |
|
| 61 | + stats.begin() |
| 62 | + renderer.render(scene.getScene, scene.getCamera) |
| 63 | + stats.end() |
70 | 64 | }
|
0 commit comments