From 1351a0c5a3880d1f6f015151d4deec017240787c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 15 Nov 2022 11:26:57 +0200 Subject: [OKG/HWK1] Added swivel chair --- .../Homework 1/moidom-6.html | 100 ++++++++++++++++++--- 1 file changed, 86 insertions(+), 14 deletions(-) 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 ee6a2fa..33ff729 100644 --- a/Year 2/Computer Graphics Fundamentals/Homework 1/moidom-6.html +++ b/Year 2/Computer Graphics Fundamentals/Homework 1/moidom-6.html @@ -27,17 +27,16 @@ var groups = []; function hNewGroup(meshes, position) { var group = new THREE.Group(); - meshes.forEach((mesh) => group.add(mesh)); + meshes.forEach((mesh) => { group.add(mesh); enableShadows(mesh); }); group.position.set(...position); groups.push(group); return group; } - function shadowSettings(mesh) { - const status = true; - - mesh.receiveShadow = status; - mesh.castShadow = status; + function enableShadows(mesh) { + mesh.receiveShadow = true; + mesh.castShadow = true; + mesh.children.forEach((child) => enableShadows(child)); } /* @@ -90,7 +89,6 @@ 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); - shadowSettings(wall); return wall; } @@ -120,7 +118,7 @@ var table = tableCSG.toMesh(); if (position !== undefined) table.position.set(...position); - shadowSettings(table); + return table; } @@ -145,18 +143,17 @@ var teleTube = new THREE.Mesh(new THREE.CylinderGeometry(scopeEyeWidth, scopeEndWidth, scopeLength), new THREE.MeshPhongMaterial({ color: scopeColor })); - shadowSettings(teleTube); var legRing = new THREE.Mesh(new THREE.TorusGeometry((scopeEyeWidth + scopeEndWidth) / 2 + legRingRadius / 2, legRingRadius, 16, scopeSegments), new THREE.MeshPhongMaterial({ color: legColor })); - shadowSettings(legRing); + legRing.rotation.x = Math.PI / 2; legRing.position.y = -legWidth * 1.5; var lens = new THREE.Mesh(new THREE.SphereGeometry(scopeEndWidth * 1.4, scopeSegments, 16, 0, 2 * Math.PI, 3/4 * Math.PI, 1/4 * Math.PI), new THREE.MeshPhongMaterial({ color: lensColor, shininess: 100 })); lens.position.y = -scopeLength / 2 + scopeEyeWidth * 2.3; - shadowSettings(lens); + var viewExtension = new THREE.Mesh(new THREE.CylinderGeometry(scopeEyeWidth * 0.7, scopeEyeWidth * 1.4, viewExtensionLength), new THREE.MeshPhongMaterial({ color: viewExtensionColor })); @@ -167,11 +164,9 @@ teleBody.add(teleTube, legRing, lens, viewExtension); teleBody.position.y = scopeHeight + (scopeEyeWidth + scopeEndWidth) / 2; teleBody.rotation.x = scopeAngle; - shadowSettings(teleBody); var teleLeg = new THREE.Mesh(new THREE.CylinderGeometry(legWidth, legWidth, scopeHeight / Math.sin(legAngle), scopeSegments), new THREE.MeshPhongMaterial({ color: legColor })); - shadowSettings(teleLeg); var telescope = new THREE.Group(); telescope.add(teleBody); @@ -193,6 +188,83 @@ return telescope; } + function swivelChair(rotation, position) { + const seatColor = 0x585058; + const seatWidth = 0.70; + const seatDepth = 0.50; + const seatThickness = 0.10; + const backrestHeight = 0.80; + const backrestAngle = 1/5 * Math.PI / 2; + const armrestHeight = 0.30; + const armrestAngle = 1/10 * Math.PI / 2; + const baseColor = 0xD1DBDD; + const basePointsCount = 10; + const baseRadius = 0.25; + const baseHeight = 0.4; + const baseTubeWidth = 0.05; + + var seat = new THREE.Group(); + + var leatherMaterial = new THREE.MeshPhongMaterial({ color: seatColor }); + var bottomPillow = new THREE.Mesh(new THREE.BoxGeometry(seatWidth, seatThickness, seatDepth), leatherMaterial); + bottomPillow.position.y = baseHeight; + + var backrest = new THREE.Group(); + var backrestBody = new THREE.Mesh(new THREE.BoxGeometry(seatWidth, backrestHeight, seatThickness), leatherMaterial); + var backrestRound = new THREE.Mesh(new THREE.CylinderGeometry(seatThickness / 2, seatThickness / 2, seatWidth), leatherMaterial); + backrestRound.rotation.z = Math.PI / 2; + backrestRound.position.y = backrestHeight / 2; + backrest.add(backrestBody, backrestRound.clone()); + backrestRound.position.y = -backrestHeight / 2; + backrest.add(backrestRound.clone()); + + backrest.position.y = baseHeight + backrestHeight / 2; + backrest.position.z = -seatDepth / 2 - backrestHeight / 2 / Math.tan(Math.PI / 2 - backrestAngle); + backrest.rotation.x = -backrestAngle; + + var armrest = new THREE.Group(); + var armrestBody = new THREE.Mesh(new THREE.BoxGeometry(seatThickness, armrestHeight, seatDepth), leatherMaterial); + var armrestVertRound = new THREE.Mesh(new THREE.CylinderGeometry(seatThickness / 2, seatThickness / 2, seatDepth), leatherMaterial); + armrestVertRound.rotation.x = Math.PI / 2; + var armrestHorRound = new THREE.Mesh(new THREE.CylinderGeometry(seatThickness / 2, seatThickness / 2, armrestHeight), leatherMaterial); + armrestHorRound.position.z = -seatDepth / 2; + var armrestRoundCaps = new THREE.Mesh(new THREE.SphereGeometry(seatThickness / 2 * 0.99, 8, 8), leatherMaterial); + armrestRoundCaps.position.z = -seatDepth / 2; + + armrestVertRound.position.y = armrestHeight / 2; + armrestRoundCaps.position.y = armrestHeight / 2; + armrest.add(armrestBody, armrestHorRound, armrestVertRound.clone(), armrestRoundCaps.clone()); + armrestVertRound.position.y = -armrestHeight / 2; + armrestRoundCaps.position.y = -armrestHeight / 2; + armrest.add(armrestVertRound.clone(), armrestRoundCaps.clone()); + + armrest.position.y = baseHeight + armrestHeight / 2; + + seat.add(bottomPillow, backrest); + armrest.position.x = -seatWidth / 2; + armrest.rotation.z = armrestAngle; + seat.add(armrest.clone()); + armrest.position.x = seatWidth / 2; + armrest.rotation.z = -armrestAngle; + seat.add(armrest.clone()); + + var basePoints = []; + for (var x = 0; x < baseRadius; x += baseRadius / basePointsCount) { + basePoints.push(new THREE.Vector2(-baseRadius + x - baseTubeWidth, Math.exp(x / baseRadius * 5 - 5 + 2) * baseHeight / 7.3)); + } + var base = new THREE.Mesh(new THREE.LatheGeometry(basePoints), + new THREE.MeshPhongMaterial({ color: baseColor })); + + var swivelChair = new THREE.Group(); + swivelChair.add(seat, base); + + swivelChair.rotation.y = rotation * Math.PI / 2; + if (position !== undefined) + swivelChair.position.set(...position); + console.log(swivelChair); + return swivelChair; + } + /* * Сцена */ @@ -251,7 +323,7 @@ /* Стаи */ var livingRoom = hNewGroup([ - table(1, 1.5, 1, [-3.3,0,1.5]), miniTelescope(1, [-3.0,1.25,1.5]), + table(1, 1.5, 1, [-3.3,0,1.5]), miniTelescope(1, [-3.0,1.25,1.5]), swivelChair(-0.2, [1, 0, -2]), ], [-2,0,4]); -- cgit v1.3.1-26-gb76a