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

Method initialize

04-dat-gui/src/lib/SceneInit.js:28–77  ·  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 = 96;
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);
63
64 // if window resizes
65 window.addEventListener('resize', () => this.onWindowResize(), false);
66
67 // NOTE: Load space background.
68 // this.loader = new THREE.TextureLoader();
69 // this.scene.background = this.loader.load('./pics/space.jpeg');
70
71 // NOTE: Declare uniforms to pass into glsl shaders.
72 // this.uniforms = {
73 // u_time: { type: 'f', value: 1.0 },
74 // colorB: { type: 'vec3', value: new THREE.Color(0xfff000) },
75 // colorA: { type: 'vec3', value: new THREE.Color(0xffffff) },
76 // };
77 }
78
79 animate() {
80 // NOTE: Window is implied.

Callers 1

AppFunction · 0.95

Calls 1

onWindowResizeMethod · 0.95

Tested by

no test coverage detected