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

Method initialize

14-tween-js/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 = 36;
37 this.camera.position.y = 12;
38
39 // NOTE: Specify a canvas which is already created in the HTML.
40 const canvas = document.getElementById(this.canvasId);
41 this.renderer = new THREE.WebGLRenderer({
42 canvas,
43 // NOTE: Anti-aliasing smooths out the edges.
44 antialias: true,
45 });
46 this.renderer.setSize(window.innerWidth, window.innerHeight);
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 // ambient light which is for the whole scene
56 this.ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
57 this.ambientLight.castShadow = true;
58 this.scene.add(this.ambientLight);
59
60 // directional light - parallel sun rays
61 this.directionalLight = new THREE.DirectionalLight(0xffffff, 1);
62 // this.directionalLight.castShadow = true;
63 this.directionalLight.position.set(0, 32, 64);
64 this.scene.add(this.directionalLight);
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