Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics Fundamentals / 05-Practice-31.10.2022 / 06.js
blob: 9bbbcb0c3fe979ba968b221ad7aff55d211501eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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 );
}