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


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

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


var radius = 2;
var width = 0.5;
var length = 6;

var a = new THREE.Mesh( new THREE.CylinderGeometry( radius, radius, length, 32 ) );
var b = new THREE.Mesh( new THREE.CylinderGeometry( radius - width, radius - width, length, 32 ) );

var csg = new CSG();
csg.subtract( [a, b] );

var c = csg.toMesh();
c.material = new THREE.MeshLambertMaterial( {color:'crimson'} );
scene.add(c);


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


function drawFrame()
{
	// въртим тръбата
	c.rotation.x += 0.005;
	c.rotation.y += 0.003;
	c.rotation.z += 0.010;
	
	renderer.render( scene, camera );
}