From 994ab130cdfc579ce04ce880ebd73bf06174070e Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 14 Nov 2022 22:00:15 +0200 Subject: [OKG/HWK1] Added walls and holes in them --- .../Homework 1/moidom-6.html | 151 ++++++++++++++++++++- 1 file changed, 150 insertions(+), 1 deletion(-) 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 @@ + @@ -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 ); -- cgit v1.3.1-23-gd82d