-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproperties.py
493 lines (476 loc) · 28.4 KB
/
properties.py
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
from math import pi, ceil
import bpy
from mathutils import Vector, Matrix
import helper
from pyclothoids import Clothoid
# ======================================= Class definitions =======================================
params_cross_section = {
'two_lanes_default': {
'sides': ['left', 'left', 'center', 'right', 'right'],
'widths': [0.20, 3.75, 0.0, 3.75, 0.20],
'widths_change': ['none', 'none', 'none', 'none', 'none'],
'types': ['border', 'driving', 'center', 'driving', 'border'],
'road_mark_types': ['none', 'solid', 'broken', 'solid', 'none'],
'road_mark_weights': ['none', 'standard', 'standard', 'standard', 'none'],
'road_mark_widths': [0.0, 0.12, 0.12, 0.12, 0.0],
'road_mark_colors': ['none', 'white', 'white', 'white', 'none'],
'road_split_type': 'none',
'road_split_lane_idx': 5,
},
# Typical German road cross sections
# See:
# https://de.wikipedia.org/wiki/Richtlinien_f%C3%BCr_die_Anlage_von_Stra%C3%9Fen_%E2%80%93_Querschnitt
# https://de.wikipedia.org/wiki/Richtlinien_f%C3%BCr_die_Anlage_von_Autobahnen
# https://de.wikipedia.org/wiki/Entwurfsklasse
# https://www.beton.wiki/index.php?title=Regelquerschnitt_im_Stra%C3%9Fenbau
# https://www.vsvi-mv.de/fileadmin/Medienpool/Seminarunterlagen/Seminare_2012/Vortrag_1_-_neue_RAL_Frau_Vetters.pdf
# https://dsgs.de/leitfaden-fahrbahnmarkierung1.html
#
'ekl4_rq9': {
'sides': ['left', 'left', 'center', 'right', 'right', 'right'],
'widths': [1.5, 0.5, 0.0, 3.5, 0.5, 1.5],
'widths_change': ['none', 'none', 'none', 'none', 'none', 'none'],
'types': ['shoulder', 'border', 'center', 'driving', 'border', 'shoulder'],
'road_mark_types': ['none', 'none', 'broken', 'broken', 'none', 'none'],
'road_mark_weights': ['none', 'none', 'standard', 'standard', 'none', 'none'],
'road_mark_widths': [0.0, 0.0, 0.12, 0.12, 0.0, 0.0],
'road_mark_colors': ['none', 'none', 'white', 'white', 'none', 'none'],
'road_split_type': 'none',
'road_split_lane_idx': 6,
},
'ekl3_rq11': {
'sides': ['left', 'left', 'left', 'center', 'right', 'right', 'right'],
'widths': [1.5, 0.50, 3.5, 0.0, 3.5, 0.50, 1.5],
'widths_change': ['none', 'none', 'none', 'none', 'none', 'none', 'none'],
'types': ['shoulder', 'border', 'driving', 'center', 'driving', 'border', 'shoulder'],
'road_mark_types': ['none', 'none', 'solid', 'broken', 'solid', 'none', 'none'],
'road_mark_weights': ['none', 'none', 'standard', 'standard', 'standard', 'none', 'none'],
'road_mark_widths': [0.0, 0.0, 0.12, 0.12, 0.12, 0.0, 0.0],
'road_mark_colors': ['none', 'none', 'white', 'white', 'white', 'none', 'none'],
'road_split_type': 'none',
'road_split_lane_idx': 7,
},
'eka1_rq31': {
'sides': ['left', 'left', 'left', 'left', 'left', 'left', 'left', 'center', 'right', 'right', 'right', 'right', 'right', 'right', 'right'],
'widths': [1.5, 3.0, 0.75, 3.75, 3.75, 0.75, 2.0, 0.0, 2.0, 0.75, 3.75, 3.75, 0.75, 3.0, 1.5],
'widths_change': ['none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none'],
'types': ['shoulder', 'stop', 'border', 'driving', 'driving', 'border', 'median', 'center', 'median', 'border', 'driving', 'driving', 'border', 'stop', 'shoulder'],
'road_mark_types': ['none', 'none', 'none', 'solid', 'broken', 'solid', 'none', 'none', 'none', 'solid', 'broken', 'solid', 'none', 'none', 'none'],
'road_mark_weights': ['none', 'none', 'none', 'bold', 'standard', 'bold', 'none', 'none', 'none', 'bold', 'standard', 'bold', 'none', 'none', 'none'],
'road_mark_widths': [0.0, 0.0, 0.0, 0.30, 0.15, 0.30, 0.0, 0.0, 0.0, 0.30, 0.15, 0.30, 0.0, 0.0, 0.0],
'road_mark_colors': ['none', 'none', 'none', 'white', 'white', 'white', 'none', 'none', 'none', 'white', 'white', 'white', 'none', 'none', 'none'],
'road_split_type': 'none',
'road_split_lane_idx': 15,
},
'eka1_rq31_exit_right_open': {
'sides': ['left', 'left', 'left', 'left', 'left', 'left', 'left', 'center', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right'],
'widths': [1.5, 3.0, 0.75, 3.75, 3.75, 0.75, 2.0, 0.0, 2.0, 0.75, 3.75, 3.75, 3.75, 0.75, 3.0, 1.5],
'widths_change': ['none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'open', 'none', 'none', 'none'],
'types': ['shoulder', 'stop', 'border', 'driving', 'driving', 'border', 'median', 'center', 'median', 'border', 'driving', 'driving', 'exit', 'border', 'stop', 'shoulder'],
'road_mark_types': ['none', 'none', 'none', 'solid', 'broken', 'solid', 'none', 'none', 'none', 'solid', 'broken', 'broken', 'solid', 'none', 'none', 'none'],
'road_mark_weights': ['none', 'none', 'none', 'bold', 'standard', 'bold', 'none', 'none', 'none', 'bold', 'standard', 'bold', 'bold', 'none', 'none', 'none'],
'road_mark_widths': [0.0, 0.0, 0.0, 0.30, 0.15, 0.30, 0.0, 0.0, 0.0, 0.30, 0.15, 0.30, 0.30, 0.0, 0.0, 0.0],
'road_mark_colors': ['none', 'none', 'none', 'white', 'white', 'white', 'none', 'none', 'none', 'white', 'white', 'white', 'white', 'none', 'none', 'none'],
'road_split_type': 'none',
'road_split_lane_idx': 16,
},
'eka1_rq31_exit_right': {
'sides': ['left', 'left', 'left', 'left', 'left', 'left', 'left', 'center', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right'],
'widths': [1.5, 3.0, 0.75, 3.75, 3.75, 0.75, 2.0, 0.0, 2.0, 0.75, 3.75, 3.75, 3.75, 0.75, 3.0, 1.5],
'widths_change': ['none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none'],
'types': ['shoulder', 'stop', 'border', 'driving', 'driving', 'border', 'median', 'center', 'median', 'border', 'driving', 'driving', 'exit', 'border', 'stop', 'shoulder'],
'road_mark_types': ['none', 'none', 'none', 'solid', 'broken', 'solid', 'none', 'none', 'none', 'solid', 'broken', 'broken', 'solid', 'none', 'none', 'none'],
'road_mark_weights': ['none', 'none', 'none', 'bold', 'standard', 'bold', 'none', 'none', 'none', 'bold', 'standard', 'bold', 'bold', 'none', 'none', 'none'],
'road_mark_widths': [0.0, 0.0, 0.0, 0.30, 0.15, 0.30, 0.0, 0.0, 0.0, 0.30, 0.15, 0.30, 0.30, 0.0, 0.0, 0.0],
'road_mark_colors': ['none', 'none', 'none', 'white', 'white', 'white', 'none', 'none', 'none', 'white', 'white', 'white', 'white', 'none', 'none', 'none'],
'road_split_type': 'end',
'road_split_lane_idx': 12,
},
'eka1_rq31_exit_right_continuation': {
'sides': ['left', 'left', 'left', 'left', 'left', 'left', 'left', 'center', 'right', 'right', 'right', 'right'],
'widths': [1.5, 3.0, 0.75, 3.75, 3.75, 0.75, 2.0, 0.0, 2.0, 0.75, 3.75, 3.75],
'widths_change': ['none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none'],
'types': ['shoulder', 'stop', 'border', 'driving', 'driving', 'border', 'median', 'center', 'median', 'border', 'driving', 'driving'],
'road_mark_types': ['none', 'none', 'none', 'solid', 'broken', 'solid', 'none', 'none', 'none', 'solid', 'broken', 'solid'],
'road_mark_weights': ['none', 'none', 'none', 'bold', 'standard', 'bold', 'none', 'none', 'none', 'bold', 'standard', 'bold'],
'road_mark_widths': [0.0, 0.0, 0.0, 0.30, 0.15, 0.30, 0.0, 0.0, 0.0, 0.30, 0.15, 0.30],
'road_mark_colors': ['none', 'none', 'none', 'white', 'white', 'white', 'none', 'none', 'none', 'white', 'white', 'white'],
'road_split_type': 'none',
'road_split_lane_idx': 12,
},
'eka1_rq31_entry_right': {
'sides': ['left', 'left', 'left', 'left', 'left', 'left', 'left', 'center', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right'],
'widths': [1.5, 3.0, 0.75, 3.75, 3.75, 0.75, 2.0, 0.0, 2.0, 0.75, 3.75, 3.75, 3.75, 0.75, 3.0, 1.5],
'widths_change': ['none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none'],
'types': ['shoulder', 'stop', 'border', 'driving', 'driving', 'border', 'median', 'center', 'median', 'border', 'driving', 'driving', 'exit', 'border', 'stop', 'shoulder'],
'road_mark_types': ['none', 'none', 'none', 'solid', 'broken', 'solid', 'none', 'none', 'none', 'solid', 'broken', 'broken', 'solid', 'none', 'none', 'none'],
'road_mark_weights': ['none', 'none', 'none', 'bold', 'standard', 'bold', 'none', 'none', 'none', 'bold', 'standard', 'bold', 'bold', 'none', 'none', 'none'],
'road_mark_widths': [0.0, 0.0, 0.0, 0.30, 0.15, 0.30, 0.0, 0.0, 0.0, 0.30, 0.15, 0.30, 0.30, 0.0, 0.0, 0.0],
'road_mark_colors': ['none', 'none', 'none', 'white', 'white', 'white', 'none', 'none', 'none', 'white', 'white', 'white', 'white', 'none', 'none', 'none'],
'road_split_type': 'start',
'road_split_lane_idx': 12,
},
'eka1_rq31_entry_right_close': {
'sides': ['left', 'left', 'left', 'left', 'left', 'left', 'left', 'center', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right'],
'widths': [1.5, 3.0, 0.75, 3.75, 3.75, 0.75, 2.0, 0.0, 2.0, 0.75, 3.75, 3.75, 3.75, 0.75, 3.0, 1.5],
'widths_change': ['none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'close', 'none', 'none', 'none'],
'types': ['shoulder', 'stop', 'border', 'driving', 'driving', 'border', 'median', 'center', 'median', 'border', 'driving', 'driving', 'exit', 'border', 'stop', 'shoulder'],
'road_mark_types': ['none', 'none', 'none', 'solid', 'broken', 'solid', 'none', 'none', 'none', 'solid', 'broken', 'broken', 'solid', 'none', 'none', 'none'],
'road_mark_weights': ['none', 'none', 'none', 'bold', 'standard', 'bold', 'none', 'none', 'none', 'bold', 'standard', 'bold', 'bold', 'none', 'none', 'none'],
'road_mark_widths': [0.0, 0.0, 0.0, 0.30, 0.15, 0.30, 0.0, 0.0, 0.0, 0.30, 0.15, 0.30, 0.30, 0.0, 0.0, 0.0],
'road_mark_colors': ['none', 'none', 'none', 'white', 'white', 'white', 'none', 'none', 'none', 'white', 'white', 'white', 'white', 'none', 'none', 'none'],
'road_split_type': 'none',
'road_split_lane_idx': 16,
},
'eka1_rq36': {
'sides': ['left', 'left', 'left', 'left', 'left', 'left', 'left', 'left', 'center', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right'],
'widths': [1.5, 2.5, 0.5, 3.75, 3.5, 3.5, 0.75, 2.0, 0.0, 2.0, 0.75, 3.5, 3.5, 3.75, 0.5, 2.5, 1.5],
'widths_change': ['none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none'],
'types': ['shoulder', 'stop', 'border', 'driving', 'driving', 'driving', 'border', 'median', 'center', 'median', 'border', 'driving', 'driving', 'driving', 'border', 'stop', 'shoulder'],
'road_mark_types': ['none', 'none', 'none', 'solid', 'broken', 'broken', 'solid', 'none', 'none', 'none', 'solid', 'broken', 'broken', 'solid', 'none', 'none', 'none'],
'road_mark_weights': ['none', 'none', 'none', 'bold', 'standard', 'standard', 'bold', 'none', 'none', 'none', 'bold', 'standard', 'standard', 'bold', 'none', 'none', 'none'],
'road_mark_widths': [0.0, 0.0, 0.0, 0.30, 0.15, 0.15, 0.30, 0.0, 0.0, 0.0, 0.30, 0.15, 0.15, 0.30, 0.0, 0.0, 0.0],
'road_mark_colors': ['none', 'none', 'none', 'white', 'white', 'white', 'white', 'none', 'none', 'none', 'white', 'white', 'white', 'white', 'none', 'none', 'none'],
'road_split_type': 'none',
'road_split_lane_idx': 17,
},
'eka1_rq43_5': {
'sides': ['left', 'left', 'left', 'left', 'left', 'left', 'left', 'left', 'left', 'center', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right'],
'widths': [2.5, 2.5, 0.5, 3.75, 3.75, 3.5, 3.5, 0.75, 2.0, 0.0, 2.0, 0.75, 3.5, 3.5, 3.75, 3.75, 0.5, 2.5, 2.5],
'widths_change': ['none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none'],
'types': ['shoulder', 'stop', 'border', 'driving', 'driving', 'driving', 'driving', 'border', 'median', 'center', 'median', 'border', 'driving', 'driving', 'driving', 'driving', 'border', 'stop', 'shoulder'],
'road_mark_types': ['none', 'none', 'none', 'solid', 'broken', 'broken', 'broken', 'solid', 'none', 'none', 'none', 'solid', 'broken', 'broken', 'broken', 'solid', 'none', 'none', 'none'],
'road_mark_weights': ['none', 'none', 'none', 'bold', 'standard', 'standard', 'standard', 'bold', 'none', 'none', 'none', 'bold', 'standard', 'standard', 'standard', 'bold', 'none', 'none', 'none'],
'road_mark_widths': [0.0, 0.0, 0.0, 0.30, 0.15, 0.15, 0.15, 0.30, 0.0, 0.0, 0.0, 0.30, 0.15, 0.15, 0.15, 0.30, 0.0, 0.0, 0.0],
'road_mark_colors': ['none', 'none', 'none', 'white', 'white', 'white', 'white', 'white', 'none', 'none', 'none', 'white', 'white', 'white', 'white', 'white', 'none', 'none', 'none'],
'road_split_type': 'none',
'road_split_lane_idx': 19,
},
'on_ramp': {
'sides': ['left', 'center', 'right', 'right', 'right'],
'widths': [3.75, 0.0, 0.75, 3.0, 1.5],
'widths_change': ['none', 'none', 'none', 'none', 'none'],
'types': ['onRamp', 'center', 'border', 'stop','shoulder'],
'road_mark_types': ['solid', 'solid', 'none', 'none', 'none'],
'road_mark_weights': ['bold', 'bold', 'none', 'none', 'none'],
'road_mark_widths': [0.30, 0.30, 0.0, 0.0, 0.0],
'road_mark_colors': ['white', 'white', 'none', 'none', 'none'],
'road_split_type': 'none',
'road_split_lane_idx': 5,
},
'off_ramp': {
'sides': ['left', 'center', 'right', 'right', 'right'],
'widths': [3.75, 0.0, 0.75, 3.0, 1.5],
'widths_change': ['none', 'none', 'none', 'none', 'none'],
'types': ['offRamp', 'center', 'border', 'stop', 'shoulder'],
'road_mark_types': ['solid', 'solid', 'none', 'none', 'none'],
'road_mark_weights': ['bold', 'bold', 'none', 'none', 'none'],
'road_mark_widths': [0.30, 0.30, 0.0, 0.0, 0.0],
'road_mark_colors': ['white', 'white', 'none', 'none', 'none'],
'road_split_type': 'none',
'road_split_lane_idx': 5,
},
}
# We need global wrapper callbacks due to Blender update callback implementation
def callback_cross_section(self, context):
self.update_cross_section()
def callback_lane_width(self, context):
self.update_lane_width(context)
def callback_road_mark_weight(self, context):
self.update_road_mark_weight(context)
def callback_num_lanes(self, context):
self.update_num_lanes()
def callback_road_split(self, context):
self.update_road_split(context)
class PR_enum_lane(bpy.types.PropertyGroup):
idx: bpy.props.IntProperty(min=0)
side: bpy.props.EnumProperty(
items=(('left', 'left', '', 0),
('right', 'right', '', 1),
('center', 'center', '', 2),
),
default='right',
)
width: bpy.props.FloatProperty(
name='Width',
default=4.0, min=0.01, max=10.0, step=1
)
# Used to open up a new lane or end a lane
width_change: bpy.props.EnumProperty(
name = 'Width change',
items=(('none', 'None', '', 0),
('open', 'Open', '', 1),
('close', 'Close', '', 2),
),
default='none',
)
type: bpy.props.EnumProperty(
name = 'Type',
items=(('driving', 'Driving', '', 0),
#('bidirectional', 'Bidirectional', '', 1),
#('bus', 'Bus', '', 2),
('stop', 'Stop', '', 3),
#('parking', 'Parking', '', 4),
#('biking', 'Biking', '', 5),
#('restricted', 'Restricted', '', 6),
#('roadWorks', 'Road works', '', 7),
('border', 'Border', '', 8),
#('curb', 'Curb', '', 9),
#('sidewalk', 'Sidewalk', '', 10),
('shoulder', 'Shoulder', '', 11),
('median', 'Median', '', 12),
('entry', 'Entry', '', 13),
('exit', 'Exit', '', 14),
('onRamp', 'On ramp', '', 15),
('offRamp', 'Off ramp', '', 16),
#('connectingRamp', 'Connecting ramp', '', 17),
('none', 'None', '', 18),
('center', 'Center', '', 19),
),
default='driving',
update=callback_lane_width,
)
road_mark_type: bpy.props.EnumProperty(
name = 'Type',
items=(('none', 'None', '', 0),
('solid', 'Solid', '', 1),
('broken', 'Broken', '', 2),
('solid_solid', 'Double solid solid', '', 3),
#('solid_broken', 'Double solid broken', '', 4),
#('broken_solid', 'Double broken solid', '', 5),
),
default='none',
)
road_mark_color: bpy.props.EnumProperty(
name = 'Color',
items=(('none', 'None', '', 0),
('white', 'White', '', 1),
('yellow', 'Yellow', '', 2),
),
default='none',
)
road_mark_weight: bpy.props.EnumProperty(
name = 'Weight',
items=(('none', 'None', '', 0),
('standard', 'Standard', '', 1),
('bold', 'Bold', '', 2),
),
default='none',
update=callback_road_mark_weight,
)
road_mark_width: bpy.props.FloatProperty(
name='Width of road mark line',
default=0.12, min=0.0, max=10.0, step=1
)
# False for the lanes/lanes going left, True for those going right
split_right: bpy.props.BoolProperty(description='Split above here', update=callback_road_split)
def update_lane_width(self, context):
mapping_width_type_lane = {
'driving' : context.scene.road_properties.width_driving,
'entry' : context.scene.road_properties.width_driving,
'exit' : context.scene.road_properties.width_driving,
'onRamp' : context.scene.road_properties.width_driving,
'offRamp' : context.scene.road_properties.width_driving,
'stop' : context.scene.road_properties.width_stop,
'border' : context.scene.road_properties.width_border,
'shoulder' : context.scene.road_properties.width_shoulder,
'median' : context.scene.road_properties.width_median,
'none' : context.scene.road_properties.width_none,
'center': 0,
}
self.width = mapping_width_type_lane[self.type]
def update_road_mark_weight(self, context):
mapping_width_type_road_mark = {
'none' : 0,
'standard' : context.scene.road_properties.width_line_standard,
'bold' : context.scene.road_properties.width_line_bold,
}
self.road_mark_width = mapping_width_type_road_mark[self.road_mark_weight]
def update_road_split(self, context):
# Avoid updating recursively
if context.scene.road_properties.lock_lanes:
return
context.scene.road_properties.lock_lanes = True
# Toggle
if self.split_right == True:
self.split_right = True
road_split_lane_idx = self.idx
else:
self.split_right = False
road_split_lane_idx = self.idx + 1
# Store new split index
context.scene.road_properties.road_split_lane_idx = road_split_lane_idx
# Split at the desired lane
for idx, lane in enumerate(context.scene.road_properties.lanes):
if idx < road_split_lane_idx:
lane.split_right = False
else:
lane.split_right = True
# Unlock updating
context.scene.road_properties.lock_lanes = False
# =============================== Road properties =================================================
class PR_road_properties(bpy.types.PropertyGroup):
width_line_standard: bpy.props.FloatProperty(default=0.12, min=0.01, max=10.0, step=1)
width_line_bold: bpy.props.FloatProperty(default=0.25, min=0.01, max=10.0, step=1)
length_broken_line: bpy.props.FloatProperty(default=3.0, min=0.01, max=10.0, step=1)
ratio_broken_line_gap: bpy.props.IntProperty(default=1, min=1, max=3)
width_driving: bpy.props.FloatProperty(default=3.75, min=0.01, max=10.0, step=1)
width_border: bpy.props.FloatProperty(default=0.5, min=0.01, max=1.0, step=1)
# width_curb: bpy.props.FloatProperty(default=0.16, min=0.10, max=0.30, step=1)
width_median: bpy.props.FloatProperty(default=2.0, min=0.01, max=10.0, step=1)
width_stop: bpy.props.FloatProperty(default=2.5, min=0.01, max=10.0, step=1)
width_shoulder: bpy.props.FloatProperty(default=1.5, min=0.01, max=10.0, step=1)
width_none: bpy.props.FloatProperty(default=2.5, min=0.01, max=10.0, step=1)
design_speed: bpy.props.FloatProperty(default=130.0, min=1.00, max=400.0, step=1)
num_lanes_left: bpy.props.IntProperty(default=2, min=0, max=20, update=callback_num_lanes)
num_lanes_right: bpy.props.IntProperty(default=2, min=0, max=20, update=callback_num_lanes)
road_split_type: bpy.props.EnumProperty(
name = 'Split type',
items=(('none', 'None', '', 0),
('start', 'Start', '', 1),
('end', 'End', '', 2),
),
default='none',
)
# Lane idx of first right lane in case of a split road (counting in -t direction)
road_split_lane_idx: bpy.props.IntProperty(default=0, min=0)
lane_idx_current: bpy.props.IntProperty(default=0, min=0)
lanes: bpy.props.CollectionProperty(type=PR_enum_lane)
cross_section_preset: bpy.props.EnumProperty(
items=(
('two_lanes_default','Two lanes (default)','Two lanes (default)'),
# Typical German road cross sections
('ekl4_rq9', 'EKL 4, RQ 9', 'EKL 4, RQ 9'),
('ekl3_rq11', 'EKL 3, RQ 11', 'EKL 3, RQ 11'),
# ('ekl2_rq11.5', 'EKL 2, RQ 11.5', 'EKL 2, RQ 11.5'),
# ('ekl1_rq15_5', 'EKL 1, RQ 15.5', 'EKL 1, RQ 15.5'),
# ('eka3_rq25', 'EKA 3, RQ 25', 'EKA 3, RQ 25'),
# ('eka3_rq31_5', 'EKA 3, RQ 31_5', 'EKA 3, RQ 31_5'),
# ('eka3_rq38_5', 'EKA 3, RQ 38_5', 'EKA 3, RQ 38_5'),
# ('eka2_rq28', 'EKA 1, RQ 28', 'EKA 1, RQ 28'),
('eka1_rq31', 'EKA 1, RQ 31', 'EKA 1, RQ 31'),
('eka1_rq31_exit_right_open', 'EKA 1, RQ 31 - exit right open', 'EKA 1, RQ 31 - exit right open'),
('eka1_rq31_exit_right', 'EKA 1, RQ 31 - exit right', 'EKA 1, RQ 31 - exit right'),
('eka1_rq31_exit_right_continuation', 'EKA 1, RQ 31 - exit right continuation', 'EKA 1, RQ 31 - exit right continuation'),
('eka1_rq31_entry_right', 'EKA 1, RQ 31 - entry right', 'EKA 1, RQ 31 - entry right'),
('eka1_rq31_entry_right_close', 'EKA 1, RQ 31 - entry right close', 'EKA 1, RQ 31 - entry right close'),
('eka1_rq36', 'EKA 1, RQ 36', 'EKA 1, RQ 36'),
('eka1_rq43_5', 'EKA 1, RQ 43.5', 'EKA 1, RQ 43.5'),
('on_ramp', 'On ramp', 'On ramp'),
('off_ramp', 'Off ramp', 'Off ramp'),
),
name='cross_section',
description='Road cross section presets',
default='two_lanes_default',
update=callback_cross_section,
)
# A lock for deactivating callbacks
lock_lanes: bpy.props.BoolProperty(default=False)
def init(self):
self.update_cross_section()
def clear_lanes(self):
self.lanes.clear()
self.lane_idx_current = 0
self.road_split_type = 'none'
self.road_split_lane_idx = 1
def update_num_lanes(self):
# Do not update recursively when switching presets
if self.lock_lanes:
return
# Avoid callbacks
self.lock_lanes = True
self.clear_lanes()
# Left lanes
for idx in range(self.num_lanes_left - 1,-1,-1):
if self.num_lanes_left == 1:
self.add_lane('left', 'driving', self.width_driving, 'none', 'solid', 'standard', 0.12, 'white')
else:
if idx == self.num_lanes_left - 1:
self.add_lane('left', 'border', self.width_border, 'none', 'none', 'none', 0.0, 'none')
elif idx == 0:
self.add_lane('left', 'driving', self.width_driving, 'none', 'solid', 'standard', 0.12, 'white')
else:
self.add_lane('left', 'driving', self.width_driving, 'none', 'broken', 'standard', 0.12, 'white')
# Center line
if self.num_lanes_left == 0:
self.add_lane('center', 'driving', 0.0, 'none', 'solid', 'standard', 0.12, 'white')
elif self.num_lanes_right == 0:
self.add_lane('center', 'driving', 0.0, 'none', 'solid', 'standard', 0.12, 'white')
else:
self.add_lane('center', 'driving', 0.0, 'none', 'broken', 'standard', 0.12, 'white')
# Right lanes
for idx in range(self.num_lanes_right):
if self.num_lanes_right == 1:
self.add_lane('right', 'driving', self.width_driving, 'none', 'solid', 'standard', 0.12, 'white')
else:
if idx == self.num_lanes_right - 1:
self.add_lane('right', 'border', self.width_border, 'none', 'none', 'none', 0.0, 'none')
elif idx == self.num_lanes_right - 2:
self.add_lane('right', 'driving', self.width_driving, 'none', 'solid', 'standard', 0.12, 'white')
else:
self.add_lane('right', 'driving', self.width_driving, 'none', 'broken', 'standard', 0.12, 'white')
self.road_split_type = 'none'
# Set split index one above maximum to make all lanes go left
self.road_split_lane_idx = self.num_lanes_left + self.num_lanes_right + 1
# Allow callbacks again
self.lock_lanes = False
def add_lane(self, side, type, width, width_change,
road_mark_type, road_mark_weight, road_mark_width, road_mark_color,
split_right=False):
lane = self.lanes.add()
lane.idx = self.lane_idx_current
self.lane_idx_current += 1
lane.side = side
lane.type = type
lane.width = width
lane.width_change = width_change
lane.road_mark_type = road_mark_type
lane.road_mark_weight = road_mark_weight
lane.road_mark_width = road_mark_width
lane.road_mark_color = road_mark_color
lane.split_right = split_right
def update_cross_section(self):
# Do not update recursively when switching presets
if self.lock_lanes:
return
# Avoid callbacks
self.lock_lanes = True
# Reset
self.clear_lanes()
num_lanes_left = 0
num_lanes_right = 0
# Build up cross section
params = params_cross_section[self.cross_section_preset]
for idx in range(len(params['sides'])):
self.add_lane(params['sides'][idx], params['types'][idx],
params['widths'][idx], params['widths_change'][idx], params['road_mark_types'][idx],
params['road_mark_weights'][idx], params['road_mark_widths'][idx],
params['road_mark_colors'][idx])
if params['sides'][idx] == 'left':
num_lanes_left += 1
if params['sides'][idx] == 'right':
num_lanes_right += 1
self.road_split_type = params['road_split_type']
self.road_split_lane_idx = params['road_split_lane_idx']
for idx, lane in enumerate(self.lanes):
if idx < self.road_split_lane_idx:
lane.split_right = False
else:
lane.split_right = True
self.print_cross_section()
# Block recursive callbacks
self.num_lanes_left = num_lanes_left
self.num_lanes_right = num_lanes_right
# Allow callbacks again
self.lock_lanes = False
def print_cross_section(self):
print('New cross section:', self.cross_section_preset)
sides = []
widths = []
types = []
road_mark_types = []
for lane in self.lanes:
sides.append(lane.side)
widths.append(lane.width)
types.append(lane.type)
road_mark_types.append(lane.road_mark_type)