| 3 | import Stats from 'three/examples/jsm/libs/stats.module'; |
| 4 | |
| 5 | export default class SceneInit { |
| 6 | constructor(canvasId) { |
| 7 | // NOTE: Core components to initialize Three.js app. |
| 8 | this.scene = undefined; |
| 9 | this.camera = undefined; |
| 10 | this.renderer = undefined; |
| 11 | |
| 12 | // NOTE: Camera params; |
| 13 | this.fov = 45; |
| 14 | this.nearPlane = 1; |
| 15 | this.farPlane = 1000; |
| 16 | this.canvasId = canvasId; |
| 17 | |
| 18 | // NOTE: Additional components. |
| 19 | this.clock = undefined; |
| 20 | this.stats = undefined; |
| 21 | this.controls = undefined; |
| 22 | |
| 23 | // NOTE: Lighting is basically required. |
| 24 | this.spotLight = undefined; |
| 25 | this.ambientLight = undefined; |
| 26 | } |
| 27 | |
| 28 | initialize() { |
| 29 | this.scene = new THREE.Scene(); |
| 30 | this.camera = new THREE.PerspectiveCamera( |
| 31 | this.fov, |
| 32 | window.innerWidth / window.innerHeight, |
| 33 | 1, |
| 34 | 1000 |
| 35 | ); |
| 36 | this.camera.position.z = 4; |
| 37 | |
| 38 | // NOTE: Specify a canvas which is already created in the HTML. |
| 39 | const canvas = document.getElementById(this.canvasId); |
| 40 | this.renderer = new THREE.WebGLRenderer({ |
| 41 | canvas, |
| 42 | // NOTE: Anti-aliasing smooths out the edges. |
| 43 | antialias: true, |
| 44 | }); |
| 45 | this.renderer.setSize(window.innerWidth, window.innerHeight); |
| 46 | document.body.appendChild(this.renderer.domElement); |
| 47 | |
| 48 | this.clock = new THREE.Clock(); |
| 49 | this.controls = new OrbitControls(this.camera, this.renderer.domElement); |
| 50 | this.stats = Stats(); |
| 51 | document.body.appendChild(this.stats.dom); |
| 52 | |
| 53 | // ambient light which is for the whole scene |
| 54 | this.ambientLight = new THREE.AmbientLight(0xffffff, 0.5); |
| 55 | this.ambientLight.castShadow = true; |
| 56 | this.scene.add(this.ambientLight); |
| 57 | |
| 58 | // spot light which is illuminating the chart directly |
| 59 | this.spotLight = new THREE.SpotLight(0xffffff, 1); |
| 60 | this.spotLight.castShadow = true; |
| 61 | this.spotLight.position.set(0, 64, 32); |
| 62 | this.scene.add(this.spotLight); |
nothing calls this directly
no outgoing calls
no test coverage detected