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
|
<html>
<head>
<style>
body { margin: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<script src="three.min.js"></script>
<script>
// От тука до "КРАЙ" е откраднато от задача 1 на практикум 2
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( 3, 3, 8 );
camera.lookAt( new THREE.Vector3() );
// КРАЙ
var material = new THREE.MeshPhongMaterial();
function createBox(x, y, w, h, d) {
var geometry = new THREE.BoxGeometry( w, h, d );
var box = new THREE.Mesh( geometry, material );
box.position.set( x, y, 0 );
scene.add( box );
}
// Всички размери са в същите съотношения както на диаграмата от условието
const obw = 0.225; // outside border width
// Горен и долен паралелепипед от външна част
createBox(0, 1.05 - obw / 2, 3.55, obw, obw);
createBox(0, -1.05 + obw / 2, 3.55, obw, obw);
// Странични паралелепипеди от външна част
createBox( 1.775 - obw / 2, 0, obw, 2.1 - 2 * obw, obw);
createBox(-1.775 + obw / 2, 0, obw, 2.1 - 2 * obw, obw);
const ibw = 0.125; // inner border width
// Тънки вътрешни паралелепипеди
createBox( 0.475 + ibw / 2, 0, ibw, 2.1 - 2 * obw, ibw);
createBox(-0.475 - ibw / 2, 0, ibw, 2.1 - 2 * obw, ibw);
// От тука до "КРАЙ" е откраднато от задача 1 на практикум 2
var light = new THREE.PointLight( );
light.position.set( 3, 4, 5 );
scene.add( light );
light = new THREE.PointLight( );
light.position.set( -3, 4, -5 );
scene.add( light );
// въртене на сцената като в микровълнова фурна
function drawFrame()
{
scene.rotation.y += 0.005;
renderer.render( scene, camera );
}
// КРАЙ
</script>
</body>
</html>
|