Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit994ab130cdfc579ce04ce880ebd73bf06174070e (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-11-14 22:00:15 +0200
Committer
 Syndamia <kamen@syndamia.com>
2022-11-14 22:00:15 +0200
Files6afffaf04b5721a077b711e9713b745e64841889
uni-projects-994ab130cdfc579ce04ce880ebd73bf06174070e.tar
uni-projects-994ab130cdfc579ce04ce880ebd73bf06174070e.tar.gz
uni-projects-994ab130cdfc579ce04ce880ebd73bf06174070e.zip
Parenta56c679cbe8ebc932d1d2d5ee31ec3134e391f83 (diff)
[OKG/HWK1] Added walls and holes in them
1 files changed, 150 insertions, 1 deletions
-rw-r--r--Year 2/Computer Graphics Fundamentals/Homework 1/moidom-6.html151
diff --git a/Year 2/Computer Graphics Fundamentals/Homework 1/moidom-6.html b/Year 2/Computer Graphics Fundamentals/Homework 1/moidom-6.html
index e79da2e..2e3c08a 100644
--- a/Year 2/Computer Graphics Fundamentals/Homework 1/moidom-6.html
+++ b/Year 2/Computer Graphics Fundamentals/Homework 1/moidom-6.html
@@ -7,6 +7,7 @@
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<script src="three.min.js"></script>
<script src="OrbitControls.js"></script>
+ <script src="CSG.js"></script>
</head>
<body>
@@ -20,6 +21,154 @@
// Обекти:
// мини телескоп и въртящ се стол
+ /*
+ * Помощни
+ */
+ function hFixCoords(coordinates, objectHeight, objectWidth) {
+ coordinates[1] += objectHeight / 2 - 0.01;
+ coordinates[2] -= objectWidth / 2;
+ return coordinates;
+ }
+
+ var groups = [];
+ function hNewGroup(meshes, position) {
+ var group = new THREE.Group();
+ meshes.forEach((mesh) => group.add(mesh));
+ group.position.set(...position);
+ groups.push(group);
+ return group;
+ }
+
+ /*
+ * Дупки
+ */
+ function holePrimitive(size, position) {
+ var hole = new THREE.Mesh(new THREE.BoxGeometry(...size));
+ position[1] -= (3.10 - size[1]) / 2; // на 3.10 трябва височината на стената, ама карай
+ hole.position.set(...position);
+ return hole;
+ }
+
+ function doorHole(x, y, z) {
+ return holePrimitive([1, 2.10, 1], [x, y, z]);
+ }
+
+ function doubleDoorHole(x, y, z) {
+ return holePrimitive([2, 2.10, 1], [x, y, z]);
+ }
+
+ function windowHole(x, y, z) {
+ return holePrimitive([0.70, 1.44, 1], [x, y+1.10, z]);
+ }
+
+ function doubleWindowHole(x, y, z) {
+ return holePrimitive([1.40, 1.44, 1], [x, y+1.10, z]);
+ }
+
+ /*
+ * Обекти
+ */
+ function wall(length, rotation, holes, position) {
+ const height = 3.10;
+ const width = 0.20;
+ const color = 'darkgray';
+
+ var wall = new THREE.Mesh(new THREE.BoxGeometry(length, height, width),
+ new THREE.MeshPhongMaterial({ color: color }));
+ if (holes !== undefined && holes.length >= 0) {
+ var wallCSG = new CSG();
+ wallCSG.subtract([wall]);
+ holes.forEach((hole) => wallCSG.subtract([hole]));
+ var wall = wallCSG.toMesh();
+ }
+
+ wall.rotation.y = rotation * Math.PI / 2;
+ if (position === undefined)
+ position = [0, 0, 0];
+ wall.position.set(position[0] -Math.sin(wall.rotation.y) * width / 2,
+ position[1] +height / 2 - 0.01,
+ position[2] -Math.cos(wall.rotation.y) * width / 2);
+
+ return wall;
+ }
+
+ /*
+ * Сцена
+ */
+
+ /* Външни стени */
+ var frontDoor = hNewGroup([
+ wall(6, 0, [doorHole(1.5,0,0)]),
+ ], [5, 0, 5]);
+
+ var wall1 = hNewGroup([
+ wall(2.20, 1),
+ ], [2, 0, 5.90]);
+
+ var wall2 = hNewGroup([
+ wall(8, 0),
+ ], [-2, 0, 7]);
+
+ var wall3 = hNewGroup([
+ wall(11, -1, [doubleWindowHole(4,0,0), doubleWindowHole(1,0,0), doubleWindowHole(-3,0,0)]),
+ ], [-6, 0, 1.5]);
+
+ var wall4 = hNewGroup([
+ wall(8, 2, [doubleDoorHole(-0.5,0,0), doorHole(1,0,0)]),
+ ], [-2, 0, -4]);
+
+ var wall5 = hNewGroup([
+ wall(1.20, 1),
+ ], [2, 0, -3.4]);
+
+ var wall6 = hNewGroup([
+ wall(6, 2),
+ ], [5, 0, -3]);
+
+ var wall7 = hNewGroup([
+ wall(8, 1),
+ ], [8, 0, 1]);
+
+ /* Вътрешни стени */
+
+ var wall8 = hNewGroup([
+ wall(3, 0), wall(1.414, -0.5, [], [-2,0,-0.5]), wall(4, -1, [doorHole(0,0,0)], [-2.5,0,-3])
+ ], [6.5,0,2]);
+
+ var wall9 = hNewGroup([
+ wall(8, 0),
+ ], [-2,0,1]);
+
+ var wall10 = hNewGroup([
+ wall(8, 1, [doubleDoorHole(-2,0,0), doubleDoorHole(2,0,0)])
+ ], [2, 0, 1]);
+
+ var wall11 = hNewGroup([
+ wall(5, -1, [doorHole([1,0,0])]),
+ ], [5, 0, -0.5]);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /*
+ * Помощен код
+ */
+ groups.forEach((group) => scene.add(group));
+
var geometry = new THREE.BoxGeometry( 2, 2, 2 ),
material = new THREE.MeshPhongMaterial( {color:'crimson', shininess: 100} );
@@ -28,7 +177,7 @@
cube.receiveShadow = true;
cube.castShadow = true;
- scene.add( cube );
+ // scene.add( cube );
</script>