Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics Fundamentals / 05-Practice-31.10.2022 / 06.js
diff options
context:
space:
mode:
Commit185f5c35d163bd4a334ed4b2eee1bcb4f7882f67 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-11-03 12:21:27 +0200
Committer
 Syndamia <kamen@syndamia.com>
2022-11-03 12:21:27 +0200
Filesd5b95fcdbba09092d72a3e8cd5d2e0c159ce24e5 /Year 2/Computer Graphics Fundamentals/05-Practice-31.10.2022/06.js
uni-projects-185f5c35d163bd4a334ed4b2eee1bcb4f7882f67.tar
uni-projects-185f5c35d163bd4a334ed4b2eee1bcb4f7882f67.tar.gz
uni-projects-185f5c35d163bd4a334ed4b2eee1bcb4f7882f67.zip
Parent6c27855a224d23e66be717518280b1cb4fab1514 (diff)
[OKG/P05] Finished Ex 04 and did exercises 05 and 06
1 files changed, 85 insertions, 0 deletions
-rw-r--r--Year 2/Computer Graphics Fundamentals/05-Practice-31.10.2022/06.js85
diff --git a/Year 2/Computer Graphics Fundamentals/05-Practice-31.10.2022/06.js b/Year 2/Computer Graphics Fundamentals/05-Practice-31.10.2022/06.js
new file mode 100644
index 0000000..9bbbcb0
--- /dev/null
+++ b/Year 2/Computer Graphics Fundamentals/05-Practice-31.10.2022/06.js
@@ -0,0 +1,85 @@
+// Задача: конструирайте ... мистериозния обект
+// с трите различни профила
+
+var renderer = new THREE.WebGLRenderer();
+renderer.setSize( window.innerWidth, window.innerHeight );
+renderer.setAnimationLoop( drawFrame );
+document.body.appendChild( renderer.domElement );
+
+var scene = new THREE.Scene();
+scene.background = new THREE.Color( 'lightgray' );
+
+var aspect = window.innerWidth/window.innerHeight;
+camera = new THREE.PerspectiveCamera( 30, aspect );
+camera.position.set( 0, 0, 60 );
+camera.lookAt( new THREE.Vector3( 0, -2, 0 ) );
+
+
+// цилиндър
+var material = new THREE.MeshPhongMaterial({
+ color: 'dimgray',
+ shininess: 100,
+ specular: 'dimgray' });
+
+var cylinder = new THREE.Mesh(new THREE.CylinderGeometry( 10, 10, 15, 160 ), material);
+
+var hole = new THREE.Mesh(new THREE.CylinderGeometry(6, 6, 15, 160));
+
+var frontRec1 = new THREE.Mesh(new THREE.BoxGeometry(20, 5, 20));
+frontRec1.position.y = 5;
+frontRec1.position.z = 4;
+var frontRec2 = new THREE.Mesh(new THREE.BoxGeometry(5, 5, 20));
+frontRec2.position.y = 5;
+frontRec2.position.x = 6;
+var frontRec3 = new THREE.Mesh(new THREE.BoxGeometry(5, 5, 20));
+frontRec3.position.y = 5;
+frontRec3.position.x = -6;
+
+var backRec1 = new THREE.Mesh(new THREE.BoxGeometry(20, 5, 20));
+backRec1.position.y = -5;
+backRec1.position.z = -4;
+var backRec2 = new THREE.Mesh(new THREE.BoxGeometry(5, 5, 20));
+backRec2.position.y = -5;
+backRec2.position.x = 6;
+var backRec3 = new THREE.Mesh(new THREE.BoxGeometry(5, 5, 20));
+backRec3.position.y = -5;
+backRec3.position.x = -6;
+
+var csg = new CSG();
+csg.subtract([cylinder, hole, frontRec1, frontRec2, frontRec3, backRec1, backRec2, backRec3]);
+
+var mystery = csg.toMesh();
+mystery.material = material;
+
+scene.add( mystery );
+
+
+// светлини
+light1 = new THREE.PointLight( 'white', 0.5 );
+light1.position.set( 0, 100, 50 );
+scene.add( light1 );
+
+light2 = new THREE.PointLight(' white', 0.5 );
+light2.position.set( 0, 0, 0 );
+scene.add( light2 );
+
+light3 = new THREE.PointLight( 'white', 0.5);
+light3.position.set( 0, -100, 50 );
+scene.add( light3 );
+
+light4 = new THREE.PointLight(' white', 0.5 );
+light4.position.set( 0, 0, 100 );
+scene.add( light4 );
+// стига толкова светлини
+
+
+function drawFrame()
+{
+ // въртим мистериозния обект
+ mystery.rotation.x += 0.005;
+ mystery.rotation.y += 0.004;
+ mystery.rotation.z += 0.003;
+
+ renderer.render( scene, camera );
+}
+