diff options
| Commit | da23345e78ef55871eb83b82beabe07d704f492b (patch) | |
|---|---|---|
| Author | 2022-11-15 10:05:57 +0200 | |
| Committer | 2022-11-15 10:05:57 +0200 | |
| Files | b6ce6fbc8b0765f58689796e6e542891a343826b | |
| uni-projects-da23345e78ef55871eb83b82beabe07d704f492b.tar uni-projects-da23345e78ef55871eb83b82beabe07d704f492b.tar.gz uni-projects-da23345e78ef55871eb83b82beabe07d704f492b.zip | ||
| Parent | 21122fa3f283ff000967b57fdb3bc4bd0358e241 (diff) | |
[OKG/HWK1] Added telescope
1 files changed, 60 insertions, 20 deletions
| -rw-r--r-- | Year 2/Computer Graphics Fundamentals/Homework 1/moidom-6.html | 80 |
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 0d985e3..ee6a2fa 100644 --- a/Year 2/Computer Graphics Fundamentals/Homework 1/moidom-6.html +++ b/Year 2/Computer Graphics Fundamentals/Homework 1/moidom-6.html @@ -24,12 +24,6 @@ /*
* Помощни
*/
- 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();
@@ -39,6 +33,13 @@ return group;
}
+ function shadowSettings(mesh) {
+ const status = true;
+
+ mesh.receiveShadow = status;
+ mesh.castShadow = status;
+ }
+
/*
* Дупки
*/
@@ -89,12 +90,13 @@ 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;
}
function table(width, depth, height, position) {
- const thickness = 0.25;
+ const thickness = 0.20;
const legWidth = 0.10;
const tableLip = 0.08;
const color = 0x55342b;
@@ -118,36 +120,74 @@ var table = tableCSG.toMesh();
if (position !== undefined)
table.position.set(...position);
+ shadowSettings(table);
return table;
}
- function miniTelescope(position) {
- const scopeEyeWidth = 0.10;
+ function miniTelescope(rotation, position) {
+ const scopeEyeWidth = 0.07;
const scopeEndWidth = 0.15;
const scopeLength = 1.0;
const scopeColor = 0xD1DBDD;
- const scopeHeight = 0.15;
+ const scopeHeight = 0.20;
+ const scopeSegments = 8;
+ const scopeAngle = 5/4 * Math.PI / 2;
+ const legRingRadius = 0.05;
+ const lensColor = 0x87CEEB;
+ const viewExtensionLength = 0.15;
+ const viewExtensionColor = 0x262626;
const legWidth = 0.05;
- const legAngle = 7/4 * Math.PI / 2;;
- const legColor = 'black';
+ const legAngle = 7/4 * Math.PI / 2;
+ const legSideAngle = 1/5 * Math.PI / 2;
+ const legColor = 0x262626;
+
+ var teleBody = new THREE.Group();
- var teleBody = new THREE.Mesh(new THREE.CylinderGeometry(scopeEyeWidth, scopeEndWidth, scopeLength),
+ var teleTube = new THREE.Mesh(new THREE.CylinderGeometry(scopeEyeWidth, scopeEndWidth, scopeLength),
new THREE.MeshPhongMaterial({ color: scopeColor }));
- teleBody.position.y = scopeHeight + scopeEyeWidth / 2;
- teleBody.rotation.x = 5/4 * Math.PI / 2;
+ shadowSettings(teleTube);
- var teleLeg = new THREE.Mesh(new THREE.CylinderGeometry(legWidth, legWidth, scopeHeight / Math.sin(legAngle)),
+ var legRing = new THREE.Mesh(new THREE.TorusGeometry((scopeEyeWidth + scopeEndWidth) / 2 + legRingRadius / 2, legRingRadius, 16, scopeSegments),
new THREE.MeshPhongMaterial({ color: legColor }));
- teleLeg.rotation.x = legAngle;
+ 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 }));
+ viewExtension.position.y = scopeLength / 2;
+ viewExtension.position.z = -scopeEyeWidth * 0.7;
+ viewExtension.rotation.x = -Math.PI / 4;
+
+ 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);
+
+ teleLeg.rotation.x = legAngle;
telescope.add(teleLeg.clone());
- teleLeg.rotation.y += 1/3 * 2 * Math.PI;
+ teleLeg.position.z -= scopeHeight * scopeHeight * 1/Math.tan(legAngle) * 1/Math.tan(legAngle);
+ teleLeg.position.x = legWidth * 1.5;
+ teleLeg.rotation.x = -legAngle;
+ teleLeg.rotation.z = -legSideAngle;
telescope.add(teleLeg.clone());
- teleLeg.rotation.y += 1/3 * 2 * Math.PI;
+ teleLeg.position.x = -legWidth * 1.5;
+ teleLeg.rotation.z = legSideAngle;
telescope.add(teleLeg.clone());
+ telescope.rotation.y = rotation * Math.PI / 2;
if (position !== undefined)
telescope.position.set(...position);
return telescope;
@@ -211,7 +251,7 @@ /* Стаи */
var livingRoom = hNewGroup([
- table(1, 1.5, 1, [-3.3,0,1.5]), miniTelescope([0,1,0]),
+ table(1, 1.5, 1, [-3.3,0,1.5]), miniTelescope(1, [-3.0,1.25,1.5]),
], [-2,0,4]);
|
