MCPcopy Create free account
hub / github.com/SuboptimalEng/three-js-tutorials / initialize

Method initialize

05-lighting/src/lib/SceneInit.js:28–79  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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 = 16;
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 // enable this for shadows
47 this.renderer.shadowMap.enabled = true;
48 document.body.appendChild(this.renderer.domElement);
49
50 this.clock = new THREE.Clock();
51 this.controls = new OrbitControls(this.camera, this.renderer.domElement);
52 this.stats = Stats();
53 document.body.appendChild(this.stats.dom);
54
55 // HIDE LIGHTING FOR DEMO.
56 // ambient light which is for the whole scene
57 // this.ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
58 // this.ambientLight.castShadow = true;
59 // this.scene.add(this.ambientLight);
60 // spot light which is illuminating the chart directly
61 // this.spotLight = new THREE.SpotLight(0xffffff, 1);
62 // this.spotLight.castShadow = true;
63 // this.spotLight.position.set(0, 64, 32);
64 // this.scene.add(this.spotLight);
65
66 // if window resizes
67 window.addEventListener('resize', () => this.onWindowResize(), false);
68
69 // NOTE: Load space background.
70 // this.loader = new THREE.TextureLoader();
71 // this.scene.background = this.loader.load('./pics/space.jpeg');
72
73 // NOTE: Declare uniforms to pass into glsl shaders.
74 // this.uniforms = {
75 // u_time: { type: 'f', value: 1.0 },
76 // colorB: { type: 'vec3', value: new THREE.Color(0xfff000) },
77 // colorA: { type: 'vec3', value: new THREE.Color(0xffffff) },
78 // };
79 }
80
81 animate() {
82 // NOTE: Window is implied.

Callers 1

AppFunction · 0.95

Calls 1

onWindowResizeMethod · 0.95

Tested by

no test coverage detected