Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics Fundamentals / 05-Practice-31.10.2022 / 02.js
blob: 2c3632c10b18d6f2a4f8d4cb16be4d9012a26b33 (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
// Задача: конструирайте златен осмоъгълен
// пепелник-сувенир за четирима. 


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( 'midnightblue' );

var aspect = window.innerWidth/window.innerHeight;
camera = new THREE.PerspectiveCamera( 30, aspect );
camera.position.set( 0, 0, 8 );
camera.lookAt( new THREE.Vector3() );

		
// Пепелник (за момента е цилиндър,
// но вие ще го оформите на пепелник)
var innerRad = 1.3;

var outsideShape = new THREE.Mesh(new THREE.CylinderGeometry( 1.6, 2, 0.8, 8 ));
var innerShape = new THREE.Mesh(new THREE.CylinderGeometry( innerRad, innerRad, 1, 8 ));
innerShape.position.y = 0.2;

var holes = new THREE.Mesh(new THREE.CylinderGeometry(0.3, 0.3, 4, 32));
holes.rotation.x = Math.PI / 2;
holes.rotation.z = Math.PI / 8;
holes.position.y = 0.5;

var holes2 = new THREE.Mesh(new THREE.CylinderGeometry(0.3, 0.3, 4, 32));
holes2.rotation.x = Math.PI / 2;
holes2.rotation.z = 5 * Math.PI / 8;
holes2.position.y = 0.5;

var csg = new CSG();
csg.subtract([outsideShape, innerShape, holes, holes2]);

var ashTray = csg.toMesh();
ashTray.material = new THREE.MeshPhongMaterial( {color: 'gold',specular: 'white'} );
scene.add( ashTray );


var light = new THREE.PointLight();
light.position.set( 0, 5, 10 );
scene.add( light );


function drawFrame()
{
	// въртим пепелника
	ashTray.rotation.x = 0.3+0.2*Math.sin(ashTray.rotation.y);
	ashTray.rotation.y += 0.010;
	
	renderer.render( scene, camera );
}