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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
<!DOCTYPE html>
<!-- Камен Младенов, група 6, ф.н. 0MI0800028 -->
<html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<script src="three.min.js"></script>
<script src="OrbitControls.js"></script>
<script src="CSG.js"></script>
</head>
<body>
<script>
const FN = '0MI0800028';
</script>
<script src="init.js"></script>
<script>
// Обекти:
// мини телескоп и въртящ се стол
/*
* Помощни
*/
function hFixCoords(coordinates, objectHeight, objectWidth) {
coordinates[1] += objectHeight / 2 - 0.01;
coordinates[2] -= objectWidth / 2;
return coordinates;
}
var groups = [];
function hNewGroup(meshes, position) {
var group = new THREE.Group();
meshes.forEach((mesh) => group.add(mesh));
group.position.set(...position);
groups.push(group);
return group;
}
/*
* Дупки
*/
function holePrimitive(size, position) {
var hole = new THREE.Mesh(new THREE.BoxGeometry(...size));
position[1] -= (3.10 - size[1]) / 2; // на 3.10 трябва височината на стената, ама карай
hole.position.set(...position);
return hole;
}
function doorHole(x, y, z) {
return holePrimitive([1, 2.10, 1], [x, y, z]);
}
function doubleDoorHole(x, y, z) {
return holePrimitive([2, 2.10, 1], [x, y, z]);
}
function windowHole(x, y, z) {
return holePrimitive([0.70, 1.44, 1], [x, y+1.10, z]);
}
function doubleWindowHole(x, y, z) {
return holePrimitive([1.40, 1.44, 1], [x, y+1.10, z]);
}
/*
* Обекти
*/
function wall(length, rotation, holes, position) {
const height = 3.10;
const width = 0.20;
const color = 'darkgray';
var wall = new THREE.Mesh(new THREE.BoxGeometry(length, height, width),
new THREE.MeshPhongMaterial({ color: color }));
if (holes !== undefined && holes.length >= 0) {
var wallCSG = new CSG();
wallCSG.subtract([wall]);
holes.forEach((hole) => wallCSG.subtract([hole]));
var wall = wallCSG.toMesh();
}
wall.rotation.y = rotation * Math.PI / 2;
if (position === undefined)
position = [0, 0, 0];
wall.position.set(position[0] -Math.sin(wall.rotation.y) * width / 2,
position[1] +height / 2 - 0.01,
position[2] -Math.cos(wall.rotation.y) * width / 2);
return wall;
}
/*
* Сцена
*/
/* Външни стени */
var frontDoor = hNewGroup([
wall(6, 0, [doorHole(1.5,0,0)]),
], [5, 0, 5]);
var wall1 = hNewGroup([
wall(2.20, 1),
], [2, 0, 5.90]);
var wall2 = hNewGroup([
wall(8, 0),
], [-2, 0, 7]);
var wall3 = hNewGroup([
wall(11, -1, [doubleWindowHole(4,0,0), doubleWindowHole(1,0,0), doubleWindowHole(-3,0,0)]),
], [-6, 0, 1.5]);
var wall4 = hNewGroup([
wall(8, 2, [doubleDoorHole(-0.5,0,0), doorHole(1,0,0)]),
], [-2, 0, -4]);
var wall5 = hNewGroup([
wall(1.20, 1),
], [2, 0, -3.4]);
var wall6 = hNewGroup([
wall(6, 2),
], [5, 0, -3]);
var wall7 = hNewGroup([
wall(8, 1),
], [8, 0, 1]);
/* Вътрешни стени */
var wall8 = hNewGroup([
wall(3, 0), wall(1.414, -0.5, [], [-2,0,-0.5]), wall(4, -1, [doorHole(0,0,0)], [-2.5,0,-3])
], [6.5,0,2]);
var wall9 = hNewGroup([
wall(8, 0),
], [-2,0,1]);
var wall10 = hNewGroup([
wall(8, 1, [doubleDoorHole(-2,0,0), doubleDoorHole(2,0,0)])
], [2, 0, 1]);
var wall11 = hNewGroup([
wall(5, -1, [doorHole([1,0,0])]),
], [5, 0, -0.5]);
/*
* Помощен код
*/
groups.forEach((group) => scene.add(group));
var geometry = new THREE.BoxGeometry( 2, 2, 2 ),
material = new THREE.MeshPhongMaterial( {color:'crimson', shininess: 100} );
var cube = new THREE.Mesh( geometry, material );
cube.position.set( 0, 1, 0 );
cube.receiveShadow = true;
cube.castShadow = true;
// scene.add( cube );
</script>
</body>
</html>
|