Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics Fundamentals / 02-Practice-10.10.2022 / 06.js
blob: 2cf5d8f581c3510a30231c22cfba4733ac847e07 (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
// Задача: направете конструкция, която изглежда
// като голям куб, от върховете на който са
// изрязани кубчета във вътрешните върхове на
// които пък са добавени още по-малки кубчета.
// Броят геометрични обекти да е под 10.

var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( drawFrame );
document.body.appendChild( renderer.domElement );

var scene = new THREE.Scene();

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



var material = new THREE.MeshPhongMaterial( );

function newBox(w, h, d) {
	var geometry = new THREE.BoxGeometry( w, h, d );
	var obj = new THREE.Mesh( geometry, material );
	scene.add( obj );
}

newBox(9, 9, 9);
newBox(10, 10, 8);
newBox(8, 10, 10);
newBox(10, 8, 10);



var light = new THREE.PointLight( );
light.position.set( 17, 14, 11 );
scene.add( light );

light = new THREE.PointLight( );
light.position.set( -17, -14, -11 );
scene.add( light );


function drawFrame()
{
	scene.rotation.x += 0.005;
	scene.rotation.y += 0.005;
	renderer.render( scene, camera );
}