diff options
[OKG/HWK2] Added template and implemented Jotaro
1 files changed, 194 insertions, 0 deletions
| -rw-r--r-- | Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html | 194 |
diff --git a/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html b/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html new file mode 100644 index 0000000..3fcb3c2 --- /dev/null +++ b/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html @@ -0,0 +1,194 @@ +<!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 изборът ви на сюжет –<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.95);
+ jotaro.position.y = 35;
+ 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;
+ }
+
+ scene.add(newJotaro());
+
+ // тук си направете човечетата и статичните елементи по позите
+ // ...
+ // ...
+
+ function animate(t)
+ {
+ // в тази функция направете движението на
+ // човечетата (параметърът t е времето)
+ // ...
+ // ...
+ }
+
+ </script>
+ </body>
+</html>
|
