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

Method initialize

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

Callers 1

AppFunction · 0.95

Calls 1

onWindowResizeMethod · 0.95

Tested by

no test coverage detected