forked from RoboCup-Humanoid-TC/hlvs_webots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRobocupSoccerField.proto
331 lines (308 loc) · 14.5 KB
/
RobocupSoccerField.proto
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#VRML_SIM R2022b utf8
# license: Apache License 2.0
# license url: http://www.apache.org/licenses/LICENSE-2.0
# Official soccer field for the Robocup Humanoid League 2021.
# template language: javascript
EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2022b/projects/appearances/protos/Grass.proto"
EXTERNPROTO "RobocupGoal.proto"
PROTO RobocupSoccerField [
field SFVec3f translation 0 0 0
field SFRotation rotation 0 1 0 0
field SFString name "soccer_field"
field SFString{"adult", "kid"} size "adult"
field SFBool turfPhysics TRUE
]
{
%<
// Official soccer field dimensions from RoboCup 2021 (in meters)
const LINE_WIDTH = 0.05; // Line width
const BRANCH_LENGTH = 0.1; // Length of one branch of the penalty/center mark (not specified in rules)
const N_VERTICES_CIRCLE = 36; // Number of vertices for the regular polygon approximating the central circle (not specified in rules)
let A, B, C, D, E, F, G, H, I, J, K;
if (fields.size.value === 'kid') {
// Kid-size dimensions
A = 9;
B = 6;
C = 0.6;
D = 2.6;
E = 1;
F = 3;
G = 1.5;
H = 1.5;
I = 1;
J = 2;
K = 5;
} else {
// Adult-size dimensions
A = 14;
B = 9;
C = 0.6;
D = 2.6;
E = 1;
F = 4;
G = 2.1;
H = 3;
I = 1;
J = 3;
K = 6;
}
const DEPTH = fields.turfPhysics.value ? 0.01 : 0;
// Points for a quarter field (except central circle)
let pts = [];
pts[0] = {x: 0, y: 0, z: DEPTH}
pts[1] = {x: 0, y: I, z: DEPTH}
pts[2] = {x: 0, y: I + (B / 2), z: DEPTH}
pts[3] = {x: I, y: I, z: DEPTH}
pts[4] = {x: I, y: I + (B / 2), z: DEPTH}
pts[5] = {x: I + LINE_WIDTH, y: I, z: DEPTH}
pts[6] = {x: I + LINE_WIDTH, y: I + LINE_WIDTH, z: DEPTH}
pts[7] = {x: I + LINE_WIDTH, y: I + ((B - K) / 2), z: DEPTH}
pts[8] = {x: I + LINE_WIDTH, y: I + ((B - K) / 2) + LINE_WIDTH, z: DEPTH}
pts[9] = {x: I + LINE_WIDTH, y: I + ((B - F) / 2), z: DEPTH}
pts[10] = {x: I + LINE_WIDTH, y: I + ((B - F) / 2) + LINE_WIDTH, z: DEPTH}
pts[11] = {x: I + LINE_WIDTH, y: I + (B / 2), z: DEPTH}
pts[12] = {x: I + E - LINE_WIDTH, y: I + ((B - F) / 2) + LINE_WIDTH, z: DEPTH}
pts[13] = {x: I + E - LINE_WIDTH, y: I + (B / 2), z: DEPTH}
pts[14] = {x: I + E, y: I + ((B - F) / 2), z: DEPTH}
pts[15] = {x: I + E, y: I + ((B - F) / 2) + LINE_WIDTH, z: DEPTH}
pts[16] = {x: I + E, y: I + (B / 2) - BRANCH_LENGTH, z: DEPTH}
pts[17] = {x: I + E, y: I + (B / 2), z: DEPTH}
pts[18] = {x: I + G - BRANCH_LENGTH, y: I + ((B - LINE_WIDTH) / 2), z: DEPTH}
pts[19] = {x: I + G - BRANCH_LENGTH, y: I + (B / 2), z: DEPTH}
pts[20] = {x: I + G - (LINE_WIDTH / 2), y: I + (B / 2) - BRANCH_LENGTH, z: DEPTH}
pts[21] = {x: I + G - (LINE_WIDTH / 2), y: I + ((B - LINE_WIDTH) / 2), z: DEPTH}
pts[22] = {x: I + G - (LINE_WIDTH / 2), y: I + (B / 2), z: DEPTH}
pts[23] = {x: I + G + (LINE_WIDTH / 2), y: I + (B / 2) - BRANCH_LENGTH, z: DEPTH}
pts[24] = {x: I + G + (LINE_WIDTH / 2), y: I + ((B - LINE_WIDTH) / 2), z: DEPTH}
pts[25] = {x: I + G + (LINE_WIDTH / 2), y: I + (B / 2), z: DEPTH}
pts[26] = {x: I + G + BRANCH_LENGTH, y: I + ((B - LINE_WIDTH) / 2), z: DEPTH}
pts[27] = {x: I + G + BRANCH_LENGTH, y: I + (B / 2), z: DEPTH}
pts[28] = {x: I + J - LINE_WIDTH, y: I + ((B - K) / 2) + LINE_WIDTH, z: DEPTH}
pts[29] = {x: I + J - LINE_WIDTH, y: I + ((B - F) / 2), z: DEPTH}
pts[30] = {x: I + J - LINE_WIDTH, y: I + (B / 2) - BRANCH_LENGTH, z: DEPTH}
pts[31] = {x: I + J - LINE_WIDTH, y: I + (B / 2), z: DEPTH}
pts[32] = {x: I + J, y: I + ((B - K) / 2), z: DEPTH}
pts[33] = {x: I + J, y: I + ((B - K) / 2) + LINE_WIDTH, z: DEPTH}
pts[34] = {x: I + J, y: I + (B / 2), z: DEPTH}
pts[35] = {x: I + (A / 2) - BRANCH_LENGTH, y: I + ((B - LINE_WIDTH) / 2), z: DEPTH}
pts[36] = {x: I + (A / 2) - BRANCH_LENGTH, y: I + (B / 2), z: DEPTH}
pts[37] = {x: I + ((A - LINE_WIDTH) / 2), y: I, z: DEPTH}
pts[38] = {x: I + ((A - LINE_WIDTH) / 2), y: I + LINE_WIDTH, z: DEPTH}
pts[39] = {x: I + ((A - LINE_WIDTH) / 2), y: I + ((B - K) / 2), z: DEPTH}
pts[40] = {x: I + ((A - LINE_WIDTH) / 2), y: I + ((B - LINE_WIDTH) / 2), z: DEPTH}
pts[41] = {x: I + ((A - LINE_WIDTH) / 2), y: I + (B / 2), z: DEPTH}
pts[42] = {x: I + (A / 2), y: 0, z: DEPTH}
pts[43] = {x: I + (A / 2), y: I, z: DEPTH}
pts[44] = {x: I + (A / 2), y: I + (B / 2), z: DEPTH}
// Triangles for a quarter field (except central circle)
// Triangles for grass
let tg = [];
tg[0] = {a: 1, b: 44, c: 43};
tg[1] = {a: 1, b: 2, c: 44};
tg[2] = {a: 2, b: 5, c: 4};
tg[3] = {a: 2, b: 3, c: 5};
tg[4] = {a: 7, b: 40, c: 39};
tg[5] = {a: 7, b: 8, c: 40};
tg[6] = {a: 9, b: 30, c: 29};
tg[7] = {a: 9, b: 10, c: 30};
tg[8] = {a: 15, b: 31, c: 30};
tg[9] = {a: 15, b: 17, c: 31};
tg[10] = {a: 11, b: 14, c: 13};
tg[11] = {a: 11, b: 12, c: 14};
tg[12] = {a: 17, b: 22, c: 21};
tg[13] = {a: 17, b: 19, c: 22};
tg[14] = {a: 17, b: 20, c: 19};
tg[15] = {a: 17, b: 18, c: 20};
tg[16] = {a: 24, b: 25, c: 31};
tg[17] = {a: 25, b: 27, c: 31};
tg[18] = {a: 27, b: 28, c: 31};
tg[19] = {a: 28, b: 32, c: 31};
// Triangles for lines
let tl = [];
tl[0] = {a: 6, b: 39, c: 38};
tl[1] = {a: 6, b: 7, c: 39};
tl[2] = {a: 4, b: 12, c: 6};
tl[3] = {a: 4, b: 5, c: 12};
tl[4] = {a: 38, b: 45, c: 44};
tl[5] = {a: 38, b: 42, c: 45};
tl[6] = {a: 8, b: 34, c: 33};
tl[7] = {a: 8, b: 9, c: 34};
tl[8] = {a: 29, b: 35, c: 34};
tl[9] = {a: 29, b: 32, c: 35};
tl[10] = {a: 10, b: 16, c: 15};
tl[11] = {a: 10, b: 11, c: 16};
tl[12] = {a: 13, b: 18, c: 16};
tl[13] = {a: 13, b: 14, c: 18};
tl[14] = {a: 19, b: 23, c: 22};
tl[15] = {a: 19, b: 20, c: 23};
tl[16] = {a: 21, b: 26, c: 24};
tl[17] = {a: 21, b: 23, c: 26};
tl[18] = {a: 25, b: 28, c: 27};
tl[19] = {a: 25, b: 26, c: 28};
tl[20] = {a: 36, b: 42, c: 41};
tl[21] = {a: 36, b: 37, c: 42};
// Creation of a quarter of the central circle
const n_vertices_quarter = Math.ceil(N_VERTICES_CIRCLE / 4) + 1; // +1 because we want to have a point both at ~0 and pi/2
// Add points for the circles to the existing ones
function circle_add_pts (radius, pts, n_vertices_quarter, line_width) {
const center = pts[44];
let alpha = Math.atan((line_width / 2) / radius); // First point must be on the inside side of the half line
const alpha_increment = (Math.PI / 2 - alpha) / (n_vertices_quarter - 1); // Number of parts is nb of vertices minus 1
const Npts = pts.length;
for (let i = 1; i <= n_vertices_quarter; ++i) {
pts.push({x: center.x - radius * Math.sin(alpha), y: center.y - radius * Math.cos(alpha), z: center.z + 0});
alpha = alpha + alpha_increment;
}
}
circle_add_pts(H / 2, pts, n_vertices_quarter, LINE_WIDTH); // Inner radius of central circle
circle_add_pts(H / 2 + LINE_WIDTH, pts, n_vertices_quarter, LINE_WIDTH); // Outer radius of central circle
// Add the triangles for the line of the central circle
let Npts = pts.length;
let cin_start = Npts - 2 * n_vertices_quarter; // Id of the first point of the inner circle
let cout_start = Npts - n_vertices_quarter; // Id of the first point of the outer circle
for (let i = 1; i <= n_vertices_quarter - 1; ++i) {
tl.push({a: cout_start + (i + 1), b: cin_start + i, c: cout_start + i}); // First part of one line rectangle
tl.push({a: cout_start + (i + 1), b: cin_start + (i + 1), c: cin_start + i}); // Second part of one line rectangle
}
// Add the triangles for the grass boundaries of the central circle
cin_start = Npts - 2 * n_vertices_quarter;
cout_start = Npts - n_vertices_quarter;
// External triangles
tg.push({a: 33, b: cout_start + 1, c: 40}) // adds first triangle (boundary with half line)
for (let i = 1; i <= n_vertices_quarter - 1; ++i)
tg.push({a: 33, b: cout_start + (i + 1), c: cout_start + i});
tg.push({a: 33, b: 35, c: cout_start + n_vertices_quarter}); // Adds last triangle (boundary with penalty area and touch line)
// Internal triangles
// There is a vertex junction_index of the inner circle (cin) that makes the junction between triangles
// going through pt.40 (top vertex of central dash) and pt.35 (bottom vertex of central dash).
// It is located at approximately two thirds of the quarter
const junction_index = Math.ceil((2 / 3) * n_vertices_quarter); // Index of the junction triangle within the inner circle
for (let i = 1; i <= junction_index - 1; ++i)
tg.push({a: cin_start + (i + 1), b: 41, c: cin_start + i});
tg.push({a: cin_start + junction_index, b: 36, c: 41}); // Adds junction triangle
for (let i = junction_index; i <= n_vertices_quarter - 1; ++i)
tg.push({a:cin_start + (i + 1), b: 36, c: cin_start + i});
tg.push({a: cin_start + n_vertices_quarter, b: 37, c: 36}); // Adds touch line triangle (boundary with touch line)
// Replication of the other 3 quarters
for (let i = 0; i < Npts; ++i) {
const pt_ref = pts[i]; // Reference point
// 2nd Quarter (which completes one team's half)
pts[Npts + i] = {x: pt_ref.x, y: 2 * I + B - pt_ref.y, z: pt_ref.z};
// 3rd Quarter (replication on the y-axis)
pts[2 * Npts + i] = {x: 2 * I + A - pt_ref.x, y: pt_ref.y, z: pt_ref.z};
// 4th Quarter (which completes opponent's half)
pts[3 * Npts + i] = {x: 2 * I + A - pt_ref.x, y: 2 * I + B - pt_ref.y, z: pt_ref.z};
}
const Ntg = tg.length;
for (let i = 0; i < Ntg; ++i) { // Grass triangles
const tg_ref = tg[i];
// Due to axis reversions, we have to update the order of coords for the new corresp. triangles
tg[Ntg + i] = {a: tg_ref.b + Npts, b: tg_ref.a + Npts, c: tg_ref.c + Npts} // 2nd Quarter (bac)
tg[2 * Ntg + i] = {a: tg_ref.c + 2 * Npts, b: tg_ref.b + 2 * Npts, c: tg_ref.a + 2 * Npts}; // 3rd Quarter (cba)
tg[3 * Ntg + i] = {a: tg_ref.c + 3 * Npts, b: tg_ref.a + 3 * Npts, c: tg_ref.b + 3 * Npts}; // 3rd Quarter (cab)
}
const Ntl = tl.length;
for (let i = 0; i < Ntl; ++i) { // Same for the line triangles
const tl_ref = tl[i];
tl[Ntl + i] = {a: tl_ref.b + Npts, b: tl_ref.a + Npts, c: tl_ref.c + Npts};
tl[2 * Ntl + i] = {a: tl_ref.c + 2 * Npts, b: tl_ref.b + 2 * Npts, c: tl_ref.a + 2 * Npts};
tl[3 * Ntl + i] = {a: tl_ref.c + 3 * Npts, b: tl_ref.a + 3 * Npts, c: tl_ref.b + 3 * Npts};
}
// Offset to have origin on the center of the field
const OFFSET_X = (2 * I + A) / 2;
const OFFSET_Y = (2 * I + B) / 2;
Npts = pts.length;
for (let i = 0; i < Npts; ++i) {
pts[i].x = pts[i].x - OFFSET_X;
pts[i].y = pts[i].y - OFFSET_Y;
}
>%
Solid {
translation IS translation
rotation IS rotation
locked TRUE
children [
%< if (fields.turfPhysics.value) { >%
DEF BLADES Solid {
contactMaterial "grass"
translation 0 0 0.01
rotation 1 0 0 0
boundingObject Plane {
size %<= 2 * I + A >% %<= 2 * I + B >%
}
}
%< } >%
DEF GRASS Shape {
appearance Grass {
colorOverride 0.6 1 0.3
type "artificial"
textureTransform TextureTransform {
scale %<= 2 * A >% %<= 2 * A >%
}
}
geometry IndexedFaceSet {
coord Coordinate {
point [
%< for (let i = 0; i < pts.length; ++i) { >%
%<= pts[i].x >% %<= pts[i].y >% %<= pts[i].z >%
%< } >%
]
}
ccw FALSE
coordIndex [ # v.X - 1 because coordIndex starts at 0, while the points (defined in Lua) start at 1
%< for (let i = 0; i < tg.length; ++i) { >%
%<= tg[i].a - 1 >% %<= tg[i].b - 1 >% %<= tg[i].c - 1 >% -1,
%< } >%
]
}
}
DEF LINES Shape {
appearance Grass {
colorOverride 1 1 1
type "artificial_white"
IBLStrength 1.5
textureTransform TextureTransform {
scale %<= 2 * A >% %<= 2 * A >%
}
}
geometry IndexedFaceSet {
coord Coordinate {
point [
%< for (let i = 0; i < pts.length; ++i) { >%
%<= pts[i].x >% %<= pts[i].y >% %<= pts[i].z >%
%< } >%
]
}
ccw FALSE
coordIndex [ # v.X - 1 because coordIndex starts at 0, while the points (defined in Lua) start at 1
%< for (let i = 0; i < tl.length; ++i) { >%
%<= tl[i].a - 1 >% %<= tl[i].b - 1 >% %<= tl[i].c - 1 >% -1
%< } >%
]
}
}
RobocupGoal {
translation %<= I - OFFSET_X >% %<= I + (B / 2) - OFFSET_Y >% 0
rotation 0 0 1 -1.5707996938995747
size IS size
name "goal_home"
}
RobocupGoal {
translation %<= I + A - OFFSET_X >% %<= I + (B / 2) - OFFSET_Y >% 0
rotation 0 0 1 1.5707996938995747
size IS size
name "goal_away"
}
]
boundingObject Transform {
rotation 1 0 0 0
children [
Shape {
geometry Plane {
size %<= 2 * I + A >% %<= 2 * I + B >%
}
}
]
}
}
}