Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics Fundamentals / Homework 2 / mannequin.html
blob: 1f9b9562753c7a202341a9568410573ea53a49cc (plain) (blame)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<!DOCTYPE html>

<html>
	<head>
		<script src="three.min.js"></script>
		<script src="mannequin.js"></script>
		<style>
			body {color: black; text-shadow: 0 0 4px gray; font-family: Calibri;}
			h1   {position: fixed; z-index: 10; top: 0; left: 0; text-align: center; width: 100%;}
			div  {position: fixed; z-index: 10; bottom: 1em; left: 1em; font-size: 1.5em; font-style: italic;}
		</style>
	</head>

	<body>
	
		<!-- Сложете реално заглавие -->
		<h1>Заглавие на сцената</h1>  
		
		<!-- Сложете описание на сцената (опитайте с рима) -->
		<div>
			Сложете тук един куплет,<br>
			кажете в него де що става,<br>
			a изборът ви на сюжет &ndash;<br>
			без милост да ни грабва.
		</div>
		
		<script>

			/**
			 ** Сцена
			 **/

			/*
			 * Инициализация
			 */
			var renderer = new THREE.WebGLRenderer({ antialias: true });
			renderer.setSize( window.innerWidth, window.innerHeight );
			renderer.setAnimationLoop( drawFrame );
			renderer.shadowMap.enabled = true;
			document.body.appendChild( renderer.domElement );

			var scene = new THREE.Scene();
			scene.background = new THREE.Color( 0xdcba5c );

			var aspect = window.innerWidth/window.innerHeight;
			var camera = new THREE.PerspectiveCamera( 30, aspect );
			camera.position.set( 0, 100, 100 );
			camera.lookAt( new THREE.Vector3(0, 40, 0) );

			function onWindowResize(event)
			{
				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();

				renderer.setSize(window.innerWidth, window.innerHeight, true);
			}
			window.addEventListener('resize', onWindowResize, false);
			onWindowResize();

			clock = new THREE.Clock();

			/*
			 * Земя
			 */

			const sceneSize = 800;

			var ground = new THREE.Mesh(new THREE.PlaneBufferGeometry(sceneSize, sceneSize),
			                            new THREE.MeshPhongMaterial({ color: 0x8eb5b2 }));
			ground.rotation.x = -Math.PI / 2;
			ground.receiveShadow = true;
			scene.add(ground);

			/*
			 * Осветяване
			 */
			var sun = new THREE.PointLight(0xffffff, 0.2);
			sun.position.set( 0, 100, 100 );
			sun.target = ground;
			sun.castShadow = true;
			scene.add( sun );

			var ambient = new THREE.AmbientLight(0xffffff, 0.8);
			scene.add(ambient);

			/**
			 ** Герои
			 **/

			/* Помощни функции */
			function thc(value) {
				return new THREE.Color(value);
			}

			var cube = new THREE.Mesh(new THREE.BoxGeometry(1.0, 1.0, 1.0), new THREE.MeshPhongMaterial({color: 'red'}));
			cube.position.y = 0.5;
			scene.add(cube);

			function newJotaro() {
				const coatC = thc(0xedf4eb);
				const skinC = thc(0xdcc7b4);
				const acctC = thc(0x8166be);

				Mannequin.colors = [
					skinC, // head
					acctC, // shoes
					coatC, // pelvis
					coatC, // joints
					coatC, // limbs
					coatC, // torso
				];

				var jotaro = new Male(0.975);
				jotaro.position.y = 33;
				jotaro.r_wrist.recolor(skinC, acctC);
				jotaro.l_wrist.recolor(skinC, acctC);
				jotaro.r_fingers.recolor(skinC);
				jotaro.l_fingers.recolor(skinC);
				jotaro.r_fingers.tips.recolor(skinC);
				jotaro.l_fingers.tips.recolor(skinC);

				var hat = new THREE.Group();
				hat.position.y = 6;
				hat.rotation.y = Math.PI / 2;
				jotaro.head.attach(hat);

				var shape = new THREE.Mesh(new THREE.CylinderGeometry(3.5, 3.5, 3.5, 32), new THREE.MeshPhongMaterial());
				hat.add(shape);
				
				var goldHand = new THREE.Mesh(new THREE.BoxGeometry(1.5, 2, 0.5), new THREE.MeshPhongMaterial({ color: 0xead57f }));
				const goldHandAngle = Math.PI * 4/25;
				goldHand.position.z = 3.5 * Math.cos(goldHandAngle);
				goldHand.position.x = 3.5 * Math.sin(goldHandAngle);
				goldHand.rotation.y = goldHandAngle;
				hat.add(goldHand);

				var ornament = new THREE.Group();
				var ornamentMaterial = new THREE.MeshPhongMaterial({ color: 0x17171b });
				var orCircle = new THREE.Mesh(new THREE.RingGeometry(0.2, 0.5, 32), ornamentMaterial);
				orCircle.position.y = 0.5;
				ornament.add(orCircle);
				var orVBar = new THREE.Mesh(new THREE.PlaneGeometry(0.3, 1.2), ornamentMaterial);
				orVBar.position.y = -0.5;
				ornament.add(orVBar);
				var orHBar = new THREE.Mesh(new THREE.PlaneGeometry(1, 0.3), ornamentMaterial);
				orHBar.position.y = -0.5 -0.1 + 0.5;
				ornament.add(orHBar);
				var orSBar = new THREE.Mesh(new THREE.PlaneGeometry(0.5, 0.3), ornamentMaterial);
				orSBar.position.y = -0.8;
				orSBar.rotation.z = -Math.PI / 4;
				orSBar.position.x = -0.2;
				ornament.add(orSBar.clone());
				orSBar.rotation.z = Math.PI / 4;
				orSBar.position.x = 0.2;
				ornament.add(orSBar);

				[-Math.PI / 4, -Math.PI / 8, 0].forEach((angle) => {
					ornament.position.z = 3.5 * Math.cos(angle);
					ornament.position.x = 3.5 * Math.sin(angle);
					ornament.rotation.y = angle;
					hat.add(ornament.clone());
				});


				var brimShape = new THREE.Shape();
				brimShape.moveTo(-3.45,0);
				brimShape.quadraticCurveTo(0,30, 3.45,0);
				var brim = new THREE.Mesh(new THREE.ExtrudeGeometry(brimShape, { depth: 0.2, bevelEnabled: true, bevelSize: 0.1, bevelThickness: 0.1  }),
				                          [new THREE.MeshPhongMaterial(), new THREE.MeshPhongMaterial({ color: 0xf4cb71 })]);
				brim.rotation.x = Math.PI / 2;
				brim.position.y = -1.5;
				hat.add(brim);


				return jotaro;
			}

			function newKira() {
				const suitC = thc(0xb983d7);
				const skinC = thc(0xf1e3bf);
				const shoeC = thc(0x775834);

				Mannequin.colors = [
					skinC, // head
					shoeC, // shoes
					suitC, // pelvis
					suitC, // joints
					suitC, // limbs
					suitC, // torso
				];

				var kira = new Male(0.875);
				kira.position.y = 29.5;
				kira.r_wrist.recolor(skinC);
				kira.l_wrist.recolor(skinC);
				kira.r_fingers.recolor(skinC);
				kira.l_fingers.recolor(skinC);
				kira.r_fingers.tips.recolor(skinC);
				kira.l_fingers.tips.recolor(skinC);

				var hair = new THREE.Mesh(new THREE.SphereGeometry(3.5, 6, 32, 0, Math.PI),
				                          new THREE.MeshPhongMaterial({ color: 0xd7d86f, flatShading: 1 }));
				hair.rotation.z = -Math.PI / 2;
				hair.rotation.x = -Math.PI / 2;
				hair.position.y = 3.9;
				hair.position.x = -0.4;
				kira.head.attach(hair);

				var tieShape = new THREE.Shape();
				tieShape.lineTo(-1, -1.5);
				tieShape.lineTo(0, -3);
				tieShape.lineTo(-1.1, -10);
				tieShape.lineTo(0, -12);
				tieShape.lineTo(1.1, -10);
				tieShape.lineTo(0, -3);
				tieShape.lineTo(1, -1.5);
				var tie = new THREE.Mesh(new THREE.ExtrudeGeometry(tieShape, { depth: 0.2, bevelEnabled: true, bevelSize: 0.1, bevelThickness: 0.1  }),
				                         new THREE.MeshPhongMaterial());
				tie.position.x = 3.5;
				tie.rotation.y = -Math.PI / 2;
				tie.position.y = 16;
				kira.torso.attach(tie);

				return kira;
			}

			scene.add(newJotaro());
			// scene.add(newKira());

			// тук си направете човечетата и статичните елементи по позите
			// ...
			// ...

			function animate(t)
			{
				scene.rotation.y += 0.02;
				// в тази функция направете движението на
				// човечетата (параметърът t е времето)
				// ...
				// ...
			}

		</script>
	</body>
</html>