-
Notifications
You must be signed in to change notification settings - Fork 0
/
stage2.js
75 lines (55 loc) · 1.78 KB
/
stage2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
let renderer,
scene,
camera,
myCanvas = document.getElementById('myCanvas');
// RENDERER
renderer = new THREE.WebGLRenderer({canvas: myCanvas, antialias: true});
renderer.setClearColor(0x000000);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
// CAMERA
camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 0.1, 10000);
// SCENE
scene = new THREE.Scene();
// LIGHTS
let light = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(light);
let light2 = new THREE.PointLight(0xffffff, 0.5);
scene.add(light2);
let loader = new THREE.FontLoader();
let font = loader.parse(comicsansJSON);
let textString = "MEMES";
let geometry = new THREE.TextGeometry(textString, {font: font, size: 120, height: 10, bevelThickness: 1, extrudeMaterial: 1});
let material = new THREE.MeshLambertMaterial({color: 0xF3FFE2});
let mesh = new THREE.Mesh(geometry, material);
mesh.position.z = -100;
let pivot = new THREE.Group();
pivot.add(mesh);
scene.add(pivot);
camera.position.set(300, 30, 900);
let reached_far = false;
let reached_near = false;
let position = 10;
function render() {
camera.rotation.z += 0.01;
pivot.rotation.y = 19.5;
if (!reached_far && !reached_near) {
camera.position.z += 10;
} else if (reached_far && !reached_near) {
camera.position.z -= 10;
} else if (reached_far && reached_near) {
reached_far = false;
reached_near = false;
camera.position.z += 10;
}
if (camera.position.z == 3000) {
reached_far = true;
}
if (camera.position.z == 900) {
reached_near = true;
}
renderer.render(scene, camera);
requestAnimationFrame(render);
}
//RENDER LOOP
render();