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
|
// Задача: конструирайте порцеланова чаша със
// загладени ръбове.
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( 'pink' );
var aspect = window.innerWidth/window.innerHeight;
camera = new THREE.PerspectiveCamera( 30, aspect );
camera.position.set( 0, 0, 10 );
camera.lookAt( new THREE.Vector3() );
// начален стадий на чаша
var material = new THREE.MeshPhongMaterial( {color: 'purple',shininess: 100, specular: 'white'} );
var outsideShape = new THREE.Mesh( new THREE.CylinderGeometry( 1.2, 1.2, 2.5, 40 ), material );
var innerHole = new THREE.Mesh(new THREE.CylinderGeometry(1, 1, 2.5, 40));
innerHole.position.y = 0.2;
var csg = new CSG();
csg.subtract([outsideShape, innerHole]);
var mug = csg.toMesh();
mug.material = material;
var topLip = new THREE.Mesh(new THREE.TorusGeometry(1.1, 0.1, 16, 64), material);
topLip.rotation.x = Math.PI / 2;
topLip.position.y = 2.5 / 2;
mug.add(topLip);
var bottomLip = new THREE.Mesh(new THREE.TorusGeometry(1.1, 0.1, 16, 64), material);
bottomLip.rotation.x = Math.PI / 2;
bottomLip.position.y = -2.5 / 2 + 0.1 / 2;
mug.add(bottomLip);
var handle = new THREE.Mesh(new THREE.TorusGeometry(1, 0.2, 16, 64, Math.PI), material);
handle.rotation.z = Math.PI / 2;
handle.position.x = -1.1;
mug.add(handle);
scene.add( mug );
var light = new THREE.PointLight();
light.position.set( 0, 5, 10 );
scene.add( light );
function drawFrame()
{
// въртим чашата
mug.rotation.x += 0.005;
mug.rotation.z = Math.sin(2*mug.rotation.x)/2;
mug.rotation.y += 0.003;
renderer.render( scene, camera );
}
|